xml_include fails if file is not found YAZ-668
[yaz-moved-to-github.git] / src / file_glob.c
index 57b51ac..3a5def2 100644 (file)
@@ -1,9 +1,9 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2011 Index Data
+ * Copyright (C) 1995-2013 Index Data
  * See the file LICENSE for details.
  */
 
-/** \file 
+/** \file
     \brief File globbing (ala POSIX glob, but simpler)
 */
 #if HAVE_CONFIG_H
@@ -36,6 +36,17 @@ struct glob_res {
     struct res_entry *entries;
 };
 
+static void add_entry(yaz_glob_res_t res, const char *str)
+{
+    struct res_entry *ent =
+        nmem_malloc(res->nmem, sizeof(*ent));
+    ent->file = nmem_strdup(res->nmem, str);
+    ent->next = 0;
+    *res->last_entry = ent;
+    res->last_entry = &ent->next;
+    res->number_of_entries++;
+}
+
 static void glob_r(yaz_glob_res_t res, const char *pattern, size_t off,
                    char *prefix)
 {
@@ -48,7 +59,7 @@ static void glob_r(yaz_glob_res_t res, const char *pattern, size_t off,
             is_pattern = 1;
         i++;
     }
-    
+
     if (!is_pattern && pattern[i]) /* no pattern and directory part */
     {
         i++; /* skip dir sep */
@@ -57,6 +68,11 @@ static void glob_r(yaz_glob_res_t res, const char *pattern, size_t off,
         glob_r(res, pattern, i, prefix);
         prefix[prefix_len] = '\0';
     }
+    else if (!is_pattern && !pattern[i])
+    {
+        strcpy(prefix + prefix_len, pattern + off);
+        add_entry(res, prefix);
+    }
     else
     {
         DIR * dir = opendir(*prefix ? prefix : "." );
@@ -82,13 +98,7 @@ static void glob_r(yaz_glob_res_t res, const char *pattern, size_t off,
                     }
                     else
                     {
-                        struct res_entry *ent =
-                            nmem_malloc(res->nmem, sizeof(*ent));
-                        ent->file = nmem_strdup(res->nmem, prefix);
-                        ent->next = 0;
-                        *res->last_entry = ent;
-                        res->last_entry = &ent->next;
-                        res->number_of_entries++;
+                        add_entry(res, prefix);
                     }
                     prefix[prefix_len] = '\0';
                 }