summaryrefslogtreecommitdiffstats
path: root/lib/patmatch.c
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>1998-11-29 15:47:24 +0100
committerMartin Mares <mj@ucw.cz>1998-11-29 15:47:24 +0100
commitdee929d86844b1956b1c0f1d2c0289a787ab9226 (patch)
tree746052f1d258a7f471fee1bb8822a3d405bf747e /lib/patmatch.c
parentbd5d0d62f10c65d56e1900014be5989a3feb8380 (diff)
downloadbird-dee929d86844b1956b1c0f1d2c0289a787ab9226.tar
bird-dee929d86844b1956b1c0f1d2c0289a787ab9226.zip
Added function for shell-like pattern matching. Will be used for
matching interface names in protocol-to-iface bindings.
Diffstat (limited to 'lib/patmatch.c')
-rw-r--r--lib/patmatch.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/patmatch.c b/lib/patmatch.c
new file mode 100644
index 0000000..15d5007
--- /dev/null
+++ b/lib/patmatch.c
@@ -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;
+}