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.9 by greg, Wed Nov 5 19:03:03 2003 UTC vs.
Revision 1.17 by greg, Wed Feb 16 17:20:22 2005 UTC

# Line 8 | Line 8 | static const char RCSid[] = "$Id$";
8   */
9  
10   #include  <stdlib.h>
11 + #include  <fcntl.h>
12   #include  <stdio.h>
13   #include  <string.h>
14   #include  <math.h>
15   #include  <ctype.h>
16  
17   #include  "platform.h"
17 #include  "calcomp.h"
18   #include  "rterror.h"
19 + #include  "rtmisc.h"
20 + #include  "rtio.h"
21 + #include  "calcomp.h"
22  
23   #define  isnum(c)       (isdigit(c) || (c)=='-' || (c)=='.' \
24                                  || (c)=='+' || (c)=='e' || (c)=='E')
25  
26   #define  isblnk(c)      (igneol ? isspace(c) : (c)==' '||(c)=='\t')
27  
28 < #define  INBSIZ         4096    /* longest record */
28 > #define  INBSIZ         16384   /* longest record */
29   #define  MAXCOL         32      /* number of columns recorded */
30  
31                                  /* field type specifications */
# Line 54 | Line 57 | struct field {                  /* record format struc
57   #define  savqstr(s)     strcpy(emalloc(strlen(s)+1),s)
58   #define  freqstr(s)     efree(s)
59  
60 + static int getinputrec(FILE *fp);
61   static void scaninp(void), advinp(void), resetinp(void);
62   static void putrec(void), putout(void), nbsynch(void);
63   static int getrec(void);
# Line 66 | Line 70 | static int getfield(struct field *f);
70   static void chanset(int n, double v);
71   static void bchanset(int n, double v);
72   static struct strvar* getsvar(char *svname);
73 + static double l_in(char *);
74  
75   struct field  *inpfmt = NULL;   /* input record format */
76   struct field  *outfmt = NULL;   /* output record structure */
# Line 73 | Line 78 | struct strvar  *svhead = NULL;  /* string variables */
78  
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? */
84   int  nbicols = 0;               /* number of binary input columns */
# Line 109 | Line 115 | char  *argv[]
115          biggerlib();
116   #endif
117          varset("PI", ':', 3.14159265358979323846);
118 +        funset("in", 1, '=', &l_in);
119  
120          for (i = 1; i < argc && argv[i][0] == '-'; i++)
121                  switch (argv[i][1]) {
# Line 118 | Line 125 | char  *argv[]
125                  case 'l':
126                          igneol = !igneol;
127                          break;
128 +                case 'p':
129 +                        passive = !passive;
130 +                        break;
131                  case 't':
132                          sepchar = argv[i][2];
133                          break;
# Line 195 | Line 205 | char  *argv[]
205                  userr:
206                          eputs("Usage: ");
207                          eputs(argv[0]);
208 < eputs(" [-b][-l][-n][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n");
208 > eputs(" [-b][-l][-n][-p][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n");
209                          quit(1);
210                  }
211  
212          if (noinput) {          /* produce a single output record */
213 +                if (i < argc) {
214 +                        eputs(argv[0]);
215 +                        eputs(": file argument(s) incompatible with -n\n");
216 +                        quit(1);
217 +                }
218                  eclock++;
219                  putout();
220                  quit(0);
# Line 215 | Line 230 | eputs(" [-b][-l][-n][-w][-u][-tS][-s svar=sval][-e exp
230                          execute(argv[i]);
231          
232          quit(0);
233 +        return 0; /* pro forma return */
234   }
235  
236  
# Line 230 | Line 246 | nbsynch(void)               /* non-blank starting sync
246   }
247  
248  
249 < int
249 > static int
250   getinputrec(            /* get next input record */
251   FILE  *fp
252   )
# Line 298 | Line 314 | putout(void)                /* produce an output recor
314   }
315  
316  
317 + static double
318 + l_in(char *funame)      /* function call for $channel */
319 + {
320 +        int  n;
321 +        register char  *cp;
322 +                        /* get argument as integer */
323 +        n = (int)(argument(1) + .5);
324 +        if (n != 0)     /* return channel value */
325 +                return(chanvalue(n));
326 +                        /* determine number of channels */
327 +        if (noinput || inpfmt != NULL)
328 +                return(0);
329 +        if (nbicols > 0)
330 +                return(nbicols);
331 +        if (nbicols < 0)
332 +                return(-nbicols);
333 +        cp = inpbuf;    /* need to count */
334 +        for (n = 0; *cp; )
335 +                if (blnkeq && isspace(sepchar)) {
336 +                        while (isspace(*cp))
337 +                                cp++;
338 +                        n += *cp != '\0';
339 +                        while (*cp && !isspace(*cp))
340 +                                cp++;
341 +                } else {
342 +                        n += *cp != '\n';
343 +                        while (*cp && *cp++ != sepchar)
344 +                                ;
345 +                }
346 +        return(n);
347 + }
348 +
349   double
350   chanvalue(            /* return value for column n */
351   int  n
# Line 411 | Line 459 | int  output
459                          eputs(": cannot open\n");
460                          quit(1);
461                  }
462 <                res = read(fd, inpbuf+1, INBSIZ-1);
462 >                res = read(fd, inpbuf+2, INBSIZ-2);
463                  if (res <= 0 || res >= INBSIZ-1) {
464                          eputs(spec);
465                          if (res < 0)
# Line 423 | Line 471 | int  output
471                          quit(1);
472                  }
473                  close(fd);
474 <                (inptr=inpbuf+1)[res] = '\0';
474 >                (inptr=inpbuf+2)[res] = '\0';
475          }
476          f = &fmt;                               /* get fields */
477          while ((res = readfield(&inptr)) != F_NUL) {
# Line 585 | Line 633 | clearrec(void)                 /* clear input record variables */
633  
634  
635   static int
636 < getrec(void)                                /* get next record from file */
636 > getrec(void)                            /* get next record from file */
637   {
638          int  eatline;
639          register struct field  *f;
640 <        
640 >
641          while (ipb.chr != EOF) {
594                eatline = !igneol && ipb.chr != '\n';
642                  if (blnkeq)             /* beware of nbsynch() */
643                          while (isblnk(ipb.chr))
644 <                                scaninp();
644 >                                resetinp();
645 >                eatline = (!igneol && ipb.chr != '\n');
646                  clearrec();             /* start with fresh record */
647                  for (f = inpfmt; f != NULL; f = f->next)
648                          if (getfield(f) == -1)
649                                  break;
650                  if (f == NULL) {
651 <                        advinp();
651 >                        advinp();       /* got one! */
652                          return(1);
653                  }
654 <                resetinp();
654 >                resetinp();             /* eat false start */
655                  if (eatline) {          /* eat rest of line */
656                          while (ipb.chr != '\n') {
657                                  if (ipb.chr == EOF)
658                                          return(0);
659 <                                scaninp();
659 >                                resetinp();
660                          }
661 <                        scaninp();
614 <                        advinp();
661 >                        resetinp();
662                  }
663          }
664          return(0);
# Line 808 | Line 855 | resetinp(void)                      /* rewind position
855                  ipb.beg = ipb.end;
856          ipb.pos = ipb.beg;
857          ipb.chr = *ipb.pos;
858 +        if (passive)                    /* transmit unmatched character? */
859 +                fputc(ipb.chr, stdout);
860          if (++ipb.beg >= &inpbuf[INBSIZ])
861                  ipb.beg = inpbuf;
862          scaninp();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines