use new ensc_wrappers/ headers
[util-vserver.git] / util-vserver / src / vunify-matchlist.c
index 9945442..2801aa3 100644 (file)
 #endif
 
 #include "vunify-matchlist.h"
+
+#include <fnmatch.h>
 #include <assert.h>
 
+#define ENSC_WRAPPERS_STDLIB   1
+#include <wrappers.h>
+
 bool
 MatchList_compare(struct MatchList const *list, char const *path)
 {
@@ -33,8 +38,8 @@ MatchList_compare(struct MatchList const *list, char const *path)
   //write(1, path, strlen(path));
   //write(1, "\n", 1);
   for (; ptr<end_ptr; ++ptr) {
-    assert(ptr->cmp!=0);
-    if ((ptr->cmp)(ptr->name, path)==0) {
+    if ((ptr->cmp==0 && strcmp(ptr->name, path)==0) ||
+       (ptr->cmp!=0 && (ptr->cmp)(ptr->name, path)==0)) {
       switch (ptr->type) {
        case stINCLUDE  :  res = true;  break;
        case stEXCLUDE  :  res = false; break;
@@ -53,8 +58,58 @@ MatchList_init(struct MatchList *list, char const *root, size_t count)
   list->skip_depth = 0;
   list->root.d     = root;
   list->root.l     = strlen(root);
-  list->data       = malloc(sizeof(struct MatchItem) * count);
+  list->data       = Emalloc(sizeof(struct MatchItem) * count);
   list->count      = count;
+  list->buf        = 0;
+  list->buf_count  = 0;
+
+  String_init(&list->id);
+}
+
+static int
+fnmatchWrap(char const *a, char const *b)
+{
+  return fnmatch(a, b, 0);
+}
+
+
+static MatchItemCompareFunc
+determineCompareFunc(char const UNUSED *fname)
+{
+  return fnmatchWrap;
+}
+
+void
+MatchList_appendFiles(struct MatchList *list, size_t idx,
+                     char **files, size_t count,
+                     bool auto_type)
+{
+  struct MatchItem     *ptr = list->data + idx;
+  size_t               i;
+  
+  assert(idx+count <= list->count);
+
+  if (auto_type) {
+    for (i=0; i<count; ++i) {
+      char     *file = files[i];
+      switch (file[0]) {
+       case '+'        :  ptr->type = stINCLUDE; ++file; break;
+       case '-'        :  ++file; /*@fallthrough@*/
+       default         :  ptr->type = stEXCLUDE; break;
+      }
+      ptr->cmp  = determineCompareFunc(file);
+      ptr->name = file;
+      ++ptr;
+    }
+  }
+  else {
+    for (i=0; i<count; ++i) {
+      ptr->type = stEXCLUDE;
+      ptr->name = files[i];
+      ptr->cmp  = 0;
+      ++ptr;
+    }
+  }
 }
 
 
@@ -88,6 +143,12 @@ PathInfo_append(PathInfo       * restrict lhs,
   lhs->l = ptr-buf-1;
 }
 
+void
+String_init(String *str)
+{
+  str->d = 0;
+  str->l = 0;
+}
 
 #ifdef ENSC_TESTSUITE
 #define CHECK(LHS,RHS, EXP)                            \