From 20b85c03e751b4876fa3c92040464e483172b746 Mon Sep 17 00:00:00 2001 From: Jannis Hoffmann Date: Wed, 3 Jul 2024 19:03:11 +0200 Subject: manual format adjustment --- src/wildmat.c | 98 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 49 insertions(+), 49 deletions(-) (limited to 'src/wildmat.c') diff --git a/src/wildmat.c b/src/wildmat.c index 363c118..bcff8dd 100644 --- a/src/wildmat.c +++ b/src/wildmat.c @@ -1,41 +1,41 @@ -/*** wildmat.c.orig Wed Dec 3 11:46:31 1997 */ -/* $Revision: 1.1 $ -** -** Do shell-style pattern matching for ?, \, [], and * characters. -** Might not be robust in face of malformed patterns; e.g., "foo[a-" -** could cause a segmentation violation. It is 8bit clean. -** -** Written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986. -** Rich $alz is now . -** April, 1991: Replaced mutually-recursive calls with in-line code -** for the star character. -** -** Special thanks to Lars Mathiesen for the ABORT code. -** This can greatly speed up failing wildcard patterns. For example: -** pattern: -*-*-*-*-*-*-12-*-*-*-m-*-*-* -** text 1: -adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1 -** text 2: -adobe-courier-bold-o-normal--12-120-75-75-X-70-iso8859-1 -** Text 1 matches with 51 calls, while text 2 fails with 54 calls. Without -** the ABORT code, it takes 22310 calls to fail. Ugh. The following -** explanation is from Lars: -** The precondition that must be fulfilled is that DoMatch will consume -** at least one character in text. This is true if *p is neither '*' nor -** '\0'.) The last return has ABORT instead of FALSE to avoid quadratic -** behaviour in cases like pattern "*a*b*c*d" with text "abcxxxxx". With -** FALSE, each star-loop has to run to the end of the text; with ABORT -** only the last one does. -** -** Once the control of one instance of DoMatch enters the star-loop, that -** instance will return either TRUE or ABORT, and any calling instance -** will therefore return immediately after (without calling recursively -** again). In effect, only one star-loop is ever active. It would be -** possible to modify the code to maintain this context explicitly, -** eliminating all recursive calls at the cost of some complication and -** loss of clarity (and the ABORT stuff seems to be unclear enough by -** itself). I think it would be unwise to try to get this into a -** released version unless you have a good test data base to try it out -** on. -*/ +/*** wildmat.c.orig Wed Dec 3 11:46:31 1997 */ +/* $Revision: 1.1 $ + * + * Do shell-style pattern matching for ?, \, [], and * characters. + * Might not be robust in face of malformed patterns; e.g., "foo[a-" + * could cause a segmentation violation. It is 8bit clean. + * + * Written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986. + * Rich $alz is now . + * April, 1991: Replaced mutually-recursive calls with in-line code + * for the star character. + * + * Special thanks to Lars Mathiesen for the ABORT code. + * This can greatly speed up failing wildcard patterns. For example: + * pattern: -*-*-*-*-*-*-12-*-*-*-m-*-*-* + * text 1: -adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1 + * text 2: -adobe-courier-bold-o-normal--12-120-75-75-X-70-iso8859-1 + * Text 1 matches with 51 calls, while text 2 fails with 54 calls. Without + * the ABORT code, it takes 22310 calls to fail. Ugh. The following + * explanation is from Lars: + * The precondition that must be fulfilled is that DoMatch will consume + * at least one character in text. This is true if *p is neither '*' nor + * '\0'.) The last return has ABORT instead of FALSE to avoid quadratic + * behaviour in cases like pattern "*a*b*c*d" with text "abcxxxxx". With + * FALSE, each star-loop has to run to the end of the text; with ABORT + * only the last one does. + * + * Once the control of one instance of DoMatch enters the star-loop, that + * instance will return either TRUE or ABORT, and any calling instance + * will therefore return immediately after (without calling recursively + * again). In effect, only one star-loop is ever active. It would be + * possible to modify the code to maintain this context explicitly, + * eliminating all recursive calls at the cost of some complication and + * loss of clarity (and the ABORT stuff seems to be unclear enough by + * itself). I think it would be unwise to try to get this into a + * released version unless you have a good test data base to try it out + * on. + */ #define TRUE 1 #define FALSE 0 @@ -48,20 +48,20 @@ /* Do tar(1) matching rules, which ignore a trailing slash? */ #undef MATCH_TAR_PATTERN -/* -** Match text and p, return TRUE, FALSE, or ABORT. -*/ -static int DoMatch(register char *text, register char *p) +/** + * Match text and p, return TRUE, FALSE, or ABORT. + */ +static int DoMatch(char *text, char *p) { - register int last; - register int matched; - register int reverse; + int last; + int matched; + int reverse; for (; *p; text++, p++) { if (*text == '\0' && *p != '*') return ABORT; switch (*p) { case '\\': /* Literal match with following character. */ p++; - case '?': /* Match anything. */ continue; + case '?': /* Match anything. */ continue; case '*': /* Consecutive stars act just like one. */ while (*++p == '*') continue; if (*p == '\0') return TRUE; /* Trailing star matches everything. */ @@ -90,9 +90,9 @@ static int DoMatch(register char *text, register char *p) return *text == '\0'; } -/* -** User-level routine. Returns TRUE or FALSE. -*/ +/** + * User-level routine. Returns TRUE or FALSE. + */ int wildmat(char *text, char *p) { #ifdef OPTIMIZE_JUST_STAR -- cgit v1.2.3