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