Category : C Source Code
Archive   : FASTGREP.ZIP
Filename : MAKESKIP.C
extern char *calloc();
MakeSkip(Pattern,Skip1,Skip2,PatLen)
char Pattern[];
int Skip1[], Skip2[];
int PatLen;
/* generate the skip tables for Boyer-Moore string search algorithm.
* Skip1 is the skip depending on the character which failed to match
* the pattern, and Skip2 is the skip depending on how far we got into
* the pattern. Pattern is the search pattern and PatLen is strlen(Pattern) */
{
int *BackTrack; /* backtracking table for t when building skip2 */
int c; /* general purpose constant */
int j,k,t,tp; /* indices into Skip's and BackTrack */
BackTrack = (int *) calloc(PatLen,sizeof (int));
for (c=0; c<=MAXCHAR; ++c)
{
Skip1[c] = PatLen;
}
for (k=0;k
Skip1[Pattern[k]] = PatLen - k - 1;
Skip2[k] = 2 * PatLen - k - 1;
} /* for */
for (j=PatLen - 1,t=PatLen;j >= 0; --j,--t)
{
BackTrack[j] = t;
while (t
Skip2[t] = min(Skip2[t], PatLen - j - 1);
t = BackTrack[t];
} /* while */
} /* for */
for (k=0;k<=t;++k)
{
Skip2[k] = min(Skip2[k],PatLen+t-k);
}
tp=BackTrack[t];
while(tp
while(t
Skip2[t] = min(Skip2[t],tp-t+PatLen);
++t;
} /* while */
tp = BackTrack[tp];
} /* while */
free(BackTrack);
} /* MakeSkip */
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/