nupa_assignment(), simplify error processing

This commit is contained in:
rlar 2017-11-18 15:55:43 +01:00
parent 66433eda0b
commit 0624584370
1 changed files with 17 additions and 11 deletions

View File

@ -1421,7 +1421,7 @@ nupa_assignment(dico_t *dico, const char * const s, char mode)
/* s has the format: ident = expression; ident= expression ... */
const char * const s_end = s + strlen(s);
const char *p = s;
bool error, err;
bool error = 0;
nupa_type dtype;
int wval = 0;
double rval = 0.0;
@ -1431,7 +1431,6 @@ nupa_assignment(dico_t *dico, const char * const s, char mode)
spice_dstring_init(&tstr);
spice_dstring_init(&ustr);
error = 0;
while ((p < s_end) && (*p <= ' '))
p++;
@ -1443,41 +1442,48 @@ nupa_assignment(dico_t *dico, const char * const s, char mode)
while (*p > ' ')
p++;
while ((p < s_end) && !error) {
while (p < s_end) {
p = getword(p, &tstr) + 1;
t_p = spice_dstring_value(&tstr);
if (t_p[0] == '\0')
if (t_p[0] == '\0') {
error = message(dico, " Identifier expected\n");
break;
}
if (!error) {
/* assignment expressions */
while ((p <= s_end) && (p[-1] != '='))
p++;
if (p > s_end)
if (p > s_end) {
error = message(dico, " = sign expected.\n");
break;
}
p = getexpress(&dtype, &ustr, p) + 1;
if (dtype == NUPA_REAL) {
const char *tmp = spice_dstring_value(&ustr);
rval = formula(dico, tmp, tmp + strlen(tmp), &error);
if (error)
if (error) {
message(dico,
" Formula() error.\n"
" %s\n", s);
break;
}
} else if (dtype == NUPA_STRING) {
wval = (int) (p - s);
}
err = nupa_define(dico, spice_dstring_value(&tstr), mode /* was ' ' */ ,
error = nupa_define(dico, spice_dstring_value(&tstr), mode /* was ' ' */ ,
dtype, rval, wval, NULL);
error = error || err;
}
if (error)
break;
if ((p < s_end) && (p[-1] != ';'))
if ((p < s_end) && (p[-1] != ';')) {
error = message(dico, " ; sign expected.\n");
break;
}
/* else
p++; */
}