--- ray/src/util/rtcontrib.c 2005/10/06 16:28:59 1.32 +++ ray/src/util/rtcontrib.c 2005/10/11 16:54:26 1.35 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rtcontrib.c,v 1.32 2005/10/06 16:28:59 greg Exp $"; +static const char RCSid[] = "$Id: rtcontrib.c,v 1.35 2005/10/11 16:54:26 greg Exp $"; #endif /* * Gather rtrace output to compute contributions from particular sources @@ -63,10 +63,13 @@ static void closestream(void *p) { STREAMOUT *sop = (STREAMOUT *)p; + int status; if (sop->reclen == CNT_PIPE) - pclose(sop->ofp); + status = pclose(sop->ofp); else - fclose(sop->ofp); + status = fclose(sop->ofp); + if (status) + error(SYSTEM, "error closing output stream"); free(p); } @@ -120,6 +123,7 @@ int inpfmt = 'a'; /* input format */ int outfmt = 'a'; /* output format */ int header = 1; /* output header? */ +int force_open = 0; /* truncate existing output? */ int xres = 0; /* horiz. output resolution */ int yres = 0; /* vert. output resolution */ @@ -263,7 +267,7 @@ main(int argc, char *argv[]) continue; } break; - case 'f': /* file or i/o format */ + case 'f': /* file or force or format */ if (!argv[i][2]) { char *fpath; if (i >= argc-2) break; @@ -278,6 +282,10 @@ main(int argc, char *argv[]) fcompile(fpath); continue; } + if (argv[i][2] == 'o') { + force_open++; + continue; + } setformat(argv[i]+2); continue; case 'e': /* expression */ @@ -699,15 +707,17 @@ getostream(const char *ospec, const char *mname, int b sop = (STREAMOUT *)malloc(sizeof(STREAMOUT)); if (sop == NULL) error(SYSTEM, "out of memory in getostream"); - sop->reclen = oname[0] == '!' ? CNT_PIPE : 0; + sop->reclen = oname[0] == '!' ? CNT_PIPE : CNT_UNKNOWN; sop->ofp = NULL; /* open iff noopen==0 */ lep->data = (char *)sop; } if (!noopen && sop->ofp == NULL) { /* open output stream */ - int i; + long i; if (oname[0] == '!') /* output to command */ sop->ofp = popen(oname+1, "w"); - else + else if (!force_open && access(oname, F_OK) == 0) + errno = EEXIST; /* file exists */ + else /* else open it */ sop->ofp = fopen(oname, "w"); if (sop->ofp == NULL) { sprintf(errmsg, "cannot open '%s' for writing", oname); @@ -731,7 +741,8 @@ getostream(const char *ospec, const char *mname, int b } printresolu(sop->ofp); /* play catch-up */ - for (i = 0; i < lastdone; i++) { + for (i = sop->reclen > 1 ? sop->reclen*lastdone : lastdone; + i--; ) { static const DCOLOR nocontrib = BLKCOLOR; put_contrib(nocontrib, sop->ofp); if (outfmt == 'a') @@ -1039,10 +1050,11 @@ trace_contribs(FILE *fin) /* loop over input */ while ((iblen = getinp(inpbuf, fin)) > 0) { if (lastray+1 < lastray || /* need reset? */ - queue_length() > 5*nrtprocs()) { + queue_length() > 10*nrtprocs()) { while (wait_rproc() != NULL) process_queue(); - lastdone = lastray = 0; + if (lastray+1 < lastray) + lastdone = lastray = 0; } rtp = get_rproc(); /* get avail. rtrace process */ rtp->raynum = ++lastray; /* assign ray to it */ @@ -1125,7 +1137,7 @@ recover_output(FILE *fin) if (oent->data != NULL) { sout = *(STREAMOUT *)oent->data; } else { - sout.reclen = 0; + sout.reclen = CNT_UNKNOWN; sout.ofp = NULL; } if (sout.ofp != NULL) { /* already open? */