1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22
23 /*
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
30
31 #pragma ident "%Z%%M% %I% %E% SMI"
32
33 #include <stdio.h>
34 #include <math.h>
35 #include <errno.h>
36
37 float deltx = 4095.0;
38 float delty = 4095.0;
39
40 static void fplt(FILE *);
41 static int getsi(FILE *);
42 static void getsd(char *, FILE *);
43
44 int
main(int argc,char ** argv)45 main(int argc, char **argv)
46 {
47 int std=1;
48 FILE *fin;
49
50 while(argc-- > 1) {
51 if(*argv[1] == '-')
52 switch(argv[1][1]) {
53 case 'l':
54 deltx = atoi(&argv[1][2]) - 1;
55 break;
56 case 'w':
57 delty = atoi(&argv[1][2]) - 1;
58 break;
59 }
60
61 else {
62 std = 0;
63 if ((fin = fopen(argv[1], "r")) == NULL) {
64 fprintf(stderr, "can't open %s\n", argv[1]);
65 exit(1);
66 }
67 fplt(fin);
68 }
69 argv++;
70 }
71 if (std)
72 fplt( stdin );
73 return (0);
74 }
75
76
77 static void
fplt(FILE * fin)78 fplt(FILE *fin)
79 {
80 int c;
81 char s[256];
82 int xi,yi,x0,y0,x1,y1,r,dx,n,i;
83 int pat[256];
84
85 openpl();
86 while((c=getc(fin)) != EOF){
87 switch(c){
88 case 'm':
89 xi = getsi(fin);
90 yi = getsi(fin);
91 move(xi,yi);
92 break;
93 case 'l':
94 x0 = getsi(fin);
95 y0 = getsi(fin);
96 x1 = getsi(fin);
97 y1 = getsi(fin);
98 line(x0,y0,x1,y1);
99 break;
100 case 't':
101 getsd(s,fin);
102 label(s);
103 break;
104 case 'e':
105 erase();
106 break;
107 case 'p':
108 xi = getsi(fin);
109 yi = getsi(fin);
110 point(xi,yi);
111 break;
112 case 'n':
113 xi = getsi(fin);
114 yi = getsi(fin);
115 cont(xi,yi);
116 break;
117 case 's':
118 x0 = getsi(fin);
119 y0 = getsi(fin);
120 x1 = getsi(fin);
121 y1 = getsi(fin);
122 space(x0,y0,x1,y1);
123 break;
124 case 'a':
125 xi = getsi(fin);
126 yi = getsi(fin);
127 x0 = getsi(fin);
128 y0 = getsi(fin);
129 x1 = getsi(fin);
130 y1 = getsi(fin);
131 arc(xi,yi,x0,y0,x1,y1);
132 break;
133 case 'c':
134 xi = getsi(fin);
135 yi = getsi(fin);
136 r = getsi(fin);
137 circle(xi,yi,r);
138 break;
139 case 'f':
140 getsd(s,fin);
141 linemod(s);
142 break;
143 case 'd':
144 xi = getsi(fin);
145 yi = getsi(fin);
146 dx = getsi(fin);
147 n = getsi(fin);
148 for(i=0; i<n; i++)pat[i] = getsi(fin);
149 dot(xi,yi,dx,n,pat);
150 break;
151 }
152 }
153 closepl();
154 }
155
156 static int
getsi(FILE * fin)157 getsi(FILE *fin)
158 {
159 /* get an integer stored in 2 ascii bytes. */
160 short a, b;
161 if((b = getc(fin)) == EOF)
162 return(EOF);
163 if((a = getc(fin)) == EOF)
164 return(EOF);
165 a = a<<8;
166 return(a|b);
167 }
168
169 static void
getsd(char * s,FILE * fin)170 getsd(char *s, FILE *fin)
171 {
172 for( ; *s = getc(fin); s++)
173 if(*s == '\n')
174 break;
175 *s = '\0';
176 }
177
178 int
matherr(struct exception * x)179 matherr(struct exception *x)
180 {
181 if(x->type==DOMAIN)
182 {errno=EDOM;
183 if(!strcmp("log",x->name))x->retval = (-HUGE);
184 else x->retval = 0;
185 return(1);
186 }
187 else if ((x->type)==SING)
188 {errno=EDOM;
189 x->retval = (-HUGE);
190 return(1);
191 }
192 else return(0);
193 }
194