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