Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

nix-common/stringsearch.c

Go to the documentation of this file.
00001 
00008 #include <sys/types.h>
00009 #include <unistd.h>
00010 #include <stdlib.h>
00011 #include <string.h>
00012 #include <stdio.h>
00013 
00014 #include <stringsearch.h>
00015 
00023 static void
00024 fillBM(const char *srch, size_t srch_len, size_t *bml, size_t bm_len)
00025 {
00026         size_t i;
00027         for (i = 0; i < bm_len; i++)
00028                 bml[i] = srch_len;
00029         for (i = 0; i < srch_len - 1; i++, srch++)
00030                 bml[(size_t)*srch] = srch_len - i - 1;
00031 }
00032 
00033 #define ASIZE   256
00034 
00035 void *
00036 inMem(const char *space, size_t space_len, const char *item,
00037     size_t item_len)
00038 {
00039         /* const char *srch_end = srch_space + srch_len;
00040         const char *item_end = srch_item + item_len; */
00041         size_t bmbc[ASIZE];
00042         unsigned char *aj, *maxj;
00043         unsigned char c;
00044         unsigned char lic;
00045 
00046         if ((space_len < item_len))
00047                 return (NULL);
00048 
00049         fillBM(item, item_len, bmbc, ASIZE);
00050 
00051         /*
00052         for (j = 0; j < ASIZE; j++)
00053                 if (bmbc[j] != item_len)
00054                         if (j < 32 || j > 127)
00055                                 printf("bmbc['%d'] == %ld\n", j, (long)bmbc[j]);
00056                         else
00057                                 printf("bmbc['%c'] == %ld\n", j, (long)bmbc[j]);
00058 
00059         */
00060 
00061         aj = (char *)space;
00062         maxj  = (char *)(space + (space_len - item_len));
00063 
00064         lic = item[item_len - 1];
00065 
00066         while (aj <= maxj) {
00067                 c = aj[item_len - 1];
00068                 if (lic == c) {
00069                         if (memcmp(item,
00070                             aj, item_len - 1) == 0) {
00071                         return ((void *)(aj));
00072                 }
00073                 }
00074                 aj += bmbc[(size_t)c];
00075         }
00076         return (NULL);
00077 }
00078 

Generated on Mon Aug 30 19:44:15 2004 for pocketcity by doxygen1.2.18