Last change
on this file since 551 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
|
Rev | Line | |
---|
[2] | 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 |
|
---|
[551] | 11 | CHAR *stristr(register CHAR * t, CHAR * s)
|
---|
| 12 | {
|
---|
[2] | 13 |
|
---|
| 14 | /* case-insensitive strstr() */
|
---|
| 15 |
|
---|
[551] | 16 | register CHAR *t1, *s1;
|
---|
[2] | 17 |
|
---|
| 18 | while (*t) {
|
---|
| 19 | t1 = t;
|
---|
| 20 | s1 = s;
|
---|
| 21 | while (*s1) {
|
---|
[551] | 22 | if (toupper(*s1) != toupper(*t))
|
---|
| 23 | break;
|
---|
[2] | 24 | else {
|
---|
[551] | 25 | s1++;
|
---|
| 26 | t++;
|
---|
[2] | 27 | }
|
---|
| 28 | }
|
---|
| 29 | if (!*s1)
|
---|
| 30 | return t1;
|
---|
| 31 | t = t1 + 1;
|
---|
| 32 | }
|
---|
| 33 | return NULL;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[551] | 36 | CHAR *strnistr(register CHAR * t, CHAR * s, LONG len)
|
---|
| 37 | {
|
---|
[2] | 38 |
|
---|
| 39 | /* case-insensitive strnstr() */
|
---|
| 40 |
|
---|
| 41 | register CHAR *s1;
|
---|
[551] | 42 | register LONG len2;
|
---|
[2] | 43 |
|
---|
| 44 | len2 = 0;
|
---|
| 45 | while (len > len2) {
|
---|
| 46 | s1 = s;
|
---|
| 47 | while (len2 < len) {
|
---|
[551] | 48 | if (toupper(*s1) != toupper(t[len2]))
|
---|
| 49 | break;
|
---|
[2] | 50 | else {
|
---|
[551] | 51 | len2++;
|
---|
| 52 | s1++;
|
---|
[2] | 53 | }
|
---|
| 54 | }
|
---|
| 55 | if (!*s1)
|
---|
| 56 | return t + (len2 - strlen(s));
|
---|
| 57 | len2++;
|
---|
| 58 | }
|
---|
| 59 | return NULL;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[551] | 62 | CHAR *strnstr(register CHAR * t, CHAR * s, LONG len)
|
---|
| 63 | {
|
---|
[2] | 64 |
|
---|
| 65 | /* strnstr() */
|
---|
| 66 |
|
---|
| 67 | register CHAR *s1;
|
---|
[551] | 68 | register LONG len2;
|
---|
[2] | 69 |
|
---|
| 70 | len2 = 0;
|
---|
| 71 | while (len > len2) {
|
---|
| 72 | s1 = s;
|
---|
| 73 | while (len2 < len) {
|
---|
| 74 | if (*s1 != t[len2])
|
---|
[551] | 75 | break;
|
---|
[2] | 76 | else {
|
---|
[551] | 77 | len2++;
|
---|
| 78 | s1++;
|
---|
[2] | 79 | }
|
---|
| 80 | }
|
---|
| 81 | if (!*s1)
|
---|
| 82 | return t + (len2 - strlen(s));
|
---|
| 83 | len2++;
|
---|
| 84 | }
|
---|
| 85 | return NULL;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[551] | 88 | CHAR *findstring(CHAR * findthis, ULONG lenthis, CHAR * findin,
|
---|
| 89 | ULONG lenin, BOOL sensitive)
|
---|
| 90 | {
|
---|
[2] | 91 |
|
---|
[551] | 92 | register CHAR *this, *in;
|
---|
| 93 | register ULONG lenthis2, lenin2;
|
---|
[2] | 94 |
|
---|
[551] | 95 | if (!findthis || !findin || !lenthis || !lenin)
|
---|
[2] | 96 | return NULL;
|
---|
| 97 | do {
|
---|
| 98 | this = findthis;
|
---|
| 99 | lenthis2 = lenthis;
|
---|
| 100 | in = findin;
|
---|
| 101 | lenin2 = lenin;
|
---|
[551] | 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 | }
|
---|
[2] | 112 | }
|
---|
| 113 | else {
|
---|
[551] | 114 | if (*this != *in)
|
---|
| 115 | break;
|
---|
| 116 | else {
|
---|
| 117 | this++;
|
---|
| 118 | in++;
|
---|
| 119 | lenthis2--;
|
---|
| 120 | lenin2--;
|
---|
| 121 | }
|
---|
[2] | 122 | }
|
---|
| 123 | }
|
---|
[551] | 124 | if (lenthis2) {
|
---|
[2] | 125 | lenin--;
|
---|
| 126 | findin++;
|
---|
| 127 | }
|
---|
[551] | 128 | } while (lenin && lenthis2);
|
---|
[2] | 129 | return (lenthis2) ? NULL : in - lenthis;
|
---|
| 130 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.