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