ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/readfargs.c
Revision: 1.3
Committed: Wed Oct 23 13:43:19 1991 UTC (32 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.2: +3 -1 lines
Log Message:
added FLOAT definition to better control size of structures

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