From 561d30e5bfadb49db0106b2c562ea5f8789657ff Mon Sep 17 00:00:00 2001 From: rlar Date: Sat, 21 Jul 2012 14:39:04 +0200 Subject: [PATCH] implement wl_chop() --- src/frontend/subckt.c | 5 +---- src/include/ngspice/wordlist.h | 1 + src/misc/wlist.c | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/frontend/subckt.c b/src/frontend/subckt.c index 367f284ee..97a1e4c62 100644 --- a/src/frontend/subckt.c +++ b/src/frontend/subckt.c @@ -674,10 +674,7 @@ doit(struct line *deck, wordlist *modnames) { #endif if(modnames != xmodnames) { - if(xmodnames && xmodnames->wl_prev) { - xmodnames->wl_prev->wl_next = NULL; - xmodnames->wl_prev = NULL; - } + wl_chop(xmodnames); wl_free(modnames); } diff --git a/src/include/ngspice/wordlist.h b/src/include/ngspice/wordlist.h index ade2b43b5..5273973fc 100644 --- a/src/include/ngspice/wordlist.h +++ b/src/include/ngspice/wordlist.h @@ -28,6 +28,7 @@ wordlist * wl_range(wordlist *wl, int low, int up); wordlist *wl_cons(char *word, wordlist *tail); void wl_append_word(wordlist **first, wordlist **last, char *word); +wordlist *wl_chop(wordlist *wlist); wordlist *wl_chop_rest(wordlist *wlist); diff --git a/src/misc/wlist.c b/src/misc/wlist.c index ad0557155..822534e4f 100644 --- a/src/misc/wlist.c +++ b/src/misc/wlist.c @@ -321,6 +321,23 @@ wl_append_word(wordlist **first, wordlist **last, char *word) } +/* + * given a pointer `wl' into a wordlist + * cut off this list from its preceding elements + * and return itself + */ + +wordlist * +wl_chop(wordlist *wl) +{ + if (wl && wl->wl_prev) { + wl->wl_prev->wl_next = NULL; + wl->wl_prev = NULL; + } + return wl; +} + + /* * given a pointer `wl' into a wordlist * cut off the rest of the list