summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoão Antônio Cardoso <joao.maker@gmail.com>2020-04-15 15:39:50 -0300
committerFelipe Magno de Almeida <felipe@expertise.dev>2020-05-04 22:28:13 -0300
commit64964ed930ada3554fbf651940c09b3a77a8a6a2 (patch)
tree11f8ebf34a12c42c0d9842d84c6135e688043ba1
parentcb1b57ec6a51faf029b1441713e2b357585436f0 (diff)
windows: Add fnmatch win32 implementation
-rw-r--r--src/bin/edje/edje_external_inspector.c6
-rw-r--r--src/bin/edje/edje_inspector.c4
-rw-r--r--src/lib/ecore_x/ecore_x_vsync.c4
-rw-r--r--src/lib/eet/eet_lib.c3
-rw-r--r--src/lib/efreet/efreet_mime.c6
-rw-r--r--src/lib/efreet/efreet_utils.c4
-rw-r--r--src/lib/eina/Eina.h1
-rw-r--r--src/lib/eina/eina_fnmatch.c249
-rw-r--r--src/lib/eina/eina_fnmatch.h37
-rw-r--r--src/lib/eina/eina_log.c6
-rw-r--r--src/lib/eina/eina_main.c1
-rw-r--r--src/lib/eina/meson.build6
-rw-r--r--src/lib/elementary/Efl_Ui.h2
-rw-r--r--src/lib/elementary/Elementary.h1
-rw-r--r--src/lib/elementary/elm_gengrid.c8
-rw-r--r--src/lib/elementary/elm_genlist.c10
-rw-r--r--src/lib/embryo/embryo_str.c4
-rw-r--r--src/lib/eo/eo_base_class.c3
-rw-r--r--src/lib/evas/canvas/evas_font_dir.c4
-rw-r--r--src/lib/evas/file/evas_path.c4
-rw-r--r--src/lib/evil/unposix/fnmatch.h23
-rw-r--r--src/lib/evil/unposix/meson.build5
-rw-r--r--src/tests/eina/eina_fnmatch_test.c174
-rwxr-xr-xsrc/tests/eina/eina_fnmatch_test.sh63
-rw-r--r--src/tests/evil/unposix/eina_fnmatch_test.c172
25 files changed, 736 insertions, 64 deletions
diff --git a/src/bin/edje/edje_external_inspector.c b/src/bin/edje/edje_external_inspector.c
index 3a4f937b06..1ab0383778 100644
--- a/src/bin/edje/edje_external_inspector.c
+++ b/src/bin/edje/edje_external_inspector.c
@@ -3,7 +3,7 @@
3#endif 3#endif
4 4
5#include <locale.h> 5#include <locale.h>
6#include <fnmatch.h> 6#include <Eina.h>
7 7
8#include <Ecore.h> 8#include <Ecore.h>
9#include <Ecore_Getopt.h> 9#include <Ecore_Getopt.h>
@@ -56,7 +56,7 @@ module_matches(const char *name)
56 if (!module_patterns) return EINA_TRUE; 56 if (!module_patterns) return EINA_TRUE;
57 57
58 for (itr = module_patterns; *itr != NULL; itr++) 58 for (itr = module_patterns; *itr != NULL; itr++)
59 if (fnmatch(*itr, name, 0) == 0) return EINA_TRUE; 59 if (eina_fnmatch(*itr, name, 0) == 0) return EINA_TRUE;
60 60
61 return EINA_FALSE; 61 return EINA_FALSE;
62} 62}
@@ -65,7 +65,7 @@ static inline Eina_Bool
65type_matches(const char *name) 65type_matches(const char *name)
66{ 66{
67 if (!type_glob) return EINA_TRUE; 67 if (!type_glob) return EINA_TRUE;
68 return fnmatch(type_glob, name, 0) == 0; 68 return eina_fnmatch(type_glob, name, 0) == 0;
69} 69}
70 70
71static int 71static int
diff --git a/src/bin/edje/edje_inspector.c b/src/bin/edje/edje_inspector.c
index 25024cee73..8e39a56081 100644
--- a/src/bin/edje/edje_inspector.c
+++ b/src/bin/edje/edje_inspector.c
@@ -3,7 +3,7 @@
3#endif 3#endif
4 4
5#include <locale.h> 5#include <locale.h>
6#include <fnmatch.h> 6#include <Eina.h>
7#include <unistd.h> 7#include <unistd.h>
8#include <errno.h> 8#include <errno.h>
9 9
@@ -101,7 +101,7 @@ static inline Eina_Bool
101matches(const char *name, const char *pattern) 101matches(const char *name, const char *pattern)
102{ 102{
103 if (!pattern) return EINA_TRUE; 103 if (!pattern) return EINA_TRUE;
104 return fnmatch(pattern, name, 0) == 0; 104 return eina_fnmatch(pattern, name, 0) == 0;
105} 105}
106 106
107static void 107static void
diff --git a/src/lib/ecore_x/ecore_x_vsync.c b/src/lib/ecore_x/ecore_x_vsync.c
index e002e48302..79f5892007 100644
--- a/src/lib/ecore_x/ecore_x_vsync.c
+++ b/src/lib/ecore_x/ecore_x_vsync.c
@@ -15,7 +15,7 @@
15#include <sys/stat.h> 15#include <sys/stat.h>
16#include <sys/select.h> 16#include <sys/select.h>
17#include <fcntl.h> 17#include <fcntl.h>
18#include <fnmatch.h> 18#include <Eina.h>
19 19
20#ifdef HAVE_PRCTL 20#ifdef HAVE_PRCTL
21# include <sys/prctl.h> 21# include <sys/prctl.h>
@@ -457,7 +457,7 @@ glob_match(const char *glob, const char *str)
457{ 457{
458 if (!glob) return EINA_TRUE; 458 if (!glob) return EINA_TRUE;
459 if (!str) return EINA_FALSE; 459 if (!str) return EINA_FALSE;
460 if (!fnmatch(glob, str, 0)) return EINA_TRUE; 460 if (!eina_fnmatch(glob, str, 0)) return EINA_TRUE;
461 return EINA_FALSE; 461 return EINA_FALSE;
462} 462}
463 463
diff --git a/src/lib/eet/eet_lib.c b/src/lib/eet/eet_lib.c
index 0e05b2acaf..957ad95035 100644
--- a/src/lib/eet/eet_lib.c
+++ b/src/lib/eet/eet_lib.c
@@ -9,7 +9,6 @@
9#include <time.h> 9#include <time.h>
10#include <string.h> 10#include <string.h>
11#include <unistd.h> 11#include <unistd.h>
12#include <fnmatch.h>
13#include <fcntl.h> 12#include <fcntl.h>
14 13
15#include <Eina.h> 14#include <Eina.h>
@@ -2607,7 +2606,7 @@ eet_list(Eet_File *ef,
2607 * check for * explicitly, because on some systems, * isn't well 2606 * check for * explicitly, because on some systems, * isn't well
2608 * supported 2607 * supported
2609 */ 2608 */
2610 if ((!glob) || !fnmatch(glob, efn->name, 0)) 2609 if ((!glob) || !eina_fnmatch(glob, efn->name, 0))
2611 { 2610 {
2612 /* add it to our list */ 2611 /* add it to our list */
2613 list_count++; 2612 list_count++;
diff --git a/src/lib/efreet/efreet_mime.c b/src/lib/efreet/efreet_mime.c
index 9eba8c8db9..b936439635 100644
--- a/src/lib/efreet/efreet_mime.c
+++ b/src/lib/efreet/efreet_mime.c
@@ -6,7 +6,7 @@
6#include <sys/stat.h> 6#include <sys/stat.h>
7#include <fcntl.h> 7#include <fcntl.h>
8#include <unistd.h> 8#include <unistd.h>
9#include <fnmatch.h> 9#include <Eina.h>
10 10
11#include <Ecore.h> 11#include <Ecore.h>
12#include <Ecore_File.h> 12#include <Ecore_File.h>
@@ -1243,7 +1243,7 @@ efreet_mime_glob_match(const char *str, const char *glob)
1243 if (str[0] == 0) return 1; 1243 if (str[0] == 0) return 1;
1244 return 0; 1244 return 0;
1245 } 1245 }
1246 if (!fnmatch(glob, str, 0)) return 1; 1246 if (!eina_fnmatch(glob, str, 0)) return 1;
1247 return 0; 1247 return 0;
1248} 1248}
1249 1249
@@ -1269,7 +1269,7 @@ efreet_mime_glob_case_match(char *str, const char *glob)
1269 tglob = alloca(strlen(glob) + 1); 1269 tglob = alloca(strlen(glob) + 1);
1270 for (tp = tglob, p = glob; *p; p++, tp++) *tp = tolower(*p); 1270 for (tp = tglob, p = glob; *p; p++, tp++) *tp = tolower(*p);
1271 *tp = 0; 1271 *tp = 0;
1272 if (!fnmatch(str, tglob, 0)) return 1; 1272 if (!eina_fnmatch(str, tglob, 0)) return 1;
1273 return 0; 1273 return 0;
1274} 1274}
1275 1275
diff --git a/src/lib/efreet/efreet_utils.c b/src/lib/efreet/efreet_utils.c
index e1cafaaf89..2e51d6dcff 100644
--- a/src/lib/efreet/efreet_utils.c
+++ b/src/lib/efreet/efreet_utils.c
@@ -4,7 +4,7 @@
4 4
5/* TODO: add no_display check, as we might want only displayable items */ 5/* TODO: add no_display check, as we might want only displayable items */
6 6
7#include <fnmatch.h> 7#include <Eina.h>
8#include <ctype.h> 8#include <ctype.h>
9 9
10#include <Ecore_File.h> 10#include <Ecore_File.h>
@@ -450,7 +450,7 @@ efreet_util_glob_match(const char *str, const char *glob)
450 return 0; 450 return 0;
451 } 451 }
452 if (!strcmp(glob, "*")) return 1; 452 if (!strcmp(glob, "*")) return 1;
453 if (!fnmatch(glob, str, 0)) return 1; 453 if (!eina_fnmatch(glob, str, 0)) return 1;
454 return 0; 454 return 0;
455} 455}
456 456
diff --git a/src/lib/eina/Eina.h b/src/lib/eina/Eina.h
index 383696d7d8..821c55f40d 100644
--- a/src/lib/eina/Eina.h
+++ b/src/lib/eina/Eina.h
@@ -277,6 +277,7 @@ extern "C" {
277#include <eina_promise.h> 277#include <eina_promise.h>
278#include <eina_vpath.h> 278#include <eina_vpath.h>
279#include <eina_abstract_content.h> 279#include <eina_abstract_content.h>
280#include <eina_fnmatch.h>
280 281
281 282
282#ifdef __cplusplus 283#ifdef __cplusplus
diff --git a/src/lib/eina/eina_fnmatch.c b/src/lib/eina/eina_fnmatch.c
new file mode 100644
index 0000000000..eae287fc22
--- /dev/null
+++ b/src/lib/eina/eina_fnmatch.c
@@ -0,0 +1,249 @@
1#include "eina_fnmatch.h"
2
3#include <stdlib.h>
4#include <errno.h>
5#include <string.h>
6#include <pcreposix.h>
7
8inline static int
9_is_escapable(char c)
10{
11 switch (c)
12 {
13 case '[': case '|': case '(': case ')': case '*': case '?':
14 case '!': case '^': case '$': case '.': case '+': case '\\':
15 return 1;
16 default:
17 return 0;
18 }
19}
20
21inline static char *
22_wildcards_to_regex(const char *pattern, int flags)
23{
24
25 // Counts how many additional chars needs to be allocated
26 int pattern_length = strlen(pattern);
27 int count = 2; // starts with '^' and ends with '$'
28 for (int j = 0; j < pattern_length; ++j)
29 {
30 if (pattern[j] == '\\')
31 {
32 if (flags & FNM_NOESCAPE) count++;
33 else count += 2;
34 }
35 else if ((pattern[j] == '*') || (pattern[j] == '?'))
36 {
37 if (flags & FNM_PATHNAME)
38 {
39 if (flags & FNM_PERIOD) // PATHNAME + PERIOD
40 {
41 if (pattern[j] == '*')
42 {
43 if (j == 0) count += 10;
44 else if (pattern[j - 1] == '/') count += 10;
45 else count += 5;
46 }
47 else if ((j == 0) || (pattern[j - 1] == '/')) count += 10;
48 else count += 4;
49 }
50 else if (pattern[j] == '*') count += 5; // PATHNAME
51 else count += 4;
52 }
53 else if (flags & FNM_PERIOD)
54 {
55 if (j == 0) // period at init
56 {
57 if (pattern[j] == '*') count += 5;
58 else count += 4;
59 }
60 // period at other places
61 else if (pattern[j] == '*') count += 2;
62 else count++;
63 }
64 else if (pattern[j] == '*') count += 2; // NORMAL
65 else count++;
66 }
67 else if (pattern[j] == '.') count += 4;
68 else count++; // OTHERS
69 }
70
71 int reg_length = pattern_length + count;
72
73 // Translates wildcards to regex
74 char *reg_pattern = (char *)malloc(reg_length * sizeof(char));
75 if (reg_pattern == NULL) exit(ENOMEM);
76 reg_pattern[0] = '^';
77 int i = 1;
78 for (int j = 0; j < pattern_length; ++j)
79 {
80 if (pattern[j] == '\\')
81 {
82 if (flags & FNM_NOESCAPE)
83 reg_pattern[i++] = '/';
84 else if (_is_escapable(pattern[j + 1]))
85 {
86 reg_pattern[i++] = '\\';
87 reg_pattern[i++] = pattern[++j];
88 }
89 else
90 {
91 reg_pattern[i++] = '\\';
92 reg_pattern[i++] = '/';
93 }
94 }
95 else if ((pattern[j] == '*') || (pattern[j] == '?'))
96 {
97 if (flags & FNM_PATHNAME)
98 {
99 if (flags & FNM_PERIOD) // PATHNAME + PERIOD
100 {
101 if (pattern[j] == '*')
102 {
103 if ( (j == 0) || (pattern[j - 1] == '/') )
104 {
105 strcpy_s(reg_pattern + i,
106 sizeof(reg_pattern + i),
107 "[^\\.][^/]*");
108 i += 10;
109 }
110 else
111 {
112 strcpy_s(reg_pattern + i,
113 sizeof(reg_pattern + i),
114 "[^/]*");
115 i += 5;
116 }
117 }
118 else if (j == 0)
119 {
120 strcpy_s(reg_pattern + i,
121 sizeof(reg_pattern + i),
122 "[^\\.][^/]?");
123 i += 10;
124 }
125 else if (pattern[j - 1] == '/')
126 {
127 strcpy_s(reg_pattern + i,
128 sizeof(reg_pattern + i),
129 "[^\\.][^/]?");
130 i += 10;
131 }
132 else
133 {
134 strcpy_s(reg_pattern + i,
135 sizeof(reg_pattern + i),
136 "[^/]");
137 i += 4;
138 }
139 }
140 else if (pattern[j] == '*') // PATHNAME
141 {
142 strcpy_s(reg_pattern + i,
143 sizeof(reg_pattern + i),
144 "[^/]*");
145 i += 5;
146 }
147 else
148 {
149 strcpy_s(reg_pattern + i,
150 sizeof(reg_pattern + i),
151 "[^/]");
152 i += 4;
153 }
154 }
155 else if (flags & FNM_PERIOD)
156 {
157 if (j == 0) // period at init
158 {
159 if (pattern[j] == '*')
160 {
161 strcpy_s(reg_pattern + i,
162 sizeof(reg_pattern + i),
163 "[\\.]*");
164 i += 5;
165 }
166 else
167 {
168 strcpy_s(reg_pattern + i,
169 sizeof(reg_pattern + i),
170 "[\\.]");
171 i += 4;
172 }
173 }
174 else if (pattern[j] == '*') // period at other places
175 {
176 strcpy_s(reg_pattern + i,
177 sizeof(reg_pattern + i),
178 ".*");
179 i += 2;
180 }
181 else
182 reg_pattern[i++] = '.';
183 }
184 else if (pattern[j] == '*') // NORMAL
185 {
186 strcpy_s(reg_pattern + i,
187 sizeof(reg_pattern + i),
188 ".*");
189 i += 2;
190 }
191 else
192 {
193 strcpy_s(reg_pattern + i,
194 sizeof(reg_pattern + i),
195 ".");
196 i++;
197 }
198 }
199 else if (pattern[j] == '.')
200 {
201 strcpy_s(reg_pattern + i,
202 sizeof(reg_pattern + i),
203 "[\\.]");
204 i += 4;
205 }
206 else reg_pattern[i++] = pattern[j]; // OTHERS
207 }
208 strcpy_s(reg_pattern + i,
209 sizeof(reg_pattern + i),
210 "$\0");
211
212 return reg_pattern;
213}
214
215int
216eina_fnmatch(const char *pattern, const char *string, int flags)
217{
218 // Converts wildcard pattern to regex pattern
219 char *reg_pattern = _wildcards_to_regex(pattern, flags);
220
221 // Configures regex
222 int regex_flags = (REG_NOSUB) // Report only success/fail in regexec()
223 || ((flags & FNM_CASEFOLD) ? REG_ICASE : 0);
224
225 // Compiles regex
226 regex_t regex;
227 if (regcomp(&regex, reg_pattern, regex_flags))
228 {
229 regfree(&regex);
230 return FNM_NOMATCH;
231 }
232
233 // Replaces '\\' with '/'
234 int string_length = strlen(string);
235 char *unix_path = (char *)malloc(string_length * sizeof(char));
236 if (unix_path == NULL) exit(ENOMEM);
237 unix_path[string_length] = '\0';
238 for (int i = 0; i < string_length; ++i)
239 unix_path[i] = (string[i] == '\\') ? '/' : string[i];
240
241 // Executes regex
242 int result = regexec(&regex, unix_path, 0, NULL, 0);
243
244 // Cleans-up and returns
245 free(unix_path);
246 free(reg_pattern);
247 regfree(&regex);
248 return result ? FNM_NOMATCH : 0;
249}
diff --git a/src/lib/eina/eina_fnmatch.h b/src/lib/eina/eina_fnmatch.h
new file mode 100644
index 0000000000..3450258ebb
--- /dev/null
+++ b/src/lib/eina/eina_fnmatch.h
@@ -0,0 +1,37 @@
1#ifndef EINA_FNMATCH_H
2#define EINA_FNMATCH_H
3
4#ifdef __cplusplus
5extern "C"
6{
7#endif
8
9#ifdef _WIN32
10
11/* Bits set in the FLAGS argument to `fnmatch'. */
12#define FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */
13#define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */
14#define FNM_PERIOD (1 << 2) /* Leading `.' is matched only explicitly. */
15
16#define FNM_FILE_NAME FNM_PATHNAME /* Preferred GNU name. */
17#define FNM_LEADING_DIR (1 << 3) /* Ignore `/...' after a match. */
18#define FNM_CASEFOLD (1 << 4) /* Compare without regard to case. */
19
20/* Value returned by `fnmatch' if STRING does not match PATTERN. */
21#define FNM_NOMATCH 1
22
23int eina_fnmatch(const char *pattern, const char *string, int flags);
24
25#else /* _WIN32 */
26
27//#define eina_fnmatch(a,b,c) fnmatch(a,b,c)
28#include <fnmatch.h>
29#define eina_fnmatch fnmatch
30
31#endif /* _WIN32 */
32
33#ifdef __cplusplus
34}
35#endif
36
37#endif /* EINA_FNMATCH_H */
diff --git a/src/lib/eina/eina_log.c b/src/lib/eina/eina_log.c
index 8cea3e9ebe..2768b16e24 100644
--- a/src/lib/eina/eina_log.c
+++ b/src/lib/eina/eina_log.c
@@ -25,7 +25,6 @@
25#include <string.h> 25#include <string.h>
26#include <stdlib.h> 26#include <stdlib.h>
27#include <unistd.h> 27#include <unistd.h>
28#include <fnmatch.h>
29#include <assert.h> 28#include <assert.h>
30#include <errno.h> 29#include <errno.h>
31 30
@@ -51,6 +50,7 @@
51#include "eina_thread.h" 50#include "eina_thread.h"
52#include "eina_convert.h" 51#include "eina_convert.h"
53#include "eina_strbuf.h" 52#include "eina_strbuf.h"
53#include "eina_fnmatch.h"
54 54
55/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */ 55/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
56#include "eina_safety_checks.h" 56#include "eina_safety_checks.h"
@@ -1280,7 +1280,7 @@ finish_register:
1280 { 1280 {
1281 EINA_INLIST_FOREACH(_glob_list, pending) 1281 EINA_INLIST_FOREACH(_glob_list, pending)
1282 { 1282 {
1283 if (!fnmatch(pending->name, name, 0)) 1283 if (!eina_fnmatch(pending->name, name, 0))
1284 { 1284 {
1285 _log_domains[i].level = pending->level; 1285 _log_domains[i].level = pending->level;
1286 break; 1286 break;
@@ -1996,7 +1996,7 @@ eina_log_domain_level_get(const char *domain_name)
1996 1996
1997 EINA_INLIST_FOREACH(_glob_list, pending) 1997 EINA_INLIST_FOREACH(_glob_list, pending)
1998 { 1998 {
1999 if (!fnmatch(pending->name, domain_name, 0)) 1999 if (!eina_fnmatch(pending->name, domain_name, 0))
2000 return pending->level; 2000 return pending->level;
2001 } 2001 }
2002 2002
diff --git a/src/lib/eina/eina_main.c b/src/lib/eina/eina_main.c
index 252b7f6465..f8e2094058 100644
--- a/src/lib/eina/eina_main.c
+++ b/src/lib/eina/eina_main.c
@@ -67,6 +67,7 @@
67#include "eina_slstr.h" 67#include "eina_slstr.h"
68#include "eina_vpath.h" 68#include "eina_vpath.h"
69#include "eina_thread.h" 69#include "eina_thread.h"
70#include "eina_fnmatch.h"
70 71
71/*============================================================================* 72/*============================================================================*
72* Local * 73* Local *
diff --git a/src/lib/eina/meson.build b/src/lib/eina/meson.build
index 83c38bb51c..d20513e544 100644
--- a/src/lib/eina/meson.build
+++ b/src/lib/eina/meson.build
@@ -1,7 +1,7 @@
1if not sys_windows 1if not sys_windows
2 eina_deps = [dl] 2 eina_deps = [dl]
3else 3else
4 eina_deps = [] 4 eina_deps = [pcre_dep]
5endif 5endif
6eina_pub_deps = [thread_dep] 6eina_pub_deps = [thread_dep]
7 7
@@ -109,7 +109,8 @@ public_sub_headers = [
109'eina_freeq.h', 109'eina_freeq.h',
110'eina_slstr.h', 110'eina_slstr.h',
111'eina_vpath.h', 111'eina_vpath.h',
112'eina_abstract_content.h' 112'eina_abstract_content.h',
113'eina_fnmatch.h'
113] 114]
114 115
115public_headers = [ 116public_headers = [
@@ -199,6 +200,7 @@ if sys_windows == true
199 public_sub_headers += 'eina_inline_thread_win32.x' 200 public_sub_headers += 'eina_inline_thread_win32.x'
200 sources += 'eina_file_win32.c' 201 sources += 'eina_file_win32.c'
201 sources += 'eina_sched_win32.c' 202 sources += 'eina_sched_win32.c'
203 sources += 'eina_fnmatch.c'
202 public_sub_headers += 'eina_inline_lock_win32.x' 204 public_sub_headers += 'eina_inline_lock_win32.x'
203else 205else
204 public_sub_headers += 'eina_thread_posix.h' 206 public_sub_headers += 'eina_thread_posix.h'
diff --git a/src/lib/elementary/Efl_Ui.h b/src/lib/elementary/Efl_Ui.h
index ffc5fd43c5..dbdbbfef15 100644
--- a/src/lib/elementary/Efl_Ui.h
+++ b/src/lib/elementary/Efl_Ui.h
@@ -14,7 +14,7 @@
14#include <sys/time.h> 14#include <sys/time.h>
15#include <sys/param.h> 15#include <sys/param.h>
16#include <math.h> 16#include <math.h>
17#include <fnmatch.h> 17#include <Eina.h>
18#include <limits.h> 18#include <limits.h>
19#include <ctype.h> 19#include <ctype.h>
20#include <time.h> 20#include <time.h>
diff --git a/src/lib/elementary/Elementary.h b/src/lib/elementary/Elementary.h
index c83481a9fd..7e02bcb40b 100644
--- a/src/lib/elementary/Elementary.h
+++ b/src/lib/elementary/Elementary.h
@@ -20,7 +20,6 @@
20#include <sys/time.h> 20#include <sys/time.h>
21#include <sys/param.h> 21#include <sys/param.h>
22#include <math.h> 22#include <math.h>
23#include <fnmatch.h>
24#include <limits.h> 23#include <limits.h>
25#include <ctype.h> 24#include <ctype.h>
26#include <time.h> 25#include <time.h>
diff --git a/src/lib/elementary/elm_gengrid.c b/src/lib/elementary/elm_gengrid.c
index 8a5bccaa2f..3ed443a099 100644
--- a/src/lib/elementary/elm_gengrid.c
+++ b/src/lib/elementary/elm_gengrid.c
@@ -433,7 +433,7 @@ _elm_gengrid_search_by_text_item_get(Eo *obj EINA_UNUSED,
433 str = it->itc->func.text_get((void *)WIDGET_ITEM_DATA_GET(EO_OBJ(it)), 433 str = it->itc->func.text_get((void *)WIDGET_ITEM_DATA_GET(EO_OBJ(it)),
434 WIDGET(it), part_name ? part_name : "elm.text"); 434 WIDGET(it), part_name ? part_name : "elm.text");
435 if (!str) continue; 435 if (!str) continue;
436 if (!fnmatch(pattern, str, fnflags)) 436 if (!eina_fnmatch(pattern, str, fnflags))
437 { 437 {
438 free(str); 438 free(str);
439 return EO_OBJ(it); 439 return EO_OBJ(it);
@@ -1019,7 +1019,7 @@ _item_text_realize(Elm_Gen_Item *it,
1019 (edje_object_data_get(target, "texts")); 1019 (edje_object_data_get(target, "texts"));
1020 EINA_LIST_FOREACH(*source, l, key) 1020 EINA_LIST_FOREACH(*source, l, key)
1021 { 1021 {
1022 if (parts && fnmatch(parts, key, FNM_PERIOD)) continue; 1022 if (parts && eina_fnmatch(parts, key, FNM_PERIOD)) continue;
1023 1023
1024 s = it->itc->func.text_get 1024 s = it->itc->func.text_get
1025 ((void *)WIDGET_ITEM_DATA_GET(EO_OBJ(it)), WIDGET(it), key); 1025 ((void *)WIDGET_ITEM_DATA_GET(EO_OBJ(it)), WIDGET(it), key);
@@ -1068,7 +1068,7 @@ _item_content_realize(Elm_Gen_Item *it,
1068 1068
1069 EINA_LIST_FREE(source, key) 1069 EINA_LIST_FREE(source, key)
1070 { 1070 {
1071 if (parts && fnmatch(parts, key, FNM_PERIOD)) 1071 if (parts && eina_fnmatch(parts, key, FNM_PERIOD))
1072 continue; 1072 continue;
1073 1073
1074 Evas_Object *old = edje_object_part_swallow_get(target, key); 1074 Evas_Object *old = edje_object_part_swallow_get(target, key);
@@ -1135,7 +1135,7 @@ _item_state_realize(Elm_Gen_Item *it, Evas_Object *target, const char *parts)
1135 src = elm_widget_stringlist_get(edje_object_data_get(target, "states")); 1135 src = elm_widget_stringlist_get(edje_object_data_get(target, "states"));
1136 EINA_LIST_FREE(src, key) 1136 EINA_LIST_FREE(src, key)
1137 { 1137 {
1138 if (parts && fnmatch(parts, key, FNM_PERIOD)) continue; 1138 if (parts && eina_fnmatch(parts, key, FNM_PERIOD)) continue;
1139 1139
1140 Eina_Bool on = it->itc->func.state_get 1140 Eina_Bool on = it->itc->func.state_get
1141 ((void *)WIDGET_ITEM_DATA_GET(EO_OBJ(it)), WIDGET(it), key); 1141 ((void *)WIDGET_ITEM_DATA_GET(EO_OBJ(it)), WIDGET(it), key);
diff --git a/src/lib/elementary/elm_genlist.c b/src/lib/elementary/elm_genlist.c
index 5da1517fc8..5841f28253 100644
--- a/src/lib/elementary/elm_genlist.c
+++ b/src/lib/elementary/elm_genlist.c
@@ -2,7 +2,7 @@
2# include "elementary_config.h" 2# include "elementary_config.h"
3#endif 3#endif
4 4
5#include <fnmatch.h> 5#include <Eina.h>
6 6
7#define EFL_ACCESS_OBJECT_PROTECTED 7#define EFL_ACCESS_OBJECT_PROTECTED
8#define EFL_ACCESS_SELECTION_PROTECTED 8#define EFL_ACCESS_SELECTION_PROTECTED
@@ -347,7 +347,7 @@ _item_text_realize(Elm_Gen_Item *it,
347 (edje_object_data_get(target, "texts")); 347 (edje_object_data_get(target, "texts"));
348 EINA_LIST_FOREACH(*source, l, key) 348 EINA_LIST_FOREACH(*source, l, key)
349 { 349 {
350 if (parts && fnmatch(parts, key, FNM_PERIOD)) continue; 350 if (parts && eina_fnmatch(parts, key, FNM_PERIOD)) continue;
351 351
352 s = it->itc->func.text_get 352 s = it->itc->func.text_get
353 ((void *)WIDGET_ITEM_DATA_GET(EO_OBJ(it)), WIDGET(it), key); 353 ((void *)WIDGET_ITEM_DATA_GET(EO_OBJ(it)), WIDGET(it), key);
@@ -423,7 +423,7 @@ _item_content_realize(Elm_Gen_Item *it,
423 423
424 EINA_LIST_FREE(source, key) 424 EINA_LIST_FREE(source, key)
425 { 425 {
426 if (parts && fnmatch(parts, key, FNM_PERIOD)) 426 if (parts && eina_fnmatch(parts, key, FNM_PERIOD))
427 continue; 427 continue;
428 428
429 Evas_Object *old = NULL; 429 Evas_Object *old = NULL;
@@ -505,7 +505,7 @@ _item_state_realize(Elm_Gen_Item *it, Evas_Object *target, const char *parts)
505 src = elm_widget_stringlist_get(edje_object_data_get(target, "states")); 505 src = elm_widget_stringlist_get(edje_object_data_get(target, "states"));
506 EINA_LIST_FREE(src, key) 506 EINA_LIST_FREE(src, key)
507 { 507 {
508 if (parts && fnmatch(parts, key, FNM_PERIOD)) continue; 508 if (parts && eina_fnmatch(parts, key, FNM_PERIOD)) continue;
509 509
510 Eina_Bool on = it->itc->func.state_get 510 Eina_Bool on = it->itc->func.state_get
511 ((void *)WIDGET_ITEM_DATA_GET(EO_OBJ(it)), WIDGET(it), key); 511 ((void *)WIDGET_ITEM_DATA_GET(EO_OBJ(it)), WIDGET(it), key);
@@ -8746,7 +8746,7 @@ _elm_genlist_search_by_text_item_get(Eo *obj EINA_UNUSED,
8746 if (!it->itc->func.text_get) continue; 8746 if (!it->itc->func.text_get) continue;
8747 str = it->itc->func.text_get((void *)WIDGET_ITEM_DATA_GET(EO_OBJ(it)), WIDGET(it), part_name); 8747 str = it->itc->func.text_get((void *)WIDGET_ITEM_DATA_GET(EO_OBJ(it)), WIDGET(it), part_name);
8748 if (!str) continue; 8748 if (!str) continue;
8749 if (!fnmatch(pattern, str, fnflags)) 8749 if (!eina_fnmatch(pattern, str, fnflags))
8750 { 8750 {
8751 free(str); 8751 free(str);
8752 return EO_OBJ(it); 8752 return EO_OBJ(it);
diff --git a/src/lib/embryo/embryo_str.c b/src/lib/embryo/embryo_str.c
index d7da4e0dd3..dc1940414b 100644
--- a/src/lib/embryo/embryo_str.c
+++ b/src/lib/embryo/embryo_str.c
@@ -14,7 +14,7 @@
14#include <stdlib.h> 14#include <stdlib.h>
15#include <stdio.h> 15#include <stdio.h>
16#include <string.h> 16#include <string.h>
17#include <fnmatch.h> 17#include <Eina.h>
18 18
19#include "Embryo.h" 19#include "Embryo.h"
20#include "embryo_private.h" 20#include "embryo_private.h"
@@ -59,7 +59,7 @@ _embryo_str_fnmatch(Embryo_Program *ep, Embryo_Cell *params)
59 STRGET(ep, s1, params[1]); 59 STRGET(ep, s1, params[1]);
60 STRGET(ep, s2, params[2]); 60 STRGET(ep, s2, params[2]);
61 if ((!s1) || (!s2)) return -1; 61 if ((!s1) || (!s2)) return -1;
62 return (Embryo_Cell)fnmatch(s1, s2, 0); 62 return (Embryo_Cell)eina_fnmatch(s1, s2, 0);
63} 63}
64 64
65static Embryo_Cell 65static Embryo_Cell
diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c
index 44fe92cf4a..cf21aedc4e 100644
--- a/src/lib/eo/eo_base_class.c
+++ b/src/lib/eo/eo_base_class.c
@@ -3,7 +3,6 @@
3#endif 3#endif
4 4
5#include <Eina.h> 5#include <Eina.h>
6#include <fnmatch.h>
7 6
8#include <Eo.h> 7#include <Eo.h>
9 8
@@ -544,7 +543,7 @@ _name_match(const char *match, Eina_Bool is_glob, const char *str)
544 // if match string is "*" special case it and match 543 // if match string is "*" special case it and match
545 if ((match[0] == '*') && (match[1] == 0)) return EINA_TRUE; 544 if ((match[0] == '*') && (match[1] == 0)) return EINA_TRUE;
546 // actual compare 545 // actual compare
547 if (!fnmatch(match, str, 0)) return EINA_TRUE; 546 if (!eina_fnmatch(match, str, 0)) return EINA_TRUE;
548 } 547 }
549 else 548 else
550 { 549 {
diff --git a/src/lib/evas/canvas/evas_font_dir.c b/src/lib/evas/canvas/evas_font_dir.c
index 5b945dcb27..83a9bdcb67 100644
--- a/src/lib/evas/canvas/evas_font_dir.c
+++ b/src/lib/evas/canvas/evas_font_dir.c
@@ -65,7 +65,7 @@ static FcConfig *fc_config = NULL;
65 65
66/* FIXME move these helper function to eina_file or eina_path */ 66/* FIXME move these helper function to eina_file or eina_path */
67/* get the casefold feature! */ 67/* get the casefold feature! */
68#include <fnmatch.h> 68#include <Eina.h>
69#include <unistd.h> 69#include <unistd.h>
70#include <sys/param.h> 70#include <sys/param.h>
71int 71int
@@ -115,7 +115,7 @@ _file_path_list(char *path, const char *match, int match_case)
115 { 115 {
116 if (match) 116 if (match)
117 { 117 {
118 if (fnmatch(match, info->path + info->name_start, flags) == 0) 118 if (eina_fnmatch(match, info->path + info->name_start, flags) == 0)
119 files = eina_list_append(files, strdup(info->path + info->name_start)); 119 files = eina_list_append(files, strdup(info->path + info->name_start));
120 } 120 }
121 else 121 else
diff --git a/src/lib/evas/file/evas_path.c b/src/lib/evas/file/evas_path.c
index ef3d439018..d064b04401 100644
--- a/src/lib/evas/file/evas_path.c
+++ b/src/lib/evas/file/evas_path.c
@@ -12,7 +12,7 @@
12#include <sys/types.h> 12#include <sys/types.h>
13#include <sys/stat.h> 13#include <sys/stat.h>
14/* get the casefold feature! */ 14/* get the casefold feature! */
15#include <fnmatch.h> 15#include <Eina.h>
16#include <unistd.h> 16#include <unistd.h>
17#include <sys/param.h> 17#include <sys/param.h>
18 18
@@ -114,7 +114,7 @@ evas_file_path_list(char *path, const char *match, int match_case)
114 { 114 {
115 if (match) 115 if (match)
116 { 116 {
117 if (fnmatch(match, info->path + info->name_start, flags) == 0) 117 if (eina_fnmatch(match, info->path + info->name_start, flags) == 0)
118 files = eina_list_append(files, strdup(info->path + info->name_start)); 118 files = eina_list_append(files, strdup(info->path + info->name_start));
119 } 119 }
120 else 120 else
diff --git a/src/lib/evil/unposix/fnmatch.h b/src/lib/evil/unposix/fnmatch.h
deleted file mode 100644
index a1442121ff..0000000000
--- a/src/lib/evil/unposix/fnmatch.h
+++ /dev/null
@@ -1,23 +0,0 @@
1#ifndef UNPOSIX_FNMATCH_H
2#define UNPOSIX_FNMATCH_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8// The string does not match the specified pattern.
9#define FNM_NOMATCH 1
10// <slash> in string only matches <slash> in pattern.
11#define FNM_PATHNAME (1 << 0)
12// Disable backslash escaping.
13#define FNM_NOESCAPE (1 << 1)
14// Leading <period> in string must be exactly matched by <period> in pattern.
15#define FNM_PERIOD (1 << 2)
16
17int fnmatch(const char *, const char *, int);
18
19#ifdef __cplusplus
20}
21#endif
22
23#endif
diff --git a/src/lib/evil/unposix/meson.build b/src/lib/evil/unposix/meson.build
index 53d82022fa..62b4bb6beb 100644
--- a/src/lib/evil/unposix/meson.build
+++ b/src/lib/evil/unposix/meson.build
@@ -4,7 +4,6 @@ if sys_windows
4 evil_unposix_src = [] 4 evil_unposix_src = []
5 5
6 evil_unposix_header_src = [ 6 evil_unposix_header_src = [
7 'fnmatch.h',
8 'libgen.h', 7 'libgen.h',
9 'limits.h', 8 'limits.h',
10 'locale.h', 9 'locale.h',
@@ -22,14 +21,14 @@ if sys_windows
22 evil_unposix_lib = static_library('evil_unposix', 21 evil_unposix_lib = static_library('evil_unposix',
23 evil_unposix_src, 22 evil_unposix_src,
24 include_directories: [include_directories('.'), config_dir], 23 include_directories: [include_directories('.'), config_dir],
25 dependencies : [pcre_dep, getopt_dep], 24 dependencies : [getopt_dep],
26 install: true, 25 install: true,
27 version: meson.project_version(), 26 version: meson.project_version(),
28 ) 27 )
29 28
30 evil_unposix = declare_dependency( 29 evil_unposix = declare_dependency(
31 include_directories: [include_directories('.')], 30 include_directories: [include_directories('.')],
32 dependencies: [pcre_dep, getopt_dep], 31 dependencies: [getopt_dep],
33 link_with: evil_unposix_lib, 32 link_with: evil_unposix_lib,
34 ) 33 )
35 34
diff --git a/src/tests/eina/eina_fnmatch_test.c b/src/tests/eina/eina_fnmatch_test.c
new file mode 100644
index 0000000000..445549aa03
--- /dev/null
+++ b/src/tests/eina/eina_fnmatch_test.c
@@ -0,0 +1,174 @@
1#include <stdlib.h>
2#include <stdio.h>
3#include <assert.h>
4
5#include "eina_fnmatch.h"
6
7// ref: http://kirste.userpage.fu-berlin.de/chemnet/use/info/libc/libc_16.html
8
9int
10test_normal_string(void)
11{
12 const char * string = "Yep. This is just a n0rmal string!";
13 const char * pattern = "*";
14 const int flags = 0;
15
16 int ret = 0;
17
18 ret |= eina_fnmatch(pattern, string, flags);
19 printf("test normal string (T): %cok!\n", !ret?:'n');
20
21 return ret;
22}
23
24int
25test_unix_path(void)
26{
27 const char * string_valid = "~/linux/usr/include/bits/types/__fpos64_t.h";
28 const char * string_invalid = "~/linux/usr/include/bits/types/__fpos64_t_h";
29 const char * pattern = "~/linux/usr/include/bits/types/__fpos64_t.h";
30 const int flags = FNM_PATHNAME | FNM_NOESCAPE | FNM_PERIOD;
31
32 int ret = 0;
33
34 ret |= eina_fnmatch(pattern, string_valid, flags);
35 printf("test unix path (T): %cok!\n", !ret?:'n');
36
37 ret |= !eina_fnmatch(pattern, string_invalid, flags);
38 printf("test unix path (F): %cok!\n", !ret?:'n');
39
40 return ret;
41}
42
43int
44test_win_path(void)
45{
46 const char * string_valid = "C:\\Program Files (x86)[1]<3>$4?!\\Git";
47 const char * string_invalid = "\\Program Files (x86)\\Git";
48 const char * pattern = "?:\\Program Files*\\Git";
49 const int flags = FNM_PATHNAME | FNM_NOESCAPE | FNM_PERIOD;
50
51 int ret = 0;
52
53 ret |= eina_fnmatch(pattern, string_valid, flags);
54 printf("test win path (T): %cok!\n", !ret?:'n');
55
56 ret |= !eina_fnmatch(pattern, string_invalid, flags);
57 printf("test win path (F): %cok!\n", !ret?:'n');
58
59 return ret;
60}
61
62int
63test_flag_pathname(void)
64{
65 const char * string = "/usr/share/clang/";
66 const char * pattern_valid = "/*/*/*/";
67 const char * pattern_invalid = "*";
68 const int flags = FNM_PATHNAME;
69
70 int ret = 0;
71
72 ret |= eina_fnmatch(pattern_valid, string, 0);
73 printf("test FNM_PATHNAME flag (T): %cok!\n", !ret?:'n');
74
75 ret |= eina_fnmatch(pattern_invalid, string, 0);
76 printf("test FNM_PATHNAME flag (T): %cok!\n", !ret?:'n');
77
78 ret |= eina_fnmatch(pattern_valid, string, flags);
79 printf("test FNM_PATHNAME flag (T): %cok!\n", !ret?:'n');
80
81 ret |= !eina_fnmatch(pattern_invalid, string, flags);
82 printf("test FNM_PATHNAME flag (F): %cok!\n", !ret?:'n');
83
84 return ret;
85}
86
87int
88test_flag_period(void)
89{
90 const char * string = ".config/.isolated-storage/d.none.FBD7";
91 const char * pattern_valid = ".*/*/*";
92 const char * pattern_invalid = "*/*/*";
93 const int flags = FNM_PERIOD;
94
95 int ret = 0;
96
97 ret |= eina_fnmatch(pattern_valid, string, 0);
98 printf("test FNM_PERIOD flag (T): %cok!\n", !ret?:'n');
99
100 ret |= eina_fnmatch(pattern_invalid, string, 0);
101 printf("test FNM_PERIOD flag (T): %cok!\n", !ret?:'n');
102
103 ret |= eina_fnmatch(pattern_valid, string, flags);
104 printf("test FNM_PERIOD flag (T): %cok!\n", !ret?:'n');
105
106 ret |= !eina_fnmatch(pattern_invalid, string, flags);
107 printf("test FNM_PERIOD flag (F): %cok!\n", !ret?:'n');
108
109 return ret;
110}
111
112int
113test_flag_pathname_period(void)
114{
115 const char * string = ".config/.isolated-storage/d.none.FBD7";
116 const char * pattern_valid = ".*/.*/*";
117 const char * pattern_invalid = ".*/*/*";
118 const int flags = FNM_PATHNAME | FNM_PERIOD;
119
120 int ret = 0;
121
122 ret |= eina_fnmatch(pattern_valid, string, 0);
123 printf("test FNM_PATHNAME+FNM_PERIOD flag (T): %cok!\n", !ret?:'n');
124
125 ret |= eina_fnmatch(pattern_invalid, string, 0);
126 printf("test FNM_PATHNAME+FNM_PERIOD flag (T): %cok!\n", !ret?:'n');
127
128 ret |= eina_fnmatch(pattern_valid, string, flags);
129 printf("test FNM_PATHNAME+FNM_PERIOD flag (T): %cok!\n", !ret?:'n');
130
131 ret |= !eina_fnmatch(pattern_invalid, string, flags);
132 printf("test FNM_PATHNAME+FNM_PERIOD flag (F): %cok!\n", !ret?:'n');
133
134 return ret;
135}
136
137int
138test_flag_noescape(void)
139{
140 const char * string_valid = "C:\\Program Files";
141 const char * pattern = "?:\\*";
142 const int flags = FNM_NOESCAPE;
143
144 int ret = 0;
145
146 ret |= eina_fnmatch(pattern, string_valid, flags);
147 printf("test FNM_NOESCAPE flag (T): %cok!\n", !ret?:'n');
148
149 ret |= !eina_fnmatch(pattern, string_valid, 0);
150 printf("test FNM_NOESCAPE flag (F): %cok!\n", !ret?:'n');
151
152 return ret;
153}
154
155int
156main(void)
157{
158 printf("---\n");
159 test_normal_string();
160 printf("---\n");
161 test_flag_pathname();
162 printf("---\n");
163 test_flag_period();
164 printf("---\n");
165 test_flag_pathname_period();
166 printf("---\n");
167 test_flag_noescape();
168 printf("---\n");
169 test_unix_path();
170 printf("---\n");
171 test_win_path();
172
173 return 0;
174}
diff --git a/src/tests/eina/eina_fnmatch_test.sh b/src/tests/eina/eina_fnmatch_test.sh
new file mode 100755
index 0000000000..c2f3b5f406
--- /dev/null
+++ b/src/tests/eina/eina_fnmatch_test.sh
@@ -0,0 +1,63 @@
1#!/bin/sh
2
3if [[ "$OSTYPE" == "linux-gnu" ]]; then
4
5 # clean and update
6 \rm -f fnmatch_test eina_fnmatch_test eina_fnmatch.[hc]
7 \cp ../../lib/eina/eina_fnmatch.[hc] . &&
8
9 # using strcpy instead of strcpy_s on linux
10 sed -i '6i#define strcpy_s(a,b,c) strcpy(a,c)\n' eina_fnmatch.c
11
12 # build
13 gcc eina_fnmatch_test.c -o fnmatch_test
14 gcc eina_fnmatch_test.c eina_fnmatch.c \
15 -lpcreposix -lpcre \
16 -o eina_fnmatch_test
17
18 # test
19 chmod +x fnmatch_test eina_fnmatch_test
20 ./fnmatch_test
21 ./eina_fnmatch_test
22
23 # clean again
24 \rm -f fnmatch_test eina_fnmatch_test eina_fnmatch.[hc]
25
26elif [[ "$OSTYPE" == "msys" ]]; then
27
28 # clean and update
29 \rm -f eina_fnmatch_test.exe eina_fnmatch.[hc]
30 \cp ../../lib/eina/eina_fnmatch.[hc] . &&
31
32 ### USING WRAP DEPENDENCY BUILD:
33 # currently not working here :(
34 # remember to change libpcre*.lib to libpcre*.a
35 # build dependency: pcre
36 #PCRE_SRC_DIR=$(pwd)/"../../../subprojects/pcre-8.37"
37 #PCRE_BIN_DIR=$PCRE_SRC_DIR/build
38 #cd $PCRE_SRC_DIR && meson configure && meson --wipe build && cd build && ninja &&
39 #cd ../../../src/tests/eina/
40
41 ### OR USING CUSTOM BUILD:
42 PCRE_SRC_DIR="/c/Users/joaoantoniocardo/Desktop/pcre-win-build"
43 PCRE_BIN_DIR=$PCRE_SRC_DIR/build-VS2019/x64/Release
44
45 # build
46 PATH=$PATH:$PCRE_BIN_DIR
47 clang-cl -o eina_fnmatch_test.exe \
48 $PCRE_BIN_DIR/libpcre*.lib \
49 eina_fnmatch_test.c eina_fnmatch.c \
50 -I $PCRE_SRC_DIR &&
51
52 # test
53 chmod +x eina_fnmatch_test.exe &&
54 ./eina_fnmatch_test.exe
55
56 # clean again
57 \rm -rf eina_fnmatch_test.exe eina_fnmatch.[hc]
58
59fi
60
61
62
63
diff --git a/src/tests/evil/unposix/eina_fnmatch_test.c b/src/tests/evil/unposix/eina_fnmatch_test.c
new file mode 100644
index 0000000000..2f4e10cd0a
--- /dev/null
+++ b/src/tests/evil/unposix/eina_fnmatch_test.c
@@ -0,0 +1,172 @@
1#include <stdlib.h>
2#include <stdio.h>
3#include <assert.h>
4
5// ref: http://kirste.userpage.fu-berlin.de/chemnet/use/info/libc/libc_16.html
6
7int
8test_normal_string(void)
9{
10 const char * string = "Yep. This is just a n0rmal string!";
11 const char * pattern = "*";
12 const int flags = 0;
13
14 int ret = 0;
15
16 ret |= eina_fnmatch(pattern, string, flags);
17 printf("test normal string (T): %cok!\n", !ret?:'n');
18
19 return ret;
20}
21
22int
23test_unix_path(void)
24{
25 const char * string_valid = "~/linux/usr/include/bits/types/__fpos64_t.h";
26 const char * string_invalid = "~/linux/usr/include/bits/types/__fpos64_t_h";
27 const char * pattern = "~/linux/usr/include/bits/types/__fpos64_t.h";
28 const int flags = FNM_PATHNAME | FNM_NOESCAPE | FNM_PERIOD;
29
30 int ret = 0;
31
32 ret |= eina_fnmatch(pattern, string_valid, flags);
33 printf("test unix path (T): %cok!\n", !ret?:'n');
34
35 ret |= !eina_fnmatch(pattern, string_invalid, flags);
36 printf("test unix path (F): %cok!\n", !ret?:'n');
37
38 return ret;
39}
40
41int
42test_win_path(void)
43{
44 const char * string_valid = "C:\\Program Files (x86)[1]<3>$4?!\\Git";
45 const char * string_invalid = "\\Program Files (x86)\\Git";
46 const char * pattern = "?:\\Program Files*\\Git";
47 const int flags = FNM_PATHNAME | FNM_NOESCAPE | FNM_PERIOD;
48
49 int ret = 0;
50
51 ret |= eina_fnmatch(pattern, string_valid, flags);
52 printf("test win path (T): %cok!\n", !ret?:'n');
53
54 ret |= !eina_fnmatch(pattern, string_invalid, flags);
55 printf("test win path (F): %cok!\n", !ret?:'n');
56
57 return ret;
58}
59
60int
61test_flag_pathname(void)
62{
63 const char * string = "/usr/share/clang/";
64 const char * pattern_valid = "/*/*/*/";
65 const char * pattern_invalid = "*";
66 const int flags = FNM_PATHNAME;
67
68 int ret = 0;
69
70 ret |= eina_fnmatch(pattern_valid, string, 0);
71 printf("test FNM_PATHNAME flag (T): %cok!\n", !ret?:'n');
72
73 ret |= eina_fnmatch(pattern_invalid, string, 0);
74 printf("test FNM_PATHNAME flag (T): %cok!\n", !ret?:'n');
75
76 ret |= eina_fnmatch(pattern_valid, string, flags);
77 printf("test FNM_PATHNAME flag (T): %cok!\n", !ret?:'n');
78
79 ret |= !eina_fnmatch(pattern_invalid, string, flags);
80 printf("test FNM_PATHNAME flag (F): %cok!\n", !ret?:'n');
81
82 return ret;
83}
84
85int
86test_flag_period(void)
87{
88 const char * string = ".config/.isolated-storage/d.none.FBD7";
89 const char * pattern_valid = ".*/*/*";
90 const char * pattern_invalid = "*/*/*";
91 const int flags = FNM_PERIOD;
92
93 int ret = 0;
94
95 ret |= eina_fnmatch(pattern_valid, string, 0);
96 printf("test FNM_PERIOD flag (T): %cok!\n", !ret?:'n');
97
98 ret |= eina_fnmatch(pattern_invalid, string, 0);
99 printf("test FNM_PERIOD flag (T): %cok!\n", !ret?:'n');
100
101 ret |= eina_fnmatch(pattern_valid, string, flags);
102 printf("test FNM_PERIOD flag (T): %cok!\n", !ret?:'n');
103
104 ret |= !eina_fnmatch(pattern_invalid, string, flags);
105 printf("test FNM_PERIOD flag (F): %cok!\n", !ret?:'n');
106
107 return ret;
108}
109
110int
111test_flag_pathname_period(void)
112{
113 const char * string = ".config/.isolated-storage/d.none.FBD7";
114 const char * pattern_valid = ".*/.*/*";
115 const char * pattern_invalid = ".*/*/*";
116 const int flags = FNM_PATHNAME | FNM_PERIOD;
117
118 int ret = 0;
119
120 ret |= eina_fnmatch(pattern_valid, string, 0);
121 printf("test FNM_PATHNAME+FNM_PERIOD flag (T): %cok!\n", !ret?:'n');
122
123 ret |= eina_fnmatch(pattern_invalid, string, 0);
124 printf("test FNM_PATHNAME+FNM_PERIOD flag (T): %cok!\n", !ret?:'n');
125
126 ret |= eina_fnmatch(pattern_valid, string, flags);
127 printf("test FNM_PATHNAME+FNM_PERIOD flag (T): %cok!\n", !ret?:'n');
128
129 ret |= !eina_fnmatch(pattern_invalid, string, flags);
130 printf("test FNM_PATHNAME+FNM_PERIOD flag (F): %cok!\n", !ret?:'n');
131
132 return ret;
133}
134
135int
136test_flag_noescape(void)
137{
138 const char * string_valid = "C:\\Program Files";
139 const char * pattern = "?:\\*";
140 const int flags = FNM_NOESCAPE;
141
142 int ret = 0;
143
144 ret |= eina_fnmatch(pattern, string_valid, flags);
145 printf("test FNM_NOESCAPE flag (T): %cok!\n", !ret?:'n');
146
147 ret |= !eina_fnmatch(pattern, string_valid, 0);
148 printf("test FNM_NOESCAPE flag (F): %cok!\n", !ret?:'n');
149
150 return ret;
151}
152
153int
154main(void)
155{
156 printf("---\n");
157 test_normal_string();
158 printf("---\n");
159 test_flag_pathname();
160 printf("---\n");
161 test_flag_period();
162 printf("---\n");
163 test_flag_pathname_period();
164 printf("---\n");
165 test_flag_noescape();
166 printf("---\n");
167 test_unix_path();
168 printf("---\n");
169 test_win_path();
170
171 return 0;
172}