source: trunk/dll/stristr.c@ 689

Last change on this file since 689 was 551, checked in by Gregg Young, 19 years ago

Indentation cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1#define INCL_DOS
2
3#include <os2.h>
4#include <stdlib.h>
5#include <stdio.h>
6#include <string.h>
7#include <ctype.h>
8
9#pragma alloc_text(MISC8,stristr,strnstr,strnistr,findstring)
10
11CHAR *stristr(register CHAR * t, CHAR * s)
12{
13
14 /* case-insensitive strstr() */
15
16 register CHAR *t1, *s1;
17
18 while (*t) {
19 t1 = t;
20 s1 = s;
21 while (*s1) {
22 if (toupper(*s1) != toupper(*t))
23 break;
24 else {
25 s1++;
26 t++;
27 }
28 }
29 if (!*s1)
30 return t1;
31 t = t1 + 1;
32 }
33 return NULL;
34}
35
36CHAR *strnistr(register CHAR * t, CHAR * s, LONG len)
37{
38
39 /* case-insensitive strnstr() */
40
41 register CHAR *s1;
42 register LONG len2;
43
44 len2 = 0;
45 while (len > len2) {
46 s1 = s;
47 while (len2 < len) {
48 if (toupper(*s1) != toupper(t[len2]))
49 break;
50 else {
51 len2++;
52 s1++;
53 }
54 }
55 if (!*s1)
56 return t + (len2 - strlen(s));
57 len2++;
58 }
59 return NULL;
60}
61
62CHAR *strnstr(register CHAR * t, CHAR * s, LONG len)
63{
64
65 /* strnstr() */
66
67 register CHAR *s1;
68 register LONG len2;
69
70 len2 = 0;
71 while (len > len2) {
72 s1 = s;
73 while (len2 < len) {
74 if (*s1 != t[len2])
75 break;
76 else {
77 len2++;
78 s1++;
79 }
80 }
81 if (!*s1)
82 return t + (len2 - strlen(s));
83 len2++;
84 }
85 return NULL;
86}
87
88CHAR *findstring(CHAR * findthis, ULONG lenthis, CHAR * findin,
89 ULONG lenin, BOOL sensitive)
90{
91
92 register CHAR *this, *in;
93 register ULONG lenthis2, lenin2;
94
95 if (!findthis || !findin || !lenthis || !lenin)
96 return NULL;
97 do {
98 this = findthis;
99 lenthis2 = lenthis;
100 in = findin;
101 lenin2 = lenin;
102 while (lenthis2 && lenin2) {
103 if (!sensitive) {
104 if (toupper(*this) != toupper(*in))
105 break;
106 else {
107 this++;
108 in++;
109 lenthis2--;
110 lenin2--;
111 }
112 }
113 else {
114 if (*this != *in)
115 break;
116 else {
117 this++;
118 in++;
119 lenthis2--;
120 lenin2--;
121 }
122 }
123 }
124 if (lenthis2) {
125 lenin--;
126 findin++;
127 }
128 } while (lenin && lenthis2);
129 return (lenthis2) ? NULL : in - lenthis;
130}
Note: See TracBrowser for help on using the repository browser.