| [793] | 1 | 
 | 
|---|
 | 2 | /***********************************************************************
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 |   $Id: stristr.c 907 2008-01-06 07:26:17Z stevenhl $
 | 
|---|
 | 5 | 
 | 
|---|
 | 6 |   Copyright (c) 1993-98 M. Kimes
 | 
|---|
 | 7 |   Copyright (c) 2003, 2007 Steven H.Levine
 | 
|---|
 | 8 | 
 | 
|---|
 | 9 |   Case insensitive strings
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 |   20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
 | 
|---|
 | 12 | 
 | 
|---|
 | 13 | ***********************************************************************/
 | 
|---|
 | 14 | 
 | 
|---|
| [2] | 15 | #include <string.h>
 | 
|---|
 | 16 | #include <ctype.h>
 | 
|---|
 | 17 | 
 | 
|---|
| [907] | 18 | #include <os2.h>
 | 
|---|
 | 19 | 
 | 
|---|
| [551] | 20 | CHAR *stristr(register CHAR * t, CHAR * s)
 | 
|---|
 | 21 | {
 | 
|---|
| [2] | 22 |   /* case-insensitive strstr() */
 | 
|---|
 | 23 | 
 | 
|---|
| [551] | 24 |   register CHAR *t1, *s1;
 | 
|---|
| [2] | 25 | 
 | 
|---|
 | 26 |   while (*t) {
 | 
|---|
 | 27 |     t1 = t;
 | 
|---|
 | 28 |     s1 = s;
 | 
|---|
 | 29 |     while (*s1) {
 | 
|---|
| [551] | 30 |       if (toupper(*s1) != toupper(*t))
 | 
|---|
 | 31 |         break;
 | 
|---|
| [2] | 32 |       else {
 | 
|---|
| [551] | 33 |         s1++;
 | 
|---|
 | 34 |         t++;
 | 
|---|
| [2] | 35 |       }
 | 
|---|
 | 36 |     }
 | 
|---|
 | 37 |     if (!*s1)
 | 
|---|
 | 38 |       return t1;
 | 
|---|
 | 39 |     t = t1 + 1;
 | 
|---|
 | 40 |   }
 | 
|---|
 | 41 |   return NULL;
 | 
|---|
 | 42 | }
 | 
|---|
 | 43 | 
 | 
|---|
| [551] | 44 | CHAR *strnistr(register CHAR * t, CHAR * s, LONG len)
 | 
|---|
 | 45 | {
 | 
|---|
| [2] | 46 |   /* case-insensitive strnstr() */
 | 
|---|
 | 47 | 
 | 
|---|
 | 48 |   register CHAR *s1;
 | 
|---|
| [551] | 49 |   register LONG len2;
 | 
|---|
| [2] | 50 | 
 | 
|---|
 | 51 |   len2 = 0;
 | 
|---|
 | 52 |   while (len > len2) {
 | 
|---|
 | 53 |     s1 = s;
 | 
|---|
 | 54 |     while (len2 < len) {
 | 
|---|
| [551] | 55 |       if (toupper(*s1) != toupper(t[len2]))
 | 
|---|
 | 56 |         break;
 | 
|---|
| [2] | 57 |       else {
 | 
|---|
| [551] | 58 |         len2++;
 | 
|---|
 | 59 |         s1++;
 | 
|---|
| [2] | 60 |       }
 | 
|---|
 | 61 |     }
 | 
|---|
 | 62 |     if (!*s1)
 | 
|---|
 | 63 |       return t + (len2 - strlen(s));
 | 
|---|
 | 64 |     len2++;
 | 
|---|
 | 65 |   }
 | 
|---|
 | 66 |   return NULL;
 | 
|---|
 | 67 | }
 | 
|---|
 | 68 | 
 | 
|---|
| [551] | 69 | CHAR *strnstr(register CHAR * t, CHAR * s, LONG len)
 | 
|---|
 | 70 | {
 | 
|---|
| [2] | 71 |   /* strnstr() */
 | 
|---|
 | 72 | 
 | 
|---|
 | 73 |   register CHAR *s1;
 | 
|---|
| [551] | 74 |   register LONG len2;
 | 
|---|
| [2] | 75 | 
 | 
|---|
 | 76 |   len2 = 0;
 | 
|---|
 | 77 |   while (len > len2) {
 | 
|---|
 | 78 |     s1 = s;
 | 
|---|
 | 79 |     while (len2 < len) {
 | 
|---|
 | 80 |       if (*s1 != t[len2])
 | 
|---|
| [551] | 81 |         break;
 | 
|---|
| [2] | 82 |       else {
 | 
|---|
| [551] | 83 |         len2++;
 | 
|---|
 | 84 |         s1++;
 | 
|---|
| [2] | 85 |       }
 | 
|---|
 | 86 |     }
 | 
|---|
 | 87 |     if (!*s1)
 | 
|---|
 | 88 |       return t + (len2 - strlen(s));
 | 
|---|
 | 89 |     len2++;
 | 
|---|
 | 90 |   }
 | 
|---|
 | 91 |   return NULL;
 | 
|---|
 | 92 | }
 | 
|---|
 | 93 | 
 | 
|---|
| [551] | 94 | CHAR *findstring(CHAR * findthis, ULONG lenthis, CHAR * findin,
 | 
|---|
 | 95 |                  ULONG lenin, BOOL sensitive)
 | 
|---|
 | 96 | {
 | 
|---|
 | 97 |   register CHAR *this, *in;
 | 
|---|
 | 98 |   register ULONG lenthis2, lenin2;
 | 
|---|
| [2] | 99 | 
 | 
|---|
| [551] | 100 |   if (!findthis || !findin || !lenthis || !lenin)
 | 
|---|
| [2] | 101 |     return NULL;
 | 
|---|
 | 102 |   do {
 | 
|---|
 | 103 |     this = findthis;
 | 
|---|
 | 104 |     lenthis2 = lenthis;
 | 
|---|
 | 105 |     in = findin;
 | 
|---|
 | 106 |     lenin2 = lenin;
 | 
|---|
| [551] | 107 |     while (lenthis2 && lenin2) {
 | 
|---|
 | 108 |       if (!sensitive) {
 | 
|---|
 | 109 |         if (toupper(*this) != toupper(*in))
 | 
|---|
 | 110 |           break;
 | 
|---|
 | 111 |         else {
 | 
|---|
 | 112 |           this++;
 | 
|---|
 | 113 |           in++;
 | 
|---|
 | 114 |           lenthis2--;
 | 
|---|
 | 115 |           lenin2--;
 | 
|---|
 | 116 |         }
 | 
|---|
| [2] | 117 |       }
 | 
|---|
 | 118 |       else {
 | 
|---|
| [551] | 119 |         if (*this != *in)
 | 
|---|
 | 120 |           break;
 | 
|---|
 | 121 |         else {
 | 
|---|
 | 122 |           this++;
 | 
|---|
 | 123 |           in++;
 | 
|---|
 | 124 |           lenthis2--;
 | 
|---|
 | 125 |           lenin2--;
 | 
|---|
 | 126 |         }
 | 
|---|
| [2] | 127 |       }
 | 
|---|
 | 128 |     }
 | 
|---|
| [551] | 129 |     if (lenthis2) {
 | 
|---|
| [2] | 130 |       lenin--;
 | 
|---|
 | 131 |       findin++;
 | 
|---|
 | 132 |     }
 | 
|---|
| [551] | 133 |   } while (lenin && lenthis2);
 | 
|---|
| [2] | 134 |   return (lenthis2) ? NULL : in - lenthis;
 | 
|---|
 | 135 | }
 | 
|---|
| [793] | 136 | 
 | 
|---|
 | 137 | #pragma alloc_text(MISC8,stristr,strnstr,strnistr,findstring)
 | 
|---|