Revision dee929d8

View differences:

lib/Modules
19 19
xmalloc.c
20 20
printf.c
21 21
string.h
22
patmatch.c
lib/patmatch.c
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
}
lib/string.h
16 16
int bsnprintf(char *str, int size, const char *fmt, ...);
17 17
int bvsnprintf(char *str, int size, const char *fmt, va_list args);
18 18

  
19
int patmatch(byte *pat, byte *str);
20

  
19 21
#endif

Also available in: Unified diff