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.4 by greg, Sun May 25 05:27:16 2003 UTC vs.
Revision 1.9 by greg, Wed Nov 5 19:03:03 2003 UTC

# Line 7 | Line 7 | static const char RCSid[] = "$Id$";
7   *     9/11/87
8   */
9  
10 #include  <stdio.h>
11
10   #include  <stdlib.h>
11 <
11 > #include  <stdio.h>
12 > #include  <string.h>
13   #include  <math.h>
15
14   #include  <ctype.h>
15  
16 + #include  "platform.h"
17   #include  "calcomp.h"
18 + #include  "rterror.h"
19  
20 #ifdef  CPM
21 #define  getc           agetc   /* text files only, right? */
22 #endif
23
20   #define  isnum(c)       (isdigit(c) || (c)=='-' || (c)=='.' \
21                                  || (c)=='+' || (c)=='e' || (c)=='E')
22  
# Line 58 | 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 < extern char  *strcpy(), *emalloc(), *savestr();
58 < struct strvar  *getsvar();
57 > static void scaninp(void), advinp(void), resetinp(void);
58 > static void putrec(void), putout(void), nbsynch(void);
59 > static int getrec(void);
60 > static void execute(char *file);
61 > static void initinp(FILE *fp);
62 > static void svpreset(char *eqn);
63 > static void readfmt(char *spec, int output);
64 > static int readfield(char **pp);
65 > static int getfield(struct field *f);
66 > static void chanset(int n, double v);
67 > static void bchanset(int n, double v);
68 > static struct strvar* getsvar(char *svname);
69  
70   struct field  *inpfmt = NULL;   /* input record format */
71   struct field  *outfmt = NULL;   /* output record structure */
# Line 88 | Line 94 | struct {
94   } ipb;                          /* circular lookahead buffer */
95  
96  
97 < main(argc, argv)
98 < int  argc;
99 < char  *argv[];
97 > int
98 > main(
99 > int  argc,
100 > char  *argv[]
101 > )
102   {
103          int  i;
104  
# Line 139 | Line 147 | char  *argv[];
147                                          nbicols = atoi(argv[i]+3);
148                                  else
149                                          nbicols = 1;
150 +                                if (nbicols*sizeof(double) > INBSIZ) {
151 +                                        eputs(argv[0]);
152 +                                        eputs(": too many input columns\n");
153 +                                        quit(1);
154 +                                }
155                                  break;
156                          case 'f':
157                                  if (isdigit(argv[i][3]))
158                                          nbicols = -atoi(argv[i]+3);
159                                  else
160                                          nbicols = -1;
161 +                                if (-nbicols*sizeof(float) > INBSIZ) {
162 +                                        eputs(argv[0]);
163 +                                        eputs(": too many input columns\n");
164 +                                        quit(1);
165 +                                }
166                                  break;
167                          default:
168                                  goto userr;
# Line 200 | Line 218 | eputs(" [-b][-l][-n][-w][-u][-tS][-s svar=sval][-e exp
218   }
219  
220  
221 < nbsynch()               /* non-blank starting synch character */
221 > static void
222 > nbsynch(void)               /* non-blank starting synch character */
223   {
224          if (inpfmt == NULL || (inpfmt->type & F_TYP) != T_LIT)
225                  return;
# Line 212 | Line 231 | nbsynch()               /* non-blank starting synch ch
231  
232  
233   int
234 < getinputrec(fp)         /* get next input record */
235 < FILE  *fp;
234 > getinputrec(            /* get next input record */
235 > FILE  *fp
236 > )
237   {
238          if (inpfmt != NULL)
239                  return(getrec());
# Line 227 | Line 247 | FILE  *fp;
247   }
248  
249  
250 < execute(file)           /* process a file */
251 < char  *file;
250 > static void
251 > execute(           /* process a file */
252 > char  *file
253 > )
254   {
255          int  conditional = vardefined("cond");
256          long  nrecs = 0;
# Line 258 | Line 280 | char  *file;
280   }
281  
282  
283 < putout()                /* produce an output record */
283 > static void
284 > putout(void)                /* produce an output record */
285   {
263        extern void  chanset(), bchanset();
286  
287          colpos = 0;
288          if (outfmt != NULL)
# Line 277 | Line 299 | putout()                /* produce an output record */
299  
300  
301   double
302 < chanvalue(n)            /* return value for column n */
303 < int  n;
302 > chanvalue(            /* return value for column n */
303 > int  n
304 > )
305   {
306          int  i;
307          register char  *cp;
# Line 329 | Line 352 | int  n;
352  
353  
354   void
355 < chanset(n, v)                   /* output column n */
356 < int  n;
357 < double  v;
355 > chanset(                   /* output column n */
356 > int  n,
357 > double  v
358 > )
359   {
360          if (colpos == 0)                /* no leading separator */
361                  colpos = 1;
# Line 344 | Line 368 | double  v;
368  
369  
370   void
371 < bchanset(n, v)                   /* output binary channel n */
372 < int  n;
373 < double  v;
371 > bchanset(                   /* output binary channel n */
372 > int  n,
373 > double  v
374 > )
375   {
376          static char     zerobuf[sizeof(double)];
377  
# Line 363 | Line 388 | double  v;
388   }
389  
390  
391 < readfmt(spec, output)                   /* read record format */
392 < char  *spec;
393 < int  output;
391 > static void
392 > readfmt(                   /* read record format */
393 > char  *spec,
394 > int  output
395 > )
396   {
397          int  fd;
398          char  *inptr;
# Line 429 | Line 456 | int  output;
456   }
457  
458  
459 < int
460 < readfield(pp)                   /* get next field in format */
461 < register char  **pp;
459 > static int
460 > readfield(                   /* get next field in format */
461 > register char  **pp
462 > )
463   {
464          int  type = F_NUL;
465          int  width = 0;
# Line 496 | Line 524 | register char  **pp;
524  
525  
526   struct strvar *
527 < getsvar(svname)                         /* get string variable */
528 < char  *svname;
527 > getsvar(                         /* get string variable */
528 > char  *svname
529 > )
530   {
531          register struct strvar  *sv;
532          
# Line 513 | Line 542 | char  *svname;
542   }
543  
544  
545 < svpreset(eqn)                    /* preset a string variable */
546 < char  *eqn;
545 > static void
546 > svpreset(                    /* preset a string variable */
547 > char  *eqn
548 > )
549   {
550          register struct strvar  *sv;
551          register char  *val;
# Line 533 | Line 564 | char  *eqn;
564   }
565  
566  
567 < clearrec()                      /* clear input record variables */
567 > static void
568 > clearrec(void)                  /* clear input record variables */
569   {
570          register struct field  *f;
571  
# Line 552 | Line 584 | clearrec()                     /* clear input record variables */
584   }
585  
586  
587 < getrec()                                /* get next record from file */
587 > static int
588 > getrec(void)                                /* get next record from file */
589   {
590          int  eatline;
591          register struct field  *f;
# Line 585 | Line 618 | getrec()                                /* get next re
618   }
619  
620  
621 < getfield(f)                             /* get next field */
622 < register struct field  *f;
621 > static int
622 > getfield(                             /* get next field */
623 > register struct field  *f
624 > )
625   {
626 <        static char  buf[MAXWORD+1];            /* no recursion! */
626 >        static char  buf[RMAXWORD+1];            /* no recursion! */
627          int  delim, inword;
628          double  d;
629          char  *np;
# Line 621 | Line 656 | register struct field  *f;
656                          delim = f->next->f.sl[0];
657                  cp = buf;
658                  do {
659 <                        if (ipb.chr == EOF)
659 >                        if (ipb.chr == EOF || ipb.chr == '\n')
660                                  inword = 0;
661                          else if (blnkeq && delim != EOF)
662                                  inword = isblnk(delim) ?
# Line 633 | Line 668 | register struct field  *f;
668                                  *cp++ = ipb.chr;
669                                  scaninp();
670                          }
671 <                } while (inword && cp < &buf[MAXWORD]);
671 >                } while (inword && cp < &buf[RMAXWORD]);
672                  *cp = '\0';
673                  if (f->f.sv->val == NULL)
674                          f->f.sv->val = savqstr(buf);    /* first setting */
# Line 662 | Line 697 | register struct field  *f;
697                                  *cp++ = ipb.chr;
698                                  scaninp();
699                          }
700 <                } while (inword && cp < &buf[MAXWORD]);
700 >                } while (inword && cp < &buf[RMAXWORD]);
701                  *cp = '\0';
702                  d = np==NULL ? 0. : atof(np);
703                  if (!vardefined(f->f.nv))
# Line 672 | Line 707 | register struct field  *f;
707                          return(-1);                     /* doesn't match! */
708                  return(0);
709          }
710 +        return -1; /* pro forma return */
711   }
712  
713  
714 < putrec()                                /* output a record */
714 > static void
715 > putrec(void)                                /* output a record */
716   {
717          char  fmt[32];
718          register int  n;
# Line 725 | Line 762 | putrec()                                /* output a re
762   }
763  
764  
765 < initinp(fp)                     /* prepare lookahead buffer */
766 < FILE  *fp;
765 > static void
766 > initinp(FILE  *fp)                     /* prepare lookahead buffer */
767 >
768   {
769          ipb.fin = fp;
770          ipb.beg = ipb.end = inpbuf;
# Line 736 | Line 774 | FILE  *fp;
774   }
775  
776  
777 < scaninp()                       /* scan next character */
777 > static void
778 > scaninp(void)                       /* scan next character */
779   {
780          if (ipb.chr == EOF)
781                  return;
# Line 755 | Line 794 | scaninp()                       /* scan next character
794   }
795  
796  
797 < advinp()                        /* move home to current position */
797 > static void
798 > advinp(void)                        /* move home to current position */
799   {
800          ipb.beg = ipb.pos;
801   }
802  
803  
804 < resetinp()                      /* rewind position and advance 1 */
804 > static void
805 > resetinp(void)                      /* rewind position and advance 1 */
806   {
807          if (ipb.beg == NULL)            /* full */
808                  ipb.beg = ipb.end;
# Line 774 | Line 815 | resetinp()                      /* rewind position and
815  
816  
817   void
818 < eputs(msg)
778 < char  *msg;
818 > eputs(char  *msg)
819   {
820          fputs(msg, stderr);
821   }
822  
823  
824   void
825 < wputs(msg)
786 < char  *msg;
825 > wputs(char  *msg)
826   {
827          if (!nowarn)
828                  eputs(msg);
# Line 791 | Line 830 | char  *msg;
830  
831  
832   void
833 < quit(code)
795 < int  code;
833 > quit(int  code)
834   {
835          exit(code);
836   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines