File: x_test_loop.c

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (358 lines) | stat: -rw-r--r-- 6,867 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/*------------------------------------------------------------------------
 *    Copyright (C) 2001-2003 Enpc/Jean-Philippe Chancelier
 *    jpc@cermics.enpc.fr 
 *--------------------------------------------------------------------------*/
#include <stdio.h>
#include <setjmp.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>

#include "../machine.h"
#include "../menusX/men_scilab.h" 
#include "All-extern-x1.h" 
#include "All-extern.h" 
     
extern int main  _PARAMS((int argc, char **argv));  
extern int C2F (dsort) _PARAMS((void));  
extern void test_plot  _PARAMS((void));  
extern void test_apropos  _PARAMS((void));  
extern void test_menu  _PARAMS((void));  
extern void test_quit  _PARAMS((void));  
extern void test_loop  _PARAMS((void));  
extern void test_message  _PARAMS((void));  
extern void test_click  _PARAMS((void));  
extern void test_events  _PARAMS((void));  
extern void test_xinfo  _PARAMS((void));  
extern void test_xgc  _PARAMS((void));  
extern void LTest  _PARAMS((char *x0));  
extern void C2F (sigbas) _PARAMS((int *i));  
extern void check_win  _PARAMS((void));  
extern void C2F (setfbutn) _PARAMS((char *name, int *rep));  
extern int C2F (scilines) _PARAMS((int *nl, int *nc));  
extern int C2F (sciquit) _PARAMS((void));  
extern void plot  _PARAMS((void));  
extern void cerro  _PARAMS((char *str));  
extern void cout  _PARAMS((char *str));  
extern void C2F (cvstr) _PARAMS((int *n, int *line, char *str, int *job, long int lstr));  

#define PI0 (integer *) 0
#define PD0 (double *)  0

extern int demo_menu_activate;

#include <string.h> /* in case of dmalloc */ 
#include <malloc.h>


int main(argc, argv)
     int argc;
     char **argv;
{
  int i,nowindow=0,nostartup=0;
  demo_menu_activate=1;
  for (i=argc-1 ; i >=0  ; i-- )
    {
      if ( strcmp(argv[i],"-ns")==0) nostartup=1;
      if ( strcmp(argv[i],"-nw")==0) nowindow=1;
    };
  if ( nowindow) 
    C2F(scilab)(&nostartup);
  else
    main_sci(argc,argv);
  return(0);
};

void C2F(fbutn)() {};
void C2F(sciwin)() {};

#define PROMPT "[loop test]-->"

typedef  struct  {
  char *name;
  void (*fonc)(); } TestOpTab ;

static void vide_() {}
     
static char buf[1000];


void test_plot()
{
  integer win=0;
  check_win();
  plot();
  C2F(xsaveplots)(&win,"pipo.sav",0L);
  C2F(xloadplots)("pipo.sav",0L);
}

jmp_buf env;

void inter(int an_int)
{
#ifdef DEBUG
  fprintf(stderr,"Signal Reached");
#endif
  longjmp(env, 1);		 /* return to prompt  */
}


void test_interupt()
{
  int i=0;
  (void) signal(SIGINT, inter);
  (void) signal(SIGKILL, inter);
  if (!setjmp(env)) 
    {
      /* first time */
    } 
  else 
    {	
#ifdef DEBUG
      fprintf(stderr,"OOOOOps");
#endif
      return;
    }
  while (1) { printf("%d\r\n",i++);};
}


void test_menu()
{
  integer win_num=0,ne=3,ierr=0,typ=0;
  static char * entries[]={
    "Un ","Deux","Trois",NULL};
  AddMenu(&win_num,"test button",entries,&ne,&typ,"poo",&ierr);
}

void test_quit() {
  ClearExit(0);
};

void test_loop() {
  while (1) {
    C2F(sxevents)();
  };
} 

void test_message() 
{
  TestMatrixDialogWindow();
  TestChoose();
  TestMessage(1);
  TestDialog() ;
  TestmDialogWindow();
  TestChoice();
}

void test_click() {
  integer i,iw=0,istr=0;
  double x,y;
  check_win();
  C2F(dr1)("xclick","void",&i,&iw,&istr,PI0,PI0, PI0,&x,&y,PD0,PD0,0L,0L);
  sprintf(buf,"-->[%d,%f,%f]",i,x,y);
  Xputstring(buf,strlen(buf));
}

void test_events() 
{
  int i;
  for ( i=0 ; i < 1000; i++) 
    {
#ifdef sun
      unsigned usec=20;
#endif
      xevents1();
#ifdef sun
      usleep(usec);
#endif
    };
  Scistring("Quittting enevent loop");
};

void test_xinfo() 
{
  xinfo_("Xinfo Tester",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
};


void test_xgc() {
  integer num=0;
  /** need ../xgc dir to work **/
  /** xgc(); **/
  DeleteWindowToList(num);
}

void test_help() {
  Sci_Help("cos");
}

void test_apropos() {
  Sci_Apropos("cos");
}


extern int C2F(stimer)(void);

void test_timer(){
  sciprint("stimer %d\r\n",(int)C2F(stimer)());
} 



static TestOpTab testTab[] ={
  {"add menu",test_menu},
  {"apropos",test_apropos},
  {"click", test_click},
  {"events",test_events},
  {"help",test_help},
  {"interupt",test_interupt},
  {"loop",test_loop},
  {"menus",test_message},
  {"plot",test_plot},
  {"quit",test_quit},
  {"stimer",test_timer},
  {"xgc",test_xgc},
  {"xinfo",test_xinfo},
  {(char *) NULL,vide_}
  };

void LTest(x0) 
     char * x0;
{
  int i=0;
  if ( strcmp("quit",x0) == 0) exit(0);
  while ( testTab[i].name != (char *) NULL)
     {
       int j;
       j = strcmp(x0,testTab[i].name);
       if ( j == 0 ) 
	 { 
	   (*(testTab[i].fonc))();
	   return;}
       else 
	 { 
	   if ( j <= 0)
	     {
	       sciprint("\nUnknow X operator <%s>\r\n",x0);
	       break;
	     }
	   else i++;
	 }
     }
  sciprint("\n Unknow X operator <%s>\r\n",x0);
  i=0;
  sciprint("%s","List of known operators \r\n");
  while ( testTab[i].name != (char *) NULL)
    {
      sciprint("\t%s\r\n",testTab[i].name);
      i++;
    }
}

int F2C(scilab)(nostartup)
     int *nostartup;
{
  int siz=1000,len_line,eof,i;
  C2F(xscion)(&i);
  if ( i == 1) 
    for ( ; ; ) {
      Xputstring(PROMPT,strlen(PROMPT));
      C2F(zzledt1)(buf,&siz,&len_line,&eof,0L);
      Xputstring(buf,len_line);
      Xputstring("\r\n",2);
      LTest(buf);
    }
  else 
    for ( ; ; ) {
      fprintf(stdout,PROMPT);
      C2F(zzledt)(buf,&siz,&len_line,&eof,0L);
      fprintf(stdout,buf);
      fprintf(stdout,"\r\n");
      LTest(buf) ;
    };
  return(0);
};


void C2F(sigbas)(i)
     int *i;
{
#ifdef DEBUG
  fprintf(stderr,"CTRL_C activated \n");
#endif
};


void check_win()
{
  integer verb=0,win,na;
  C2F(dr1)("xget","window",&verb,&win,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
  C2F(dr1)("xset","window",&win,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
};

void C2F(setfbutn)(name,rep)
     char *name;
     int *rep;
{
  
}

int C2F(dsort)(){};

int C2F(scilines)(nl,nc)
     int *nl, *nc;
{return(0);};

int C2F(sciquit)()
{
  return(1);
}
     
#include <math.h>

#define XN2DD 2
#define NCURVES2DD  1

void plot()
{
  integer style[NCURVES2DD],aaint[4],n1,n2;
  double x[NCURVES2DD*XN2DD],y[NCURVES2DD*XN2DD],brect[4];
  int i,j;
  for ( j =0 ; j < NCURVES2DD ; j++)
    {
      i=0;
      x[i+ XN2DD*j]= ((double) i+1)/10.0;
      y[i+ XN2DD*j]= 1.234;
      i=1;
      x[i+ XN2DD*j]= ((double) i+2)/10.0;
      y[i+ XN2DD*j]= 2,64;
      }
  for ( i=0 ; i < NCURVES2DD ; i++)
    style[i]= -NCURVES2DD+i;
  n1=NCURVES2DD;n2=XN2DD;
  aaint[0]=aaint[2]=2;aaint[1]=aaint[3]=10;
  C2F(plot2d)(x,y,&n1,&n2,style,"021"," ",brect,aaint,0L,0L);
};


void cerro(str)
char *str;
{
  fprintf(stderr,"%s",str);
}

void cout(str)
char *str;
{
  fprintf(stdout,"%s",str);
}


void C2F(cvstr)(n,line,str,job,lstr)
     int *n,*line;
     char str[];
     int  *job;
     long int lstr;
{};