ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/readfargs.c
Revision: 2.4
Committed: Fri Jun 4 14:28:52 1993 UTC (30 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.3: +2 -3 lines
Log Message:
Removed unnecessary declaration of atof()

File Contents

# Content
1 /* Copyright (c) 1991 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * Allocate, read and free object arguments
9 */
10
11 #include <stdio.h>
12
13 #include <math.h>
14
15 #include "fvect.h"
16
17 #include "object.h"
18
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 register int n, i;
38
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 (!getstr(sbuf))
47 return(0);
48 fa->sarg[i] = savestr(sbuf);
49 }
50 } else
51 fa->sarg = NULL;
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 (!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 (!getint(sbuf) || (n = atoi(sbuf)) < 0)
71 return(0);
72 if (fa->nfargs = n) {
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 (!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 */
92 register FUNARGS *fa;
93 {
94 register int i;
95
96 if (fa->nsargs) {
97 for (i = 0; i < fa->nsargs; i++)
98 freestr(fa->sarg[i]);
99 free((char *)fa->sarg);
100 }
101 #ifdef IARGS
102 if (fa->niargs)
103 free((char *)fa->iarg);
104 #endif
105 if (fa->nfargs)
106 free((char *)fa->farg);
107 }
108 #endif