From fb5e17e40733fb2867963ddefdf0851665dcacde Mon Sep 17 00:00:00 2001 From: rlar Date: Wed, 5 Jun 2013 22:10:54 +0200 Subject: [PATCH] inpcom.c, abstraction, new function `find_assignment()' --- src/frontend/inpcom.c | 85 ++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 49 deletions(-) diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index 0b4bf8c30..d0111b547 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -335,6 +335,38 @@ inp_stitch_continuation_lines(struct line *working) } +/* + * search for `=' assignment operator + * take care of `!=' `<=' `==' and `>=' + */ + +static char * +find_assignment(char *str) +{ + char *p = str; + + while ((p = strchr(p, '=')) != NULL) { + + // check for equality '==' + if (p[1] == '=') { + p += 2; + continue; + } + + // check for '!=', '<=', '>=' + if (p > str) + if (p[-1] == '!' || p[-1] == '<' || p[-1] == '>') { + p += 1; + continue; + } + + return p; + } + + return NULL; +} + + /*------------------------------------------------------------------------- Read the entire input file and return a pointer to the first line of the linked list of 'card' records in data. The pointer is stored in @@ -2370,18 +2402,7 @@ inp_get_params(char *line, char *param_names[], char *param_values[]) char keep; bool is_expression = FALSE; - while ((equal_ptr = strchr(line, '=')) != NULL) { - - // check for equality '==' - if (equal_ptr[1] == '=') { - line = equal_ptr + 2; - continue; - } - // check for '!=', '<=', '>=' - if (*(equal_ptr-1) == '!' || *(equal_ptr-1) == '<' || *(equal_ptr-1) == '>') { - line = equal_ptr + 1; - continue; - } + while ((equal_ptr = find_assignment(line)) != NULL) { is_expression = FALSE; @@ -3152,7 +3173,7 @@ inp_fix_param_values(struct line *deck) if (strstr(line, "ic.file")) continue; - while ((equal_ptr = strchr(line, '=')) != NULL) { + while ((equal_ptr = find_assignment(line)) != NULL) { // special case: .MEASURE {DC|AC|TRAN} result FIND out_variable WHEN out_variable2=out_variable3 // no braces around out_variable3. out_variable3 may be v(...) or i(...) @@ -3167,18 +3188,6 @@ inp_fix_param_values(struct line *deck) continue; } - // skip over equality '==' - if (equal_ptr[1] == '=') { - line += 2; - continue; - } - // check for '!=', '<=', '>=' - if (*(equal_ptr-1) == '!' || *(equal_ptr-1) == '<' || *(equal_ptr-1) == '>') - { - line += 1; - continue; - } - beg_of_str = skip_ws(equal_ptr + 1); /* all cases where no {} have to be put around selected token */ if (isdigit(*beg_of_str) || @@ -3932,17 +3941,7 @@ inp_split_multi_param_lines(struct line *card, int line_num) char *equal_ptr, *array[5000]; int i, counter = 0; - while ((equal_ptr = strchr(curr_line, '=')) != NULL) { - // check for equality '==' - if (equal_ptr[1] == '=') { - curr_line = equal_ptr + 2; - continue; - } - // check for '!=', '<=', '>=' - if (*(equal_ptr-1) == '!' || *(equal_ptr-1) == '<' || *(equal_ptr-1) == '>') { - curr_line = equal_ptr + 1; - continue; - } + while ((equal_ptr = find_assignment(curr_line)) != NULL) { counter++; curr_line = equal_ptr + 1; } @@ -3953,25 +3952,13 @@ inp_split_multi_param_lines(struct line *card, int line_num) // need to split multi param line curr_line = card->li_line; counter = 0; - while (curr_line < card->li_line+strlen(card->li_line) && (equal_ptr = strchr(curr_line, '=')) != NULL) { + while ((equal_ptr = find_assignment(curr_line)) != NULL) { char keep, *beg_param, *end_param, *new_line; bool get_expression = FALSE; bool get_paren_expression = FALSE; - // check for equality '==' - if (equal_ptr[1] == '=') { - curr_line = equal_ptr + 2; - continue; - } - - // check for '!=', '<=', '>=' - if (*(equal_ptr-1) == '!' || *(equal_ptr-1) == '<' || *(equal_ptr-1) == '>') { - curr_line = equal_ptr + 1; - continue; - } - beg_param = skip_back_ws(equal_ptr); beg_param = skip_back_non_ws(beg_param); end_param = skip_ws(equal_ptr + 1);