--- ray/src/gen/mkillum.c 1994/01/07 14:51:28 2.7 +++ ray/src/gen/mkillum.c 2003/11/16 10:29:38 2.19 @@ -1,19 +1,17 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: mkillum.c,v 2.19 2003/11/16 10:29:38 schorsch Exp $"; #endif - /* * Make illum sources for optimizing rendering process */ -#include "mkillum.h" - #include - #include +#include "platform.h" +#include "mkillum.h" +#include "random.h" + /* default parameters */ #define SAMPDENS 48 /* points per projected steradian */ #define NSAMPS 32 /* samples per point */ @@ -27,10 +25,11 @@ static char SCCSid[] = "$SunId$ LBL"; /* rtrace command and defaults */ char *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-dv-", - "-ab", "2", "-ad", "256", "-as", "128", "-aa", ".15", }; + "-ab", "2", "-ad", "1024", "-as", "512", "-aa", ".1", }; int rtargc = 14; /* overriding rtrace options */ -char *myrtopts[] = { "-I-", "-i-", "-ov", "-h-", "-fff", "-y", "0", NULL }; +char *myrtopts[] = { "-I-", "-i-", "-ld-", "-ov", "-h-", + "-fff", "-y", "0", NULL }; struct rtproc rt; /* our rtrace process */ @@ -59,16 +58,20 @@ int doneheader = 0; /* printed header yet? */ int warnings = 1; /* print warnings? */ -extern char *fgetline(), *fgetword(), *sskip(), - *atos(), *iskip(), *fskip(), *strcpy(); -extern FILE *popen(); +void init(void); +void filter(register FILE *infp, char *name); +void xoptions(char *s, char *nm); +void printopts(void); +void printhead(register int ac, register char **av); +void xobject(FILE *fp, char *nm); -main(argc, argv) /* compute illum distributions using rtrace */ -int argc; -char *argv[]; +int +main( /* compute illum distributions using rtrace */ + int argc, + char *argv[] +) { - extern char *getenv(), *getpath(); char *rtpath; FILE *fp; register int i; @@ -133,27 +136,29 @@ char *argv[]; } else filter(stdin, "standard input"); - quit(0); + return 0; } +void quit(status) /* exit with status */ int status; { int rtstat; - rtstat = close_process(rt.pd); - if (status == 0) + rtstat = close_process(&(rt.pd)); + if (status == 0) { if (rtstat < 0) error(WARNING, "unknown return status from rtrace process"); else status = rtstat; + } exit(status); } - -init() /* start rtrace and set up buffers */ +void +init(void) /* start rtrace and set up buffers */ { extern int o_face(), o_sphere(), o_ring(); int maxbytes; @@ -162,10 +167,12 @@ init() /* start rtrace and set up buffers */ ofun[OBJ_SPHERE].funp = o_sphere; ofun[OBJ_RING].funp = o_ring; /* set up signal handling */ +#ifdef SIGPIPE /* not present on Windows */ signal(SIGPIPE, quit); +#endif /* start rtrace process */ errno = 0; - maxbytes = open_process(rt.pd, rtargv); + maxbytes = open_process(&(rt.pd), rtargv); if (maxbytes == 0) { eputs(rtargv[0]); eputs(": command not found\n"); @@ -184,8 +191,10 @@ init() /* start rtrace and set up buffers */ } -eputs(s) /* put string to stderr */ -register char *s; +void +eputs( /* put string to stderr */ + register char *s +) { static int midline = 0; @@ -199,6 +208,7 @@ register char *s; } +void wputs(s) /* print warning if enabled */ char *s; { @@ -207,9 +217,11 @@ char *s; } -filter(infp, name) /* process stream */ -register FILE *infp; -char *name; +void +filter( /* process stream */ + register FILE *infp, + char *name +) { char buf[512]; FILE *pfp; @@ -239,9 +251,11 @@ char *name; } -xoptions(s, nm) /* process options in string s */ -char *s; -char *nm; +void +xoptions( /* process options in string s */ + char *s, + char *nm +) { extern FILE *freopen(); char buf[64]; @@ -258,12 +272,14 @@ char *nm; case ' ': case '\t': case '\n': + case '\r': + case '\f': cp++; continue; case 'm': /* material name */ if (*++cp != '=') break; - if (!*++cp) + if (!*++cp || isspace(*cp)) break; atos(thisillum.matname, MAXSTR, cp); cp = sskip(cp); @@ -275,7 +291,7 @@ char *nm; case 'f': /* data file name */ if (*++cp != '=') break; - if (!*++cp) { + if (!*++cp || isspace(*cp)) { strcpy(thisillum.datafile,thisillum.matname); thisillum.dfnum = 0; thisillum.flags &= ~IL_DATCLB; @@ -325,7 +341,7 @@ char *nm; case 'd': /* point sample density */ if (*++cp != '=') break; - if (!isintd(++cp, " \t\n")) + if (!isintd(++cp, " \t\n\r")) break; thisillum.sampdens = atoi(cp); cp = sskip(cp); @@ -333,7 +349,7 @@ char *nm; case 's': /* point super-samples */ if (*++cp != '=') break; - if (!isintd(++cp, " \t\n")) + if (!isintd(++cp, " \t\n\r")) break; thisillum.nsamps = atoi(cp); cp = sskip(cp); @@ -351,7 +367,7 @@ char *nm; case 'b': /* brightness */ if (*++cp != '=') break; - if (!isfltd(++cp, " \t\n")) + if (!isfltd(++cp, " \t\n\r")) break; thisillum.minbrt = atof(cp); if (thisillum.minbrt < 0.) @@ -361,7 +377,7 @@ char *nm; case 'o': /* output file */ if (*++cp != '=') break; - if (!*++cp) + if (!*++cp || isspace(*cp)) break; atos(buf, sizeof(buf), cp); cp = sskip(cp); @@ -379,7 +395,8 @@ char *nm; return; } opterr: /* skip faulty option */ - cp = sskip(cp); + while (*cp && !isspace(*cp)) + cp++; nerrs++; } /* print header? */ @@ -397,8 +414,8 @@ char *nm; printf("# %s", s+2); } - -printopts() /* print out option default values */ +void +printopts(void) /* print out option default values */ { printf("m=%-15s\t\t# material name\n", thisillum.matname); printf("f=%-15s\t\t# data file name\n", thisillum.datafile); @@ -419,9 +436,11 @@ printopts() /* print out option default values */ } -printhead(ac, av) /* print out header */ -register int ac; -register char **av; +void +printhead( /* print out header */ + register int ac, + register char **av +) { putchar('#'); while (ac-- > 0) { @@ -432,9 +451,11 @@ register char **av; } -xobject(fp, nm) /* translate an object from fp */ -FILE *fp; -char *nm; +void +xobject( /* translate an object from fp */ + FILE *fp, + char *nm +) { OBJREC thisobj; char str[MAXSTR]; @@ -445,10 +466,10 @@ char *nm; if (fgetword(str, MAXSTR, fp) == NULL) goto readerr; /* is it an alias? */ - if (!strcmp(str, ALIASID)) { + if (!strcmp(str, ALIASKEY)) { if (fgetword(str, MAXSTR, fp) == NULL) goto readerr; - printf("\n%s %s %s", thisillum.altmat, ALIASID, str); + printf("\n%s %s %s", thisillum.altmat, ALIASKEY, str); if (fgetword(str, MAXSTR, fp) == NULL) goto readerr; printf("\t%s\n", str);