|
|
1.1 root 1: #include <stdio.h>
2: #include <ctype.h>
3: #define void int
4: #define MAXL 16
5: double atof();
6: char *index();
7: char *getl();
8: void idle();
9: void arc();
10: void box();
11: void circle();
12: void disc();
13: void erase();
14: void closepl();
15: void color();
16: void cfill();
17: void pen();
18: void frame();
19: void grade();
20: void ppause();
21: void line();
22: void move();
23: void openpl();
24: void point();
25: void parabola();
26: void range();
27: void rmove();
28: void text();
29: void sbox();
30: void vec();
31: void rvec();
32: void fill();
33: void poly();
34: void spline();
35: void fspline();
36: void lspline();
37: void dspline();
38: void cspline();
39: void save();
40: void restore();
41: void define();
42: void call();
43: void pinclude();
44: struct pcall {
45: void (*plot)();
46: int kount;
47: char *cc;
48: int numc;
49: } plots[] = {
50: arc, 7, "a", 1,
51: box, 4, "bo", 2,
52: circle, 3, "ci", 2,
53: disc, 3, "di", 2,
54: erase, -1, "e", 1,
55: closepl, -1, "cl", 2,
56: frame, 4, "fr", 2,
57: grade, 1, "g", 1,
58: ppause, -1, "pau", 3,
59: color, 0, "co", 2,
60: cfill, 0, "cf", 2,
61: pen, 0, "pe", 2,
62: line, 4, "li", 2,
63: move, 2, "m", 1,
64: idle, -2, "id", 2,
65: openpl, 0, "o", 1,
66: point, 2, "poi", 3,
67: parabola, 6, "par", 3,
68: range, 4, "ra", 2,
69: rmove, 2, "rm", 2,
70: text, 0, "t", 1,
71: sbox, 4, "sb", 2,
72: vec, 2, "v", 1,
73: rvec, 2, "rv", 2,
74: fill, 256, "fi", 2,
75: poly, 256, "pol", 3,
76: spline, 256, "sp", 2,
77: fspline, 256, "fs", 2,
78: lspline, 256, "ls", 2,
79: dspline, 256, "ds", 2,
80: cspline, 256, "cs", 2,
81: save, -1, "sa", 2,
82: restore, -1, "re", 2,
83: define, 0, "de", 2,
84: call, 0, "ca", 2,
85: pinclude, 0, "in", 2,
86: 0, 0, 0, 0
87: };
88: struct pcall *pplots;
89: struct fcall {
90: char *name;
91: char *stash;
92: } flibr[MAXL];
93: struct fcall *fptr = flibr;
94: short FN = 1;
95: double SC = 1.0;
96: char *fstack[64], **fstp;
97:
98: int num[256],*nn;
99: double *ff[256], **fp;
100: char aa[256];
101: FILE *fd;
102: main(arc, arv)
103: int arc;
104: char **arv;
105: {
106: char *ap;
107: fd = stdin;
108: for (; arc > 1; arc--, arv++) {
109: if (arv[1][0] == '-') {
110: ap = arv[1];
111: ap++;
112: if (*ap == 'T')
113: continue;
114: if (*ap == 'D') {
115: ptype(++ap);
116: continue;
117: }
118: switch (*ap) {
119: case 'e':
120: erase();
121: continue;
122: case 'C':
123: closepl();
124: continue;
125: case 'w':
126: ppause();
127: continue;
128: case 'c':
129: color(++ap);
130: continue;
131: case 'f':
132: cfill(++ap);
133: continue;
134: case 'p':
135: pen(++ap);
136: continue;
137: case 'o':
138: openpl(++ap);
139: continue;
140: case 'g':
141: grade(atof(++ap));
142: continue;
143: default:
144: fprintf(stderr, "%s not allowed as argument\n",
145: ap);
146: exit(1);
147: }
148: continue;
149: }
150: if ((fd = fopen(arv[1], "r")) == NULL) {
151: perror();
152: fprintf(stderr, "Cannot find file %s\n", arv[1]);
153: continue;
154: }
155: process();
156: fclose(fd);
157: }
158: if (fd == stdin)
159: process();
160: exit(0);
161: }
162: process()
163: {
164: short i, j, k, n, acn,curl;
165: double x, y, X[256], *xp;
166: char c, *ap, *aq, truef;
167: fstp = fstack;
168: fp = ff;
169: nn = num;
170: while((ap=getl(aa))){
171: while(isspace(*ap))ap++;
172: if(*ap == ':')continue;
173: while(*ap == '.' && !(isdigit(*(ap+1))))
174: ap++;
175: if (isupper(*ap))
176: *ap = tolower(*ap);
177: if (!islower(*ap)){
178: if (pplots->kount > 1)
179: goto aresume;
180: continue;
181: }
182: if(fp != ff){
183: if(acn%2 != 0){
184: closepl();
185: fprintf(stderr,"phase error\n");
186: exit(1);
187: }
188: *nn++ = acn/2;
189: *nn = 0;
190: (*pplots->plot)(num,ff);
191: fp = ff;
192: nn = num;
193: }
194: for (pplots = plots; pplots->plot != 0; pplots++)
195: if (strncmp(ap, pplots->cc, pplots->numc) == 0){
196: break;
197: }
198: if (pplots->plot == 0) {
199: closepl();
200: fprintf(stderr,"no command for %s\n", ap);
201: exit();
202: }
203: if (pplots->kount < 0) {
204: (*pplots->plot)();
205: continue;
206: }
207: if (*ap != '\n')
208: while(islower(*ap))
209: ap++;
210: if (*ap != '\n')
211: while (isspace(*ap) || *ap == ',')
212: ap++;
213: if (*ap == '\n') {
214: if (!(pplots->kount))
215: (*pplots->plot)(" ");
216: continue;
217: }
218: if (!(pplots->kount)) {
219: for(aq=ap; *aq != '\n';aq++)
220: if(*aq == '\\')aq++;
221: if (*ap == '"'){
222: ap++;
223: if(*(aq-1) == '"')
224: aq--;
225: }
226: *aq = NULL;
227: (*pplots->plot)(ap);
228: continue;
229: }
230: acn = 0;
231: xp = X;
232: if(pplots->kount == 256){
233: curl = 0;
234: *fp++ = X;
235: }
236: aresume:
237: while (*ap != '\n') {
238: while (isspace(*ap) || *ap == ',')
239: ap++;
240: if (*ap == '\n')
241: break;
242: if(*ap == '{'){
243: ap++;
244: if(curl==0 || ( curl==1 && acn == 0)){
245: curl++;
246: continue;
247: }
248: *fp++ = xp;
249: continue;
250: }
251: if(*ap == '}'){
252: ap++;
253: curl++;
254: if(acn==0){
255: *nn = 0;
256: (*pplots->plot)(num,ff);
257: fp = ff;
258: nn = num;
259: continue;
260: }
261: if(acn%2 != 0){
262: closepl();
263: fprintf(stderr,"phase error\n");
264: exit(1);
265: }
266: *nn++ = acn/2;
267: acn = 0;
268: continue;
269: }
270: aq = ap;
271: while (!(isspace(*ap)) && *ap != ',' && *ap != '\n')
272: ap++;
273: if (isdigit(*aq)||(*aq == '-'||*aq == '+'||*aq == '.')){
274: *xp++ = atof(aq)*SC;
275: if (++acn >= pplots->kount) {
276: switch (acn) {
277: case 1:
278: (*pplots->plot)(X[0]);
279: break;
280: case 2:
281: (*pplots->plot)(X[0], X[1]);
282: break;
283: case 3:
284: (*pplots->plot)(X[0],X[1],X[2]);
285: break;
286: case 4:
287: (*pplots->plot)(X[0],X[1],X[2],X[3]);
288: break;
289: case 6:
290: (*pplots->plot)(X[0],X[1],X[2],
291: X[3], X[4], X[5]);
292: break;
293: case 7:
294: (*pplots->plot)(X[0],X[1],X[2],
295: X[3], X[4], X[5], X[6]);
296: break;
297: case 256:
298: (*pplots->plot)(truef, X);
299: break;
300: }
301: acn = 0;
302: xp = X;
303: }
304: }
305: }
306: }
307: }
308: char *malloc();
309: char *realloc();
310: char *names = 0;
311: char *enames = 0;
312: char *bstash = 0;
313: char *estash = 0;
314: unsigned size = 1024;
315: char *nstash = 0;
316: define(a)
317: char *a;
318: {
319: char *ap, *aq;
320: short i, j;
321: int curly = 0;
322: ap = a;
323: while(isalpha(*ap))ap++;
324: if(ap == a){
325: fprintf(stderr,"no name with define\n");
326: exit(1);
327: }
328: i = ap - a;
329: if(names+i+1 > enames){
330: names = malloc((unsigned)512);
331: enames = names + 512;
332: }
333: fptr->name = names;
334: strncpy(names, a,i);
335: names += i;
336: *names++ = '\0';
337: if(!bstash){
338: bstash = nstash = malloc(size);
339: estash = bstash + size;
340: }
341: fptr->stash = nstash;
342: while(*ap != '{')
343: if(*ap == '\n'){
344: if((ap=fgets(aa,256,fd))==NULL){
345: fprintf(stderr,"unexpected end of file\n");
346: exit(1);
347: }
348: }
349: else ap++;
350: while((j=getc(fd))!= EOF){
351: if(j == '{')curly++;
352: else if(j == '}'){
353: if(curly == 0)break;
354: else curly--;
355: }
356: *nstash++ = j;
357: if(nstash == estash){
358: free(bstash);
359: size += 1024;
360: bstash = realloc(bstash,size);
361: estash = bstash+size;
362: }
363: }
364: *nstash++ = '\0';
365: if(fptr++ >= &flibr[MAXL]){
366: fprintf(stderr,"Too many objects\n");
367: exit(1);
368: }
369: }
370: call(a)
371: char *a;
372: {
373: char *ap;
374: struct fcall *f;
375: char sav;
376: ap = a;
377: while(isalpha(*ap))ap++;
378: sav = *ap;
379: *ap = '\0';
380: for(f=flibr;f<fptr;f++){
381: if (!(strcmp(a, f->name)))
382: break;
383: }
384: if(f == fptr){
385: fprintf(stderr, "object %s not defined\n",a);
386: exit(1);
387: }
388: *ap = sav;
389: while (isspace(*ap) || *ap == ',')
390: ap++;
391: if (*ap != '\0')
392: SC = atof(ap);
393: else SC = 1.;
394: *(++fstp) = f->stash;
395: FN = 0;
396: }
397: pinclude(a)
398: char *a;
399: {
400: FILE * fd1;
401: char aa[256], *ap;
402: double x[256], *xp;
403: int n;
404: if ((fd1 = fopen(a + 1, "r")) == NULL) {
405: perror();
406: fprintf(stderr, "Cannot find %s\n", a + 1);
407: return(0);
408: }
409: xp = x;
410: while (fgets(aa, 256, fd1) != NULL) {
411: ap = aa;
412: while (*ap != NULL && *ap != '\n') {
413: while (isspace(*ap) || *ap == ',')
414: ap++;
415: if (*ap == NULL)
416: break;
417: *xp++ = atof(ap);
418: while (!(isspace(*ap)) && *ap != ',' && *ap != NULL)
419: ap++;
420: }
421: }
422: fclose(fd1);
423: }
424: char *getl(a)
425: char a[];
426: {
427: char *ap;
428: newl:
429: if(FN){
430: if (fgets(a, 256, fd) == NULL)
431: return(0);
432: if(*a == '\n')goto newl;
433: return(a);
434: } else {
435: if(**fstp == '\0'){
436: fstp--;
437: if(fstp == fstack){
438: SC = 1.;
439: FN = 1;
440: }
441: goto newl;
442: }
443: ap = *fstp;
444: *fstp = index(*fstp,'\n') +1;
445: return(ap);
446: }
447: }
448: spline(n1, f1)
449: int n1[];
450: double *f1[];
451: {
452: splin(0,n1,f1);
453: }
454: fspline(n1,f1)
455: int n1[];
456: double *f1[];
457: {
458: splin(1,n1,f1);
459: }
460: lspline(n1,f1)
461: int n1[];
462: double *f1[];
463: {
464: splin(2,n1,f1);
465: }
466: dspline(n1,f1)
467: int n1[];
468: double *f1[];
469: {
470: splin(3,n1,f1);
471: }
472: cspline(n1,f1)
473: int n1[];
474: double *f1[];
475: {
476: splin(4,n1,f1);
477: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.