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