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.5 by greg, Wed Sep 8 09:12:36 1993 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines