comparison th_strglob.c @ 735:31bc1ed07cf5

Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 07 Dec 2022 12:14:39 +0200
parents 29e44a58bc73
children 600a3c08747f
comparison
equal deleted inserted replaced
734:2ae1045f6c18 735:31bc1ed07cf5
4 * (C) Copyright 2002-2022 Tecnic Software productions (TNSP) 4 * (C) Copyright 2002-2022 Tecnic Software productions (TNSP)
5 * 5 *
6 * Please read file 'COPYING' for information on license and distribution. 6 * Please read file 'COPYING' for information on license and distribution.
7 */ 7 */
8 8
9 BOOL TH_STRGLOB_FUNC (const char *haystack, const char *pattern) 9 bool TH_STRGLOB_FUNC (const char *haystack, const char *pattern)
10 { 10 {
11 BOOL matched = TRUE, any = FALSE, end = FALSE; 11 bool matched = true, any = false, end = false;
12 const char *tmp = NULL; 12 const char *tmp = NULL;
13 13
14 // Check given pattern and string 14 // Check given pattern and string
15 if (haystack == NULL || pattern == NULL) 15 if (haystack == NULL || pattern == NULL)
16 return FALSE; 16 return false;
17 17
18 // Start comparision 18 // Start comparision
19 while (matched && !end) 19 while (matched && !end)
20 switch (*pattern) 20 switch (*pattern)
21 { 21 {
25 { 25 {
26 pattern++; 26 pattern++;
27 haystack++; 27 haystack++;
28 } 28 }
29 else 29 else
30 matched = FALSE; 30 matched = false;
31 break; 31 break;
32 32
33 case '*': 33 case '*':
34 pattern++; 34 pattern++;
35 if (!*pattern || *pattern == '?') 35 if (!*pattern || *pattern == '?')
36 end = TRUE; 36 end = true;
37 any = TRUE; 37 any = true;
38 tmp = pattern; 38 tmp = pattern;
39 break; 39 break;
40 40
41 case 0: 41 case 0:
42 if (any) 42 if (any)
43 { 43 {
44 if (*haystack) 44 if (*haystack)
45 haystack++; 45 haystack++;
46 else 46 else
47 end = TRUE; 47 end = true;
48 } 48 }
49 else 49 else
50 if (*haystack) 50 if (*haystack)
51 { 51 {
52 if (tmp) 52 if (tmp)
53 { 53 {
54 any = TRUE; 54 any = true;
55 pattern = tmp; 55 pattern = tmp;
56 } 56 }
57 else 57 else
58 matched = FALSE; 58 matched = false;
59 } 59 }
60 else 60 else
61 end = TRUE; 61 end = true;
62 break; 62 break;
63 63
64 default: 64 default:
65 { 65 {
66 BOOL equals = TH_STRGLOB_COLLATE(*pattern) == TH_STRGLOB_COLLATE(*haystack); 66 bool equals = TH_STRGLOB_COLLATE(*pattern) == TH_STRGLOB_COLLATE(*haystack);
67 if (any) 67 if (any)
68 { 68 {
69 if (equals) 69 if (equals)
70 { 70 {
71 any = FALSE; 71 any = false;
72 } 72 }
73 else 73 else
74 if (*haystack) 74 if (*haystack)
75 haystack++; 75 haystack++;
76 else 76 else
77 matched = FALSE; 77 matched = false;
78 } 78 }
79 else 79 else
80 { 80 {
81 if (equals) 81 if (equals)
82 { 82 {
86 haystack++; 86 haystack++;
87 } 87 }
88 else 88 else
89 if (tmp) 89 if (tmp)
90 { 90 {
91 any = TRUE; 91 any = true;
92 pattern = tmp; 92 pattern = tmp;
93 } 93 }
94 else 94 else
95 matched = FALSE; 95 matched = false;
96 } 96 }
97 97
98 if (!*haystack && !*pattern) 98 if (!*haystack && !*pattern)
99 end = TRUE; 99 end = true;
100 } 100 }
101 break; 101 break;
102 } 102 }
103 103
104 return matched; 104 return matched;