ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/readfargs.c
Revision: 1.1
Committed: Fri Jul 19 09:24:41 1991 UTC (32 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

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