81 /*PARABOLA*/ "par", 3,
98 struct pcall *pplots; /* last command read */
104 } flibr[MAXL]; /* define strings */
106 struct fcall *fptr = flibr;
115 }fstack[NFSTACK]; /* stack of open input files & defines */
116 struct fstack *fsp=fstack;
119 char argstr[NARGSTR+1]; /* string arguments */
122 double x[NX]; /* numeric arguments */
125 int cnt[NPTS]; /* control-polygon vertex counts */
126 double *pts[NPTS]; /* control-polygon vertex pointers */
128 void eresized(int new){
129 if(new && getwindow(display, Refnone) < 0){
130 fprint(2, "Can't reattach to window: %r\n");
140 main(int arc, char *arv[]){
149 fd = dup(0, -1); /* because openpl will close 0! */
153 for(i=1;i!=arc;i++) if(arv[i][0]=='-') switch(arv[i][1]){
154 case 'd': dflag=1; break;
155 case 'o': oflag=arv[i]+2; break;
156 case 's': fd=server(); break;
159 if(dflag) doublebuffer();
160 for (; arc > 1; arc--, arv++) {
161 if (arv[1][0] == '-') {
166 fprint(2, "%s not allowed as argument\n", ap);
173 case 'e': erase(); break;
174 case 'C': closepl(); break;
175 case 'w': ppause(); break;
176 case 'c': color(ap+1); break;
177 case 'f': cfill(ap+1); break;
178 case 'p': pen(ap+1); break;
179 case 'g': grade(atof(ap+1)); break;
180 case 'W': winsize = ap+1; break;
183 else if ((bp = Bopen(arv[1], OREAD)) == 0) {
185 fprint(2, "Cannot find file %s\n", arv[1]);
187 else if(process(bp)) Bterm(fsp->fd);
191 bp = malloc(sizeof *bp);
192 Binit(bp, fd, OREAD);
198 if(m.buttons&4 && emenuhit(3, &m, &menu)==0) exits(0);
205 if(fsp->peekc!=Beof){
212 else if(*fsp->corebuf){
213 fsp->corebuf+=chartorune(&r, fsp->corebuf);
217 if(c!=Beof || fsp==fstack) break;
218 if(fsp->fd) Bterm(fsp->fd);
221 if(c=='\n') fsp->lineno++;
225 * Read a string into argstr -- ignores leading spaces
226 * and an optional leading quote-mark
236 while(c==' ' || c=='\t');
237 if(c=='\'' || c=='"'){
242 while(c!='\n' && c!=Beof){
244 s+=runetochar(s, &r);
247 if(quote && s!=argstr && r==quote) --s;
251 * Read a floating point number into argstr
259 if(c=='+' || c=='-'){
263 while(isdigit(c) || c=='.'){
264 if(s!=&argstr[NARGSTR]) *s++=c;
269 if(ndp>1 || ndig==0){
273 if(c=='e' || c=='E'){
274 if(s!=&argstr[NARGSTR]) *s++=c;
276 if(c=='+' || c=='-'){
277 if(s!=&argstr[NARGSTR]) *s++=c;
285 if(s!=&argstr[NARGSTR]) *s++=c;
294 * Read n numeric arguments, storing them in
303 }while(strchr(" \t\n", c) || c!='.' && c!='+' && c!='-' && ispunct(c));
306 fprint(2, "line %d: number expected\n", fsp->lineno);
307 exits("input error");
309 x[i]=atof(argstr)*fsp->scale;
313 * Read a list of lists of control vertices, storing points in x[.],
314 * pointers in pts[.] and counts in cnt[.]
319 double **ptsp=pts, *xp=x;
323 }while(c==' ' || c=='\t');
340 fprint(2, "line %d: phase error\n",
345 if(ptsp==&pts[NPTS]){
346 fprint(2, "line %d: out of polygons\n",
348 exits("exceeded limit");
353 if(--nleft==0) return;
360 case '.': case '+': case '-':
361 case '0': case '1': case '2': case '3': case '4':
362 case '5': case '6': case '7': case '8': case '9':
365 fprint(2, "line %d: expected number\n", fsp->lineno);
369 fprint(2, "line %d: out of space\n", fsp->lineno);
370 exits("exceeded limit");
377 else if(!ispunct(c)){
398 while(c==' ' || c=='\t');
402 while(c!='\n' && c!=Beof);
409 if(fsp->fd) Bungetc(fsp->fd);
416 if(c=='\n') continue;
420 if(isupper(c)) c=tolower(c);
421 if(s!=&argstr[NARGSTR]) *s++=c;
426 for(pplots=plots;pplots->cc;pplots++)
427 if(strncmp(argstr, pplots->cc, pplots->numc)==0)
430 fprint(2, "line %d, %s unknown\n", fsp->lineno,
432 exits("bad command");
439 fprint(2, "line %d, no command!\n", fsp->lineno);
442 switch(pplots-plots){
443 case ARC: numargs(7); rarc(x[0],x[1],x[2],x[3],x[4],x[5],x[6]); break;
444 case BOX: numargs(4); box(x[0], x[1], x[2], x[3]); break;
445 case CALL: strarg(); call(argstr); pplots=0; break;
446 case CFILL: strarg(); cfill(argstr); pplots=0; break;
447 case CIRC: numargs(3); circ(x[0], x[1], x[2]); break;
448 case CLOSEPL: strarg(); closepl(); pplots=0; break;
449 case COLOR: strarg(); color(argstr); pplots=0; break;
450 case CSPLINE: polyarg(); splin(4, cnt, pts); break;
451 case DEFINE: strarg(); define(argstr); pplots=0; break;
452 case DISK: numargs(3); plotdisc(x[0], x[1], x[2]); break;
453 case DSPLINE: polyarg(); splin(3, cnt, pts); break;
454 case ERASE: strarg(); erase(); pplots=0; break;
455 case FILL: polyarg(); fill(cnt, pts); break;
456 case FRAME: numargs(4); frame(x[0], x[1], x[2], x[3]); break;
457 case FSPLINE: polyarg(); splin(1, cnt, pts); break;
458 case GRADE: numargs(1); grade(x[0]); break;
459 case IDLE: strarg(); idle(); pplots=0; break;
460 case INCLUDE: strarg(); include(argstr); pplots=0; break;
461 case LINE: numargs(4); plotline(x[0], x[1], x[2], x[3]); break;
462 case LSPLINE: polyarg(); splin(2, cnt, pts); break;
463 case MOVE: numargs(2); move(x[0], x[1]); break;
464 case OPENPL: strarg(); openpl(argstr); pplots=0; break;
465 case PARABOLA: numargs(6); parabola(x[0],x[1],x[2],x[3],x[4],x[5]); break;
466 case PAUSE: strarg(); ppause(); pplots=0; break;
467 case PEN: strarg(); pen(argstr); pplots=0; break;
468 case POINT: numargs(2); dpoint(x[0], x[1]); break;
469 case POLY: polyarg(); plotpoly(cnt, pts); break;
470 case RANGE: numargs(4); range(x[0], x[1], x[2], x[3]); break;
471 case RESTORE: strarg(); restore(); pplots=0; break;
472 case RMOVE: numargs(2); rmove(x[0], x[1]); break;
473 case RVEC: numargs(2); rvec(x[0], x[1]); break;
474 case SAVE: strarg(); save(); pplots=0; break;
475 case SBOX: numargs(4); sbox(x[0], x[1], x[2], x[3]); break;
476 case SPLINE: polyarg(); splin(0, cnt, pts); break;
477 case TEXT: strarg(); text(argstr); pplots=0; break;
478 case VEC: numargs(2); vec(x[0], x[1]); break;
480 fprint(2, "plot: missing case %ld\n", pplots-plots);
481 exits("internal error");
490 unsigned size = 1024;
492 void define(char *a){
497 while(isalpha((uchar)*ap))ap++;
499 fprint(2,"no name with define\n");
503 if(names+i+1 > enames){
504 names = malloc((unsigned)512);
505 enames = names + 512;
512 bstash = nstash = malloc(size);
513 estash = bstash + size;
515 fptr->stash = nstash;
518 if((ap=Brdline(fsp->fd, '\n'))==0){
519 fprint(2,"unexpected end of file\n");
524 while((j=Bgetc(fsp->fd))!= Beof){
531 if(nstash == estash){
534 bstash = realloc(bstash,size);
535 estash = bstash+size;
539 if(fptr++ >= &flibr[MAXL]){
540 fprint(2,"Too many objects\n");
541 exits("too many objects");
550 while(isalpha((uchar)*ap))ap++;
553 for(f=flibr;f<fptr;f++){
554 if (!(strcmp(a, f->name)))
558 fprint(2, "object %s not defined\n",a);
562 while (isspace((uchar)*ap) || *ap == ',')
567 if(++fsp==&fstack[NFSTACK]){
568 fprint(2, "input stack overflow\n");
573 fsp->corebuf=f->stash;
575 fsp->scale=fsp[-1].scale*SC;
577 void include(char *a){
582 exits("can't include");
584 if(++fsp==&fstack[NFSTACK]){
585 fprint(2, "input stack overflow\n");
600 fd = create("/srv/plot", 1, 0666);
601 sprint(buf, "%d", p[1]);
602 write(fd, buf, strlen(buf));