32 |
|
fp = stdin; |
33 |
|
else if ((fp = fopen(rfname, "r")) == NULL) { |
34 |
|
perror(rfname); |
35 |
< |
exit(1); |
35 |
> |
quit(1); |
36 |
|
} |
37 |
|
while (fgetline(buf, sizeof(buf), fp) != NULL) { |
38 |
|
for (cp = buf; *cp; cp++) { |
48 |
|
} |
49 |
|
break; |
50 |
|
} |
51 |
< |
setvariable(buf); |
51 |
> |
if (setvariable(buf, matchvar) < 0) { |
52 |
> |
fprintf(stderr, "%s: unknown variable: %s\n", |
53 |
> |
rfname, buf); |
54 |
> |
quit(1); |
55 |
> |
} |
56 |
|
} |
57 |
|
fclose(fp); |
58 |
|
} |
59 |
|
|
60 |
|
|
61 |
< |
setvariable(ass) /* assign variable according to string */ |
61 |
> |
int |
62 |
> |
setvariable(ass, mv) /* assign variable according to string */ |
63 |
|
register char *ass; |
64 |
+ |
VARIABLE *(*mv)(); |
65 |
|
{ |
66 |
|
char varname[32]; |
67 |
|
int n; |
77 |
|
*cp++ = *ass++; |
78 |
|
*cp = '\0'; |
79 |
|
if (!varname[0]) |
80 |
< |
return; /* no variable name! */ |
80 |
> |
return(0); /* no variable name! */ |
81 |
|
/* trim value */ |
82 |
|
while (isspace(*ass) || *ass == '=') |
83 |
|
ass++; |
84 |
|
for (n = strlen(ass); n > 0; n--) |
85 |
|
if (!isspace(ass[n-1])) |
86 |
|
break; |
87 |
< |
if (!n) { |
88 |
< |
if (!nowarn) |
83 |
< |
fprintf(stderr, |
84 |
< |
"%s: warning - missing value for variable '%s'\n", |
85 |
< |
progname, varname); |
86 |
< |
return; |
87 |
< |
} |
87 |
> |
if (!n) |
88 |
> |
return(0); /* no assignment */ |
89 |
|
/* match variable from list */ |
90 |
< |
vp = matchvar(varname); |
91 |
< |
if (vp == NULL) { |
92 |
< |
fprintf(stderr, "%s: unknown variable '%s'\n", |
92 |
< |
progname, varname); |
93 |
< |
exit(1); |
94 |
< |
} |
90 |
> |
vp = (*mv)(varname); |
91 |
> |
if (vp == NULL) |
92 |
> |
return(-1); |
93 |
|
/* assign new value */ |
94 |
|
if (i = vp->nass) { |
95 |
|
cp = vp->value; |
102 |
|
vp->value = malloc(n+1); |
103 |
|
if (vp->value == NULL) { |
104 |
|
perror(progname); |
105 |
< |
exit(1); |
105 |
> |
quit(1); |
106 |
|
} |
107 |
|
cp = vp->value+i; /* copy value, squeezing spaces */ |
108 |
|
*cp = *ass; |
116 |
|
} |
117 |
|
if (isspace(*cp)) /* remove trailing space */ |
118 |
|
*cp = '\0'; |
119 |
< |
vp->nass++; |
119 |
> |
return(++vp->nass); |
120 |
|
} |
121 |
|
|
122 |
|
|
219 |
|
} |
220 |
|
fprintf(stderr, "%s: illegal value for boolean variable '%s'\n", |
221 |
|
progname, vp->name); |
222 |
< |
exit(1); |
222 |
> |
quit(1); |
223 |
|
} |
224 |
|
|
225 |
|
|
241 |
|
} |
242 |
|
fprintf(stderr, "%s: illegal value for qualitative variable '%s'\n", |
243 |
|
progname, vp->name); |
244 |
< |
exit(1); |
244 |
> |
quit(1); |
245 |
|
} |
246 |
|
|
247 |
|
|
253 |
|
if (isint(vp->value)) return; |
254 |
|
fprintf(stderr, "%s: illegal value for integer variable '%s'\n", |
255 |
|
progname, vp->name); |
256 |
< |
exit(1); |
256 |
> |
quit(1); |
257 |
|
} |
258 |
|
|
259 |
|
|
265 |
|
if (isflt(vp->value)) return; |
266 |
|
fprintf(stderr, "%s: illegal value for real variable '%s'\n", |
267 |
|
progname, vp->name); |
268 |
< |
exit(1); |
268 |
> |
quit(1); |
269 |
|
} |
270 |
|
|
271 |
|
|