From e6c873a1bf7291b89cfcfe76184c4154c61056e1 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 28 Oct 1998 10:54:37 +0000 Subject: [PATCH] SDRKit integration. --- index/extract.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++---- index/main.c | 22 ++++++++++++-- index/retrieve.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++-- index/zserver.c | 15 ++++++++- zebra.dsp | 2 +- 5 files changed, 196 insertions(+), 14 deletions(-) diff --git a/index/extract.c b/index/extract.c index de9e04f..c031719 100644 --- a/index/extract.c +++ b/index/extract.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: extract.c,v $ - * Revision 1.88 1998-10-16 08:14:29 adam + * Revision 1.89 1998-10-28 10:54:38 adam + * SDRKit integration. + * + * Revision 1.88 1998/10/16 08:14:29 adam * Updated record control system. * * Revision 1.87 1998/10/15 13:10:33 adam @@ -337,6 +340,14 @@ #include "zinfo.h" +#ifndef ZEBRASDR +#define ZEBRASDR 0 +#endif + +#if ZEBRASDR +#include "zebrasdr.h" +#endif + static Dict matchDict; static Records records = NULL; @@ -950,11 +961,13 @@ static const char **searchRecordKey (struct recKeys *reckeys, } struct file_read_info { - off_t file_max; - off_t file_offset; - off_t file_moffset; + off_t file_max; /* maximum offset so far */ + off_t file_offset; /* current offset */ + off_t file_moffset; /* offset of rec/rec boundary */ int file_more; int fd; + char *sdrbuf; + int sdrmax; }; static struct file_read_info *file_read_start (int fd) @@ -964,6 +977,8 @@ static struct file_read_info *file_read_start (int fd) fi->fd = fd; fi->file_max = 0; fi->file_moffset = 0; + fi->sdrbuf = 0; + fi->sdrmax = 0; return fi; } @@ -976,6 +991,8 @@ static off_t file_seek (void *handle, off_t offset) { struct file_read_info *p = handle; p->file_offset = offset; + if (p->sdrbuf) + return offset; return lseek (p->fd, offset, SEEK_SET); } @@ -990,7 +1007,16 @@ static int file_read (void *handle, char *buf, size_t count) struct file_read_info *p = handle; int fd = p->fd; int r; - r = read (fd, buf, count); + if (p->sdrbuf) + { + r = count; + if (r > p->sdrmax - p->file_offset) + r = p->sdrmax - p->file_offset; + if (r) + memcpy (buf, p->sdrbuf + p->file_offset, r); + } + else + r = read (fd, buf, count); if (r > 0) { p->file_offset += r; @@ -1005,7 +1031,7 @@ static void file_begin (void *handle) struct file_read_info *p = handle; p->file_offset = p->file_moffset; - if (p->file_moffset) + if (!p->sdrbuf && p->file_moffset) lseek (p->fd, p->file_moffset, SEEK_SET); p->file_more = 0; } @@ -1590,6 +1616,57 @@ int fileExtract (SYSNO *sysno, const char *fname, if (rGroup->flagStoreKeys == -1) rGroup->flagStoreKeys = 0; +#if ZEBRASDR + if (1) + { + ZebraSdrHandle h; + char xname[128], *xp; + + strncpy (xname, fname, 127); + if ((xp = strchr (xname, '.'))) + *xp = '\0'; + + h = zebraSdr_open (xname); + if (!h) + { + logf (LOG_WARN, "sdr open %s", xname); + return 0; + } + for (;;) + { + unsigned char *buf; + char sdr_name[128]; + int r, segmentno; + + segmentno = zebraSdr_segment (h, 0); + sprintf (sdr_name, "%%%s.%d", xname, segmentno); + logf (LOG_LOG, "SDR: %s", sdr_name); + +#if 1 + if (segmentno > 20) + break; +#endif + r = zebraSdr_read (h, &buf); + + if (!r) + break; + + fi = file_read_start (0); + fi->sdrbuf = buf; + fi->sdrmax = r; + do + { + file_begin (fi); + r = recordExtract (sysno, sdr_name, rGroup, deleteFlag, fi, + recType, subType); + } while (r && !sysno && fi->file_more); + file_read_stop (fi); + free (buf); + } + zebraSdr_close (h); + return 1; + } +#endif if (sysno && deleteFlag) fd = -1; else diff --git a/index/main.c b/index/main.c index 45da827..97ac380 100644 --- a/index/main.c +++ b/index/main.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: main.c,v $ - * Revision 1.59 1998-10-16 08:14:32 adam + * Revision 1.60 1998-10-28 10:54:39 adam + * SDRKit integration. + * + * Revision 1.59 1998/10/16 08:14:32 adam * Updated record control system. * * Revision 1.58 1998/06/08 14:43:13 adam @@ -232,6 +235,14 @@ #include "index.h" #include "recindex.h" +#ifndef ZEBRASDR +#define ZEBRASDR 0 +#endif + +#if ZEBRASDR +#include "zebrasdr.h" +#endif + char *prog; Res common_resource = 0; @@ -250,6 +261,9 @@ int main (int argc, char **argv) nmem_init (); +#if ZEBRASDR + zebraSdr_std (); +#endif rGroupDef.groupName = NULL; rGroupDef.databaseName = NULL; rGroupDef.path = NULL; @@ -290,7 +304,7 @@ int main (int argc, char **argv) ); exit (1); } - while ((ret = options ("sVt:c:g:d:m:v:nf:", argv, argc, &arg)) != -2) + while ((ret = options ("sVt:c:g:d:m:v:nf:l:", argv, argc, &arg)) != -2) { if (ret == 0) { @@ -471,7 +485,9 @@ int main (int argc, char **argv) fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE); } else if (ret == 'v') - log_init (log_mask_str(arg), prog, NULL); + log_init_level (log_mask_str(arg)); + else if (ret == 'l') + log_init_file (arg); else if (ret == 'm') mem_max = 1024*1024*atoi(arg); else if (ret == 'd') diff --git a/index/retrieve.c b/index/retrieve.c index 2bdadcf..3ab4d8a 100644 --- a/index/retrieve.c +++ b/index/retrieve.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: retrieve.c,v $ - * Revision 1.2 1998-10-16 08:14:33 adam + * Revision 1.3 1998-10-28 10:54:40 adam + * SDRKit integration. + * + * Revision 1.2 1998/10/16 08:14:33 adam * Updated record control system. * * Revision 1.1 1998/03/05 08:45:13 adam @@ -27,6 +30,14 @@ #include #include "zserver.h" +#ifndef ZEBRASDR +#define ZEBRASDR 0 +#endif + +#if ZEBRASDR +#include "zebrasdr.h" +#endif + struct fetch_control { int record_offset; int record_int_pos; @@ -71,7 +82,7 @@ static int record_int_read (void *fh, char *buf, size_t count) int l = fc->record_int_len - fc->record_int_pos; if (l <= 0) return 0; - l = (l < count) ? l : count; + l = (l < (int) count) ? l : count; memcpy (buf, fc->record_int_buf + fc->record_int_pos, l); fc->record_int_pos += l; return l; @@ -122,7 +133,72 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream, fc.record_int_pos = 0; logf (LOG_DEBUG, "Internal retrieve. %d bytes", fc.record_int_len); } - else +#if ZEBRASDR + else if (*fname == '%') + { + ZebraSdrHandle h; + int segment = 0, r; + char *cp, xname[128]; + unsigned char *buf; + + logf (LOG_DEBUG, "SDR"); + strcpy (xname, fname+1); + if ((cp = strrchr (xname, '.'))) + { + *cp++ = 0; + segment = atoi(cp); + } + h = zebraSdr_open (xname); + if (!h) + { + logf (LOG_WARN, "sdr open %s", xname); + return 0; + } + if (zebraSdr_segment (h, &segment) < 0) + { + logf (LOG_WARN, "zebraSdr_segment fail segment=%d", + segment); + rec_rm (&rec); + return 14; + } + r = zebraSdr_read (h, &buf); + if (r < 1) + { + logf (LOG_WARN, "zebraSdr_read fail segment=%d", + segment); + rec_rm (&rec); + return 14; + } + zebraSdr_close (h); + + fc.record_int_len = recordAttr->recordSize; + fc.record_int_buf = buf + recordAttr->recordOffset; + fc.record_int_pos = 0; + + logf (LOG_LOG, "segment = %d len=%d off=%d", + segment, + recordAttr->recordSize, + recordAttr->recordOffset); + if (fc.record_int_len > 180) + { + logf (LOG_LOG, "%0.70s", fc.record_int_buf); + logf (LOG_LOG, "%0.70s", fc.record_int_buf + + (fc.record_int_len - 70)); + } + else + logf (LOG_LOG, "%0.*s", + fc.record_int_len, fc.record_int_buf); + + /* the following two lines makes rec_rm delete buf */ + rec->size[recInfo_storeData] = r; + rec->info[recInfo_storeData] = buf; + + retrieveCtrl.readf = record_int_read; + retrieveCtrl.seekf = record_int_seek; + retrieveCtrl.tellf = record_int_tell; + } +#endif + else { if ((fc.fd = open (fname, O_BINARY|O_RDONLY)) == -1) { diff --git a/index/zserver.c b/index/zserver.c index 530ee8f..9e4543c 100644 --- a/index/zserver.c +++ b/index/zserver.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zserver.c,v $ - * Revision 1.65 1998-10-18 07:54:54 adam + * Revision 1.66 1998-10-28 10:54:41 adam + * SDRKit integration. + * + * Revision 1.65 1998/10/18 07:54:54 adam * Additional info added for diagnostics 114 (Unsupported use attribute) and * 121 (Unsupported attribute set). * @@ -252,6 +255,13 @@ #include "zserver.h" +#ifndef ZEBRASDR +#define ZEBRASDR 0 +#endif +#if ZEBRASDR +#include "zebrasdr.h" +#endif + static int bend_sort (void *handle, bend_sort_rr *rr); bend_initresult *bend_init (bend_initrequest *q) @@ -441,5 +451,8 @@ int main (int argc, char **argv) #endif statserv_setcontrol (sob); +#if ZEBRASDR + zebraSdr_std (); +#endif return statserv_main (argc, argv); } diff --git a/zebra.dsp b/zebra.dsp index 5bcb189..718a680 100644 --- a/zebra.dsp +++ b/zebra.dsp @@ -60,7 +60,7 @@ LIB32=link.exe -lib # PROP Intermediate_Dir "Debug" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /MDd /W3 /GX /Z7 /Od /I "include" /I "..\yaz\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "WINDOWS" /FR /YX /FD /c +# ADD CPP /nologo /MDd /W3 /GX /Zi /Od /I "include" /I "..\yaz\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "WINDOWS" /FR /YX /FD /c BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo -- 1.7.10.4