From 5747982ae8e57131443625940ca037e8fa8674fa Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Thu, 28 Jan 2021 17:06:02 +0100 Subject: [PATCH] Re-enable devices like E2 1 0 (2,3) 1 Add a new function nexttok_noparens(const char *s) which skips tokens. Characters , ( and ) are treated like spaces. --- src/frontend/inpcom.c | 10 +++++----- src/include/ngspice/ngspice.h | 1 + src/misc/string.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index 1ea5f51e9..99722e7df 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -9455,9 +9455,9 @@ static int inp_poly_2g6_compat(struct card* deck) { case 'g': case 'e': case 'f': - curr_line = nexttok(curr_line); - curr_line = nexttok(curr_line); - curr_line = nexttok(curr_line); + curr_line = nexttok_noparens(curr_line); + curr_line = nexttok_noparens(curr_line); + curr_line = nexttok_noparens(curr_line); /* exclude all of the following fourth tokens */ if (ciprefix("poly", curr_line)) continue; @@ -9488,8 +9488,8 @@ static int inp_poly_2g6_compat(struct card* deck) { switch (*thisline) { case 'g': case 'e': - curr_line = nexttok(curr_line); - curr_line = nexttok(curr_line); + curr_line = nexttok_noparens(curr_line); + curr_line = nexttok_noparens(curr_line); if (!curr_line) { fprintf(stderr, "Error: not enough parameters in line\n %s\n", thisline); fprintf(stderr, "No circuit loaded!\n"); diff --git a/src/include/ngspice/ngspice.h b/src/include/ngspice/ngspice.h index 0b4f6e710..74535553e 100644 --- a/src/include/ngspice/ngspice.h +++ b/src/include/ngspice/ngspice.h @@ -253,6 +253,7 @@ extern char *gettok_noparens(char **s); extern char *gettok_node(char **s); extern char *gettok_iv(char **s); extern char *nexttok(const char *s); +extern char *nexttok_noparens(const char *s); extern char *gettok_model(char **s); extern int get_l_paren(char **s); extern int get_r_paren(char **s); diff --git a/src/misc/string.c b/src/misc/string.c index e69ff9173..7e20daf10 100644 --- a/src/misc/string.c +++ b/src/misc/string.c @@ -450,6 +450,40 @@ nexttok(const char *s) return (char *) s; } +/*-------------------------------------------------------------------------* + * nexttok skips over whitespaces and the next token in s + * returns NULL if there is nothing left to skip. + * It replaces constructs like txfree(gettok(&actstring)) by + * actstring = nexttok(actstring). This is derived from the gettok_noparens version. + * It acts like gettok, except that it treats parens and commas like + * whitespace. + *-------------------------------------------------------------------------*/ + +char* +nexttok_noparens(const char* s) +{ + if (!s) + return NULL; + int paren = 0; + + s = skip_ws(s); + if (!*s) + return NULL; + + for (; *s && !isspace_c(*s); s++) + if (*s == '(') + break; + else if (*s == ')') + break; + else if (*s == ',') + break; + + while (isspace_c(*s) || *s == ',' || *s == '(' || *s == ')') + s++; + + return (char*)s; +} + /*-------------------------------------------------------------------------* * gettok skips over whitespaces or '=' and returns the next token found,