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