#include #define ARRAY_1_SIZE 255 unsigned char toupper(unsigned char c) { if ((c>='a' && c<='z')) return c-32; return c; } void bm_init_array(unsigned char *motif, unsigned char *dest,int size, unsigned char *dest2) { int i,j ; unsigned char c; for(i=size;i>=0; i--) { j=i-1; c=toupper(motif[i]); if (dest2[c]==0) { dest2[c]=i+1; } while (1) { if (c==toupper(motif[j])) { dest[i]=(i-j+1); break; } if(j==0) { dest[i]=0; break; } j--; } } } int bm(unsigned char *text,int text_size, unsigned char *motif, int motif_size,unsigned char *array_2, unsigned char *array_1) { int retour = 0; int i,index1,index2,index3; unsigned char c,d; memset(array_2,0,(motif_size)); memset(array_1,0,(ARRAY_1_SIZE)); preambule(motif, array_2, motif_size+1, array_1); /* for (i=0;itext_size) { retour=2; break; } } else { index3=index1; index2=motif_size; while (1) { if (index2==0) { retour=1; break; } index2--; index1--; if (toupper(motif[index2])!=toupper(text[index1])) { // printf("!!!%c::%c!!%d::%d\n",text[index1],motif[index2],index1,index2); if(array_2[motif_size]!=0) index1=index3+(array_2[motif_size])-1; else index1=index3+(motif_size)-1; break; } } } } if (retour==1) return 1; else return 0; }