35 #define MAX_LENGTH 1024
61 m[mc->
n * ch + wno] |= 1<<off;
70 return m[mc->
n * ch + wno] & (1<<off);
80 mc->
fact = (range+1)*mc->
n;
91 xfree((*mc)->match_mask);
97 struct DFA *dfa,
int ch)
102 for (j = 0; j<mc->
n; j++)
116 if (ch >= state->
trans[i].
ch[0] &&
125 if (ch >= state->
trans[i].
ch[0] &&
134 if (ch >= state->
trans[i].
ch[0] &&
143 if (ch >= state->
trans[i].
ch[0] &&
161 for (j = 0; j<mc->
n; j++)
211 for (i = 0; i<mc->
n; i++)
212 Rdst[i] = Rsrc1[i] | Rsrc2[i];
223 for (d = 1; d <= mc->
range; d++)
225 or(mc, Rtmp, Rj, Rj1);
227 shift(mc, Rtmp_2, Rtmp, dfa);
231 or(mc, Rtmp, Rtmp_2, Rtmp);
235 or(mc, Rj1, Rtmp, Rj);
246 int (*userfunc)(
char *,
const char *,
void *),
258 indxp = (
short*) ((
char*) p+
DICT_bsize(p)-
sizeof(short));
269 info = (
char*)p + indxp[-lo];
280 if (pos+j > *max_pos)
286 int ret = userfunc((
char*) prefix,
297 move(mc, Rj1, Rj0, ch, dfa, Rj_tmp, range);
298 for (d = mc->
n; --d >= 0; )
299 if (Rj1[range*mc->
n + d])
304 for (d = mc->
n; --d >= 0; )
323 info = (
char*)p - indxp[-lo];
333 move(mc, Rj1, Rj, ch, dfa, Rj_tmp, range);
334 for (d = mc->
n; --d >= 0; )
335 if (Rj1[range*mc->
n + d])
342 for (d = mc->
n; --d >= 0; )
347 ret = userfunc((
char*) prefix,
355 memcpy(&subptr, info,
sizeof(
Dict_ptr));
358 int ret =
grep(
dict, subptr, mc, Rj1, pos+1,
359 client, userfunc, prefix, dfa, max_pos,
365 indxp = (
short*) ((
char*) p+
DICT_bsize(p)-
sizeof(short));
376 int (*userfunc)(
char *name,
const char *info,
381 const char *this_pattern = pattern;
395 yaz_log(YLOG_DEBUG,
"dict_lookup_grep range=%d", range);
396 for (i = 0; pattern[i]; i++)
398 yaz_log(YLOG_DEBUG,
" %2d %3d %c", i, pattern[i],
399 (pattern[i] >
' ' && pattern[i] < 127) ? pattern[i] :
'?');
405 if (i || *this_pattern)
407 yaz_log(YLOG_WARN,
"dfa_parse fail=%d", i);
418 for (d = 1; d<=mc->
range; d++)
421 memcpy(Rj + mc->
n * d, Rj + mc->
n * (d-1), mc->
n *
sizeof(*Rj));
438 yaz_log(YLOG_DEBUG,
"max_pos = %d", *max_pos);
446 const char **(*cmap)(
void *vp,
const char **from,
int len))
static void init_pos(struct DFA_parse *parse_info)
void dfa_anyset_includes_nl(struct DFA *dfa)
int dfa_parse(struct DFA *, const char **)
void dfa_mkstate(struct DFA *)
void dfa_delete(struct DFA **)
void dfa_set_cmap(struct DFA *dfa, void *vp, const char **(*cmap)(void *vp, const char **from, int len))
struct DFA * dfa_init(void)
int dict_bf_readp(Dict_BFile bf, int no, void **bufp)
static INLINE void set_bit(MatchContext *mc, MatchWord *m, int ch, int state)
static int grep(Dict dict, Dict_ptr ptr, MatchContext *mc, MatchWord *Rj, int pos, void *client, int(*userfunc)(char *, const char *, void *), Dict_char *prefix, struct DFA *dfa, int *max_pos, int init_pos)
static void mask_shift(MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc, struct DFA *dfa, int ch)
void dict_grep_cmap(Dict dict, void *vp, const char **(*cmap)(void *vp, const char **from, int len))
install character mapping handler for dict_lookup_grep
static void or(MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc1, MatchWord *Rsrc2)
static INLINE MatchWord get_bit(MatchContext *mc, MatchWord *m, int ch, int state)
static void rm_MatchContext(MatchContext **mc)
static INLINE int move(MatchContext *mc, MatchWord *Rj1, MatchWord *Rj, Dict_char ch, struct DFA *dfa, MatchWord *Rtmp, int range)
static void shift(MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc, struct DFA *dfa)
int dict_lookup_grep(Dict dict, const char *pattern, int range, void *client, int *max_pos, int init_pos, int(*userfunc)(char *name, const char *info, void *client))
regular expression search with error correction
static MatchContext * mk_MatchContext(struct DFA *dfa, int range)
struct DFA_state ** states
const char **(* grep_cmap)(void *vp, const char **from, int len)