123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #if HAVE_CONFIG_H
- # include <config.h>
- #endif
- #if defined _LIBC || defined HAVE_STRING_H
- # include <string.h>
- #endif
- typedef unsigned chartype;
- #if defined(L_strstr)
- #define VAL(x) (x)
- #define FUNC strstr
- #undef strstr
- #elif defined(L_strcasestr)
- #include <ctype.h>
- #define VAL(x) tolower(x)
- #define FUNC strcasestr
- #undef strcasestr
- #else
- #error "No target function defined."
- #endif
- char * FUNC ( 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--;
- do {
- c = *++haystack;
- if (c == '\0')
- goto ret0;
- }
- while (VAL(c) != VAL(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 (VAL(a) == VAL(b))
- break;
- a = *++haystack;
- if (a == '\0')
- goto ret0;
- shloop:
- ;
- }
- while (VAL(a) != VAL(b));
- jin:a = *++haystack;
- if (a == '\0')
- goto ret0;
- if (VAL(a) != VAL(c))
- goto shloop;
- rhaystack = haystack-- + 1;
- rneedle = needle;
- a = *rneedle;
- if (VAL(*rhaystack) == VAL(a))
- do {
- if (a == '\0')
- goto foundneedle;
- ++rhaystack;
- a = *++needle;
- if (VAL(*rhaystack) != VAL(a))
- break;
- if (a == '\0')
- goto foundneedle;
- ++rhaystack;
- a = *++needle;
- }
- while (VAL(*rhaystack) == VAL(a));
- needle = rneedle;
- if (a == '\0')
- break;
- }
- }
- foundneedle:
- return (char *) haystack;
- ret0:
- return 0;
- }
|