X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=recctrl%2Frectext.c;h=99957160e14c15d27e8f2c9242750ece899e18ec;hb=896c0427df9d8eff5de6a1735dcd992e067df844;hp=a3177513f77162bf2e6b8509f5bcfae9edbf19a3;hpb=db4634a724c423fc5d2facda6e9e11d959c13617;p=idzebra-moved-to-github.git diff --git a/recctrl/rectext.c b/recctrl/rectext.c index a317751..9995716 100644 --- a/recctrl/rectext.c +++ b/recctrl/rectext.c @@ -1,46 +1,26 @@ -/* - * Copyright (C) 1994-1995, Index Data I/S - * All rights reserved. - * Sebastian Hammer, Adam Dickmeiss - * - * $Log: rectext.c,v $ - * Revision 1.4 1996-11-04 14:09:16 adam - * Minor changes. - * - * Revision 1.3 1996/11/01 09:00:33 adam - * This simple "text" format now supports element specs B and M. - * - * Revision 1.2 1996/10/29 14:02:45 adam - * Uses buffered read to speed up things. - * - * Revision 1.1 1996/10/11 10:57:28 adam - * New module recctrl. Used to manage records (extract/retrieval). - * - * Revision 1.7 1996/01/17 14:57:55 adam - * Prototype changed for reader functions in extract/retrieve. File - * is identified by 'void *' instead of 'int. - * - * Revision 1.6 1995/10/10 13:59:24 adam - * Function rset_open changed its wflag parameter to general flags. - * - * Revision 1.5 1995/10/02 16:24:39 adam - * Use attribute actually used in search requests. - * - * Revision 1.4 1995/10/02 15:42:55 adam - * Extract uses file descriptors instead of FILE pointers. - * - * Revision 1.3 1995/09/28 09:19:45 adam - * xfree/xmalloc used everywhere. - * Extract/retrieve method seems to work for text records. - * - * Revision 1.2 1995/09/15 14:45:21 adam - * Retrieve control. - * Work on truncation. - * - * Revision 1.1 1995/09/14 07:48:25 adam - * Record control management. - * - */ +/* $Id: rectext.c,v 1.15 2002-08-02 19:26:56 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 + Index Data Aps + +This file is part of the Zebra server. + +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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +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. +*/ + + #include #include #include @@ -48,7 +28,12 @@ #include #include "rectext.h" -static void text_init (void) +static void *text_init (RecType recType) +{ + return 0; +} + +static void text_destroy (void *clientData) { } @@ -61,10 +46,10 @@ struct buf_info { struct buf_info *buf_open (struct recExtractCtrl *p) { - struct buf_info *fi = xmalloc (sizeof(*fi)); + struct buf_info *fi = (struct buf_info *) xmalloc (sizeof(*fi)); fi->p = p; - fi->buf = xmalloc (4096); + fi->buf = (char *) xmalloc (4096); fi->offset = 1; fi->max = 1; return fi; @@ -91,41 +76,37 @@ void buf_close (struct buf_info *fi) xfree (fi); } -static int text_extract (struct recExtractCtrl *p) +static int text_extract (void *clientData, struct recExtractCtrl *p) { - char w[256]; + char w[512]; RecWord recWord; - int r, seqno = 1; + int r; struct buf_info *fi = buf_open (p); - (*p->init)(&recWord); - recWord.which = Word_String; + (*p->init)(p, &recWord); + recWord.reg_type = 'w'; do { int i = 0; r = buf_read (fi, w); - while (r > 0 && i < 255 && isalnum(w[i])) + while (r > 0 && i < 511 && w[i] != '\n' && w[i] != '\r') { i++; r = buf_read (fi, w + i); } if (i) { - int j; - for (j = 0; jadd)(&recWord); + recWord.string = w; + recWord.length = i; + (*p->tokenAdd)(&recWord); } } while (r > 0); buf_close (fi); - return 0; + return RECCTRL_EXTRACT_OK; } -static int text_retrieve (struct recRetrieveCtrl *p) +static int text_retrieve (void *clientData, struct recRetrieveCtrl *p) { int r, text_ptr = 0; static char *text_buf = NULL; @@ -138,6 +119,9 @@ static int text_retrieve (struct recRetrieveCtrl *p) p->comp->u.simple->which == Z_ElementSetNames_generic) elementSetName = p->comp->u.simple->u.generic; + /* don't make header for the R(aw) element set name */ + if (elementSetName && !strcmp(elementSetName, "R")) + start_flag = 0; while (1) { if (text_ptr + 4096 >= text_size) @@ -145,7 +129,7 @@ static int text_retrieve (struct recRetrieveCtrl *p) char *nb; text_size = 2*text_size + 8192; - nb = xmalloc (text_size); + nb = (char *) xmalloc (text_size); if (text_buf) { memcpy (nb, text_buf, text_ptr); @@ -199,6 +183,7 @@ static int text_retrieve (struct recRetrieveCtrl *p) static struct recType text_type = { "text", text_init, + text_destroy, text_extract, text_retrieve };