2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1996-10-29 14:02:45 adam
8 * Uses buffered read to speed up things.
10 * Revision 1.1 1996/10/11 10:57:28 adam
11 * New module recctrl. Used to manage records (extract/retrieval).
13 * Revision 1.7 1996/01/17 14:57:55 adam
14 * Prototype changed for reader functions in extract/retrieve. File
15 * is identified by 'void *' instead of 'int.
17 * Revision 1.6 1995/10/10 13:59:24 adam
18 * Function rset_open changed its wflag parameter to general flags.
20 * Revision 1.5 1995/10/02 16:24:39 adam
21 * Use attribute actually used in search requests.
23 * Revision 1.4 1995/10/02 15:42:55 adam
24 * Extract uses file descriptors instead of FILE pointers.
26 * Revision 1.3 1995/09/28 09:19:45 adam
27 * xfree/xmalloc used everywhere.
28 * Extract/retrieve method seems to work for text records.
30 * Revision 1.2 1995/09/15 14:45:21 adam
34 * Revision 1.1 1995/09/14 07:48:25 adam
35 * Record control management.
45 static void text_init (void)
50 struct recExtractCtrl *p;
56 struct buf_info *buf_open (struct recExtractCtrl *p)
58 struct buf_info *fi = xmalloc (sizeof(*fi));
61 fi->buf = xmalloc (4096);
67 int buf_read (struct buf_info *fi, char *dst)
71 if (fi->offset >= fi->max)
73 fi->max = (*fi->p->readf)(fi->p->fh, fi->buf, 4096);
78 *dst = fi->buf[(fi->offset)++];
82 void buf_close (struct buf_info *fi)
88 static int text_extract (struct recExtractCtrl *p)
93 struct buf_info *fi = buf_open (p);
96 recWord.which = Word_String;
101 r = buf_read (fi, w);
102 while (r > 0 && i < 255 && isalnum(w[i]))
105 r = buf_read (fi, w + i);
110 for (j = 0; j<i; j++)
111 w[j] = tolower(w[j]);
113 recWord.seqno = seqno++;
114 recWord.u.string = w;
122 static int text_retrieve (struct recRetrieveCtrl *p)
125 static char *text_buf = NULL;
126 static int text_size = 0;
131 if (text_ptr + 4096 >= text_size)
135 text_size = 2*text_size + 8192;
136 nb = xmalloc (text_size);
139 memcpy (nb, text_buf, text_ptr);
149 sprintf (text_buf, "Rank: %d\n", p->score);
150 text_ptr = strlen(text_buf);
152 sprintf (text_buf + text_ptr, "Local Number: %d\n", p->localno);
153 text_ptr = strlen(text_buf);
155 r = (*p->readf)(p->fh, text_buf + text_ptr, 4096);
160 p->output_format = VAL_SUTRS;
161 p->rec_buf = text_buf;
162 p->rec_len = text_ptr;
166 static struct recType text_type = {
173 RecType recTypeText = &text_type;