From 8dbefe215315820a200dc4e5fb0c2f4bd1e381df Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sat, 21 Dec 2013 13:00:52 +0100 Subject: [PATCH] inpcom.c: allow proper 'temper' substitution if device name and parameter name are the same, or if parameter name is the last token in the line. --- src/frontend/inpcom.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index 1a44ed176..17262652e 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -5689,7 +5689,7 @@ inp_bsource_compat(struct line *card) } -/* Find all expression containing the keyword 'temper', +/* Find all expressions containing the keyword 'temper', * except for B lines and some other exclusions. Prepare * these expressions by calling inp_modify_exp() and return * a modified card->li_line @@ -6369,7 +6369,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; + char * new_tmp_str, *tmp_str, *firsttok_str; /* Some new variables... */ char *chp; char *chp_start; @@ -6408,8 +6408,15 @@ inp_fix_temper_in_param(struct line *deck) if (sub_count[subckt_depth] != new_func->subckt_count) continue; + /* remove first token, ignore it here, restore it later */ + firsttok_str = gettok(&curr_line); + if (*curr_line == '\0') { + tfree(firsttok_str); + continue; + } + /* This is the new code - it finds each variable name and checks it against new_func->funcname */ - for (state = 0, var_name = chp_start = chp = curr_line; *chp; chp++) { + for (state = 0, var_name = chp_start = chp = curr_line; ; chp++) { switch(state) { case 0: @@ -6425,7 +6432,7 @@ inp_fix_temper_in_param(struct line *deck) /* In state 1 we are looking for the last character of a variable name. The variable name consists of alphanumeric characters and special characters, which are defined above as VALIDCHARS. */ - state = (isalphanum(*chp) || strchr(VALIDCHARS, *chp)); + state = (*chp) && (isalphanum(*chp) || strchr(VALIDCHARS, *chp)); if (!state) { ch = *chp; *chp = 0; @@ -6438,9 +6445,16 @@ inp_fix_temper_in_param(struct line *deck) } break; } + if (!(*chp)) + break; } - if (new_str) /* add final part of line */ + 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;