summary refs log tree commit diff
path: root/runit-2.1.2/src/pmatch.c
blob: 2fc9a53224240cd5a7da0741c226c53c14ba9e74 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

int pmatch(const char *p, const char *s, unsigned int len) {
  for (;;) {
    char c =*p++;
    if (! c) return(! len);
    switch(c) {
    case '*':
      if (! (c =*p)) return(1);
      for (;;) {
        if (! len) return(0);
        if (*s == c) break;
        ++s; --len;
      }
      continue;
    case '+':
      if ((c =*p++) != *s) return(0);
      for (;;) {
        if (! len) return(1);
        if (*s != c) break;
        ++s; --len;
      }
      continue;
      /*
    case '?':
      if (*p == '?') {
        if (*s != '?') return(0);
        ++p;
      }
      ++s; --len;
      continue;
      */
    default:
      if (! len) return(0);
      if (*s != c) return(0);
      ++s; --len;
      continue;
    }
  }
  return(0);
}