38 #include <linux/kernel.h>
39 #include <linux/module.h>
40 #include <linux/types.h>
41 #include <linux/string.h>
42 #include <linux/ctype.h>
51 #define DEBUGP(args, format...)
64 struct ts_bm *bm = ts_config_priv(conf);
65 unsigned int i, text_len, consumed = state->
offset;
67 int shift = bm->
patlen - 1, bs;
76 while (shift < text_len) {
77 DEBUGP(
"Searching in position %d (%c)\n",
79 for (i = 0; i < bm->
patlen; i++)
80 if ((icase ?
toupper(text[shift-i])
87 return consumed += (shift-(bm->
patlen-1));
100 static int subpattern(
u8 *
pattern,
int i,
int j,
int g)
102 int x = i+g-1,
y = j+g-1,
ret = 0;
104 while(pattern[x--] == pattern[y--]) {
110 ret = pattern[i-1] != pattern[j-1];
118 static void compute_prefix_tbl(
struct ts_bm *bm,
int flags)
122 for (i = 0; i <
ASIZE; i++)
134 for (i = 1; i < bm->
patlen; i++)
136 for (i = bm->
patlen-1, g = 1; i > 0; g++, i--) {
137 for (j = i-1; j >= 1-g ; j--)
138 if (subpattern(bm->
pattern, i, j, g)) {
145 static struct ts_config *bm_init(
const void *pattern,
unsigned int len,
151 unsigned int prefix_tbl_len = len *
sizeof(
unsigned int);
152 size_t priv_size =
sizeof(*bm) + len + prefix_tbl_len;
154 conf = alloc_ts_config(priv_size, gfp_mask);
159 bm = ts_config_priv(conf);
163 for (i = 0; i < len; i++)
167 compute_prefix_tbl(bm, flags);
172 static void *bm_get_pattern(
struct ts_config *conf)
174 struct ts_bm *bm = ts_config_priv(conf);
178 static unsigned int bm_get_pattern_len(
struct ts_config *conf)
180 struct ts_bm *bm = ts_config_priv(conf);
184 static struct ts_ops bm_ops = {
188 .get_pattern = bm_get_pattern,
189 .get_pattern_len = bm_get_pattern_len,
194 static int __init init_bm(
void)
199 static void __exit exit_bm(
void)