Statistics
| Branch: | Revision:

iof-bird-daemon / lib / patmatch.c @ dee929d8

History | View | Annotate | Download (830 Bytes)

1
/*
2
 *        BIRD Library -- Generic Shell-Like Pattern Matching (currently only '?' and '*')
3
 *
4
 *        (c) 1998 Martin Mares, <mj@atrey.karlin.mff.cuni.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(byte *p, 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
}