File: McWildMatch.cpp

package info (click to toggle)
doc%2B%2B 3.2-1
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 1,844 kB
  • ctags: 1,925
  • sloc: cpp: 16,762; lex: 2,938; makefile: 278; java: 273; yacc: 139; perl: 20; sh: 17
file content (52 lines) | stat: -rw-r--r-- 839 bytes parent folder | download | duplicates (2)
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
41
42
43
44
45
46
47
48
49
50
51
52
/////////////////////////////////////////////////////////////////
//
// $Id: McWildMatch.cpp,v 3.0 1997/02/04 17:49:00 bzfzoeck Exp $
//
/////////////////////////////////////////////////////////////////

int mcWildMatch(const char* str, const char* pat)
{
    register int i = 0, j = 0;
    int	star = 0, k = 0;

    while (pat[i] != '\0'&& str[j] != '\0')
    {
	if (pat[i] == '*')
	{
	    star = 1;
	    while (pat[i] == '*') i++;
	    k = i;
	}
	else
	{
	    if (pat[i] == '?' || pat[i] == str[j])
	    {
	        j++; i++;
	    }
	    else
	    {
		if (star == 0)
		{
		    return 0;
		}
	        i = k;
		j++;
	    }
	}
    }

    while (pat[i] == '*') i++;

    if (pat[i] == str[j])
    {
	return 1;
    }
    else if (pat[i] == '\0' && (pat[i-1] == '*' || pat[i-1] == '?'))
    {
	return 1;
    }
    else
    {
	return 0;
    }
}