1 |
greg |
1.1 |
#ifndef lint |
2 |
schorsch |
1.28 |
static const char RCSid[] = "$Id: parser.c,v 1.27 2003/02/28 20:11:29 greg Exp $"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Parse an MGF file, converting or discarding unsupported entities |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
#include <stdio.h> |
9 |
greg |
1.27 |
#include <stdlib.h> |
10 |
greg |
1.1 |
#include <math.h> |
11 |
|
|
#include <ctype.h> |
12 |
|
|
#include <string.h> |
13 |
|
|
#include "parser.h" |
14 |
|
|
#include "lookup.h" |
15 |
|
|
#include "messages.h" |
16 |
|
|
|
17 |
|
|
/* |
18 |
|
|
* Global definitions of variables declared in parser.h |
19 |
|
|
*/ |
20 |
|
|
/* entity names */ |
21 |
|
|
|
22 |
|
|
char mg_ename[MG_NENTITIES][MG_MAXELEN] = MG_NAMELIST; |
23 |
|
|
|
24 |
|
|
/* Handler routines for each entity */ |
25 |
|
|
|
26 |
|
|
int (*mg_ehand[MG_NENTITIES])(); |
27 |
|
|
|
28 |
greg |
1.18 |
/* Handler routine for unknown entities */ |
29 |
|
|
|
30 |
|
|
int (*mg_uhand)() = mg_defuhand; |
31 |
|
|
|
32 |
|
|
unsigned mg_nunknown; /* count of unknown entities */ |
33 |
|
|
|
34 |
greg |
1.1 |
/* error messages */ |
35 |
|
|
|
36 |
|
|
char *mg_err[MG_NERRS] = MG_ERRLIST; |
37 |
|
|
|
38 |
|
|
MG_FCTXT *mg_file; /* current file context pointer */ |
39 |
|
|
|
40 |
|
|
int mg_nqcdivs = MG_NQCD; /* number of divisions per quarter circle */ |
41 |
|
|
|
42 |
|
|
/* |
43 |
|
|
* The idea with this parser is to compensate for any missing entries in |
44 |
|
|
* mg_ehand with alternate handlers that express these entities in terms |
45 |
|
|
* of others that the calling program can handle. |
46 |
|
|
* |
47 |
|
|
* In some cases, no alternate handler is possible because the entity |
48 |
|
|
* has no approximate equivalent. These entities are simply discarded. |
49 |
|
|
* |
50 |
|
|
* Certain entities are dependent on others, and mg_init() will fail |
51 |
|
|
* if the supported entities are not consistent. |
52 |
|
|
* |
53 |
|
|
* Some alternate entity handlers require that earlier entities be |
54 |
|
|
* noted in some fashion, and we therefore keep another array of |
55 |
|
|
* parallel support handlers to assist in this effort. |
56 |
|
|
*/ |
57 |
|
|
|
58 |
|
|
/* temporary settings for testing */ |
59 |
|
|
#define e_ies e_any_toss |
60 |
|
|
/* alternate handler routines */ |
61 |
|
|
|
62 |
schorsch |
1.28 |
static void make_axes(FVECT u, FVECT v, FVECT w); |
63 |
|
|
static int put_cxy(void); |
64 |
|
|
static int put_cspec(void); |
65 |
|
|
|
66 |
|
|
static int e_any_toss(int ac, char **av); /* discard an unwanted entity */ |
67 |
|
|
static int e_cspec(int ac, char **av); /* handle spectral color */ |
68 |
|
|
static int e_cmix(int ac, char **av); /* handle mixing of colors */ |
69 |
|
|
static int e_cct(int ac, char **av); /* handle color temperature */ |
70 |
|
|
|
71 |
greg |
1.23 |
|
72 |
greg |
1.1 |
/* alternate handler support functions */ |
73 |
|
|
|
74 |
schorsch |
1.28 |
static int (*e_supp[MG_NENTITIES])(int ac, char **av); |
75 |
greg |
1.1 |
|
76 |
|
|
static char FLTFMT[] = "%.12g"; |
77 |
|
|
|
78 |
|
|
static int warpconends; /* hack for generating good normals */ |
79 |
|
|
|
80 |
|
|
|
81 |
|
|
void |
82 |
schorsch |
1.28 |
mg_init(void) /* initialize alternate entity handlers */ |
83 |
greg |
1.1 |
{ |
84 |
|
|
unsigned long ineed = 0, uneed = 0; |
85 |
|
|
register int i; |
86 |
|
|
/* pick up slack */ |
87 |
|
|
if (mg_ehand[MG_E_IES] == NULL) |
88 |
|
|
mg_ehand[MG_E_IES] = e_ies; |
89 |
|
|
if (mg_ehand[MG_E_INCLUDE] == NULL) |
90 |
|
|
mg_ehand[MG_E_INCLUDE] = e_include; |
91 |
|
|
if (mg_ehand[MG_E_SPH] == NULL) { |
92 |
|
|
mg_ehand[MG_E_SPH] = e_sph; |
93 |
greg |
1.17 |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
94 |
greg |
1.1 |
} else |
95 |
greg |
1.17 |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
96 |
greg |
1.1 |
if (mg_ehand[MG_E_CYL] == NULL) { |
97 |
|
|
mg_ehand[MG_E_CYL] = e_cyl; |
98 |
greg |
1.17 |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
99 |
greg |
1.1 |
} else |
100 |
greg |
1.17 |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
101 |
greg |
1.1 |
if (mg_ehand[MG_E_CONE] == NULL) { |
102 |
|
|
mg_ehand[MG_E_CONE] = e_cone; |
103 |
greg |
1.17 |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
104 |
greg |
1.1 |
} else |
105 |
greg |
1.17 |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
106 |
greg |
1.1 |
if (mg_ehand[MG_E_RING] == NULL) { |
107 |
|
|
mg_ehand[MG_E_RING] = e_ring; |
108 |
greg |
1.17 |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX; |
109 |
greg |
1.1 |
} else |
110 |
greg |
1.17 |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
111 |
greg |
1.4 |
if (mg_ehand[MG_E_PRISM] == NULL) { |
112 |
|
|
mg_ehand[MG_E_PRISM] = e_prism; |
113 |
greg |
1.17 |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
114 |
greg |
1.4 |
} else |
115 |
greg |
1.17 |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
116 |
greg |
1.1 |
if (mg_ehand[MG_E_TORUS] == NULL) { |
117 |
|
|
mg_ehand[MG_E_TORUS] = e_torus; |
118 |
greg |
1.17 |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX; |
119 |
greg |
1.1 |
} else |
120 |
greg |
1.17 |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
121 |
greg |
1.24 |
if (mg_ehand[MG_E_FACE] == NULL) |
122 |
|
|
mg_ehand[MG_E_FACE] = mg_ehand[MG_E_FACEH]; |
123 |
|
|
else if (mg_ehand[MG_E_FACEH] == NULL) |
124 |
|
|
mg_ehand[MG_E_FACEH] = e_faceh; |
125 |
greg |
1.4 |
if (mg_ehand[MG_E_COLOR] != NULL) { |
126 |
greg |
1.6 |
if (mg_ehand[MG_E_CMIX] == NULL) { |
127 |
greg |
1.4 |
mg_ehand[MG_E_CMIX] = e_cmix; |
128 |
greg |
1.17 |
ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT; |
129 |
greg |
1.6 |
} |
130 |
|
|
if (mg_ehand[MG_E_CSPEC] == NULL) { |
131 |
greg |
1.4 |
mg_ehand[MG_E_CSPEC] = e_cspec; |
132 |
greg |
1.17 |
ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT; |
133 |
greg |
1.6 |
} |
134 |
greg |
1.13 |
if (mg_ehand[MG_E_CCT] == NULL) { |
135 |
|
|
mg_ehand[MG_E_CCT] = e_cct; |
136 |
greg |
1.17 |
ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT; |
137 |
greg |
1.13 |
} |
138 |
greg |
1.4 |
} |
139 |
greg |
1.1 |
/* check for consistency */ |
140 |
|
|
if (mg_ehand[MG_E_FACE] != NULL) |
141 |
greg |
1.17 |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
142 |
greg |
1.6 |
if (mg_ehand[MG_E_CXY] != NULL || mg_ehand[MG_E_CSPEC] != NULL || |
143 |
|
|
mg_ehand[MG_E_CMIX] != NULL) |
144 |
greg |
1.17 |
uneed |= 1L<<MG_E_COLOR; |
145 |
greg |
1.1 |
if (mg_ehand[MG_E_RD] != NULL || mg_ehand[MG_E_TD] != NULL || |
146 |
greg |
1.15 |
mg_ehand[MG_E_IR] != NULL || |
147 |
greg |
1.1 |
mg_ehand[MG_E_ED] != NULL || |
148 |
|
|
mg_ehand[MG_E_RS] != NULL || |
149 |
greg |
1.11 |
mg_ehand[MG_E_TS] != NULL || |
150 |
|
|
mg_ehand[MG_E_SIDES] != NULL) |
151 |
greg |
1.17 |
uneed |= 1L<<MG_E_MATERIAL; |
152 |
greg |
1.1 |
for (i = 0; i < MG_NENTITIES; i++) |
153 |
greg |
1.17 |
if (uneed & 1L<<i && mg_ehand[i] == NULL) { |
154 |
greg |
1.1 |
fprintf(stderr, "Missing support for \"%s\" entity\n", |
155 |
|
|
mg_ename[i]); |
156 |
|
|
exit(1); |
157 |
|
|
} |
158 |
|
|
/* add support as needed */ |
159 |
greg |
1.17 |
if (ineed & 1L<<MG_E_VERTEX && mg_ehand[MG_E_VERTEX] != c_hvertex) |
160 |
greg |
1.1 |
e_supp[MG_E_VERTEX] = c_hvertex; |
161 |
greg |
1.17 |
if (ineed & 1L<<MG_E_POINT && mg_ehand[MG_E_POINT] != c_hvertex) |
162 |
greg |
1.1 |
e_supp[MG_E_POINT] = c_hvertex; |
163 |
greg |
1.17 |
if (ineed & 1L<<MG_E_NORMAL && mg_ehand[MG_E_NORMAL] != c_hvertex) |
164 |
greg |
1.1 |
e_supp[MG_E_NORMAL] = c_hvertex; |
165 |
greg |
1.17 |
if (ineed & 1L<<MG_E_COLOR && mg_ehand[MG_E_COLOR] != c_hcolor) |
166 |
greg |
1.6 |
e_supp[MG_E_COLOR] = c_hcolor; |
167 |
greg |
1.17 |
if (ineed & 1L<<MG_E_CXY && mg_ehand[MG_E_CXY] != c_hcolor) |
168 |
greg |
1.6 |
e_supp[MG_E_CXY] = c_hcolor; |
169 |
greg |
1.17 |
if (ineed & 1L<<MG_E_CSPEC && mg_ehand[MG_E_CSPEC] != c_hcolor) |
170 |
greg |
1.6 |
e_supp[MG_E_CSPEC] = c_hcolor; |
171 |
greg |
1.17 |
if (ineed & 1L<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor) |
172 |
greg |
1.6 |
e_supp[MG_E_CMIX] = c_hcolor; |
173 |
greg |
1.17 |
if (ineed & 1L<<MG_E_CCT && mg_ehand[MG_E_CCT] != c_hcolor) |
174 |
greg |
1.13 |
e_supp[MG_E_CCT] = c_hcolor; |
175 |
greg |
1.1 |
/* discard remaining entities */ |
176 |
|
|
for (i = 0; i < MG_NENTITIES; i++) |
177 |
|
|
if (mg_ehand[i] == NULL) |
178 |
|
|
mg_ehand[i] = e_any_toss; |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
|
182 |
|
|
int |
183 |
schorsch |
1.28 |
mg_entity( /* get entity number from its name */ |
184 |
|
|
char *name |
185 |
|
|
) |
186 |
greg |
1.1 |
{ |
187 |
greg |
1.9 |
static LUTAB ent_tab = LU_SINIT(NULL,NULL); /* lookup table */ |
188 |
greg |
1.1 |
register char *cp; |
189 |
|
|
|
190 |
|
|
if (!ent_tab.tsiz) { /* initialize hash table */ |
191 |
|
|
if (!lu_init(&ent_tab, MG_NENTITIES)) |
192 |
|
|
return(-1); /* what to do? */ |
193 |
|
|
for (cp = mg_ename[MG_NENTITIES-1]; cp >= mg_ename[0]; |
194 |
|
|
cp -= sizeof(mg_ename[0])) |
195 |
|
|
lu_find(&ent_tab, cp)->key = cp; |
196 |
|
|
} |
197 |
|
|
cp = lu_find(&ent_tab, name)->key; |
198 |
|
|
if (cp == NULL) |
199 |
|
|
return(-1); |
200 |
|
|
return((cp - mg_ename[0])/sizeof(mg_ename[0])); |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
|
204 |
greg |
1.10 |
int |
205 |
schorsch |
1.28 |
mg_handle( /* pass entity to appropriate handler */ |
206 |
|
|
register int en, |
207 |
|
|
int ac, |
208 |
|
|
char **av |
209 |
|
|
) |
210 |
greg |
1.1 |
{ |
211 |
|
|
int rv; |
212 |
|
|
|
213 |
greg |
1.18 |
if (en < 0 && (en = mg_entity(av[0])) < 0) { /* unknown entity */ |
214 |
|
|
if (mg_uhand != NULL) |
215 |
|
|
return((*mg_uhand)(ac, av)); |
216 |
greg |
1.1 |
return(MG_EUNK); |
217 |
greg |
1.18 |
} |
218 |
|
|
if (e_supp[en] != NULL) { /* support handler */ |
219 |
greg |
1.1 |
if ((rv = (*e_supp[en])(ac, av)) != MG_OK) |
220 |
|
|
return(rv); |
221 |
|
|
} |
222 |
greg |
1.18 |
return((*mg_ehand[en])(ac, av)); /* assigned handler */ |
223 |
greg |
1.1 |
} |
224 |
|
|
|
225 |
|
|
|
226 |
|
|
int |
227 |
schorsch |
1.28 |
mg_open( /* open new input file */ |
228 |
|
|
register MG_FCTXT *ctx, |
229 |
|
|
char *fn |
230 |
|
|
) |
231 |
greg |
1.1 |
{ |
232 |
greg |
1.10 |
static int nfids; |
233 |
greg |
1.1 |
register char *cp; |
234 |
|
|
|
235 |
greg |
1.10 |
ctx->fid = ++nfids; |
236 |
greg |
1.1 |
ctx->lineno = 0; |
237 |
|
|
if (fn == NULL) { |
238 |
greg |
1.8 |
strcpy(ctx->fname, "<stdin>"); |
239 |
greg |
1.1 |
ctx->fp = stdin; |
240 |
|
|
ctx->prev = mg_file; |
241 |
|
|
mg_file = ctx; |
242 |
|
|
return(MG_OK); |
243 |
|
|
} |
244 |
|
|
/* get name relative to this context */ |
245 |
greg |
1.27 |
if (fn[0] != '/' && mg_file != NULL && |
246 |
|
|
(cp = strrchr(mg_file->fname, '/')) != NULL) { |
247 |
greg |
1.1 |
strcpy(ctx->fname, mg_file->fname); |
248 |
greg |
1.16 |
strcpy(ctx->fname+(cp-mg_file->fname+1), fn); |
249 |
|
|
} else |
250 |
|
|
strcpy(ctx->fname, fn); |
251 |
greg |
1.1 |
ctx->fp = fopen(ctx->fname, "r"); |
252 |
greg |
1.8 |
if (ctx->fp == NULL) |
253 |
greg |
1.1 |
return(MG_ENOFILE); |
254 |
|
|
ctx->prev = mg_file; /* establish new context */ |
255 |
|
|
mg_file = ctx; |
256 |
|
|
return(MG_OK); |
257 |
|
|
} |
258 |
|
|
|
259 |
|
|
|
260 |
|
|
void |
261 |
schorsch |
1.28 |
mg_close(void) /* close input file */ |
262 |
greg |
1.1 |
{ |
263 |
|
|
register MG_FCTXT *ctx = mg_file; |
264 |
|
|
|
265 |
|
|
mg_file = ctx->prev; /* restore enclosing context */ |
266 |
greg |
1.23 |
if (ctx->fp != stdin) /* close file if it's a file */ |
267 |
|
|
fclose(ctx->fp); |
268 |
greg |
1.1 |
} |
269 |
|
|
|
270 |
|
|
|
271 |
greg |
1.10 |
void |
272 |
schorsch |
1.28 |
mg_fgetpos( /* get current position in input file */ |
273 |
|
|
register MG_FPOS *pos |
274 |
|
|
) |
275 |
greg |
1.10 |
{ |
276 |
|
|
pos->fid = mg_file->fid; |
277 |
|
|
pos->lineno = mg_file->lineno; |
278 |
|
|
pos->offset = ftell(mg_file->fp); |
279 |
|
|
} |
280 |
|
|
|
281 |
|
|
|
282 |
greg |
1.1 |
int |
283 |
schorsch |
1.28 |
mg_fgoto( /* reposition input file pointer */ |
284 |
|
|
register MG_FPOS *pos |
285 |
|
|
) |
286 |
greg |
1.1 |
{ |
287 |
greg |
1.10 |
if (pos->fid != mg_file->fid) |
288 |
|
|
return(MG_ESEEK); |
289 |
|
|
if (pos->lineno == mg_file->lineno) |
290 |
greg |
1.1 |
return(MG_OK); |
291 |
|
|
if (mg_file->fp == stdin) |
292 |
|
|
return(MG_ESEEK); /* cannot seek on standard input */ |
293 |
greg |
1.10 |
if (fseek(mg_file->fp, pos->offset, 0) == EOF) |
294 |
greg |
1.1 |
return(MG_ESEEK); |
295 |
greg |
1.10 |
mg_file->lineno = pos->lineno; |
296 |
greg |
1.1 |
return(MG_OK); |
297 |
|
|
} |
298 |
|
|
|
299 |
|
|
|
300 |
|
|
int |
301 |
schorsch |
1.28 |
mg_read(void) /* read next line from file */ |
302 |
greg |
1.1 |
{ |
303 |
|
|
register int len = 0; |
304 |
|
|
|
305 |
|
|
do { |
306 |
|
|
if (fgets(mg_file->inpline+len, |
307 |
|
|
MG_MAXLINE-len, mg_file->fp) == NULL) |
308 |
|
|
return(len); |
309 |
greg |
1.22 |
len += strlen(mg_file->inpline+len); |
310 |
|
|
if (len >= MG_MAXLINE-1) |
311 |
|
|
return(len); |
312 |
greg |
1.1 |
mg_file->lineno++; |
313 |
greg |
1.22 |
} while (len > 1 && mg_file->inpline[len-2] == '\\'); |
314 |
greg |
1.1 |
|
315 |
|
|
return(len); |
316 |
|
|
} |
317 |
|
|
|
318 |
|
|
|
319 |
|
|
int |
320 |
schorsch |
1.28 |
mg_parse(void) /* parse current input line */ |
321 |
greg |
1.1 |
{ |
322 |
|
|
char abuf[MG_MAXLINE]; |
323 |
|
|
char *argv[MG_MAXARGC]; |
324 |
greg |
1.22 |
register char *cp, *cp2, **ap; |
325 |
|
|
/* copy line, removing escape chars */ |
326 |
|
|
cp = abuf; cp2 = mg_file->inpline; |
327 |
|
|
while ((*cp++ = *cp2++)) |
328 |
|
|
if (cp2[0] == '\n' && cp2[-1] == '\\') |
329 |
|
|
cp--; |
330 |
|
|
cp = abuf; ap = argv; /* break into words */ |
331 |
greg |
1.1 |
for ( ; ; ) { |
332 |
|
|
while (isspace(*cp)) |
333 |
|
|
*cp++ = '\0'; |
334 |
|
|
if (!*cp) |
335 |
|
|
break; |
336 |
|
|
if (ap - argv >= MG_MAXARGC-1) |
337 |
|
|
return(MG_EARGC); |
338 |
|
|
*ap++ = cp; |
339 |
|
|
while (*++cp && !isspace(*cp)) |
340 |
|
|
; |
341 |
|
|
} |
342 |
|
|
if (ap == argv) |
343 |
|
|
return(MG_OK); /* no words in line */ |
344 |
|
|
*ap = NULL; |
345 |
|
|
/* else handle it */ |
346 |
greg |
1.10 |
return(mg_handle(-1, ap-argv, argv)); |
347 |
greg |
1.1 |
} |
348 |
|
|
|
349 |
|
|
|
350 |
|
|
int |
351 |
schorsch |
1.28 |
mg_load( /* load an MGF file */ |
352 |
|
|
char *fn |
353 |
|
|
) |
354 |
greg |
1.1 |
{ |
355 |
|
|
MG_FCTXT cntxt; |
356 |
greg |
1.21 |
int rval; |
357 |
|
|
register int nbr; |
358 |
greg |
1.1 |
|
359 |
|
|
if ((rval = mg_open(&cntxt, fn)) != MG_OK) { |
360 |
greg |
1.2 |
fprintf(stderr, "%s: %s\n", fn, mg_err[rval]); |
361 |
greg |
1.1 |
return(rval); |
362 |
|
|
} |
363 |
greg |
1.21 |
while ((nbr = mg_read()) > 0) { /* parse each line */ |
364 |
greg |
1.22 |
if (nbr >= MG_MAXLINE-1) { |
365 |
greg |
1.20 |
fprintf(stderr, "%s: %d: %s\n", cntxt.fname, |
366 |
|
|
cntxt.lineno, mg_err[rval=MG_ELINE]); |
367 |
|
|
break; |
368 |
|
|
} |
369 |
greg |
1.1 |
if ((rval = mg_parse()) != MG_OK) { |
370 |
|
|
fprintf(stderr, "%s: %d: %s:\n%s", cntxt.fname, |
371 |
|
|
cntxt.lineno, mg_err[rval], |
372 |
|
|
cntxt.inpline); |
373 |
|
|
break; |
374 |
|
|
} |
375 |
greg |
1.20 |
} |
376 |
greg |
1.1 |
mg_close(); |
377 |
|
|
return(rval); |
378 |
greg |
1.18 |
} |
379 |
|
|
|
380 |
|
|
|
381 |
|
|
int |
382 |
schorsch |
1.28 |
mg_defuhand( /* default handler for unknown entities */ |
383 |
|
|
int ac, |
384 |
|
|
char **av |
385 |
|
|
) |
386 |
greg |
1.18 |
{ |
387 |
|
|
if (mg_nunknown++ == 0) /* report first incident */ |
388 |
|
|
fprintf(stderr, "%s: %d: %s: %s\n", mg_file->fname, |
389 |
|
|
mg_file->lineno, mg_err[MG_EUNK], av[0]); |
390 |
|
|
return(MG_OK); |
391 |
greg |
1.1 |
} |
392 |
|
|
|
393 |
|
|
|
394 |
|
|
void |
395 |
schorsch |
1.28 |
mg_clear(void) /* clear parser history */ |
396 |
greg |
1.1 |
{ |
397 |
|
|
c_clearall(); /* clear context tables */ |
398 |
greg |
1.23 |
while (mg_file != NULL) /* reset our file context */ |
399 |
|
|
mg_close(); |
400 |
greg |
1.1 |
} |
401 |
|
|
|
402 |
|
|
|
403 |
|
|
/**************************************************************************** |
404 |
|
|
* The following routines handle unsupported entities |
405 |
|
|
*/ |
406 |
|
|
|
407 |
|
|
|
408 |
|
|
static int |
409 |
schorsch |
1.28 |
e_any_toss( /* discard an unwanted entity */ |
410 |
|
|
int ac, |
411 |
|
|
char **av |
412 |
|
|
) |
413 |
greg |
1.1 |
{ |
414 |
|
|
return(MG_OK); |
415 |
|
|
} |
416 |
|
|
|
417 |
|
|
|
418 |
greg |
1.23 |
int |
419 |
schorsch |
1.28 |
e_include( /* include file */ |
420 |
|
|
int ac, |
421 |
|
|
char **av |
422 |
|
|
) |
423 |
greg |
1.1 |
{ |
424 |
greg |
1.10 |
char *xfarg[MG_MAXARGC]; |
425 |
greg |
1.1 |
MG_FCTXT ictx; |
426 |
greg |
1.16 |
XF_SPEC *xf_orig = xf_context; |
427 |
greg |
1.20 |
register int rv; |
428 |
greg |
1.1 |
|
429 |
|
|
if (ac < 2) |
430 |
|
|
return(MG_EARGC); |
431 |
|
|
if ((rv = mg_open(&ictx, av[1])) != MG_OK) |
432 |
|
|
return(rv); |
433 |
greg |
1.10 |
if (ac > 2) { |
434 |
|
|
register int i; |
435 |
|
|
|
436 |
|
|
xfarg[0] = mg_ename[MG_E_XF]; |
437 |
|
|
for (i = 1; i < ac-1; i++) |
438 |
|
|
xfarg[i] = av[i+1]; |
439 |
|
|
xfarg[ac-1] = NULL; |
440 |
greg |
1.21 |
if ((rv = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK) { |
441 |
|
|
mg_close(); |
442 |
greg |
1.10 |
return(rv); |
443 |
greg |
1.21 |
} |
444 |
greg |
1.1 |
} |
445 |
greg |
1.16 |
do { |
446 |
greg |
1.20 |
while ((rv = mg_read()) > 0) { |
447 |
greg |
1.22 |
if (rv >= MG_MAXLINE-1) { |
448 |
greg |
1.20 |
fprintf(stderr, "%s: %d: %s\n", ictx.fname, |
449 |
|
|
ictx.lineno, mg_err[MG_ELINE]); |
450 |
|
|
mg_close(); |
451 |
|
|
return(MG_EINCL); |
452 |
|
|
} |
453 |
greg |
1.10 |
if ((rv = mg_parse()) != MG_OK) { |
454 |
|
|
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
455 |
|
|
ictx.lineno, mg_err[rv], |
456 |
|
|
ictx.inpline); |
457 |
|
|
mg_close(); |
458 |
|
|
return(MG_EINCL); |
459 |
|
|
} |
460 |
greg |
1.20 |
} |
461 |
greg |
1.10 |
if (ac > 2) |
462 |
greg |
1.21 |
if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK) { |
463 |
|
|
mg_close(); |
464 |
greg |
1.10 |
return(rv); |
465 |
greg |
1.21 |
} |
466 |
greg |
1.16 |
} while (xf_context != xf_orig); |
467 |
greg |
1.1 |
mg_close(); |
468 |
|
|
return(MG_OK); |
469 |
greg |
1.24 |
} |
470 |
|
|
|
471 |
|
|
|
472 |
|
|
int |
473 |
schorsch |
1.28 |
e_faceh( /* replace face+holes with single contour */ |
474 |
|
|
int ac, |
475 |
|
|
char **av |
476 |
|
|
) |
477 |
greg |
1.24 |
{ |
478 |
|
|
char *newav[MG_MAXARGC]; |
479 |
|
|
int lastp = 0; |
480 |
|
|
register int i, j; |
481 |
|
|
|
482 |
|
|
newav[0] = mg_ename[MG_E_FACE]; |
483 |
|
|
for (i = 1; i < ac; i++) |
484 |
|
|
if (av[i][0] == '-') { |
485 |
|
|
if (i < 4) |
486 |
|
|
return(MG_EARGC); |
487 |
|
|
if (i >= ac-1) |
488 |
|
|
break; |
489 |
|
|
if (!lastp) |
490 |
|
|
lastp = i-1; |
491 |
|
|
for (j = i+1; j < ac-1 && av[j+1][0] != '-'; j++) |
492 |
|
|
; |
493 |
|
|
if (j - i < 3) |
494 |
|
|
return(MG_EARGC); |
495 |
|
|
newav[i] = av[j]; /* connect hole loop */ |
496 |
|
|
} else |
497 |
|
|
newav[i] = av[i]; /* hole or perimeter vertex */ |
498 |
|
|
if (lastp) |
499 |
|
|
newav[i++] = av[lastp]; /* finish seam to outside */ |
500 |
|
|
newav[i] = NULL; |
501 |
|
|
return(mg_handle(MG_E_FACE, i, newav)); |
502 |
greg |
1.1 |
} |
503 |
|
|
|
504 |
|
|
|
505 |
|
|
static void |
506 |
schorsch |
1.28 |
make_axes( /* compute u and v given w (normalized) */ |
507 |
|
|
FVECT u, |
508 |
|
|
FVECT v, |
509 |
|
|
FVECT w |
510 |
|
|
) |
511 |
greg |
1.1 |
{ |
512 |
|
|
register int i; |
513 |
|
|
|
514 |
|
|
v[0] = v[1] = v[2] = 0.; |
515 |
|
|
for (i = 0; i < 3; i++) |
516 |
|
|
if (w[i] < .6 && w[i] > -.6) |
517 |
|
|
break; |
518 |
|
|
v[i] = 1.; |
519 |
|
|
fcross(u, v, w); |
520 |
|
|
normalize(u); |
521 |
|
|
fcross(v, w, u); |
522 |
|
|
} |
523 |
|
|
|
524 |
|
|
|
525 |
greg |
1.23 |
int |
526 |
schorsch |
1.28 |
e_sph( /* expand a sphere into cones */ |
527 |
|
|
int ac, |
528 |
|
|
char **av |
529 |
|
|
) |
530 |
greg |
1.1 |
{ |
531 |
|
|
static char p2x[24], p2y[24], p2z[24], r1[24], r2[24]; |
532 |
|
|
static char *v1ent[5] = {mg_ename[MG_E_VERTEX],"_sv1","=","_sv2"}; |
533 |
|
|
static char *v2ent[4] = {mg_ename[MG_E_VERTEX],"_sv2","="}; |
534 |
|
|
static char *p2ent[5] = {mg_ename[MG_E_POINT],p2x,p2y,p2z}; |
535 |
|
|
static char *conent[6] = {mg_ename[MG_E_CONE],"_sv1",r1,"_sv2",r2}; |
536 |
|
|
register C_VERTEX *cv; |
537 |
|
|
register int i; |
538 |
|
|
int rval; |
539 |
|
|
double rad; |
540 |
|
|
double theta; |
541 |
|
|
|
542 |
|
|
if (ac != 3) |
543 |
|
|
return(MG_EARGC); |
544 |
|
|
if ((cv = c_getvert(av[1])) == NULL) |
545 |
|
|
return(MG_EUNDEF); |
546 |
|
|
if (!isflt(av[2])) |
547 |
|
|
return(MG_ETYPE); |
548 |
|
|
rad = atof(av[2]); |
549 |
|
|
/* initialize */ |
550 |
|
|
warpconends = 1; |
551 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_VERTEX, 3, v2ent)) != MG_OK) |
552 |
greg |
1.1 |
return(rval); |
553 |
|
|
sprintf(p2x, FLTFMT, cv->p[0]); |
554 |
|
|
sprintf(p2y, FLTFMT, cv->p[1]); |
555 |
|
|
sprintf(p2z, FLTFMT, cv->p[2]+rad); |
556 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
557 |
greg |
1.1 |
return(rval); |
558 |
|
|
r2[0] = '0'; r2[1] = '\0'; |
559 |
|
|
for (i = 1; i <= 2*mg_nqcdivs; i++) { |
560 |
|
|
theta = i*(PI/2)/mg_nqcdivs; |
561 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
562 |
greg |
1.1 |
return(rval); |
563 |
|
|
sprintf(p2z, FLTFMT, cv->p[2]+rad*cos(theta)); |
564 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
565 |
greg |
1.1 |
return(rval); |
566 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
567 |
greg |
1.1 |
return(rval); |
568 |
|
|
strcpy(r1, r2); |
569 |
|
|
sprintf(r2, FLTFMT, rad*sin(theta)); |
570 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
571 |
greg |
1.1 |
return(rval); |
572 |
|
|
} |
573 |
|
|
warpconends = 0; |
574 |
|
|
return(MG_OK); |
575 |
|
|
} |
576 |
|
|
|
577 |
|
|
|
578 |
greg |
1.23 |
int |
579 |
schorsch |
1.28 |
e_torus( /* expand a torus into cones */ |
580 |
|
|
int ac, |
581 |
|
|
char **av |
582 |
|
|
) |
583 |
greg |
1.1 |
{ |
584 |
|
|
static char p2[3][24], r1[24], r2[24]; |
585 |
|
|
static char *v1ent[5] = {mg_ename[MG_E_VERTEX],"_tv1","=","_tv2"}; |
586 |
|
|
static char *v2ent[5] = {mg_ename[MG_E_VERTEX],"_tv2","="}; |
587 |
|
|
static char *p2ent[5] = {mg_ename[MG_E_POINT],p2[0],p2[1],p2[2]}; |
588 |
|
|
static char *conent[6] = {mg_ename[MG_E_CONE],"_tv1",r1,"_tv2",r2}; |
589 |
|
|
register C_VERTEX *cv; |
590 |
|
|
register int i, j; |
591 |
|
|
int rval; |
592 |
|
|
int sgn; |
593 |
|
|
double minrad, maxrad, avgrad; |
594 |
|
|
double theta; |
595 |
|
|
|
596 |
|
|
if (ac != 4) |
597 |
|
|
return(MG_EARGC); |
598 |
|
|
if ((cv = c_getvert(av[1])) == NULL) |
599 |
|
|
return(MG_EUNDEF); |
600 |
greg |
1.3 |
if (is0vect(cv->n)) |
601 |
greg |
1.1 |
return(MG_EILL); |
602 |
|
|
if (!isflt(av[2]) || !isflt(av[3])) |
603 |
|
|
return(MG_ETYPE); |
604 |
|
|
minrad = atof(av[2]); |
605 |
greg |
1.3 |
round0(minrad); |
606 |
greg |
1.1 |
maxrad = atof(av[3]); |
607 |
|
|
/* check orientation */ |
608 |
|
|
if (minrad > 0.) |
609 |
|
|
sgn = 1; |
610 |
|
|
else if (minrad < 0.) |
611 |
|
|
sgn = -1; |
612 |
|
|
else if (maxrad > 0.) |
613 |
|
|
sgn = 1; |
614 |
|
|
else if (maxrad < 0.) |
615 |
|
|
sgn = -1; |
616 |
|
|
else |
617 |
|
|
return(MG_EILL); |
618 |
|
|
if (sgn*(maxrad-minrad) <= 0.) |
619 |
|
|
return(MG_EILL); |
620 |
|
|
/* initialize */ |
621 |
|
|
warpconends = 1; |
622 |
|
|
v2ent[3] = av[1]; |
623 |
|
|
for (j = 0; j < 3; j++) |
624 |
|
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
625 |
|
|
.5*sgn*(maxrad-minrad)*cv->n[j]); |
626 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
627 |
greg |
1.1 |
return(rval); |
628 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
629 |
greg |
1.1 |
return(rval); |
630 |
|
|
sprintf(r2, FLTFMT, avgrad=.5*(minrad+maxrad)); |
631 |
|
|
/* run outer section */ |
632 |
|
|
for (i = 1; i <= 2*mg_nqcdivs; i++) { |
633 |
|
|
theta = i*(PI/2)/mg_nqcdivs; |
634 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
635 |
greg |
1.1 |
return(rval); |
636 |
|
|
for (j = 0; j < 3; j++) |
637 |
|
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
638 |
|
|
.5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); |
639 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
640 |
greg |
1.1 |
return(rval); |
641 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
642 |
greg |
1.1 |
return(rval); |
643 |
|
|
strcpy(r1, r2); |
644 |
|
|
sprintf(r2, FLTFMT, avgrad + .5*(maxrad-minrad)*sin(theta)); |
645 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
646 |
greg |
1.1 |
return(rval); |
647 |
|
|
} |
648 |
|
|
/* run inner section */ |
649 |
|
|
sprintf(r2, FLTFMT, -.5*(minrad+maxrad)); |
650 |
|
|
for ( ; i <= 4*mg_nqcdivs; i++) { |
651 |
|
|
theta = i*(PI/2)/mg_nqcdivs; |
652 |
|
|
for (j = 0; j < 3; j++) |
653 |
|
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
654 |
|
|
.5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); |
655 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
656 |
greg |
1.1 |
return(rval); |
657 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
658 |
greg |
1.1 |
return(rval); |
659 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
660 |
greg |
1.1 |
return(rval); |
661 |
|
|
strcpy(r1, r2); |
662 |
|
|
sprintf(r2, FLTFMT, -avgrad - .5*(maxrad-minrad)*sin(theta)); |
663 |
greg |
1.10 |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
664 |
greg |
1.1 |
return(rval); |
665 |
|
|
} |
666 |
|
|
warpconends = 0; |
667 |
|
|
return(MG_OK); |
668 |
|
|
} |
669 |
|
|
|
670 |
|
|
|
671 |
greg |
1.23 |
int |
672 |
schorsch |
1.28 |
e_cyl( /* replace a cylinder with equivalent cone */ |
673 |
|
|
int ac, |
674 |
|
|
char **av |
675 |
|
|
) |
676 |
greg |
1.1 |
{ |
677 |
|
|
static char *avnew[6] = {mg_ename[MG_E_CONE]}; |
678 |
|
|
|
679 |
|
|
if (ac != 4) |
680 |
|
|
return(MG_EARGC); |
681 |
|
|
avnew[1] = av[1]; |
682 |
|
|
avnew[2] = av[2]; |
683 |
|
|
avnew[3] = av[3]; |
684 |
|
|
avnew[4] = av[2]; |
685 |
greg |
1.10 |
return(mg_handle(MG_E_CONE, 5, avnew)); |
686 |
greg |
1.1 |
} |
687 |
|
|
|
688 |
|
|
|
689 |
greg |
1.23 |
int |
690 |
schorsch |
1.28 |
e_ring( /* turn a ring into polygons */ |
691 |
|
|
int ac, |
692 |
|
|
char **av |
693 |
|
|
) |
694 |
greg |
1.1 |
{ |
695 |
|
|
static char p3[3][24], p4[3][24]; |
696 |
|
|
static char *nzent[5] = {mg_ename[MG_E_NORMAL],"0","0","0"}; |
697 |
|
|
static char *v1ent[5] = {mg_ename[MG_E_VERTEX],"_rv1","="}; |
698 |
|
|
static char *v2ent[5] = {mg_ename[MG_E_VERTEX],"_rv2","=","_rv3"}; |
699 |
|
|
static char *v3ent[4] = {mg_ename[MG_E_VERTEX],"_rv3","="}; |
700 |
|
|
static char *p3ent[5] = {mg_ename[MG_E_POINT],p3[0],p3[1],p3[2]}; |
701 |
|
|
static char *v4ent[4] = {mg_ename[MG_E_VERTEX],"_rv4","="}; |
702 |
|
|
static char *p4ent[5] = {mg_ename[MG_E_POINT],p4[0],p4[1],p4[2]}; |
703 |
|
|
static char *fent[6] = {mg_ename[MG_E_FACE],"_rv1","_rv2","_rv3","_rv4"}; |
704 |
|
|
register C_VERTEX *cv; |
705 |
|
|
register int i, j; |
706 |
|
|
FVECT u, v; |
707 |
|
|
double minrad, maxrad; |
708 |
|
|
int rv; |
709 |
|
|
double theta, d; |
710 |
|
|
|
711 |
|
|
if (ac != 4) |
712 |
|
|
return(MG_EARGC); |
713 |
|
|
if ((cv = c_getvert(av[1])) == NULL) |
714 |
|
|
return(MG_EUNDEF); |
715 |
greg |
1.3 |
if (is0vect(cv->n)) |
716 |
greg |
1.1 |
return(MG_EILL); |
717 |
|
|
if (!isflt(av[2]) || !isflt(av[3])) |
718 |
|
|
return(MG_ETYPE); |
719 |
|
|
minrad = atof(av[2]); |
720 |
greg |
1.3 |
round0(minrad); |
721 |
greg |
1.1 |
maxrad = atof(av[3]); |
722 |
|
|
if (minrad < 0. || maxrad <= minrad) |
723 |
|
|
return(MG_EILL); |
724 |
|
|
/* initialize */ |
725 |
|
|
make_axes(u, v, cv->n); |
726 |
|
|
for (j = 0; j < 3; j++) |
727 |
|
|
sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*u[j]); |
728 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
729 |
greg |
1.1 |
return(rv); |
730 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
731 |
greg |
1.1 |
return(rv); |
732 |
|
|
if (minrad == 0.) { /* closed */ |
733 |
|
|
v1ent[3] = av[1]; |
734 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
735 |
greg |
1.1 |
return(rv); |
736 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_NORMAL, 4, nzent)) != MG_OK) |
737 |
greg |
1.1 |
return(rv); |
738 |
|
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
739 |
|
|
theta = i*(PI/2)/mg_nqcdivs; |
740 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
741 |
greg |
1.1 |
return(rv); |
742 |
|
|
for (j = 0; j < 3; j++) |
743 |
|
|
sprintf(p3[j], FLTFMT, cv->p[j] + |
744 |
|
|
maxrad*u[j]*cos(theta) + |
745 |
|
|
maxrad*v[j]*sin(theta)); |
746 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
747 |
greg |
1.1 |
return(rv); |
748 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
749 |
greg |
1.1 |
return(rv); |
750 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK) |
751 |
greg |
1.1 |
return(rv); |
752 |
|
|
} |
753 |
|
|
} else { /* open */ |
754 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
755 |
greg |
1.1 |
return(rv); |
756 |
|
|
for (j = 0; j < 3; j++) |
757 |
|
|
sprintf(p4[j], FLTFMT, cv->p[j] + minrad*u[j]); |
758 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
759 |
greg |
1.1 |
return(rv); |
760 |
|
|
v1ent[3] = "_rv4"; |
761 |
|
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
762 |
|
|
theta = i*(PI/2)/mg_nqcdivs; |
763 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
764 |
greg |
1.1 |
return(rv); |
765 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
766 |
greg |
1.1 |
return(rv); |
767 |
|
|
for (j = 0; j < 3; j++) { |
768 |
|
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
769 |
|
|
sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*d); |
770 |
|
|
sprintf(p4[j], FLTFMT, cv->p[j] + minrad*d); |
771 |
|
|
} |
772 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
773 |
greg |
1.1 |
return(rv); |
774 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
775 |
greg |
1.1 |
return(rv); |
776 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
777 |
greg |
1.1 |
return(rv); |
778 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
779 |
greg |
1.1 |
return(rv); |
780 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK) |
781 |
greg |
1.1 |
return(rv); |
782 |
|
|
} |
783 |
|
|
} |
784 |
|
|
return(MG_OK); |
785 |
|
|
} |
786 |
|
|
|
787 |
|
|
|
788 |
greg |
1.23 |
int |
789 |
schorsch |
1.28 |
e_cone( /* turn a cone into polygons */ |
790 |
|
|
int ac, |
791 |
|
|
char **av |
792 |
|
|
) |
793 |
greg |
1.1 |
{ |
794 |
|
|
static char p3[3][24], p4[3][24], n3[3][24], n4[3][24]; |
795 |
|
|
static char *v1ent[5] = {mg_ename[MG_E_VERTEX],"_cv1","="}; |
796 |
|
|
static char *v2ent[5] = {mg_ename[MG_E_VERTEX],"_cv2","=","_cv3"}; |
797 |
|
|
static char *v3ent[4] = {mg_ename[MG_E_VERTEX],"_cv3","="}; |
798 |
|
|
static char *p3ent[5] = {mg_ename[MG_E_POINT],p3[0],p3[1],p3[2]}; |
799 |
|
|
static char *n3ent[5] = {mg_ename[MG_E_NORMAL],n3[0],n3[1],n3[2]}; |
800 |
|
|
static char *v4ent[4] = {mg_ename[MG_E_VERTEX],"_cv4","="}; |
801 |
|
|
static char *p4ent[5] = {mg_ename[MG_E_POINT],p4[0],p4[1],p4[2]}; |
802 |
|
|
static char *n4ent[5] = {mg_ename[MG_E_NORMAL],n4[0],n4[1],n4[2]}; |
803 |
|
|
static char *fent[6] = {mg_ename[MG_E_FACE],"_cv1","_cv2","_cv3","_cv4"}; |
804 |
greg |
1.19 |
char *v1n; |
805 |
greg |
1.1 |
register C_VERTEX *cv1, *cv2; |
806 |
|
|
register int i, j; |
807 |
|
|
FVECT u, v, w; |
808 |
|
|
double rad1, rad2; |
809 |
|
|
int sgn; |
810 |
|
|
double n1off, n2off; |
811 |
|
|
double d; |
812 |
|
|
int rv; |
813 |
|
|
double theta; |
814 |
|
|
|
815 |
|
|
if (ac != 5) |
816 |
|
|
return(MG_EARGC); |
817 |
|
|
if ((cv1 = c_getvert(av[1])) == NULL || |
818 |
|
|
(cv2 = c_getvert(av[3])) == NULL) |
819 |
|
|
return(MG_EUNDEF); |
820 |
greg |
1.19 |
v1n = av[1]; |
821 |
greg |
1.1 |
if (!isflt(av[2]) || !isflt(av[4])) |
822 |
|
|
return(MG_ETYPE); |
823 |
|
|
rad1 = atof(av[2]); |
824 |
greg |
1.3 |
round0(rad1); |
825 |
greg |
1.1 |
rad2 = atof(av[4]); |
826 |
greg |
1.3 |
round0(rad2); |
827 |
greg |
1.1 |
if (rad1 == 0.) { |
828 |
|
|
if (rad2 == 0.) |
829 |
|
|
return(MG_EILL); |
830 |
|
|
} else if (rad2 != 0.) { |
831 |
greg |
1.25 |
if ((rad1 < 0.) ^ (rad2 < 0.)) |
832 |
greg |
1.1 |
return(MG_EILL); |
833 |
|
|
} else { /* swap */ |
834 |
|
|
C_VERTEX *cv; |
835 |
|
|
|
836 |
|
|
cv = cv1; |
837 |
|
|
cv1 = cv2; |
838 |
|
|
cv2 = cv; |
839 |
greg |
1.19 |
v1n = av[3]; |
840 |
greg |
1.1 |
d = rad1; |
841 |
|
|
rad1 = rad2; |
842 |
|
|
rad2 = d; |
843 |
|
|
} |
844 |
|
|
sgn = rad2 < 0. ? -1 : 1; |
845 |
|
|
/* initialize */ |
846 |
|
|
for (j = 0; j < 3; j++) |
847 |
|
|
w[j] = cv1->p[j] - cv2->p[j]; |
848 |
|
|
if ((d = normalize(w)) == 0.) |
849 |
|
|
return(MG_EILL); |
850 |
|
|
n1off = n2off = (rad2 - rad1)/d; |
851 |
greg |
1.3 |
if (warpconends) { /* hack for e_sph and e_torus */ |
852 |
|
|
d = atan(n2off) - (PI/4)/mg_nqcdivs; |
853 |
|
|
if (d <= -PI/2+FTINY) |
854 |
|
|
n2off = -FHUGE; |
855 |
|
|
else |
856 |
|
|
n2off = tan(d); |
857 |
|
|
} |
858 |
greg |
1.1 |
make_axes(u, v, w); |
859 |
|
|
for (j = 0; j < 3; j++) { |
860 |
|
|
sprintf(p3[j], FLTFMT, cv2->p[j] + rad2*u[j]); |
861 |
greg |
1.3 |
if (n2off <= -FHUGE) |
862 |
|
|
sprintf(n3[j], FLTFMT, -w[j]); |
863 |
|
|
else |
864 |
|
|
sprintf(n3[j], FLTFMT, u[j] + w[j]*n2off); |
865 |
greg |
1.1 |
} |
866 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
867 |
greg |
1.1 |
return(rv); |
868 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
869 |
greg |
1.1 |
return(rv); |
870 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
871 |
greg |
1.1 |
return(rv); |
872 |
|
|
if (rad1 == 0.) { /* triangles */ |
873 |
greg |
1.19 |
v1ent[3] = v1n; |
874 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
875 |
greg |
1.1 |
return(rv); |
876 |
|
|
for (j = 0; j < 3; j++) |
877 |
|
|
sprintf(n4[j], FLTFMT, w[j]); |
878 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
879 |
greg |
1.1 |
return(rv); |
880 |
|
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
881 |
|
|
theta = sgn*i*(PI/2)/mg_nqcdivs; |
882 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
883 |
greg |
1.1 |
return(rv); |
884 |
|
|
for (j = 0; j < 3; j++) { |
885 |
|
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
886 |
|
|
sprintf(p3[j], FLTFMT, cv2->p[j] + rad2*d); |
887 |
greg |
1.3 |
if (n2off > -FHUGE) |
888 |
|
|
sprintf(n3[j], FLTFMT, d + w[j]*n2off); |
889 |
greg |
1.1 |
} |
890 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
891 |
greg |
1.1 |
return(rv); |
892 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
893 |
greg |
1.1 |
return(rv); |
894 |
greg |
1.3 |
if (n2off > -FHUGE && |
895 |
greg |
1.10 |
(rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
896 |
greg |
1.1 |
return(rv); |
897 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK) |
898 |
greg |
1.1 |
return(rv); |
899 |
|
|
} |
900 |
|
|
} else { /* quads */ |
901 |
|
|
v1ent[3] = "_cv4"; |
902 |
greg |
1.3 |
if (warpconends) { /* hack for e_sph and e_torus */ |
903 |
|
|
d = atan(n1off) + (PI/4)/mg_nqcdivs; |
904 |
|
|
if (d >= PI/2-FTINY) |
905 |
|
|
n1off = FHUGE; |
906 |
|
|
else |
907 |
|
|
n1off = tan(atan(n1off)+(PI/4)/mg_nqcdivs); |
908 |
|
|
} |
909 |
greg |
1.1 |
for (j = 0; j < 3; j++) { |
910 |
|
|
sprintf(p4[j], FLTFMT, cv1->p[j] + rad1*u[j]); |
911 |
greg |
1.3 |
if (n1off >= FHUGE) |
912 |
|
|
sprintf(n4[j], FLTFMT, w[j]); |
913 |
|
|
else |
914 |
|
|
sprintf(n4[j], FLTFMT, u[j] + w[j]*n1off); |
915 |
greg |
1.1 |
} |
916 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
917 |
greg |
1.1 |
return(rv); |
918 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
919 |
greg |
1.1 |
return(rv); |
920 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
921 |
greg |
1.1 |
return(rv); |
922 |
|
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
923 |
|
|
theta = sgn*i*(PI/2)/mg_nqcdivs; |
924 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
925 |
greg |
1.1 |
return(rv); |
926 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
927 |
greg |
1.1 |
return(rv); |
928 |
|
|
for (j = 0; j < 3; j++) { |
929 |
|
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
930 |
|
|
sprintf(p3[j], FLTFMT, cv2->p[j] + rad2*d); |
931 |
greg |
1.3 |
if (n2off > -FHUGE) |
932 |
|
|
sprintf(n3[j], FLTFMT, d + w[j]*n2off); |
933 |
greg |
1.1 |
sprintf(p4[j], FLTFMT, cv1->p[j] + rad1*d); |
934 |
greg |
1.3 |
if (n1off < FHUGE) |
935 |
|
|
sprintf(n4[j], FLTFMT, d + w[j]*n1off); |
936 |
greg |
1.1 |
} |
937 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
938 |
greg |
1.1 |
return(rv); |
939 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
940 |
greg |
1.1 |
return(rv); |
941 |
greg |
1.3 |
if (n2off > -FHUGE && |
942 |
greg |
1.10 |
(rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
943 |
greg |
1.1 |
return(rv); |
944 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
945 |
greg |
1.1 |
return(rv); |
946 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
947 |
greg |
1.1 |
return(rv); |
948 |
greg |
1.3 |
if (n1off < FHUGE && |
949 |
greg |
1.10 |
(rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
950 |
greg |
1.1 |
return(rv); |
951 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK) |
952 |
greg |
1.1 |
return(rv); |
953 |
|
|
} |
954 |
greg |
1.4 |
} |
955 |
|
|
return(MG_OK); |
956 |
|
|
} |
957 |
|
|
|
958 |
|
|
|
959 |
greg |
1.23 |
int |
960 |
schorsch |
1.28 |
e_prism( /* turn a prism into polygons */ |
961 |
|
|
int ac, |
962 |
|
|
char **av |
963 |
|
|
) |
964 |
greg |
1.4 |
{ |
965 |
|
|
static char p[3][24]; |
966 |
greg |
1.12 |
static char *vent[5] = {mg_ename[MG_E_VERTEX],NULL,"="}; |
967 |
greg |
1.4 |
static char *pent[5] = {mg_ename[MG_E_POINT],p[0],p[1],p[2]}; |
968 |
greg |
1.12 |
static char *znorm[5] = {mg_ename[MG_E_NORMAL],"0","0","0"}; |
969 |
greg |
1.4 |
char *newav[MG_MAXARGC], nvn[MG_MAXARGC-1][8]; |
970 |
|
|
double length; |
971 |
greg |
1.12 |
int hasnorm; |
972 |
greg |
1.4 |
FVECT v1, v2, v3, norm; |
973 |
|
|
register C_VERTEX *cv; |
974 |
|
|
C_VERTEX *cv0; |
975 |
|
|
int rv; |
976 |
|
|
register int i, j; |
977 |
greg |
1.12 |
/* check arguments */ |
978 |
greg |
1.4 |
if (ac < 5) |
979 |
|
|
return(MG_EARGC); |
980 |
greg |
1.5 |
if (!isflt(av[ac-1])) |
981 |
greg |
1.4 |
return(MG_ETYPE); |
982 |
greg |
1.5 |
length = atof(av[ac-1]); |
983 |
greg |
1.4 |
if (length <= FTINY && length >= -FTINY) |
984 |
|
|
return(MG_EILL); |
985 |
greg |
1.12 |
/* compute face normal */ |
986 |
greg |
1.7 |
if ((cv0 = c_getvert(av[1])) == NULL) |
987 |
greg |
1.4 |
return(MG_EUNDEF); |
988 |
greg |
1.12 |
hasnorm = 0; |
989 |
greg |
1.4 |
norm[0] = norm[1] = norm[2] = 0.; |
990 |
|
|
v1[0] = v1[1] = v1[2] = 0.; |
991 |
|
|
for (i = 2; i < ac-1; i++) { |
992 |
greg |
1.5 |
if ((cv = c_getvert(av[i])) == NULL) |
993 |
greg |
1.4 |
return(MG_EUNDEF); |
994 |
greg |
1.12 |
hasnorm += !is0vect(cv->n); |
995 |
greg |
1.4 |
v2[0] = cv->p[0] - cv0->p[0]; |
996 |
|
|
v2[1] = cv->p[1] - cv0->p[1]; |
997 |
|
|
v2[2] = cv->p[2] - cv0->p[2]; |
998 |
|
|
fcross(v3, v1, v2); |
999 |
|
|
norm[0] += v3[0]; |
1000 |
|
|
norm[1] += v3[1]; |
1001 |
|
|
norm[2] += v3[2]; |
1002 |
|
|
VCOPY(v1, v2); |
1003 |
|
|
} |
1004 |
|
|
if (normalize(norm) == 0.) |
1005 |
|
|
return(MG_EILL); |
1006 |
greg |
1.12 |
/* create moved vertices */ |
1007 |
greg |
1.4 |
for (i = 1; i < ac-1; i++) { |
1008 |
|
|
sprintf(nvn[i-1], "_pv%d", i); |
1009 |
|
|
vent[1] = nvn[i-1]; |
1010 |
greg |
1.12 |
vent[3] = av[i]; |
1011 |
|
|
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
1012 |
greg |
1.4 |
return(rv); |
1013 |
greg |
1.5 |
cv = c_getvert(av[i]); /* checked above */ |
1014 |
greg |
1.4 |
for (j = 0; j < 3; j++) |
1015 |
|
|
sprintf(p[j], FLTFMT, cv->p[j] - length*norm[j]); |
1016 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_POINT, 4, pent)) != MG_OK) |
1017 |
greg |
1.4 |
return(rv); |
1018 |
|
|
} |
1019 |
greg |
1.12 |
/* make faces */ |
1020 |
|
|
newav[0] = mg_ename[MG_E_FACE]; |
1021 |
greg |
1.4 |
/* do the side faces */ |
1022 |
|
|
newav[5] = NULL; |
1023 |
greg |
1.5 |
newav[3] = av[ac-2]; |
1024 |
greg |
1.4 |
newav[4] = nvn[ac-3]; |
1025 |
|
|
for (i = 1; i < ac-1; i++) { |
1026 |
|
|
newav[1] = nvn[i-1]; |
1027 |
greg |
1.5 |
newav[2] = av[i]; |
1028 |
greg |
1.10 |
if ((rv = mg_handle(MG_E_FACE, 5, newav)) != MG_OK) |
1029 |
greg |
1.4 |
return(rv); |
1030 |
|
|
newav[3] = newav[2]; |
1031 |
|
|
newav[4] = newav[1]; |
1032 |
greg |
1.6 |
} |
1033 |
greg |
1.12 |
/* do top face */ |
1034 |
|
|
for (i = 1; i < ac-1; i++) { |
1035 |
|
|
if (hasnorm) { /* zero normals */ |
1036 |
|
|
vent[1] = nvn[i-1]; |
1037 |
|
|
if ((rv = mg_handle(MG_E_VERTEX, 2, vent)) != MG_OK) |
1038 |
|
|
return(rv); |
1039 |
|
|
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
1040 |
|
|
return(rv); |
1041 |
|
|
} |
1042 |
|
|
newav[ac-1-i] = nvn[i-1]; /* reverse */ |
1043 |
|
|
} |
1044 |
|
|
if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK) |
1045 |
|
|
return(rv); |
1046 |
|
|
/* do bottom face */ |
1047 |
|
|
if (hasnorm) |
1048 |
|
|
for (i = 1; i < ac-1; i++) { |
1049 |
|
|
vent[1] = nvn[i-1]; |
1050 |
|
|
vent[3] = av[i]; |
1051 |
|
|
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
1052 |
|
|
return(rv); |
1053 |
|
|
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
1054 |
|
|
return(rv); |
1055 |
|
|
newav[i] = nvn[i-1]; |
1056 |
|
|
} |
1057 |
|
|
else |
1058 |
|
|
for (i = 1; i < ac-1; i++) |
1059 |
|
|
newav[i] = av[i]; |
1060 |
|
|
newav[i] = NULL; |
1061 |
|
|
if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK) |
1062 |
|
|
return(rv); |
1063 |
greg |
1.6 |
return(MG_OK); |
1064 |
|
|
} |
1065 |
|
|
|
1066 |
|
|
|
1067 |
|
|
static int |
1068 |
schorsch |
1.28 |
put_cxy(void) /* put out current xy chromaticities */ |
1069 |
greg |
1.6 |
{ |
1070 |
|
|
static char xbuf[24], ybuf[24]; |
1071 |
|
|
static char *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf}; |
1072 |
|
|
|
1073 |
greg |
1.13 |
sprintf(xbuf, "%.4f", c_ccolor->cx); |
1074 |
|
|
sprintf(ybuf, "%.4f", c_ccolor->cy); |
1075 |
greg |
1.23 |
return(mg_handle(MG_E_CXY, 3, ccom)); |
1076 |
greg |
1.13 |
} |
1077 |
|
|
|
1078 |
|
|
|
1079 |
|
|
static int |
1080 |
schorsch |
1.28 |
put_cspec(void) /* put out current color spectrum */ |
1081 |
greg |
1.13 |
{ |
1082 |
|
|
char wl[2][6], vbuf[C_CNSS][24]; |
1083 |
|
|
char *newav[C_CNSS+4]; |
1084 |
|
|
double sf; |
1085 |
|
|
register int i; |
1086 |
|
|
|
1087 |
|
|
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
1088 |
|
|
sprintf(wl[0], "%d", C_CMINWL); |
1089 |
|
|
sprintf(wl[1], "%d", C_CMAXWL); |
1090 |
|
|
newav[0] = mg_ename[MG_E_CSPEC]; |
1091 |
|
|
newav[1] = wl[0]; |
1092 |
|
|
newav[2] = wl[1]; |
1093 |
|
|
sf = (double)C_CNSS / c_ccolor->ssum; |
1094 |
|
|
for (i = 0; i < C_CNSS; i++) { |
1095 |
greg |
1.14 |
sprintf(vbuf[i], "%.4f", sf*c_ccolor->ssamp[i]); |
1096 |
greg |
1.13 |
newav[i+3] = vbuf[i]; |
1097 |
|
|
} |
1098 |
|
|
newav[C_CNSS+3] = NULL; |
1099 |
|
|
if ((i = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
1100 |
|
|
return(i); |
1101 |
|
|
} |
1102 |
|
|
return(MG_OK); |
1103 |
|
|
} |
1104 |
|
|
|
1105 |
|
|
|
1106 |
|
|
static int |
1107 |
schorsch |
1.28 |
e_cspec( /* handle spectral color */ |
1108 |
|
|
int ac, |
1109 |
|
|
char **av |
1110 |
|
|
) |
1111 |
greg |
1.13 |
{ |
1112 |
|
|
/* convert to xy chromaticity */ |
1113 |
greg |
1.6 |
c_ccvt(c_ccolor, C_CSXY); |
1114 |
|
|
/* if it's really their handler, use it */ |
1115 |
greg |
1.13 |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1116 |
|
|
return(put_cxy()); |
1117 |
greg |
1.6 |
return(MG_OK); |
1118 |
|
|
} |
1119 |
|
|
|
1120 |
|
|
|
1121 |
|
|
static int |
1122 |
schorsch |
1.28 |
e_cmix( /* handle mixing of colors */ |
1123 |
|
|
int ac, |
1124 |
|
|
char **av |
1125 |
|
|
) |
1126 |
greg |
1.6 |
{ |
1127 |
|
|
/* |
1128 |
|
|
* Contorted logic works as follows: |
1129 |
|
|
* 1. the colors are already mixed in c_hcolor() support function |
1130 |
|
|
* 2. if we would handle a spectral result, make sure it's not |
1131 |
|
|
* 3. if c_hcolor() would handle a spectral result, don't bother |
1132 |
|
|
* 4. otherwise, make cspec entity and pass it to their handler |
1133 |
|
|
* 5. if we have only xy results, handle it as c_spec() would |
1134 |
|
|
*/ |
1135 |
|
|
if (mg_ehand[MG_E_CSPEC] == e_cspec) |
1136 |
|
|
c_ccvt(c_ccolor, C_CSXY); |
1137 |
greg |
1.13 |
else if (c_ccolor->flags & C_CDSPEC) |
1138 |
|
|
return(put_cspec()); |
1139 |
|
|
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1140 |
|
|
return(put_cxy()); |
1141 |
|
|
return(MG_OK); |
1142 |
|
|
} |
1143 |
|
|
|
1144 |
|
|
|
1145 |
|
|
static int |
1146 |
schorsch |
1.28 |
e_cct( /* handle color temperature */ |
1147 |
|
|
int ac, |
1148 |
|
|
char **av |
1149 |
|
|
) |
1150 |
greg |
1.13 |
{ |
1151 |
|
|
/* |
1152 |
|
|
* Logic is similar to e_cmix here. Support handler has already |
1153 |
|
|
* converted temperature to spectral color. Put it out as such |
1154 |
|
|
* if they support it, otherwise convert to xy chromaticity and |
1155 |
|
|
* put it out if they handle it. |
1156 |
|
|
*/ |
1157 |
|
|
if (mg_ehand[MG_E_CSPEC] != e_cspec) |
1158 |
|
|
return(put_cspec()); |
1159 |
|
|
c_ccvt(c_ccolor, C_CSXY); |
1160 |
|
|
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1161 |
|
|
return(put_cxy()); |
1162 |
greg |
1.1 |
return(MG_OK); |
1163 |
|
|
} |