From fbb4007ac88656122f9319dea4563a3a4fd40e82 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Sat, 7 Oct 2000 23:37:03 +0000 Subject: Update and simplification. --- libc/string/strstr.c | 156 ++++++++++++++++++++++++--------------------------- 1 file changed, 74 insertions(+), 82 deletions(-) (limited to 'libc/string/strstr.c') diff --git a/libc/string/strstr.c b/libc/string/strstr.c index 03d6c8e5f..b1890559b 100644 --- a/libc/string/strstr.c +++ b/libc/string/strstr.c @@ -38,88 +38,80 @@ typedef unsigned chartype; #undef strstr -char * -strstr (phaystack, pneedle) - const char *phaystack; - const char *pneedle; +char *strstr( const char *phaystack, const char *pneedle) { - register const unsigned char *haystack, *needle; - register chartype b, c; - - haystack = (const unsigned char *) phaystack; - needle = (const unsigned char *) pneedle; - - b = *needle; - if (b != '\0') - { - haystack--; /* possible ANSI violation */ - do - { - c = *++haystack; - if (c == '\0') - goto ret0; + register const unsigned char *haystack, *needle; + register chartype b, c; + + haystack = (const unsigned char *) phaystack; + needle = (const unsigned char *) pneedle; + + b = *needle; + if (b != '\0') { + haystack--; /* possible ANSI violation */ + do { + c = *++haystack; + if (c == '\0') + goto ret0; + } + while (c != b); + + c = *++needle; + if (c == '\0') + goto foundneedle; + ++needle; + goto jin; + + for (;;) { + register chartype a; + register const unsigned char *rhaystack, *rneedle; + + do { + a = *++haystack; + if (a == '\0') + goto ret0; + if (a == b) + break; + a = *++haystack; + if (a == '\0') + goto ret0; + shloop:} + while (a != b); + + jin:a = *++haystack; + if (a == '\0') + goto ret0; + + if (a != c) + goto shloop; + + rhaystack = haystack-- + 1; + rneedle = needle; + a = *rneedle; + + if (*rhaystack == a) + do { + if (a == '\0') + goto foundneedle; + ++rhaystack; + a = *++needle; + if (*rhaystack != a) + break; + if (a == '\0') + goto foundneedle; + ++rhaystack; + a = *++needle; + } + while (*rhaystack == a); + + needle = rneedle; /* took the register-poor approach */ + + if (a == '\0') + break; + } } - while (c != b); - - c = *++needle; - if (c == '\0') - goto foundneedle; - ++needle; - goto jin; - - for (;;) - { - register chartype a; - register const unsigned char *rhaystack, *rneedle; - - do - { - a = *++haystack; - if (a == '\0') - goto ret0; - if (a == b) - break; - a = *++haystack; - if (a == '\0') - goto ret0; -shloop: } - while (a != b); - -jin: a = *++haystack; - if (a == '\0') - goto ret0; - - if (a != c) - goto shloop; - - rhaystack = haystack-- + 1; - rneedle = needle; - a = *rneedle; - - if (*rhaystack == a) - do - { - if (a == '\0') - goto foundneedle; - ++rhaystack; - a = *++needle; - if (*rhaystack != a) - break; - if (a == '\0') - goto foundneedle; - ++rhaystack; - a = *++needle; - } - while (*rhaystack == a); - - needle = rneedle; /* took the register-poor approach */ - - if (a == '\0') - break; - } - } -foundneedle: - return (char*) haystack; -ret0: - return 0; + foundneedle: + return (char *) haystack; + ret0: + return 0; } -- cgit v1.2.3