From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONTRIB/SNIP/xstrcmp.c | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 reference/C/CONTRIB/SNIP/xstrcmp.c (limited to 'reference/C/CONTRIB/SNIP/xstrcmp.c') diff --git a/reference/C/CONTRIB/SNIP/xstrcmp.c b/reference/C/CONTRIB/SNIP/xstrcmp.c new file mode 100755 index 0000000..3d9502c --- /dev/null +++ b/reference/C/CONTRIB/SNIP/xstrcmp.c @@ -0,0 +1,67 @@ +/* +** xstrcmp() - compares strings using DOS wildcards +** 'mask' may contain '*' and '?' +** returns 1 if 's' matches 'mask', otherwise 0 +** public domain by Steffen Offermann 1991 +*/ + + +int xstrcmp (char *mask, char *s) +{ + while (*mask) + { + switch (*mask) + { + case '?': + if (!*s) + return (0); + s++; + mask++; + break; + + case '*': + while (*mask == '*') + mask++; + if (!*mask) + return ( 1 ); + if (*mask == '?') + break; + while (*s != *mask) + { + if (!*s) + return (0); + s++; + } + s++; + mask++; + break; + + default: + if (*s != *mask) + return (0); + s++; + mask++; + } + } + + if (!*s && *mask) + return (0); + return ( 1 ); +} + +#ifdef TEST + +#include + +void main(int argc, char *argv[]) +{ + if (3 != argc) + { + puts("Usage: XSTRCMP string_1 string_2"); + return; + } + printf("xstrcmp(\"%s\", \"%s\") returned %d\n", argv[1], argv[2], + xstrcmp(argv[1], argv[2])); +} + +#endif /* TEST */ -- cgit v1.2.3-54-g00ecf