--- ray/src/util/rtcontrib.c 2005/06/11 15:01:03 1.21 +++ ray/src/util/rtcontrib.c 2005/09/21 17:17:24 1.28 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rtcontrib.c,v 1.21 2005/06/11 15:01:03 greg Exp $"; +static const char RCSid[] = "$Id: rtcontrib.c,v 1.28 2005/09/21 17:17:24 greg Exp $"; #endif /* * Gather rtrace output to compute contributions from particular sources @@ -173,6 +173,13 @@ main(int argc, char *argv[]) char *binval = NULL; char fmt[8]; int i, j; + /* need at least one argument */ + if (argc < 2) { + fprintf(stderr, +"Usage: %s [-n nprocs][-r][-e expr][-f source][-o ospec][-b binv] {-m mod | -M file} [rtrace options] octree\n", + argv[0]); + exit(1); + } /* global program name */ gargv = argv; /* initialize calcomp routines */ @@ -315,20 +322,23 @@ main(int argc, char *argv[]) error(USER, "missing octree argument"); rtargv[rtargc++] = octree = argv[i]; rtargv[rtargc] = NULL; - /* start rtrace & compute contributions */ + /* start rtrace */ init(nprocs); if (recover) /* perform recovery if requested */ recover_output(stdin); - trace_contribs(stdin); + trace_contribs(stdin); /* compute contributions */ quit(0); } +#ifndef SIGALRM +#define SIGALRM SIGTERM +#endif /* kill persistent rtrace process */ static void killpersist(void) { FILE *fp = fopen(persistfn, "r"); - int pid; + RT_PID pid; if (fp == NULL) return; @@ -623,10 +633,8 @@ getofile(const char *ospec, const char *mname, int bn) if (header) { char info[512]; char *cp = info; - if (ofl & OF_MODIFIER) { - sprintf(cp, "MODIFIER=%s\n", mname); - while (*cp) ++cp; - } + sprintf(cp, "MODIFIER=%s\n", mname); + while (*cp) ++cp; if (ofl & OF_BIN) { sprintf(cp, "BIN=%d\n", bn); while (*cp) ++cp; @@ -708,7 +716,7 @@ add_contrib(const char *modn) bn = (int)(evalue(mp->binv) + .5); if (bn <= 0) bn = 0; - else if (bn > mp->nbins) { /* new bin */ + else if (bn >= mp->nbins) { /* new bin */ mp = (MODCONT *)realloc(mp, sizeof(MODCONT) + bn*sizeof(DCOLOR)); if (mp == NULL) @@ -907,7 +915,7 @@ wait_rproc(void) if (rt->bsiz + BUFSIZ <= treebufsiz) rt->bsiz = treebufsiz; else - rt->bsiz = treebufsiz += BUFSIZ; + treebufsiz = rt->bsiz += BUFSIZ; rt->buf = (char *)realloc(rt->buf, rt->bsiz); } if (rt->buf == NULL) @@ -1032,8 +1040,13 @@ recover_output(FILE *fin) error(USER, "cannot recover from command"); /* open output */ fp = fopen(oname, "rb+"); - if (fp == NULL) - break; /* must be end of modifier */ + if (fp == NULL) { + if (j) + break; /* assume end of modifier */ + sprintf(errmsg, "missing recover file '%s'", + oname); + error(USER, errmsg); + } nvals = lseek(fileno(fp), 0, SEEK_END); if (nvals <= 0) { lastout = 0; /* empty output, quit here */ @@ -1088,10 +1101,15 @@ recover_output(FILE *fin) error(WARNING, "no output files to recover"); return; } + if (raysleft && lastout >= raysleft) { + error(WARNING, "output appears to be complete"); + /* XXX should read & discard input? */ + quit(0); + } /* seek on all files */ nvals = lastout * outvsiz; lu_doall(&ofiletab, myseeko, &nvals); - /* discard input */ + /* skip repeated input */ for (nvals = 0; nvals < lastout; nvals++) if (getinp(oname, fin) <= 0) error(USER, "unexpected EOF on input");