Start work on file_glob .
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 25 Jan 2010 15:30:14 +0000 (16:30 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 25 Jan 2010 15:30:14 +0000 (16:30 +0100)
src/Makefile.am
src/file_glob.c [new file with mode: 0644]

index 7cff54e..2208c7f 100644 (file)
@@ -103,7 +103,7 @@ libyaz_la_SOURCES=version.c options.c log.c \
   copy_types.c match_glob.c poll.c daemon.c \
   iconv_encode_marc8.c iconv_encode_iso_8859_1.c iconv_encode_wchar.c \
   iconv_decode_marc8.c iconv_decode_iso5426.c iconv_decode_danmarc.c sc.c \
-  json.c xml_include.c
+  json.c xml_include.c file_glob.c
 
 libyaz_la_LDFLAGS=-version-info $(YAZ_VERSION_INFO)
 
diff --git a/src/file_glob.c b/src/file_glob.c
new file mode 100644 (file)
index 0000000..2f3ff7f
--- /dev/null
@@ -0,0 +1,55 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+/** \file 
+    \brief File globbing (ala POSIX glob)
+*/
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <yaz/wrbuf.h>
+#include <yaz/tpath.h>
+#include <yaz/log.h>
+
+struct res_entry {
+    struct res_entry *next;
+};
+
+struct glob_res {
+    struct res_entry *entries;
+};
+
+typedef struct glob_res *yaz_glob_res_t;
+
+static void glob_r(const char *pattern, yaz_glob_res_t res, size_t off)
+{
+    size_t i = off;
+    while (pattern[i] && !strchr("/\\", pattern[i]))
+        i++;
+}
+
+int yaz_file_glob(const char *pattern, yaz_glob_res_t *res)
+{
+    *res = xmalloc(sizeof(**res));
+    (*res)->entries = 0;
+    glob_r(pattern, *res, 0);
+    return 0;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+