2 * Copyright (C) 1994-1998, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.13 1999-09-07 07:19:21 adam
8 * Work on character mapping. Implemented replace rules.
10 * Revision 1.12 1999/05/26 07:49:14 adam
13 * Revision 1.11 1999/05/21 12:00:17 adam
14 * Better diagnostics for extraction process.
16 * Revision 1.10 1999/05/20 12:57:18 adam
17 * Implemented TCL filter. Updated recctrl system.
19 * Revision 1.9 1998/10/16 08:14:38 adam
20 * Updated record control system.
22 * Revision 1.8 1998/05/20 10:12:27 adam
23 * Implemented automatic EXPLAIN database maintenance.
24 * Modified Zebra to work with ASN.1 compiled version of YAZ.
26 * Revision 1.7 1998/03/11 11:19:05 adam
27 * Changed the way sequence numbers are generated.
29 * Revision 1.6 1998/02/10 12:03:06 adam
32 * Revision 1.5 1997/10/27 14:33:06 adam
33 * Moved towards generic character mapping depending on "structure"
34 * field in abstract syntax file. Fixed a few memory leaks. Fixed
35 * bug with negative integers when doing searches with relational
38 * Revision 1.4 1996/11/04 14:09:16 adam
41 * Revision 1.3 1996/11/01 09:00:33 adam
42 * This simple "text" format now supports element specs B and M.
44 * Revision 1.2 1996/10/29 14:02:45 adam
45 * Uses buffered read to speed up things.
47 * Revision 1.1 1996/10/11 10:57:28 adam
48 * New module recctrl. Used to manage records (extract/retrieval).
50 * Revision 1.7 1996/01/17 14:57:55 adam
51 * Prototype changed for reader functions in extract/retrieve. File
52 * is identified by 'void *' instead of 'int.
54 * Revision 1.6 1995/10/10 13:59:24 adam
55 * Function rset_open changed its wflag parameter to general flags.
57 * Revision 1.5 1995/10/02 16:24:39 adam
58 * Use attribute actually used in search requests.
60 * Revision 1.4 1995/10/02 15:42:55 adam
61 * Extract uses file descriptors instead of FILE pointers.
63 * Revision 1.3 1995/09/28 09:19:45 adam
64 * xfree/xmalloc used everywhere.
65 * Extract/retrieve method seems to work for text records.
67 * Revision 1.2 1995/09/15 14:45:21 adam
71 * Revision 1.1 1995/09/14 07:48:25 adam
72 * Record control management.
82 static void *text_init (RecType recType)
87 static void text_destroy (void *clientData)
92 struct recExtractCtrl *p;
98 struct buf_info *buf_open (struct recExtractCtrl *p)
100 struct buf_info *fi = (struct buf_info *) xmalloc (sizeof(*fi));
103 fi->buf = (char *) xmalloc (4096);
109 int buf_read (struct buf_info *fi, char *dst)
111 if (fi->offset >= fi->max)
115 fi->max = (*fi->p->readf)(fi->p->fh, fi->buf, 4096);
120 *dst = fi->buf[(fi->offset)++];
124 void buf_close (struct buf_info *fi)
130 static int text_extract (void *clientData, struct recExtractCtrl *p)
135 struct buf_info *fi = buf_open (p);
137 (*p->init)(p, &recWord);
138 recWord.reg_type = 'w';
143 r = buf_read (fi, w);
144 while (r > 0 && i < 511 && w[i] != '\n' && w[i] != '\r')
147 r = buf_read (fi, w + i);
153 (*p->tokenAdd)(&recWord);
157 return RECCTRL_EXTRACT_OK;
160 static int text_retrieve (void *clientData, struct recRetrieveCtrl *p)
163 static char *text_buf = NULL;
164 static int text_size = 0;
166 const char *elementSetName = NULL;
169 if (p->comp && p->comp->which == Z_RecordComp_simple &&
170 p->comp->u.simple->which == Z_ElementSetNames_generic)
171 elementSetName = p->comp->u.simple->u.generic;
175 if (text_ptr + 4096 >= text_size)
179 text_size = 2*text_size + 8192;
180 nb = (char *) xmalloc (text_size);
183 memcpy (nb, text_buf, text_ptr);
193 sprintf (text_buf, "Rank: %d\n", p->score);
194 text_ptr = strlen(text_buf);
196 sprintf (text_buf + text_ptr, "Local Number: %d\n", p->localno);
197 text_ptr = strlen(text_buf);
199 r = (*p->readf)(p->fh, text_buf + text_ptr, 4096);
204 text_buf[text_ptr] = '\0';
207 if (!strcmp (elementSetName, "B"))
209 if (!strcmp (elementSetName, "M"))
217 while (++i <= no_lines && (p = strchr (p, '\n')))
222 text_ptr = p-text_buf;
225 p->output_format = VAL_SUTRS;
226 p->rec_buf = text_buf;
227 p->rec_len = text_ptr;
231 static struct recType text_type = {
239 RecType recTypeText = &text_type;