inpcom.c, use inp_modify_exp() to remove duplicated code in inp_bsource_compat()
This commit is contained in:
parent
5464859ebb
commit
8b04ff6b7c
|
|
@ -5354,13 +5354,8 @@ static void
|
|||
inp_bsource_compat(struct line *card)
|
||||
{
|
||||
char *equal_ptr, *str_ptr, *tmp_char, *new_str, *final_str;
|
||||
char actchar;
|
||||
struct line *new_line;
|
||||
wordlist *wl = NULL, *wlist = NULL;
|
||||
char buf[512];
|
||||
size_t i, ustate = 0;
|
||||
int skip_control = 0;
|
||||
int error1;
|
||||
|
||||
for (; card; card = card->li_next) {
|
||||
|
||||
|
|
@ -5391,203 +5386,7 @@ inp_bsource_compat(struct line *card)
|
|||
/* find the m={m} token and remove it */
|
||||
if ((str_ptr = strstr(curr_line, "m={m}")) != NULL)
|
||||
memcpy(str_ptr, " ", 5);
|
||||
/* scan the line and remove all '{' and '}' */
|
||||
str_ptr = equal_ptr + 1;
|
||||
while (*str_ptr) {
|
||||
if ((*str_ptr == '{') || (*str_ptr == '}'))
|
||||
*str_ptr = ' ';
|
||||
str_ptr++;
|
||||
}
|
||||
/* scan the expression */
|
||||
str_ptr = equal_ptr + 1;
|
||||
while (*str_ptr != '\0') {
|
||||
str_ptr = skip_ws(str_ptr);
|
||||
if (*str_ptr == '\0')
|
||||
break;
|
||||
actchar = *str_ptr;
|
||||
wl_append_word(&wlist, &wl, NULL);
|
||||
if ((actchar == ',') || (actchar == '(') || (actchar == ')') ||
|
||||
(actchar == '*') || (actchar == '/') || (actchar == '^') ||
|
||||
(actchar == '+') || (actchar == '?') || (actchar == ':'))
|
||||
{
|
||||
if ((actchar == '*') && (str_ptr[1] == '*')) {
|
||||
actchar = '^';
|
||||
str_ptr++;
|
||||
}
|
||||
buf[0] = actchar;
|
||||
buf[1] = '\0';
|
||||
wl->wl_word = copy(buf);
|
||||
str_ptr++;
|
||||
if (actchar == ')')
|
||||
ustate = 0;
|
||||
else
|
||||
ustate = 1; /* we have an operator */
|
||||
} else if ((actchar == '>') || (actchar == '<') ||
|
||||
(actchar == '!') || (actchar == '='))
|
||||
{
|
||||
/* >=, <=, !=, ==, <>, ... */
|
||||
char *beg = str_ptr++;
|
||||
if ((*str_ptr == '=') || (*str_ptr == '<') || (*str_ptr == '>'))
|
||||
str_ptr++;
|
||||
wl->wl_word = copy_substring(beg, str_ptr);
|
||||
ustate = 1; /* we have an operator */
|
||||
} else if ((actchar == '|') || (actchar == '&')) {
|
||||
char *beg = str_ptr++;
|
||||
if ((*str_ptr == '|') || (*str_ptr == '&'))
|
||||
str_ptr++;
|
||||
wl->wl_word = copy_substring(beg, str_ptr);
|
||||
ustate = 1; /* we have an operator */
|
||||
} else if ((actchar == '-') && (ustate == 0)) {
|
||||
buf[0] = actchar;
|
||||
buf[1] = '\0';
|
||||
wl->wl_word = copy(buf);
|
||||
str_ptr++;
|
||||
ustate = 1; /* we have an operator */
|
||||
} else if ((actchar == '-') && (ustate == 1)) {
|
||||
wl->wl_word = copy("");
|
||||
str_ptr++;
|
||||
ustate = 2; /* place a '-' in front of token */
|
||||
} else if (isalpha(actchar)) {
|
||||
/* unary -, change sign */
|
||||
if (ustate == 2) {
|
||||
i = 1;
|
||||
buf[0] = '-';
|
||||
} else {
|
||||
i = 0;
|
||||
}
|
||||
|
||||
if (((actchar == 'v') || (actchar == 'i')) && (str_ptr[1] == '(')) {
|
||||
while (*str_ptr != ')') {
|
||||
buf[i] = *str_ptr;
|
||||
i++;
|
||||
str_ptr++;
|
||||
}
|
||||
buf[i] = *str_ptr;
|
||||
buf[i+1] = '\0';
|
||||
wl->wl_word = copy(buf);
|
||||
str_ptr++;
|
||||
} else {
|
||||
while (isalnum(*str_ptr) ||
|
||||
(*str_ptr == '!') || (*str_ptr == '#') ||
|
||||
(*str_ptr == '$') || (*str_ptr == '%') ||
|
||||
(*str_ptr == '_') || (*str_ptr == '[') ||
|
||||
(*str_ptr == ']'))
|
||||
{
|
||||
buf[i] = *str_ptr;
|
||||
i++;
|
||||
str_ptr++;
|
||||
}
|
||||
buf[i] = '\0';
|
||||
/* no parens {} around time, hertz, temper, the constants
|
||||
pi and e which are defined in inpptree.c, around pwl and temp. coeffs */
|
||||
if ((*str_ptr == '(') ||
|
||||
cieq(buf, "hertz") || cieq(buf, "temper") ||
|
||||
cieq(buf, "time") || cieq(buf, "pi") ||
|
||||
cieq(buf, "e") || cieq(buf, "pwl"))
|
||||
{
|
||||
/* special handling of pwl lines:
|
||||
Put braces around tokens and around expressions, use ','
|
||||
as separator like:
|
||||
pwl(i(Vin), {x0-1},{y0},
|
||||
{x0},{y0},{x1},{y1}, {x2},{y2},{x3},{y3},
|
||||
{x3+1},{y3})
|
||||
*/
|
||||
/*
|
||||
* if (cieq(buf, "pwl")) {
|
||||
* // go past i(Vin)
|
||||
* i = 3;
|
||||
* while (*str_ptr != ')') {
|
||||
* buf[i] = *str_ptr;
|
||||
* i++;
|
||||
* str_ptr++;
|
||||
* }
|
||||
* buf[i] = *str_ptr;
|
||||
* i++;
|
||||
* str_ptr++;
|
||||
* // find first ','
|
||||
* while (*str_ptr != ',') {
|
||||
* buf[i] = *str_ptr;
|
||||
* i++;
|
||||
* str_ptr++;
|
||||
* }
|
||||
* buf[i] = *str_ptr;
|
||||
* i++;
|
||||
* buf[i] = '{';
|
||||
* i++;
|
||||
* str_ptr++;
|
||||
* while (*str_ptr != ')') {
|
||||
* if (*str_ptr == ',') {
|
||||
* buf[i] = '}';
|
||||
* i++;
|
||||
* buf[i] = ',';
|
||||
* i++;
|
||||
* buf[i] = '{';
|
||||
* i++;
|
||||
* str_ptr++;
|
||||
* }
|
||||
* else {
|
||||
* buf[i] = *str_ptr;
|
||||
* i++;
|
||||
* str_ptr++;
|
||||
* }
|
||||
* }
|
||||
* buf[i] = '}';
|
||||
* i++;
|
||||
* buf[i] = *str_ptr;
|
||||
* i++;
|
||||
* buf[i] = '\0';
|
||||
* str_ptr++;
|
||||
* }
|
||||
*/
|
||||
wl->wl_word = copy(buf);
|
||||
|
||||
} else if (cieq(buf, "tc1") || cieq(buf, "tc2") ||
|
||||
cieq(buf, "reciproctc"))
|
||||
{
|
||||
|
||||
str_ptr = skip_ws(str_ptr);
|
||||
/* no {} around tc1 = or tc2 = , these are temp coeffs. */
|
||||
if (str_ptr[0] == '=' && str_ptr[1] != '=') {
|
||||
buf[i++] = '=';
|
||||
buf[i] = '\0';
|
||||
str_ptr++;
|
||||
wl->wl_word = copy(buf);
|
||||
} else {
|
||||
wl->wl_word = tprintf("{%s}", buf);
|
||||
}
|
||||
|
||||
} else {
|
||||
/* {} around all other tokens */
|
||||
wl->wl_word = tprintf("{%s}", buf);
|
||||
}
|
||||
}
|
||||
ustate = 0; /* we have a number */
|
||||
} else if (isdigit(actchar) || (actchar == '.')) { /* allow .5 format too */
|
||||
/* allow 100p, 5MEG etc. */
|
||||
double dvalue = INPevaluate(&str_ptr, &error1, 0);
|
||||
char cvalue[19];
|
||||
/* unary -, change sign */
|
||||
if (ustate == 2)
|
||||
dvalue *= -1;
|
||||
sprintf(cvalue, "%18.10e", dvalue);
|
||||
wl->wl_word = copy(cvalue);
|
||||
ustate = 0; /* we have a number */
|
||||
/* skip the `unit', FIXME INPevaluate() should do this */
|
||||
while (isalpha(*str_ptr))
|
||||
str_ptr++;
|
||||
} else { /* strange char */
|
||||
printf("Preparing B line for numparam\nWhat is this?\n%s\n", str_ptr);
|
||||
buf[0] = *str_ptr;
|
||||
buf[1] = '\0';
|
||||
wl->wl_word = copy(buf);
|
||||
str_ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
new_str = wl_flatten(wlist);
|
||||
wl_free(wlist);
|
||||
wlist = NULL;
|
||||
wl = NULL;
|
||||
new_str = inp_modify_exp(equal_ptr + 1);
|
||||
|
||||
tmp_char = copy(curr_line);
|
||||
equal_ptr = strchr(tmp_char, '=');
|
||||
|
|
|
|||
Loading…
Reference in New Issue