| Last change
 on this file since 116 was             2, checked in by root, 23 years ago | 
        
          | 
Initial revision
 | 
        
          | 
              
Property                 svn:eol-style
 set to                 native
Property                 svn:keywords
 set to                 Author Date Id Revision | 
        
          | File size:
            2.1 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 |  | 
|---|
|  | 11 |  | 
|---|
|  | 12 | CHAR * stristr (register CHAR *t, CHAR *s) { | 
|---|
|  | 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 |  | 
|---|
|  | 36 |  | 
|---|
|  | 37 |  | 
|---|
|  | 38 | CHAR * strnistr (register CHAR *t, CHAR *s, LONG len) { | 
|---|
|  | 39 |  | 
|---|
|  | 40 | /* case-insensitive strnstr() */ | 
|---|
|  | 41 |  | 
|---|
|  | 42 | register CHAR *s1; | 
|---|
|  | 43 | register LONG  len2; | 
|---|
|  | 44 |  | 
|---|
|  | 45 | len2 = 0; | 
|---|
|  | 46 | while (len > len2) { | 
|---|
|  | 47 | s1 = s; | 
|---|
|  | 48 | while (len2 < len) { | 
|---|
|  | 49 | if (toupper (*s1) != toupper (t[len2])) | 
|---|
|  | 50 | break; | 
|---|
|  | 51 | else { | 
|---|
|  | 52 | len2++; | 
|---|
|  | 53 | s1++; | 
|---|
|  | 54 | } | 
|---|
|  | 55 | } | 
|---|
|  | 56 | if (!*s1) | 
|---|
|  | 57 | return t + (len2 - strlen(s)); | 
|---|
|  | 58 | len2++; | 
|---|
|  | 59 | } | 
|---|
|  | 60 | return NULL; | 
|---|
|  | 61 | } | 
|---|
|  | 62 |  | 
|---|
|  | 63 |  | 
|---|
|  | 64 | CHAR * strnstr (register CHAR *t, CHAR *s, LONG len) { | 
|---|
|  | 65 |  | 
|---|
|  | 66 | /* strnstr() */ | 
|---|
|  | 67 |  | 
|---|
|  | 68 | register CHAR *s1; | 
|---|
|  | 69 | register LONG  len2; | 
|---|
|  | 70 |  | 
|---|
|  | 71 | len2 = 0; | 
|---|
|  | 72 | while (len > len2) { | 
|---|
|  | 73 | s1 = s; | 
|---|
|  | 74 | while (len2 < len) { | 
|---|
|  | 75 | if (*s1 != t[len2]) | 
|---|
|  | 76 | break; | 
|---|
|  | 77 | else { | 
|---|
|  | 78 | len2++; | 
|---|
|  | 79 | s1++; | 
|---|
|  | 80 | } | 
|---|
|  | 81 | } | 
|---|
|  | 82 | if (!*s1) | 
|---|
|  | 83 | return t + (len2 - strlen(s)); | 
|---|
|  | 84 | len2++; | 
|---|
|  | 85 | } | 
|---|
|  | 86 | return NULL; | 
|---|
|  | 87 | } | 
|---|
|  | 88 |  | 
|---|
|  | 89 |  | 
|---|
|  | 90 | CHAR * findstring (CHAR *findthis, ULONG lenthis, CHAR *findin, | 
|---|
|  | 91 | ULONG lenin, BOOL sensitive) { | 
|---|
|  | 92 |  | 
|---|
|  | 93 | register CHAR *this,*in; | 
|---|
|  | 94 | register ULONG lenthis2,lenin2; | 
|---|
|  | 95 |  | 
|---|
|  | 96 | if(!findthis || !findin || !lenthis || !lenin) | 
|---|
|  | 97 | return NULL; | 
|---|
|  | 98 | do { | 
|---|
|  | 99 | this = findthis; | 
|---|
|  | 100 | lenthis2 = lenthis; | 
|---|
|  | 101 | in = findin; | 
|---|
|  | 102 | lenin2 = lenin; | 
|---|
|  | 103 | while(lenthis2 && lenin2) { | 
|---|
|  | 104 | if(!sensitive) { | 
|---|
|  | 105 | if(toupper(*this) != toupper(*in)) | 
|---|
|  | 106 | break; | 
|---|
|  | 107 | else { | 
|---|
|  | 108 | this++; | 
|---|
|  | 109 | in++; | 
|---|
|  | 110 | lenthis2--; | 
|---|
|  | 111 | lenin2--; | 
|---|
|  | 112 | } | 
|---|
|  | 113 | } | 
|---|
|  | 114 | else { | 
|---|
|  | 115 | if(*this != *in) | 
|---|
|  | 116 | break; | 
|---|
|  | 117 | else { | 
|---|
|  | 118 | this++; | 
|---|
|  | 119 | in++; | 
|---|
|  | 120 | lenthis2--; | 
|---|
|  | 121 | lenin2--; | 
|---|
|  | 122 | } | 
|---|
|  | 123 | } | 
|---|
|  | 124 | } | 
|---|
|  | 125 | if(lenthis2) { | 
|---|
|  | 126 | lenin--; | 
|---|
|  | 127 | findin++; | 
|---|
|  | 128 | } | 
|---|
|  | 129 | } while(lenin && lenthis2); | 
|---|
|  | 130 | return (lenthis2) ? NULL : in - lenthis; | 
|---|
|  | 131 | } | 
|---|
|  | 132 |  | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.