Commit dee929d8 authored by Martin Mareš's avatar Martin Mareš

Added function for shell-like pattern matching. Will be used for

matching interface names in protocol-to-iface bindings.
parent bd5d0d62
...@@ -19,3 +19,4 @@ unaligned.h ...@@ -19,3 +19,4 @@ unaligned.h
xmalloc.c xmalloc.c
printf.c printf.c
string.h string.h
patmatch.c
/*
* 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;
}
...@@ -16,4 +16,6 @@ int bvsprintf(char *str, const char *fmt, va_list args); ...@@ -16,4 +16,6 @@ int bvsprintf(char *str, const char *fmt, va_list args);
int bsnprintf(char *str, int size, const char *fmt, ...); int bsnprintf(char *str, int size, const char *fmt, ...);
int bvsnprintf(char *str, int size, const char *fmt, va_list args); int bvsnprintf(char *str, int size, const char *fmt, va_list args);
int patmatch(byte *pat, byte *str);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment