ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/readfargs.c
Revision: 2.11
Committed: Thu Jun 12 22:12:20 2014 UTC (10 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad4R2P2, rad5R0, rad5R1, rad4R2, rad4R2P1, rad5R3, HEAD
Changes since 2.10: +10 -8 lines
Log Message:
ANSIfication

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.11 static const char RCSid[] = "$Id: readfargs.c,v 2.10 2003/07/27 22:12:01 schorsch Exp $";
3 greg 1.1 #endif
4     /*
5     * Allocate, read and free object arguments
6     */
7    
8 greg 2.8 #include "copyright.h"
9 greg 2.7
10 gwlarson 2.6 #include "standard.h"
11 greg 1.1
12     #include "object.h"
13    
14    
15    
16 greg 2.7 int
17 greg 2.11 readfargs( /* read function arguments from stream */
18     FUNARGS *fa,
19     FILE *fp
20     )
21 greg 1.1 {
22 greg 2.3 #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 greg 1.1 char sbuf[MAXSTR];
26 greg 2.11 int n, i;
27 greg 1.1
28 greg 2.3 if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
29 greg 1.1 return(0);
30 schorsch 2.10 if ( (fa->nsargs = n) ) {
31 greg 2.7 fa->sarg = (char **)malloc(n*sizeof(char *));
32 greg 1.1 if (fa->sarg == NULL)
33     return(-1);
34     for (i = 0; i < fa->nsargs; i++) {
35 greg 2.3 if (!getstr(sbuf))
36 greg 1.1 return(0);
37     fa->sarg[i] = savestr(sbuf);
38     }
39     } else
40     fa->sarg = NULL;
41 greg 2.3 if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
42 greg 1.1 return(0);
43     #ifdef IARGS
44     if (fa->niargs = n) {
45 greg 2.7 fa->iarg = (long *)malloc(n*sizeof(long));
46 greg 1.1 if (fa->iarg == NULL)
47     return(-1);
48 greg 1.2 for (i = 0; i < n; i++) {
49 greg 2.3 if (!getint(sbuf))
50 greg 1.1 return(0);
51 greg 1.2 fa->iarg[i] = atol(sbuf);
52     }
53 greg 1.1 } else
54     fa->iarg = NULL;
55     #else
56     if (n != 0)
57     return(0);
58     #endif
59 greg 2.3 if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
60 greg 1.1 return(0);
61 schorsch 2.10 if ( (fa->nfargs = n) ) {
62 schorsch 2.9 fa->farg = (RREAL *)malloc(n*sizeof(RREAL));
63 greg 1.1 if (fa->farg == NULL)
64     return(-1);
65 greg 1.2 for (i = 0; i < n; i++) {
66 greg 2.3 if (!getflt(sbuf))
67 greg 1.1 return(0);
68 greg 1.2 fa->farg[i] = atof(sbuf);
69     }
70 greg 1.1 } else
71     fa->farg = NULL;
72     return(1);
73 greg 1.2 #undef getflt
74     #undef getint
75     #undef getstr
76 greg 1.1 }
77    
78    
79 greg 2.7 void
80 greg 2.11 freefargs( /* free object arguments */
81     FUNARGS *fa
82     )
83 greg 1.1 {
84 greg 2.11 int i;
85 greg 1.1
86     if (fa->nsargs) {
87     for (i = 0; i < fa->nsargs; i++)
88     freestr(fa->sarg[i]);
89 greg 2.7 free((void *)fa->sarg);
90     fa->sarg = NULL;
91     fa->nsargs = 0;
92 greg 1.1 }
93     #ifdef IARGS
94 greg 2.7 if (fa->niargs) {
95     free((void *)fa->iarg);
96     fa->iarg = NULL;
97     fa->niargs = 0;
98     }
99 greg 1.1 #endif
100 greg 2.7 if (fa->nfargs) {
101     free((void *)fa->farg);
102     fa->farg = NULL;
103     fa->nfargs = 0;
104     }
105 greg 1.1 }