| 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 |  | 
|---|
| 15 | #include <string.h> | 
|---|
| 16 | #include <ctype.h> | 
|---|
| 17 |  | 
|---|
| 18 | #include <os2.h> | 
|---|
| 19 |  | 
|---|
| 20 | CHAR *stristr(register CHAR * t, CHAR * s) | 
|---|
| 21 | { | 
|---|
| 22 | /* case-insensitive strstr() */ | 
|---|
| 23 |  | 
|---|
| 24 | register CHAR *t1, *s1; | 
|---|
| 25 |  | 
|---|
| 26 | while (*t) { | 
|---|
| 27 | t1 = t; | 
|---|
| 28 | s1 = s; | 
|---|
| 29 | while (*s1) { | 
|---|
| 30 | if (toupper(*s1) != toupper(*t)) | 
|---|
| 31 | break; | 
|---|
| 32 | else { | 
|---|
| 33 | s1++; | 
|---|
| 34 | t++; | 
|---|
| 35 | } | 
|---|
| 36 | } | 
|---|
| 37 | if (!*s1) | 
|---|
| 38 | return t1; | 
|---|
| 39 | t = t1 + 1; | 
|---|
| 40 | } | 
|---|
| 41 | return NULL; | 
|---|
| 42 | } | 
|---|
| 43 |  | 
|---|
| 44 | CHAR *strnistr(register CHAR * t, CHAR * s, LONG len) | 
|---|
| 45 | { | 
|---|
| 46 | /* case-insensitive strnstr() */ | 
|---|
| 47 |  | 
|---|
| 48 | register CHAR *s1; | 
|---|
| 49 | register LONG len2; | 
|---|
| 50 |  | 
|---|
| 51 | len2 = 0; | 
|---|
| 52 | while (len > len2) { | 
|---|
| 53 | s1 = s; | 
|---|
| 54 | while (len2 < len) { | 
|---|
| 55 | if (toupper(*s1) != toupper(t[len2])) | 
|---|
| 56 | break; | 
|---|
| 57 | else { | 
|---|
| 58 | len2++; | 
|---|
| 59 | s1++; | 
|---|
| 60 | } | 
|---|
| 61 | } | 
|---|
| 62 | if (!*s1) | 
|---|
| 63 | return t + (len2 - strlen(s)); | 
|---|
| 64 | len2++; | 
|---|
| 65 | } | 
|---|
| 66 | return NULL; | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | CHAR *strnstr(register CHAR * t, CHAR * s, LONG len) | 
|---|
| 70 | { | 
|---|
| 71 | /* strnstr() */ | 
|---|
| 72 |  | 
|---|
| 73 | register CHAR *s1; | 
|---|
| 74 | register LONG len2; | 
|---|
| 75 |  | 
|---|
| 76 | len2 = 0; | 
|---|
| 77 | while (len > len2) { | 
|---|
| 78 | s1 = s; | 
|---|
| 79 | while (len2 < len) { | 
|---|
| 80 | if (*s1 != t[len2]) | 
|---|
| 81 | break; | 
|---|
| 82 | else { | 
|---|
| 83 | len2++; | 
|---|
| 84 | s1++; | 
|---|
| 85 | } | 
|---|
| 86 | } | 
|---|
| 87 | if (!*s1) | 
|---|
| 88 | return t + (len2 - strlen(s)); | 
|---|
| 89 | len2++; | 
|---|
| 90 | } | 
|---|
| 91 | return NULL; | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 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; | 
|---|
| 99 |  | 
|---|
| 100 | if (!findthis || !findin || !lenthis || !lenin) | 
|---|
| 101 | return NULL; | 
|---|
| 102 | do { | 
|---|
| 103 | this = findthis; | 
|---|
| 104 | lenthis2 = lenthis; | 
|---|
| 105 | in = findin; | 
|---|
| 106 | lenin2 = lenin; | 
|---|
| 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 | } | 
|---|
| 117 | } | 
|---|
| 118 | else { | 
|---|
| 119 | if (*this != *in) | 
|---|
| 120 | break; | 
|---|
| 121 | else { | 
|---|
| 122 | this++; | 
|---|
| 123 | in++; | 
|---|
| 124 | lenthis2--; | 
|---|
| 125 | lenin2--; | 
|---|
| 126 | } | 
|---|
| 127 | } | 
|---|
| 128 | } | 
|---|
| 129 | if (lenthis2) { | 
|---|
| 130 | lenin--; | 
|---|
| 131 | findin++; | 
|---|
| 132 | } | 
|---|
| 133 | } while (lenin && lenthis2); | 
|---|
| 134 | return (lenthis2) ? NULL : in - lenthis; | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 | #pragma alloc_text(MISC8,stristr,strnstr,strnistr,findstring) | 
|---|