33 #include <linux/module.h>
34 #include <linux/types.h>
35 #include <linux/string.h>
36 #include <linux/ctype.h>
48 struct ts_kmp *kmp = ts_config_priv(conf);
49 unsigned int i,
q = 0, text_len, consumed = state->
offset;
59 for (i = 0; i < text_len; i++) {
61 != (icase ?
toupper(text[i]) : text[i]))
64 == (icase ?
toupper(text[i]) : text[i]))
67 state->
offset = consumed + i + 1;
78 static inline void compute_prefix_tbl(
const u8 *
pattern,
unsigned int len,
84 for (k = 0, q = 1; q < len; q++) {
85 while (k > 0 && (icase ?
toupper(pattern[k]) : pattern[k])
86 != (icase ?
toupper(pattern[q]) : pattern[q]))
88 if ((icase ?
toupper(pattern[k]) : pattern[k])
89 == (icase ?
toupper(pattern[q]) : pattern[q]))
95 static struct ts_config *kmp_init(
const void *pattern,
unsigned int len,
101 unsigned int prefix_tbl_len = len *
sizeof(
unsigned int);
102 size_t priv_size =
sizeof(*kmp) + len + prefix_tbl_len;
104 conf = alloc_ts_config(priv_size, gfp_mask);
109 kmp = ts_config_priv(conf);
111 compute_prefix_tbl(pattern, len, kmp->
prefix_tbl, flags);
113 if (flags & TS_IGNORECASE)
114 for (i = 0; i < len; i++)
122 static void *kmp_get_pattern(
struct ts_config *conf)
124 struct ts_kmp *kmp = ts_config_priv(conf);
128 static unsigned int kmp_get_pattern_len(
struct ts_config *conf)
130 struct ts_kmp *kmp = ts_config_priv(conf);
134 static struct ts_ops kmp_ops = {
138 .get_pattern = kmp_get_pattern,
139 .get_pattern_len = kmp_get_pattern_len,
144 static int __init init_kmp(
void)
149 static void __exit exit_kmp(
void)