2 * Copyright (C) 1994-1998, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.7 1998-03-11 11:19:05 adam
8 * Changed the way sequence numbers are generated.
10 * Revision 1.6 1998/02/10 12:03:06 adam
13 * Revision 1.5 1997/10/27 14:33:06 adam
14 * Moved towards generic character mapping depending on "structure"
15 * field in abstract syntax file. Fixed a few memory leaks. Fixed
16 * bug with negative integers when doing searches with relational
19 * Revision 1.4 1996/11/04 14:09:16 adam
22 * Revision 1.3 1996/11/01 09:00:33 adam
23 * This simple "text" format now supports element specs B and M.
25 * Revision 1.2 1996/10/29 14:02:45 adam
26 * Uses buffered read to speed up things.
28 * Revision 1.1 1996/10/11 10:57:28 adam
29 * New module recctrl. Used to manage records (extract/retrieval).
31 * Revision 1.7 1996/01/17 14:57:55 adam
32 * Prototype changed for reader functions in extract/retrieve. File
33 * is identified by 'void *' instead of 'int.
35 * Revision 1.6 1995/10/10 13:59:24 adam
36 * Function rset_open changed its wflag parameter to general flags.
38 * Revision 1.5 1995/10/02 16:24:39 adam
39 * Use attribute actually used in search requests.
41 * Revision 1.4 1995/10/02 15:42:55 adam
42 * Extract uses file descriptors instead of FILE pointers.
44 * Revision 1.3 1995/09/28 09:19:45 adam
45 * xfree/xmalloc used everywhere.
46 * Extract/retrieve method seems to work for text records.
48 * Revision 1.2 1995/09/15 14:45:21 adam
52 * Revision 1.1 1995/09/14 07:48:25 adam
53 * Record control management.
63 static void text_init (void)
68 struct recExtractCtrl *p;
74 struct buf_info *buf_open (struct recExtractCtrl *p)
76 struct buf_info *fi = xmalloc (sizeof(*fi));
79 fi->buf = xmalloc (4096);
85 int buf_read (struct buf_info *fi, char *dst)
87 if (fi->offset >= fi->max)
91 fi->max = (*fi->p->readf)(fi->p->fh, fi->buf, 4096);
96 *dst = fi->buf[(fi->offset)++];
100 void buf_close (struct buf_info *fi)
106 static int text_extract (struct recExtractCtrl *p)
111 struct buf_info *fi = buf_open (p);
113 (*p->init)(p, &recWord);
114 recWord.reg_type = 'w';
119 r = buf_read (fi, w);
120 while (r > 0 && i < 511 && w[i] != '\n' && w[i] != '\r')
123 r = buf_read (fi, w + i);
136 static int text_retrieve (struct recRetrieveCtrl *p)
139 static char *text_buf = NULL;
140 static int text_size = 0;
142 const char *elementSetName = NULL;
145 if (p->comp && p->comp->which == Z_RecordComp_simple &&
146 p->comp->u.simple->which == Z_ElementSetNames_generic)
147 elementSetName = p->comp->u.simple->u.generic;
151 if (text_ptr + 4096 >= text_size)
155 text_size = 2*text_size + 8192;
156 nb = xmalloc (text_size);
159 memcpy (nb, text_buf, text_ptr);
169 sprintf (text_buf, "Rank: %d\n", p->score);
170 text_ptr = strlen(text_buf);
172 sprintf (text_buf + text_ptr, "Local Number: %d\n", p->localno);
173 text_ptr = strlen(text_buf);
175 r = (*p->readf)(p->fh, text_buf + text_ptr, 4096);
180 text_buf[text_ptr] = '\0';
183 if (!strcmp (elementSetName, "B"))
185 if (!strcmp (elementSetName, "M"))
193 while (++i <= no_lines && (p = strchr (p, '\n')))
198 text_ptr = p-text_buf;
201 p->output_format = VAL_SUTRS;
202 p->rec_buf = text_buf;
203 p->rec_len = text_ptr;
207 static struct recType text_type = {
214 RecType recTypeText = &text_type;