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.31 by greg, Thu Oct 6 05:49:44 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 75 | Line 78 | LUTAB  ofiletab = LU_SINIT(free,closestream);  /* output
78   #define OF_MODIFIER     01
79   #define OF_BIN          02
80  
81 < STREAMOUT *getostream(const char *ospec, const char *mname, int bn, int bincnt);
81 > STREAMOUT *getostream(const char *ospec, const char *mname, int bn, int noopen);
82   int ofname(char *oname, const char *ospec, const char *mname, int bn);
83   void printheader(FILE *fout, const char *info);
84   void printresolu(FILE *fout);
# 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 505 | Line 513 | addmodifier(char *modn, char *outf, char *binv, int bi
513   {
514          LUENT   *lep = lu_find(&modconttab, modn);
515          MODCONT *mp;
516 +        int     i;
517          
518          if (lep->data != NULL) {
519                  sprintf(errmsg, "duplicate modifier '%s'", modn);
# Line 517 | Line 526 | addmodifier(char *modn, char *outf, char *binv, int bi
526          mp = (MODCONT *)malloc(sizeof(MODCONT));
527          if (mp == NULL)
528                  error(SYSTEM, "out of memory in addmodifier");
520        lep->data = (char *)mp;
529          mp->outspec = outf;             /* XXX assumes static string */
530          mp->modname = modn;             /* XXX assumes static string */
531          if (binv != NULL)
# Line 530 | Line 538 | addmodifier(char *modn, char *outf, char *binv, int bi
538                  bincnt = 1;
539          else if (bincnt > 1)
540                  mp = growmodifier(mp, bincnt);
541 <        if (bincnt > 0)                 /* allocate output stream */
542 <                getostream(mp->outspec, mp->modname, 0, bincnt);
541 >        lep->data = (char *)mp;
542 >                                        /* allocate output streams */
543 >        for (i = outf==NULL || outf[0]=='!' ? 0 : bincnt; i--; )
544 >                getostream(mp->outspec, mp->modname, i, 1);
545          return mp;
546   }
547  
# Line 660 | Line 670 | printresolu(FILE *fout)
670          }
671   }
672  
673 < /* Get output stream pointer (open and write header if new and bincnt==0) */
673 > /* Get output stream pointer (open and write header if new and noopen==0) */
674   STREAMOUT *
675 < getostream(const char *ospec, const char *mname, int bn, int bincnt)
675 > getostream(const char *ospec, const char *mname, int bn, int noopen)
676   {
677          static STREAMOUT        stdos;
678          int                     ofl;
# Line 671 | Line 681 | getostream(const char *ospec, const char *mname, int b
681          STREAMOUT               *sop;
682          
683          if (ospec == NULL) {                    /* use stdout? */
684 <                if (!bincnt && !using_stdout) {
684 >                if (!noopen && !using_stdout) {
685                          stdos.reclen = 0;
686                          if (outfmt != 'a')
687                                  SET_FILE_BINARY(stdout);
# Line 681 | Line 691 | getostream(const char *ospec, const char *mname, int b
691                          using_stdout = 1;
692                  }
693                  stdos.ofp = stdout;
694 <                stdos.reclen += bincnt;
694 >                stdos.reclen += noopen;
695                  return &stdos;
696          }
697          ofl = ofname(oname, ospec, mname, bn);  /* get output name */
# Line 694 | Line 704 | getostream(const char *ospec, const char *mname, int b
704                  lep->key = strcpy((char *)malloc(strlen(oname)+1), oname);
705          sop = (STREAMOUT *)lep->data;
706          if (sop == NULL) {                      /* allocate stream */
697                if (ofl & OF_BIN && bincnt > 1) /* don't overcount bins */
698                        bincnt = 1;
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;
711 <                sop->ofp = NULL;                /* open iff bincnt==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 (!bincnt && sop->ofp == NULL) {      /* open output stream */
715 <                int             i;
714 >        if (!noopen && sop->ofp == NULL) {      /* open output stream */
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 718 | Line 728 | getostream(const char *ospec, const char *mname, int b
728                  if (header) {
729                          char    info[512];
730                          char    *cp = info;
731 <                        if (ofl & OF_MODIFIER) {
731 >                        if (ofl & OF_MODIFIER || sop->reclen == 1) {
732                                  sprintf(cp, "MODIFIER=%s\n", mname);
733                                  while (*cp) ++cp;
734                          }
# 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 740 | Line 751 | getostream(const char *ospec, const char *mname, int b
751                  if (xres > 0)
752                          fflush(sop->ofp);
753          }
754 <        if (sop->reclen != CNT_PIPE)            /* add bincnt to count */
755 <                sop->reclen += bincnt;
754 >        if (sop->reclen != CNT_PIPE)            /* add to length if noopen */
755 >                sop->reclen += noopen;
756          return sop;                             /* return open stream */
757   }
758  
# 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? */
# Line 1148 | Line 1160 | recover_output(FILE *fin)
1160                                  fclose(sout.ofp);
1161                                  break;
1162                          }
1163 <                        if (!sout.reclen) {     /* unspecified record length */
1163 >                        if (sout.reclen == CNT_UNKNOWN) {
1164                                  if (!(ofl & OF_BIN)) {
1165                                          sprintf(errmsg,
1166 <                                                "guessing 1 value per record in '%s'",
1166 >                                                "need -bn to recover file '%s'",
1167                                                          oname);
1168 <                                        error(WARNING, errmsg);
1168 >                                        error(USER, errmsg);
1169                                  }
1170                                  recsiz = outvsiz;
1171                          } else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines