From 32d6519f09cfbc259022cb008375c482749dc921 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 13 Apr 2019 12:42:55 +0200 Subject: [PATCH] add a new function gettok_model to consider {...} expressions in VDMOS .model statements --- src/frontend/inpcom.c | 2 +- src/include/ngspice/ngspice.h | 1 + src/misc/string.c | 37 +++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index 59f5d2e98..bf180120e 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -6645,7 +6645,7 @@ inp_vdmos_model(struct card *deck) cut_line = cut_line + 1; new_line = NULL; while (cut_line && *cut_line) { - token = gettok_noparens(&cut_line); + token = gettok_model(&cut_line); if (!ciprefix("pchan", token) && !ciprefix("ron=", token) && !ciprefix("vds=", token) && !ciprefix("qg=", token) && !ciprefix("mfg=", token) && !ciprefix("nchan", token)) wl_append_word(NULL, &wl, token); diff --git a/src/include/ngspice/ngspice.h b/src/include/ngspice/ngspice.h index 74119a2c4..4f90b827f 100644 --- a/src/include/ngspice/ngspice.h +++ b/src/include/ngspice/ngspice.h @@ -241,6 +241,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 *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 91aea0786..5279c4a43 100644 --- a/src/misc/string.c +++ b/src/misc/string.c @@ -413,6 +413,43 @@ gettok_noparens(char **s) return copy_substring(token, token_e); } +/*-------------------------------------------------------------------------* +* gettok_model acts like gettok_noparens, however when it encounters a '{', +* it searches for the corresponding '}' and adds the string to the output +* token. +*-------------------------------------------------------------------------*/ +char * +gettok_model(char **s) +{ + char c; + const char *token, *token_e; + + *s = skip_ws(*s); + + 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)++; + if (**s == '{') { + char *tmpstr = gettok_char(s, '}', FALSE, TRUE); + tfree(tmpstr); + } + } + token_e = *s; + + *s = skip_ws(*s); + + return copy_substring(token, token_e); +} + + char * gettok_instance(char **s)