]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Added function for shell-like pattern matching. Will be used for
authorMartin Mares <mj@ucw.cz>
Sun, 29 Nov 1998 14:47:24 +0000 (14:47 +0000)
committerMartin Mares <mj@ucw.cz>
Sun, 29 Nov 1998 14:47:24 +0000 (14:47 +0000)
matching interface names in protocol-to-iface bindings.

lib/Modules
lib/patmatch.c [new file with mode: 0644]
lib/string.h

index 5657ee73cb28e8f4172bbe4e090392ab838c3f80..a1c1fd7f7333d50f70470db2351ff08c3c3b938f 100644 (file)
@@ -19,3 +19,4 @@ unaligned.h
 xmalloc.c
 printf.c
 string.h
+patmatch.c
diff --git a/lib/patmatch.c b/lib/patmatch.c
new file mode 100644 (file)
index 0000000..15d5007
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ *     BIRD Library -- Generic Shell-Like Pattern Matching (currently only '?' and '*')
+ *
+ *     (c) 1998 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
+ */
+
+#include "nest/bird.h"
+#include "lib/string.h"
+
+#ifndef MATCH_FUNC_NAME
+#define MATCH_FUNC_NAME patmatch
+#endif
+
+#ifndef Convert
+#define Convert(x) x
+#endif
+
+int
+MATCH_FUNC_NAME(byte *p, byte *s)
+{
+  while (*p)
+    {
+      if (*p == '?' && *s)
+       p++, s++;
+      else if (*p == '*')
+       {
+         int z = p[1];
+
+         if (!z)
+           return 1;
+         if (z == '\\' && p[2])
+           z = p[2];
+         z = Convert(z);
+         for(;;)
+           {
+             while (*s && Convert(*s) != z)
+               s++;
+             if (!*s)
+               return 0;
+             if (MATCH_FUNC_NAME(p+1, s))
+               return 1;
+             s++;
+           }
+       }
+      else
+       {
+         if (*p == '\\' && p[1])
+           p++;
+         if (Convert(*p++) != Convert(*s++))
+           return 0;
+       }
+    }
+  return !*s;
+}
index 202db0abf41fb9de681afb246ffa53fb569f525b..03affacc538ff7319540f826cdb716ed6aa6f6c8 100644 (file)
@@ -16,4 +16,6 @@ int bvsprintf(char *str, const char *fmt, va_list args);
 int bsnprintf(char *str, int size, const char *fmt, ...);
 int bvsnprintf(char *str, int size, const char *fmt, va_list args);
 
+int patmatch(byte *pat, byte *str);
+
 #endif