implement wl_cons(), wl_append_word() and wl_chop_rest()

This commit is contained in:
rlar 2012-07-14 09:18:39 +02:00
parent 8defa56cf6
commit d9ddaec784
2 changed files with 47 additions and 0 deletions

View File

@ -25,6 +25,11 @@ wordlist * wl_nthelem(int i, wordlist *wl);
void wl_sort(wordlist *wl);
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_rest(wordlist *wlist);
/* For quoting individual characters. '' strings are all quoted, but
* `` and "" strings are maintained as single words with the quotes

View File

@ -294,3 +294,45 @@ wl_range(wordlist *wl, int low, int up)
return (wl);
}
wordlist *
wl_cons(char *word, wordlist *tail)
{
wordlist *w = alloc(struct wordlist);
w->wl_next = tail;
w->wl_prev = NULL;
w->wl_word = word;
if (tail)
tail->wl_prev = w;
return w;
}
void
wl_append_word(wordlist **first, wordlist **last, char *word)
{
wordlist *w = alloc(struct wordlist);
w->wl_next = NULL;
w->wl_prev = (*last);
w->wl_word = word;
if (*last)
(*last)->wl_next = w;
else
(*first) = w;
(*last) = w;
}
wordlist *
wl_chop_rest(wordlist *wl)
{
wordlist *rest = wl->wl_next;
wl->wl_next = NULL;
if(rest)
rest->wl_prev = NULL;
return rest;
}