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.21 by greg, Sun Jun 14 00:33:16 2009 UTC vs.
Revision 1.24 by greg, Sat May 10 01:27:14 2014 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>
11   #include  <math.h>
12   #include  <ctype.h>
13  
# Line 107 | Line 104 | int  argc,
104   char  *argv[]
105   )
106   {
107 +        char  *fpath;
108          int  i;
109  
110          esupport |= E_VARIABLE|E_FUNCTION|E_INCHAN|E_OUTCHAN|E_RCONST;
# Line 136 | Line 134 | char  *argv[]
134                          svpreset(argv[++i]);
135                          break;
136                  case 'f':
137 <                        fcompile(argv[++i]);
137 >                        fpath = getpath(argv[++i], getrlibpath(), 0);
138 >                        if (fpath == NULL) {
139 >                                eputs(argv[0]);
140 >                                eputs(": cannot find file '");
141 >                                eputs(argv[i]);
142 >                                eputs("'\n");
143 >                                quit(1);
144 >                        }
145 >                        fcompile(fpath);
146                          break;
147                  case 'e':
148                          scompile(argv[++i], NULL, 0);
# Line 219 | Line 225 | eputs(" [-b][-l][-n][-p][-w][-u][-tS][-s svar=sval][-e
225                  }
226          if (otype != 'a')
227                  SET_FILE_BINARY(stdout);
228 + #ifdef getc_unlocked            /* avoid lock/unlock overhead */
229 +        flockfile(stdout);
230 + #endif
231          if (noinput) {          /* produce a single output record */
232                  if (i < argc) {
233                          eputs(argv[0]);
# Line 229 | Line 238 | eputs(" [-b][-l][-n][-p][-w][-u][-tS][-s svar=sval][-e
238                  putout();
239                  quit(0);
240          }
232        if (itype != 'a')
233                SET_FILE_BINARY(stdin);
234
241          if (blnkeq)             /* for efficiency */
242                  nbsynch();
243  
# Line 300 | Line 306 | char  *file
306                  eputs(": cannot open\n");
307                  quit(1);
308          }
309 +        if (itype != 'a')
310 +                SET_FILE_BINARY(fp);
311 + #ifdef getc_unlocked            /* avoid lock/unlock overhead */
312 +        flockfile(fp);
313 + #endif
314          if (inpfmt != NULL)
315                  initinp(fp);
316          
# Line 339 | Line 350 | static double
350   l_in(char *funame)      /* function call for $channel */
351   {
352          int  n;
353 <        register char  *cp;
353 >        char  *cp;
354                          /* get argument as integer */
355          n = (int)(argument(1) + .5);
356          if (n != 0)     /* return channel value */
# Line 371 | Line 382 | int  n
382   )
383   {
384          int  i;
385 <        register char  *cp;
385 >        char  *cp;
386  
387          if (noinput || inpfmt != NULL) {
388                  eputs("no column input\n");
# Line 472 | Line 483 | int  output
483          char  *inptr;
484          struct field  fmt;
485          int  res;
486 <        register struct field  *f;
486 >        struct field  *f;
487                                                  /* check for inline format */
488          for (inptr = spec; *inptr; inptr++)
489                  if (*inptr == '$')
# Line 532 | Line 543 | int  output
543  
544   static int
545   readfield(                   /* get next field in format */
546 < register char  **pp
546 > char  **pp
547   )
548   {
549          int  type = F_NUL;
550          int  width = 0;
551 <        register char  *cp;
551 >        char  *cp;
552          
553          cp = inpbuf;
554          while (cp < &inpbuf[INBSIZ-1] && **pp != '\0') {
# Line 602 | Line 613 | getsvar(                         /* get string variabl
613   char  *svname
614   )
615   {
616 <        register struct strvar  *sv;
616 >        struct strvar  *sv;
617          
618          for (sv = svhead; sv != NULL; sv = sv->next)
619                  if (!strcmp(sv->name, svname))
# Line 621 | Line 632 | svpreset(                    /* preset a string variab
632   char  *eqn
633   )
634   {
635 <        register struct strvar  *sv;
636 <        register char  *val;
635 >        struct strvar  *sv;
636 >        char  *val;
637  
638          for (val = eqn; *val != '='; val++)
639                  if (!*val)
# Line 641 | Line 652 | char  *eqn
652   static void
653   clearrec(void)                  /* clear input record variables */
654   {
655 <        register struct field  *f;
655 >        struct field  *f;
656  
657          for (f = inpfmt; f != NULL; f = f->next)
658                  switch (f->type & F_TYP) {
# Line 662 | Line 673 | static int
673   getrec(void)                            /* get next record from file */
674   {
675          int  eatline;
676 <        register struct field  *f;
676 >        struct field  *f;
677  
678          while (ipb.chr != EOF) {
679                  if (blnkeq) {           /* beware of nbsynch() */
# Line 696 | Line 707 | getrec(void)                           /* get next record from file */
707  
708   static int
709   getfield(                             /* get next field */
710 < register struct field  *f
710 > struct field  *f
711   )
712   {
713          static char  buf[RMAXWORD+1];            /* no recursion! */
714          int  delim, inword;
715          double  d;
716          char  *np;
717 <        register char  *cp;
717 >        char  *cp;
718  
719          switch (f->type & F_TYP) {
720          case T_LIT:
# Line 790 | Line 801 | register struct field  *f
801   static void
802   putrec(void)                                /* output a record */
803   {
804 <        char  fmt[32];
805 <        register int  n;
806 <        register struct field  *f;
804 >        char  fmt[32], typ[32];
805 >        int  n;
806 >        struct field  *f;
807          int  adlast, adnext;
808 +        double  dv, av;
809          
810          adlast = 0;
811          for (f = outfmt; f != NULL; f = f->next) {
# Line 824 | Line 836 | putrec(void)                                /* output
836                          break;
837                  case T_NUM:
838                          n = f->type & F_WID;
839 +                        typ[0] = (n <= 6) ? 'g' : 'e';
840 +                        typ[1] = '\0';
841 +                        dv = evalue(f->f.ne);
842 +                        if ((av = fabs(dv)) < 1L<<31) {
843 +                                long    iv = (int)(av + .5);
844 +                                if (iv && fabs(av-iv) <= av*1e-14)
845 +                                        strcpy(typ, ".0f");
846 +                        }
847                          if (adlast && adnext)
848 <                                strcpy(fmt, "%g");
848 >                                sprintf(fmt, "%%%s", typ);
849                          else if (adlast)
850 <                                sprintf(fmt, "%%-%dg", n);
850 >                                sprintf(fmt, "%%-%d%s", n, typ);
851                          else
852 <                                sprintf(fmt, "%%%dg", n);
853 <                        printf(fmt, evalue(f->f.ne));
852 >                                sprintf(fmt, "%%%d%s", n, typ);
853 >                        printf(fmt, dv);
854                          adlast = 1;
855                          break;
856                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines