From f5d05af51d640b6de65da0b34980d5d50a6253e4 Mon Sep 17 00:00:00 2001 From: rlar Date: Sat, 9 Aug 2014 15:35:31 +0200 Subject: [PATCH] inpgmod.c, INPgetModBin(), use model_name_match() --- src/include/ngspice/stringutil.h | 2 +- src/misc/string.c | 16 +++++++++------- src/spicelib/parser/inpgmod.c | 7 +++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/include/ngspice/stringutil.h b/src/include/ngspice/stringutil.h index 0f9ef75d2..8e42dad3b 100644 --- a/src/include/ngspice/stringutil.h +++ b/src/include/ngspice/stringutil.h @@ -26,7 +26,7 @@ char * stripWhiteSpacesInsideParens(char *str); char * gettok(char **s); char * gettok_instance(char **); char * gettok_char(char **s, char p, bool inc_p, bool nested); -bool model_name_match(const char *token, const char *model_name); +int model_name_match(const char *token, const char *model_name); extern char *tvprintf(const char *fmt, va_list args); diff --git a/src/misc/string.c b/src/misc/string.c index 38c78b954..2230fa378 100644 --- a/src/misc/string.c +++ b/src/misc/string.c @@ -685,37 +685,39 @@ get_comma_separated_values( char *values[], char *str ) { /* check if the given token matches a model name either exact + then return 1 or modulo a trailing model binning extension '\.[0-9]+' + then return 2 */ -bool +int model_name_match(const char *token, const char *model_name) { const char *p; size_t token_len = strlen(token); if (strncmp(token, model_name, token_len) != 0) - return FALSE; + return 0; p = model_name + token_len; // exact match if (*p == '\0') - return TRUE; + return 1; // check for . if (*p++ != '.') - return FALSE; + return 0; // minimum one trailing char if (*p == '\0') - return FALSE; + return 0; // all of them digits for (; *p; p++) if (!isdigit(*p)) - return FALSE; + return 0; - return TRUE; + return 2; } diff --git a/src/spicelib/parser/inpgmod.c b/src/spicelib/parser/inpgmod.c index 2cb17d347..c63ede454 100644 --- a/src/spicelib/parser/inpgmod.c +++ b/src/spicelib/parser/inpgmod.c @@ -212,6 +212,10 @@ INPgetModBin( CKTcircuit* ckt, char* name, INPmodel** model, INPtables* tab, cha w = parse_values[1]*scale; for ( modtmp = modtab; modtmp != NULL; modtmp = modtmp->INPnextModel ) { + + if ( model_name_match(name, modtmp->INPmodName) < 2 ) + continue; + if ( /* This is the list of binable models */ modtmp->INPmodType != INPtypelook ("BSIM3") && modtmp->INPmodType != INPtypelook ("BSIM3v32") @@ -238,8 +242,7 @@ INPgetModBin( CKTcircuit* ckt, char* name, INPmodel** model, INPtables* tab, cha lmin = parse_values[0]; lmax = parse_values[1]; wmin = parse_values[2]; wmax = parse_values[3]; - if ( strncmp( modtmp->INPmodName, name, strlen( name ) ) == 0 && - in_range( l, lmin, lmax ) && in_range( w, wmin, wmax ) ) { + if ( in_range( l, lmin, lmax ) && in_range( w, wmin, wmax ) ) { if ( !modtmp->INPmodfast ) { error = create_model( ckt, modtmp, tab ); if ( error ) return NULL;