nupa_assignment(), simplify error processing
This commit is contained in:
parent
66433eda0b
commit
0624584370
|
|
@ -1421,7 +1421,7 @@ nupa_assignment(dico_t *dico, const char * const s, char mode)
|
||||||
/* s has the format: ident = expression; ident= expression ... */
|
/* s has the format: ident = expression; ident= expression ... */
|
||||||
const char * const s_end = s + strlen(s);
|
const char * const s_end = s + strlen(s);
|
||||||
const char *p = s;
|
const char *p = s;
|
||||||
bool error, err;
|
bool error = 0;
|
||||||
nupa_type dtype;
|
nupa_type dtype;
|
||||||
int wval = 0;
|
int wval = 0;
|
||||||
double rval = 0.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(&tstr);
|
||||||
spice_dstring_init(&ustr);
|
spice_dstring_init(&ustr);
|
||||||
error = 0;
|
|
||||||
|
|
||||||
while ((p < s_end) && (*p <= ' '))
|
while ((p < s_end) && (*p <= ' '))
|
||||||
p++;
|
p++;
|
||||||
|
|
@ -1443,41 +1442,48 @@ nupa_assignment(dico_t *dico, const char * const s, char mode)
|
||||||
while (*p > ' ')
|
while (*p > ' ')
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
while ((p < s_end) && !error) {
|
while (p < s_end) {
|
||||||
|
|
||||||
p = getword(p, &tstr) + 1;
|
p = getword(p, &tstr) + 1;
|
||||||
t_p = spice_dstring_value(&tstr);
|
t_p = spice_dstring_value(&tstr);
|
||||||
if (t_p[0] == '\0')
|
if (t_p[0] == '\0') {
|
||||||
error = message(dico, " Identifier expected\n");
|
error = message(dico, " Identifier expected\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!error) {
|
|
||||||
/* assignment expressions */
|
/* assignment expressions */
|
||||||
while ((p <= s_end) && (p[-1] != '='))
|
while ((p <= s_end) && (p[-1] != '='))
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
if (p > s_end)
|
if (p > s_end) {
|
||||||
error = message(dico, " = sign expected.\n");
|
error = message(dico, " = sign expected.\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
p = getexpress(&dtype, &ustr, p) + 1;
|
p = getexpress(&dtype, &ustr, p) + 1;
|
||||||
|
|
||||||
if (dtype == NUPA_REAL) {
|
if (dtype == NUPA_REAL) {
|
||||||
const char *tmp = spice_dstring_value(&ustr);
|
const char *tmp = spice_dstring_value(&ustr);
|
||||||
rval = formula(dico, tmp, tmp + strlen(tmp), &error);
|
rval = formula(dico, tmp, tmp + strlen(tmp), &error);
|
||||||
if (error)
|
if (error) {
|
||||||
message(dico,
|
message(dico,
|
||||||
" Formula() error.\n"
|
" Formula() error.\n"
|
||||||
" %s\n", s);
|
" %s\n", s);
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else if (dtype == NUPA_STRING) {
|
} else if (dtype == NUPA_STRING) {
|
||||||
wval = (int) (p - s);
|
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);
|
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");
|
error = message(dico, " ; sign expected.\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
/* else
|
/* else
|
||||||
p++; */
|
p++; */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue