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

Comparing ray/src/cal/rcalc.c (file contents):
Revision 1.31 by greg, Mon Feb 21 23:00:55 2022 UTC vs.
Revision 1.32 by greg, Fri Mar 11 22:50:13 2022 UTC

# Line 55 | Line 55 | struct field {          /* record format structure */
55   #define freqstr(s) efree(s)
56  
57   static int getinputrec(FILE *fp);
58 < static void scaninp(void), advinp(void), skipinp(void);
58 > static void scaninp(void), advinp(void), passinp(void), skipinp(void);
59   static void putrec(void), putout(void), nbsynch(void);
60   static int getrec(void);
61   static void execute(char *file);
# Line 69 | Line 69 | static void bchanset(int n, double v);
69   static struct strvar* getsvar(char *svname);
70   static double l_in(char *);
71  
72 < struct field *inpfmt = NULL; /* input record format */
73 < struct field *outfmt = NULL; /* output record structure */
74 < struct strvar *svhead = NULL; /* string variables */
72 > struct field *inpfmt = NULL;    /* input record format */
73 > struct field *outfmt = NULL;    /* output record structure */
74 > struct strvar *svhead = NULL;   /* string variables */
75  
76 < long incnt = 0;         /* limit number of input records? */
76 > long incnt = 0;                 /* limit number of input records? */
77   long outcnt = 0;                /* limit number of output records? */
78  
79 < int blnkeq = 1;         /* blanks compare equal? */
80 < int igneol = 0;         /* ignore end of line? */
79 > int blnkeq = 1;                 /* blanks compare equal? */
80 > int igneol = 0;                 /* ignore end of line? */
81   int passive = 0;                /* passive mode (transmit unmatched input) */
82 < char sepchar = '\t';     /* input/output separator */
83 < int noinput = 0;         /* no input records? */
82 > char sepchar = '\t';            /* input/output separator */
83 > int noinput = 0;                /* no input records? */
84   int itype = 'a';                /* input type (a/f/F/d/D) */
85   int nbicols = 0;                /* number of binary input columns */
86   int otype = 'a';                /* output format (a/f/F/d/D) */
87 < char inpbuf[INBSIZ];     /* input buffer */
88 < double colval[MAXCOL];   /* input column values */
89 < unsigned long colflg = 0; /* column retrieved flags */
90 < int colpos;              /* output column position */
87 > char inpbuf[INBSIZ];            /* input buffer */
88 > double colval[MAXCOL];          /* input column values */
89 > unsigned long colflg = 0;       /* column retrieved flags */
90 > int colpos;                     /* output column position */
91  
92 < int nowarn = 0;         /* non-fatal diagnostic output */
93 < int unbuff = 0;         /* unbuffered output (flush each record) */
92 > int nowarn = 0;                 /* non-fatal diagnostic output */
93 > int unbuff = 0;                 /* unbuffered output (flush each record) */
94  
95   struct {
96          FILE *fin;               /* input file */
# Line 128 | Line 128 | char *argv[]
128                          igneol = !igneol;
129                          break;
130                  case 'p':
131 <                        passive = !passive;
131 >                        passive = 1;
132                          break;
133 +                case 'P':
134 +                        passive = -1;
135 +                        break;
136                  case 't':
137                          sepchar = argv[i][2];
138                          break;
# Line 229 | Line 232 | char *argv[]
232                  userr:
233                          eputs("Usage: ");
234                          eputs(argv[0]);
235 < eputs(" [-b][-l][-n][-p][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n");
235 > eputs(" [-b][-l][-n][-p|-P][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n");
236                          quit(1);
237                  }
238          if (otype != 'a')
# Line 247 | Line 250 | eputs(" [-b][-l][-n][-p][-w][-u][-tS][-s svar=sval][-e
250                  putout();
251                  quit(0);
252          }
253 +        if (passive && (inpfmt == NULL) | (outfmt == NULL)) {
254 +                eputs(argv[0]);
255 +                eputs(": options -p and -P require -i and -o formats\n");
256 +                quit(1);
257 +        }
258          if (blnkeq)      /* for efficiency */
259                  nbsynch();
260  
# Line 278 | Line 286 | getinputrec(           /* get next input record */
286   FILE *fp
287   )
288   {
281        if (inpfmt != NULL)
282                return(getrec());
289          if ((itype == 'd') | (itype == 'D')) {
290                  if (getbinary(inpbuf, sizeof(double), nbicols, fp) != nbicols)
291                          return(0);
# Line 325 | Line 331 | char *file
331          if (inpfmt != NULL)
332                  initinp(fp);
333          
334 <        while (getinputrec(fp)) {
334 >        while (inpfmt != NULL ? getrec() : getinputrec(fp)) {
335                  ++nrecs;
336                  if (set_recno)
337                          varset("recno", '=', (double)nrecs);
# Line 336 | Line 342 | char *file
342                  if (!conditional || varvalue("cond") > 0.0) {
343                          putout();
344                          ++nout;
345 +                        advinp();
346 +                } else if (inpfmt != NULL) {
347 +                        if (passive < 0)
348 +                                passinp();
349 +                        else
350 +                                advinp();
351                  }
352                  if (incnt && nrecs >= incnt)
353                          break;
# Line 688 | Line 700 | clearrec(void)                 /* clear input record variables */
700  
701  
702   static int
703 < getrec(void)                            /* get next record from file */
703 > getrec(void)                    /* get next record from file */
704   {
705          int eatline;
706          struct field *f;
# Line 705 | Line 717 | getrec(void)                           /* get next record from file */
717                  for (f = inpfmt; f != NULL; f = f->next)
718                          if (!getfield(f))
719                                  break;
720 <                if (f == NULL) {
709 <                        advinp(); /* got one! */
720 >                if (f == NULL)          /* got one? */
721                          return(1);
722 <                }
723 <                skipinp();              /* eat false start */
713 <                if (eatline) {   /* eat rest of line */
722 >                skipinp();              /* else eat false start */
723 >                if (eatline) {          /* eat rest of line */
724                          while (ipb.chr != '\n') {
725                                  if (ipb.chr == EOF)
726                                          return(0);
# Line 919 | Line 929 | advinp(void)                   /* move home to current position */
929  
930  
931   static void
932 < skipinp(void)            /* rewind position and advance 1 */
932 > passinp(void)                   /* pass beginning to current position */
933   {
934 <        if (ipb.beg == NULL)    /* full */
934 >        if (!passive | (ipb.beg == NULL)) {
935 >                advinp();
936 >                return;
937 >        }
938 >        while (ipb.beg != ipb.pos) {    /* transfer buffer unaltered */
939 >                putchar(*ipb.beg);
940 >                if (++ipb.beg >= &inpbuf[INBSIZ])
941 >                        ipb.beg = inpbuf;
942 >        }
943 > }
944 >
945 >
946 > static void
947 > skipinp(void)                   /* rewind position and advance 1 */
948 > {
949 >        if (ipb.beg == NULL)            /* full */
950                  ipb.beg = ipb.end;
951          ipb.pos = ipb.beg;
952          ipb.chr = *ipb.pos;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines