From d82b836136515e286ce0efbaad7f2d79d9983807 Mon Sep 17 00:00:00 2001 From: rlar Date: Fri, 25 Jul 2014 21:09:29 +0200 Subject: [PATCH] subckt.c, inp_subcktexpand(), abstraction, new function `collect_global_nodes()' --- src/frontend/subckt.c | 69 ++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/src/frontend/subckt.c b/src/frontend/subckt.c index beb653c9b..5ff46d3b6 100644 --- a/src/frontend/subckt.c +++ b/src/frontend/subckt.c @@ -134,6 +134,43 @@ static char start[32], sbend[32], invoke[32], model[32]; static char global_nodes[128][128]; static int num_global_nodes; + +static void +collect_global_nodes(struct line *c) +{ + int i; + + for (i = 0; i < 128; i++) + strcpy(global_nodes[i], ""); /* Clear global node holder */ + + num_global_nodes = 0; + for (; c; c = c->li_next) + if (ciprefix(".global", c->li_line)) { + char *s = c->li_line; + txfree(gettok(&s)); + while (*s) { + char *t = s; + i = 0; + for (/*s*/; *s && !isspace(*s); s++) + i++; + strncpy(global_nodes[num_global_nodes], t, (size_t) i); + if (i>0 && t[i-1] != '\0') + global_nodes[num_global_nodes][i] = '\0'; + while (isspace(*s)) + s++; + num_global_nodes++; + } /* global_nodes[] holds name of global node */ +#ifdef TRACE + printf("***Global node option has been found.***\n"); + for (i = 0; ili_line[0] = '*'; /* comment it out */ + } +} + + /*------------------------------------------------------------------- inp_subcktexpand is the top level function which translates .subckts into mainlined code. Note that there are several things @@ -238,37 +275,7 @@ inp_subcktexpand(struct line *deck) { #endif /* Added by H.Tanaka to find global nodes */ - { - int i; - for (i = 0; i < 128; i++) - strcpy(global_nodes[i], ""); /* Clear global node holder */ - - num_global_nodes = 0; - for (c = deck; c; c = c->li_next) - if (ciprefix(".global", c->li_line)) { - char *s = c->li_line; - txfree(gettok(&s)); - while (*s) { - char *t = s; - i = 0; - for (/*s*/; *s && !isspace(*s); s++) - i++; - strncpy(global_nodes[num_global_nodes], t, (size_t) i); - if (i>0 && t[i-1] != '\0') - global_nodes[num_global_nodes][i] = '\0'; - while (isspace(*s)) - s++; - num_global_nodes++; - } /* global_nodes[] holds name of global node */ -#ifdef TRACE - printf("***Global node option has been found.***\n"); - for (i = 0; ili_line[0] = '*'; /* comment it out */ - } - } + collect_global_nodes(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 */