From 2fe85974cebb31f3f17efe3771727f52a6ed95bc Mon Sep 17 00:00:00 2001 From: h_vogt Date: Fri, 21 May 2010 20:58:31 +0000 Subject: [PATCH] ternary fcn in numparam bugfix 2936702 --- ChangeLog | 3 +++ src/frontend/inpcom.c | 26 ++++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 66e210add..f3ef54261 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2010-05-21 Holger Vogt + * inpcom.c: bugfix 2936702 correct handling of ternary fcn in numparam + 2010-05-15 Holger Vogt * inpcom.c: exclude comment lines from stripping EOL comments, make ngspice abort if .inc fails. diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index a73971665..108752dbb 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -892,19 +892,8 @@ inp_fix_ternary_operator_str( char *line ) paren_ptr = strstr( str_ptr, "(" ); if ( paren_ptr != NULL && paren_ptr < question ) { - str_ptr = question; - while ( *str_ptr != '(' ) str_ptr--; - *str_ptr = '\0'; - beg_str = strdup(line); - *str_ptr = '('; - str_ptr++; paren_ptr = NULL; } - else { - keep = *str_ptr; *str_ptr = '\0'; - beg_str = strdup(line); - *str_ptr = keep; - } } else return line; // hvogt @@ -913,12 +902,23 @@ inp_fix_ternary_operator_str( char *line ) str_ptr2--; while ( isspace(*str_ptr2) ) str_ptr2--; if ( *str_ptr2 == ')' ) { - while ( *str_ptr != '(' ) str_ptr--; + count = 1; + str_ptr = str_ptr2; + while ( (count != 0) && (str_ptr != line) ){ + str_ptr--; + if ( *str_ptr == '(' ) count--; + if ( *str_ptr == ')' ) count++; + } } str_ptr2++; keep = *str_ptr2; *str_ptr2 = '\0'; conditional = strdup(str_ptr); *str_ptr2 = keep; + // get beginning (whatever is left before the conditional) + keep = *str_ptr; *str_ptr = '\0'; + beg_str = strdup(line); + *str_ptr = keep; + // get if str_ptr = question + 1; while ( isspace(*str_ptr) ) str_ptr++; @@ -941,6 +941,8 @@ inp_fix_ternary_operator_str( char *line ) fprintf(stderr,"ERROR: problem parsing ternary string (finding ':') %s!\n", line); controlled_exit(EXIT_FAILURE); } + str_ptr2 = colon - 1; + while ( isspace(*str_ptr2) ) str_ptr2--; } else if ( ( colon = strstr( str_ptr, ":" ) ) ) { str_ptr2 = colon - 1;