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