18 |
|
|
19 |
|
#include <ctype.h> |
20 |
|
|
21 |
+ |
extern char *fgetword(), *strcpy(); |
22 |
+ |
|
23 |
|
OBJREC *objblock[MAXOBJBLK]; /* our objects */ |
24 |
|
OBJECT nobjects = 0; /* # of objects */ |
25 |
|
|
72 |
|
{ |
73 |
|
OBJECT obj; |
74 |
|
char sbuf[MAXSTR]; |
75 |
+ |
int rval; |
76 |
|
register OBJREC *objp; |
77 |
|
|
78 |
|
if ((obj = newobject()) == OVOID) |
79 |
|
error(SYSTEM, "out of object space"); |
80 |
|
objp = objptr(obj); |
81 |
|
/* get modifier */ |
82 |
< |
fscanf(fp, "%s", sbuf); |
82 |
> |
strcpy(sbuf, "EOF"); |
83 |
> |
fgetword(sbuf, MAXSTR, fp); |
84 |
|
if (!strcmp(sbuf, VOIDID)) |
85 |
|
objp->omod = OVOID; |
86 |
|
else if ((objp->omod = modifier(sbuf)) == OVOID) { |
88 |
|
error(USER, errmsg); |
89 |
|
} |
90 |
|
/* get type */ |
91 |
< |
fscanf(fp, "%s", sbuf); |
91 |
> |
strcpy(sbuf, "EOF"); |
92 |
> |
fgetword(sbuf, MAXSTR, fp); |
93 |
|
if (!strcmp(sbuf, ALIASID)) |
94 |
|
objp->otype = -1; |
95 |
|
else if ((objp->otype = otype(sbuf)) < 0) { |
97 |
|
error(USER, errmsg); |
98 |
|
} |
99 |
|
/* get identifier */ |
100 |
< |
fscanf(fp, "%s", sbuf); |
100 |
> |
sbuf[0] = '\0'; |
101 |
> |
fgetword(sbuf, MAXSTR, fp); |
102 |
|
objp->oname = savqstr(sbuf); |
103 |
|
/* get arguments */ |
104 |
|
if (objp->otype == -1) { |
105 |
|
register OBJECT alias; |
106 |
< |
fscanf(fp, "%s", sbuf); |
106 |
> |
strcpy(sbuf, "EOF"); |
107 |
> |
fgetword(sbuf, MAXSTR, fp); |
108 |
|
if ((alias = modifier(sbuf)) == OVOID) { |
109 |
|
sprintf(errmsg, |
110 |
|
"(%s): bad reference \"%s\" for %s \"%s\"", |
113 |
|
} |
114 |
|
objp->otype = objptr(alias)->otype; |
115 |
|
copystruct(&objp->oargs, &objptr(alias)->oargs); |
116 |
< |
} else if (readfargs(&objp->oargs, fp) < 0) { |
116 |
> |
} else if ((rval = readfargs(&objp->oargs, fp)) == 0) { |
117 |
|
sprintf(errmsg, "(%s): bad arguments", name); |
118 |
|
objerror(objp, USER, errmsg); |
119 |
+ |
} else if (rval < 0) { |
120 |
+ |
sprintf(errmsg, "(%s): error reading scene", name); |
121 |
+ |
error(SYSTEM, errmsg); |
122 |
|
} |
123 |
|
/* initialize */ |
124 |
|
objp->os = NULL; |
125 |
|
objp->lastrno = -1; |
126 |
|
|
127 |
|
insertobject(obj); /* add to global structure */ |
118 |
– |
} |
119 |
– |
|
120 |
– |
|
121 |
– |
readfargs(fa, fp) /* read function arguments from stream */ |
122 |
– |
register FUNARGS *fa; |
123 |
– |
FILE *fp; |
124 |
– |
{ |
125 |
– |
char sbuf[MAXSTR]; |
126 |
– |
int n; |
127 |
– |
register int i; |
128 |
– |
|
129 |
– |
if (fscanf(fp, "%d", &n) != 1 || n < 0) |
130 |
– |
return(-1); |
131 |
– |
if (fa->nsargs = n) { |
132 |
– |
fa->sarg = (char **)bmalloc(n*sizeof(char *)); |
133 |
– |
if (fa->sarg == NULL) |
134 |
– |
goto memerr; |
135 |
– |
for (i = 0; i < fa->nsargs; i++) { |
136 |
– |
if (fscanf(fp, "%s", sbuf) != 1) |
137 |
– |
return(-1); |
138 |
– |
fa->sarg[i] = savestr(sbuf); |
139 |
– |
} |
140 |
– |
} else |
141 |
– |
fa->sarg = NULL; |
142 |
– |
if (fscanf(fp, "%d", &n) != 1 || n < 0) |
143 |
– |
return(-1); |
144 |
– |
#ifdef IARGS |
145 |
– |
if (fa->niargs = n) { |
146 |
– |
fa->iarg = (long *)bmalloc(n*sizeof(long)); |
147 |
– |
if (fa->iarg == NULL) |
148 |
– |
goto memerr; |
149 |
– |
for (i = 0; i < n; i++) |
150 |
– |
if (fscanf(fp, "%ld", &fa->iarg[i]) != 1) |
151 |
– |
return(-1); |
152 |
– |
} else |
153 |
– |
fa->iarg = NULL; |
154 |
– |
#else |
155 |
– |
if (n != 0) |
156 |
– |
return(-1); |
157 |
– |
#endif |
158 |
– |
if (fscanf(fp, "%d", &n) != 1 || n < 0) |
159 |
– |
return(-1); |
160 |
– |
if (fa->nfargs = n) { |
161 |
– |
fa->farg = (double *)bmalloc(n*sizeof(double)); |
162 |
– |
if (fa->farg == NULL) |
163 |
– |
goto memerr; |
164 |
– |
for (i = 0; i < n; i++) |
165 |
– |
if (fscanf(fp, "%lf", &fa->farg[i]) != 1) |
166 |
– |
return(-1); |
167 |
– |
} else |
168 |
– |
fa->farg = NULL; |
169 |
– |
return(0); |
170 |
– |
memerr: |
171 |
– |
error(SYSTEM, "out of memory in readfargs"); |
128 |
|
} |
129 |
|
|
130 |
|
|