Back to index

tetex-bin  3.0
Defines | Typedefs | Functions
strstr.c File Reference

Go to the source code of this file.

Defines

#define const

Typedefs

typedef unsigned chartype

Functions

char * strstr (char *phaystack, const char *pneedle) const

Define Documentation

#define const

Definition at line 33 of file strstr.c.


Typedef Documentation

typedef unsigned chartype

Definition at line 37 of file strstr.c.


Function Documentation

char* strstr ( char *  phaystack,
const char *  pneedle 
) const

Definition at line 40 of file strstr.c.

{
  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 aproach */

         if (a == '\0')
           break;
        }
    }
foundneedle:
  return (char*) haystack;
ret0:
  return 0;
}