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
8void call(char*);8void call(char*);
9void include(char*);9void include(char*);
10int process(Biobuf*);10int process(Biobuf*);
11int server(void);
11 12
12enum{13enum{
13 ARC,14 ARC,
@@ -125,67 +126,60 @@ double *pts[NPTS]; /* control-polygon vertex pointers */ · 111 unmodified lines
125void126void
126main(int arc, char *arv[]){127main(int arc, char *arv[]){
127 char *ap;128 char *ap;
128 Biobuf *fd;129 Biobuf *bp;
129 fd = 0;130 int fd;
130 openpl("");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();
131 for (; arc > 1; arc--, arv++) {146 for (; arc > 1; arc--, arv++) {
132 if (arv[1][0] == '-') {147 if (arv[1][0] == '-') {
133 ap = arv[1];148 ap = arv[1];
134 ap++;149 ap++;
135 if (*ap == 'T')
136 continue;
137 if (*ap == 'D')
138 continue;
139 switch (*ap) {150 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;
167 default:151 default:
168 fprint(2, "%s not allowed as argument\n",152 fprint(2, "%s not allowed as argument\n", ap);
169 ap);
170 exits("usage");153 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;
171 }167 }
172 continue;
173 }168 }
174 if ((fd = Bopen(arv[1], OREAD)) == 0) {169 else if ((bp = Bopen(arv[1], OREAD)) == 0) {
175 perror(arv[1]);170 perror(arv[1]);
176 fprint(2, "Cannot find file %s\n", arv[1]);171 fprint(2, "Cannot find file %s\n", arv[1]);
177 continue;
178 }172 }
179 if(!process(fd))173 else if(process(bp)) Bterm(fsp->fd);
180 break;174 else break;
181 Bclose(fsp->fd);
182 }175 }
183 if (fd == 0){176 if (bp == 0){
184 fd = malloc(sizeof *fd);177 bp = malloc(sizeof *bp);
185 Binit(fd, 0, OREAD);178 Binit(bp, fd, OREAD);
186 process(fd);179 process(bp);
187 }180 }
188 closepl();181 closepl();
182 read(0, "x", 1);
189 exits(0);183 exits(0);
190}184}
191int isalpha(int c)185int isalpha(int c)
@@ -225,7 +219,7 @@ int nextc(void){ · 33 unmodified lines
225 }else219 }else
226 c=Beof;220 c=Beof;
227 if(c!=Beof || fsp==fstack) break;221 if(c!=Beof || fsp==fstack) break;
228 if(fsp->fd) Bclose(fsp->fd);222 if(fsp->fd) Bterm(fsp->fd);
229 --fsp;223 --fsp;
230 }224 }
231 if(c=='\n') fsp->lineno++;225 if(c=='\n') fsp->lineno++;
@@ -599,3 +593,17 @@ void include(char *a){ · 367 unmodified lines
599 fsp->corebuf=0;593 fsp->corebuf=0;
600 fsp->fd=fd;594 fsp->fd=fd;
601}595}
596/*
597 * Doesn't work. Why?
598 */
599int 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}