History

Plan 9 from Bell Labs Second Edition 1995-04-05

David du Colombier committed 31 years ago2e-1995-04-05

Commit 219b2ee1 parent bd389b311749 files · +2555453 −1889727Browse files

Showing the changes to sys/src/cmd/plot/plot.c (1 of 11749 files). Show all

Unified · Split

sys/src/cmd/plot/plot.c+55−47
@@ -8,6 +8,7 @@ void define(char*); · 7 unmodified lines
88 void call(char*);
99 void include(char*);
1010 int process(Biobuf*);
11+int server(void);
1112
1213 enum{
1314 ARC,
@@ -125,67 +126,60 @@ double *pts[NPTS]; /* control-polygon vertex pointers */ · 111 unmodified lines
125126 void
126127 main(int arc, char *arv[]){
127128 char *ap;
128− Biobuf *fd;
129− fd = 0;
130− openpl("");
129+ Biobuf *bp;
130+ int fd;
131+ int i;
132+ int dflag;
133+ char *oflag;
134+ bp = 0;
135+ fd = dup(0, -1); /* because openpl will close 0! */
136+ dflag=0;
137+ oflag="";
138+ for(i=1;i!=arc;i++) if(arv[i][0]=='-') switch(arv[i][1]){
139+ case 'd': dflag=1; break;
140+ case 'o': oflag=arv[i]+2; break;
141+ case 's': fd=server(); break;
142+ case 'W': setwindow(arv[i]+2); break;
143+ }
144+ openpl(oflag);
145+ if(dflag) doublebuffer();
131146 for (; arc > 1; arc--, arv++) {
132147 if (arv[1][0] == '-') {
133148 ap = arv[1];
134149 ap++;
135− if (*ap == 'T')
136− continue;
137− if (*ap == 'D')
138− continue;
139150 switch (*ap) {
140− case 'd':
141− doublebuffer();
142− break;
143− case 'e':
144− erase();
145− continue;
146− case 'C':
147− closepl();
148− continue;
149− case 'w':
150− ppause();
151− continue;
152− case 'c':
153− color(ap+1);
154− continue;
155− case 'f':
156− cfill(ap+1);
157− continue;
158− case 'p':
159− pen(ap+1);
160− continue;
161− case 'o':
162− openpl(ap+1);
163− continue;
164− case 'g':
165− grade(atof(ap+1));
166− continue;
167151 default:
168− fprint(2, "%s not allowed as argument\n",
169− ap);
152+ fprint(2, "%s not allowed as argument\n", ap);
170153 exits("usage");
154+ case 'T': break;
155+ case 'D': break;
156+ case 'd': break;
157+ case 'o': break;
158+ case 'W': break;
159+ case 's': break;
160+ case 'e': erase(); break;
161+ case 'C': closepl(); break;
162+ case 'w': ppause(); break;
163+ case 'c': color(ap+1); break;
164+ case 'f': cfill(ap+1); break;
165+ case 'p': pen(ap+1); break;
166+ case 'g': grade(atof(ap+1)); break;
171167 }
172− continue;
173168 }
174− if ((fd = Bopen(arv[1], OREAD)) == 0) {
169+ else if ((bp = Bopen(arv[1], OREAD)) == 0) {
175170 perror(arv[1]);
176171 fprint(2, "Cannot find file %s\n", arv[1]);
177− continue;
178172 }
179− if(!process(fd))
180− break;
181− Bclose(fsp->fd);
173+ else if(process(bp)) Bterm(fsp->fd);
174+ else break;
182175 }
183− if (fd == 0){
184− fd = malloc(sizeof *fd);
185− Binit(fd, 0, OREAD);
186− process(fd);
176+ if (bp == 0){
177+ bp = malloc(sizeof *bp);
178+ Binit(bp, fd, OREAD);
179+ process(bp);
187180 }
188181 closepl();
182+ read(0, "x", 1);
189183 exits(0);
190184 }
191185 int isalpha(int c)
@@ -225,7 +219,7 @@ int nextc(void){ · 33 unmodified lines
225219 }else
226220 c=Beof;
227221 if(c!=Beof || fsp==fstack) break;
228− if(fsp->fd) Bclose(fsp->fd);
222+ if(fsp->fd) Bterm(fsp->fd);
229223 --fsp;
230224 }
231225 if(c=='\n') fsp->lineno++;
@@ -599,3 +593,17 @@ void include(char *a){ · 367 unmodified lines
599593 fsp->corebuf=0;
600594 fsp->fd=fd;
601595 }
596+/*
597+ * Doesn't work. Why?
598+ */
599+int server(void){
600+ int fd, p[2];
601+ char buf[32];
602+ pipe(p);
603+ fd = create("/srv/plot", 1, 0666);
604+ sprint(buf, "%d", p[1]);
605+ write(fd, buf, strlen(buf));
606+ close(fd);
607+ close(p[1]);
608+ return p[0];
609+}