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.5 by schorsch, Sun Jun 8 12:03:09 2003 UTC vs.
Revision 1.10 by greg, Thu Nov 6 05:39:33 2003 UTC

# Line 15 | Line 15 | static const char RCSid[] = "$Id$";
15  
16   #include  "platform.h"
17   #include  "calcomp.h"
18 + #include  "rterror.h"
19  
19 #ifdef  CPM
20 #define  getc           agetc   /* text files only, right? */
21 #endif
22
20   #define  isnum(c)       (isdigit(c) || (c)=='-' || (c)=='.' \
21                                  || (c)=='+' || (c)=='e' || (c)=='E')
22  
# Line 57 | Line 54 | struct field {                  /* record format struc
54   #define  savqstr(s)     strcpy(emalloc(strlen(s)+1),s)
55   #define  freqstr(s)     efree(s)
56  
57 + static int getinputrec(FILE *fp);
58   static void scaninp(void), advinp(void), resetinp(void);
59   static void putrec(void), putout(void), nbsynch(void);
60   static int getrec(void);
# Line 69 | Line 67 | static int getfield(struct field *f);
67   static void chanset(int n, double v);
68   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 */
# Line 112 | Line 111 | char  *argv[]
111          biggerlib();
112   #endif
113          varset("PI", ':', 3.14159265358979323846);
114 +        funset("in", 1, '=', &l_in);
115  
116          for (i = 1; i < argc && argv[i][0] == '-'; i++)
117                  switch (argv[i][1]) {
# Line 150 | Line 150 | char  *argv[]
150                                          nbicols = atoi(argv[i]+3);
151                                  else
152                                          nbicols = 1;
153 +                                if (nbicols*sizeof(double) > INBSIZ) {
154 +                                        eputs(argv[0]);
155 +                                        eputs(": too many input columns\n");
156 +                                        quit(1);
157 +                                }
158                                  break;
159                          case 'f':
160                                  if (isdigit(argv[i][3]))
161                                          nbicols = -atoi(argv[i]+3);
162                                  else
163                                          nbicols = -1;
164 +                                if (-nbicols*sizeof(float) > INBSIZ) {
165 +                                        eputs(argv[0]);
166 +                                        eputs(": too many input columns\n");
167 +                                        quit(1);
168 +                                }
169                                  break;
170                          default:
171                                  goto userr;
# Line 223 | Line 233 | nbsynch(void)               /* non-blank starting sync
233   }
234  
235  
236 < int
236 > static int
237   getinputrec(            /* get next input record */
238   FILE  *fp
239   )
# Line 291 | Line 301 | putout(void)                /* produce an output recor
301   }
302  
303  
304 + static double
305 + l_in(char *funame)      /* function call for $channel */
306 + {
307 +        int  n;
308 +        register char  *cp;
309 +                        /* get argument as integer */
310 +        n = (int)(argument(1) + .5);
311 +        if (n != 0)     /* return channel value */
312 +                return(chanvalue(n));
313 +                        /* determine number of channels */
314 +        if (noinput || inpfmt != NULL)
315 +                return(0);
316 +        if (nbicols > 0)
317 +                return(nbicols);
318 +        if (nbicols < 0)
319 +                return(-nbicols);
320 +        cp = inpbuf;    /* need to count */
321 +        for (n = 0; *cp; )
322 +                if (blnkeq && isspace(sepchar)) {
323 +                        while (isspace(*cp))
324 +                                cp++;
325 +                        n += *cp != '\0';
326 +                        while (*cp && !isspace(*cp))
327 +                                cp++;
328 +                } else {
329 +                        n += *cp != '\n';
330 +                        while (*cp && *cp++ != sepchar)
331 +                                ;
332 +                }
333 +        return(n);
334 + }
335 +
336   double
337   chanvalue(            /* return value for column n */
338   int  n
# Line 616 | Line 658 | getfield(                             /* get next fiel
658   register struct field  *f
659   )
660   {
661 <        static char  buf[MAXWORD+1];            /* no recursion! */
661 >        static char  buf[RMAXWORD+1];            /* no recursion! */
662          int  delim, inword;
663          double  d;
664          char  *np;
# Line 649 | Line 691 | register struct field  *f
691                          delim = f->next->f.sl[0];
692                  cp = buf;
693                  do {
694 <                        if (ipb.chr == EOF)
694 >                        if (ipb.chr == EOF || ipb.chr == '\n')
695                                  inword = 0;
696                          else if (blnkeq && delim != EOF)
697                                  inword = isblnk(delim) ?
# Line 661 | Line 703 | register struct field  *f
703                                  *cp++ = ipb.chr;
704                                  scaninp();
705                          }
706 <                } while (inword && cp < &buf[MAXWORD]);
706 >                } while (inword && cp < &buf[RMAXWORD]);
707                  *cp = '\0';
708                  if (f->f.sv->val == NULL)
709                          f->f.sv->val = savqstr(buf);    /* first setting */
# Line 690 | Line 732 | register struct field  *f
732                                  *cp++ = ipb.chr;
733                                  scaninp();
734                          }
735 <                } while (inword && cp < &buf[MAXWORD]);
735 >                } while (inword && cp < &buf[RMAXWORD]);
736                  *cp = '\0';
737                  d = np==NULL ? 0. : atof(np);
738                  if (!vardefined(f->f.nv))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines