gdisplay.c
13.2 KB
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
#include "gdisplay.h"
#include <sys/types.h>
#include <sys/prctl.h>
#include <stdio.h>
struct item *items;
struct trace *traces;
struct wind *winds;
struct glob *g = 0;
static int gpinit = 0;
int xo,yo;
int np;
int s0 = 0;
int *mbuf0,*mbuf1,*mbuf2,*mbuf3,*mbuf4;
static int gmn = 0;
static int gmemid[16],gmemi[16];
#define MBSIZE 1024
/* -------------------------------------------------------------------- */
/* Initialize multi-process environment */
/* -------------------------------------------------------------------- */
init_proc()
{
static int wfirst = 1;
int pp;
extern void proc1();
if(wfirst==0)
return;
pp = getpid();
#ifdef SPROC
sproc(proc1,PR_SALL,pp);
#else
if(!fork())
proc1(pp);
#endif
wfirst = 0;
}
/* -------------------------------------------------------------------- */
/* Initialize shared memory environment */
/* -------------------------------------------------------------------- */
init_shm()
{
static int sfirst = 1;
int i;
if(sfirst==0)
return;
#ifdef SPROC
items = (struct item *)malloc(N_ITEMS*sizeof(struct item));
traces = (struct trace *)malloc(N_TRACES*sizeof(struct trace));
winds = (struct wind *)malloc(N_WINDS*sizeof(struct wind));
g = (struct glob *)malloc(sizeof(struct glob));
mbuf0 = (int *)malloc(MBSIZE*4);
mbuf1 = (int *)malloc(MBSIZE*4);
mbuf2 = (int *)malloc(MBSIZE*4);
mbuf3 = (int *)malloc(MBSIZE*4);
mbuf4 = (int *)malloc(MBSIZE*4);
#else
s0 = shmget(IPC_PRIVATE,N_ITEMS*sizeof(struct item) +
N_TRACES*sizeof(struct trace) + N_WINDS*sizeof(struct wind) +
sizeof(struct glob)+MBSIZE*4*5,0777);
items = (struct item *)shmat(s0,0,0);
traces = (struct trace *)(((long)items)+N_ITEMS*sizeof(struct item));
winds = (struct wind *)(((long)traces)+N_TRACES*sizeof(struct trace));
g = (struct glob *)(((long)winds)+N_WINDS*sizeof(struct wind));
mbuf0 = (int *)(((long)g)+sizeof(struct glob));
mbuf1 = (int *)(((long)mbuf0)+MBSIZE*4);
mbuf2 = (int *)(((long)mbuf1)+MBSIZE*4);
mbuf3 = (int *)(((long)mbuf2)+MBSIZE*4);
mbuf4 = (int *)(((long)mbuf3)+MBSIZE*4);
#endif
g->nwindows = 0;
g->ni = 0;
g->nt = 0;
g->wpt = g->rpt = 0;
g->oldnoise = 0;
g->newnoise = 6;
g->mem0 = mc_scan_plusargs("mem0");
sfirst = 0;
}
/* -------------------------------------------------------------------- */
/* Set time between updates */
/* -------------------------------------------------------------------- */
gupdate(a,b)
{
g->newnoise = tf_getp(1);
}
/* -------------------------------------------------------------------- */
/* Write Memory Location */
/* -------------------------------------------------------------------- */
gwmem(a,b)
{
int i,x,y,val,valz,id;
id = tf_getp(1);
x = tf_getp(2);
y = tf_getp(3);
tf_getpz(4,&val,&valz);
for(i=0;i<gmn;i++)
if(gmemid[i]==id)
break;
if(i==gmn) return;
i = gmemi[i];
if(items[i].mem1==0)
clear_mem1(&items[i]);
if(items[i].mem1[y]==0)
clear_mem1y(&items[i],y);
while((g->wpt+1)%MBSIZE==g->rpt);
mbuf0[g->wpt] = i;
mbuf1[g->wpt] = x;
mbuf2[g->wpt] = y;
mbuf3[g->wpt] = val;
mbuf4[g->wpt] = valz;
g->wpt = (g->wpt+1)%MBSIZE;
items[i].mem1[y][x]=val;
items[i].zmem1[y][x]=valz;
}
/* -------------------------------------------------------------------- */
/* Read Memory Location */
/* -------------------------------------------------------------------- */
grmem(a,b)
{
int i,x,y,val,id;
id = tf_getp(1);
x = tf_getp(2);
y = tf_getp(3);
for(i=0;i<gmn;i++)
if(gmemid[i]==id)
break;
if(i==gmn) return;
i = gmemi[i];
if(items[i].mem1==0)
clear_mem1(&items[i]);
if(items[i].mem1[y]==0)
clear_mem1y(&items[i],y);
tf_putpz(4,items[i].mem1[y][x],
items[i].zmem1[y][x]);
}
/* -------------------------------------------------------------------- */
/* Initialize gdisplay window */
/* -------------------------------------------------------------------- */
gdisplay_call(a,b)
int a,b;
{
int i,n,cmd,w,j,k;
char str[256];
int x,y,xx;
short p1;
int p0;
int tmp;
int cc;
int msz;
struct t_tfexprinfo ee;
int temp;
int dot;
i = 1;
init_shm();
strcpy(winds[g->nwindows].mipname,tf_mipname());
winds[g->nwindows].col = tf_getp(i++);
winds[g->nwindows].x = tf_getp(i++);
winds[g->nwindows].y = tf_getp(i++);
winds[g->nwindows].w = tf_getp(i++);
winds[g->nwindows].h = tf_getp(i++);
winds[g->nwindows].ci = tf_getinstance();
winds[g->nwindows].oldshow = 0;
winds[g->nwindows].tpos = 0;
for(j=0,dot=0;winds[g->nwindows].mipname[j];j++)
if(winds[g->nwindows].mipname[j]=='.')dot++;
if(dot>1)
winds[g->nwindows].newshow = 0;
else
winds[g->nwindows].newshow = 1;
n = tf_nump();
while(i<n)
{
items[g->ni].cmd = tf_getp(i++);
if(tf_typep(i)!=tf_string)
items[g->ni].col = tf_getp(i++);
else
items[g->ni].col = winds[g->nwindows].col;
items[g->ni].tag = -1;
strcpy(items[g->ni].name,tf_getp(i++));
if(items[g->ni].cmd==0||items[g->ni].cmd==3||
items[g->ni].cmd==6)
strcpy(items[g->ni].fmt,tf_getp(i++));
items[g->ni].x0 = tf_getp(i++);
items[g->ni].y0 = tf_getp(i++);
items[g->ni].x1=items[g->ni].x0+tf_getp(i++);
items[g->ni].y1=items[g->ni].y0+tf_getp(i++);
if(items[g->ni].cmd<5)
{
if(items[g->ni].cmd!=2)
items[g->ni].p = i++;
if(items[g->ni].cmd==1||items[g->ni].cmd==2||
items[g->ni].cmd==3)
items[g->ni].tag = tf_getp(i++);
if(items[g->ni].cmd==2)
items[g->ni].newval = items[g->ni].oldval =
items[g->ni].newnewval = 0;
else
tf_getpz(items[g->ni].p,&items[g->ni].newval,
&items[g->ni].newzval);
items[g->ni].oldval = items[g->ni].newval;
items[g->ni].oldzval = items[g->ni].newzval;
items[g->ni].tval = tf_getp(items[g->ni].p);
tf_exprinfo(items[g->ni].p,&ee);
items[g->ni].size = ee.expr_vec_size;
}
else if(items[g->ni].cmd==5)
{
strcpy(items[g->ni].fmt,tf_getp(i++));
items[g->ni].newval = 0;
items[g->ni].oldval = 0;
items[g->ni].newzval = 0;
items[g->ni].oldzval = 0;
items[g->ni].tval = 0;
items[g->ni].size = 1;
}
else if(items[g->ni].cmd==6)
{
items[g->ni].tval = 0;
items[g->ni].size = 1;
items[g->ni].xsize = tf_getp(i++);
items[g->ni].ysize = tf_getp(i++);
items[g->ni].mem = 0;
items[g->ni].mem = 0;
items[g->ni].zmem = 0;
items[g->ni].mem1 = 0;
items[g->ni].zmem1 = 0;
items[g->ni].xpos = 0;
items[g->ni].ypos = 0;
#ifdef OLDMEM
items[g->ni].px = i++;
items[g->ni].py = i++;
items[g->ni].pwe = i++;
items[g->ni].pwd = i++;
items[g->ni].prd = i++;
#else
gmemid[gmn] = tf_getp(i++);
gmemi[gmn] = g->ni;
gmn++;
#endif
}
else if(items[g->ni].cmd==7)
{
int pos;
items[g->ni].tval = 0;
items[g->ni].size = 1;
pos = 0;
items[g->ni].tsize = tf_getp(i++);
items[g->ni].tmul = tf_getp(i++);
items[g->ni].major = tf_getp(i++)*items[g->ni].tmul;
items[g->ni].p = i++;
items[g->ni].nt = 1;
items[g->ni].px1 = 0;
items[g->ni].ci = tf_getinstance();
msz = -1;
while(1)
{
if(i==n)
break;
if(tf_typep(i)!=tf_string)
break;
else if(!strcmp(tf_getp(i),""))
{
pos++;
i += 3;
items[g->ni].nt ++;
continue;
}
else
traces[g->nt].pos = pos++;
traces[g->nt].ci = tf_getinstance();
strcpy(traces[g->nt].name,tf_getp(i++));
for(k=0;traces[g->nt].name[k];k++);
if(k>msz)
{
msz = k;
items[g->ni].px1 = msz*7+25;
}
strcpy(traces[g->nt].fmt,tf_getp(i++));
traces[g->nt].p = i++;
tf_getpz(traces[g->nt].p,&traces[g->nt].newval,
&traces[g->nt].newzval);
tf_exprinfo(traces[g->nt].p,&ee);
traces[g->nt].size = ee.expr_vec_size;
traces[g->nt].op[0].data = traces[g->nt].newval;
traces[g->nt].op[0].zdata=traces[g->nt].newzval;
traces[g->nt].op[0].time = 0;
traces[g->nt].op[0].on=tf_getp(items[g->ni].p);
traces[g->nt].oN = traces[g->nt].op[0].on;
traces[g->nt].n = 1;
traces[g->nt].in = g->ni;
traces[g->nt].wrap = 0;
g->nt++;
items[g->ni].nt ++;
}
items[g->ni].ypos = 0;
w = items[g->ni].x1-items[g->ni].x0;
if(items[g->ni].tsize+items[g->ni].px1 > w-24)
items[g->ni].xpos=items[g->ni].tsize+
items[g->ni].px1-(w-24);
else
items[g->ni].xpos = 0;
}
items[g->ni].redraw = 1;
items[g->ni].wn = g->nwindows;
g->ni++;
}
tf_asynchon();
g->nwindows++;
init_proc();
gdisplay_update(a,b);
}
/* -------------------------------------------------------------------- */
/* Update gdisplay window */
/* -------------------------------------------------------------------- */
gdisplay_update(a,b)
int a,b;
{
register int k;
int n,cmd,j;
char str[256];
int x,y,xx,z;
short p1;
int p0;
int tmp;
int cc;
struct t_tfexprinfo ee;
char * ci;
int tn;
register struct trace *t;
register struct item *i;
char change[2048];
if(g==0) return;
for(k=tf_nump()-1;k>=0;k--)
change[k] = 0;
tf_movepvc_flag(-1);
for(k=tf_getpchange(0);k;k=tf_getpchange(k))
change[k] = 1;
g->thetime = tf_gettime();
ci = tf_getinstance();
for(k=0;k<g->ni;k++)
{
i = &items[k];
if(winds[i->wn].ci != ci)
continue;
if(!change[i->p])
continue;
if(i->cmd==0)
tf_getpz(i->p,&i->newval,&i->newzval);
}
for(k=0;k<g->nt;k++)
{
t = &traces[k];
i = &items[t->in];
if(t->ci != ci)
continue;
if(!change[t->p]&&!change[i->p])
continue;
tf_getpz(t->p,&x,&z);
if(t->oN && (x!=t->newval||z!=t->newzval)||
t->oN != tf_getp(i->p))
{
if(t->op[t->n-1].time==g->thetime*i->tmul)
tn = t->n-1;
else
tn = t->n;
if(tn==TSIZE)
{
tn = 0;
t->wrap = 1;
}
t->op[tn].data = x;
t->op[tn].zdata = z;
t->op[tn].time = g->thetime*i->tmul;
t->oN = tf_getp(i->p);
t->op[tn].on = t->oN;
t->n=tn+1;
}
t->newval = x;
t->newzval = z;
}
#ifdef __sgi__
sginap(0);
#else
usleep(0);
#endif
}
/* -------------------------------------------------------------------- */
/* Check arguments for gdisplay */
/* -------------------------------------------------------------------- */
gdisplay_error(a,b)
int a,b;
{
int i,n,cmd;
char str[256];
int x0,y0,x1,y1;
int x,y;
static int redraw;
short p1;
int p0;
n = tf_nump();
if(n<5)
{
tf_error("Argument count error for $gdisplay");
return;
}
i = 1;
if(is_val(tf_typep(i++)))
{
tf_error("Bad Argument for win_x");
return;
}
if(is_val(tf_typep(i++)))
{
tf_error("Bad Argument for win_y");
return;
}
if(is_val(tf_typep(i++)))
{
tf_error("Bad Argument for win_w");
return;
}
if(is_val(tf_typep(i++)))
{
tf_error("Bad Argument for win_h");
return;
}
if(tf_typep(i++)!=tf_string)
{
tf_error("Bad Argument for $gdisplay");
return;
}
while(i<n)
{
cmd = tf_getp(i);
if(is_val(tf_typep(i++)))
{
tf_error("Bad Argument for cmd");
return;
}
if(tf_typep(i++)!=tf_string)
{
tf_error("Bad Argument for name (%d)",i);
return;
}
if(cmd==0||cmd==3||cmd==4)
{
if(tf_typep(i++)!=tf_string)
{
tf_error("Bad Argument for format");
return;
}
}
if(cmd==1||cmd==2||cmd==3)
{
if(is_val(tf_typep(i++)))
{
tf_error("Bad Argument for tag");
return;
}
}
if(cmd==0||cmd==1||cmd==2||cmd==3)
{
if(is_val(tf_typep(i++)))
{
tf_error("Bad Argument for x");
return;
}
if(is_val(tf_typep(i++)))
{
tf_error("Bad Argument for y");
return;
}
if(is_val(tf_typep(i++)))
{
tf_error("Bad Argument for w");
return;
}
if(is_val(tf_typep(i++)))
{
tf_error("Bad Argument for h");
return;
}
}
if(is_val(tf_typep(i++)))
{
tf_error("Bad Argument for expr");
return;
}
}
}
/* -------------------------------------------------------------------- */
/* Return size for gget */
/* -------------------------------------------------------------------- */
gget_fsize(a,b)
int a,b;
{
int i;
char *mn;
mn = tf_mipname();
for(i=0;i<g->ni;i++)
if(!strcmp(mn,winds[items[i].wn].mipname)&&
items[i].tag==tf_getp(1))
{
if(items[i].cmd==1||items[i].cmd==2||items[i].cmd==3)
return(items[i].size);
}
return(0);
}
/* -------------------------------------------------------------------- */
/* Return value for gget */
/* -------------------------------------------------------------------- */
gget(a,b)
int a,b;
{
int i;
int x;
char *mn;
mn = tf_mipname();
x = 0;
for(i=0;i<g->ni;i++)
if(!strcmp(mn,winds[items[i].wn].mipname)&&
items[i].tag==tf_getp(1))
{
if(items[i].cmd==1||items[i].cmd==3)
{
x = items[i].newval;
}
if(items[i].cmd==2)
{
x = (items[i].newnewval!=0);
if(items[i].newnewval)
items[i].newnewval --;
}
}
tf_putp(0,x);
}
is_val(v)
{
if(v!=tf_readonly&&v!=tf_readwrite)
return(1);
else
return(0);
}
int get_message(a,b,c,d,e)
int *a,*b,*c,*d,*e;
{
if(g->rpt==g->wpt)return(-1);
*a = mbuf0[g->rpt];
*b = mbuf1[g->rpt];
*c = mbuf2[g->rpt];
*d = mbuf3[g->rpt];
*e = mbuf4[g->rpt];
g->rpt = (g->rpt+1)%MBSIZE;
return(0);
}
clear_mem1(i)
struct item *i;
{
int j,k;
i->mem1 = (int **)malloc(i->ysize*4);
i->zmem1 = (int **)malloc(i->ysize*4);
for(k=0;k<i->ysize;k++)
{
i->mem1[k] = 0;
i->zmem1[k] = 0;
}
}
clear_mem1y(i,y)
struct item *i;
{
int j,k;
i->mem1[y] = (int *)malloc(i->xsize*4);
i->zmem1[y] = (int *)malloc(i->xsize*4);
if(g->mem0)
for(k=0;k<i->xsize;k++)
{
i->mem1[y][k] = 0x0;
i->zmem1[y][k] = 0x0;
}
else
for(k=0;k<i->xsize;k++)
{
i->mem1[y][k] = 0xffffffff;
i->zmem1[y][k] = 0xffffffff;
}
}