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.4 by greg, Fri Jun 4 14:28:52 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 + extern char  *bmalloc(), *savestr(), *fgetword();
25 + extern int  atoi();
26 + extern long  atol();
27  
28 +
29   readfargs(fa, fp)               /* read function arguments from stream */
30   register FUNARGS  *fa;
31   FILE  *fp;
32   {
33 + #define getstr(s)       (fgetword(s,sizeof(s),fp)!=NULL)
34 + #define getint(s)       (getstr(s) && isint(s))
35 + #define getflt(s)       (getstr(s) && isflt(s))
36          char  sbuf[MAXSTR];
37 <        int  n;
31 <        register int  i;
37 >        register int  n, i;
38  
39 <        if (fscanf(fp, "%d", &n) != 1 || n < 0)
39 >        if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
40                  return(0);
41          if (fa->nsargs = n) {
42                  fa->sarg = (char **)bmalloc(n*sizeof(char *));
43                  if (fa->sarg == NULL)
44                          return(-1);
45                  for (i = 0; i < fa->nsargs; i++) {
46 <                        if (fscanf(fp, "%s", sbuf) != 1)
46 >                        if (!getstr(sbuf))
47                                  return(0);
48                          fa->sarg[i] = savestr(sbuf);
49                  }
50          } else
51                  fa->sarg = NULL;
52 <        if (fscanf(fp, "%d", &n) != 1 || n < 0)
52 >        if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
53                  return(0);
54   #ifdef  IARGS
55          if (fa->niargs = n) {
56                  fa->iarg = (long *)bmalloc(n*sizeof(long));
57                  if (fa->iarg == NULL)
58                          return(-1);
59 <                for (i = 0; i < n; i++)
60 <                        if (fscanf(fp, "%ld", &fa->iarg[i]) != 1)
59 >                for (i = 0; i < n; i++) {
60 >                        if (!getint(sbuf))
61                                  return(0);
62 +                        fa->iarg[i] = atol(sbuf);
63 +                }
64          } else
65                  fa->iarg = NULL;
66   #else
67          if (n != 0)
68                  return(0);
69   #endif
70 <        if (fscanf(fp, "%d", &n) != 1 || n < 0)
70 >        if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
71                  return(0);
72          if (fa->nfargs = n) {
73 <                fa->farg = (double *)bmalloc(n*sizeof(double));
73 >                fa->farg = (FLOAT *)bmalloc(n*sizeof(FLOAT));
74                  if (fa->farg == NULL)
75                          return(-1);
76 <                for (i = 0; i < n; i++)
77 <                        if (fscanf(fp, "%lf", &fa->farg[i]) != 1)
76 >                for (i = 0; i < n; i++) {
77 >                        if (!getflt(sbuf))
78                                  return(0);
79 +                        fa->farg[i] = atof(sbuf);
80 +                }
81          } else
82                  fa->farg = NULL;
83          return(1);
84 + #undef getflt
85 + #undef getint
86 + #undef getstr
87   }
88  
89  
90   #ifndef  MEMHOG
91 < freefargs(fa)           /* free object arguments */
91 > freefargs(fa)                   /* free object arguments */
92   register FUNARGS  *fa;
93   {
94          register int  i;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines