ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rtcontrib.c
(Generate patch)

Comparing ray/src/util/rtcontrib.c (file contents):
Revision 1.32 by greg, Thu Oct 6 16:28:59 2005 UTC vs.
Revision 1.35 by greg, Tue Oct 11 16:54:26 2005 UTC

# Line 63 | Line 63 | static void
63   closestream(void *p)
64   {
65          STREAMOUT       *sop = (STREAMOUT *)p;
66 +        int             status;
67          if (sop->reclen == CNT_PIPE)
68 <                pclose(sop->ofp);
68 >                status = pclose(sop->ofp);
69          else
70 <                fclose(sop->ofp);
70 >                status = fclose(sop->ofp);
71 >        if (status)
72 >                error(SYSTEM, "error closing output stream");
73          free(p);
74   }
75  
# Line 120 | Line 123 | int            inpfmt = 'a';           /* input format */
123   int             outfmt = 'a';           /* output format */
124  
125   int             header = 1;             /* output header? */
126 + int             force_open = 0;         /* truncate existing output? */
127   int             xres = 0;               /* horiz. output resolution */
128   int             yres = 0;               /* vert. output resolution */
129  
# Line 263 | Line 267 | main(int argc, char *argv[])
267                                          continue;
268                                  }
269                                  break;
270 <                        case 'f':               /* file or i/o format */
270 >                        case 'f':               /* file or force or format */
271                                  if (!argv[i][2]) {
272                                          char    *fpath;
273                                          if (i >= argc-2) break;
# Line 278 | Line 282 | main(int argc, char *argv[])
282                                          fcompile(fpath);
283                                          continue;
284                                  }
285 +                                if (argv[i][2] == 'o') {
286 +                                        force_open++;
287 +                                        continue;
288 +                                }
289                                  setformat(argv[i]+2);
290                                  continue;
291                          case 'e':               /* expression */
# Line 699 | Line 707 | getostream(const char *ospec, const char *mname, int b
707                  sop = (STREAMOUT *)malloc(sizeof(STREAMOUT));
708                  if (sop == NULL)
709                          error(SYSTEM, "out of memory in getostream");
710 <                sop->reclen = oname[0] == '!' ? CNT_PIPE : 0;
710 >                sop->reclen = oname[0] == '!' ? CNT_PIPE : CNT_UNKNOWN;
711                  sop->ofp = NULL;                /* open iff noopen==0 */
712                  lep->data = (char *)sop;
713          }
714          if (!noopen && sop->ofp == NULL) {      /* open output stream */
715 <                int             i;
715 >                long            i;
716                  if (oname[0] == '!')            /* output to command */
717                          sop->ofp = popen(oname+1, "w");
718 <                else
718 >                else if (!force_open && access(oname, F_OK) == 0)
719 >                        errno = EEXIST;         /* file exists */
720 >                else                            /* else open it */
721                          sop->ofp = fopen(oname, "w");
722                  if (sop->ofp == NULL) {
723                          sprintf(errmsg, "cannot open '%s' for writing", oname);
# Line 731 | Line 741 | getostream(const char *ospec, const char *mname, int b
741                  }
742                  printresolu(sop->ofp);
743                                                  /* play catch-up */
744 <                for (i = 0; i < lastdone; i++) {
744 >                for (i = sop->reclen > 1 ? sop->reclen*lastdone : lastdone;
745 >                                                                i--; ) {
746                          static const DCOLOR     nocontrib = BLKCOLOR;
747                          put_contrib(nocontrib, sop->ofp);
748                          if (outfmt == 'a')
# Line 1039 | Line 1050 | trace_contribs(FILE *fin)
1050                                                  /* loop over input */
1051          while ((iblen = getinp(inpbuf, fin)) > 0) {
1052                  if (lastray+1 < lastray ||      /* need reset? */
1053 <                                queue_length() > 5*nrtprocs()) {
1053 >                                queue_length() > 10*nrtprocs()) {
1054                          while (wait_rproc() != NULL)
1055                                  process_queue();
1056 <                        lastdone = lastray = 0;
1056 >                        if (lastray+1 < lastray)
1057 >                                lastdone = lastray = 0;
1058                  }
1059                  rtp = get_rproc();              /* get avail. rtrace process */
1060                  rtp->raynum = ++lastray;        /* assign ray to it */
# Line 1125 | Line 1137 | recover_output(FILE *fin)
1137                          if (oent->data != NULL) {
1138                                  sout = *(STREAMOUT *)oent->data;
1139                          } else {
1140 <                                sout.reclen = 0;
1140 >                                sout.reclen = CNT_UNKNOWN;
1141                                  sout.ofp = NULL;
1142                          }
1143                          if (sout.ofp != NULL) { /* already open? */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines