Annotation of embedaddon/bird/lib/patmatch.c, revision 1.1.1.1
1.1 misho 1: /*
2: * BIRD Library -- Generic Shell-Like Pattern Matching (currently only '?' and '*')
3: *
4: * (c) 1998--2000 Martin Mares <mj@ucw.cz>
5: */
6:
7: #include "nest/bird.h"
8: #include "lib/string.h"
9:
10: #ifndef MATCH_FUNC_NAME
11: #define MATCH_FUNC_NAME patmatch
12: #endif
13:
14: #ifndef Convert
15: #define Convert(x) x
16: #endif
17:
18: int
19: MATCH_FUNC_NAME(const byte *p, const byte *s)
20: {
21: while (*p)
22: {
23: if (*p == '?' && *s)
24: p++, s++;
25: else if (*p == '*')
26: {
27: int z = p[1];
28:
29: if (!z)
30: return 1;
31: if (z == '\\' && p[2])
32: z = p[2];
33: z = Convert(z);
34: for(;;)
35: {
36: while (*s && Convert(*s) != z)
37: s++;
38: if (!*s)
39: return 0;
40: if (MATCH_FUNC_NAME(p+1, s))
41: return 1;
42: s++;
43: }
44: }
45: else
46: {
47: if (*p == '\\' && p[1])
48: p++;
49: if (Convert(*p++) != Convert(*s++))
50: return 0;
51: }
52: }
53: return !*s;
54: }
55:
56: #if 0
57: /**
58: * patmatch - match shell-like patterns
59: * @p: pattern
60: * @s: string
61: *
62: * patmatch() returns whether given string @s matches the given shell-like
63: * pattern @p. The patterns consist of characters (which are matched literally),
64: * question marks which match any single character, asterisks which match any
65: * (possibly empty) string of characters and backslashes which are used to
66: * escape any special characters and force them to be treated literally.
67: *
68: * The matching process is not optimized with respect to time, so please
69: * avoid using this function for complex patterns.
70: */
71: int
72: patmatch(byte *p, byte *s)
73: { DUMMY; }
74: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>