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.7 by gwlarson, Thu Jun 4 13:29:27 1998 UTC vs.
Revision 2.15 by greg, Fri May 22 14:44:11 2015 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 +
14 + #include "standard.h"
15   #include "vars.h"
16  
17   #define NOCHAR  127             /* constant for character to delete */
18  
17 #ifndef malloc
18 extern char  *malloc(), *realloc();
19 #endif
20
19   extern char  *fgetline();
20  
21  
22 < loadvars(rfname)                /* load variables into vv from file */
23 < char    *rfname;
22 > void
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 59 | 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 91 | 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 = realloc(vp->value, i+n+1);
101 >                vp->value = (char *)realloc((void *)vp->value, i+n+1);
102          } else
103 <                vp->value = malloc(n+1);
103 >                vp->value = (char *)malloc(n+1);
104          if (vp->value == NULL) {
105                  perror(progname);
106                  quit(1);
# Line 121 | 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 135 | 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 151 | Line 154 | register int   n;
154   }
155  
156  
157 < checkvalues()                   /* check assignments */
157 > void
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 161 | Line 165 | checkvalues()                  /* check assignments */
165   }
166  
167  
168 < onevalue(vp)                    /* only one assignment for this variable */
169 < register VARIABLE       *vp;
168 > void
169 > onevalue(                       /* only one assignment for this variable */
170 >        VARIABLE        *vp
171 > )
172   {
173          if (vp->nass < 2)
174                  return;
# Line 176 | Line 182 | register VARIABLE      *vp;
182   }
183  
184  
185 < catvalues(vp)                   /* concatenate variable values */
186 < register VARIABLE       *vp;
185 > void
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 192 | 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 204 | Line 214 | register char  *tv, *cv;
214   }
215  
216  
217 < boolvalue(vp)                   /* check boolean for legal values */
218 < register VARIABLE       *vp;
217 > void
218 > boolvalue(                      /* check boolean for legal values */
219 >        VARIABLE        *vp
220 > )
221   {
222          if (!vp->nass) return;
223          onevalue(vp);
# Line 223 | Line 235 | register VARIABLE      *vp;
235   }
236  
237  
238 < qualvalue(vp)                   /* check qualitative var. for legal values */
239 < register VARIABLE       *vp;
238 > void
239 > qualvalue(                      /* check qualitative var. for legal values */
240 >        VARIABLE        *vp
241 > )
242   {
243          if (!vp->nass) return;
244          onevalue(vp);
# Line 245 | Line 259 | register VARIABLE      *vp;
259   }
260  
261  
262 < intvalue(vp)                    /* check integer variable for legal values */
263 < register VARIABLE       *vp;
262 > void
263 > intvalue(                               /* check integer variable for legal values */
264 >        VARIABLE        *vp
265 > )
266   {
267          if (!vp->nass) return;
268          onevalue(vp);
# Line 257 | Line 273 | register VARIABLE      *vp;
273   }
274  
275  
276 < fltvalue(vp)                    /* check float variable for legal values */
277 < register VARIABLE       *vp;
276 > void
277 > fltvalue(                               /* check float variable for legal values */
278 >        VARIABLE        *vp
279 > )
280   {
281          if (!vp->nass) return;
282          onevalue(vp);
# Line 269 | Line 287 | register VARIABLE      *vp;
287   }
288  
289  
290 < printvars(fp)                   /* print variable values */
291 < register FILE   *fp;
290 > void
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 */
300                  fputs(vnam(i), fp);
301                  fputs("= ", fp);
302 <                k = clipline = ( vv[i].fixval == catvalues ? 64 : 120 )
302 >                k = clipline = ( vv[i].fixval == catvalues ? 64 : 236 )
303                                  - strlen(vnam(i)) ;
304                  cp = nvalue(i, j);
305                  while (*cp) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines