pcb 4.1.1
An interactive printed circuit board layout editor.

strcasestr.c

Go to the documentation of this file.
00001 
00029 #ifdef HAVE_CONFIG_H
00030 #include "config.h"
00031 #endif
00032 
00033 #include <stdio.h>
00034 #include <ctype.h>
00035 #ifdef HAVE_STDLIB_H
00036 #include <stdlib.h>
00037 #endif
00038 #ifdef HAVE_STRING_H
00039 #include <string.h>
00040 #endif
00041 
00042 #if !HAVE_STRCASESTR
00043 /*
00044  * strcasestr() is non-standard so provide a replacement
00045  * when missing
00046  */
00047 char * strcasestr(const char *big, const char *little)
00048 {
00049   char *b, *l, *p;
00050 
00051   b = strdup(big);
00052   if(b == NULL ) {
00053     return NULL;
00054   }
00055 
00056   l = strdup(little);
00057   if(l == NULL ) {
00058     free(b);
00059     return NULL;
00060   }
00061 
00062 
00063   p = b;
00064   while(*p != '\0') {
00065     if (islower(*p)) {
00066       *p = (char) toupper( (int) *p);
00067     }
00068     p++;
00069   }
00070 
00071   p = l;
00072   while(*p != '\0') {
00073     if (islower(*p)) {
00074       *p = (char) toupper( (int) *p);
00075     }
00076     p++;
00077   }
00078 
00079 
00080   /* cheat and do this the easy.  Convert to upper case,
00081    * use strstr, and then figure out an offset in *big
00082    */
00083   p = strstr(b, l);
00084   if (p == NULL) {
00085     free(b);
00086     free(l);
00087     return NULL;
00088   }
00089 
00090   p = (char *) big + (p - b);
00091   free(b);
00092   free(l);
00093   return p;
00094 }
00095 #endif