diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /rushs/tinyprintf/simple_fnmatch/simple_fnmatch.c | |
add: graphs et rushs
Diffstat (limited to 'rushs/tinyprintf/simple_fnmatch/simple_fnmatch.c')
| -rw-r--r-- | rushs/tinyprintf/simple_fnmatch/simple_fnmatch.c | 46 |
1 files changed, 46 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; +} |
