Browse Source

nupa_substitute(), cleanup

pre-master-46
rlar 10 years ago
parent
commit
8e69f7e70a
  1. 36
      src/frontend/numparam/xpressn.c

36
src/frontend/numparam/xpressn.c

@ -1208,19 +1208,19 @@ nupa_substitute(dico_t *dico, char * const s, char *r)
const char * const s_end = strchr(s, '\0'); const char * const s_end = strchr(s, '\0');
const char *kptr; const char *kptr;
while (((iptr - s) < (s_end - s)) && !err) {
while ((iptr < s_end) && !err) {
iptr++; iptr++;
c = s[(iptr - s) - 1];
c = iptr[-1];
if (c == '{') { if (c == '{') {
/* try ps expression syntax */ /* try ps expression syntax */
kptr = s + (iptr - s);
kptr = iptr;
nnest = 1; nnest = 1;
do do
{ {
kptr++; kptr++;
d = s[(kptr - s) - 1];
d = kptr[-1];
if (d == '{') if (d == '{')
nnest++; nnest++;
else if (d == '}') else if (d == '}')
@ -1231,7 +1231,7 @@ nupa_substitute(dico_t *dico, char * const s, char *r)
if (d == '\0') { if (d == '\0') {
err = message(dico, "Closing \"}\" not found.\n"); err = message(dico, "Closing \"}\" not found.\n");
} else { } else {
pscopy(&tstr, s, (int) (iptr - s) , (int) (kptr - s) - (int) (iptr - s) - 1);
pscopy(&tstr, s, (int) (iptr - s) , (int) (kptr - iptr - 1));
/* exeption made for .meas */ /* exeption made for .meas */
if (strcasecmp(spice_dstring_value(&tstr), "LAST") == 0) { if (strcasecmp(spice_dstring_value(&tstr), "LAST") == 0) {
spice_dstring_reinit(&qstr); spice_dstring_reinit(&qstr);
@ -1252,40 +1252,40 @@ nupa_substitute(dico_t *dico, char * const s, char *r)
} else if (c == Intro) { } else if (c == Intro) {
/* skip "&&" which may occur in B source */ /* skip "&&" which may occur in B source */
if (((iptr - s) + 1 < (s_end - s)) && (s[(iptr - s)] == Intro)) {
if ((iptr + 1 < s_end) && (*iptr == Intro)) {
iptr++; iptr++;
continue; continue;
} }
iptr++; iptr++;
while (((iptr - s) < (s_end - s)) && (s[(iptr - s) - 1] <= ' '))
while ((iptr < s_end) && (iptr[-1] <= ' '))
iptr++; iptr++;
kptr = s + (iptr - s);
kptr = iptr;
if (s[(kptr - s) - 1] == '(') {
if (kptr[-1] == '(') {
/* sub-formula */ /* sub-formula */
level = 1; level = 1;
do do
{ {
kptr++; kptr++;
if ((kptr - s) > (s_end - s))
if (kptr > s_end)
d = '\0'; d = '\0';
else else
d = s[(kptr - s) - 1];
d = kptr[-1];
if (d == '(') if (d == '(')
level++; level++;
else if (d == ')') else if (d == ')')
level--; level--;
} while (((kptr - s) <= (s_end - s)) && !((d == ')') && (level <= 0)));
} while ((kptr <= s_end) && !((d == ')') && (level <= 0)));
if ((kptr - s) > (s_end - s)) {
if (kptr > s_end) {
err = message(dico, "Closing \")\" not found.\n"); err = message(dico, "Closing \")\" not found.\n");
} else { } else {
pscopy(&tstr, s, (int) (iptr - s), (int) (kptr - s) - (int) (iptr - s) - 1);
pscopy(&tstr, s, (int) (iptr - s), (int) (kptr - iptr - 1));
const char *xx = spice_dstring_value(&tstr); const char *xx = spice_dstring_value(&tstr);
err = evaluate_expr(dico, &qstr, xx, xx + strlen(xx)); err = evaluate_expr(dico, &qstr, xx, xx + strlen(xx));
} }
@ -1298,14 +1298,14 @@ nupa_substitute(dico_t *dico, char * const s, char *r)
do do
{ {
kptr++; kptr++;
if ((kptr - s) > (s_end - s))
if (kptr > s_end)
d = '\0'; d = '\0';
else else
d = s[(kptr - s) - 1];
d = kptr[-1];
} while (((kptr - s) <= (s_end - s)) && (d > ' '));
} while ((kptr <= s_end) && (d > ' '));
pscopy(&tstr, s, (int) (iptr - s)-1, (int) (kptr - s) - (int) (iptr - s));
pscopy(&tstr, s, (int) (iptr - s)-1, (int) (kptr - iptr));
const char *xx = spice_dstring_value(&tstr); const char *xx = spice_dstring_value(&tstr);
err = evaluate_variable(dico, &qstr, xx, xx + strlen(xx)); err = evaluate_variable(dico, &qstr, xx, xx + strlen(xx));
iptr = kptr - 1; iptr = kptr - 1;

Loading…
Cancel
Save