home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 9 Archive
/
09-Archive.zip
/
lha100bt.zip
/
lha-1.00
/
src
/
patmatch.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-31
|
1KB
|
39 lines
/*
* Returns true if string s matches pattern p.
*/
#include <ctype.h>
int
patmatch(p, s, f)
register char *p; /* pattern */
register char *s; /* string to match */
int f; /* flag for case force */
{
char pc; /* a single character from pattern */
if (p[0]=='-') return(1);
while (pc = ((f && islower(*p)) ? toupper(*p++) : *p++))
{
if (pc == '*')
{
do { /* look for match till s exhausted */
if (patmatch (p, s, f))
return (1);
} while (*s++);
return (0);
}
else
if (*s == 0)
return (0); /* s exhausted, p not */
else
if (pc == '?')
s++; /* matches all, just bump */
else
if (pc != ((f && islower(*s)) ? toupper(*s++) : *s++))
return (0);
}
return (!*s); /* p exhausted, ret true if s exhausted */
}