xref: /original-bsd/usr.bin/plot/driver.c (revision 42c7e7a1)
1 /*-
2  * %sccs.include.proprietary.c%
3  */
4 
5 #ifndef lint
6 static char sccsid[] = "@(#)driver.c	4.5 (Berkeley) 04/18/91";
7 #endif /* not lint */
8 
9 #include <stdio.h>
10 
11 float deltx;
12 float delty;
13 int PlotRes;
14 
15 main(argc,argv)
16 	int argc;
17 	char *argv[];
18 {
19 	int std = 1;
20 	char *progname;
21 	FILE *fin;
22 
23 	progname = argv[0];
24 	for (argc--, argv++; argc > 0; argc--, argv++) {
25 		if (argv[0][0] == '-') {
26 			switch (argv[0][1]) {
27 			case 'l':
28 				deltx = atoi(&argv[0][2]) - 1;
29 				break;
30 			case 'w':
31 				delty = atoi(&argv[0][2]) - 1;
32 				break;
33 			case 'r':
34 				PlotRes = atoi(&argv[0][2]);
35 				break;
36 			}
37 			continue;
38 		}
39 		std = 0;
40 		fin = fopen(argv[0], "r");
41 		if (fin == NULL) {
42 			fprintf(stderr, "%s: can't open %s\n", progname,
43 			    argv[0]);
44 			exit(1);
45 		}
46 		fplt(fin);
47 		fclose(fin);
48 	}
49 	if (std)
50 		fplt(stdin);
51 	exit(0);
52 }
53 
54 fplt(fin)
55 	FILE *fin;
56 {
57 	register int c;
58 	char s[256];
59 	int xi,yi,x0,y0,x1,y1,r,dx,n,i;
60 	int pat[256];
61 
62 	openpl();
63 	while((c = getc(fin)) != EOF) {
64 		switch(c) {
65 		case 'm':
66 			xi = getsi(fin);
67 			yi = getsi(fin);
68 			move(xi,yi);
69 			break;
70 		case 'l':
71 			x0 = getsi(fin);
72 			y0 = getsi(fin);
73 			x1 = getsi(fin);
74 			y1 = getsi(fin);
75 			line(x0,y0,x1,y1);
76 			break;
77 		case 't':
78 			getstr(s,fin);
79 			label(s);
80 			break;
81 		case 'e':
82 			erase();
83 			break;
84 		case 'p':
85 			xi = getsi(fin);
86 			yi = getsi(fin);
87 			point(xi,yi);
88 			break;
89 		case 'n':
90 			xi = getsi(fin);
91 			yi = getsi(fin);
92 			cont(xi,yi);
93 			break;
94 		case 's':
95 			x0 = getsi(fin);
96 			y0 = getsi(fin);
97 			x1 = getsi(fin);
98 			y1 = getsi(fin);
99 			space(x0,y0,x1,y1);
100 			break;
101 		case 'a':
102 			xi = getsi(fin);
103 			yi = getsi(fin);
104 			x0 = getsi(fin);
105 			y0 = getsi(fin);
106 			x1 = getsi(fin);
107 			y1 = getsi(fin);
108 			arc(xi,yi,x0,y0,x1,y1);
109 			break;
110 		case 'c':
111 			xi = getsi(fin);
112 			yi = getsi(fin);
113 			r = getsi(fin);
114 			circle(xi,yi,r);
115 			break;
116 		case 'f':
117 			getstr(s,fin);
118 			linemod(s);
119 			break;
120 		case 'd':
121 			xi = getsi(fin);
122 			yi = getsi(fin);
123 			dx = getsi(fin);
124 			n = getsi(fin);
125 			for(i=0; i<n; i++)
126 				pat[i] = getsi(fin);
127 			dot(xi,yi,dx,n,pat);
128 			break;
129 		}
130 	}
131 	closepl();
132 }
133 
134 /* get an integer stored in 2 ascii bytes. */
135 getsi(fin)
136 	register FILE *fin;
137 {
138 	short a, b;
139 
140 	if((b = getc(fin)) == EOF)
141 		return(EOF);
142 	if((a = getc(fin)) == EOF)
143 		return(EOF);
144 	a = a<<8;
145 	return(a|b);
146 }
147 
148 getstr(s, fin)
149 	register char *s;
150 	register FILE *fin;
151 {
152 
153 	for( ; *s = getc(fin); s++)
154 		if(*s == '\n')
155 			break;
156 	*s = '\0';
157 }
158