# HG changeset patch # User Matti Hamalainen # Date 1578999203 -7200 # Node ID 5ec903f366b5b50e1ce1b3c861e35f7d3025bbd1 # Parent 492633200ddd67b4b6b9ef2415fb1973869a3929 Rename th_strmatch.c to th_strglob.c diff -r 492633200ddd -r 5ec903f366b5 Makefile.inc --- a/Makefile.inc Tue Jan 14 03:28:53 2020 +0200 +++ b/Makefile.inc Tue Jan 14 12:53:23 2020 +0200 @@ -68,7 +68,8 @@ all: $(NOBUILD_TARGETS) $(NOINST_TARGETS) $(TARGETS) -$(THLIBS)th_string.c: $(addprefix $(THLIBS), th_printf.c th_printf1.c th_strmatch.c th_string.h) +$(THLIBS)th_string.c: $(addprefix $(THLIBS), \ + th_printf.c th_printf1.c th_strglob.c th_string.h) @touch $@ diff -r 492633200ddd -r 5ec903f366b5 th_strglob.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/th_strglob.c Tue Jan 14 12:53:23 2020 +0200 @@ -0,0 +1,108 @@ +/* + * String glob match implementation + * Programmed and designed by Matti 'ccr' Hamalainen + * (C) Copyright 2002-2020 Tecnic Software productions (TNSP) + * + * Please read file 'COPYING' for information on license and distribution. + */ + +BOOL TH_STRGLOB_FUNC (const char *haystack, const char *pattern) +{ + BOOL matched = TRUE, any = FALSE, end = FALSE; + const char *tmp = NULL; + + // Check given pattern and string + if (haystack == NULL || pattern == NULL) + return FALSE; + + // Start comparision + while (matched && !end) + switch (*pattern) + { + case '?': + // Any single character matches + if (*haystack) + { + pattern++; + haystack++; + } + else + matched = FALSE; + break; + + case '*': + pattern++; + if (!*pattern || *pattern == '?') + end = TRUE; + any = TRUE; + tmp = pattern; + break; + + case 0: + if (any) + { + if (*haystack) + haystack++; + else + end = TRUE; + } + else + if (*haystack) + { + if (tmp) + { + any = TRUE; + pattern = tmp; + } + else + matched = FALSE; + } + else + end = TRUE; + break; + + default: + if (any) + { + if (TH_STRGLOB_COLLATE(*pattern) == TH_STRGLOB_COLLATE(*haystack)) + { + any = FALSE; + } + else + if (*haystack) + haystack++; + else + matched = FALSE; + } + else + { + if (TH_STRGLOB_COLLATE(*pattern) == TH_STRGLOB_COLLATE(*haystack)) + { + if (*pattern) + pattern++; + if (*haystack) + haystack++; + } + else + if (tmp) + { + any = TRUE; + pattern = tmp; + } + else + matched = FALSE; + } + + if (!*haystack && !*pattern) + end = TRUE; + + break; + } + + return matched; +} + + +#undef TH_STRGLOB_FUNC +#undef TH_STRGLOB_COLLATE + diff -r 492633200ddd -r 5ec903f366b5 th_string.c --- a/th_string.c Tue Jan 14 03:28:53 2020 +0200 +++ b/th_string.c Tue Jan 14 12:53:23 2020 +0200 @@ -543,14 +543,14 @@ */ #define TH_STRGLOB_FUNC th_strmatch #define TH_STRGLOB_COLLATE(px) (px) -#include "th_strmatch.c" +#include "th_strglob.c" /* Compare a string to a pattern. Case-INSENSITIVE version. */ #define TH_STRGLOB_FUNC th_strcasematch #define TH_STRGLOB_COLLATE(px) th_tolower(px) -#include "th_strmatch.c" +#include "th_strglob.c" BOOL th_get_hex_triplet(const char *str, unsigned int *value) diff -r 492633200ddd -r 5ec903f366b5 th_strmatch.c --- a/th_strmatch.c Tue Jan 14 03:28:53 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -/* - * String glob match implementation - * Programmed and designed by Matti 'ccr' Hamalainen - * (C) Copyright 2002-2020 Tecnic Software productions (TNSP) - * - * Please read file 'COPYING' for information on license and distribution. - */ - -BOOL TH_STRGLOB_FUNC (const char *haystack, const char *pattern) -{ - BOOL matched = TRUE, any = FALSE, end = FALSE; - const char *tmp = NULL; - - // Check given pattern and string - if (haystack == NULL || pattern == NULL) - return FALSE; - - // Start comparision - while (matched && !end) - switch (*pattern) - { - case '?': - // Any single character matches - if (*haystack) - { - pattern++; - haystack++; - } - else - matched = FALSE; - break; - - case '*': - pattern++; - if (!*pattern || *pattern == '?') - end = TRUE; - any = TRUE; - tmp = pattern; - break; - - case 0: - if (any) - { - if (*haystack) - haystack++; - else - end = TRUE; - } - else - if (*haystack) - { - if (tmp) - { - any = TRUE; - pattern = tmp; - } - else - matched = FALSE; - } - else - end = TRUE; - break; - - default: - if (any) - { - if (TH_STRGLOB_COLLATE(*pattern) == TH_STRGLOB_COLLATE(*haystack)) - { - any = FALSE; - } - else - if (*haystack) - haystack++; - else - matched = FALSE; - } - else - { - if (TH_STRGLOB_COLLATE(*pattern) == TH_STRGLOB_COLLATE(*haystack)) - { - if (*pattern) - pattern++; - if (*haystack) - haystack++; - } - else - if (tmp) - { - any = TRUE; - pattern = tmp; - } - else - matched = FALSE; - } - - if (!*haystack && !*pattern) - end = TRUE; - - break; - } - - return matched; -} - - -#undef TH_STRGLOB_FUNC -#undef TH_STRGLOB_COLLATE -