about summary refs log tree commit diff
path: root/util.c
diff options
context:
space:
mode:
authorHeikki Kallasjoki <fis@zem.fi>2018-11-30 21:49:29 +0000
committerHeikki Kallasjoki <fis@zem.fi>2018-11-30 21:50:10 +0000
commit1df8f91af10605e3245774ed4b86254e8d9a1ffe (patch)
tree483932952a00c047dc5b617746efa13ec537eed5 /util.c
parentcf2969241324d2464bf1121406404cd8c0f6e0bc (diff)
downloadnano-exporter-1df8f91af10605e3245774ed4b86254e8d9a1ffe.tar.gz
nano-exporter-1df8f91af10605e3245774ed4b86254e8d9a1ffe.tar.xz
nano-exporter-1df8f91af10605e3245774ed4b86254e8d9a1ffe.zip
Add support for matching with prefix in include/exclude lists.
Diffstat (limited to 'util.c')
-rw-r--r--util.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/util.c b/util.c
index 976de0b..1d85d5c 100644
--- a/util.c
+++ b/util.c
@@ -168,6 +168,22 @@ bool slist_contains(const struct slist *list, const char *key) {
   return false;
 }
 
+bool slist_matches(const struct slist *list, const char *key) {
+  size_t key_len = strlen(key);
+
+  for (; list; list = list->next) {
+    size_t match_len = strlen(list->data);
+    if (match_len > 0 && list->data[match_len-1] == '*') {
+      if (match_len-1 <= key_len && memcmp(list->data, key, match_len-1) == 0)
+        return true;
+    } else {
+      if (match_len == key_len && memcmp(list->data, key, key_len) == 0)
+        return true;
+    }
+  }
+  return false;
+}
+
 // miscellaneous utilities
 
 void *must_malloc(size_t size) {