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.18 by greg, Mon Jun 5 16:32:42 2023 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 >        const 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 54 | Line 54 | char   *rfname;
54                          quit(1);
55                  }
56          }
57 <        fclose(fp);
57 >        if (fp != stdin)
58 >                fclose(fp);
59   }
60  
61  
62   int
63 < setvariable(ass, mv)            /* assign variable according to string */
64 < register char   *ass;
65 < VARIABLE        *(*mv)();
63 > setvariable(                    /* assign variable according to string */
64 >        const char      *ass,
65 >        VARIABLE        *(*mv)(const char*)
66 > )
67   {
68          char    varname[32];
69          int     n;
70 <        register char   *cp;
71 <        register VARIABLE       *vp;
72 <        register int    i;
70 >        char    *cp;
71 >        VARIABLE        *vp;
72 >        int     i;
73  
74          while (isspace(*ass))           /* skip leading space */
75                  ass++;
# Line 91 | Line 93 | VARIABLE       *(*mv)();
93          if (vp == NULL)
94                  return(-1);
95                                          /* assign new value */
96 <        if (i = vp->nass) {
96 >        if ( (i = vp->nass) ) {
97                  cp = vp->value;
98                  while (i--)
99                          while (*cp++)
100                                  ;
101                  i = cp - vp->value;
102 <                vp->value = realloc(vp->value, i+n+1);
102 >                vp->value = (char *)realloc((void *)vp->value, i+n+1);
103          } else
104 <                vp->value = malloc(n+1);
104 >                vp->value = (char *)malloc(n+1);
105          if (vp->value == NULL) {
106                  perror(progname);
107                  quit(1);
# Line 121 | Line 123 | VARIABLE       *(*mv)();
123  
124  
125   VARIABLE *
126 < matchvar(nam)                   /* match a variable by its name */
127 < char    *nam;
126 > matchvar(                       /* match a variable by its name */
127 >        const char      *nam
128 > )
129   {
130          int     n = strlen(nam);
131 <        register int    i;
131 >        int     i;
132  
133          for (i = 0; i < NVARS; i++)
134                  if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n))
# Line 135 | Line 138 | char   *nam;
138  
139  
140   char *
141 < nvalue(vn, n)                   /* return nth variable value */
142 < register int    vn;
143 < register int    n;
141 > nvalue(                         /* return nth variable value */
142 >        int     vn,
143 >        int     n
144 > )
145   {
146 <        register char   *cp;
146 >        char    *cp;
147  
148 <        if (vval(vn) == NULL | n < 0 | n >= vdef(vn))
148 >        if ((vval(vn) == NULL) | (n < 0) | (n >= vdef(vn)))
149                  return(NULL);
150          cp = vval(vn);
151          while (n--)
# Line 151 | Line 155 | register int   n;
155   }
156  
157  
158 < checkvalues()                   /* check assignments */
158 > void
159 > checkvalues(void)               /* check assignments */
160   {
161 <        register int    i;
161 >        int     i;
162  
163          for (i = 0; i < NVARS; i++)
164                  if (vv[i].fixval != NULL)
# Line 161 | Line 166 | checkvalues()                  /* check assignments */
166   }
167  
168  
169 < onevalue(vp)                    /* only one assignment for this variable */
170 < register VARIABLE       *vp;
169 > void
170 > onevalue(                       /* only one assignment for this variable */
171 >        VARIABLE        *vp
172 > )
173   {
174          if (vp->nass < 2)
175                  return;
# Line 176 | Line 183 | register VARIABLE      *vp;
183   }
184  
185  
186 < catvalues(vp)                   /* concatenate variable values */
187 < register VARIABLE       *vp;
186 > void
187 > catvalues(                      /* concatenate variable values */
188 >        VARIABLE        *vp
189 > )
190   {
191 <        register char   *cp;
191 >        char    *cp;
192  
193          if (vp->nass < 2)
194                  return;
# Line 192 | Line 201 | register VARIABLE      *vp;
201  
202  
203   int
204 < badmatch(tv, cv)                /* case insensitive truncated comparison */
205 < register char   *tv, *cv;
204 > badmatch(                       /* case insensitive truncated comparison */
205 >        char    *tv,
206 >        char    *cv
207 > )
208   {
209          if (!*tv) return(1);            /* null string cannot match */
210          do
# Line 204 | Line 215 | register char  *tv, *cv;
215   }
216  
217  
218 < boolvalue(vp)                   /* check boolean for legal values */
219 < register VARIABLE       *vp;
218 > void
219 > boolvalue(                      /* check boolean for legal values */
220 >        VARIABLE        *vp
221 > )
222   {
223          if (!vp->nass) return;
224          onevalue(vp);
# Line 223 | Line 236 | register VARIABLE      *vp;
236   }
237  
238  
239 < qualvalue(vp)                   /* check qualitative var. for legal values */
240 < register VARIABLE       *vp;
239 > void
240 > qualvalue(                      /* check qualitative var. for legal values */
241 >        VARIABLE        *vp
242 > )
243   {
244          if (!vp->nass) return;
245          onevalue(vp);
# Line 245 | Line 260 | register VARIABLE      *vp;
260   }
261  
262  
263 < intvalue(vp)                    /* check integer variable for legal values */
264 < register VARIABLE       *vp;
263 > void
264 > intvalue(                               /* check integer variable for legal values */
265 >        VARIABLE        *vp
266 > )
267   {
268          if (!vp->nass) return;
269          onevalue(vp);
# Line 257 | Line 274 | register VARIABLE      *vp;
274   }
275  
276  
277 < fltvalue(vp)                    /* check float variable for legal values */
278 < register VARIABLE       *vp;
277 > void
278 > fltvalue(                               /* check float variable for legal values */
279 >        VARIABLE        *vp
280 > )
281   {
282          if (!vp->nass) return;
283          onevalue(vp);
# Line 269 | Line 288 | register VARIABLE      *vp;
288   }
289  
290  
291 < printvars(fp)                   /* print variable values */
292 < register FILE   *fp;
291 > void
292 > printvars(                              /* print variable values */
293 >        FILE    *fp
294 > )
295   {
296          int     i, j, k, clipline;
297 <        register char   *cp;
297 >        char    *cp;
298  
299          for (i = 0; i < NVARS; i++)             /* print each variable */
300              for (j = 0; j < vdef(i); j++) {     /* print each assignment */
301                  fputs(vnam(i), fp);
302                  fputs("= ", fp);
303 <                k = clipline = ( vv[i].fixval == catvalues ? 64 : 120 )
303 >                k = clipline = ( vv[i].fixval == catvalues ? 64 : 236 )
304                                  - strlen(vnam(i)) ;
305                  cp = nvalue(i, j);
306                  while (*cp) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines