Handle streams separately in tree_add_track()
[cmus.git] / tabexp.c
blob271da5ff11ce47cdf8783169e845f9e7106d8d93
1 #include "tabexp.h"
2 #include "xmalloc.h"
3 #include "xstrjoin.h"
4 #include "debug.h"
6 #include <stdlib.h>
8 struct tabexp tabexp = {
9 .head = NULL,
10 .tails = NULL
13 char *tabexp_expand(const char *src, void (*load_matches)(const char *src))
15 static int idx = 0;
16 char *expanded;
18 if (tabexp.tails == NULL) {
19 load_matches(src);
20 if (tabexp.tails == NULL) {
21 BUG_ON(tabexp.head != NULL);
22 return NULL;
24 BUG_ON(tabexp.head == NULL);
25 idx = 0;
28 expanded = xstrjoin(tabexp.head, tabexp.tails[idx++]);
29 if (!tabexp.tails[idx])
30 idx = 0;
31 if (!tabexp.tails[1])
32 tabexp_reset();
33 return expanded;
36 void tabexp_reset(void)
38 free_str_array(tabexp.tails);
39 free(tabexp.head);
40 tabexp.tails = NULL;
41 tabexp.head = NULL;