From cdef8aa10eedd76e995aa422ad2e651482dd4c42 Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 29 Jul 2012 10:17:09 +0200 Subject: [PATCH] implement wl_delete_slice() --- src/include/ngspice/wordlist.h | 1 + src/misc/wlist.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/include/ngspice/wordlist.h b/src/include/ngspice/wordlist.h index 930b6df00..286b8a841 100644 --- a/src/include/ngspice/wordlist.h +++ b/src/include/ngspice/wordlist.h @@ -32,6 +32,7 @@ wordlist *wl_chop(wordlist *wlist); wordlist *wl_chop_rest(wordlist *wlist); wordlist *wl_find(const char *string, wordlist *wlist); +void wl_delete_slice(wordlist *from, wordlist *to); /* For quoting individual characters. '' strings are all quoted, but diff --git a/src/misc/wlist.c b/src/misc/wlist.c index 0701eab0e..d7de3784f 100644 --- a/src/misc/wlist.c +++ b/src/misc/wlist.c @@ -367,3 +367,31 @@ wl_find(const char *string, wordlist *wl) break; return wl; } + + +/* + * delete elements from a wordlist + * from inclusive `from' + * up to exclusive `to' + */ + +void +wl_delete_slice(wordlist *from, wordlist *to) +{ + wordlist *prev; + + if (from == to) + return; + + prev = from->wl_prev; + + if(prev) + prev->wl_next = to; + + if (to) { + to->wl_prev->wl_next = NULL; + to->wl_prev = prev; + } + + wl_free(from); +}