X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=dict%2Flookgrep.c;h=a503d25e9d22499fd48cf48f1f1c30b8628ff07b;hp=ebd54b7822945946cfcfe60e2f8b28a9bb830cd7;hb=HEAD;hpb=ac13dceecd5f75669820819575daf88e0add5c8d diff --git a/dict/lookgrep.c b/dict/lookgrep.c index ebd54b7..a503d25 100644 --- a/dict/lookgrep.c +++ b/dict/lookgrep.c @@ -1,5 +1,5 @@ /* This file is part of the Zebra server. - Copyright (C) 1994-2011 Index Data + Copyright (C) Index Data Zebra is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -34,11 +34,11 @@ typedef unsigned MatchWord; #define WORD_BITS 32 #define MAX_LENGTH 1024 -/* This code is based +/* This code is based * Sun Wu and Udi Manber: Fast Text Searching Allowing Errors. * Communications of the ACM, pp. 83-91, Vol. 35, No. 10, Oct. 1992, USA. * PostScript version of the paper in its submitted form: agrep1.ps) - * recommended reading to understand AGREP ! + * recommended reading to understand AGREP ! * * http://www.tgries.de/agrep/#AGREP1PS * http://www.tgries.de/agrep/doc/agrep1ps.zip @@ -51,13 +51,13 @@ typedef struct { MatchWord *match_mask; /* match_mask */ } MatchContext; -#define INLINE +#define INLINE static INLINE void set_bit(MatchContext *mc, MatchWord *m, int ch, int state) { int off = state & (WORD_BITS-1); int wno = state / WORD_BITS; - + m[mc->n * ch + wno] |= 1<range; d++) { or(mc, Rtmp, Rj, Rj1); /* 2,3 */ - + shift(mc, Rtmp_2, Rtmp, dfa); mask_shift(mc, Rtmp, Rj+mc->n, dfa, ch); /* 1 */ - + or(mc, Rtmp, Rtmp_2, Rtmp); /* 1,2,3*/ Rj1 += mc->n; - + or(mc, Rj1, Rtmp, Rj); /* 1,2,3,4 */ Rj += mc->n; @@ -283,7 +283,7 @@ static int grep(Dict dict, Dict_ptr ptr, MatchContext *mc, { if (was_match) { - int ret = userfunc((char*) prefix, + int ret = userfunc((char*) prefix, info+(j+1)*sizeof(Dict_char), client); if (ret) return ret; @@ -323,7 +323,7 @@ static int grep(Dict dict, Dict_ptr ptr, MatchContext *mc, info = (char*)p - indxp[-lo]; memcpy(&ch, info+sizeof(Dict_ptr), sizeof(Dict_char)); prefix[pos] = ch; - + if (pos > *max_pos) *max_pos = pos; if (pos >= init_pos) @@ -398,7 +398,7 @@ int dict_lookup_grep(Dict dict, const char *pattern, int range, void *client, yaz_log(YLOG_DEBUG, " %2d %3d %c", i, pattern[i], (pattern[i] > ' ' && pattern[i] < 127) ? pattern[i] : '?'); } - + dfa_set_cmap(dfa, dict->grep_cmap_data, dict->grep_cmap); i = dfa_parse(dfa, &this_pattern); @@ -412,7 +412,7 @@ int dict_lookup_grep(Dict dict, const char *pattern, int range, void *client, mc = mk_MatchContext(dfa, range); - Rj = (MatchWord *) xcalloc((MAX_LENGTH+1) * mc->n, sizeof(*Rj)); + Rj = (MatchWord *) xcalloc((MAX_LENGTH+2) * mc->fact, sizeof(*Rj)); set_bit (mc, Rj, 0, 0); for (d = 1; d<=mc->range; d++)