summaryrefslogtreecommitdiff
path: root/libc/string/strstr.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-10-07 23:37:03 +0000
committerEric Andersen <andersen@codepoet.org>2000-10-07 23:37:03 +0000
commitfbb4007ac88656122f9319dea4563a3a4fd40e82 (patch)
treeca4265ac43d139b3fd02ba32bfe6d5e12cadb65c /libc/string/strstr.c
parentb8f03a94957c913fa0d8588c41b0332b49310ff0 (diff)
Update and simplification.
Diffstat (limited to 'libc/string/strstr.c')
-rw-r--r--libc/string/strstr.c156
1 files changed, 74 insertions, 82 deletions
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;
}