summaryrefslogtreecommitdiff
path: root/src/wildmat.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
commita6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f (patch)
treeb88cc7a8457658d67e0321718556ac807f6bccf3 /src/wildmat.c
parent00be7622c428f279872f84569f098ce16150f8a8 (diff)
format files
Diffstat (limited to 'src/wildmat.c')
-rw-r--r--src/wildmat.c75
1 files changed, 34 insertions, 41 deletions
diff --git a/src/wildmat.c b/src/wildmat.c
index 739f943..363c118 100644
--- a/src/wildmat.c
+++ b/src/wildmat.c
@@ -37,8 +37,8 @@
** on.
*/
-#define TRUE 1
-#define FALSE 0
+#define TRUE 1
+#define FALSE 0
#define ABORT -1
/* What character marks an inverted character class? */
@@ -53,57 +53,50 @@
*/
static int DoMatch(register char *text, register char *p)
{
- register int last;
- register int matched;
- register int reverse;
+ register int last;
+ register int matched;
+ register int reverse;
for (; *p; text++, p++) {
- if (*text == '\0' && *p != '*')
- return ABORT;
+ if (*text == '\0' && *p != '*') return ABORT;
switch (*p) {
- case '\\': /* Literal match with following character. */
- p++;
- case '?': /* Match anything. */
- continue;
- case '*': /* Consecutive stars act just like one. */
- while (*++p == '*')
- continue;
- if (*p == '\0') return TRUE; /* Trailing star matches everything. */
- while (*text)
- if ((matched = DoMatch(text++, p)) != FALSE) return matched;
- return ABORT;
- case '[':
- reverse = p[1] == NEGATE_CLASS ? TRUE : FALSE;
- if (reverse) p++; /* Inverted character class. */
- matched = FALSE;
- if (p[1] == ']' || p[1] == '-')
- if (*++p == *text) matched = TRUE;
- for (last = *p; *++p && *p != ']'; last = *p) /* This next line requires a good C compiler. */
- if (*p == '-' && p[1] != ']' ? *text <= *++p && *text >= last : *text == *p)
- matched = TRUE;
- if (matched == reverse) return FALSE;
- continue;
- default: /* FALLTHROUGH */
- if (*text != *p) return FALSE;
- continue;
+ case '\\': /* Literal match with following character. */ p++;
+ case '?': /* Match anything. */ continue;
+ case '*': /* Consecutive stars act just like one. */
+ while (*++p == '*') continue;
+ if (*p == '\0') return TRUE; /* Trailing star matches everything. */
+ while (*text)
+ if ((matched = DoMatch(text++, p)) != FALSE) return matched;
+ return ABORT;
+ case '[':
+ reverse = p[1] == NEGATE_CLASS ? TRUE : FALSE;
+ if (reverse) p++; /* Inverted character class. */
+ matched = FALSE;
+ if (p[1] == ']' || p[1] == '-')
+ if (*++p == *text) matched = TRUE;
+ for (last = *p; *++p && *p != ']'; last = *p) /* This next line requires a good C compiler. */
+ if (*p == '-' && p[1] != ']' ? *text <= *++p && *text >= last : *text == *p) matched = TRUE;
+ if (matched == reverse) return FALSE;
+ continue;
+ default: /* FALLTHROUGH */
+ if (*text != *p) return FALSE;
+ continue;
}
}
-#ifdef MATCH_TAR_PATTERN
- if (*text == '/')
- return TRUE;
-#endif /* MATCH_TAR_ATTERN */
+#ifdef MATCH_TAR_PATTERN
+ if (*text == '/') return TRUE;
+#endif /* MATCH_TAR_ATTERN */
return *text == '\0';
}
/*
** User-level routine. Returns TRUE or FALSE.
*/
-int wildmat(char *text,char *p)
+int wildmat(char *text, char *p)
{
-#ifdef OPTIMIZE_JUST_STAR
- if (p[0] == '*' && p[1] == '\0')
- return TRUE;
-#endif /* OPTIMIZE_JUST_STAR */
+#ifdef OPTIMIZE_JUST_STAR
+ if (p[0] == '*' && p[1] == '\0') return TRUE;
+#endif /* OPTIMIZE_JUST_STAR */
return DoMatch(text, p) == TRUE;
}