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.2 by greg, Wed Jan 17 15:45:16 1996 UTC vs.
Revision 2.9 by greg, Sat Feb 22 02:07:22 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 + /* ====================================================================
9 + * The Radiance Software License, Version 1.0
10 + *
11 + * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 + * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 + *
14 + * Redistribution and use in source and binary forms, with or without
15 + * modification, are permitted provided that the following conditions
16 + * are met:
17 + *
18 + * 1. Redistributions of source code must retain the above copyright
19 + *         notice, this list of conditions and the following disclaimer.
20 + *
21 + * 2. Redistributions in binary form must reproduce the above copyright
22 + *       notice, this list of conditions and the following disclaimer in
23 + *       the documentation and/or other materials provided with the
24 + *       distribution.
25 + *
26 + * 3. The end-user documentation included with the redistribution,
27 + *           if any, must include the following acknowledgment:
28 + *             "This product includes Radiance software
29 + *                 (http://radsite.lbl.gov/)
30 + *                 developed by the Lawrence Berkeley National Laboratory
31 + *               (http://www.lbl.gov/)."
32 + *       Alternately, this acknowledgment may appear in the software itself,
33 + *       if and wherever such third-party acknowledgments normally appear.
34 + *
35 + * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 + *       and "The Regents of the University of California" must
37 + *       not be used to endorse or promote products derived from this
38 + *       software without prior written permission. For written
39 + *       permission, please contact [email protected].
40 + *
41 + * 5. Products derived from this software may not be called "Radiance",
42 + *       nor may "Radiance" appear in their name, without prior written
43 + *       permission of Lawrence Berkeley National Laboratory.
44 + *
45 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 + * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 + * SUCH DAMAGE.
57 + * ====================================================================
58 + *
59 + * This software consists of voluntary contributions made by many
60 + * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 + * information on Lawrence Berkeley National Laboratory, please see
62 + * <http://www.lbl.gov/>.
63 + */
64 +
65   #include <stdio.h>
66 + #include <stdlib.h>
67   #include <ctype.h>
68   #include "vars.h"
69  
70   #define NOCHAR  127             /* constant for character to delete */
71  
72 < #ifndef malloc
18 < extern char  *malloc(), *realloc();
19 < #endif
72 > extern char  *fgetline();
73  
74  
75 + void
76   loadvars(rfname)                /* load variables into vv from file */
77   char    *rfname;
78   {
# Line 30 | Line 84 | char   *rfname;
84                  fp = stdin;
85          else if ((fp = fopen(rfname, "r")) == NULL) {
86                  perror(rfname);
87 <                exit(1);
87 >                quit(1);
88          }
89          while (fgetline(buf, sizeof(buf), fp) != NULL) {
90                  for (cp = buf; *cp; cp++) {
# Line 46 | Line 100 | char   *rfname;
100                          }
101                          break;
102                  }
103 <                setvariable(buf);
103 >                if (setvariable(buf, matchvar) < 0) {
104 >                        fprintf(stderr, "%s: unknown variable: %s\n",
105 >                                        rfname, buf);
106 >                        quit(1);
107 >                }
108          }
109          fclose(fp);
110   }
111  
112  
113 < setvariable(ass)                /* assign variable according to string */
113 > int
114 > setvariable(ass, mv)            /* assign variable according to string */
115   register char   *ass;
116 + VARIABLE        *(*mv)();
117   {
118          char    varname[32];
119          int     n;
# Line 69 | Line 129 | register char  *ass;
129                  *cp++ = *ass++;
130          *cp = '\0';
131          if (!varname[0])
132 <                return;         /* no variable name! */
132 >                return(0);      /* no variable name! */
133                                          /* trim value */
134          while (isspace(*ass) || *ass == '=')
135                  ass++;
136          for (n = strlen(ass); n > 0; n--)
137                  if (!isspace(ass[n-1]))
138                          break;
139 <        if (!n && !nowarn) {
140 <                fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
81 <                                progname, varname);
82 <                return;
83 <        }
139 >        if (!n)
140 >                return(0);      /* no assignment */
141                                          /* match variable from list */
142 <        vp = matchvar(varname);
143 <        if (vp == NULL) {
144 <                fprintf(stderr, "%s: unknown variable '%s'\n",
88 <                                progname, varname);
89 <                exit(1);
90 <        }
142 >        vp = (*mv)(varname);
143 >        if (vp == NULL)
144 >                return(-1);
145                                          /* assign new value */
146          if (i = vp->nass) {
147                  cp = vp->value;
# Line 95 | Line 149 | register char  *ass;
149                          while (*cp++)
150                                  ;
151                  i = cp - vp->value;
152 <                vp->value = realloc(vp->value, i+n+1);
152 >                vp->value = (char *)realloc(vp->value, i+n+1);
153          } else
154 <                vp->value = malloc(n+1);
154 >                vp->value = (char *)malloc(n+1);
155          if (vp->value == NULL) {
156                  perror(progname);
157 <                exit(1);
157 >                quit(1);
158          }
159          cp = vp->value+i;               /* copy value, squeezing spaces */
160          *cp = *ass;
# Line 114 | Line 168 | register char  *ass;
168          }
169          if (isspace(*cp))               /* remove trailing space */
170                  *cp = '\0';
171 <        vp->nass++;
171 >        return(++vp->nass);
172   }
173  
174  
# Line 149 | Line 203 | register int   n;
203   }
204  
205  
206 + void
207   checkvalues()                   /* check assignments */
208   {
209          register int    i;
# Line 159 | Line 214 | checkvalues()                  /* check assignments */
214   }
215  
216  
217 + void
218   onevalue(vp)                    /* only one assignment for this variable */
219   register VARIABLE       *vp;
220   {
# Line 174 | Line 230 | register VARIABLE      *vp;
230   }
231  
232  
233 + void
234   catvalues(vp)                   /* concatenate variable values */
235   register VARIABLE       *vp;
236   {
# Line 202 | Line 259 | register char  *tv, *cv;
259   }
260  
261  
262 + void
263   boolvalue(vp)                   /* check boolean for legal values */
264   register VARIABLE       *vp;
265   {
# Line 217 | Line 275 | register VARIABLE      *vp;
275          }
276          fprintf(stderr, "%s: illegal value for boolean variable '%s'\n",
277                          progname, vp->name);
278 <        exit(1);
278 >        quit(1);
279   }
280  
281  
282 + void
283   qualvalue(vp)                   /* check qualitative var. for legal values */
284   register VARIABLE       *vp;
285   {
# Line 239 | Line 298 | register VARIABLE      *vp;
298          }
299          fprintf(stderr, "%s: illegal value for qualitative variable '%s'\n",
300                          progname, vp->name);
301 <        exit(1);
301 >        quit(1);
302   }
303  
304  
305 + void
306   intvalue(vp)                    /* check integer variable for legal values */
307   register VARIABLE       *vp;
308   {
# Line 251 | Line 311 | register VARIABLE      *vp;
311          if (isint(vp->value)) return;
312          fprintf(stderr, "%s: illegal value for integer variable '%s'\n",
313                          progname, vp->name);
314 <        exit(1);
314 >        quit(1);
315   }
316  
317  
318 + void
319   fltvalue(vp)                    /* check float variable for legal values */
320   register VARIABLE       *vp;
321   {
# Line 263 | Line 324 | register VARIABLE      *vp;
324          if (isflt(vp->value)) return;
325          fprintf(stderr, "%s: illegal value for real variable '%s'\n",
326                          progname, vp->name);
327 <        exit(1);
327 >        quit(1);
328   }
329  
330  
331 + void
332   printvars(fp)                   /* print variable values */
333   register FILE   *fp;
334   {
# Line 277 | Line 339 | register FILE  *fp;
339              for (j = 0; j < vdef(i); j++) {     /* print each assignment */
340                  fputs(vnam(i), fp);
341                  fputs("= ", fp);
342 <                k = clipline = ( vv[i].fixval == catvalues ? 64 : 320 )
342 >                k = clipline = ( vv[i].fixval == catvalues ? 64 : 236 )
343                                  - strlen(vnam(i)) ;
344                  cp = nvalue(i, j);
345                  while (*cp) {
346                      putc(*cp++, fp);
347                      if (--k <= 0) {             /* line too long */
348                          while (*cp && !isspace(*cp))
349 <                            putc(*cp++, fp);    /* finish this word */
349 >                            fputc(*cp++, fp);   /* finish this word */
350                          if (*cp) {              /* start new line */
351 <                            putc('\n', fp);
352 <                            fputs(vnam(i), fp);
353 <                            putc('=', fp);
351 >                            if (vv[i].fixval == catvalues) {
352 >                                fputc('\n', fp);
353 >                                fputs(vnam(i), fp);
354 >                                fputc('=', fp);
355 >                            } else
356 >                                fputs(" \\\n", fp);
357                              k = clipline;
358                          }
359                      }
360                  }
361 <                putc('\n', fp);
361 >                fputc('\n', fp);
362              }
363          fflush(fp);
364   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines