--- ray/src/rt/rcontrib.c 2020/09/10 00:45:01 2.38 +++ ray/src/rt/rcontrib.c 2021/02/21 17:18:41 2.41 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcontrib.c,v 2.38 2020/09/10 00:45:01 greg Exp $"; +static const char RCSid[] = "$Id: rcontrib.c,v 2.41 2021/02/21 17:18:41 greg Exp $"; #endif /* * Accumulate ray contributions for a set of materials @@ -102,14 +102,19 @@ addmodifier(char *modn, char *outf, char *prms, char * sprintf(errmsg, "duplicate modifier '%s'", modn); error(USER, errmsg); } - if (nmods >= MAXMODLIST) { - sprintf(errmsg, "too many modifiers (%d limit)", MAXMODLIST); - error(INTERNAL, errmsg); - } if (!strcmp(modn, VOIDID)) { sprintf(errmsg, "cannot track '%s' modifier", VOIDID); error(USER, errmsg); } + if (nmods >= modasiz) { /* need bigger modifier array */ + modasiz += modasiz/2 + 64; + if (modname == NULL) + modname = (char **)malloc(modasiz*sizeof(char *)); + else + modname = (char **)realloc(modname, modasiz*sizeof(char *)); + if (modname == NULL) + error(SYSTEM, "Out of memory in addmodifier()"); + } modname[nmods++] = modn; /* XXX assumes static string */ lep->key = modn; /* XXX assumes static string */ if (binv == NULL) @@ -154,21 +159,20 @@ addmodifier(char *modn, char *outf, char *prms, char * void addmodfile(char *fname, char *outf, char *prms, char *binv, int bincnt) { - char *mname[MAXMODLIST]; - int i; - /* find the file & store strings */ - i = wordfile(mname, MAXMODLIST, getpath(fname, getrlibpath(), R_OK)); - if (i < 0) { - sprintf(errmsg, "cannot find modifier file '%s'", fname); + char *path = getpath(fname, getrlibpath(), R_OK); + char mod[MAXSTR]; + FILE *fp; + + if (path == NULL || (fp = fopen(path, "r")) == NULL) { + if (path == NULL) + sprintf(errmsg, "cannot find modifier file '%s'", fname); + else + sprintf(errmsg, "cannot load modifier file '%s'", path); error(SYSTEM, errmsg); } - if (i >= MAXMODLIST-1) { - sprintf(errmsg, "too many modifiers (%d limit) in file '%s'", - MAXMODLIST-1, fname); - error(INTERNAL, errmsg); - } - for (i = 0; mname[i]; i++) /* add each one */ - addmodifier(mname[i], outf, prms, binv, bincnt); + while (fgetword(mod, sizeof(mod), fp) != NULL) + addmodifier(savqstr(mod), outf, prms, binv, bincnt); + fclose(fp); } @@ -187,11 +191,12 @@ morays(void) if (!total_rays) { total_rays = raysleft; tstart = tnow; + } else { + sprintf(errmsg, "%.2f%% done after %.3f hours\n", + 100.-100.*raysleft/total_rays, + (1./3600.)*(tnow - tstart)); + eputs(errmsg); } - sprintf(errmsg, "%.2f%% done after %.3f hours\n", - 100.-100.*raysleft/total_rays, - (1./3600.)*(tnow - tstart)); - eputs(errmsg); last_report = tnow; } return(--raysleft);