nupa_assignment(), i ==> p - (const) s

This commit is contained in:
rlar 2016-05-06 19:22:37 +02:00
parent f595db7619
commit 8300021c7a
1 changed files with 20 additions and 19 deletions

View File

@ -1419,7 +1419,8 @@ 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 ... */
int i, ls; int ls;
const char *p;
bool error, err; bool error, err;
nupa_type dtype; nupa_type dtype;
int wval = 0; int wval = 0;
@ -1432,36 +1433,36 @@ nupa_assignment(dico_t *dico, const char * const s, char mode)
spice_dstring_init(&ustr); spice_dstring_init(&ustr);
ls = (int) strlen(s); ls = (int) strlen(s);
error = 0; error = 0;
i = 0; (p - s) = 0;
while ((i < ls) && (s[i] <= ' ')) while (((p - s) < ls) && (s[(p - s)] <= ' '))
i++; (p - s)++;
if (s[i] == Intro) if (s[(p - s)] == Intro)
i++; (p - s)++;
if (s[i] == '.') /* skip any dot keyword */ if (s[(p - s)] == '.') /* skip any dot keyword */
while (s[i] > ' ') while (s[(p - s)] > ' ')
i++; (p - s)++;
while ((i < ls) && !error) { while (((p - s) < ls) && !error) {
i = (int) (getword(s + i, &tstr) + 1 - s); (p - s) = (int) (getword(s + (p - s), &tstr) + 1 - s);
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");
if (!error) { if (!error) {
/* assignment expressions */ /* assignment expressions */
while ((i <= ls) && (s[i - 1] != '=')) while (((p - s) <= ls) && (s[(p - s) - 1] != '='))
i++; (p - s)++;
if (i > ls) if ((p - s) > ls)
error = message(dico, " = sign expected.\n"); error = message(dico, " = sign expected.\n");
const char *tmp = s + i; const char *tmp = s + (p - s);
tmp = getexpress(&dtype, &ustr, tmp) + 1; tmp = getexpress(&dtype, &ustr, tmp) + 1;
i = (int) (tmp - s); (p - s) = (int) (tmp - s);
if (dtype == NUPA_REAL) { if (dtype == NUPA_REAL) {
const char *tmp = spice_dstring_value(&ustr); const char *tmp = spice_dstring_value(&ustr);
@ -1471,7 +1472,7 @@ nupa_assignment(dico_t *dico, const char * const s, char mode)
" Formula() error.\n" " Formula() error.\n"
" %s\n", s); " %s\n", s);
} else if (dtype == NUPA_STRING) { } else if (dtype == NUPA_STRING) {
wval = i; wval = (int) (p - s);
} }
err = nupa_define(dico, spice_dstring_value(&tstr), mode /* was ' ' */ , err = nupa_define(dico, spice_dstring_value(&tstr), mode /* was ' ' */ ,
@ -1479,10 +1480,10 @@ nupa_assignment(dico_t *dico, const char * const s, char mode)
error = error || err; error = error || err;
} }
if ((i < ls) && (s[i - 1] != ';')) if (((p - s) < ls) && (s[(p - s) - 1] != ';'))
error = message(dico, " ; sign expected.\n"); error = message(dico, " ; sign expected.\n");
/* else /* else
i++; */ (p - s)++; */
} }
spice_dstring_free(&tstr); spice_dstring_free(&tstr);