summaryrefslogtreecommitdiff
path: root/reference/C/CONTRIB/SNIP/xstrcmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'reference/C/CONTRIB/SNIP/xstrcmp.c')
-rwxr-xr-xreference/C/CONTRIB/SNIP/xstrcmp.c67
1 files changed, 67 insertions, 0 deletions
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 <stdio.h>
+
+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 */