summaryrefslogtreecommitdiff
path: root/rushs/tinyprintf/simple_fnmatch
diff options
context:
space:
mode:
Diffstat (limited to 'rushs/tinyprintf/simple_fnmatch')
-rw-r--r--rushs/tinyprintf/simple_fnmatch/simple_fnmatch.c46
-rw-r--r--rushs/tinyprintf/simple_fnmatch/simple_fnmatch.h8
2 files changed, 54 insertions, 0 deletions
diff --git a/rushs/tinyprintf/simple_fnmatch/simple_fnmatch.c b/rushs/tinyprintf/simple_fnmatch/simple_fnmatch.c
new file mode 100644
index 0000000..d40353f
--- /dev/null
+++ b/rushs/tinyprintf/simple_fnmatch/simple_fnmatch.c
@@ -0,0 +1,46 @@
+#include "simple_fnmatch.h"
+
+int simple_fnmatch(const char *pattern, const char *string)
+{
+ if (!pattern || !string)
+ return FNM_NOMATCH;
+ if (*pattern == '*' && pattern[1] == '\0')
+ return 0;
+ while (*pattern && *string)
+ {
+ if (*pattern == '?')
+ {
+ pattern++;
+ string++;
+ }
+ else if (*pattern == '\\')
+ {
+ pattern++;
+ if (!pattern || *pattern != *string)
+ return FNM_NOMATCH;
+ string++;
+ pattern++;
+ }
+ else if (*pattern == '*')
+ {
+ pattern++;
+ while (*string && simple_fnmatch(pattern, string))
+ string++;
+ if (*string)
+ return 0;
+ }
+ else if (*pattern != *string)
+ return FNM_NOMATCH;
+ else
+ {
+ string++;
+ pattern++;
+ }
+ }
+
+ if (*pattern == '*' && pattern[1] == '\0')
+ return 0;
+ if (*string || *pattern)
+ return FNM_NOMATCH;
+ return 0;
+}
diff --git a/rushs/tinyprintf/simple_fnmatch/simple_fnmatch.h b/rushs/tinyprintf/simple_fnmatch/simple_fnmatch.h
new file mode 100644
index 0000000..e1ae166
--- /dev/null
+++ b/rushs/tinyprintf/simple_fnmatch/simple_fnmatch.h
@@ -0,0 +1,8 @@
+#ifndef SIMPLE_FNMATCH_H
+#define SIMPLE_FNMATCH_H
+
+#define FNM_NOMATCH 1
+
+int simple_fnmatch(const char *pattern, const char *string);
+
+#endif /* !SIMPLE_FNMATCH_H */