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.7 by schorsch, Sun Jul 27 22:12:01 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? */
# Line 58 | Line 58 | struct field {                  /* record format struc
58   #define  savqstr(s)     strcpy(emalloc(strlen(s)+1),s)
59   #define  freqstr(s)     efree(s)
60  
61 < extern char  *strcpy(), *emalloc(), *savestr();
62 < struct strvar  *getsvar();
61 > static void scaninp(void), advinp(void), resetinp(void);
62 > static void putrec(void), putout(void), nbsynch(void);
63 > static int getrec(void);
64 > static void execute(char *file);
65 > static void initinp(FILE *fp);
66 > static void svpreset(char *eqn);
67 > static void readfmt(char *spec, int output);
68 > static int readfield(char **pp);
69 > 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  
74   struct field  *inpfmt = NULL;   /* input record format */
75   struct field  *outfmt = NULL;   /* output record structure */
# Line 88 | Line 98 | struct {
98   } ipb;                          /* circular lookahead buffer */
99  
100  
101 < main(argc, argv)
102 < int  argc;
103 < char  *argv[];
101 > int
102 > main(
103 > int  argc,
104 > char  *argv[]
105 > )
106   {
107          int  i;
108  
# Line 200 | Line 212 | eputs(" [-b][-l][-n][-w][-u][-tS][-s svar=sval][-e exp
212   }
213  
214  
215 < nbsynch()               /* non-blank starting synch character */
215 > static void
216 > nbsynch(void)               /* non-blank starting synch character */
217   {
218          if (inpfmt == NULL || (inpfmt->type & F_TYP) != T_LIT)
219                  return;
# Line 212 | Line 225 | nbsynch()               /* non-blank starting synch ch
225  
226  
227   int
228 < getinputrec(fp)         /* get next input record */
229 < FILE  *fp;
228 > getinputrec(            /* get next input record */
229 > FILE  *fp
230 > )
231   {
232          if (inpfmt != NULL)
233                  return(getrec());
# Line 227 | Line 241 | FILE  *fp;
241   }
242  
243  
244 < execute(file)           /* process a file */
245 < char  *file;
244 > static void
245 > execute(           /* process a file */
246 > char  *file
247 > )
248   {
249          int  conditional = vardefined("cond");
250          long  nrecs = 0;
# Line 258 | Line 274 | char  *file;
274   }
275  
276  
277 < putout()                /* produce an output record */
277 > static void
278 > putout(void)                /* produce an output record */
279   {
263        extern void  chanset(), bchanset();
280  
281          colpos = 0;
282          if (outfmt != NULL)
# Line 277 | Line 293 | putout()                /* produce an output record */
293  
294  
295   double
296 < chanvalue(n)            /* return value for column n */
297 < int  n;
296 > chanvalue(            /* return value for column n */
297 > int  n
298 > )
299   {
300          int  i;
301          register char  *cp;
# Line 329 | Line 346 | int  n;
346  
347  
348   void
349 < chanset(n, v)                   /* output column n */
350 < int  n;
351 < double  v;
349 > chanset(                   /* output column n */
350 > int  n,
351 > double  v
352 > )
353   {
354          if (colpos == 0)                /* no leading separator */
355                  colpos = 1;
# Line 344 | Line 362 | double  v;
362  
363  
364   void
365 < bchanset(n, v)                   /* output binary channel n */
366 < int  n;
367 < double  v;
365 > bchanset(                   /* output binary channel n */
366 > int  n,
367 > double  v
368 > )
369   {
370          static char     zerobuf[sizeof(double)];
371  
# Line 363 | Line 382 | double  v;
382   }
383  
384  
385 < readfmt(spec, output)                   /* read record format */
386 < char  *spec;
387 < int  output;
385 > static void
386 > readfmt(                   /* read record format */
387 > char  *spec,
388 > int  output
389 > )
390   {
391          int  fd;
392          char  *inptr;
# Line 429 | Line 450 | int  output;
450   }
451  
452  
453 < int
454 < readfield(pp)                   /* get next field in format */
455 < register char  **pp;
453 > static int
454 > readfield(                   /* get next field in format */
455 > register char  **pp
456 > )
457   {
458          int  type = F_NUL;
459          int  width = 0;
# Line 496 | Line 518 | register char  **pp;
518  
519  
520   struct strvar *
521 < getsvar(svname)                         /* get string variable */
522 < char  *svname;
521 > getsvar(                         /* get string variable */
522 > char  *svname
523 > )
524   {
525          register struct strvar  *sv;
526          
# Line 513 | Line 536 | char  *svname;
536   }
537  
538  
539 < svpreset(eqn)                    /* preset a string variable */
540 < char  *eqn;
539 > static void
540 > svpreset(                    /* preset a string variable */
541 > char  *eqn
542 > )
543   {
544          register struct strvar  *sv;
545          register char  *val;
# Line 533 | Line 558 | char  *eqn;
558   }
559  
560  
561 < clearrec()                      /* clear input record variables */
561 > static void
562 > clearrec(void)                  /* clear input record variables */
563   {
564          register struct field  *f;
565  
# Line 552 | Line 578 | clearrec()                     /* clear input record variables */
578   }
579  
580  
581 < getrec()                                /* get next record from file */
581 > static int
582 > getrec(void)                                /* get next record from file */
583   {
584          int  eatline;
585          register struct field  *f;
# Line 585 | Line 612 | getrec()                                /* get next re
612   }
613  
614  
615 < getfield(f)                             /* get next field */
616 < register struct field  *f;
615 > static int
616 > getfield(                             /* get next field */
617 > register struct field  *f
618 > )
619   {
620 <        static char  buf[MAXWORD+1];            /* no recursion! */
620 >        static char  buf[RMAXWORD+1];            /* no recursion! */
621          int  delim, inword;
622          double  d;
623          char  *np;
# Line 633 | Line 662 | register struct field  *f;
662                                  *cp++ = ipb.chr;
663                                  scaninp();
664                          }
665 <                } while (inword && cp < &buf[MAXWORD]);
665 >                } while (inword && cp < &buf[RMAXWORD]);
666                  *cp = '\0';
667                  if (f->f.sv->val == NULL)
668                          f->f.sv->val = savqstr(buf);    /* first setting */
# Line 662 | Line 691 | register struct field  *f;
691                                  *cp++ = ipb.chr;
692                                  scaninp();
693                          }
694 <                } while (inword && cp < &buf[MAXWORD]);
694 >                } while (inword && cp < &buf[RMAXWORD]);
695                  *cp = '\0';
696                  d = np==NULL ? 0. : atof(np);
697                  if (!vardefined(f->f.nv))
# Line 672 | Line 701 | register struct field  *f;
701                          return(-1);                     /* doesn't match! */
702                  return(0);
703          }
704 +        return -1; /* pro forma return */
705   }
706  
707  
708 < putrec()                                /* output a record */
708 > static void
709 > putrec(void)                                /* output a record */
710   {
711          char  fmt[32];
712          register int  n;
# Line 725 | Line 756 | putrec()                                /* output a re
756   }
757  
758  
759 < initinp(fp)                     /* prepare lookahead buffer */
760 < FILE  *fp;
759 > static void
760 > initinp(FILE  *fp)                     /* prepare lookahead buffer */
761 >
762   {
763          ipb.fin = fp;
764          ipb.beg = ipb.end = inpbuf;
# Line 736 | Line 768 | FILE  *fp;
768   }
769  
770  
771 < scaninp()                       /* scan next character */
771 > static void
772 > scaninp(void)                       /* scan next character */
773   {
774          if (ipb.chr == EOF)
775                  return;
# Line 755 | Line 788 | scaninp()                       /* scan next character
788   }
789  
790  
791 < advinp()                        /* move home to current position */
791 > static void
792 > advinp(void)                        /* move home to current position */
793   {
794          ipb.beg = ipb.pos;
795   }
796  
797  
798 < resetinp()                      /* rewind position and advance 1 */
798 > static void
799 > resetinp(void)                      /* rewind position and advance 1 */
800   {
801          if (ipb.beg == NULL)            /* full */
802                  ipb.beg = ipb.end;
# Line 774 | Line 809 | resetinp()                      /* rewind position and
809  
810  
811   void
812 < eputs(msg)
778 < char  *msg;
812 > eputs(char  *msg)
813   {
814          fputs(msg, stderr);
815   }
816  
817  
818   void
819 < wputs(msg)
786 < char  *msg;
819 > wputs(char  *msg)
820   {
821          if (!nowarn)
822                  eputs(msg);
# Line 791 | Line 824 | char  *msg;
824  
825  
826   void
827 < quit(code)
795 < int  code;
827 > quit(int  code)
828   {
829          exit(code);
830   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines