ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/loadvars.c
(Generate patch)

Comparing ray/src/common/loadvars.c (file contents):
Revision 2.3 by greg, Tue Jan 23 11:52:57 1996 UTC vs.
Revision 2.10 by greg, Tue Feb 25 02:47:21 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1995 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  Routines for loading and checking variables from file.
6   */
7  
8 + #include "copyright.h"
9 +
10   #include <stdio.h>
11 + #include <stdlib.h>
12   #include <ctype.h>
13   #include "vars.h"
14  
15   #define NOCHAR  127             /* constant for character to delete */
16  
17 < #ifndef malloc
18 < extern char  *malloc(), *realloc();
19 < #endif
17 > extern char  *fgetline();
18  
19  
20 + void
21   loadvars(rfname)                /* load variables into vv from file */
22   char    *rfname;
23   {
# Line 30 | Line 29 | char   *rfname;
29                  fp = stdin;
30          else if ((fp = fopen(rfname, "r")) == NULL) {
31                  perror(rfname);
32 <                exit(1);
32 >                quit(1);
33          }
34          while (fgetline(buf, sizeof(buf), fp) != NULL) {
35                  for (cp = buf; *cp; cp++) {
# Line 46 | Line 45 | char   *rfname;
45                          }
46                          break;
47                  }
48 <                setvariable(buf);
48 >                if (setvariable(buf, matchvar) < 0) {
49 >                        fprintf(stderr, "%s: unknown variable: %s\n",
50 >                                        rfname, buf);
51 >                        quit(1);
52 >                }
53          }
54          fclose(fp);
55   }
56  
57  
58 < setvariable(ass)                /* assign variable according to string */
58 > int
59 > setvariable(ass, mv)            /* assign variable according to string */
60   register char   *ass;
61 + VARIABLE        *(*mv)();
62   {
63          char    varname[32];
64          int     n;
# Line 69 | Line 74 | register char  *ass;
74                  *cp++ = *ass++;
75          *cp = '\0';
76          if (!varname[0])
77 <                return;         /* no variable name! */
77 >                return(0);      /* no variable name! */
78                                          /* trim value */
79          while (isspace(*ass) || *ass == '=')
80                  ass++;
81          for (n = strlen(ass); n > 0; n--)
82                  if (!isspace(ass[n-1]))
83                          break;
84 <        if (!n) {
85 <                if (!nowarn)
81 <                        fprintf(stderr,
82 <                        "%s: warning - missing value for variable '%s'\n",
83 <                                        progname, varname);
84 <                return;
85 <        }
84 >        if (!n)
85 >                return(0);      /* no assignment */
86                                          /* match variable from list */
87 <        vp = matchvar(varname);
88 <        if (vp == NULL) {
89 <                fprintf(stderr, "%s: unknown variable '%s'\n",
90 <                                progname, varname);
91 <                exit(1);
92 <        }
87 >        vp = (*mv)(varname);
88 >        if (vp == NULL)
89 >                return(-1);
90                                          /* assign new value */
91          if (i = vp->nass) {
92                  cp = vp->value;
# Line 97 | Line 94 | register char  *ass;
94                          while (*cp++)
95                                  ;
96                  i = cp - vp->value;
97 <                vp->value = realloc(vp->value, i+n+1);
97 >                vp->value = (char *)realloc(vp->value, i+n+1);
98          } else
99 <                vp->value = malloc(n+1);
99 >                vp->value = (char *)malloc(n+1);
100          if (vp->value == NULL) {
101                  perror(progname);
102 <                exit(1);
102 >                quit(1);
103          }
104          cp = vp->value+i;               /* copy value, squeezing spaces */
105          *cp = *ass;
# Line 116 | Line 113 | register char  *ass;
113          }
114          if (isspace(*cp))               /* remove trailing space */
115                  *cp = '\0';
116 <        vp->nass++;
116 >        return(++vp->nass);
117   }
118  
119  
# Line 151 | Line 148 | register int   n;
148   }
149  
150  
151 + void
152   checkvalues()                   /* check assignments */
153   {
154          register int    i;
# Line 161 | Line 159 | checkvalues()                  /* check assignments */
159   }
160  
161  
162 + void
163   onevalue(vp)                    /* only one assignment for this variable */
164   register VARIABLE       *vp;
165   {
# Line 176 | Line 175 | register VARIABLE      *vp;
175   }
176  
177  
178 + void
179   catvalues(vp)                   /* concatenate variable values */
180   register VARIABLE       *vp;
181   {
# Line 204 | Line 204 | register char  *tv, *cv;
204   }
205  
206  
207 + void
208   boolvalue(vp)                   /* check boolean for legal values */
209   register VARIABLE       *vp;
210   {
# Line 219 | Line 220 | register VARIABLE      *vp;
220          }
221          fprintf(stderr, "%s: illegal value for boolean variable '%s'\n",
222                          progname, vp->name);
223 <        exit(1);
223 >        quit(1);
224   }
225  
226  
227 + void
228   qualvalue(vp)                   /* check qualitative var. for legal values */
229   register VARIABLE       *vp;
230   {
# Line 241 | Line 243 | register VARIABLE      *vp;
243          }
244          fprintf(stderr, "%s: illegal value for qualitative variable '%s'\n",
245                          progname, vp->name);
246 <        exit(1);
246 >        quit(1);
247   }
248  
249  
250 + void
251   intvalue(vp)                    /* check integer variable for legal values */
252   register VARIABLE       *vp;
253   {
# Line 253 | Line 256 | register VARIABLE      *vp;
256          if (isint(vp->value)) return;
257          fprintf(stderr, "%s: illegal value for integer variable '%s'\n",
258                          progname, vp->name);
259 <        exit(1);
259 >        quit(1);
260   }
261  
262  
263 + void
264   fltvalue(vp)                    /* check float variable for legal values */
265   register VARIABLE       *vp;
266   {
# Line 265 | Line 269 | register VARIABLE      *vp;
269          if (isflt(vp->value)) return;
270          fprintf(stderr, "%s: illegal value for real variable '%s'\n",
271                          progname, vp->name);
272 <        exit(1);
272 >        quit(1);
273   }
274  
275  
276 + void
277   printvars(fp)                   /* print variable values */
278   register FILE   *fp;
279   {
# Line 279 | Line 284 | register FILE  *fp;
284              for (j = 0; j < vdef(i); j++) {     /* print each assignment */
285                  fputs(vnam(i), fp);
286                  fputs("= ", fp);
287 <                k = clipline = ( vv[i].fixval == catvalues ? 64 : 320 )
287 >                k = clipline = ( vv[i].fixval == catvalues ? 64 : 236 )
288                                  - strlen(vnam(i)) ;
289                  cp = nvalue(i, j);
290                  while (*cp) {
291                      putc(*cp++, fp);
292                      if (--k <= 0) {             /* line too long */
293                          while (*cp && !isspace(*cp))
294 <                            putc(*cp++, fp);    /* finish this word */
294 >                            fputc(*cp++, fp);   /* finish this word */
295                          if (*cp) {              /* start new line */
296 <                            putc('\n', fp);
297 <                            fputs(vnam(i), fp);
298 <                            putc('=', fp);
296 >                            if (vv[i].fixval == catvalues) {
297 >                                fputc('\n', fp);
298 >                                fputs(vnam(i), fp);
299 >                                fputc('=', fp);
300 >                            } else
301 >                                fputs(" \\\n", fp);
302                              k = clipline;
303                          }
304                      }
305                  }
306 <                putc('\n', fp);
306 >                fputc('\n', fp);
307              }
308          fflush(fp);
309   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines