ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/readfargs.c
Revision: 1.2
Committed: Mon Jul 22 11:23:00 1991 UTC (32 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +24 -12 lines
Log Message:
removed scanf calls from readfargs

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