OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / user / netflash / kmp.h
1 #ifndef KMP_H
2 #define KMP_H
3
4 /* Implementation of the Knuth-Morris-Pratt fast searching algorithm
5  * from http://www-igm.univ-mlv.fr/~lecroq/string/node8.html
6  */
7
8 typedef int getblock_function(const char **text, void *cookie);
9
10 /**
11  * Searches for an exact string match for 'x' of length 'm' in a stream
12  * Using the Knuth-Morris-Pratt algorith.
13  *
14  * 'getter' returns one character at a time from the stream
15  * and EOF at end of file. 'cookie' is passed to 'getter'.
16  *
17  * If a match is found, returns the offset character JUST PAST THE END OF THE MATCH.
18  * e.g. KMP("abc", "xxabcyy") will return 5.
19  * The input stream will be read to this point.
20  *
21  * Returns -1 if the string is not found.
22  */
23 int KMP(const char *x, int m, getblock_function *getter, void *cookie);
24
25 #endif