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.14 by greg, Mon Oct 11 10:02:15 2004 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')
# 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  
# Line 215 | Line 225 | eputs(" [-b][-l][-n][-w][-u][-tS][-s svar=sval][-e exp
225                          execute(argv[i]);
226          
227          quit(0);
228 +        return 0; /* pro forma return */
229   }
230  
231  
# Line 230 | Line 241 | nbsynch(void)               /* non-blank starting sync
241   }
242  
243  
244 < int
244 > static int
245   getinputrec(            /* get next input record */
246   FILE  *fp
247   )
# Line 298 | Line 309 | putout(void)                /* produce an output recor
309   }
310  
311  
312 + static double
313 + l_in(char *funame)      /* function call for $channel */
314 + {
315 +        int  n;
316 +        register char  *cp;
317 +                        /* get argument as integer */
318 +        n = (int)(argument(1) + .5);
319 +        if (n != 0)     /* return channel value */
320 +                return(chanvalue(n));
321 +                        /* determine number of channels */
322 +        if (noinput || inpfmt != NULL)
323 +                return(0);
324 +        if (nbicols > 0)
325 +                return(nbicols);
326 +        if (nbicols < 0)
327 +                return(-nbicols);
328 +        cp = inpbuf;    /* need to count */
329 +        for (n = 0; *cp; )
330 +                if (blnkeq && isspace(sepchar)) {
331 +                        while (isspace(*cp))
332 +                                cp++;
333 +                        n += *cp != '\0';
334 +                        while (*cp && !isspace(*cp))
335 +                                cp++;
336 +                } else {
337 +                        n += *cp != '\n';
338 +                        while (*cp && *cp++ != sepchar)
339 +                                ;
340 +                }
341 +        return(n);
342 + }
343 +
344   double
345   chanvalue(            /* return value for column n */
346   int  n
# Line 411 | Line 454 | int  output
454                          eputs(": cannot open\n");
455                          quit(1);
456                  }
457 <                res = read(fd, inpbuf+1, INBSIZ-1);
457 >                res = read(fd, inpbuf+2, INBSIZ-2);
458                  if (res <= 0 || res >= INBSIZ-1) {
459                          eputs(spec);
460                          if (res < 0)
# Line 423 | Line 466 | int  output
466                          quit(1);
467                  }
468                  close(fd);
469 <                (inptr=inpbuf+1)[res] = '\0';
469 >                (inptr=inpbuf+2)[res] = '\0';
470          }
471          f = &fmt;                               /* get fields */
472          while ((res = readfield(&inptr)) != F_NUL) {
# Line 585 | Line 628 | clearrec(void)                 /* clear input record variables */
628  
629  
630   static int
631 < getrec(void)                                /* get next record from file */
631 > getrec(void)                            /* get next record from file */
632   {
633          int  eatline;
634          register struct field  *f;
635 <        
635 >
636          while (ipb.chr != EOF) {
637                  eatline = !igneol && ipb.chr != '\n';
638                  if (blnkeq)             /* beware of nbsynch() */
639                          while (isblnk(ipb.chr))
640 <                                scaninp();
640 >                                resetinp();
641                  clearrec();             /* start with fresh record */
642                  for (f = inpfmt; f != NULL; f = f->next)
643                          if (getfield(f) == -1)
644                                  break;
645                  if (f == NULL) {
646 <                        advinp();
646 >                        advinp();       /* got one! */
647                          return(1);
648                  }
649 <                resetinp();
649 >                resetinp();             /* eat false start */
650                  if (eatline) {          /* eat rest of line */
651                          while (ipb.chr != '\n') {
652                                  if (ipb.chr == EOF)
653                                          return(0);
654 <                                scaninp();
654 >                                resetinp();
655                          }
656 <                        scaninp();
614 <                        advinp();
656 >                        resetinp();
657                  }
658          }
659          return(0);
# Line 808 | Line 850 | resetinp(void)                      /* rewind position
850                  ipb.beg = ipb.end;
851          ipb.pos = ipb.beg;
852          ipb.chr = *ipb.pos;
853 +        if (passive)                    /* transmit unmatched character? */
854 +                fputc(ipb.chr, stdout);
855          if (++ipb.beg >= &inpbuf[INBSIZ])
856                  ipb.beg = inpbuf;
857          scaninp();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines