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.10 by greg, Tue Feb 25 02:47:21 2003 UTC vs.
Revision 2.18 by greg, Mon Jun 5 16:32:42 2023 UTC

# Line 10 | Line 10 | static const char      RCSid[] = "$Id$";
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 18 | 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 >        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 51 | 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 88 | 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 = (char *)realloc(vp->value, i+n+1);
102 >                vp->value = (char *)realloc((void *)vp->value, i+n+1);
103          } else
104                  vp->value = (char *)malloc(n+1);
105          if (vp->value == NULL) {
# Line 118 | 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 132 | 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 149 | Line 156 | register int   n;
156  
157  
158   void
159 < checkvalues()                   /* check assignments */
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 160 | Line 167 | checkvalues()                  /* check assignments */
167  
168  
169   void
170 < onevalue(vp)                    /* only one assignment for this variable */
171 < register VARIABLE       *vp;
170 > onevalue(                       /* only one assignment for this variable */
171 >        VARIABLE        *vp
172 > )
173   {
174          if (vp->nass < 2)
175                  return;
# Line 176 | Line 184 | register VARIABLE      *vp;
184  
185  
186   void
187 < catvalues(vp)                   /* concatenate variable values */
188 < register VARIABLE       *vp;
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 205 | Line 216 | register char  *tv, *cv;
216  
217  
218   void
219 < boolvalue(vp)                   /* check boolean for legal values */
220 < register VARIABLE       *vp;
219 > boolvalue(                      /* check boolean for legal values */
220 >        VARIABLE        *vp
221 > )
222   {
223          if (!vp->nass) return;
224          onevalue(vp);
# Line 225 | Line 237 | register VARIABLE      *vp;
237  
238  
239   void
240 < qualvalue(vp)                   /* check qualitative var. for legal values */
241 < register VARIABLE       *vp;
240 > qualvalue(                      /* check qualitative var. for legal values */
241 >        VARIABLE        *vp
242 > )
243   {
244          if (!vp->nass) return;
245          onevalue(vp);
# Line 248 | Line 261 | register VARIABLE      *vp;
261  
262  
263   void
264 < intvalue(vp)                    /* check integer variable for legal values */
265 < register VARIABLE       *vp;
264 > intvalue(                               /* check integer variable for legal values */
265 >        VARIABLE        *vp
266 > )
267   {
268          if (!vp->nass) return;
269          onevalue(vp);
# Line 261 | Line 275 | register VARIABLE      *vp;
275  
276  
277   void
278 < fltvalue(vp)                    /* check float variable for legal values */
279 < register VARIABLE       *vp;
278 > fltvalue(                               /* check float variable for legal values */
279 >        VARIABLE        *vp
280 > )
281   {
282          if (!vp->nass) return;
283          onevalue(vp);
# Line 274 | Line 289 | register VARIABLE      *vp;
289  
290  
291   void
292 < printvars(fp)                   /* print variable values */
293 < register FILE   *fp;
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 */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines