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.32 by greg, Fri Mar 11 22:50:13 2022 UTC vs.
Revision 1.34 by greg, Sat Mar 12 18:14:45 2022 UTC

# Line 309 | Line 309 | execute(        /* process a file */
309   char *file
310   )
311   {
312 <        const int conditional = vardefined("cond");
313 <        const int set_recno = (varlookup("recno") != NULL);
314 <        const int set_outno = (varlookup("outno") != NULL);
315 <        long nrecs = 0;
316 <        long nout = 0;
317 <        FILE *fp;
312 >        static char     condVN[] = "cond";
313 >        static char     recnoVN[] = "recno";
314 >        static char     outnoVN[] = "outno";
315 >        const int       conditional = vardefined(condVN);
316 >        const int       set_recno = (varlookup(recnoVN) != NULL);
317 >        const int       set_outno = (varlookup(outnoVN) != NULL);
318 >        long            nrecs = 0;
319 >        long            nout = 0;
320 >        FILE            *fp;
321          
322          if (file == NULL)
323                  fp = stdin;
# Line 328 | Line 331 | char *file
331   #ifdef getc_unlocked            /* avoid lock/unlock overhead */
332          flockfile(fp);
333   #endif
334 +        if (conditional == ':') {
335 +                eputs(condVN);
336 +                eputs(": defined as constant\n");
337 +                quit(1);
338 +        }
339          if (inpfmt != NULL)
340                  initinp(fp);
341          
342          while (inpfmt != NULL ? getrec() : getinputrec(fp)) {
343                  ++nrecs;
344                  if (set_recno)
345 <                        varset("recno", '=', (double)nrecs);
345 >                        varset(recnoVN, '=', (double)nrecs);
346                  if (set_outno)
347 <                        varset("outno", '=', (double)(nout+1));
347 >                        varset(outnoVN, '=', (double)(nout+1));
348                  colflg = 0;
349                  eclock++;
350 <                if (!conditional || varvalue("cond") > 0.0) {
350 >                if (!conditional || varvalue(condVN) > 0.0) {
351                          putout();
352                          ++nout;
353                          advinp();
# Line 931 | Line 939 | advinp(void)                   /* move home to current position */
939   static void
940   passinp(void)                   /* pass beginning to current position */
941   {
942 <        if (!passive | (ipb.beg == NULL)) {
943 <                advinp();
942 >        if (!passive) {
943 >                advinp();               /* mistake to call us */
944                  return;
945          }
946 +        if (ipb.beg == NULL)            /* buffer overflowed a bit */
947 +                ipb.beg = ipb.end;
948          while (ipb.beg != ipb.pos) {    /* transfer buffer unaltered */
949                  putchar(*ipb.beg);
950                  if (++ipb.beg >= &inpbuf[INBSIZ])
# Line 946 | Line 956 | passinp(void)                  /* pass beginning to current position
956   static void
957   skipinp(void)                   /* rewind position and advance 1 */
958   {
959 <        if (ipb.beg == NULL)            /* full */
959 >        if (ipb.beg == NULL)            /* overflow - can't fully rewind */
960                  ipb.beg = ipb.end;
961          ipb.pos = ipb.beg;
962          ipb.chr = *ipb.pos;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines