MCPcopy Create free account
hub / github.com/RsyncProject/rsync / dowild

Function dowild

lib/wildmatch.c:64–234  ·  view source on GitHub ↗

Match pattern "p" against the a virtually-joined string consisting * of "text" and any strings in array "a". */

Source from the content-addressed store, hash-verified

62/* Match pattern "p" against the a virtually-joined string consisting
63 * of "text" and any strings in array "a". */
64static int dowild(const uchar *p, const uchar *text, const uchar*const *a)
65{
66 uchar p_ch;
67
68#ifdef WILD_TEST_ITERATIONS
69 wildmatch_iteration_count++;
70#endif
71
72 for ( ; (p_ch = *p) != '\0'; text++, p++) {
73 int matched, special;
74 uchar t_ch, prev_ch;
75 while ((t_ch = *text) == '\0') {
76 if (*a == NULL) {
77 if (p_ch != '*')
78 return ABORT_ALL;
79 break;
80 }
81 text = *a++;
82 }
83 if (force_lower_case && ISUPPER(t_ch))
84 t_ch = tolower(t_ch);
85 switch (p_ch) {
86 case '\\':
87 /* Literal match with following character. Note that the test
88 * in "default" handles the p[1] == '\0' failure case. */
89 p_ch = *++p;
90 /* FALLTHROUGH */
91 default:
92 if (t_ch != p_ch)
93 return FALSE;
94 continue;
95 case '?':
96 /* Match anything but '/'. */
97 if (t_ch == '/')
98 return FALSE;
99 continue;
100 case '*':
101 if (*++p == '*') {
102 while (*++p == '*') {}
103 special = TRUE;
104 } else
105 special = FALSE;
106 if (*p == '\0') {
107 /* Trailing "**" matches everything. Trailing "*" matches
108 * only if there are no more slash characters. */
109 if (!special) {
110 do {
111 if (strchr((char*)text, '/') != NULL)
112 return FALSE;
113 } while ((text = *a++) != NULL);
114 }
115 return TRUE;
116 }
117 while (1) {
118 if (t_ch == '\0') {
119 if ((text = *a++) == NULL)
120 break;
121 t_ch = *text;

Callers 3

wildmatchFunction · 0.85
iwildmatchFunction · 0.85
wildmatch_arrayFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected