From 39d391fe334fbef77e613150a4a2b08f2105c422 Mon Sep 17 00:00:00 2001 From: rlar Date: Sat, 28 Feb 2015 11:01:21 +0100 Subject: [PATCH] parser/inpgtok.c, whitespace cleanup --- src/spicelib/parser/inpgtok.c | 634 +++++++++++++++++----------------- 1 file changed, 323 insertions(+), 311 deletions(-) diff --git a/src/spicelib/parser/inpgtok.c b/src/spicelib/parser/inpgtok.c index 3c8d09728..3fe9861fe 100644 --- a/src/spicelib/parser/inpgtok.c +++ b/src/spicelib/parser/inpgtok.c @@ -4,99 +4,105 @@ Author: 1985 Thomas L. Quarles Modified: 2000 AlansFixes **********/ - /* get input token from 'line', - * and return a pointer to it in 'token' - */ +/* get input token from 'line', + * and return a pointer to it in 'token' + */ /* INPgetTok: node names INPgetUTok: numbers and other elements in expressions - (called from INPevaluate) - */ + (called from INPevaluate) +*/ #include "ngspice/ngspice.h" #include "ngspice/iferrmsg.h" #include "ngspice/inpdefs.h" #include "inpxx.h" + /*------------------------------------------------------------------- - * INPgetTok -- this fcn extracts a generic input token from - * 'line' and returns a pointer to it in 'token'. + * INPgetTok -- this fcn extracts a generic input token from + * 'line' and returns a pointer to it in 'token'. *------------------------------------------------------------------*/ -int INPgetTok(char **line, char **token, int gobble) - /* eat non-whitespace trash AFTER token? */ + +int +INPgetTok(char **line, char **token, int gobble) +/* gobble: eat non-whitespace trash AFTER token? */ { char *point; int signstate; - int diffpoints; + int diffpoints; /* scan along throwing away garbage characters until end of line or a separation char is found */ for (point = *line; *point != '\0'; point++) { - if (*point == ' ') - continue; - if (*point == '\t') - continue; - if (*point == '\r') - continue; - if (*point == '=') - continue; - if (*point == '(') - continue; - if (*point == ')') - continue; - if (*point == ',') - continue; - break; + if (*point == ' ') + continue; + if (*point == '\t') + continue; + if (*point == '\r') + continue; + if (*point == '=') + continue; + if (*point == '(') + continue; + if (*point == ')') + continue; + if (*point == ',') + continue; + break; } + /* mark beginning of token */ *line = point; - /* now find all good characters up to next occurance of a + /* now find all good characters up to next occurance of a separation character. */ signstate = 0; for (point = *line; *point != '\0'; point++) { - if (*point == ' ') - break; - if (*point == '\t') - break; - if (*point == '\r') - break; - if (*point == '=') - break; - if (*point == '(') - break; - if (*point == ')') - break; - if (*point == ',') - break; - /* This is not complex enough to catch all errors, - but it will get the "good" parses */ - if ((*point == '+') || (*point == '-')){ - /* Treat '+' signs same as '-' signs */ - if (signstate == 1 || signstate == 3) break; - signstate += 1; - continue; - } - if (*point == '*') - break; - if (*point == '/') - break; - if (*point == '^') - break; - if (isdigit(*point) || *point == '.') { - if (signstate > 1) - signstate = 3; - else - signstate = 1; - } else if (tolower(*point) == 'e' && signstate == 1) - signstate = 2; - else - signstate = 3; + if (*point == ' ') + break; + if (*point == '\t') + break; + if (*point == '\r') + break; + if (*point == '=') + break; + if (*point == '(') + break; + if (*point == ')') + break; + if (*point == ',') + break; + /* This is not complex enough to catch all errors, + but it will get the "good" parses */ + if ((*point == '+') || (*point == '-')) { + /* Treat '+' signs same as '-' signs */ + if (signstate == 1 || signstate == 3) + break; + signstate += 1; + continue; + } + if (*point == '*') + break; + if (*point == '/') + break; + if (*point == '^') + break; + + if (isdigit(*point) || *point == '.') { + if (signstate > 1) + signstate = 3; + else + signstate = 1; + } else if (tolower(*point) == 'e' && signstate == 1) + signstate = 2; + else + signstate = 3; } - if (point == *line && *point) /* Weird items, 1 char */ - point++; + if (point == *line && *point) /* Weird items, 1 char */ + point++; diffpoints = (int)(point - *line); *token = TMALLOC(char, 1 + diffpoints); @@ -104,30 +110,22 @@ int INPgetTok(char **line, char **token, int gobble) return (E_NOMEM); (void) strncpy(*token, *line, (size_t) diffpoints); *(*token + diffpoints) = '\0'; + *line = point; -/* - if (point == *line && *point) - point++; - *token = TMALLOC(char, 1 + point - *line); - if (!*token) - return (E_NOMEM); - (void) strncpy(*token, *line, point - *line); - *(*token + (point - *line)) = '\0'; - *line = point; - */ + /* gobble garbage to next token */ for (; **line != '\0'; (*line)++) { - if (**line == ' ') - continue; - if (**line == '\t') - continue; - if (**line == '\r') - continue; - if ((**line == '=') && gobble) - continue; - if ((**line == ',') && gobble) - continue; - break; + if (**line == ' ') + continue; + if (**line == '\t') + continue; + if (**line == '\r') + continue; + if ((**line == '=') && gobble) + continue; + if ((**line == ',') && gobble) + continue; + break; } #ifdef TRACE @@ -140,14 +138,16 @@ int INPgetTok(char **line, char **token, int gobble) /*------------------------------------------------------------------- - * INPgetNetTok -- this fcn extracts an input netname token from - * 'line' and returns a pointer to it in 'token'. + * INPgetNetTok -- this fcn extracts an input netname token from + * 'line' and returns a pointer to it in 'token'. * This fcn cloned from INPgetTok by SDB to enable * complex netnames (e.g. netnames like '+VCC' and 'IN-'). * mailto:sdb@cloud9.net -- 4.7.2003 *------------------------------------------------------------------*/ -int INPgetNetTok(char **line, char **token, int gobble) - /* eat non-whitespace trash AFTER token? */ + +int +INPgetNetTok(char **line, char **token, int gobble) +/* gobble: eat non-whitespace trash AFTER token? */ { char *point; int diffpoints; @@ -155,77 +155,67 @@ int INPgetNetTok(char **line, char **token, int gobble) /* scan along throwing away garbage characters until end of line or a separation char is found */ for (point = *line; *point != '\0'; point++) { - if (*point == ' ') - continue; - if (*point == '\t') - continue; - if (*point == '=') - continue; - if (*point == '(') - continue; - if (*point == ')') - continue; - if (*point == ',') - continue; - break; + if (*point == ' ') + continue; + if (*point == '\t') + continue; + if (*point == '=') + continue; + if (*point == '(') + continue; + if (*point == ')') + continue; + if (*point == ',') + continue; + break; } /* mark beginning of token */ *line = point; - /* now find all good characters up to next occurance of a + /* now find all good characters up to next occurance of a separation character. INPgetNetTok is very liberal about what it accepts. */ for (point = *line; *point != '\0'; point++) { - if (*point == ' ') - break; - if (*point == '\t') - break; - if (*point == '\r') - break; - if (*point == '=') - break; - if (*point == ',') - break; - if (*point == ')') - break; + if (*point == ' ') + break; + if (*point == '\t') + break; + if (*point == '\r') + break; + if (*point == '=') + break; + if (*point == ',') + break; + if (*point == ')') + break; } - if (point == *line && *point) /* Weird items, 1 char */ - point++; + if (point == *line && *point) /* Weird items, 1 char */ + point++; - /* now copy found token into *token */ diffpoints = (int)(point - *line); *token = TMALLOC(char, 1 + diffpoints); if (!*token) return (E_NOMEM); (void) strncpy(*token, *line, (size_t) diffpoints); *(*token + diffpoints) = '\0'; + *line = point; -/* - if (point == *line && *point) - point++; - *token = TMALLOC(char, 1 + point - *line); - if (!*token) - return (E_NOMEM); - (void) strncpy(*token, *line, point - *line); - *(*token + (point - *line)) = '\0'; - *line = point; -*/ /* gobble garbage to next token */ for (; **line != '\0'; (*line)++) { - if (**line == ' ') - continue; - if (**line == '\t') - continue; - if (**line == '\r') - continue; - if ((**line == '=') && gobble) - continue; - if ((**line == ',') && gobble) - continue; - break; + if (**line == ' ') + continue; + if (**line == '\t') + continue; + if (**line == '\r') + continue; + if ((**line == '=') && gobble) + continue; + if ((**line == ',') && gobble) + continue; + break; } #ifdef TRACE @@ -237,42 +227,43 @@ int INPgetNetTok(char **line, char **token, int gobble) } - /*------------------------------------------------------------------- - * INPgetUTok -- this fcn extracts an input refdes token from - * 'line' and returns a pointer to it in 'token'. + * INPgetUTok -- this fcn extracts an input refdes token from + * 'line' and returns a pointer to it in 'token'. *------------------------------------------------------------------*/ -int INPgetUTok(char **line, char **token, int gobble) - - /* eat non-whitespace trash AFTER token? */ +int +INPgetUTok(char **line, char **token, int gobble) +/* gobble: eat non-whitespace trash AFTER token? */ { char *point, separator; int signstate; + /* scan along throwing away garbage characters */ for (point = *line; *point != '\0'; point++) { - if (*point == ' ') - continue; - if (*point == '\t') - continue; - if (*point == '=') - continue; - if (*point == '(') - continue; - if (*point == ')') - continue; - if (*point == ',') - continue; - break; + if (*point == ' ') + continue; + if (*point == '\t') + continue; + if (*point == '=') + continue; + if (*point == '(') + continue; + if (*point == ')') + continue; + if (*point == ',') + continue; + break; } + if (*point == '"') { - separator = '"'; - point++; + separator = '"'; + point++; } else if (*point == '\'') { - separator = '\''; - point++; + separator = '\''; + point++; } else - separator = 0; + separator = 0; /* mark beginning of token */ *line = point; @@ -280,118 +271,131 @@ int INPgetUTok(char **line, char **token, int gobble) /* now find all good characters */ signstate = 0; for (point = *line; *point != '\0'; point++) { - if (separator) { - if (*point == separator) - break; - else - continue; - } - if (*point == ' ') - break; - if (*point == '\t') - break; - if (*point == '=') - break; - if (*point == '(') - break; - if (*point == ')') - break; - if (*point == ',') - break; - /* This is not complex enough to catch all errors, but it will - get the "good" parses */ - if (*point == '+' && (signstate == 1 || signstate == 3)) - break; - if (*point == '-') { - if (signstate == 1 || signstate == 3) - break; - signstate += 1; - continue; - } - if (*point == '*') - break; - if (*point == '/') - break; - if (*point == '^') - break; - if (isdigit(*point) || *point == '.') { - if (signstate > 1) - signstate = 3; - else - signstate = 1; - } else if (tolower(*point) == 'e' && signstate == 1) - signstate = 2; - else - signstate = 3; + + if (separator) { + if (*point == separator) + break; + else + continue; + } + + if (*point == ' ') + break; + if (*point == '\t') + break; + if (*point == '=') + break; + if (*point == '(') + break; + if (*point == ')') + break; + if (*point == ',') + break; + /* This is not complex enough to catch all errors, but it will + get the "good" parses */ + if (*point == '+' && (signstate == 1 || signstate == 3)) + break; + if (*point == '-') { + if (signstate == 1 || signstate == 3) + break; + signstate += 1; + continue; + } + if (*point == '*') + break; + if (*point == '/') + break; + if (*point == '^') + break; + + if (isdigit(*point) || *point == '.') { + if (signstate > 1) + signstate = 3; + else + signstate = 1; + } else if (tolower(*point) == 'e' && signstate == 1) + signstate = 2; + else + signstate = 3; } + if (separator && *point == separator) - point--; - if (point == *line && *point) /* Weird items, 1 char */ - point++; + point--; + + if (point == *line && *point) /* Weird items, 1 char */ + point++; + *token = TMALLOC(char, 1 + point - *line); if (!*token) - return (E_NOMEM); + return (E_NOMEM); (void) strncpy(*token, *line, (size_t) (point - *line)); *(*token + (point - *line)) = '\0'; + /* gobble garbage to next token */ for (; *point != '\0'; point++) { - if (*point == separator) - continue; - if (*point == ' ') - continue; - if (*point == '\t') - continue; - if ((*point == '=') && gobble) - continue; - if ((*point == ',') && gobble) - continue; - break; + if (*point == separator) + continue; + if (*point == ' ') + continue; + if (*point == '\t') + continue; + if ((*point == '=') && gobble) + continue; + if ((*point == ',') && gobble) + continue; + break; } + *line = point; #ifdef TRACE /* SDB debug statement */ - /* printf("found refdes token (%s) and rest of line (%s)\n",*token,*line); */ + /* printf("found refdes token (%s) and rest of line (%s)\n",*token,*line); */ #endif return (OK); } + /*------------------------------------------------------------------- * INPgetUTok plus points < > ? :, called from INPevaluate called * from INPevaluate with gobble == 2 * fcn added to avoid unforeseeable side effects during other calls - * to INPevaluate. + * to INPevaluate. *------------------------------------------------------------------*/ -int INPgetU2Tok(char **line, char **token, int gobble) - /* eat non-whitespace trash AFTER token? */ + +int +INPgetU2Tok(char **line, char **token, int gobble) +/* gobble: eat non-whitespace trash AFTER token? */ { char *point, separator; int signstate; + /* scan along throwing away garbage characters */ for (point = *line; *point != '\0'; point++) { - if (*point == ' ') - continue; - if (*point == '\t') - continue; - if (*point == '=') - continue; - if (*point == '(') - continue; - if (*point == ')') - continue; - if (*point == ',') - continue; - break; + if (*point == ' ') + continue; + if (*point == '\t') + continue; + if (*point == '=') + continue; + if (*point == '(') + continue; + if (*point == ')') + continue; + if (*point == ',') + continue; + break; } + if (*point == '"') { - separator = '"'; - point++; + separator = '"'; + point++; } else if (*point == '\'') { - separator = '\''; - point++; + separator = '\''; + point++; } else - separator = 0; + separator = 0; /* mark beginning of token */ *line = point; @@ -399,86 +403,94 @@ int INPgetU2Tok(char **line, char **token, int gobble) /* now find all good characters */ signstate = 0; for (point = *line; *point != '\0'; point++) { - if (separator) { - if (*point == separator) - break; - else - continue; - } - if (*point == ' ') - break; - if (*point == '\t') - break; - if (*point == '=') - break; - if (*point == '(') - break; - if (*point == ')') - break; - if (*point == ',') - break; - /* This is not complex enough to catch all errors, but it will - get the "good" parses */ - if (*point == '+' && (signstate == 1 || signstate == 3)) - break; - if (*point == '-') { - if (signstate == 1 || signstate == 3) - break; - signstate += 1; - continue; - } - if (*point == '*') - break; - if (*point == '/') - break; - if (*point == '^') - break; - if (*point == '<') - break; - if (*point == '>') - break; - if (*point == '?') - break; - if (*point == ':') - break; - if (isdigit(*point) || *point == '.') { - if (signstate > 1) - signstate = 3; - else - signstate = 1; - } else if (tolower(*point) == 'e' && signstate == 1) - signstate = 2; - else - signstate = 3; + + if (separator) { + if (*point == separator) + break; + else + continue; + } + + if (*point == ' ') + break; + if (*point == '\t') + break; + if (*point == '=') + break; + if (*point == '(') + break; + if (*point == ')') + break; + if (*point == ',') + break; + /* This is not complex enough to catch all errors, but it will + get the "good" parses */ + if (*point == '+' && (signstate == 1 || signstate == 3)) + break; + if (*point == '-') { + if (signstate == 1 || signstate == 3) + break; + signstate += 1; + continue; + } + if (*point == '*') + break; + if (*point == '/') + break; + if (*point == '^') + break; + if (*point == '<') + break; + if (*point == '>') + break; + if (*point == '?') + break; + if (*point == ':') + break; + + if (isdigit(*point) || *point == '.') { + if (signstate > 1) + signstate = 3; + else + signstate = 1; + } else if (tolower(*point) == 'e' && signstate == 1) + signstate = 2; + else + signstate = 3; } + if (separator && *point == separator) - point--; - if (point == *line && *point) /* Weird items, 1 char */ - point++; + point--; + + if (point == *line && *point) /* Weird items, 1 char */ + point++; + *token = TMALLOC(char, 1 + point - *line); if (!*token) - return (E_NOMEM); + return (E_NOMEM); (void) strncpy(*token, *line, (size_t) (point - *line)); *(*token + (point - *line)) = '\0'; + /* gobble garbage to next token */ for (; *point != '\0'; point++) { - if (*point == separator) - continue; - if (*point == ' ') - continue; - if (*point == '\t') - continue; - if ((*point == '=') && gobble) - continue; - if ((*point == ',') && gobble) - continue; - break; + if (*point == separator) + continue; + if (*point == ' ') + continue; + if (*point == '\t') + continue; + if ((*point == '=') && gobble) + continue; + if ((*point == ',') && gobble) + continue; + break; } + *line = point; #ifdef TRACE /* SDB debug statement */ - /* printf("found refdes token (%s) and rest of line (%s)\n",*token,*line); */ + /* printf("found refdes token (%s) and rest of line (%s)\n",*token,*line); */ #endif return (OK);