2 * Copyright (C) 1994-1998, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.9 1998-10-16 08:14:38 adam
8 * Updated record control system.
10 * Revision 1.8 1998/05/20 10:12:27 adam
11 * Implemented automatic EXPLAIN database maintenance.
12 * Modified Zebra to work with ASN.1 compiled version of YAZ.
14 * Revision 1.7 1998/03/11 11:19:05 adam
15 * Changed the way sequence numbers are generated.
17 * Revision 1.6 1998/02/10 12:03:06 adam
20 * Revision 1.5 1997/10/27 14:33:06 adam
21 * Moved towards generic character mapping depending on "structure"
22 * field in abstract syntax file. Fixed a few memory leaks. Fixed
23 * bug with negative integers when doing searches with relational
26 * Revision 1.4 1996/11/04 14:09:16 adam
29 * Revision 1.3 1996/11/01 09:00:33 adam
30 * This simple "text" format now supports element specs B and M.
32 * Revision 1.2 1996/10/29 14:02:45 adam
33 * Uses buffered read to speed up things.
35 * Revision 1.1 1996/10/11 10:57:28 adam
36 * New module recctrl. Used to manage records (extract/retrieval).
38 * Revision 1.7 1996/01/17 14:57:55 adam
39 * Prototype changed for reader functions in extract/retrieve. File
40 * is identified by 'void *' instead of 'int.
42 * Revision 1.6 1995/10/10 13:59:24 adam
43 * Function rset_open changed its wflag parameter to general flags.
45 * Revision 1.5 1995/10/02 16:24:39 adam
46 * Use attribute actually used in search requests.
48 * Revision 1.4 1995/10/02 15:42:55 adam
49 * Extract uses file descriptors instead of FILE pointers.
51 * Revision 1.3 1995/09/28 09:19:45 adam
52 * xfree/xmalloc used everywhere.
53 * Extract/retrieve method seems to work for text records.
55 * Revision 1.2 1995/09/15 14:45:21 adam
59 * Revision 1.1 1995/09/14 07:48:25 adam
60 * Record control management.
70 static void text_init (RecType recType)
74 static void text_destroy (RecType recType)
79 struct recExtractCtrl *p;
85 struct buf_info *buf_open (struct recExtractCtrl *p)
87 struct buf_info *fi = xmalloc (sizeof(*fi));
90 fi->buf = xmalloc (4096);
96 int buf_read (struct buf_info *fi, char *dst)
98 if (fi->offset >= fi->max)
102 fi->max = (*fi->p->readf)(fi->p->fh, fi->buf, 4096);
107 *dst = fi->buf[(fi->offset)++];
111 void buf_close (struct buf_info *fi)
117 static int text_extract (struct recExtractCtrl *p)
122 struct buf_info *fi = buf_open (p);
124 (*p->init)(p, &recWord);
125 recWord.reg_type = 'w';
130 r = buf_read (fi, w);
131 while (r > 0 && i < 511 && w[i] != '\n' && w[i] != '\r')
134 r = buf_read (fi, w + i);
140 (*p->addWord)(&recWord);
147 static int text_retrieve (struct recRetrieveCtrl *p)
150 static char *text_buf = NULL;
151 static int text_size = 0;
153 const char *elementSetName = NULL;
156 if (p->comp && p->comp->which == Z_RecordComp_simple &&
157 p->comp->u.simple->which == Z_ElementSetNames_generic)
158 elementSetName = p->comp->u.simple->u.generic;
162 if (text_ptr + 4096 >= text_size)
166 text_size = 2*text_size + 8192;
167 nb = xmalloc (text_size);
170 memcpy (nb, text_buf, text_ptr);
180 sprintf (text_buf, "Rank: %d\n", p->score);
181 text_ptr = strlen(text_buf);
183 sprintf (text_buf + text_ptr, "Local Number: %d\n", p->localno);
184 text_ptr = strlen(text_buf);
186 r = (*p->readf)(p->fh, text_buf + text_ptr, 4096);
191 text_buf[text_ptr] = '\0';
194 if (!strcmp (elementSetName, "B"))
196 if (!strcmp (elementSetName, "M"))
204 while (++i <= no_lines && (p = strchr (p, '\n')))
209 text_ptr = p-text_buf;
212 p->output_format = VAL_SUTRS;
213 p->rec_buf = text_buf;
214 p->rec_len = text_ptr;
218 static struct recType text_type = {
226 RecType recTypeText = &text_type;