X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=index%2Fregxread.c;h=ecf8f9526304f0f4680249ac9460ba37bcd68cbe;hp=95bf213fea83f34161a7be8026e52a524956c2d7;hb=97a7adeb9e5059463f039495cc01cfa448463a27;hpb=7415d28c149c1bab51fe93aeaccdd14085b69bd9 diff --git a/index/regxread.c b/index/regxread.c index 95bf213..ecf8f95 100644 --- a/index/regxread.c +++ b/index/regxread.c @@ -1,8 +1,5 @@ -/* $Id: regxread.c,v 1.1 2006-07-03 14:27:09 adam Exp $ - Copyright (C) 1995-2005 - Index Data ApS - -This file is part of the Zebra server. +/* This file is part of the Zebra server. + Copyright (C) 1995-2008 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 @@ -15,9 +12,9 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with Zebra; see the file LICENSE.zebra. If not, write to the -Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ #include @@ -115,15 +112,15 @@ struct lexSpec { #if HAVE_TCL_H Tcl_Interp *tcl_interp; #endif - void *f_win_fh; - void (*f_win_ef)(void *, off_t); + struct ZebraRecStream *stream; + off_t (*f_win_ef)(struct ZebraRecStream *s, off_t *); int f_win_start; /* first byte of buffer is this file offset */ int f_win_end; /* last byte of buffer is this offset - 1 */ int f_win_size; /* size of buffer */ char *f_win_buf; /* buffer itself */ - int (*f_win_rf)(void *, char *, size_t); - off_t (*f_win_sf)(void *, off_t); + int (*f_win_rf)(struct ZebraRecStream *, char *, size_t); + off_t (*f_win_sf)(struct ZebraRecStream *, off_t); struct lexConcatBuf *concatBuf; int maxLevel; @@ -154,12 +151,12 @@ static char *f_win_get (struct lexSpec *spec, off_t start_pos, off_t end_pos, } if (off < 0 || start_pos >= spec->f_win_end) { - (*spec->f_win_sf)(spec->f_win_fh, start_pos); + (*spec->f_win_sf)(spec->stream, start_pos); spec->f_win_start = start_pos; if (!spec->f_win_buf) spec->f_win_buf = (char *) xmalloc (spec->f_win_size); - *size = (*spec->f_win_rf)(spec->f_win_fh, spec->f_win_buf, + *size = (*spec->f_win_rf)(spec->stream, spec->f_win_buf, spec->f_win_size); spec->f_win_end = spec->f_win_start + *size; @@ -169,7 +166,7 @@ static char *f_win_get (struct lexSpec *spec, off_t start_pos, off_t end_pos, } for (i = 0; if_win_end - start_pos; i++) spec->f_win_buf[i] = spec->f_win_buf[i + off]; - r = (*spec->f_win_rf)(spec->f_win_fh, + r = (*spec->f_win_rf)(spec->stream, spec->f_win_buf + i, spec->f_win_size - i); spec->f_win_start = start_pos; @@ -646,7 +643,7 @@ int readFileSpec (struct lexSpec *spec) } } fclose (spec_inf); - wrbuf_free(lineBuf, 1); + wrbuf_destroy(lineBuf); for (lc = spec->context; lc; lc = lc->next) { @@ -1692,7 +1689,7 @@ static int execRule (struct lexSpec *spec, struct lexContext *context, start_ptr, pptr); } -data1_node *lexNode (struct lexSpec *spec, int *ptr) +int lexNode (struct lexSpec *spec, int *ptr) { struct lexContext *context = spec->context_stack[spec->context_stack_top]; struct DFA_state *state = context->dfa->states[0]; @@ -1704,6 +1701,7 @@ data1_node *lexNode (struct lexSpec *spec, int *ptr) int last_ptr = *ptr; /* last char of match */ int start_ptr = *ptr; /* first char of match */ int skip_ptr = *ptr; /* first char of run */ + int more = 0; while (1) { @@ -1726,7 +1724,7 @@ data1_node *lexNode (struct lexSpec *spec, int *ptr) *ptr = last_ptr; /* execute rule */ if (!execRule (spec, context, last_rule, start_ptr, ptr)) - break; + return more; /* restore skip pointer */ skip_ptr = *ptr; last_rule = 0; @@ -1739,8 +1737,9 @@ data1_node *lexNode (struct lexSpec *spec, int *ptr) buf = f_win_get (spec, skip_ptr, *ptr, &size); execDataP (spec, buf, size, 0); } + state = context->dfa->states[0]; if (*ptr == F_WIN_EOF) - break; + return more; } t = state->trans; i = state->tran_no; @@ -1763,12 +1762,13 @@ data1_node *lexNode (struct lexSpec *spec, int *ptr) { if (spec->f_win_ef && *ptr != F_WIN_EOF) { + off_t end_offset = *ptr; #if REGX_DEBUG yaz_log (YLOG_LOG, "regx: endf ptr=%d", *ptr); #endif - (*spec->f_win_ef)(spec->f_win_fh, *ptr); + (*spec->f_win_ef)(spec->stream, &end_offset); } - return NULL; + return more; } context = spec->context_stack[spec->context_stack_top]; skip_ptr = *ptr; @@ -1803,13 +1803,14 @@ data1_node *lexNode (struct lexSpec *spec, int *ptr) last_rule = state->rule_nno; last_ptr = *ptr; } + more = 1; } break; } else t++; } - return NULL; + return more; } static data1_node *lexRoot (struct lexSpec *spec, off_t offset, @@ -1817,6 +1818,7 @@ static data1_node *lexRoot (struct lexSpec *spec, off_t offset, { struct lexContext *lt = spec->context; int ptr = offset; + int ret; spec->stop_flag = 0; spec->d1_level = 0; @@ -1842,12 +1844,15 @@ static data1_node *lexRoot (struct lexSpec *spec, off_t offset, } #endif execAction (spec, lt->beginActionList, ptr, &ptr); - lexNode (spec, &ptr); + + ret = lexNode (spec, &ptr); while (spec->d1_level) { tagDataRelease (spec); (spec->d1_level)--; } + if (!ret) + return 0; execAction (spec, lt->endActionList, ptr, &ptr); return spec->d1_stack[0]; } @@ -1884,6 +1889,7 @@ data1_node *grs_read_regx (struct grs_read_info *p) int res; struct lexSpecs *specs = (struct lexSpecs *) p->clientData; struct lexSpec **curLexSpec = &specs->spec; + off_t start_offset; #if REGX_DEBUG yaz_log (YLOG_LOG, "grs_read_regx"); @@ -1901,18 +1907,19 @@ data1_node *grs_read_regx (struct grs_read_info *p) } } (*curLexSpec)->dh = p->dh; - if (!p->offset) + start_offset = p->stream->tellf(p->stream); + if (start_offset == 0) { (*curLexSpec)->f_win_start = 0; (*curLexSpec)->f_win_end = 0; - (*curLexSpec)->f_win_rf = p->readf; - (*curLexSpec)->f_win_sf = p->seekf; - (*curLexSpec)->f_win_fh = p->fh; - (*curLexSpec)->f_win_ef = p->endf; + (*curLexSpec)->f_win_rf = p->stream->readf; + (*curLexSpec)->f_win_sf = p->stream->seekf; + (*curLexSpec)->stream = p->stream; + (*curLexSpec)->f_win_ef = p->stream->endf; (*curLexSpec)->f_win_size = 500000; } (*curLexSpec)->m = p->mem; - return lexRoot (*curLexSpec, p->offset, "main"); + return lexRoot (*curLexSpec, start_offset, "main"); } static int extract_regx(void *clientData, struct recExtractCtrl *ctrl) @@ -1942,6 +1949,7 @@ data1_node *grs_read_tcl (struct grs_read_info *p) int res; struct lexSpecs *specs = (struct lexSpecs *) p->clientData; struct lexSpec **curLexSpec = &specs->spec; + off_t start_offset; #if REGX_DEBUG yaz_log (YLOG_LOG, "grs_read_tcl"); @@ -1968,18 +1976,19 @@ data1_node *grs_read_tcl (struct grs_read_info *p) } } (*curLexSpec)->dh = p->dh; - if (!p->offset) + start_offset = p->stream->tellf(p->stream); + if (start_offset == 0) { (*curLexSpec)->f_win_start = 0; (*curLexSpec)->f_win_end = 0; - (*curLexSpec)->f_win_rf = p->readf; - (*curLexSpec)->f_win_sf = p->seekf; - (*curLexSpec)->f_win_fh = p->fh; - (*curLexSpec)->f_win_ef = p->endf; + (*curLexSpec)->f_win_rf = p->stream->readf; + (*curLexSpec)->f_win_sf = p->stream->seekf; + (*curLexSpec)->stream = p->stream; + (*curLexSpec)->f_win_ef = p->stream->endf; (*curLexSpec)->f_win_size = 500000; } (*curLexSpec)->m = p->mem; - return lexRoot (*curLexSpec, p->offset, "main"); + return lexRoot (*curLexSpec, start_offset, "main"); } static int extract_tcl(void *clientData, struct recExtractCtrl *ctrl)