projects
/
idzebra-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added include stdlib.h a few places to get prototype for atoi/exit/..
[idzebra-moved-to-github.git]
/
recctrl
/
rectext.c
diff --git
a/recctrl/rectext.c
b/recctrl/rectext.c
index
9995716
..
be72590
100644
(file)
--- a/
recctrl/rectext.c
+++ b/
recctrl/rectext.c
@@
-1,6
+1,6
@@
-/* $Id: rectext.c,v 1.15 2002-08-02 19:26:56 adam Exp $
- Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
- Index Data Aps
+/* $Id: rectext.c,v 1.23 2005-01-15 19:38:32 adam Exp $
+ Copyright (C) 1995-2005
+ Index Data ApS
This file is part of the Zebra server.
This file is part of the Zebra server.
@@
-26,15
+26,29
@@
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include <ctype.h>
#include <zebrautl.h>
#include <ctype.h>
#include <zebrautl.h>
-#include "rectext.h"
+#include <idzebra/recctrl.h>
-static void *text_init (RecType recType)
+struct text_info {
+ char *sep;
+};
+
+static void *text_init (Res res, RecType recType)
{
{
- return 0;
+ struct text_info *tinfo = (struct text_info *) xmalloc(sizeof(*tinfo));
+ tinfo->sep = 0;
+ return tinfo;
+}
+
+static void text_config(void *clientData, Res res, const char *args)
+{
+
}
static void text_destroy (void *clientData)
{
}
static void text_destroy (void *clientData)
{
+ struct text_info *tinfo = clientData;
+ xfree (tinfo->sep);
+ xfree (tinfo);
}
struct buf_info {
}
struct buf_info {
@@
-55,7
+69,7
@@
struct buf_info *buf_open (struct recExtractCtrl *p)
return fi;
}
return fi;
}
-int buf_read (struct buf_info *fi, char *dst)
+int buf_read (struct text_info *tinfo, struct buf_info *fi, char *dst)
{
if (fi->offset >= fi->max)
{
{
if (fi->offset >= fi->max)
{
@@
-67,6
+81,12
@@
int buf_read (struct buf_info *fi, char *dst)
return 0;
}
*dst = fi->buf[(fi->offset)++];
return 0;
}
*dst = fi->buf[(fi->offset)++];
+ if (tinfo->sep && *dst == *tinfo->sep)
+ {
+ off_t off = (*fi->p->tellf)(fi->p->fh);
+ (*fi->p->endf)(fi->p->fh, off - (fi->max - fi->offset));
+ return 0;
+ }
return 1;
}
return 1;
}
@@
-78,23
+98,30
@@
void buf_close (struct buf_info *fi)
static int text_extract (void *clientData, struct recExtractCtrl *p)
{
static int text_extract (void *clientData, struct recExtractCtrl *p)
{
+ struct text_info *tinfo = clientData;
char w[512];
RecWord recWord;
int r;
struct buf_info *fi = buf_open (p);
char w[512];
RecWord recWord;
int r;
struct buf_info *fi = buf_open (p);
+#if 0
+ yaz_log(YLOG_LOG, "text_extract off=%ld",
+ (long) (*fi->p->tellf)(fi->p->fh));
+#endif
+ xfree(tinfo->sep);
+ tinfo->sep = 0;
(*p->init)(p, &recWord);
recWord.reg_type = 'w';
do
{
int i = 0;
(*p->init)(p, &recWord);
recWord.reg_type = 'w';
do
{
int i = 0;
- r = buf_read (fi, w);
+ r = buf_read (tinfo, fi, w);
while (r > 0 && i < 511 && w[i] != '\n' && w[i] != '\r')
{
i++;
while (r > 0 && i < 511 && w[i] != '\n' && w[i] != '\r')
{
i++;
- r = buf_read (fi, w + i);
- }
+ r = buf_read (tinfo, fi, w + i);
+ }
if (i)
{
recWord.string = w;
if (i)
{
recWord.string = w;
@@
-111,7
+138,8
@@
static int text_retrieve (void *clientData, struct recRetrieveCtrl *p)
int r, text_ptr = 0;
static char *text_buf = NULL;
static int text_size = 0;
int r, text_ptr = 0;
static char *text_buf = NULL;
static int text_size = 0;
- int start_flag = 1;
+ int make_header = 1;
+ int make_body = 1;
const char *elementSetName = NULL;
int no_lines = 0;
const char *elementSetName = NULL;
int no_lines = 0;
@@
-119,9
+147,21
@@
static int text_retrieve (void *clientData, struct recRetrieveCtrl *p)
p->comp->u.simple->which == Z_ElementSetNames_generic)
elementSetName = p->comp->u.simple->u.generic;
p->comp->u.simple->which == Z_ElementSetNames_generic)
elementSetName = p->comp->u.simple->u.generic;
- /* don't make header for the R(aw) element set name */
- if (elementSetName && !strcmp(elementSetName, "R"))
- start_flag = 0;
+ if (elementSetName)
+ {
+ /* don't make header for the R(aw) element set name */
+ if (!strcmp(elementSetName, "R"))
+ {
+ make_header = 0;
+ make_body = 1;
+ }
+ /* only make header for the H(eader) element set name */
+ else if (!strcmp(elementSetName, "H"))
+ {
+ make_header = 1;
+ make_body = 0;
+ }
+ }
while (1)
{
if (text_ptr + 4096 >= text_size)
while (1)
{
if (text_ptr + 4096 >= text_size)
@@
-137,17
+177,25
@@
static int text_retrieve (void *clientData, struct recRetrieveCtrl *p)
}
text_buf = nb;
}
}
text_buf = nb;
}
- if (start_flag)
+ if (make_header && text_ptr == 0)
{
{
- start_flag = 0;
if (p->score >= 0)
{
sprintf (text_buf, "Rank: %d\n", p->score);
text_ptr = strlen(text_buf);
}
if (p->score >= 0)
{
sprintf (text_buf, "Rank: %d\n", p->score);
text_ptr = strlen(text_buf);
}
- sprintf (text_buf + text_ptr, "Local Number: %d\n", p->localno);
+ sprintf (text_buf + text_ptr, "Local Number: " ZINT_FORMAT "\n",
+ p->localno);
text_ptr = strlen(text_buf);
text_ptr = strlen(text_buf);
+ if (p->fname)
+ {
+ sprintf (text_buf + text_ptr, "Filename: %s\n", p->fname);
+ text_ptr = strlen(text_buf);
+ }
+ strcpy(text_buf+text_ptr++, "\n");
}
}
+ if (!make_body)
+ break;
r = (*p->readf)(p->fh, text_buf + text_ptr, 4096);
if (r <= 0)
break;
r = (*p->readf)(p->fh, text_buf + text_ptr, 4096);
if (r <= 0)
break;
@@
-183,9
+231,20
@@
static int text_retrieve (void *clientData, struct recRetrieveCtrl *p)
static struct recType text_type = {
"text",
text_init,
static struct recType text_type = {
"text",
text_init,
+ text_config,
text_destroy,
text_extract,
text_retrieve
};
text_destroy,
text_extract,
text_retrieve
};
-RecType recTypeText = &text_type;
+RecType
+#ifdef IDZEBRA_STATIC_TEXT
+idzebra_filter_text
+#else
+idzebra_filter
+#endif
+
+[] = {
+ &text_type,
+ 0,
+};