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.9 by greg, Sat Feb 22 02:07:22 2003 UTC vs.
Revision 2.15 by greg, Fri May 22 14:44:11 2015 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
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 < */
8 > #include "copyright.h"
9  
10   #include <stdio.h>
11   #include <stdlib.h>
12   #include <ctype.h>
13 +
14 + #include "standard.h"
15   #include "vars.h"
16  
17   #define NOCHAR  127             /* constant for character to delete */
# Line 73 | Line 20 | extern char  *fgetline();
20  
21  
22   void
23 < loadvars(rfname)                /* load variables into vv from file */
24 < char    *rfname;
23 > loadvars(                       /* load variables into vv from file */
24 >        char    *rfname
25 > )
26   {
27          FILE    *fp;
28          char    buf[512];
29 <        register char   *cp;
29 >        char    *cp;
30  
31          if (rfname == NULL)
32                  fp = stdin;
# Line 111 | Line 59 | char   *rfname;
59  
60  
61   int
62 < setvariable(ass, mv)            /* assign variable according to string */
63 < register char   *ass;
64 < VARIABLE        *(*mv)();
62 > setvariable(                    /* assign variable according to string */
63 >        char    *ass,
64 >        VARIABLE        *(*mv)(char*)
65 > )
66   {
67          char    varname[32];
68          int     n;
69 <        register char   *cp;
70 <        register VARIABLE       *vp;
71 <        register int    i;
69 >        char    *cp;
70 >        VARIABLE        *vp;
71 >        int     i;
72  
73          while (isspace(*ass))           /* skip leading space */
74                  ass++;
# Line 143 | Line 92 | VARIABLE       *(*mv)();
92          if (vp == NULL)
93                  return(-1);
94                                          /* assign new value */
95 <        if (i = vp->nass) {
95 >        if ( (i = vp->nass) ) {
96                  cp = vp->value;
97                  while (i--)
98                          while (*cp++)
99                                  ;
100                  i = cp - vp->value;
101 <                vp->value = (char *)realloc(vp->value, i+n+1);
101 >                vp->value = (char *)realloc((void *)vp->value, i+n+1);
102          } else
103                  vp->value = (char *)malloc(n+1);
104          if (vp->value == NULL) {
# Line 173 | Line 122 | VARIABLE       *(*mv)();
122  
123  
124   VARIABLE *
125 < matchvar(nam)                   /* match a variable by its name */
126 < char    *nam;
125 > matchvar(                       /* match a variable by its name */
126 >        char    *nam
127 > )
128   {
129          int     n = strlen(nam);
130 <        register int    i;
130 >        int     i;
131  
132          for (i = 0; i < NVARS; i++)
133                  if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n))
# Line 187 | Line 137 | char   *nam;
137  
138  
139   char *
140 < nvalue(vn, n)                   /* return nth variable value */
141 < register int    vn;
142 < register int    n;
140 > nvalue(                         /* return nth variable value */
141 >        int     vn,
142 >        int     n
143 > )
144   {
145 <        register char   *cp;
145 >        char    *cp;
146  
147 <        if (vval(vn) == NULL | n < 0 | n >= vdef(vn))
147 >        if ((vval(vn) == NULL) | (n < 0) | (n >= vdef(vn)))
148                  return(NULL);
149          cp = vval(vn);
150          while (n--)
# Line 204 | Line 155 | register int   n;
155  
156  
157   void
158 < checkvalues()                   /* check assignments */
158 > checkvalues(void)               /* check assignments */
159   {
160 <        register int    i;
160 >        int     i;
161  
162          for (i = 0; i < NVARS; i++)
163                  if (vv[i].fixval != NULL)
# Line 215 | Line 166 | checkvalues()                  /* check assignments */
166  
167  
168   void
169 < onevalue(vp)                    /* only one assignment for this variable */
170 < register VARIABLE       *vp;
169 > onevalue(                       /* only one assignment for this variable */
170 >        VARIABLE        *vp
171 > )
172   {
173          if (vp->nass < 2)
174                  return;
# Line 231 | Line 183 | register VARIABLE      *vp;
183  
184  
185   void
186 < catvalues(vp)                   /* concatenate variable values */
187 < register VARIABLE       *vp;
186 > catvalues(                      /* concatenate variable values */
187 >        VARIABLE        *vp
188 > )
189   {
190 <        register char   *cp;
190 >        char    *cp;
191  
192          if (vp->nass < 2)
193                  return;
# Line 247 | Line 200 | register VARIABLE      *vp;
200  
201  
202   int
203 < badmatch(tv, cv)                /* case insensitive truncated comparison */
204 < register char   *tv, *cv;
203 > badmatch(                       /* case insensitive truncated comparison */
204 >        char    *tv,
205 >        char    *cv
206 > )
207   {
208          if (!*tv) return(1);            /* null string cannot match */
209          do
# Line 260 | Line 215 | register char  *tv, *cv;
215  
216  
217   void
218 < boolvalue(vp)                   /* check boolean for legal values */
219 < register VARIABLE       *vp;
218 > boolvalue(                      /* check boolean for legal values */
219 >        VARIABLE        *vp
220 > )
221   {
222          if (!vp->nass) return;
223          onevalue(vp);
# Line 280 | Line 236 | register VARIABLE      *vp;
236  
237  
238   void
239 < qualvalue(vp)                   /* check qualitative var. for legal values */
240 < register VARIABLE       *vp;
239 > qualvalue(                      /* check qualitative var. for legal values */
240 >        VARIABLE        *vp
241 > )
242   {
243          if (!vp->nass) return;
244          onevalue(vp);
# Line 303 | Line 260 | register VARIABLE      *vp;
260  
261  
262   void
263 < intvalue(vp)                    /* check integer variable for legal values */
264 < register VARIABLE       *vp;
263 > intvalue(                               /* check integer variable for legal values */
264 >        VARIABLE        *vp
265 > )
266   {
267          if (!vp->nass) return;
268          onevalue(vp);
# Line 316 | Line 274 | register VARIABLE      *vp;
274  
275  
276   void
277 < fltvalue(vp)                    /* check float variable for legal values */
278 < register VARIABLE       *vp;
277 > fltvalue(                               /* check float variable for legal values */
278 >        VARIABLE        *vp
279 > )
280   {
281          if (!vp->nass) return;
282          onevalue(vp);
# Line 329 | Line 288 | register VARIABLE      *vp;
288  
289  
290   void
291 < printvars(fp)                   /* print variable values */
292 < register FILE   *fp;
291 > printvars(                              /* print variable values */
292 >        FILE    *fp
293 > )
294   {
295          int     i, j, k, clipline;
296 <        register char   *cp;
296 >        char    *cp;
297  
298          for (i = 0; i < NVARS; i++)             /* print each variable */
299              for (j = 0; j < vdef(i); j++) {     /* print each assignment */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines