--- ray/src/util/rtcontrib.c 2010/06/11 20:26:09 1.56 +++ ray/src/util/rtcontrib.c 2011/04/04 22:17:35 1.61 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rtcontrib.c,v 1.56 2010/06/11 20:26:09 greg Exp $"; +static const char RCSid[] = "$Id: rtcontrib.c,v 1.61 2011/04/04 22:17:35 greg Exp $"; #endif /* * Gather rtrace output to compute contributions from particular sources @@ -20,7 +20,7 @@ static const char RCSid[] = "$Id: rtcontrib.c,v 1.56 2 #define MAXMODLIST 1024 /* maximum modifiers we'll track */ #endif -int treebufsiz = BUFSIZ; /* current tree buffer size */ +size_t treebufsiz = BUFSIZ; /* current tree buffer size */ typedef double DCOLOR[3]; /* double-precision color */ @@ -92,9 +92,9 @@ struct rtproc { struct rtproc *next; /* next in list of processes */ SUBPROC pd; /* rtrace pipe descriptors */ unsigned long raynum; /* ray number for this tree */ - int bsiz; /* ray tree buffer length */ + size_t bsiz; /* ray tree buffer length */ char *buf; /* ray tree buffer */ - int nbr; /* number of bytes from rtrace */ + size_t nbr; /* number of bytes from rtrace */ }; /* rtrace process buffer */ /* rtrace command and defaults */ @@ -107,8 +107,8 @@ int rtargc = 9; char *myrtopts[] = { "-h-", "-x", "1", "-y", "0", "-dt", "0", "-as", "0", "-aa", "0", NULL }; -#define RTCOEFF "-o~~TmWdp" /* compute coefficients only */ -#define RTCONTRIB "-o~~TmVdp" /* compute ray contributions */ +#define RTCOEFF "-o~~~~TmWdp" /* compute coefficients only */ +#define RTCONTRIB "-o~~~~TmVdp" /* compute ray contributions */ struct rtproc rt0; /* head of rtrace process list */ @@ -545,7 +545,7 @@ init(int np) raysleft = 0; if ((account = accumulate) > 0) raysleft *= accumulate; - waitflush = xres; + waitflush = (yres > 0) & (xres > 1) ? 0 : xres; if (!recover) return; /* recover previous values */ @@ -736,8 +736,6 @@ printresolu(FILE *fout, int xr, int yr) { if ((xr > 0) & (yr > 0)) /* resolution string */ fprtresolu(xr, yr, fout); - if (xres > 0) /* global flush flag */ - fflush(fout); } /* Get output stream pointer (open and write header if new and noopen==0) */ @@ -758,6 +756,8 @@ getostream(const char *ospec, const char *mname, int b if (header) printheader(stdout, NULL); printresolu(stdout, xres, yres); + if (waitflush > 0) + fflush(stdout); stdos.xr = xres; stdos.yr = yres; using_stdout = 1; } @@ -826,7 +826,7 @@ getostream(const char *ospec, const char *mname, int b if (outfmt == 'a') putc('\n', sop->ofp); } - if (xres > 0) + if (waitflush > 0) fflush(sop->ofp); } sop->reclen += noopen; /* add to length if noopen */ @@ -993,7 +993,7 @@ done_contrib(int navg) if (using_stdout & (outfmt == 'a')) putc('\n', stdout); if (!waitflush) { - waitflush = xres; + waitflush = (yres > 0) & (xres > 1) ? 0 : xres; if (using_stdout) fflush(stdout); } @@ -1075,7 +1075,7 @@ wait_rproc(void) { struct rtproc *rtfree = NULL; fd_set readset, errset; - int nr; + ssize_t nr; struct rtproc *rt; int n; @@ -1120,9 +1120,9 @@ wait_rproc(void) if (nr <= 0) error(USER, "rtrace process died"); rt->nbr += nr; /* advance & check */ - if (rt->nbr >= 4 && !memcmp(rt->buf+rt->nbr-4, - "~\t~\t", 4)) { - rt->nbr -= 4; /* elide terminator */ + if (rt->nbr >= 8 && !memcmp(rt->buf+rt->nbr-8, + "~\t~\t~\t~\t", 8)) { + rt->nbr -= 8; /* elide terminator */ queue_raytree(rt); rtfree = rt; /* ready for next ray */ }