Browse Source

inp_modify_exp(), cleanup #13/17, rename `ustate' --> `state'

pre-master-46
rlar 12 years ago
parent
commit
e1f8344bae
  1. 26
      src/frontend/inpcom.c

26
src/frontend/inpcom.c

@ -5498,7 +5498,7 @@ inp_modify_exp(char* expr)
char *s; char *s;
wordlist *wl = NULL, *wlist = NULL; wordlist *wl = NULL, *wlist = NULL;
char buf[512]; char buf[512];
enum { S_value = 0, S_operator, S_unary_minus } ustate = S_value;
enum { S_value = 0, S_operator, S_unary_minus } state = S_value;
/* scan the expression and remove all '{' and '}' */ /* scan the expression and remove all '{' and '}' */
for (s = expr; *s; s++) for (s = expr; *s; s++)
@ -5524,9 +5524,9 @@ inp_modify_exp(char* expr)
wl->wl_word = tprintf("%c", c); wl->wl_word = tprintf("%c", c);
s++; s++;
if (c == ')') if (c == ')')
ustate = S_value;
state = S_value;
else else
ustate = S_operator;
state = S_operator;
} else if ((c == '>') || (c == '<') || } else if ((c == '>') || (c == '<') ||
(c == '!') || (c == '=')) (c == '!') || (c == '='))
{ {
@ -5535,24 +5535,24 @@ inp_modify_exp(char* expr)
if ((*s == '=') || (*s == '<') || (*s == '>')) if ((*s == '=') || (*s == '<') || (*s == '>'))
s++; s++;
wl->wl_word = copy_substring(beg, s); wl->wl_word = copy_substring(beg, s);
ustate = S_operator;
state = S_operator;
} else if ((c == '|') || (c == '&')) { } else if ((c == '|') || (c == '&')) {
char *beg = s++; char *beg = s++;
if ((*s == '|') || (*s == '&')) if ((*s == '|') || (*s == '&'))
s++; s++;
wl->wl_word = copy_substring(beg, s); wl->wl_word = copy_substring(beg, s);
ustate = S_operator;
} else if ((c == '-') && (ustate == S_value)) {
state = S_operator;
} else if ((c == '-') && (state == S_value)) {
wl->wl_word = tprintf("%c", c); wl->wl_word = tprintf("%c", c);
s++; s++;
ustate = S_operator;
} else if ((c == '-') && (ustate == S_operator)) {
state = S_operator;
} else if ((c == '-') && (state == S_operator)) {
wl->wl_word = copy(""); wl->wl_word = copy("");
s++; s++;
ustate = S_unary_minus;
state = S_unary_minus;
} else if (isalpha(c)) { } else if (isalpha(c)) {
int i = 0; int i = 0;
if (ustate == S_unary_minus)
if (state == S_unary_minus)
buf[i++] = '-'; buf[i++] = '-';
if (((c == 'v') || (c == 'i')) && (s[1] == '(')) { if (((c == 'v') || (c == 'i')) && (s[1] == '(')) {
@ -5600,15 +5600,15 @@ inp_modify_exp(char* expr)
wl->wl_word = tprintf("{%s}", buf); wl->wl_word = tprintf("{%s}", buf);
} }
} }
ustate = S_value;
state = S_value;
} else if (isdigit(c) || (c == '.')) { /* allow .5 format too */ } else if (isdigit(c) || (c == '.')) { /* allow .5 format too */
int error1; int error1;
/* allow 100p, 5MEG etc. */ /* allow 100p, 5MEG etc. */
double dvalue = INPevaluate(&s, &error1, 0); double dvalue = INPevaluate(&s, &error1, 0);
if (ustate == S_unary_minus)
if (state == S_unary_minus)
dvalue *= -1; dvalue *= -1;
wl->wl_word = tprintf("%18.10e", dvalue); wl->wl_word = tprintf("%18.10e", dvalue);
ustate = S_value;
state = S_value;
/* skip the `unit', FIXME INPevaluate() should do this */ /* skip the `unit', FIXME INPevaluate() should do this */
while (isalpha(*s)) while (isalpha(*s))
s++; s++;

Loading…
Cancel
Save