implement wl_chop()

This commit is contained in:
rlar 2012-07-21 14:39:04 +02:00
parent 87c80b842c
commit 561d30e5bf
3 changed files with 19 additions and 4 deletions

View File

@ -674,10 +674,7 @@ doit(struct line *deck, wordlist *modnames) {
#endif #endif
if(modnames != xmodnames) { if(modnames != xmodnames) {
if(xmodnames && xmodnames->wl_prev) { wl_chop(xmodnames);
xmodnames->wl_prev->wl_next = NULL;
xmodnames->wl_prev = NULL;
}
wl_free(modnames); wl_free(modnames);
} }

View File

@ -28,6 +28,7 @@ wordlist * wl_range(wordlist *wl, int low, int up);
wordlist *wl_cons(char *word, wordlist *tail); wordlist *wl_cons(char *word, wordlist *tail);
void wl_append_word(wordlist **first, wordlist **last, char *word); void wl_append_word(wordlist **first, wordlist **last, char *word);
wordlist *wl_chop(wordlist *wlist);
wordlist *wl_chop_rest(wordlist *wlist); wordlist *wl_chop_rest(wordlist *wlist);

View File

@ -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 * given a pointer `wl' into a wordlist
* cut off the rest of the list * cut off the rest of the list