8 |
|
#include <signal.h> |
9 |
|
#include <ctype.h> |
10 |
|
|
11 |
< |
#include "rtprocess.h" /* win_popen() */ |
11 |
> |
#include "paths.h" /* win_popen() */ |
12 |
|
#include "mkillum.h" |
13 |
|
|
14 |
|
/* default parameters */ |
24 |
|
|
25 |
|
struct illum_args thisillum = { /* our illum and default values */ |
26 |
|
0, |
27 |
– |
UDzpos, |
28 |
– |
0., |
27 |
|
DFLMAT, |
28 |
|
DFLDAT, |
29 |
|
0, |
30 |
|
VOIDID, |
31 |
|
SAMPDENS, |
32 |
|
NSAMPS, |
35 |
– |
NULL, |
33 |
|
0., |
34 |
|
}; |
35 |
|
|
45 |
|
int warnings = 1; /* print warnings? */ |
46 |
|
|
47 |
|
void init(char *octnm, int np); |
48 |
< |
void filter(register FILE *infp, char *name); |
48 |
> |
void filter(FILE *infp, char *name); |
49 |
|
void xoptions(char *s, char *nm); |
50 |
|
void printopts(void); |
51 |
< |
void printhead(register int ac, register char **av); |
51 |
> |
void printhead(int ac, char **av); |
52 |
|
void xobject(FILE *fp, char *nm); |
53 |
|
|
54 |
|
|
61 |
|
int nprocs = 1; |
62 |
|
FILE *fp; |
63 |
|
int rval; |
64 |
< |
register int i; |
64 |
> |
int i; |
65 |
|
/* set global arguments */ |
66 |
|
gargv = argv; |
67 |
|
progname = gargv[0]; |
148 |
|
|
149 |
|
void |
150 |
|
eputs( /* put string to stderr */ |
151 |
< |
register char *s |
151 |
> |
const char *s |
152 |
|
) |
153 |
|
{ |
154 |
|
static int midline = 0; |
164 |
|
|
165 |
|
|
166 |
|
void |
167 |
< |
wputs(s) /* print warning if enabled */ |
171 |
< |
char *s; |
167 |
> |
wputs(const char *s) /* print warning if enabled */ |
168 |
|
{ |
169 |
|
if (warnings) |
170 |
|
eputs(s); |
172 |
|
|
173 |
|
|
174 |
|
void |
175 |
< |
quit(ec) /* make sure exit is called */ |
180 |
< |
int ec; |
175 |
> |
quit(int ec) /* make sure exit is called */ |
176 |
|
{ |
177 |
|
if (ray_pnprocs > 0) /* close children if any */ |
178 |
< |
ray_pclose(0); |
178 |
> |
ray_pclose(0); |
179 |
> |
else if (ray_pnprocs < 0) |
180 |
> |
_exit(ec); /* avoid flush() in child */ |
181 |
|
exit(ec); |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
void |
186 |
|
filter( /* process stream */ |
187 |
< |
register FILE *infp, |
187 |
> |
FILE *infp, |
188 |
|
char *name |
189 |
|
) |
190 |
|
{ |
191 |
|
char buf[512]; |
192 |
|
FILE *pfp; |
193 |
< |
register int c; |
193 |
> |
int c; |
194 |
|
|
195 |
|
while ((c = getc(infp)) != EOF) { |
196 |
|
if (isspace(c)) |
207 |
|
error(SYSTEM, errmsg); |
208 |
|
} |
209 |
|
filter(pfp, buf); |
210 |
< |
pclose(pfp); |
210 |
> |
if (pclose(pfp) != 0) { |
211 |
> |
sprintf(errmsg, "bad status from \"%s\"", buf); |
212 |
> |
error(USER, errmsg); |
213 |
> |
} |
214 |
|
} else { /* object */ |
215 |
|
ungetc(c, infp); |
216 |
|
xobject(infp, name); |
225 |
|
char *nm |
226 |
|
) |
227 |
|
{ |
228 |
– |
extern FILE *freopen(); |
228 |
|
char buf[64]; |
229 |
|
int negax; |
230 |
|
int nerrs = 0; |
231 |
< |
register char *cp; |
231 |
> |
char *cp; |
232 |
|
|
233 |
|
if (strncmp(s, "#@mkillum", 9) || !isspace(s[9])) { |
234 |
|
fputs(s, stdout); /* not for us */ |
306 |
|
} |
307 |
|
cp = sskip(cp); |
308 |
|
continue; |
309 |
< |
case 'd': /* sample density / BSDF data */ |
309 |
> |
case 'd': /* sample density */ |
310 |
|
if (*++cp != '=') |
311 |
|
break; |
313 |
– |
if (thisillum.sd != NULL) { |
314 |
– |
free_BSDF(thisillum.sd); |
315 |
– |
thisillum.sd = NULL; |
316 |
– |
} |
312 |
|
if (!*++cp || isspace(*cp)) |
313 |
|
continue; |
314 |
|
if (isintd(cp, " \t\n\r")) { |
315 |
|
thisillum.sampdens = atoi(cp); |
316 |
|
} else { |
317 |
< |
atos(buf, sizeof(buf), cp); |
318 |
< |
thisillum.sd = load_BSDF(buf); |
324 |
< |
if (thisillum.sd == NULL) |
325 |
< |
break; |
317 |
> |
error(WARNING, "direct BSDF input unsupported"); |
318 |
> |
goto opterr; |
319 |
|
} |
320 |
|
cp = sskip(cp); |
321 |
|
continue; |
361 |
|
} |
362 |
|
doneheader = 0; |
363 |
|
continue; |
371 |
– |
case 'u': /* up direction */ |
372 |
– |
if (*++cp != '=') |
373 |
– |
break; |
374 |
– |
if (!*++cp || isspace(*cp)) { |
375 |
– |
thisillum.udir = UDunknown; |
376 |
– |
continue; |
377 |
– |
} |
378 |
– |
negax = 0; |
379 |
– |
if (*cp == '+') |
380 |
– |
cp++; |
381 |
– |
else if (*cp == '-') { |
382 |
– |
negax++; |
383 |
– |
cp++; |
384 |
– |
} |
385 |
– |
switch (*cp++) { |
386 |
– |
case 'x': |
387 |
– |
case 'X': |
388 |
– |
thisillum.udir = negax ? UDxneg : UDxpos; |
389 |
– |
break; |
390 |
– |
case 'y': |
391 |
– |
case 'Y': |
392 |
– |
thisillum.udir = negax ? UDyneg : UDypos; |
393 |
– |
break; |
394 |
– |
case 'z': |
395 |
– |
case 'Z': |
396 |
– |
thisillum.udir = negax ? UDzneg : UDzpos; |
397 |
– |
break; |
398 |
– |
default: |
399 |
– |
thisillum.udir = UDunknown; |
400 |
– |
break; |
401 |
– |
} |
402 |
– |
if (thisillum.udir == UDunknown || !isspace(*cp)) |
403 |
– |
break; |
404 |
– |
continue; |
405 |
– |
case 't': /* object thickness */ |
406 |
– |
if (*++cp != '=') |
407 |
– |
break; |
408 |
– |
if (!isfltd(++cp, " \t\n\r")) |
409 |
– |
break; |
410 |
– |
thisillum.thick = atof(cp); |
411 |
– |
if (thisillum.thick < .0) |
412 |
– |
thisillum.thick = .0; |
413 |
– |
cp = sskip(cp); |
414 |
– |
continue; |
364 |
|
case '!': /* processed file! */ |
365 |
|
sprintf(errmsg, "(%s): already processed!", nm); |
366 |
|
error(WARNING, errmsg); |
406 |
|
printf("d=%d\t\t\t\t# density of directions\n", thisillum.sampdens); |
407 |
|
printf("s=%d\t\t\t\t# samples per direction\n", thisillum.nsamps); |
408 |
|
printf("b=%f\t\t\t# minimum average brightness\n", thisillum.minbrt); |
460 |
– |
switch (thisillum.udir) { |
461 |
– |
case UDzneg: |
462 |
– |
fputs("u=-Z\t\t\t\t# up is negative Z\n", stdout); |
463 |
– |
break; |
464 |
– |
case UDyneg: |
465 |
– |
fputs("u=-Y\t\t\t\t# up is negative Y\n", stdout); |
466 |
– |
break; |
467 |
– |
case UDxneg: |
468 |
– |
fputs("u=-X\t\t\t\t# up is negative X\n", stdout); |
469 |
– |
break; |
470 |
– |
case UDxpos: |
471 |
– |
fputs("u=+X\t\t\t\t# up is positive X\n", stdout); |
472 |
– |
break; |
473 |
– |
case UDypos: |
474 |
– |
fputs("u=+Y\t\t\t\t# up is positive Y\n", stdout); |
475 |
– |
break; |
476 |
– |
case UDzpos: |
477 |
– |
fputs("u=+Z\t\t\t\t# up is positive Z\n", stdout); |
478 |
– |
break; |
479 |
– |
case UDunknown: |
480 |
– |
break; |
481 |
– |
} |
482 |
– |
printf("t=%f\t\t\t# object thickness\n", thisillum.thick); |
409 |
|
} |
410 |
|
|
411 |
|
|
412 |
|
void |
413 |
|
printhead( /* print out header */ |
414 |
< |
register int ac, |
415 |
< |
register char **av |
414 |
> |
int ac, |
415 |
> |
char **av |
416 |
|
) |
417 |
|
{ |
418 |
|
putchar('#'); |