2 * Copyright 2004-2005 Timo Hirvonen
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 struct tabexp tabexp
= {
33 /* index to tabexp.tails */
34 static int tabexp_index
= 0;
36 char *tabexp_expand(const char *src
, void (*load_matches
)(const char *src
))
38 if (tabexp
.tails
== NULL
) {
43 if (tabexp
.tails
== NULL
) {
44 BUG_ON(tabexp
.head
!= NULL
);
45 BUG_ON(tabexp
.nr_tails
!= 0);
49 BUG_ON(tabexp
.head
== NULL
);
50 BUG_ON(tabexp
.nr_tails
< 1);
52 expanded
= xstrjoin(tabexp
.head
, tabexp
.tails
[0]);
53 if (tabexp
.nr_tails
== 1)
58 tabexp_index
%= tabexp
.nr_tails
;
59 return xstrjoin(tabexp
.head
, tabexp
.tails
[tabexp_index
]);
63 void tabexp_reset(void)
67 for (i
= 0; i
< tabexp
.nr_tails
; i
++)
68 free(tabexp
.tails
[i
]);