1 |
< |
/* Copyright (c) 1994 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
27 |
|
|
28 |
|
int (*mg_ehand[MG_NENTITIES])(); |
29 |
|
|
30 |
+ |
/* Handler routine for unknown entities */ |
31 |
+ |
|
32 |
+ |
int (*mg_uhand)() = mg_defuhand; |
33 |
+ |
|
34 |
+ |
unsigned mg_nunknown; /* count of unknown entities */ |
35 |
+ |
|
36 |
|
/* error messages */ |
37 |
|
|
38 |
|
char *mg_err[MG_NERRS] = MG_ERRLIST; |
65 |
|
e_ies(), /* IES luminaire file */ |
66 |
|
e_include(), /* include file */ |
67 |
|
e_sph(), /* sphere */ |
68 |
+ |
e_cct(), /* color temperature */ |
69 |
|
e_cmix(), /* color mixtures */ |
70 |
|
e_cspec(), /* color spectra */ |
71 |
|
e_cyl(), /* cylinder */ |
95 |
|
mg_ehand[MG_E_INCLUDE] = e_include; |
96 |
|
if (mg_ehand[MG_E_SPH] == NULL) { |
97 |
|
mg_ehand[MG_E_SPH] = e_sph; |
98 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
98 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
99 |
|
} else |
100 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
100 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
101 |
|
if (mg_ehand[MG_E_CYL] == NULL) { |
102 |
|
mg_ehand[MG_E_CYL] = e_cyl; |
103 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
103 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
104 |
|
} else |
105 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
105 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
106 |
|
if (mg_ehand[MG_E_CONE] == NULL) { |
107 |
|
mg_ehand[MG_E_CONE] = e_cone; |
108 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
108 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
109 |
|
} else |
110 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
110 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
111 |
|
if (mg_ehand[MG_E_RING] == NULL) { |
112 |
|
mg_ehand[MG_E_RING] = e_ring; |
113 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX; |
113 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX; |
114 |
|
} else |
115 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX|1<<MG_E_XF; |
115 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
116 |
|
if (mg_ehand[MG_E_PRISM] == NULL) { |
117 |
|
mg_ehand[MG_E_PRISM] = e_prism; |
118 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
118 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
119 |
|
} else |
120 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
120 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
121 |
|
if (mg_ehand[MG_E_TORUS] == NULL) { |
122 |
|
mg_ehand[MG_E_TORUS] = e_torus; |
123 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX; |
123 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX; |
124 |
|
} else |
125 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX|1<<MG_E_XF; |
125 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
126 |
|
if (mg_ehand[MG_E_COLOR] != NULL) { |
127 |
|
if (mg_ehand[MG_E_CMIX] == NULL) { |
128 |
|
mg_ehand[MG_E_CMIX] = e_cmix; |
129 |
< |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX; |
129 |
> |
ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT; |
130 |
|
} |
131 |
|
if (mg_ehand[MG_E_CSPEC] == NULL) { |
132 |
|
mg_ehand[MG_E_CSPEC] = e_cspec; |
133 |
< |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX; |
133 |
> |
ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT; |
134 |
|
} |
135 |
+ |
if (mg_ehand[MG_E_CCT] == NULL) { |
136 |
+ |
mg_ehand[MG_E_CCT] = e_cct; |
137 |
+ |
ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT; |
138 |
+ |
} |
139 |
|
} |
140 |
|
/* check for consistency */ |
141 |
|
if (mg_ehand[MG_E_FACE] != NULL) |
142 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
142 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
143 |
|
if (mg_ehand[MG_E_CXY] != NULL || mg_ehand[MG_E_CSPEC] != NULL || |
144 |
|
mg_ehand[MG_E_CMIX] != NULL) |
145 |
< |
uneed |= 1<<MG_E_COLOR; |
145 |
> |
uneed |= 1L<<MG_E_COLOR; |
146 |
|
if (mg_ehand[MG_E_RD] != NULL || mg_ehand[MG_E_TD] != NULL || |
147 |
+ |
mg_ehand[MG_E_IR] != NULL || |
148 |
|
mg_ehand[MG_E_ED] != NULL || |
149 |
|
mg_ehand[MG_E_RS] != NULL || |
150 |
< |
mg_ehand[MG_E_TS] != NULL) |
151 |
< |
uneed |= 1<<MG_E_MATERIAL; |
150 |
> |
mg_ehand[MG_E_TS] != NULL || |
151 |
> |
mg_ehand[MG_E_SIDES] != NULL) |
152 |
> |
uneed |= 1L<<MG_E_MATERIAL; |
153 |
|
for (i = 0; i < MG_NENTITIES; i++) |
154 |
< |
if (uneed & 1<<i && mg_ehand[i] == NULL) { |
154 |
> |
if (uneed & 1L<<i && mg_ehand[i] == NULL) { |
155 |
|
fprintf(stderr, "Missing support for \"%s\" entity\n", |
156 |
|
mg_ename[i]); |
157 |
|
exit(1); |
158 |
|
} |
159 |
|
/* add support as needed */ |
160 |
< |
if (ineed & 1<<MG_E_VERTEX && mg_ehand[MG_E_VERTEX] != c_hvertex) |
160 |
> |
if (ineed & 1L<<MG_E_VERTEX && mg_ehand[MG_E_VERTEX] != c_hvertex) |
161 |
|
e_supp[MG_E_VERTEX] = c_hvertex; |
162 |
< |
if (ineed & 1<<MG_E_POINT && mg_ehand[MG_E_POINT] != c_hvertex) |
162 |
> |
if (ineed & 1L<<MG_E_POINT && mg_ehand[MG_E_POINT] != c_hvertex) |
163 |
|
e_supp[MG_E_POINT] = c_hvertex; |
164 |
< |
if (ineed & 1<<MG_E_NORMAL && mg_ehand[MG_E_NORMAL] != c_hvertex) |
164 |
> |
if (ineed & 1L<<MG_E_NORMAL && mg_ehand[MG_E_NORMAL] != c_hvertex) |
165 |
|
e_supp[MG_E_NORMAL] = c_hvertex; |
166 |
< |
if (ineed & 1<<MG_E_COLOR && mg_ehand[MG_E_COLOR] != c_hcolor) |
166 |
> |
if (ineed & 1L<<MG_E_COLOR && mg_ehand[MG_E_COLOR] != c_hcolor) |
167 |
|
e_supp[MG_E_COLOR] = c_hcolor; |
168 |
< |
if (ineed & 1<<MG_E_CXY && mg_ehand[MG_E_CXY] != c_hcolor) |
168 |
> |
if (ineed & 1L<<MG_E_CXY && mg_ehand[MG_E_CXY] != c_hcolor) |
169 |
|
e_supp[MG_E_CXY] = c_hcolor; |
170 |
< |
if (ineed & 1<<MG_E_CSPEC && mg_ehand[MG_E_CSPEC] != c_hcolor) |
170 |
> |
if (ineed & 1L<<MG_E_CSPEC && mg_ehand[MG_E_CSPEC] != c_hcolor) |
171 |
|
e_supp[MG_E_CSPEC] = c_hcolor; |
172 |
< |
if (ineed & 1<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor) |
172 |
> |
if (ineed & 1L<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor) |
173 |
|
e_supp[MG_E_CMIX] = c_hcolor; |
174 |
+ |
if (ineed & 1L<<MG_E_CCT && mg_ehand[MG_E_CCT] != c_hcolor) |
175 |
+ |
e_supp[MG_E_CCT] = c_hcolor; |
176 |
|
/* discard remaining entities */ |
177 |
|
for (i = 0; i < MG_NENTITIES; i++) |
178 |
|
if (mg_ehand[i] == NULL) |
180 |
|
} |
181 |
|
|
182 |
|
|
168 |
– |
|
183 |
|
int |
184 |
|
mg_entity(name) /* get entity number from its name */ |
185 |
|
char *name; |
186 |
|
{ |
187 |
< |
static LUTAB ent_tab; /* entity lookup table */ |
187 |
> |
static LUTAB ent_tab = LU_SINIT(NULL,NULL); /* lookup table */ |
188 |
|
register char *cp; |
189 |
|
|
190 |
|
if (!ent_tab.tsiz) { /* initialize hash table */ |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
< |
static int |
205 |
< |
handle_it(en, ac, av) /* pass entity to appropriate handler */ |
204 |
> |
int |
205 |
> |
mg_handle(en, ac, av) /* pass entity to appropriate handler */ |
206 |
|
register int en; |
207 |
|
int ac; |
208 |
|
char **av; |
209 |
|
{ |
210 |
|
int rv; |
211 |
|
|
212 |
< |
if (en < 0 && (en = mg_entity(av[0])) < 0) |
212 |
> |
if (en < 0 && (en = mg_entity(av[0])) < 0) { /* unknown entity */ |
213 |
> |
if (mg_uhand != NULL) |
214 |
> |
return((*mg_uhand)(ac, av)); |
215 |
|
return(MG_EUNK); |
216 |
< |
if (e_supp[en] != NULL) { |
216 |
> |
} |
217 |
> |
if (e_supp[en] != NULL) { /* support handler */ |
218 |
|
if ((rv = (*e_supp[en])(ac, av)) != MG_OK) |
219 |
|
return(rv); |
220 |
|
} |
221 |
< |
return((*mg_ehand[en])(ac, av)); |
221 |
> |
return((*mg_ehand[en])(ac, av)); /* assigned handler */ |
222 |
|
} |
223 |
|
|
224 |
|
|
227 |
|
register MG_FCTXT *ctx; |
228 |
|
char *fn; |
229 |
|
{ |
230 |
< |
int olen; |
230 |
> |
static int nfids; |
231 |
|
register char *cp; |
232 |
|
|
233 |
+ |
ctx->fid = ++nfids; |
234 |
|
ctx->lineno = 0; |
235 |
|
if (fn == NULL) { |
236 |
< |
ctx->fname = "<stdin>"; |
236 |
> |
strcpy(ctx->fname, "<stdin>"); |
237 |
|
ctx->fp = stdin; |
238 |
|
ctx->prev = mg_file; |
239 |
|
mg_file = ctx; |
240 |
|
return(MG_OK); |
241 |
|
} |
242 |
|
/* get name relative to this context */ |
243 |
< |
if (mg_file != NULL && |
226 |
< |
(cp = strrchr(mg_file->fname, '/')) != NULL) |
227 |
< |
olen = cp - mg_file->fname + 1; |
228 |
< |
else |
229 |
< |
olen = 0; |
230 |
< |
ctx->fname = (char *)malloc(olen+strlen(fn)+1); |
231 |
< |
if (ctx->fname == NULL) |
232 |
< |
return(MG_EMEM); |
233 |
< |
if (olen) |
243 |
> |
if (mg_file != NULL && (cp = strrchr(mg_file->fname, '/')) != NULL) { |
244 |
|
strcpy(ctx->fname, mg_file->fname); |
245 |
< |
strcpy(ctx->fname+olen, fn); |
245 |
> |
strcpy(ctx->fname+(cp-mg_file->fname+1), fn); |
246 |
> |
} else |
247 |
> |
strcpy(ctx->fname, fn); |
248 |
|
ctx->fp = fopen(ctx->fname, "r"); |
249 |
< |
if (ctx->fp == NULL) { |
238 |
< |
free((MEM_PTR)ctx->fname); |
249 |
> |
if (ctx->fp == NULL) |
250 |
|
return(MG_ENOFILE); |
240 |
– |
} |
251 |
|
ctx->prev = mg_file; /* establish new context */ |
252 |
|
mg_file = ctx; |
253 |
|
return(MG_OK); |
263 |
|
if (ctx->fp == stdin) |
264 |
|
return; /* don't close standard input */ |
265 |
|
fclose(ctx->fp); |
256 |
– |
free((MEM_PTR)ctx->fname); |
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
+ |
void |
270 |
+ |
mg_fgetpos(pos) /* get current position in input file */ |
271 |
+ |
register MG_FPOS *pos; |
272 |
+ |
{ |
273 |
+ |
extern long ftell(); |
274 |
+ |
|
275 |
+ |
pos->fid = mg_file->fid; |
276 |
+ |
pos->lineno = mg_file->lineno; |
277 |
+ |
pos->offset = ftell(mg_file->fp); |
278 |
+ |
} |
279 |
+ |
|
280 |
+ |
|
281 |
|
int |
282 |
< |
mg_rewind() /* rewind input file */ |
282 |
> |
mg_fgoto(pos) /* reposition input file pointer */ |
283 |
> |
register MG_FPOS *pos; |
284 |
|
{ |
285 |
< |
if (mg_file->lineno == 0) |
285 |
> |
if (pos->fid != mg_file->fid) |
286 |
> |
return(MG_ESEEK); |
287 |
> |
if (pos->lineno == mg_file->lineno) |
288 |
|
return(MG_OK); |
289 |
|
if (mg_file->fp == stdin) |
290 |
|
return(MG_ESEEK); /* cannot seek on standard input */ |
291 |
< |
if (fseek(mg_file->fp, 0L, 0) == EOF) |
291 |
> |
if (fseek(mg_file->fp, pos->offset, 0) == EOF) |
292 |
|
return(MG_ESEEK); |
293 |
< |
mg_file->lineno = 0; |
293 |
> |
mg_file->lineno = pos->lineno; |
294 |
|
return(MG_OK); |
295 |
|
} |
296 |
|
|
304 |
|
if (fgets(mg_file->inpline+len, |
305 |
|
MG_MAXLINE-len, mg_file->fp) == NULL) |
306 |
|
return(len); |
283 |
– |
mg_file->lineno++; |
307 |
|
len += strlen(mg_file->inpline+len); |
308 |
< |
if (len > 1 && mg_file->inpline[len-2] == '\\') |
309 |
< |
mg_file->inpline[--len-1] = ' '; |
310 |
< |
} while (mg_file->inpline[len]); |
308 |
> |
if (len >= MG_MAXLINE-1) |
309 |
> |
return(len); |
310 |
> |
mg_file->lineno++; |
311 |
> |
} while (len > 1 && mg_file->inpline[len-2] == '\\'); |
312 |
|
|
313 |
|
return(len); |
314 |
|
} |
320 |
|
char abuf[MG_MAXLINE]; |
321 |
|
char *argv[MG_MAXARGC]; |
322 |
|
int en; |
323 |
< |
register char *cp, **ap; |
324 |
< |
|
325 |
< |
strcpy(cp=abuf, mg_file->inpline); |
326 |
< |
ap = argv; /* break into words */ |
323 |
> |
register char *cp, *cp2, **ap; |
324 |
> |
/* copy line, removing escape chars */ |
325 |
> |
cp = abuf; cp2 = mg_file->inpline; |
326 |
> |
while ((*cp++ = *cp2++)) |
327 |
> |
if (cp2[0] == '\n' && cp2[-1] == '\\') |
328 |
> |
cp--; |
329 |
> |
cp = abuf; ap = argv; /* break into words */ |
330 |
|
for ( ; ; ) { |
331 |
|
while (isspace(*cp)) |
332 |
|
*cp++ = '\0'; |
342 |
|
return(MG_OK); /* no words in line */ |
343 |
|
*ap = NULL; |
344 |
|
/* else handle it */ |
345 |
< |
return(handle_it(-1, ap-argv, argv)); |
345 |
> |
return(mg_handle(-1, ap-argv, argv)); |
346 |
|
} |
347 |
|
|
348 |
|
|
352 |
|
{ |
353 |
|
MG_FCTXT cntxt; |
354 |
|
int rval; |
355 |
+ |
register int nbr; |
356 |
|
|
357 |
|
if ((rval = mg_open(&cntxt, fn)) != MG_OK) { |
358 |
|
fprintf(stderr, "%s: %s\n", fn, mg_err[rval]); |
359 |
|
return(rval); |
360 |
|
} |
361 |
< |
while (mg_read()) /* parse each line */ |
361 |
> |
while ((nbr = mg_read()) > 0) { /* parse each line */ |
362 |
> |
if (nbr >= MG_MAXLINE-1) { |
363 |
> |
fprintf(stderr, "%s: %d: %s\n", cntxt.fname, |
364 |
> |
cntxt.lineno, mg_err[rval=MG_ELINE]); |
365 |
> |
break; |
366 |
> |
} |
367 |
|
if ((rval = mg_parse()) != MG_OK) { |
368 |
|
fprintf(stderr, "%s: %d: %s:\n%s", cntxt.fname, |
369 |
|
cntxt.lineno, mg_err[rval], |
370 |
|
cntxt.inpline); |
371 |
|
break; |
372 |
|
} |
373 |
+ |
} |
374 |
|
mg_close(); |
375 |
|
return(rval); |
376 |
|
} |
377 |
|
|
378 |
|
|
379 |
+ |
int |
380 |
+ |
mg_defuhand(ac, av) /* default handler for unknown entities */ |
381 |
+ |
int ac; |
382 |
+ |
char **av; |
383 |
+ |
{ |
384 |
+ |
if (mg_nunknown++ == 0) /* report first incident */ |
385 |
+ |
fprintf(stderr, "%s: %d: %s: %s\n", mg_file->fname, |
386 |
+ |
mg_file->lineno, mg_err[MG_EUNK], av[0]); |
387 |
+ |
return(MG_OK); |
388 |
+ |
} |
389 |
+ |
|
390 |
+ |
|
391 |
|
void |
392 |
|
mg_clear() /* clear parser history */ |
393 |
|
{ |
396 |
|
} |
397 |
|
|
398 |
|
|
353 |
– |
int |
354 |
– |
mg_iterate(ac, av, f) /* iterate on statement */ |
355 |
– |
int ac; |
356 |
– |
register char **av; |
357 |
– |
int (*f)(); |
358 |
– |
{ |
359 |
– |
int niter, rval; |
360 |
– |
register int i, j; |
361 |
– |
char *argv[MG_MAXARGC]; |
362 |
– |
char cntbuf[10]; |
363 |
– |
/* build partial transformation */ |
364 |
– |
for (i = 0; i < ac; i++) { |
365 |
– |
if (av[i][0] == '-' && av[i][1] == 'a' && av[i][2] == '\0') |
366 |
– |
break; |
367 |
– |
argv[i+1] = av[i]; |
368 |
– |
} |
369 |
– |
argv[i+1] = NULL; |
370 |
– |
if (i) { /* handle transformation */ |
371 |
– |
argv[0] = mg_ename[MG_E_XF]; |
372 |
– |
if ((rval = handle_it(MG_E_XF, i+1, argv)) != MG_OK) |
373 |
– |
return(rval); |
374 |
– |
} |
375 |
– |
if (i < ac) { /* run array */ |
376 |
– |
if (i+1 >= ac || !isint(av[i+1])) |
377 |
– |
return(MG_ETYPE); |
378 |
– |
niter = atoi(av[i+1]); |
379 |
– |
argv[0] = mg_ename[MG_E_OBJECT]; |
380 |
– |
argv[1] = cntbuf; |
381 |
– |
for (j = 2; j+i < ac; j++) |
382 |
– |
argv[j] = av[j+i]; |
383 |
– |
argv[j] = NULL; |
384 |
– |
for (j = 0; j < niter; j++) { |
385 |
– |
sprintf(cntbuf, "%d", j); |
386 |
– |
if ((rval = handle_it(MG_E_OBJECT, 2, argv)) != MG_OK) |
387 |
– |
return(rval); |
388 |
– |
argv[0] = "-i"; |
389 |
– |
if ((rval = mg_iterate(ac-i, argv, f)) != MG_OK) |
390 |
– |
return(rval); |
391 |
– |
argv[0] = mg_ename[MG_E_OBJECT]; |
392 |
– |
if ((rval = handle_it(MG_E_OBJECT, 1, argv)) != MG_OK) |
393 |
– |
return(rval); |
394 |
– |
} |
395 |
– |
} else if ((rval = (*f)()) != MG_OK) /* else do this instance */ |
396 |
– |
return(rval); |
397 |
– |
if (i) { /* reset the transform */ |
398 |
– |
argv[0] = mg_ename[MG_E_XF]; |
399 |
– |
argv[1] = NULL; |
400 |
– |
(void)handle_it(MG_E_XF, 1, argv); |
401 |
– |
} |
402 |
– |
return(MG_OK); |
403 |
– |
} |
404 |
– |
|
405 |
– |
|
399 |
|
/**************************************************************************** |
400 |
|
* The following routines handle unsupported entities |
401 |
|
*/ |
411 |
|
|
412 |
|
|
413 |
|
static int |
421 |
– |
reload_file() /* reload current MGF file */ |
422 |
– |
{ |
423 |
– |
register int rval; |
424 |
– |
|
425 |
– |
if ((rval = mg_rewind()) != MG_OK) |
426 |
– |
return(rval); |
427 |
– |
while (mg_read()) |
428 |
– |
if ((rval = mg_parse()) != MG_OK) |
429 |
– |
return(rval); |
430 |
– |
return(MG_OK); |
431 |
– |
} |
432 |
– |
|
433 |
– |
|
434 |
– |
static int |
414 |
|
e_include(ac, av) /* include file */ |
415 |
|
int ac; |
416 |
|
char **av; |
417 |
|
{ |
418 |
+ |
char *xfarg[MG_MAXARGC]; |
419 |
|
MG_FCTXT ictx; |
420 |
< |
int rv; |
420 |
> |
XF_SPEC *xf_orig = xf_context; |
421 |
> |
register int rv; |
422 |
|
|
423 |
|
if (ac < 2) |
424 |
|
return(MG_EARGC); |
425 |
|
if ((rv = mg_open(&ictx, av[1])) != MG_OK) |
426 |
|
return(rv); |
427 |
< |
if ((rv = mg_iterate(ac-2, av+2, reload_file)) != MG_OK) { |
428 |
< |
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
429 |
< |
ictx.lineno, mg_err[rv], ictx.inpline); |
430 |
< |
mg_close(); |
431 |
< |
return(MG_EINCL); |
427 |
> |
if (ac > 2) { |
428 |
> |
register int i; |
429 |
> |
|
430 |
> |
xfarg[0] = mg_ename[MG_E_XF]; |
431 |
> |
for (i = 1; i < ac-1; i++) |
432 |
> |
xfarg[i] = av[i+1]; |
433 |
> |
xfarg[ac-1] = NULL; |
434 |
> |
if ((rv = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK) { |
435 |
> |
mg_close(); |
436 |
> |
return(rv); |
437 |
> |
} |
438 |
|
} |
439 |
+ |
do { |
440 |
+ |
while ((rv = mg_read()) > 0) { |
441 |
+ |
if (rv >= MG_MAXLINE-1) { |
442 |
+ |
fprintf(stderr, "%s: %d: %s\n", ictx.fname, |
443 |
+ |
ictx.lineno, mg_err[MG_ELINE]); |
444 |
+ |
mg_close(); |
445 |
+ |
return(MG_EINCL); |
446 |
+ |
} |
447 |
+ |
if ((rv = mg_parse()) != MG_OK) { |
448 |
+ |
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
449 |
+ |
ictx.lineno, mg_err[rv], |
450 |
+ |
ictx.inpline); |
451 |
+ |
mg_close(); |
452 |
+ |
return(MG_EINCL); |
453 |
+ |
} |
454 |
+ |
} |
455 |
+ |
if (ac > 2) |
456 |
+ |
if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK) { |
457 |
+ |
mg_close(); |
458 |
+ |
return(rv); |
459 |
+ |
} |
460 |
+ |
} while (xf_context != xf_orig); |
461 |
|
mg_close(); |
462 |
|
return(MG_OK); |
463 |
|
} |
505 |
|
rad = atof(av[2]); |
506 |
|
/* initialize */ |
507 |
|
warpconends = 1; |
508 |
< |
if ((rval = handle_it(MG_E_VERTEX, 3, v2ent)) != MG_OK) |
508 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 3, v2ent)) != MG_OK) |
509 |
|
return(rval); |
510 |
|
sprintf(p2x, FLTFMT, cv->p[0]); |
511 |
|
sprintf(p2y, FLTFMT, cv->p[1]); |
512 |
|
sprintf(p2z, FLTFMT, cv->p[2]+rad); |
513 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
513 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
514 |
|
return(rval); |
515 |
|
r2[0] = '0'; r2[1] = '\0'; |
516 |
|
for (i = 1; i <= 2*mg_nqcdivs; i++) { |
517 |
|
theta = i*(PI/2)/mg_nqcdivs; |
518 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
518 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
519 |
|
return(rval); |
520 |
|
sprintf(p2z, FLTFMT, cv->p[2]+rad*cos(theta)); |
521 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
521 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
522 |
|
return(rval); |
523 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
523 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
524 |
|
return(rval); |
525 |
|
strcpy(r1, r2); |
526 |
|
sprintf(r2, FLTFMT, rad*sin(theta)); |
527 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
527 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
528 |
|
return(rval); |
529 |
|
} |
530 |
|
warpconends = 0; |
579 |
|
for (j = 0; j < 3; j++) |
580 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
581 |
|
.5*sgn*(maxrad-minrad)*cv->n[j]); |
582 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
582 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
583 |
|
return(rval); |
584 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
584 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
585 |
|
return(rval); |
586 |
|
sprintf(r2, FLTFMT, avgrad=.5*(minrad+maxrad)); |
587 |
|
/* run outer section */ |
588 |
|
for (i = 1; i <= 2*mg_nqcdivs; i++) { |
589 |
|
theta = i*(PI/2)/mg_nqcdivs; |
590 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
590 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
591 |
|
return(rval); |
592 |
|
for (j = 0; j < 3; j++) |
593 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
594 |
|
.5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); |
595 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
595 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
596 |
|
return(rval); |
597 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
597 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
598 |
|
return(rval); |
599 |
|
strcpy(r1, r2); |
600 |
|
sprintf(r2, FLTFMT, avgrad + .5*(maxrad-minrad)*sin(theta)); |
601 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
601 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
602 |
|
return(rval); |
603 |
|
} |
604 |
|
/* run inner section */ |
608 |
|
for (j = 0; j < 3; j++) |
609 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
610 |
|
.5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); |
611 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
611 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
612 |
|
return(rval); |
613 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
613 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
614 |
|
return(rval); |
615 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
615 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
616 |
|
return(rval); |
617 |
|
strcpy(r1, r2); |
618 |
|
sprintf(r2, FLTFMT, -avgrad - .5*(maxrad-minrad)*sin(theta)); |
619 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
619 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
620 |
|
return(rval); |
621 |
|
} |
622 |
|
warpconends = 0; |
637 |
|
avnew[2] = av[2]; |
638 |
|
avnew[3] = av[3]; |
639 |
|
avnew[4] = av[2]; |
640 |
< |
return(handle_it(MG_E_CONE, 5, avnew)); |
640 |
> |
return(mg_handle(MG_E_CONE, 5, avnew)); |
641 |
|
} |
642 |
|
|
643 |
|
|
679 |
|
make_axes(u, v, cv->n); |
680 |
|
for (j = 0; j < 3; j++) |
681 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*u[j]); |
682 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
682 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
683 |
|
return(rv); |
684 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
684 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
685 |
|
return(rv); |
686 |
|
if (minrad == 0.) { /* closed */ |
687 |
|
v1ent[3] = av[1]; |
688 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
688 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
689 |
|
return(rv); |
690 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, nzent)) != MG_OK) |
690 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, nzent)) != MG_OK) |
691 |
|
return(rv); |
692 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
693 |
|
theta = i*(PI/2)/mg_nqcdivs; |
694 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
694 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
695 |
|
return(rv); |
696 |
|
for (j = 0; j < 3; j++) |
697 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + |
698 |
|
maxrad*u[j]*cos(theta) + |
699 |
|
maxrad*v[j]*sin(theta)); |
700 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
700 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
701 |
|
return(rv); |
702 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
702 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
703 |
|
return(rv); |
704 |
< |
if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK) |
704 |
> |
if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK) |
705 |
|
return(rv); |
706 |
|
} |
707 |
|
} else { /* open */ |
708 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
708 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
709 |
|
return(rv); |
710 |
|
for (j = 0; j < 3; j++) |
711 |
|
sprintf(p4[j], FLTFMT, cv->p[j] + minrad*u[j]); |
712 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
712 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
713 |
|
return(rv); |
714 |
|
v1ent[3] = "_rv4"; |
715 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
716 |
|
theta = i*(PI/2)/mg_nqcdivs; |
717 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
717 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
718 |
|
return(rv); |
719 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
719 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
720 |
|
return(rv); |
721 |
|
for (j = 0; j < 3; j++) { |
722 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
723 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*d); |
724 |
|
sprintf(p4[j], FLTFMT, cv->p[j] + minrad*d); |
725 |
|
} |
726 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
726 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
727 |
|
return(rv); |
728 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
728 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
729 |
|
return(rv); |
730 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
730 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
731 |
|
return(rv); |
732 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
732 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
733 |
|
return(rv); |
734 |
< |
if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK) |
734 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK) |
735 |
|
return(rv); |
736 |
|
} |
737 |
|
} |
754 |
|
static char *p4ent[5] = {mg_ename[MG_E_POINT],p4[0],p4[1],p4[2]}; |
755 |
|
static char *n4ent[5] = {mg_ename[MG_E_NORMAL],n4[0],n4[1],n4[2]}; |
756 |
|
static char *fent[6] = {mg_ename[MG_E_FACE],"_cv1","_cv2","_cv3","_cv4"}; |
757 |
+ |
char *v1n; |
758 |
|
register C_VERTEX *cv1, *cv2; |
759 |
|
register int i, j; |
760 |
|
FVECT u, v, w; |
770 |
|
if ((cv1 = c_getvert(av[1])) == NULL || |
771 |
|
(cv2 = c_getvert(av[3])) == NULL) |
772 |
|
return(MG_EUNDEF); |
773 |
+ |
v1n = av[1]; |
774 |
|
if (!isflt(av[2]) || !isflt(av[4])) |
775 |
|
return(MG_ETYPE); |
776 |
|
rad1 = atof(av[2]); |
789 |
|
cv = cv1; |
790 |
|
cv1 = cv2; |
791 |
|
cv2 = cv; |
792 |
+ |
v1n = av[3]; |
793 |
|
d = rad1; |
794 |
|
rad1 = rad2; |
795 |
|
rad2 = d; |
816 |
|
else |
817 |
|
sprintf(n3[j], FLTFMT, u[j] + w[j]*n2off); |
818 |
|
} |
819 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
819 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
820 |
|
return(rv); |
821 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
821 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
822 |
|
return(rv); |
823 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
823 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
824 |
|
return(rv); |
825 |
|
if (rad1 == 0.) { /* triangles */ |
826 |
< |
v1ent[3] = av[1]; |
827 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
826 |
> |
v1ent[3] = v1n; |
827 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
828 |
|
return(rv); |
829 |
|
for (j = 0; j < 3; j++) |
830 |
|
sprintf(n4[j], FLTFMT, w[j]); |
831 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
831 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
832 |
|
return(rv); |
833 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
834 |
|
theta = sgn*i*(PI/2)/mg_nqcdivs; |
835 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
835 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
836 |
|
return(rv); |
837 |
|
for (j = 0; j < 3; j++) { |
838 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
840 |
|
if (n2off > -FHUGE) |
841 |
|
sprintf(n3[j], FLTFMT, d + w[j]*n2off); |
842 |
|
} |
843 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
843 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
844 |
|
return(rv); |
845 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
845 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
846 |
|
return(rv); |
847 |
|
if (n2off > -FHUGE && |
848 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
848 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
849 |
|
return(rv); |
850 |
< |
if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK) |
850 |
> |
if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK) |
851 |
|
return(rv); |
852 |
|
} |
853 |
|
} else { /* quads */ |
866 |
|
else |
867 |
|
sprintf(n4[j], FLTFMT, u[j] + w[j]*n1off); |
868 |
|
} |
869 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
869 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
870 |
|
return(rv); |
871 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
871 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
872 |
|
return(rv); |
873 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
873 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
874 |
|
return(rv); |
875 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
876 |
|
theta = sgn*i*(PI/2)/mg_nqcdivs; |
877 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
877 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
878 |
|
return(rv); |
879 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
879 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
880 |
|
return(rv); |
881 |
|
for (j = 0; j < 3; j++) { |
882 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
887 |
|
if (n1off < FHUGE) |
888 |
|
sprintf(n4[j], FLTFMT, d + w[j]*n1off); |
889 |
|
} |
890 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
890 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
891 |
|
return(rv); |
892 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
892 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
893 |
|
return(rv); |
894 |
|
if (n2off > -FHUGE && |
895 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
895 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
896 |
|
return(rv); |
897 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
897 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
898 |
|
return(rv); |
899 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
899 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
900 |
|
return(rv); |
901 |
|
if (n1off < FHUGE && |
902 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
902 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
903 |
|
return(rv); |
904 |
< |
if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK) |
904 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK) |
905 |
|
return(rv); |
906 |
|
} |
907 |
|
} |
915 |
|
char **av; |
916 |
|
{ |
917 |
|
static char p[3][24]; |
918 |
< |
static char *vent[4] = {mg_ename[MG_E_VERTEX],NULL,"="}; |
918 |
> |
static char *vent[5] = {mg_ename[MG_E_VERTEX],NULL,"="}; |
919 |
|
static char *pent[5] = {mg_ename[MG_E_POINT],p[0],p[1],p[2]}; |
920 |
+ |
static char *znorm[5] = {mg_ename[MG_E_NORMAL],"0","0","0"}; |
921 |
|
char *newav[MG_MAXARGC], nvn[MG_MAXARGC-1][8]; |
922 |
|
double length; |
923 |
+ |
int hasnorm; |
924 |
|
FVECT v1, v2, v3, norm; |
925 |
|
register C_VERTEX *cv; |
926 |
|
C_VERTEX *cv0; |
927 |
|
int rv; |
928 |
|
register int i, j; |
929 |
< |
|
929 |
> |
/* check arguments */ |
930 |
|
if (ac < 5) |
931 |
|
return(MG_EARGC); |
932 |
|
if (!isflt(av[ac-1])) |
934 |
|
length = atof(av[ac-1]); |
935 |
|
if (length <= FTINY && length >= -FTINY) |
936 |
|
return(MG_EILL); |
937 |
< |
/* do bottom face */ |
924 |
< |
newav[0] = mg_ename[MG_E_FACE]; |
925 |
< |
for (i = 1; i < ac-1; i++) |
926 |
< |
newav[i] = av[i]; |
927 |
< |
newav[i] = NULL; |
928 |
< |
if ((rv = handle_it(MG_E_FACE, i, newav)) != MG_OK) |
929 |
< |
return(rv); |
930 |
< |
/* compute face normal */ |
937 |
> |
/* compute face normal */ |
938 |
|
if ((cv0 = c_getvert(av[1])) == NULL) |
939 |
|
return(MG_EUNDEF); |
940 |
+ |
hasnorm = 0; |
941 |
|
norm[0] = norm[1] = norm[2] = 0.; |
942 |
|
v1[0] = v1[1] = v1[2] = 0.; |
943 |
|
for (i = 2; i < ac-1; i++) { |
944 |
|
if ((cv = c_getvert(av[i])) == NULL) |
945 |
|
return(MG_EUNDEF); |
946 |
+ |
hasnorm += !is0vect(cv->n); |
947 |
|
v2[0] = cv->p[0] - cv0->p[0]; |
948 |
|
v2[1] = cv->p[1] - cv0->p[1]; |
949 |
|
v2[2] = cv->p[2] - cv0->p[2]; |
955 |
|
} |
956 |
|
if (normalize(norm) == 0.) |
957 |
|
return(MG_EILL); |
958 |
< |
/* create moved vertices */ |
958 |
> |
/* create moved vertices */ |
959 |
|
for (i = 1; i < ac-1; i++) { |
960 |
|
sprintf(nvn[i-1], "_pv%d", i); |
961 |
|
vent[1] = nvn[i-1]; |
962 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, vent)) != MG_OK) |
962 |
> |
vent[3] = av[i]; |
963 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
964 |
|
return(rv); |
965 |
|
cv = c_getvert(av[i]); /* checked above */ |
966 |
|
for (j = 0; j < 3; j++) |
967 |
|
sprintf(p[j], FLTFMT, cv->p[j] - length*norm[j]); |
968 |
< |
if ((rv = handle_it(MG_E_POINT, 4, pent)) != MG_OK) |
968 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, pent)) != MG_OK) |
969 |
|
return(rv); |
960 |
– |
newav[ac-1-i] = nvn[i-1]; /* reverse */ |
970 |
|
} |
971 |
< |
/* do top face */ |
972 |
< |
if ((rv = handle_it(MG_E_FACE, ac-1, newav)) != MG_OK) |
964 |
< |
return(rv); |
971 |
> |
/* make faces */ |
972 |
> |
newav[0] = mg_ename[MG_E_FACE]; |
973 |
|
/* do the side faces */ |
974 |
|
newav[5] = NULL; |
975 |
|
newav[3] = av[ac-2]; |
977 |
|
for (i = 1; i < ac-1; i++) { |
978 |
|
newav[1] = nvn[i-1]; |
979 |
|
newav[2] = av[i]; |
980 |
< |
if ((rv = handle_it(MG_E_FACE, 5, newav)) != MG_OK) |
980 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, newav)) != MG_OK) |
981 |
|
return(rv); |
982 |
|
newav[3] = newav[2]; |
983 |
|
newav[4] = newav[1]; |
984 |
|
} |
985 |
+ |
/* do top face */ |
986 |
+ |
for (i = 1; i < ac-1; i++) { |
987 |
+ |
if (hasnorm) { /* zero normals */ |
988 |
+ |
vent[1] = nvn[i-1]; |
989 |
+ |
if ((rv = mg_handle(MG_E_VERTEX, 2, vent)) != MG_OK) |
990 |
+ |
return(rv); |
991 |
+ |
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
992 |
+ |
return(rv); |
993 |
+ |
} |
994 |
+ |
newav[ac-1-i] = nvn[i-1]; /* reverse */ |
995 |
+ |
} |
996 |
+ |
if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK) |
997 |
+ |
return(rv); |
998 |
+ |
/* do bottom face */ |
999 |
+ |
if (hasnorm) |
1000 |
+ |
for (i = 1; i < ac-1; i++) { |
1001 |
+ |
vent[1] = nvn[i-1]; |
1002 |
+ |
vent[3] = av[i]; |
1003 |
+ |
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
1004 |
+ |
return(rv); |
1005 |
+ |
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
1006 |
+ |
return(rv); |
1007 |
+ |
newav[i] = nvn[i-1]; |
1008 |
+ |
} |
1009 |
+ |
else |
1010 |
+ |
for (i = 1; i < ac-1; i++) |
1011 |
+ |
newav[i] = av[i]; |
1012 |
+ |
newav[i] = NULL; |
1013 |
+ |
if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK) |
1014 |
+ |
return(rv); |
1015 |
|
return(MG_OK); |
1016 |
|
} |
1017 |
|
|
1018 |
|
|
1019 |
|
static int |
1020 |
< |
e_cspec(ac, av) /* handle spectral color */ |
983 |
< |
int ac; |
984 |
< |
char **av; |
1020 |
> |
put_cxy() /* put out current xy chromaticities */ |
1021 |
|
{ |
1022 |
|
static char xbuf[24], ybuf[24]; |
1023 |
|
static char *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf}; |
1024 |
|
int rv; |
1025 |
|
|
1026 |
+ |
sprintf(xbuf, "%.4f", c_ccolor->cx); |
1027 |
+ |
sprintf(ybuf, "%.4f", c_ccolor->cy); |
1028 |
+ |
if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK) |
1029 |
+ |
return(rv); |
1030 |
+ |
return(MG_OK); |
1031 |
+ |
} |
1032 |
+ |
|
1033 |
+ |
|
1034 |
+ |
static int |
1035 |
+ |
put_cspec() /* put out current color spectrum */ |
1036 |
+ |
{ |
1037 |
+ |
char wl[2][6], vbuf[C_CNSS][24]; |
1038 |
+ |
char *newav[C_CNSS+4]; |
1039 |
+ |
double sf; |
1040 |
+ |
register int i; |
1041 |
+ |
|
1042 |
+ |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
1043 |
+ |
sprintf(wl[0], "%d", C_CMINWL); |
1044 |
+ |
sprintf(wl[1], "%d", C_CMAXWL); |
1045 |
+ |
newav[0] = mg_ename[MG_E_CSPEC]; |
1046 |
+ |
newav[1] = wl[0]; |
1047 |
+ |
newav[2] = wl[1]; |
1048 |
+ |
sf = (double)C_CNSS / c_ccolor->ssum; |
1049 |
+ |
for (i = 0; i < C_CNSS; i++) { |
1050 |
+ |
sprintf(vbuf[i], "%.4f", sf*c_ccolor->ssamp[i]); |
1051 |
+ |
newav[i+3] = vbuf[i]; |
1052 |
+ |
} |
1053 |
+ |
newav[C_CNSS+3] = NULL; |
1054 |
+ |
if ((i = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
1055 |
+ |
return(i); |
1056 |
+ |
} |
1057 |
+ |
return(MG_OK); |
1058 |
+ |
} |
1059 |
+ |
|
1060 |
+ |
|
1061 |
+ |
static int |
1062 |
+ |
e_cspec(ac, av) /* handle spectral color */ |
1063 |
+ |
int ac; |
1064 |
+ |
char **av; |
1065 |
+ |
{ |
1066 |
+ |
/* convert to xy chromaticity */ |
1067 |
|
c_ccvt(c_ccolor, C_CSXY); |
1068 |
|
/* if it's really their handler, use it */ |
1069 |
< |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
1070 |
< |
sprintf(xbuf, "%.4f", c_ccolor->cx); |
994 |
< |
sprintf(ybuf, "%.4f", c_ccolor->cy); |
995 |
< |
if ((rv = handle_it(MG_E_CXY, 3, ccom)) != MG_OK) |
996 |
< |
return(rv); |
997 |
< |
} |
1069 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1070 |
> |
return(put_cxy()); |
1071 |
|
return(MG_OK); |
1072 |
|
} |
1073 |
|
|
1077 |
|
int ac; |
1078 |
|
char **av; |
1079 |
|
{ |
1007 |
– |
char wl[2][6], vbuf[C_CNSS][24]; |
1008 |
– |
char *newav[C_CNSS+4]; |
1009 |
– |
int rv; |
1010 |
– |
register int i; |
1080 |
|
/* |
1081 |
|
* Contorted logic works as follows: |
1082 |
|
* 1. the colors are already mixed in c_hcolor() support function |
1087 |
|
*/ |
1088 |
|
if (mg_ehand[MG_E_CSPEC] == e_cspec) |
1089 |
|
c_ccvt(c_ccolor, C_CSXY); |
1090 |
< |
else if (c_ccolor->flags & C_CDSPEC) { |
1091 |
< |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
1092 |
< |
sprintf(wl[0], "%d", C_CMINWL); |
1093 |
< |
sprintf(wl[1], "%d", C_CMAXWL); |
1094 |
< |
newav[0] = mg_ename[MG_E_CSPEC]; |
1095 |
< |
newav[1] = wl[0]; |
1096 |
< |
newav[2] = wl[1]; |
1097 |
< |
for (i = 0; i < C_CNSS; i++) { |
1098 |
< |
sprintf(vbuf[i], "%.6f", |
1099 |
< |
(double)c_ccolor->ssamp[i] / |
1100 |
< |
c_ccolor->ssum); |
1101 |
< |
newav[i+3] = vbuf[i]; |
1102 |
< |
} |
1103 |
< |
newav[C_CNSS+3] = NULL; |
1104 |
< |
if ((rv = handle_it(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
1105 |
< |
return(rv); |
1106 |
< |
} |
1107 |
< |
return(MG_OK); |
1108 |
< |
} |
1109 |
< |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
1110 |
< |
sprintf(vbuf[0], "%.4f", c_ccolor->cx); |
1111 |
< |
sprintf(vbuf[1], "%.4f", c_ccolor->cy); |
1112 |
< |
newav[0] = mg_ename[MG_E_CXY]; |
1113 |
< |
newav[1] = vbuf[0]; |
1045 |
< |
newav[2] = vbuf[1]; |
1046 |
< |
newav[3] = NULL; |
1047 |
< |
if ((rv = handle_it(MG_E_CXY, 3, newav)) != MG_OK) |
1048 |
< |
return(rv); |
1049 |
< |
} |
1090 |
> |
else if (c_ccolor->flags & C_CDSPEC) |
1091 |
> |
return(put_cspec()); |
1092 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1093 |
> |
return(put_cxy()); |
1094 |
> |
return(MG_OK); |
1095 |
> |
} |
1096 |
> |
|
1097 |
> |
|
1098 |
> |
static int |
1099 |
> |
e_cct(ac, av) /* handle color temperature */ |
1100 |
> |
int ac; |
1101 |
> |
char **av; |
1102 |
> |
{ |
1103 |
> |
/* |
1104 |
> |
* Logic is similar to e_cmix here. Support handler has already |
1105 |
> |
* converted temperature to spectral color. Put it out as such |
1106 |
> |
* if they support it, otherwise convert to xy chromaticity and |
1107 |
> |
* put it out if they handle it. |
1108 |
> |
*/ |
1109 |
> |
if (mg_ehand[MG_E_CSPEC] != e_cspec) |
1110 |
> |
return(put_cspec()); |
1111 |
> |
c_ccvt(c_ccolor, C_CSXY); |
1112 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1113 |
> |
return(put_cxy()); |
1114 |
|
return(MG_OK); |
1115 |
|
} |