From dd66fc72204a9e3817f6197b8dd85d8bd90e7814 Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sun, 16 May 2010 16:31:03 +0000 Subject: [PATCH] abort if .inc fails --- ChangeLog | 5 ++- src/frontend/inpcom.c | 7 +++- src/frontend/subckt.c | 86 +++++++++++++++++++++---------------------- 3 files changed, 51 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index dc24aaca6..66e210add 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2010-05-15 Holger Vogt - * inpcom.c exclude comment lines from stripping EOL comments - subckt.c: exclude *, . and .control ... .endc lines from processing to + * inpcom.c: exclude comment lines from stripping EOL comments, + make ngspice abort if .inc fails. + subckt.c: exclude *, and . lines from processing to getting rid of ( ) around node lists 2010-05-14 Holger Vogt diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index ede340d57..a73971665 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -1242,7 +1242,8 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name) if (!*s) { /* if at end of line, error */ fprintf(cp_err, "Error: .include filename missing\n"); tfree(buffer); /* was allocated by readline() */ - continue; + controlled_exit(EXIT_FAILURE); +// continue; } /* Now s points to first char after .include */ for (t = s; *t && !isspace(*t) && !isquote(*t); t++) /* now advance past non-space chars */ ; @@ -1266,8 +1267,10 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name) if(copys) { tfree(copys); /* allocated by the cp_tildexpand() above */ } + fprintf(cp_err, "Error: .include statement failed.\n"); tfree(buffer); /* allocated by readline() above */ - continue; + controlled_exit(EXIT_FAILURE); +// continue; } } diff --git a/src/frontend/subckt.c b/src/frontend/subckt.c index 3c6b57e78..3c274c418 100644 --- a/src/frontend/subckt.c +++ b/src/frontend/subckt.c @@ -271,58 +271,58 @@ inp_subcktexpand(struct line *deck) /* Let's do a few cleanup things... Get rid of ( ) around node lists... */ for (c = deck; c; c = c->li_next) { /* iterate on lines in deck */ - /* exclude any line inside .control ... .endc */ - if ( ciprefix(".control", c->li_line) ) { - skip_control ++; - continue; - } else if( ciprefix(".endc", c->li_line) ) { - skip_control --; - continue; - } else if(skip_control > 0) { + + char *s = c->li_line; + + if(*s == '*') /* skip comment */ continue; - } - if (ciprefix(start, c->li_line)) { /* if we find .subckt . . . */ + if (ciprefix(start, s)) { /* if we find .subckt . . . */ #ifdef TRACE - /* SDB debug statement */ - printf("In inp_subcktexpand, found a .subckt: %s\n", c->li_line); -#endif /* TRACE */ - for (s = c->li_line; *s && (*s != '('); s++) /* Iterate charwise along line until ( is found */ - ; - if (*s) { - while (s[0] && (s[1] != ')')) { - s[0] = s[1]; - s++; - } - while (s[1]) { - s[0] = s[2]; - s++; - } - } /* if (*s) . . . */ - } - else if ((*(c->li_line)=='*') || (*(c->li_line)=='.')) { - continue; + /* SDB debug statement */ + printf("In inp_subcktexpand, found a .subckt: %s\n", s); +#endif + while (*s && *s != '(') /* search opening paren */ + s++; + + if (*s == '(') { + int level = 0; + do { + /* strip outer parens '(' ')', just the first pair */ + if(*s == '(' && level++ == 0) { + *s = ' '; + } + if(*s == ')' && --level == 0) { + *s = ' '; + break; + } + } while(*s++); + } + } + else if (*s=='.') { + continue; /* skip .commands */ } - else { /* any other line . . . */ - /* Iterate charwise along line until first space is found */ - for (s = c->li_line; *s && !isspace(*s); s++) - ; - while (isspace(*s)) + else { /* any other line . . . */ + while (*s && !isspace(*s)) /* skip first token */ s++; - /* continure here only if '(' follows after the first space */ + while (*s && isspace(*s)) /* skip whitespace */ + s++; + if (*s == '(') { - while (s[0] && (s[1] != ')')) { - s[0] = s[1]; - s++; - } - while (s[1]) { - s[0] = s[2]; - s++; - } /* while */ + int level = 0; + do { + /* strip outer parens '(' ')', just the first pair, why ? */ + if(*s == '(' && level++ == 0) { + *s = ' '; + } + if(*s == ')' && --level == 0) { + *s = ' '; + break; + } + } while(*s++); } /* if (*s == '(' . . . */ } /* any other line */ } /* for (c = deck . . . */ - /* doit does the actual splicing in of the .subckt . . . */ #ifdef TRACE