1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Allocate, read and free object arguments |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include <stdio.h> |
8 |
> |
#include "copyright.h" |
9 |
|
|
10 |
< |
#include "fvect.h" |
10 |
> |
#include "standard.h" |
11 |
|
|
12 |
|
#include "object.h" |
13 |
|
|
14 |
|
|
18 |
– |
extern char *savestr(), *malloc(), *fgetword(); |
19 |
– |
extern double atof(); |
20 |
– |
extern int atoi(); |
21 |
– |
extern long atol(); |
15 |
|
|
16 |
< |
#ifdef MEMHOG |
24 |
< |
extern char *bmalloc(); |
25 |
< |
#else |
26 |
< |
#define bmalloc malloc |
27 |
< |
#endif |
28 |
< |
|
29 |
< |
|
16 |
> |
int |
17 |
|
readfargs(fa, fp) /* read function arguments from stream */ |
18 |
|
register FUNARGS *fa; |
19 |
|
FILE *fp; |
20 |
|
{ |
21 |
< |
#define getstr() (fgetword(sbuf,MAXSTR,fp)!=NULL) |
22 |
< |
#define getint() (getstr() && isint(sbuf)) |
23 |
< |
#define getflt() (getstr() && isflt(sbuf)) |
21 |
> |
#define getstr(s) (fgetword(s,sizeof(s),fp)!=NULL) |
22 |
> |
#define getint(s) (getstr(s) && isint(s)) |
23 |
> |
#define getflt(s) (getstr(s) && isflt(s)) |
24 |
|
char sbuf[MAXSTR]; |
25 |
|
register int n, i; |
26 |
|
|
27 |
< |
if (!getint() || (n = atoi(sbuf)) < 0) |
27 |
> |
if (!getint(sbuf) || (n = atoi(sbuf)) < 0) |
28 |
|
return(0); |
29 |
< |
if (fa->nsargs = n) { |
30 |
< |
fa->sarg = (char **)bmalloc(n*sizeof(char *)); |
29 |
> |
if ( (fa->nsargs = n) ) { |
30 |
> |
fa->sarg = (char **)malloc(n*sizeof(char *)); |
31 |
|
if (fa->sarg == NULL) |
32 |
|
return(-1); |
33 |
|
for (i = 0; i < fa->nsargs; i++) { |
34 |
< |
if (!getstr()) |
34 |
> |
if (!getstr(sbuf)) |
35 |
|
return(0); |
36 |
|
fa->sarg[i] = savestr(sbuf); |
37 |
|
} |
38 |
|
} else |
39 |
|
fa->sarg = NULL; |
40 |
< |
if (!getint() || (n = atoi(sbuf)) < 0) |
40 |
> |
if (!getint(sbuf) || (n = atoi(sbuf)) < 0) |
41 |
|
return(0); |
42 |
|
#ifdef IARGS |
43 |
|
if (fa->niargs = n) { |
44 |
< |
fa->iarg = (long *)bmalloc(n*sizeof(long)); |
44 |
> |
fa->iarg = (long *)malloc(n*sizeof(long)); |
45 |
|
if (fa->iarg == NULL) |
46 |
|
return(-1); |
47 |
|
for (i = 0; i < n; i++) { |
48 |
< |
if (!getint()) |
48 |
> |
if (!getint(sbuf)) |
49 |
|
return(0); |
50 |
|
fa->iarg[i] = atol(sbuf); |
51 |
|
} |
55 |
|
if (n != 0) |
56 |
|
return(0); |
57 |
|
#endif |
58 |
< |
if (!getint() || (n = atoi(sbuf)) < 0) |
58 |
> |
if (!getint(sbuf) || (n = atoi(sbuf)) < 0) |
59 |
|
return(0); |
60 |
< |
if (fa->nfargs = n) { |
61 |
< |
fa->farg = (FLOAT *)bmalloc(n*sizeof(FLOAT)); |
60 |
> |
if ( (fa->nfargs = n) ) { |
61 |
> |
fa->farg = (RREAL *)malloc(n*sizeof(RREAL)); |
62 |
|
if (fa->farg == NULL) |
63 |
|
return(-1); |
64 |
|
for (i = 0; i < n; i++) { |
65 |
< |
if (!getflt()) |
65 |
> |
if (!getflt(sbuf)) |
66 |
|
return(0); |
67 |
|
fa->farg[i] = atof(sbuf); |
68 |
|
} |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
< |
#ifndef MEMHOG |
78 |
> |
void |
79 |
|
freefargs(fa) /* free object arguments */ |
80 |
|
register FUNARGS *fa; |
81 |
|
{ |
84 |
|
if (fa->nsargs) { |
85 |
|
for (i = 0; i < fa->nsargs; i++) |
86 |
|
freestr(fa->sarg[i]); |
87 |
< |
free((char *)fa->sarg); |
87 |
> |
free((void *)fa->sarg); |
88 |
> |
fa->sarg = NULL; |
89 |
> |
fa->nsargs = 0; |
90 |
|
} |
91 |
|
#ifdef IARGS |
92 |
< |
if (fa->niargs) |
93 |
< |
free((char *)fa->iarg); |
92 |
> |
if (fa->niargs) { |
93 |
> |
free((void *)fa->iarg); |
94 |
> |
fa->iarg = NULL; |
95 |
> |
fa->niargs = 0; |
96 |
> |
} |
97 |
|
#endif |
98 |
< |
if (fa->nfargs) |
99 |
< |
free((char *)fa->farg); |
98 |
> |
if (fa->nfargs) { |
99 |
> |
free((void *)fa->farg); |
100 |
> |
fa->farg = NULL; |
101 |
> |
fa->nfargs = 0; |
102 |
> |
} |
103 |
|
} |
109 |
– |
#endif |