2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 1996-11-04 14:09:16 adam
10 * Revision 1.3 1996/11/01 09:00:33 adam
11 * This simple "text" format now supports element specs B and M.
13 * Revision 1.2 1996/10/29 14:02:45 adam
14 * Uses buffered read to speed up things.
16 * Revision 1.1 1996/10/11 10:57:28 adam
17 * New module recctrl. Used to manage records (extract/retrieval).
19 * Revision 1.7 1996/01/17 14:57:55 adam
20 * Prototype changed for reader functions in extract/retrieve. File
21 * is identified by 'void *' instead of 'int.
23 * Revision 1.6 1995/10/10 13:59:24 adam
24 * Function rset_open changed its wflag parameter to general flags.
26 * Revision 1.5 1995/10/02 16:24:39 adam
27 * Use attribute actually used in search requests.
29 * Revision 1.4 1995/10/02 15:42:55 adam
30 * Extract uses file descriptors instead of FILE pointers.
32 * Revision 1.3 1995/09/28 09:19:45 adam
33 * xfree/xmalloc used everywhere.
34 * Extract/retrieve method seems to work for text records.
36 * Revision 1.2 1995/09/15 14:45:21 adam
40 * Revision 1.1 1995/09/14 07:48:25 adam
41 * Record control management.
51 static void text_init (void)
56 struct recExtractCtrl *p;
62 struct buf_info *buf_open (struct recExtractCtrl *p)
64 struct buf_info *fi = xmalloc (sizeof(*fi));
67 fi->buf = xmalloc (4096);
73 int buf_read (struct buf_info *fi, char *dst)
75 if (fi->offset >= fi->max)
79 fi->max = (*fi->p->readf)(fi->p->fh, fi->buf, 4096);
84 *dst = fi->buf[(fi->offset)++];
88 void buf_close (struct buf_info *fi)
94 static int text_extract (struct recExtractCtrl *p)
99 struct buf_info *fi = buf_open (p);
101 (*p->init)(&recWord);
102 recWord.which = Word_String;
107 r = buf_read (fi, w);
108 while (r > 0 && i < 255 && isalnum(w[i]))
111 r = buf_read (fi, w + i);
116 for (j = 0; j<i; j++)
117 w[j] = tolower(w[j]);
119 recWord.seqno = seqno++;
120 recWord.u.string = w;
128 static int text_retrieve (struct recRetrieveCtrl *p)
131 static char *text_buf = NULL;
132 static int text_size = 0;
134 const char *elementSetName = NULL;
137 if (p->comp && p->comp->which == Z_RecordComp_simple &&
138 p->comp->u.simple->which == Z_ElementSetNames_generic)
139 elementSetName = p->comp->u.simple->u.generic;
143 if (text_ptr + 4096 >= text_size)
147 text_size = 2*text_size + 8192;
148 nb = xmalloc (text_size);
151 memcpy (nb, text_buf, text_ptr);
161 sprintf (text_buf, "Rank: %d\n", p->score);
162 text_ptr = strlen(text_buf);
164 sprintf (text_buf + text_ptr, "Local Number: %d\n", p->localno);
165 text_ptr = strlen(text_buf);
167 r = (*p->readf)(p->fh, text_buf + text_ptr, 4096);
172 text_buf[text_ptr] = '\0';
175 if (!strcmp (elementSetName, "B"))
177 if (!strcmp (elementSetName, "M"))
185 while (++i <= no_lines && (p = strchr (p, '\n')))
190 text_ptr = p-text_buf;
193 p->output_format = VAL_SUTRS;
194 p->rec_buf = text_buf;
195 p->rec_len = text_ptr;
199 static struct recType text_type = {
206 RecType recTypeText = &text_type;