inpcom.c, inp_fix_temper_in_param(), abstraction, introduce `inp_functionalise_identifier()'
This commit is contained in:
parent
ff613c3c41
commit
9579b78091
|
|
@ -5903,6 +5903,8 @@ inp_dot_if(struct line *card)
|
|||
* add info to end of new_func and continue scanning.
|
||||
*/
|
||||
|
||||
static char *inp_functionalise_identifier(char *curr_line, char *identifier);
|
||||
|
||||
static void
|
||||
inp_fix_temper_in_param(struct line *deck)
|
||||
{
|
||||
|
|
@ -6021,13 +6023,7 @@ inp_fix_temper_in_param(struct line *deck)
|
|||
|
||||
char *new_str = NULL; /* string we assemble here */
|
||||
char *curr_line = card->li_line;
|
||||
char * new_tmp_str, *tmp_str, *firsttok_str;
|
||||
/* Some new variables... */
|
||||
char *chp;
|
||||
char *chp_start;
|
||||
char *var_name;
|
||||
char ch;
|
||||
int state;
|
||||
char *firsttok_str;
|
||||
|
||||
if (*curr_line == '*')
|
||||
continue;
|
||||
|
|
@ -6067,7 +6063,46 @@ inp_fix_temper_in_param(struct line *deck)
|
|||
continue;
|
||||
}
|
||||
|
||||
/* This is the new code - it finds each variable name and checks it against new_func->funcname */
|
||||
new_str = inp_functionalise_identifier(curr_line, new_func->funcname);
|
||||
|
||||
if (new_str) {
|
||||
/* restore first part of the line */
|
||||
new_str = INPstrCat(firsttok_str, new_str, " ");
|
||||
new_str = inp_remove_ws(new_str);
|
||||
}
|
||||
else
|
||||
continue;
|
||||
|
||||
/* if we have inserted into a .param line, convert to .func */
|
||||
if (prefix(".param", new_str)) {
|
||||
char *new_tmp_str = new_str;
|
||||
txfree(gettok(&new_tmp_str));
|
||||
funcname = gettok_char(&new_tmp_str, '=', FALSE, FALSE);
|
||||
funcbody = copy(new_tmp_str + 1);
|
||||
inp_new_func(funcname, funcbody, card, &new_func, sub_count, subckt_depth);
|
||||
tfree(new_str);
|
||||
tfree(funcbody);
|
||||
} else {
|
||||
/* Or just enter new line into deck */
|
||||
card->li_next = xx_new_line(card->li_next, new_str, 0, card->li_linenum);
|
||||
*card->li_line = '*';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* final memory clearance */
|
||||
tfree(sub_count);
|
||||
/* remove new_func */
|
||||
inp_rem_func(&beg_func);
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
inp_functionalise_identifier(char *curr_line, char *identifier)
|
||||
{
|
||||
/* This is the new code - it finds each variable name and checks it against `identifier' */
|
||||
int state;
|
||||
char *var_name, *chp_start, *chp, *new_str = NULL;
|
||||
for (state = 0, var_name = chp_start = chp = curr_line; ; chp++) {
|
||||
switch(state)
|
||||
{
|
||||
|
|
@ -6086,9 +6121,9 @@ inp_fix_temper_in_param(struct line *deck)
|
|||
which are defined above as VALIDCHARS. */
|
||||
state = (*chp) && (isalphanum(*chp) || strchr(VALIDCHARS, *chp));
|
||||
if (!state) {
|
||||
ch = *chp;
|
||||
char ch = *chp;
|
||||
*chp = '\0';
|
||||
if (strcmp(var_name, new_func->funcname) == 0 && ch != '(') {
|
||||
if (strcmp(var_name, identifier) == 0 && ch != '(') {
|
||||
new_str = INPstrCat(new_str, copy(chp_start), "");
|
||||
new_str = INPstrCat(new_str, copy("()"), "");
|
||||
chp_start=chp;
|
||||
|
|
@ -6103,35 +6138,8 @@ inp_fix_temper_in_param(struct line *deck)
|
|||
if (new_str) {
|
||||
/* add final part of line */
|
||||
new_str = INPstrCat(new_str, copy(chp_start), "");
|
||||
/* restore first part of the line */
|
||||
new_str = INPstrCat(firsttok_str, new_str, " ");
|
||||
new_str = inp_remove_ws(new_str);
|
||||
}
|
||||
else
|
||||
continue;
|
||||
|
||||
/* if we have inserted into a .param line, convert to .func */
|
||||
new_tmp_str = new_str;
|
||||
if (prefix(".param", new_tmp_str)) {
|
||||
tmp_str = gettok(&new_tmp_str);
|
||||
tfree(tmp_str);
|
||||
funcname = gettok_char(&new_tmp_str, '=', FALSE, FALSE);
|
||||
funcbody = copy(new_tmp_str + 1);
|
||||
inp_new_func(funcname, funcbody, card, &new_func, sub_count, subckt_depth);
|
||||
tfree(new_str);
|
||||
tfree(funcbody);
|
||||
} else {
|
||||
/* Or just enter new line into deck */
|
||||
card->li_next = xx_new_line(card->li_next, new_str, 0, card->li_linenum);
|
||||
*card->li_line = '*';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* final memory clearance */
|
||||
tfree(sub_count);
|
||||
/* remove new_func */
|
||||
inp_rem_func(&beg_func);
|
||||
return new_str;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue