14#include <grass/config.h>
27static void init(
struct buffer *buf)
34static void add(
struct buffer *buf,
char c)
36 if (buf->len >= buf->alloc) {
38 buf->buf = G_realloc(buf->buf, buf->alloc);
41 buf->buf[buf->len++] = c;
44static void fini(
struct buffer *buf)
49static const char *do_set(
struct buffer *buf,
const char *p)
63 for (; *p && *p !=
']'; p++)
74static int wc2regex(
struct buffer *buf,
const char *pat)
83 for (p = pat; p && *p; p++) {
123 if (!(p = do_set(buf, p)))
144static int re_filter(
const char *filename,
void *closure)
146 regex_t *regex = closure;
148 return filename[0] !=
'.' && regexec(regex, filename, 0,
NULL, 0) == 0;
151void *G_ls_regex_filter(
const char *pat,
int exclude,
int extended,
154 regex_t *regex = G_malloc(
sizeof(regex_t));
156 if (regcomp(regex, pat,
157 REG_NOSUB | (extended ? REG_EXTENDED : 0) |
158 (ignorecase ? REG_ICASE : 0)) != 0) {
171void *G_ls_glob_filter(
const char *pat,
int exclude,
int ignorecase)
178 if (!wc2regex(&buf, pat)) {
183 regex = G_ls_regex_filter(buf.buf, exclude, 1, ignorecase);
190void G_free_ls_filter(
void *regex)
void G_free(void *buf)
Free allocated memory.
void G_set_ls_filter(ls_filter_func *func, void *closure)
Sets a function and its complementary data for G_ls2 filtering.
void G_set_ls_exclude_filter(ls_filter_func *func, void *closure)