ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/readfargs.c
(Generate patch)

Comparing ray/src/common/readfargs.c (file contents):
Revision 1.1 by greg, Fri Jul 19 09:24:41 1991 UTC vs.
Revision 2.11 by greg, Thu Jun 12 22:12:20 2014 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 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   * Allocate, read and free object arguments
6   */
7  
8 < #include <stdio.h>
8 > #include "copyright.h"
9  
10 + #include "standard.h"
11 +
12   #include "object.h"
13  
14  
16 extern char  *savestr(), *malloc();
15  
16 < #ifdef  MEMHOG
17 < extern char  *bmalloc();
18 < #else
19 < #define  bmalloc        malloc
20 < #endif
23 <
24 <
25 < readfargs(fa, fp)               /* read function arguments from stream */
26 < register FUNARGS  *fa;
27 < FILE  *fp;
16 > int
17 > readfargs(                      /* read function arguments from stream */
18 >        FUNARGS  *fa,
19 >        FILE  *fp
20 > )
21   {
22 + #define getstr(s)       (fgetword(s,sizeof(s),fp)!=NULL)
23 + #define getint(s)       (getstr(s) && isint(s))
24 + #define getflt(s)       (getstr(s) && isflt(s))
25          char  sbuf[MAXSTR];
26 <        int  n;
31 <        register int  i;
26 >        int  n, i;
27  
28 <        if (fscanf(fp, "%d", &n) != 1 || n < 0)
28 >        if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
29                  return(0);
30 <        if (fa->nsargs = n) {
31 <                fa->sarg = (char **)bmalloc(n*sizeof(char *));
30 >        if ( (fa->nsargs = n) ) {
31 >                fa->sarg = (char **)malloc(n*sizeof(char *));
32                  if (fa->sarg == NULL)
33                          return(-1);
34                  for (i = 0; i < fa->nsargs; i++) {
35 <                        if (fscanf(fp, "%s", sbuf) != 1)
35 >                        if (!getstr(sbuf))
36                                  return(0);
37                          fa->sarg[i] = savestr(sbuf);
38                  }
39          } else
40                  fa->sarg = NULL;
41 <        if (fscanf(fp, "%d", &n) != 1 || n < 0)
41 >        if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
42                  return(0);
43   #ifdef  IARGS
44          if (fa->niargs = n) {
45 <                fa->iarg = (long *)bmalloc(n*sizeof(long));
45 >                fa->iarg = (long *)malloc(n*sizeof(long));
46                  if (fa->iarg == NULL)
47                          return(-1);
48 <                for (i = 0; i < n; i++)
49 <                        if (fscanf(fp, "%ld", &fa->iarg[i]) != 1)
48 >                for (i = 0; i < n; i++) {
49 >                        if (!getint(sbuf))
50                                  return(0);
51 +                        fa->iarg[i] = atol(sbuf);
52 +                }
53          } else
54                  fa->iarg = NULL;
55   #else
56          if (n != 0)
57                  return(0);
58   #endif
59 <        if (fscanf(fp, "%d", &n) != 1 || n < 0)
59 >        if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
60                  return(0);
61 <        if (fa->nfargs = n) {
62 <                fa->farg = (double *)bmalloc(n*sizeof(double));
61 >        if ( (fa->nfargs = n) ) {
62 >                fa->farg = (RREAL *)malloc(n*sizeof(RREAL));
63                  if (fa->farg == NULL)
64                          return(-1);
65 <                for (i = 0; i < n; i++)
66 <                        if (fscanf(fp, "%lf", &fa->farg[i]) != 1)
65 >                for (i = 0; i < n; i++) {
66 >                        if (!getflt(sbuf))
67                                  return(0);
68 +                        fa->farg[i] = atof(sbuf);
69 +                }
70          } else
71                  fa->farg = NULL;
72          return(1);
73 + #undef getflt
74 + #undef getint
75 + #undef getstr
76   }
77  
78  
79 < #ifndef  MEMHOG
80 < freefargs(fa)           /* free object arguments */
81 < register FUNARGS  *fa;
79 > void
80 > freefargs(                              /* free object arguments */
81 >        FUNARGS  *fa
82 > )
83   {
84 <        register int  i;
84 >        int  i;
85  
86          if (fa->nsargs) {
87                  for (i = 0; i < fa->nsargs; i++)
88                          freestr(fa->sarg[i]);
89 <                free((char *)fa->sarg);
89 >                free((void *)fa->sarg);
90 >                fa->sarg = NULL;
91 >                fa->nsargs = 0;
92          }
93   #ifdef  IARGS
94 <        if (fa->niargs)
95 <                free((char *)fa->iarg);
94 >        if (fa->niargs) {
95 >                free((void *)fa->iarg);
96 >                fa->iarg = NULL;
97 >                fa->niargs = 0;
98 >        }
99   #endif
100 <        if (fa->nfargs)
101 <                free((char *)fa->farg);
100 >        if (fa->nfargs) {
101 >                free((void *)fa->farg);
102 >                fa->farg = NULL;
103 >                fa->nfargs = 0;
104 >        }
105   }
95 #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines