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