8 |
|
* Allocate, read and free object arguments |
9 |
|
*/ |
10 |
|
|
11 |
< |
#include <stdio.h> |
11 |
> |
#include "standard.h" |
12 |
|
|
13 |
|
#include "object.h" |
14 |
|
|
15 |
|
|
16 |
< |
extern char *savestr(), *malloc(); |
17 |
< |
|
18 |
< |
#ifdef MEMHOG |
19 |
< |
extern char *bmalloc(); |
20 |
< |
#else |
16 |
> |
#ifndef MEMHOG |
17 |
|
#define bmalloc malloc |
18 |
|
#endif |
19 |
|
|
20 |
+ |
extern char *fgetword(); |
21 |
+ |
extern int atoi(); |
22 |
+ |
extern long atol(); |
23 |
|
|
24 |
+ |
|
25 |
|
readfargs(fa, fp) /* read function arguments from stream */ |
26 |
|
register FUNARGS *fa; |
27 |
|
FILE *fp; |
28 |
|
{ |
29 |
+ |
#define getstr(s) (fgetword(s,sizeof(s),fp)!=NULL) |
30 |
+ |
#define getint(s) (getstr(s) && isint(s)) |
31 |
+ |
#define getflt(s) (getstr(s) && isflt(s)) |
32 |
|
char sbuf[MAXSTR]; |
33 |
< |
int n; |
31 |
< |
register int i; |
33 |
> |
register int n, i; |
34 |
|
|
35 |
< |
if (fscanf(fp, "%d", &n) != 1 || n < 0) |
35 |
> |
if (!getint(sbuf) || (n = atoi(sbuf)) < 0) |
36 |
|
return(0); |
37 |
|
if (fa->nsargs = n) { |
38 |
|
fa->sarg = (char **)bmalloc(n*sizeof(char *)); |
39 |
|
if (fa->sarg == NULL) |
40 |
|
return(-1); |
41 |
|
for (i = 0; i < fa->nsargs; i++) { |
42 |
< |
if (fscanf(fp, "%s", sbuf) != 1) |
42 |
> |
if (!getstr(sbuf)) |
43 |
|
return(0); |
44 |
|
fa->sarg[i] = savestr(sbuf); |
45 |
|
} |
46 |
|
} else |
47 |
|
fa->sarg = NULL; |
48 |
< |
if (fscanf(fp, "%d", &n) != 1 || n < 0) |
48 |
> |
if (!getint(sbuf) || (n = atoi(sbuf)) < 0) |
49 |
|
return(0); |
50 |
|
#ifdef IARGS |
51 |
|
if (fa->niargs = n) { |
52 |
|
fa->iarg = (long *)bmalloc(n*sizeof(long)); |
53 |
|
if (fa->iarg == NULL) |
54 |
|
return(-1); |
55 |
< |
for (i = 0; i < n; i++) |
56 |
< |
if (fscanf(fp, "%ld", &fa->iarg[i]) != 1) |
55 |
> |
for (i = 0; i < n; i++) { |
56 |
> |
if (!getint(sbuf)) |
57 |
|
return(0); |
58 |
+ |
fa->iarg[i] = atol(sbuf); |
59 |
+ |
} |
60 |
|
} else |
61 |
|
fa->iarg = NULL; |
62 |
|
#else |
63 |
|
if (n != 0) |
64 |
|
return(0); |
65 |
|
#endif |
66 |
< |
if (fscanf(fp, "%d", &n) != 1 || n < 0) |
66 |
> |
if (!getint(sbuf) || (n = atoi(sbuf)) < 0) |
67 |
|
return(0); |
68 |
|
if (fa->nfargs = n) { |
69 |
< |
fa->farg = (double *)bmalloc(n*sizeof(double)); |
69 |
> |
fa->farg = (FLOAT *)bmalloc(n*sizeof(FLOAT)); |
70 |
|
if (fa->farg == NULL) |
71 |
|
return(-1); |
72 |
< |
for (i = 0; i < n; i++) |
73 |
< |
if (fscanf(fp, "%lf", &fa->farg[i]) != 1) |
72 |
> |
for (i = 0; i < n; i++) { |
73 |
> |
if (!getflt(sbuf)) |
74 |
|
return(0); |
75 |
+ |
fa->farg[i] = atof(sbuf); |
76 |
+ |
} |
77 |
|
} else |
78 |
|
fa->farg = NULL; |
79 |
|
return(1); |
80 |
+ |
#undef getflt |
81 |
+ |
#undef getint |
82 |
+ |
#undef getstr |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
#ifndef MEMHOG |
87 |
< |
freefargs(fa) /* free object arguments */ |
87 |
> |
freefargs(fa) /* free object arguments */ |
88 |
|
register FUNARGS *fa; |
89 |
|
{ |
90 |
|
register int i; |