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