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.3 by greg, Sun Apr 27 06:08:03 2003 UTC vs.
Revision 1.8 by schorsch, Fri Aug 1 14:14:23 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 200 | Line 208 | eputs(" [-b][-l][-n][-w][-u][-tS][-s svar=sval][-e exp
208   }
209  
210  
211 < nbsynch()               /* non-blank starting synch character */
211 > static void
212 > nbsynch(void)               /* non-blank starting synch character */
213   {
214          if (inpfmt == NULL || (inpfmt->type & F_TYP) != T_LIT)
215                  return;
# Line 212 | Line 221 | nbsynch()               /* non-blank starting synch ch
221  
222  
223   int
224 < getinputrec(fp)         /* get next input record */
225 < FILE  *fp;
224 > getinputrec(            /* get next input record */
225 > FILE  *fp
226 > )
227   {
228          if (inpfmt != NULL)
229                  return(getrec());
# Line 227 | Line 237 | FILE  *fp;
237   }
238  
239  
240 < execute(file)           /* process a file */
241 < char  *file;
240 > static void
241 > execute(           /* process a file */
242 > char  *file
243 > )
244   {
245          int  conditional = vardefined("cond");
246          long  nrecs = 0;
# Line 258 | Line 270 | char  *file;
270   }
271  
272  
273 < putout()                /* produce an output record */
273 > static void
274 > putout(void)                /* produce an output record */
275   {
263        extern void  chanset(), bchanset();
276  
277          colpos = 0;
278          if (outfmt != NULL)
# Line 269 | Line 281 | putout()                /* produce an output record */
281                  chanout(bchanset);
282          else
283                  chanout(chanset);
284 <        if (colpos && !bchanset)
284 >        if (colpos && !bocols)
285                  putchar('\n');
286          if (unbuff)
287                  fflush(stdout);
# Line 277 | Line 289 | putout()                /* produce an output record */
289  
290  
291   double
292 < chanvalue(n)            /* return value for column n */
293 < int  n;
292 > chanvalue(            /* return value for column n */
293 > int  n
294 > )
295   {
296          int  i;
297          register char  *cp;
# Line 329 | Line 342 | int  n;
342  
343  
344   void
345 < chanset(n, v)                   /* output column n */
346 < int  n;
347 < double  v;
345 > chanset(                   /* output column n */
346 > int  n,
347 > double  v
348 > )
349   {
350          if (colpos == 0)                /* no leading separator */
351                  colpos = 1;
# Line 344 | Line 358 | double  v;
358  
359  
360   void
361 < bchanset(n, v)                   /* output binary channel n */
362 < int  n;
363 < double  v;
361 > bchanset(                   /* output binary channel n */
362 > int  n,
363 > double  v
364 > )
365   {
366          static char     zerobuf[sizeof(double)];
367  
# Line 363 | Line 378 | double  v;
378   }
379  
380  
381 < readfmt(spec, output)                   /* read record format */
382 < char  *spec;
383 < int  output;
381 > static void
382 > readfmt(                   /* read record format */
383 > char  *spec,
384 > int  output
385 > )
386   {
387          int  fd;
388          char  *inptr;
# Line 429 | Line 446 | int  output;
446   }
447  
448  
449 < int
450 < readfield(pp)                   /* get next field in format */
451 < register char  **pp;
449 > static int
450 > readfield(                   /* get next field in format */
451 > register char  **pp
452 > )
453   {
454          int  type = F_NUL;
455          int  width = 0;
# Line 496 | Line 514 | register char  **pp;
514  
515  
516   struct strvar *
517 < getsvar(svname)                         /* get string variable */
518 < char  *svname;
517 > getsvar(                         /* get string variable */
518 > char  *svname
519 > )
520   {
521          register struct strvar  *sv;
522          
# Line 513 | Line 532 | char  *svname;
532   }
533  
534  
535 < svpreset(eqn)                    /* preset a string variable */
536 < char  *eqn;
535 > static void
536 > svpreset(                    /* preset a string variable */
537 > char  *eqn
538 > )
539   {
540          register struct strvar  *sv;
541          register char  *val;
# Line 533 | Line 554 | char  *eqn;
554   }
555  
556  
557 < clearrec()                      /* clear input record variables */
557 > static void
558 > clearrec(void)                  /* clear input record variables */
559   {
560          register struct field  *f;
561  
# Line 552 | Line 574 | clearrec()                     /* clear input record variables */
574   }
575  
576  
577 < getrec()                                /* get next record from file */
577 > static int
578 > getrec(void)                                /* get next record from file */
579   {
580          int  eatline;
581          register struct field  *f;
# Line 585 | Line 608 | getrec()                                /* get next re
608   }
609  
610  
611 < getfield(f)                             /* get next field */
612 < register struct field  *f;
611 > static int
612 > getfield(                             /* get next field */
613 > register struct field  *f
614 > )
615   {
616 <        static char  buf[MAXWORD+1];            /* no recursion! */
616 >        static char  buf[RMAXWORD+1];            /* no recursion! */
617          int  delim, inword;
618          double  d;
619          char  *np;
# Line 633 | Line 658 | register struct field  *f;
658                                  *cp++ = ipb.chr;
659                                  scaninp();
660                          }
661 <                } while (inword && cp < &buf[MAXWORD]);
661 >                } while (inword && cp < &buf[RMAXWORD]);
662                  *cp = '\0';
663                  if (f->f.sv->val == NULL)
664                          f->f.sv->val = savqstr(buf);    /* first setting */
# Line 662 | Line 687 | register struct field  *f;
687                                  *cp++ = ipb.chr;
688                                  scaninp();
689                          }
690 <                } while (inword && cp < &buf[MAXWORD]);
690 >                } while (inword && cp < &buf[RMAXWORD]);
691                  *cp = '\0';
692                  d = np==NULL ? 0. : atof(np);
693                  if (!vardefined(f->f.nv))
# Line 672 | Line 697 | register struct field  *f;
697                          return(-1);                     /* doesn't match! */
698                  return(0);
699          }
700 +        return -1; /* pro forma return */
701   }
702  
703  
704 < putrec()                                /* output a record */
704 > static void
705 > putrec(void)                                /* output a record */
706   {
707          char  fmt[32];
708          register int  n;
# Line 725 | Line 752 | putrec()                                /* output a re
752   }
753  
754  
755 < initinp(fp)                     /* prepare lookahead buffer */
756 < FILE  *fp;
755 > static void
756 > initinp(FILE  *fp)                     /* prepare lookahead buffer */
757 >
758   {
759          ipb.fin = fp;
760          ipb.beg = ipb.end = inpbuf;
# Line 736 | Line 764 | FILE  *fp;
764   }
765  
766  
767 < scaninp()                       /* scan next character */
767 > static void
768 > scaninp(void)                       /* scan next character */
769   {
770          if (ipb.chr == EOF)
771                  return;
# Line 755 | Line 784 | scaninp()                       /* scan next character
784   }
785  
786  
787 < advinp()                        /* move home to current position */
787 > static void
788 > advinp(void)                        /* move home to current position */
789   {
790          ipb.beg = ipb.pos;
791   }
792  
793  
794 < resetinp()                      /* rewind position and advance 1 */
794 > static void
795 > resetinp(void)                      /* rewind position and advance 1 */
796   {
797          if (ipb.beg == NULL)            /* full */
798                  ipb.beg = ipb.end;
# Line 774 | Line 805 | resetinp()                      /* rewind position and
805  
806  
807   void
808 < eputs(msg)
778 < char  *msg;
808 > eputs(char  *msg)
809   {
810          fputs(msg, stderr);
811   }
812  
813  
814   void
815 < wputs(msg)
786 < char  *msg;
815 > wputs(char  *msg)
816   {
817          if (!nowarn)
818                  eputs(msg);
# Line 791 | Line 820 | char  *msg;
820  
821  
822   void
823 < quit(code)
795 < int  code;
823 > quit(int  code)
824   {
825          exit(code);
826   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines