From e25c70b2bbcc98733bec373ca33f4e2128e7ead5 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Fri, 19 Sep 2025 16:53:11 +0200 Subject: [PATCH] add new function gettok_node_br which adds braces { } on its list of ignored characters. --- src/include/ngspice/ngspice.h | 1 + src/misc/string.c | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/include/ngspice/ngspice.h b/src/include/ngspice/ngspice.h index e228cf2dd..ecafe3736 100644 --- a/src/include/ngspice/ngspice.h +++ b/src/include/ngspice/ngspice.h @@ -236,6 +236,7 @@ extern FILE *newfopen(const char *fn, const char* md); void findtok_noparen(char **p_str, char **p_token, char **p_token_end); extern char *gettok_noparens(char **s); extern char *gettok_node(char **s); +extern char *gettok_node_br(char **s); extern char *gettok_iv(char **s); extern char *nexttok(const char *s); extern char *nexttok_noparens(const char *s); diff --git a/src/misc/string.c b/src/misc/string.c index 97acd9c92..ac03d3f1e 100644 --- a/src/misc/string.c +++ b/src/misc/string.c @@ -861,6 +861,57 @@ gettok_node(char **s) return copy_substring(token, token_e); } +/*-------------------------------------------------------------------------* + * gettok_node_br acts like gettok_node, including braces { }. + *-------------------------------------------------------------------------*/ + +char* +gettok_node_br(char** s) +{ + char c; + const char* token, * token_e; + + if (*s == NULL) + return NULL; + + while (isspace_c(**s) || + (**s == '(') || + (**s == ')') || + (**s == '{') || + (**s == '}') || + (**s == ',') + ) + (*s)++; /* iterate over whitespace and ( , ) */ + + if (!**s) + return NULL; /* return NULL if we come to end of line */ + + token = *s; + while ((c = **s) != '\0' && + !isspace_c(c) && + (**s != '(') && + (**s != ')') && + (**s != '{') && + (**s != '}') && + (**s != ',') + ) /* collect chars until whitespace or ( , ) */ + (*s)++; + + token_e = *s; + + /* Now iterate up to next non-whitespace char */ + while (isspace_c(**s) || + (**s == '(') || + (**s == ')') || + (**s == '{') || + (**s == '}') || + (**s == ',') + ) + (*s)++; /* iterate over whitespace and ( , ) */ + + return copy_substring(token, token_e); +} + /*-------------------------------------------------------------------------* * get_l_paren iterates the pointer forward in a string until it hits