From b9093505b17a074e79137ed64595c8269f77d330 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 17 Sep 1997 12:19:05 +0000 Subject: [PATCH] Zebra version corresponds to YAZ version 1.4. Changed Zebra server so that it doesn't depend on global common_resource. --- Makefile | 4 +- TODO | 26 ++++++ bfile/bfile.c | 115 +++++++++++++---------- bfile/mfile.c | 40 +++----- dict/dopen.c | 11 ++- dict/open.c | 10 +- include/bfile.h | 25 +++-- include/dict.h | 11 ++- include/direntz.h | 12 ++- include/isam.h | 12 ++- include/isamc.h | 10 +- include/mfile.h | 11 ++- include/recctrl.h | 9 +- include/res.h | 10 +- include/rstemp.h | 7 +- include/zebrautl.h | 8 +- index/attribute.c | 46 +++++---- index/extract.c | 17 ++-- index/index.h | 45 +++++---- index/invstat.c | 19 ++-- index/kcompare.c | 10 +- index/kinput.c | 18 ++-- index/lockidx.c | 20 ++-- index/locksrv.c | 14 ++- index/lockutil.c | 10 +- index/main.c | 65 ++++++++----- index/recindex.c | 14 ++- index/recindex.h | 9 +- index/recstat.c | 10 +- index/trav.c | 10 +- index/trunc.c | 7 +- index/zrpn.c | 44 +++++---- index/zserver.c | 263 ++++++++++++++++++++++++++++------------------------ index/zserver.h | 24 ++++- isam/Makefile | 8 +- isam/isam.c | 44 +++++---- isamc/isamc.c | 10 +- recctrl/grsread.h | 7 +- recctrl/marcread.c | 43 +++++---- recctrl/recgrs.c | 75 +++++++++------ recctrl/regxread.c | 25 +++-- recctrl/sgmlread.c | 8 +- rset/rsrel.c | 21 ++++- rset/rstemp.c | 32 ++++--- util/Makefile | 4 +- util/dirent.c | 14 +++ util/res.c | 12 ++- 47 files changed, 782 insertions(+), 487 deletions(-) create mode 100644 TODO diff --git a/Makefile b/Makefile index 497d404..f3bafaf 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ -# Copyright (C) 1994-1996, Index Data I/S +# Copyright (C) 1994-1997, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.59 1997-09-04 13:59:27 adam Exp $ +# $Id: Makefile,v 1.60 1997-09-17 12:19:05 adam Exp $ SHELL=/bin/sh MAKE=make diff --git a/TODO b/TODO new file mode 100644 index 0000000..760ba82 --- /dev/null +++ b/TODO @@ -0,0 +1,26 @@ +Zebra TODO $Id: TODO,v 1.1 1997-09-17 12:19:06 adam Exp $ + +NT port: locking mechanisms needs to be ported. Locking should + probably be moved to Zebra util instead. + +Better ranking in searches. Admin should be able specify initial + weight to certain fields. + +Search result should hold information about hits for each term, + especially when using ranked search. + +Admin should be able to specify set/attr when none is specified + (currently bib1,use=any is used). + +Explain support - including d1 to grs (d1_grs.c) in YAZ; Zebra + to auto-generate explain information depending on data1 system. + +Generic character set mapping (w, p, etc.) + +ISAMC optimization: indirect block with pointers to all blocks + in chain. The initial block should include the count as well. + +Test mode fix: when using test mode (-s) Zebra should only do + read-locking and not write-locking thus preventing Zebra thinking + the index is inconsistent. + diff --git a/bfile/bfile.c b/bfile/bfile.c index 993f3b2..06bca15 100644 --- a/bfile/bfile.c +++ b/bfile/bfile.c @@ -1,10 +1,14 @@ /* - * Copyright (C) 1994, Index Data I/S + * Copyright (C) 1994-1997, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: bfile.c,v $ - * Revision 1.22 1997-09-09 13:37:52 adam + * Revision 1.23 1997-09-17 12:19:06 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.22 1997/09/09 13:37:52 adam * Partial port to WIN95/NT. * * Revision 1.21 1996/10/29 13:56:13 adam @@ -85,61 +89,70 @@ #include #include "cfile.h" -static MFile_area commit_area = NULL; -static char *commit_lockDir = NULL; +struct BFiles_struct { + MFile_area commit_area; + MFile_area_struct *register_area; + char *lockDir; +}; + +BFiles bfs_create (const char *spec) +{ + BFiles bfs = xmalloc (sizeof(*bfs)); + bfs->commit_area = NULL; + bfs->register_area = mf_init("register", spec); + bfs->lockDir = NULL; + return bfs; +} + +void bfs_destroy (BFiles bfs) +{ + xfree (bfs); +} -static FILE *open_cache (const char *flags) +static FILE *open_cache (BFiles bfs, const char *flags) { char cacheFilename[1024]; FILE *file; - sprintf (cacheFilename, "%scache", commit_lockDir ? commit_lockDir : ""); + sprintf (cacheFilename, "%scache", + bfs->lockDir ? bfs->lockDir : ""); file = fopen (cacheFilename, flags); return file; } -static void unlink_cache (void) +static void unlink_cache (BFiles bfs) { char cacheFilename[1024]; - sprintf (cacheFilename, "%scache", commit_lockDir ? commit_lockDir : ""); + sprintf (cacheFilename, "%scache", + bfs->lockDir ? bfs->lockDir : ""); unlink (cacheFilename); } -void bf_lockDir (const char *lockDir) +void bf_lockDir (BFiles bfs, const char *lockDir) { size_t len; - xfree (commit_lockDir); - + xfree (bfs->lockDir); if (lockDir == NULL) lockDir = ""; len = strlen(lockDir); - commit_lockDir = xmalloc (len+2); - strcpy (commit_lockDir, lockDir); + bfs->lockDir = xmalloc (len+2); + strcpy (bfs->lockDir, lockDir); - if (len > 0 && commit_lockDir[len-1] != '/') - strcpy (commit_lockDir + len, "/"); + if (len > 0 && bfs->lockDir[len-1] != '/') + strcpy (bfs->lockDir + len, "/"); } -void bf_cache (int enableFlag) +void bf_cache (BFiles bfs, const char *spec) { - if (enableFlag) + if (spec) { - if (!commit_area) - if (res_get (common_resource, "shadow")) - { - commit_area = mf_init ("shadow"); - } - else - { - logf (LOG_FATAL, "Shadow area must be defined if commit" - "is to be enabled"); - exit (1); - } + if (!bfs->commit_area) + bfs->commit_area = mf_init ("shadow", spec); } else - commit_area = NULL; + bfs->commit_area = NULL; } int bf_close (BFile bf) @@ -151,26 +164,26 @@ int bf_close (BFile bf) return 0; } -BFile bf_open (const char *name, int block_size, int wflag) +BFile bf_open (BFiles bfs, const char *name, int block_size, int wflag) { BFile tmp = xmalloc(sizeof(BFile_struct)); - if (commit_area) + if (bfs->commit_area) { int first_time; - tmp->mf = mf_open (0, name, block_size, 0); - tmp->cf = cf_open (tmp->mf, commit_area, name, block_size, + tmp->mf = mf_open (bfs->register_area, name, block_size, 0); + tmp->cf = cf_open (tmp->mf, bfs->commit_area, name, block_size, wflag, &first_time); if (first_time) { FILE *outf; - outf = open_cache ("a"); + outf = open_cache (bfs, "a"); if (!outf) { logf (LOG_FATAL|LOG_ERRNO, "open %scache", - commit_lockDir ? commit_lockDir : ""); + bfs->lockDir ? bfs->lockDir : ""); exit (1); } fprintf (outf, "%s %d\n", name, block_size); @@ -179,7 +192,7 @@ BFile bf_open (const char *name, int block_size, int wflag) } else { - tmp->mf = mf_open(0, name, block_size, wflag); + tmp->mf = mf_open(bfs->register_area, name, block_size, wflag); tmp->cf = NULL; } if (!tmp->mf) @@ -207,11 +220,11 @@ int bf_write (BFile bf, int no, int offset, int num, const void *buf) return mf_write (bf->mf, no, offset, num, buf); } -int bf_commitExists (void) +int bf_commitExists (BFiles bfs) { FILE *inf; - inf = open_cache ("r"); + inf = open_cache (bfs, "r"); if (inf) { fclose (inf); @@ -220,7 +233,7 @@ int bf_commitExists (void) return 0; } -void bf_commitExec (void) +void bf_commitExec (BFiles bfs) { FILE *inf; int block_size; @@ -229,16 +242,16 @@ void bf_commitExec (void) CFile cf; int first_time; - assert (commit_area); - if (!(inf = open_cache ("r"))) + assert (bfs->commit_area); + if (!(inf = open_cache (bfs, "r"))) { logf (LOG_LOG, "No commit file"); return ; } while (fscanf (inf, "%s %d", path, &block_size) == 2) { - mf = mf_open (0, path, block_size, 1); - cf = cf_open (mf, commit_area, path, block_size, 0, &first_time); + mf = mf_open (bfs->register_area, path, block_size, 1); + cf = cf_open (mf, bfs->commit_area, path, block_size, 0, &first_time); cf_commit (cf); @@ -248,7 +261,7 @@ void bf_commitExec (void) fclose (inf); } -void bf_commitClean (void) +void bf_commitClean (BFiles bfs, const char *spec) { FILE *inf; int block_size; @@ -258,24 +271,24 @@ void bf_commitClean (void) int mustDisable = 0; int firstTime; - if (!commit_area) + if (!bfs->commit_area) { - bf_cache (1); + bf_cache (bfs, spec); mustDisable = 1; } - if (!(inf = open_cache ("r"))) + if (!(inf = open_cache (bfs, "r"))) return ; while (fscanf (inf, "%s %d", path, &block_size) == 2) { - mf = mf_open (0, path, block_size, 0); - cf = cf_open (mf, commit_area, path, block_size, 1, &firstTime); + mf = mf_open (bfs->register_area, path, block_size, 0); + cf = cf_open (mf, bfs->commit_area, path, block_size, 1, &firstTime); cf_unlink (cf); cf_close (cf); mf_close (mf); } fclose (inf); - unlink_cache (); + unlink_cache (bfs); if (mustDisable) - bf_cache (0); + bf_cache (bfs, 0); } diff --git a/bfile/mfile.c b/bfile/mfile.c index a87ac69..6074cfb 100644 --- a/bfile/mfile.c +++ b/bfile/mfile.c @@ -1,10 +1,14 @@ /* - * Copyright (C) 1994, Index Data I/S + * Copyright (C) 1994-1997, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: mfile.c,v $ - * Revision 1.23 1997-09-09 13:37:53 adam + * Revision 1.24 1997-09-17 12:19:06 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.23 1997/09/09 13:37:53 adam * Partial port to WIN95/NT. * * Revision 1.22 1997/09/04 13:56:39 adam @@ -98,23 +102,16 @@ #include #include -static MFile_area_struct *open_areas = 0; -static MFile_area_struct *default_area = 0; - -static int scan_areadef(MFile_area ma, const char *name) +static int scan_areadef(MFile_area ma, const char *name, const char *ad) { /* * If no definition is given, use current directory, unlimited. */ - const char *ad = res_get_def(common_resource, name, ".:-1b"); char dirname[FILENAME_MAX+1]; mf_dir **dp = &ma->dirs, *dir = *dp; if (!ad) - { - logf (LOG_FATAL, "Could not find resource '%s'", name); - return -1; - } + ad = ".:-1b"; for (;;) { const char *ad0 = ad; @@ -225,9 +222,9 @@ static int cmp_part_file(const void *p1, const void *p2) * Create a new area, cotaining metafiles in directories. * Find the part-files in each directory, and inventory the existing metafiles. */ -MFile_area mf_init(const char *name) +MFile_area mf_init(const char *name, const char *spec) { - MFile_area ma = xmalloc(sizeof(MFile_area_struct)), mp; + MFile_area ma = xmalloc(sizeof(MFile_area_struct)); mf_dir *dirp; meta_file *meta_f; part_file *part_f = 0; @@ -237,16 +234,11 @@ MFile_area mf_init(const char *name) char metaname[FILENAME_MAX+1], tmpnam[FILENAME_MAX+1]; logf (LOG_DEBUG, "mf_init(%s)", name); - for (mp = open_areas; mp; mp = mp->next) - if (!strcmp(name, mp->name)) - return mp; ma = xmalloc(sizeof(MFile_area_struct)); strcpy(ma->name, name); - ma->next = open_areas; - open_areas = ma; ma->mfiles = 0; ma->dirs = 0; - if (scan_areadef(ma, name) < 0) + if (scan_areadef(ma, name, spec) < 0) { logf (LOG_FATAL, "Failed to access description of '%s'", name); return 0; @@ -338,15 +330,7 @@ MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag) logf(LOG_DEBUG, "mf_open(%s bs=%d, %s)", name, block_size, wflag ? "RW" : "RDONLY"); - if (!ma) - { - if (!default_area && !(default_area = mf_init(MF_DEFAULT_AREA))) - { - logf (LOG_FATAL, "Failed to open default area."); - return 0; - } - ma = default_area; - } + assert (ma); for (new = ma->mfiles; new; new = new->next) if (!strcmp(name, new->name)) if (new->open) diff --git a/dict/dopen.c b/dict/dopen.c index 192a3ce..1f1fda3 100644 --- a/dict/dopen.c +++ b/dict/dopen.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dopen.c,v $ - * Revision 1.4 1997-09-09 13:38:01 adam + * Revision 1.5 1997-09-17 12:19:07 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.4 1997/09/09 13:38:01 adam * Partial port to WIN95/NT. * * Revision 1.3 1994/09/01 17:49:37 adam @@ -59,12 +63,13 @@ static void common_init (Dict_BFile bf, int block_size, int cache) } -Dict_BFile dict_bf_open (const char *name, int block_size, int cache, int rw) +Dict_BFile dict_bf_open (BFiles bfs, const char *name, int block_size, + int cache, int rw) { Dict_BFile dbf; dbf = xmalloc (sizeof(*dbf)); - dbf->bf = bf_open (name, block_size, rw); + dbf->bf = bf_open (bfs, name, block_size, rw); if (!dbf->bf) return NULL; common_init (dbf, block_size, cache); diff --git a/dict/open.c b/dict/open.c index 0ededaa..02b73fe 100644 --- a/dict/open.c +++ b/dict/open.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: open.c,v $ - * Revision 1.11 1996-10-29 14:00:05 adam + * Revision 1.12 1997-09-17 12:19:07 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.11 1996/10/29 14:00:05 adam * Page size given by DICT_DEFAULT_PAGESIZE in dict.h. * * Revision 1.10 1996/05/24 14:46:04 adam @@ -47,7 +51,7 @@ #include -Dict dict_open (const char *name, int cache, int rw) +Dict dict_open (BFiles bfs, const char *name, int cache, int rw) { Dict dict; void *head_buf; @@ -67,7 +71,7 @@ Dict dict_open (const char *name, int cache, int rw) resource_str); page_size = 2048; } - dict->dbf = dict_bf_open (name, page_size, cache, rw); + dict->dbf = dict_bf_open (bfs, name, page_size, cache, rw); dict->rw = rw; if(!dict->dbf) diff --git a/include/bfile.h b/include/bfile.h index 8618b77..69a3b5b 100644 --- a/include/bfile.h +++ b/include/bfile.h @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: bfile.h,v $ - * Revision 1.14 1997-09-05 15:29:58 adam + * Revision 1.15 1997-09-17 12:19:07 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.14 1997/09/05 15:29:58 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -55,6 +59,11 @@ extern "C" { #define bf_blocksize(bf) mf_blocksize(bf->mf) +typedef struct BFiles_struct *BFiles; + +BFiles bfs_create (const char *spec); +void bfs_destroy (BFiles bfiles); + typedef struct BFile_struct { MFile mf; @@ -70,7 +79,7 @@ int bf_close (BFile); opens bfile with name 'name' and with 'block_size' as block size. returns bfile handle is successful; NULL otherwise */ -BFile bf_open (const char *name, int block_size, int wflag); +BFile bf_open (BFiles bfs, const char *name, int block_size, int wflag); /* bf_read: reads bytes from bfile 'bf'. reads 'num' bytes (or whole block if 0) from offset 'offset' from @@ -86,20 +95,20 @@ int bf_read (BFile bf, int no, int offset, int num, void *buf); */ int bf_write (BFile bf, int no, int offset, int num, const void *buf); -/* bf_cache: enables/disables bfile cache */ -void bf_cache (int enableFlag); +/* bf_cache: enables bfile cache if spec is not NULL */ +void bf_cache (BFiles bfs, const char *spec); /* bf_lockDir: specifies locking directory for the cache system */ -void bf_lockDir (const char *lockDir); +void bf_lockDir (BFiles bfs, const char *lockDir); /* bf_commitExists: returns 1 if commit is pending; 0 otherwise */ -int bf_commitExists (void); +int bf_commitExists (BFiles bfs); /* bf_commitExec: executes commit */ -void bf_commitExec (void); +void bf_commitExec (BFiles bfs); /* bf_commitClean: cleans commit files, etc */ -void bf_commitClean (void); +void bf_commitClean (BFiles bfs, const char *spec); #ifdef __cplusplus } diff --git a/include/dict.h b/include/dict.h index 0b94ffd..b631c72 100644 --- a/include/dict.h +++ b/include/dict.h @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dict.h,v $ - * Revision 1.24 1997-09-05 15:30:00 adam + * Revision 1.25 1997-09-17 12:19:09 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.24 1997/09/05 15:30:00 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -148,10 +152,11 @@ int dict_bf_readp (Dict_BFile bf, int no, void **bufp); int dict_bf_newp (Dict_BFile bf, int no, void **bufp); int dict_bf_touch (Dict_BFile bf, int no); void dict_bf_flush_blocks (Dict_BFile bf, int no_to_flush); -Dict_BFile dict_bf_open (const char *name, int block_size, int cache, int rw); +Dict_BFile dict_bf_open (BFiles bfs, const char *name, int block_size, + int cache, int rw); int dict_bf_close (Dict_BFile dbf); -Dict dict_open (const char *name, int cache, int rw); +Dict dict_open (BFiles bfs, const char *name, int cache, int rw); int dict_close (Dict dict); int dict_insert (Dict dict, const char *p, int userlen, void *userinfo); int dict_delete (Dict dict, const char *p); diff --git a/include/direntz.h b/include/direntz.h index 25477d5..3883511 100644 --- a/include/direntz.h +++ b/include/direntz.h @@ -4,15 +4,22 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: direntz.h,v $ - * Revision 1.1 1997-09-09 13:38:03 adam + * Revision 1.2 1997-09-17 12:19:09 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.1 1997/09/09 13:38:03 adam * Partial port to WIN95/NT. * * */ + + #ifdef WINDOWS +/* make own version of dirent */ #include struct dirent { - char d_name[MAX_PATH+1]; + char d_name[MAX_PATH]; }; typedef struct DIR DIR; @@ -21,5 +28,6 @@ DIR *opendir (const char *path); struct dirent *readdir (DIR *dd); void closedir (DIR *dd); #else +/* include UNIX version */ #include #endif diff --git a/include/isam.h b/include/isam.h index fc4ebb9..c667175 100644 --- a/include/isam.h +++ b/include/isam.h @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: isam.h,v $ - * Revision 1.12 1997-09-05 15:30:00 adam + * Revision 1.13 1997-09-17 12:19:09 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.12 1997/09/05 15:30:00 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -46,6 +50,7 @@ #ifndef ISAM_H #define ISAM_H +#include #include #include "../isam/memory.h" @@ -109,8 +114,9 @@ typedef struct ispt_struct /* * Open isam file. */ -ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2), - int writeflag, int keysize); +ISAM is_open(BFiles bfs, const char *name, + int (*cmp)(const void *p1, const void *p2), + int writeflag, int keysize, Res res); /* * Close isam file. diff --git a/include/isamc.h b/include/isamc.h index b68b0d6..706e479 100644 --- a/include/isamc.h +++ b/include/isamc.h @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: isamc.h,v $ - * Revision 1.5 1997-09-05 15:30:00 adam + * Revision 1.6 1997-09-17 12:19:10 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.5 1997/09/05 15:30:00 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -26,6 +30,8 @@ #ifndef ISAMC_H #define ISAMC_H +#include + #ifdef __cplusplus extern "C" { #endif @@ -63,7 +69,7 @@ typedef struct ISAMC_I_s { ISAMC_M isc_getmethod (void); -ISAMC isc_open (const char *name, int writeflag, ISAMC_M method); +ISAMC isc_open (BFiles bfs, const char *name, int writeflag, ISAMC_M method); int isc_close (ISAMC is); ISAMC_P isc_merge (ISAMC is, ISAMC_P pos, ISAMC_I data); diff --git a/include/mfile.h b/include/mfile.h index ee6e6d5..7959b25 100644 --- a/include/mfile.h +++ b/include/mfile.h @@ -1,10 +1,14 @@ /* - * Copyright (C) 1994-1995, Index Data I/S + * Copyright (C) 1994-1997, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: mfile.h,v $ - * Revision 1.7 1997-09-05 15:30:01 adam + * Revision 1.8 1997-09-17 12:19:10 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.7 1997/09/05 15:30:01 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -44,7 +48,6 @@ extern "C" { #endif #define MF_MIN_BLOCKS_CREAT 1 /* minimum free blocks in new dir */ -#define MF_DEFAULT_AREA "register" /* Use if no mf_init */ #define MF_MAX_PARTS 28 /* max # of part-files per metafile */ #define mf_blocksize(mf) ((mf)->blocksize) @@ -97,7 +100,7 @@ typedef struct MFile_area_struct /* * Open an area, cotaining metafiles in directories. */ -MFile_area mf_init(const char *name); +MFile_area mf_init(const char *name, const char *spec); /* * Release an area. diff --git a/include/recctrl.h b/include/recctrl.h index da9faf8..d89c8ec 100644 --- a/include/recctrl.h +++ b/include/recctrl.h @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: recctrl.h,v $ - * Revision 1.19 1997-09-05 15:30:02 adam + * Revision 1.20 1997-09-17 12:19:10 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.19 1997/09/05 15:30:02 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -77,6 +81,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -120,6 +125,7 @@ struct recExtractCtrl { void (*add)(const RecWord *p); const char **(*map_chrs_input)(const char **from, int len); int flagShowRecords; + data1_handle dh; }; /* Retrieve record control */ @@ -135,6 +141,7 @@ struct recRetrieveCtrl { int localno; /* local id of record */ int score; /* score 0-1000 or -1 if none */ char *subType; + data1_handle dh; /* response */ oid_value output_format; diff --git a/include/res.h b/include/res.h index 0836dae..1903cf6 100644 --- a/include/res.h +++ b/include/res.h @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: res.h,v $ - * Revision 1.7 1997-09-05 15:30:02 adam + * Revision 1.8 1997-09-17 12:19:10 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.7 1997/09/05 15:30:02 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -50,8 +54,8 @@ char *res_get (Res r, const char *name); char *res_get_def (Res r, const char *name, char *def); int res_get_match (Res r, const char *name, const char *value, const char *s); void res_put (Res r, const char *name, const char *value); -void res_trav (Res r, const char *prefix, - void (*f)(const char *name, const char *value)); +void res_trav (Res r, const char *prefix, void *p, + void (*f)(void *p, const char *name, const char *value)); int res_write (Res r); #ifdef __cplusplus diff --git a/include/rstemp.h b/include/rstemp.h index 2ba086d..b8c41cf 100644 --- a/include/rstemp.h +++ b/include/rstemp.h @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rstemp.h,v $ - * Revision 1.3 1997-09-05 15:30:05 adam + * Revision 1.4 1997-09-17 12:19:11 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.3 1997/09/05 15:30:05 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -30,6 +34,7 @@ extern const rset_control *rset_kind_temp; typedef struct rset_temp_parms { int key_size; + char *temp_path; } rset_temp_parms; #ifdef __cplusplus diff --git a/include/zebrautl.h b/include/zebrautl.h index c18c9f1..84e21f0 100644 --- a/include/zebrautl.h +++ b/include/zebrautl.h @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zebrautl.h,v $ - * Revision 1.2 1997-09-05 15:30:06 adam + * Revision 1.3 1997-09-17 12:19:11 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.2 1997/09/05 15:30:06 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -23,6 +27,4 @@ #include #include -#include - #endif diff --git a/index/attribute.c b/index/attribute.c index 78af3c1..7595591 100644 --- a/index/attribute.c +++ b/index/attribute.c @@ -1,10 +1,14 @@ /* - * Copyright (C) 1994-1995, Index Data I/S + * Copyright (C) 1994-1997, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: attribute.c,v $ - * Revision 1.5 1997-09-05 15:30:08 adam + * Revision 1.6 1997-09-17 12:19:11 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.5 1997/09/05 15:30:08 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -26,30 +30,26 @@ #include #include -#include #include -#include "attribute.h" - -static int initialized = 0; - -static data1_attset *registered_sets = 0; +#include "zserver.h" -static void att_loadset(const char *n, const char *name) +static void att_loadset(void *p, const char *n, const char *name) { data1_attset *cnew; + ZServerInfo *zi = p; - if (!(cnew = data1_read_attset((char*) name))) + if (!(cnew = data1_read_attset(zi->dh, (char*) name))) { logf(LOG_WARN|LOG_ERRNO, "%s", name); return; } - cnew->next = registered_sets; - registered_sets = cnew; + cnew->next = zi->registered_sets; + zi->registered_sets = cnew; } -static void load_atts() +static void load_atts(ZServerInfo *zi) { - res_trav(common_resource, "attset", att_loadset); + res_trav(zi->res, "attset", zi, att_loadset); } static data1_att *getatt(data1_attset *p, int att) @@ -69,23 +69,19 @@ static data1_att *getatt(data1_attset *p, int att) return 0; } -attent *att_getentbyatt(oid_value set, int att) +int att_getentbyatt(ZServerInfo *zi, attent *res, oid_value set, int att) { - static attent res; data1_att *r; data1_attset *p; - if (!initialized) - { - initialized = 1; - load_atts(); - } - for (p = registered_sets; p; p = p->next) + if (!zi->registered_sets) + load_atts(zi); + for (p = zi->registered_sets; p; p = p->next) if (p->reference == set && (r = getatt(p, att))) break;; if (!p) return 0; - res.attset_ordinal = r->parent->ordinal; - res.local_attributes = r->locals; - return &res; + res->attset_ordinal = r->parent->ordinal; + res->local_attributes = r->locals; + return 1; } diff --git a/index/extract.c b/index/extract.c index 4978551..a085d72 100644 --- a/index/extract.c +++ b/index/extract.c @@ -1,10 +1,14 @@ /* - * Copyright (C) 1994-1996, Index Data I/S + * Copyright (C) 1994-1997, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: extract.c,v $ - * Revision 1.74 1997-09-09 13:38:06 adam + * Revision 1.75 1997-09-17 12:19:12 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.74 1997/09/09 13:38:06 adam * Partial port to WIN95/NT. * * Revision 1.73 1997/09/04 13:57:20 adam @@ -310,7 +314,7 @@ static void logRecord (int showFlag) } } -void key_open (int mem) +void key_open (BFiles bfs, int mem) { if (!mem) mem = atoi(res_get_def (common_resource, "memMax", "4"))*1024*1024; @@ -323,13 +327,13 @@ void key_open (int mem) key_buf_used = 0; key_file_no = 0; - if (!(matchDict = dict_open (GMATCH_DICT, 50, 1))) + if (!(matchDict = dict_open (bfs, GMATCH_DICT, 50, 1))) { logf (LOG_FATAL, "dict_open fail of %s", GMATCH_DICT); exit (1); } assert (!records); - records = rec_open (1); + records = rec_open (bfs, 1); #if 1 zti = zebTargetInfo_open (records, 1); #endif @@ -503,7 +507,7 @@ void key_flush (void) key_buf_used = 0; } -int key_close (void) +int key_close () { key_flush (); xfree (key_buf); @@ -985,6 +989,7 @@ static int recordExtract (SYSNO *sysno, const char *fname, extractCtrl.subType = subType; extractCtrl.init = wordInit; extractCtrl.add = addRecordKey; + extractCtrl.dh = rGroup->dh; reckeys.buf_used = 0; reckeys.prevAttrUse = -1; diff --git a/index/index.h b/index/index.h index 9f3e8bf..2e60e90 100644 --- a/index/index.h +++ b/index/index.h @@ -1,10 +1,14 @@ /* - * Copyright (C) 1995-1996, Index Data I/S + * Copyright (C) 1995-1997, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: index.h,v $ - * Revision 1.49 1997-09-05 15:30:08 adam + * Revision 1.50 1997-09-17 12:19:13 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.49 1997/09/05 15:30:08 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -183,6 +187,7 @@ #include #include #include +#include #define IT_MAX_WORD 256 #define IT_KEY_HAVE_SEQNO 1 @@ -211,15 +216,17 @@ struct dirs_entry { }; struct recordGroup { - char *groupName; - char *databaseName; - char *path; - char *recordId; - char *recordType; - int flagStoreData; - int flagStoreKeys; - int flagShowRecords; - int fileVerboseLimit; + char *groupName; + char *databaseName; + char *path; + char *recordId; + char *recordType; + int flagStoreData; + int flagStoreKeys; + int flagShowRecords; + int fileVerboseLimit; + data1_handle dh; + BFiles bfs; }; void getFnameTmp (char *fname, int no); @@ -243,15 +250,15 @@ void repositoryAdd (struct recordGroup *rGroup); void repositoryDelete (struct recordGroup *rGroup); void repositoryShow (struct recordGroup *rGroup); -void key_open (int mem); +void key_open (BFiles bfs, int mem); int key_close (void); int key_compare (const void *p1, const void *p2); int key_compare_it (const void *p1, const void *p2); int key_qsort_compare (const void *p1, const void *p2); void key_logdump (int mask, const void *p); -void inv_prstat (void); -void key_input (int nkeys, int cache); -ISAMC_M key_isamc_m (void); +void inv_prstat (BFiles bfs); +void key_input (BFiles bfs, int nkeys, int cache); +ISAMC_M key_isamc_m (Res res); int merge_sort (char **buf, int from, int to); #define FNAME_DICT "dict" @@ -276,11 +283,11 @@ int fileExtract (SYSNO *sysno, const char *fname, void rec_prstat (void); -void zebraLockPrefix (char *pathPrefix); +void zebraLockPrefix (Res res, char *pathPrefix); void zebraIndexLockMsg (const char *str); void zebraIndexUnlock (void); -void zebraIndexLock (int commitNow); +void zebraIndexLock (BFiles bfs, int commitNow, const char *rval); int zebraIndexWait (int commitPhase); #define FNAME_MAIN_LOCK "zebraidx.LCK" @@ -292,6 +299,8 @@ int zebraLock (int fd, int wr); int zebraLockNB (int fd, int wr); int zebraUnlock (int fd); -void init_charmap(void); +void init_charmap(Res res); const char **map_chrs_input(const char **from, int len); const char *map_chrs_output(const char **from); + +extern Res common_resource; diff --git a/index/invstat.c b/index/invstat.c index 8929c44..2e14ede 100644 --- a/index/invstat.c +++ b/index/invstat.c @@ -1,10 +1,14 @@ /* - * Copyright (C) 1994-1996, Index Data I/S + * Copyright (C) 1994-1997, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: invstat.c,v $ - * Revision 1.4 1996-11-08 11:10:21 adam + * Revision 1.5 1997-09-17 12:19:13 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.4 1996/11/08 11:10:21 adam * Buffers used during file match got bigger. * Compressed ISAM support everywhere. * Bug fixes regarding masking characters in queries. @@ -83,7 +87,7 @@ static int inv_stat_handle (char *name, const char *info, int pos, return 0; } -void inv_prstat (void) +void inv_prstat (BFiles bfs) { Dict dict; ISAM isam = NULL; @@ -98,7 +102,7 @@ void inv_prstat (void) term_dict[0] = 1; term_dict[1] = 0; - dict = dict_open (FNAME_DICT, 100, 0); + dict = dict_open (bfs, FNAME_DICT, 100, 0); if (!dict) { logf (LOG_FATAL, "dict_open fail"); @@ -106,7 +110,7 @@ void inv_prstat (void) } if (res_get_match (common_resource, "isam", "c", NULL)) { - isamc = isc_open (FNAME_ISAMC, 0, key_isamc_m ()); + isamc = isc_open (bfs, FNAME_ISAMC, 0, key_isamc_m (common_resource)); if (!isamc) { logf (LOG_FATAL, "isc_open fail"); @@ -115,14 +119,15 @@ void inv_prstat (void) } else { - isam = is_open (FNAME_ISAM, key_compare, 0, sizeof(struct it_key)); + isam = is_open (bfs, FNAME_ISAM, key_compare, 0, + sizeof(struct it_key), common_resource); if (!isam) { logf (LOG_FATAL, "is_open fail"); exit (1); } } - records = rec_open (0); + records = rec_open (bfs, 0); stat_info.no_dict_entries = 0; stat_info.no_dict_bytes = 0; diff --git a/index/kcompare.c b/index/kcompare.c index 388d473..849d8fa 100644 --- a/index/kcompare.c +++ b/index/kcompare.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: kcompare.c,v $ - * Revision 1.20 1996-12-23 15:30:44 adam + * Revision 1.21 1997-09-17 12:19:13 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.20 1996/12/23 15:30:44 adam * Work on truncation. * Bug fix: result sets weren't deleted after server shut down. * @@ -248,7 +252,7 @@ static void iscz1_code_item (int mode, void *vp, char **dst, char **src) } } -ISAMC_M key_isamc_m (void) +ISAMC_M key_isamc_m (Res res) { static ISAMC_M me = NULL; @@ -263,7 +267,7 @@ ISAMC_M key_isamc_m (void) me->code_item = iscz1_code_item; me->code_stop = iscz1_code_stop; - me->debug = atoi(res_get_def (common_resource, "isamcDebug", "0")); + me->debug = atoi(res_get_def (res, "isamcDebug", "0")); logf (LOG_LOG, "ISAMC system active"); return me; diff --git a/index/kinput.c b/index/kinput.c index 4da9460..64c1906 100644 --- a/index/kinput.c +++ b/index/kinput.c @@ -1,10 +1,14 @@ /* - * Copyright (C) 1994-1996, Index Data I/S + * Copyright (C) 1994-1997, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: kinput.c,v $ - * Revision 1.24 1997-09-09 13:38:07 adam + * Revision 1.25 1997-09-17 12:19:14 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.24 1997/09/09 13:38:07 adam * Partial port to WIN95/NT. * * Revision 1.23 1997/09/04 13:57:39 adam @@ -579,7 +583,7 @@ void progressFunc (struct key_file *keyp, void *info) #define R_OK 4 #endif -void key_input (int nkeys, int cache) +void key_input (BFiles bfs, int nkeys, int cache) { Dict dict; @@ -605,7 +609,7 @@ void key_input (int nkeys, int cache) if (!nkeys) return ; } - dict = dict_open (FNAME_DICT, cache, 1); + dict = dict_open (bfs, FNAME_DICT, cache, 1); if (!dict) { logf (LOG_FATAL, "dict_open fail"); @@ -613,7 +617,8 @@ void key_input (int nkeys, int cache) } if (res_get_match (common_resource, "isam", "c", NULL)) { - isamc = isc_open (FNAME_ISAMC, 1, key_isamc_m ()); + isamc = isc_open (bfs, + FNAME_ISAMC, 1, key_isamc_m (common_resource)); if (!isamc) { logf (LOG_FATAL, "isc_open fail"); @@ -622,7 +627,8 @@ void key_input (int nkeys, int cache) } else { - isam = is_open (FNAME_ISAM, key_compare, 1, sizeof(struct it_key)); + isam = is_open (bfs, FNAME_ISAM, key_compare, 1, + sizeof(struct it_key), common_resource); if (!isam) { logf (LOG_FATAL, "is_open fail"); diff --git a/index/lockidx.c b/index/lockidx.c index f2c418c..10be062 100644 --- a/index/lockidx.c +++ b/index/lockidx.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: lockidx.c,v $ - * Revision 1.10 1997-09-09 13:38:07 adam + * Revision 1.11 1997-09-17 12:19:15 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.10 1997/09/09 13:38:07 adam * Partial port to WIN95/NT. * * Revision 1.9 1997/09/04 13:58:04 adam @@ -66,7 +70,7 @@ int zebraIndexWait (int commitPhase) char path[1024]; int fd; - zebraLockPrefix (pathPrefix); + zebraLockPrefix (common_resource, pathPrefix); if (server_lock_cmt == -1) { @@ -135,7 +139,7 @@ void zebraIndexLockMsg (const char *str) logf (LOG_FATAL|LOG_ERRNO, "write lock file"); exit (1); } - zebraLockPrefix (pathPrefix); + zebraLockPrefix (common_resource, pathPrefix); sprintf (path, "%s%s", pathPrefix, FNAME_TOUCH_TIME); fd = creat (path, 0666); close (fd); @@ -146,12 +150,12 @@ void zebraIndexUnlock (void) char path[1024]; char pathPrefix[1024]; - zebraLockPrefix (pathPrefix); + zebraLockPrefix (common_resource, pathPrefix); sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK); unlink (path); } -void zebraIndexLock (int commitNow) +void zebraIndexLock (BFiles bfs, int commitNow, const char *rval) { char path[1024]; char pathPrefix[1024]; @@ -160,7 +164,7 @@ void zebraIndexLock (int commitNow) if (lock_fd != -1) return ; - zebraLockPrefix (pathPrefix); + zebraLockPrefix (common_resource, pathPrefix); sprintf (path, "%s%s", pathPrefix, FNAME_MAIN_LOCK); while (1) { @@ -212,7 +216,7 @@ void zebraIndexLock (int commitNow) logf (LOG_WARN, "previous transaction didn't" " reach commit"); close (lock_fd); - bf_commitClean (); + bf_commitClean (bfs, rval); unlink (path); continue; } @@ -220,7 +224,7 @@ void zebraIndexLock (int commitNow) { logf (LOG_WARN, "commit file wan't deleted after commit"); close (lock_fd); - bf_commitClean (); + bf_commitClean (bfs, rval); unlink (path); continue; } diff --git a/index/locksrv.c b/index/locksrv.c index 5ea2c92..abb0349 100644 --- a/index/locksrv.c +++ b/index/locksrv.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: locksrv.c,v $ - * Revision 1.7 1997-09-04 13:58:04 adam + * Revision 1.8 1997-09-17 12:19:15 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.7 1997/09/04 13:58:04 adam * Added O_BINARY for open calls. * * Revision 1.6 1996/10/29 14:06:52 adam @@ -43,12 +47,12 @@ static int server_lock_cmt = -1; static int server_lock_org = -1; -int zebraServerLock (int commitPhase) +int zebraServerLock (Res res, int commitPhase) { char pathPrefix[1024]; char path[1024]; - zebraLockPrefix (pathPrefix); + zebraLockPrefix (res, pathPrefix); if (server_lock_cmt == -1) { @@ -98,7 +102,7 @@ void zebraServerUnlock (int commitPhase) } } -int zebraServerLockGetState (time_t *timep) +int zebraServerLockGetState (Res res, time_t *timep) { char pathPrefix[1024]; char path[1024]; @@ -106,7 +110,7 @@ int zebraServerLockGetState (time_t *timep) int fd; struct stat xstat; - zebraLockPrefix (pathPrefix); + zebraLockPrefix (res, pathPrefix); sprintf (path, "%s%s", pathPrefix, FNAME_TOUCH_TIME); if (stat (path, &xstat) == -1) diff --git a/index/lockutil.c b/index/lockutil.c index afed16d..1e0eb92 100644 --- a/index/lockutil.c +++ b/index/lockutil.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: lockutil.c,v $ - * Revision 1.7 1997-09-09 13:38:08 adam + * Revision 1.8 1997-09-17 12:19:15 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.7 1997/09/09 13:38:08 adam * Partial port to WIN95/NT. * * Revision 1.6 1996/10/29 14:08:14 adam @@ -46,10 +50,10 @@ static char *lockDir = NULL; -void zebraLockPrefix (char *pathPrefix) +void zebraLockPrefix (Res res, char *pathPrefix) { if (!lockDir) - lockDir = res_get_def (common_resource, "lockDir", ""); + lockDir = res_get_def (res, "lockDir", ""); assert (lockDir); strcpy (pathPrefix, lockDir); diff --git a/index/main.c b/index/main.c index d238bb9..4991924 100644 --- a/index/main.c +++ b/index/main.c @@ -1,10 +1,14 @@ /* - * Copyright (C) 1994-1996, Index Data I/S + * Copyright (C) 1994-1997, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: main.c,v $ - * Revision 1.48 1997-09-09 13:38:08 adam + * Revision 1.49 1997-09-17 12:19:15 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.48 1997/09/09 13:38:08 adam * Partial port to WIN95/NT. * * Revision 1.47 1997/02/12 20:39:46 adam @@ -192,6 +196,8 @@ char *prog; size_t mem_max = 0; +Res common_resource = 0; + static void abort_func (int level, const char *msg, void *info) { if (level & LOG_FATAL) @@ -218,6 +224,7 @@ int main (int argc, char **argv) rGroupDef.flagStoreKeys = -1; rGroupDef.flagShowRecords = 0; rGroupDef.fileVerboseLimit = 100000; + rGroupDef.dh = data1_create (); prog = *argv; if (argc < 2) @@ -262,10 +269,15 @@ int main (int argc, char **argv) configName); exit (1); } - data1_set_tabpath (res_get (common_resource, - "profilePath")); - bf_lockDir (res_get (common_resource, "lockDir")); - init_charmap(); + data1_set_tabpath (rGroupDef.dh, res_get (common_resource, + "profilePath")); + + rGroupDef.bfs = + bfs_create (res_get (common_resource, "register")); + + bf_lockDir (rGroupDef.bfs, + res_get (common_resource, "lockDir")); + init_charmap(common_resource); } if (!strcmp (arg, "update")) cmd = 'u'; @@ -279,56 +291,57 @@ int main (int argc, char **argv) cmd = 'd'; else if (!strcmp (arg, "commit")) { - zebraIndexLock (1); rval = res_get (common_resource, "shadow"); + zebraIndexLock (rGroupDef.bfs, 1, rval); if (rval && *rval) - bf_cache (1); + bf_cache (rGroupDef.bfs, rval); else { logf (LOG_FATAL, "Cannot perform commit"); logf (LOG_FATAL, "No shadow area defined"); exit (1); } - if (bf_commitExists ()) + if (bf_commitExists (rGroupDef.bfs)) { logf (LOG_LOG, "commit start"); zebraIndexLockMsg ("c"); zebraIndexWait (1); logf (LOG_LOG, "commit execute"); - bf_commitExec (); + bf_commitExec (rGroupDef.bfs); sync (); zebraIndexLockMsg ("d"); zebraIndexWait (0); logf (LOG_LOG, "commit clean"); - bf_commitClean (); + bf_commitClean (rGroupDef.bfs, rval); } else logf (LOG_LOG, "cothing to commit"); } else if (!strcmp (arg, "clean")) { - zebraIndexLock (1); - if (bf_commitExists ()) + rval = res_get (common_resource, "shadow"); + zebraIndexLock (rGroupDef.bfs, 1, rval); + if (bf_commitExists (rGroupDef.bfs)) { zebraIndexLockMsg ("d"); zebraIndexWait (0); logf (LOG_LOG, "commit clean"); - bf_commitClean (); + bf_commitClean (rGroupDef.bfs, rval); } else logf (LOG_LOG, "nothing to clean"); } else if (!strcmp (arg, "stat") || !strcmp (arg, "status")) { - zebraIndexLock (0); rval = res_get (common_resource, "shadow"); + zebraIndexLock (rGroupDef.bfs, 0, rval); if (rval && *rval) { - bf_cache (1); + bf_cache (rGroupDef.bfs, rval); zebraIndexLockMsg ("r"); } rec_prstat (); - inv_prstat (); + inv_prstat (rGroupDef.bfs); } else { @@ -341,16 +354,16 @@ int main (int argc, char **argv) struct recordGroup rGroup; log_event_end (abort_func, NULL); - zebraIndexLock (0); rval = res_get (common_resource, "shadow"); + zebraIndexLock (rGroupDef.bfs, 0, rval); if (rval && *rval && !disableCommit) { - bf_cache (1); + bf_cache (rGroupDef.bfs, rval); zebraIndexLockMsg ("r"); } else { - bf_cache (0); + bf_cache (rGroupDef.bfs, 0); zebraIndexLockMsg ("w"); } zebraIndexWait (0); @@ -360,20 +373,20 @@ int main (int argc, char **argv) switch (cmd) { case 'u': - key_open (mem_max); + key_open (rGroup.bfs, mem_max); logf (LOG_LOG, "updating %s", rGroup.path); repositoryUpdate (&rGroup); nsections = key_close (); break; case 'U': - key_open (mem_max); + key_open (rGroup.bfs,mem_max); logf (LOG_LOG, "updating (pass 1) %s", rGroup.path); repositoryUpdate (&rGroup); key_close (); nsections = 0; break; case 'd': - key_open (mem_max); + key_open (rGroup.bfs,mem_max); logf (LOG_LOG, "deleting %s", rGroup.path); repositoryDelete (&rGroup); nsections = key_close (); @@ -393,7 +406,7 @@ int main (int argc, char **argv) if (nsections) { logf (LOG_LOG, "merging with index"); - key_input (nsections, 60); + key_input (rGroup.bfs, nsections, 60); sync (); } log_event_end (NULL, NULL); @@ -428,7 +441,11 @@ int main (int argc, char **argv) } } if (common_resource) + { zebraIndexUnlock (); + bfs_destroy (rGroupDef.bfs); + } + data1_destroy (rGroupDef.dh); exit (0); } diff --git a/index/recindex.c b/index/recindex.c index a6dfbe9..25a997f 100644 --- a/index/recindex.c +++ b/index/recindex.c @@ -1,10 +1,14 @@ /* - * Copyright (C) 1994-1996, Index Data I/S + * Copyright (C) 1994-1997, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: recindex.c,v $ - * Revision 1.18 1997-07-15 16:28:42 adam + * Revision 1.19 1997-09-17 12:19:16 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.18 1997/07/15 16:28:42 adam * Bug fix: storeData didn't work with files with multiple records. * Bug fix: fixed memory management with records; not really well * thought through. @@ -261,7 +265,7 @@ static void rec_update_single (Records p, Record rec) rec_write_single (p, rec); } -Records rec_open (int rw) +Records rec_open (BFiles bfs, int rw) { Records p; int i, r; @@ -271,7 +275,7 @@ Records rec_open (int rw) p->tmp_size = 1024; p->tmp_buf = xmalloc (p->tmp_size); p->index_fname = "recindex"; - p->index_BFile = bf_open (p->index_fname, 128, rw); + p->index_BFile = bf_open (bfs, p->index_fname, 128, rw); if (p->index_BFile == NULL) { logf (LOG_FATAL|LOG_ERRNO, "open %s", p->index_fname); @@ -321,7 +325,7 @@ Records rec_open (int rw) } for (i = 0; idata_BFile[i] = bf_open (p->data_fname[i], + if (!(p->data_BFile[i] = bf_open (bfs, p->data_fname[i], p->head.block_size[i], rw))) { diff --git a/index/recindex.h b/index/recindex.h index af1da33..40c2c68 100644 --- a/index/recindex.h +++ b/index/recindex.h @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: recindex.h,v $ - * Revision 1.10 1996-10-29 14:06:53 adam + * Revision 1.11 1997-09-17 12:19:16 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.10 1996/10/29 14:06:53 adam * Include zebrautl.h instead of alexutil.h. * * Revision 1.9 1996/05/01 13:46:36 adam @@ -46,6 +50,7 @@ */ #include +#include #define REC_NO_INFO 8 @@ -65,7 +70,7 @@ void rec_put (Records p, Record *recpp); Record rec_new (Records p); Record rec_get (Records p, int sysno); void rec_close (Records *p); -Records rec_open (int rw); +Records rec_open (BFiles bfs, int rw); char *rec_strdup (const char *s, size_t *len); enum { diff --git a/index/recstat.c b/index/recstat.c index 882f228..dc904b0 100644 --- a/index/recstat.c +++ b/index/recstat.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: recstat.c,v $ - * Revision 1.4 1997-09-09 13:38:08 adam + * Revision 1.5 1997-09-17 12:19:17 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.4 1997/09/09 13:38:08 adam * Partial port to WIN95/NT. * * Revision 1.3 1996/06/04 10:19:00 adam @@ -30,9 +34,9 @@ #endif #include "recindxp.h" -void rec_prstat (void) +void rec_prstat (BFiles bfs) { - Records records = rec_open (0); + Records records = rec_open (bfs, 0); int i; int total_bytes = 0; diff --git a/index/trav.c b/index/trav.c index 9b5ecec..e251f24 100644 --- a/index/trav.c +++ b/index/trav.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: trav.c,v $ - * Revision 1.30 1997-09-09 13:38:09 adam + * Revision 1.31 1997-09-17 12:19:17 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.30 1997/09/09 13:38:09 adam * Partial port to WIN95/NT. * * Revision 1.29 1997/02/12 20:39:47 adam @@ -356,7 +360,7 @@ void repositoryShow (struct recordGroup *rGroup) Dict dict; struct dirs_info *di; - if (!(dict = dict_open (FMATCH_DICT, 50, 1))) + if (!(dict = dict_open (rGroup->bfs, FMATCH_DICT, 50, 1))) { logf (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT); exit (1); @@ -471,7 +475,7 @@ void repositoryUpdate (struct recordGroup *rGroup) if (rGroup->recordId && !strcmp (rGroup->recordId, "file")) { Dict dict; - if (!(dict = dict_open (FMATCH_DICT, 50, 1))) + if (!(dict = dict_open (rGroup->bfs, FMATCH_DICT, 50, 1))) { logf (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT); exit (1); diff --git a/index/trunc.c b/index/trunc.c index d1deaa1..3212c6d 100644 --- a/index/trunc.c +++ b/index/trunc.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: trunc.c,v $ - * Revision 1.4 1996-12-23 15:30:44 adam + * Revision 1.5 1997-09-17 12:19:17 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.4 1996/12/23 15:30:44 adam * Work on truncation. * Bug fix: result sets weren't deleted after server shut down. * @@ -139,6 +143,7 @@ static RSET rset_trunc_r (ZServerInfo *zi, ISAM_P *isam_p, int from, int to, rset_temp_parms parms; parms.key_size = sizeof(struct it_key); + parms.temp_path = res_get (zi->res, "setTmpDir"); result = rset_create (rset_kind_temp, &parms); result_rsfd = rset_open (result, RSETF_WRITE|RSETF_SORT_SYSNO); diff --git a/index/zrpn.c b/index/zrpn.c index f196a52..8a6af0b 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zrpn.c,v $ - * Revision 1.62 1997-09-05 15:30:09 adam + * Revision 1.63 1997-09-17 12:19:18 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.62 1997/09/05 15:30:09 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -220,7 +224,6 @@ #include #include "zserver.h" -#include "attribute.h" #include #include @@ -674,13 +677,12 @@ static int field_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt, for (base_no = 0; base_no < num_bases; base_no++) { - attent *attp; + attent attp; data1_local_attribute *local_attr; int max_pos, prefix_len = 0; termp = *term_sub; - attp = att_getentbyatt (curAttributeSet, use_value); - if (!attp) + if (!att_getentbyatt (zi, &attp, curAttributeSet, use_value)) { logf (LOG_DEBUG, "att_getentbyatt fail. set=%d use=%d", curAttributeSet, use_value); @@ -693,12 +695,12 @@ static int field_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt, zi->errString = basenames[base_no]; return -1; } - for (local_attr = attp->local_attributes; local_attr; + for (local_attr = attp.local_attributes; local_attr; local_attr = local_attr->next) { int ord; - ord = zebTargetInfo_lookupSU (zi->zti, attp->attset_ordinal, + ord = zebTargetInfo_lookupSU (zi->zti, attp.attset_ordinal, local_attr->local); if (ord < 0) continue; @@ -927,7 +929,8 @@ static RSET rpn_search_APT_cphrase (ZServerInfo *zi, return result; } -static RSET rpn_proximity (RSET rset1, RSET rset2, int ordered, +static RSET rpn_proximity (ZServerInfo *zi, RSET rset1, RSET rset2, + int ordered, int exclusion, int relation, int distance) { int i; @@ -945,6 +948,7 @@ static RSET rpn_proximity (RSET rset1, RSET rset2, int ordered, more2 = rset_read (rset2, rsfd2, &buf2); parms.key_size = sizeof (struct it_key); + parms.temp_path = res_get (zi->res, "setTmpDir"); result = rset_create (rset_kind_temp, &parms); rsfd_result = rset_open (result, RSETF_WRITE|RSETF_SORT_SYSNO); @@ -1016,7 +1020,7 @@ static RSET rpn_proximity (RSET rset1, RSET rset2, int ordered, return result; } -static RSET rpn_prox (RSET *rset, int rset_no) +static RSET rpn_prox (ZServerInfo *zi, RSET *rset, int rset_no) { int i; RSFD *rsfd; @@ -1049,6 +1053,7 @@ static RSET rpn_prox (RSET *rset, int rset_no) } } parms.key_size = sizeof (struct it_key); + parms.temp_path = res_get (zi->res, "setTmpDir"); result = rset_create (rset_kind_temp, &parms); rsfd_result = rset_open (result, RSETF_WRITE|RSETF_SORT_SYSNO); @@ -1147,7 +1152,7 @@ static RSET rpn_search_APT_phrase (ZServerInfo *zi, return rset_create (rset_kind_null, NULL); else if (rset_no == 1) return (rset[0]); - result = rpn_prox (rset, rset_no); + result = rpn_prox (zi, rset, rset_no); for (i = 0; ires, "setTmpDir"); result = rset_create (rset_kind_temp, &parms); rsfd = rset_open (result, RSETF_WRITE|RSETF_SORT_SYSNO); @@ -1330,7 +1336,7 @@ static RSET rpn_search_structure (ZServerInfo *zi, Z_RPNStructure *zs, sprintf (val, "%d", *zop->u.prox->proximityUnitCode); return NULL; } - r = rpn_proximity (bool_parms.rset_l, bool_parms.rset_r, + r = rpn_proximity (zi, bool_parms.rset_l, bool_parms.rset_r, *zop->u.prox->ordered, (!zop->u.prox->exclusion ? 0 : *zop->u.prox->exclusion), @@ -1369,7 +1375,7 @@ static RSET rpn_search_structure (ZServerInfo *zi, Z_RPNStructure *zs, return r; } -void count_set_save (RSET *r, int *count) +void count_set_save (ZServerInfo *zi, RSET *r, int *count) { int psysno = 0; int kno = 0; @@ -1377,11 +1383,12 @@ void count_set_save (RSET *r, int *count) RSFD rfd, wfd; RSET w; rset_temp_parms parms; - int maxResultSetSize = atoi (res_get_def (common_resource, + int maxResultSetSize = atoi (res_get_def (zi->res, "maxResultSetSize", "400")); logf (LOG_DEBUG, "count_set_save"); *count = 0; parms.key_size = sizeof(struct it_key); + parms.temp_path = res_get (zi->res, "setTmpDir"); w = rset_create (rset_kind_temp, &parms); wfd = rset_open (w, RSETF_WRITE|RSETF_SORT_SYSNO); rfd = rset_open (*r, RSETF_READ|RSETF_SORT_SYSNO); @@ -1447,7 +1454,7 @@ int rpn_search (ZServerInfo *zi, if (!rset) return zi->errCode; if (rset_is_volatile(rset)) - count_set_save(&rset,hits); + count_set_save(zi, &rset,hits); else count_set (rset, hits); resultSetAdd (zi, setname, 1, rset); @@ -1542,11 +1549,10 @@ int rpn_scan (ZServerInfo *zi, Z_AttributesPlusTerm *zapt, use_value = 1016; for (base_no = 0; base_no < num_bases && ord_no < 32; base_no++) { - attent *attp; + attent attp; data1_local_attribute *local_attr; - attp = att_getentbyatt (attributeset, use_value); - if (!attp) + if (!att_getentbyatt (zi, &attp, attributeset, use_value)) { logf (LOG_DEBUG, "att_getentbyatt fail. set=%d use=%d", attributeset, use_value); @@ -1557,12 +1563,12 @@ int rpn_scan (ZServerInfo *zi, Z_AttributesPlusTerm *zapt, zi->errString = basenames[base_no]; return zi->errCode = 109; /* Database unavailable */ } - for (local_attr = attp->local_attributes; local_attr && ord_no < 32; + for (local_attr = attp.local_attributes; local_attr && ord_no < 32; local_attr = local_attr->next) { int ord; - ord = zebTargetInfo_lookupSU (zi->zti, attp->attset_ordinal, + ord = zebTargetInfo_lookupSU (zi->zti, attp.attset_ordinal, local_attr->local); if (ord > 0) ords[ord_no++] = ord; diff --git a/index/zserver.c b/index/zserver.c index e9fc320..9c59eae 100644 --- a/index/zserver.c +++ b/index/zserver.c @@ -1,10 +1,14 @@ /* - * Copyright (C) 1995-1996, Index Data I/S + * Copyright (C) 1995-1997, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: zserver.c,v $ - * Revision 1.47 1997-09-04 13:58:36 adam + * Revision 1.48 1997-09-17 12:19:19 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.47 1997/09/04 13:58:36 adam * New retrieve/extract method tellf (added). * Added O_BINARY for open calls. * @@ -177,7 +181,6 @@ #include #include -#include #include #include #include @@ -192,7 +195,6 @@ #endif #include "zserver.h" -ZServerInfo server_info; #if USE_TIMES static struct tms tms1; @@ -202,7 +204,7 @@ static struct tms tms2; static int register_lock (ZServerInfo *zi) { time_t lastChange; - int state = zebraServerLockGetState(&lastChange); + int state = zebraServerLockGetState(zi->res, &lastChange); switch (state) { @@ -212,7 +214,7 @@ static int register_lock (ZServerInfo *zi) default: state = 0; } - zebraServerLock (state); + zebraServerLock (zi->res, state); #if USE_TIMES times (&tms1); #endif @@ -239,27 +241,28 @@ static int register_lock (ZServerInfo *zi) isc_close (zi->isamc); rec_close (&zi->records); } - bf_cache (state); + bf_cache (zi->bfs, state ? res_get (zi->res, "shadow") : NULL); zi->registerState = state; - zi->records = rec_open (0); - if (!(zi->dict = dict_open (FNAME_DICT, 40, 0))) + zi->records = rec_open (zi->bfs, 0); + if (!(zi->dict = dict_open (zi->bfs, FNAME_DICT, 40, 0))) return -1; zi->isam = NULL; zi->isamc = NULL; - if (res_get_match (common_resource, "isam", "c", NULL)) + if (res_get_match (zi->res, "isam", "c", NULL)) { - if (!(zi->isamc = isc_open (FNAME_ISAMC, 0, key_isamc_m()))) + if (!(zi->isamc = isc_open (zi->bfs, FNAME_ISAMC, + 0, key_isamc_m(zi->res)))) return -1; } else { - if (!(zi->isam = is_open (FNAME_ISAM, key_compare, 0, - sizeof (struct it_key)))) + if (!(zi->isam = is_open (zi->bfs, FNAME_ISAM, key_compare, 0, + sizeof (struct it_key), zi->res))) return -1; } zi->zti = zebTargetInfo_open (zi->records, 0); - init_charmap (); + init_charmap (zi->res); return 0; } @@ -275,7 +278,7 @@ static void register_unlock (ZServerInfo *zi) #endif if (waitSec == -1) { - char *s = res_get (common_resource, "debugRequestWait"); + char *s = res_get (zi->res, "debugRequestWait"); if (s) waitSec = atoi (s); else @@ -289,106 +292,114 @@ static void register_unlock (ZServerInfo *zi) bend_initresult *bend_init (bend_initrequest *q) { - static bend_initresult r; - static char *name = "zserver"; + bend_initresult *r = odr_malloc (q->stream, sizeof(*r)); + ZServerInfo *zi = xmalloc (sizeof(*zi)); + struct statserv_options_block *sob; - r.errcode = 0; - r.errstring = 0; - r.handle = name; + r->errcode = 0; + r->errstring = 0; + r->handle = zi; logf (LOG_DEBUG, "bend_init"); - if (!common_resource) + sob = statserv_getcontrol (); + logf (LOG_LOG, "Reading resources from %s", sob->configname); + if (!(zi->res = res_open (sob->configname))) { - struct statserv_options_block *sob; - - sob = statserv_getcontrol (); - logf (LOG_LOG, "Reading resources from %s", sob->configname); - if (!(common_resource = res_open (sob->configname))) - { - logf (LOG_FATAL, "Cannot open resource `%s'", sob->configname); - exit (1); - } - bf_lockDir (res_get (common_resource, "lockDir")); - data1_set_tabpath (res_get(common_resource, "profilePath")); + logf (LOG_FATAL, "Cannot open resource `%s'", sob->configname); + exit (1); } - server_info.sets = NULL; - server_info.registerState = -1; /* trigger open of registers! */ - server_info.registerChange = 0; - - server_info.records = NULL; - server_info.odr = odr_createmem (ODR_ENCODE); - return &r; + zi->dh = data1_create (); + zi->bfs = bfs_create (res_get (zi->res, "register")); + bf_lockDir (zi->bfs, res_get (zi->res, "lockDir")); + data1_set_tabpath (zi->dh, res_get(zi->res, "profilePath")); + zi->sets = NULL; + zi->registerState = -1; /* trigger open of registers! */ + zi->registerChange = 0; + + zi->records = NULL; + zi->odr = odr_createmem (ODR_ENCODE); + zi->registered_sets = NULL; + return r; } bend_searchresult *bend_search (void *handle, bend_searchrequest *q, int *fd) { - static bend_searchresult r; + ZServerInfo *zi = handle; + bend_searchresult *r = odr_malloc (q->stream, sizeof(*r)); - r.errcode = 0; - r.errstring = 0; - r.hits = 0; + r->errcode = 0; + r->errstring = 0; + r->hits = 0; - register_lock (&server_info); - odr_reset (server_info.odr); - server_info.errCode = 0; - server_info.errString = NULL; + register_lock (zi); + odr_reset (zi->odr); + zi->errCode = 0; + zi->errString = NULL; logf (LOG_LOG, "ResultSet '%s'", q->setname); switch (q->query->which) { case Z_Query_type_1: case Z_Query_type_101: - r.errcode = rpn_search (&server_info, q->query->u.type_1, + r->errcode = rpn_search (zi, q->query->u.type_1, q->num_bases, q->basenames, q->setname, - &r.hits); - r.errstring = server_info.errString; + &r->hits); + r->errstring = zi->errString; break; default: - r.errcode = 107; + r->errcode = 107; } - register_unlock (&server_info); - return &r; + register_unlock (zi); + return r; } -static int record_offset; +struct fetch_control { + int record_offset; + int record_int_pos; + char *record_int_buf; + int record_int_len; + int fd; +}; static int record_ext_read (void *fh, char *buf, size_t count) { - return read (*((int*) fh), buf, count); + struct fetch_control *fc = fh; + return read (fc->fd, buf, count); } static off_t record_ext_seek (void *fh, off_t offset) { - return lseek (*((int*) fh), offset + record_offset, SEEK_SET); + struct fetch_control *fc = fh; + return lseek (fc->fd, offset + fc->record_offset, SEEK_SET); } static off_t record_ext_tell (void *fh) { - return lseek (*((int*) fh), 0, SEEK_CUR) - record_offset; + struct fetch_control *fc = fh; + return lseek (fc->fd, 0, SEEK_CUR) - fc->record_offset; } -static int record_int_pos; -static char *record_int_buf; -static int record_int_len; - static off_t record_int_seek (void *fh, off_t offset) { - return (off_t) (record_int_pos = offset); + struct fetch_control *fc = fh; + return (off_t) (fc->record_int_pos = offset); } static off_t record_int_tell (void *fh) { - return (off_t) record_int_pos; + struct fetch_control *fc = fh; + return (off_t) fc->record_int_pos; } static int record_int_read (void *fh, char *buf, size_t count) { - int l = record_int_len - record_int_pos; + struct fetch_control *fc = fh; + int l = fc->record_int_len - fc->record_int_pos; if (l <= 0) return 0; l = (l < count) ? l : count; - memcpy (buf, record_int_buf + record_int_pos, l); - record_int_pos += l; + memcpy (buf, fc->record_int_buf + fc->record_int_pos, l); + fc->record_int_pos += l; return l; } @@ -400,9 +411,9 @@ static int record_fetch (ZServerInfo *zi, int sysno, int score, ODR stream, Record rec; char *fname, *file_type, *basename; RecType rt; - int fd = -1; struct recRetrieveCtrl retrieveCtrl; char subType[128]; + struct fetch_control fc; rec = rec_get (zi->records, sysno); if (!rec) @@ -423,29 +434,30 @@ static int record_fetch (ZServerInfo *zi, int sysno, int score, ODR stream, exit (1); } logf (LOG_DEBUG, "retrieve localno=%d score=%d", sysno, score); + retrieveCtrl.fh = &fc; + fc.fd = -1; if (rec->size[recInfo_storeData] > 0) { retrieveCtrl.readf = record_int_read; retrieveCtrl.seekf = record_int_seek; retrieveCtrl.tellf = record_int_tell; - record_int_len = rec->size[recInfo_storeData]; - record_int_buf = rec->info[recInfo_storeData]; - record_int_pos = 0; - logf (LOG_DEBUG, "Internal retrieve. %d bytes", record_int_len); + fc.record_int_len = rec->size[recInfo_storeData]; + fc.record_int_buf = rec->info[recInfo_storeData]; + fc.record_int_pos = 0; + logf (LOG_DEBUG, "Internal retrieve. %d bytes", fc.record_int_len); } else { - if ((fd = open (fname, O_BINARY|O_RDONLY)) == -1) + if ((fc.fd = open (fname, O_BINARY|O_RDONLY)) == -1) { logf (LOG_WARN|LOG_ERRNO, "Retrieve fail; missing file: %s", fname); rec_rm (&rec); return 14; } - memcpy (&record_offset, rec->info[recInfo_offset], - sizeof(record_offset)); + memcpy (&fc.record_offset, rec->info[recInfo_offset], + sizeof(fc.record_offset)); - retrieveCtrl.fh = &fd; retrieveCtrl.readf = record_ext_read; retrieveCtrl.seekf = record_ext_seek; retrieveCtrl.tellf = record_ext_tell; @@ -459,12 +471,13 @@ static int record_fetch (ZServerInfo *zi, int sysno, int score, ODR stream, retrieveCtrl.input_format = retrieveCtrl.output_format = input_format; retrieveCtrl.comp = comp; retrieveCtrl.diagnostic = 0; + retrieveCtrl.dh = zi->dh; (*rt->retrieve)(&retrieveCtrl); *output_format = retrieveCtrl.output_format; *rec_bufp = retrieveCtrl.rec_buf; *rec_lenp = retrieveCtrl.rec_len; - if (fd != -1) - close (fd); + if (fc.fd != -1) + close (fc.fd); rec_rm (&rec); return retrieveCtrl.diagnostic; @@ -472,87 +485,93 @@ static int record_fetch (ZServerInfo *zi, int sysno, int score, ODR stream, bend_fetchresult *bend_fetch (void *handle, bend_fetchrequest *q, int *num) { - static bend_fetchresult r; + ZServerInfo *zi = handle; + bend_fetchresult *r = odr_malloc (q->stream, sizeof(*r)); int positions[2]; ZServerSetSysno *records; - register_lock (&server_info); + register_lock (zi); - r.errstring = 0; - r.last_in_set = 0; - r.basename = "base"; + r->errstring = 0; + r->last_in_set = 0; + r->basename = "base"; - odr_reset (server_info.odr); - server_info.errCode = 0; + odr_reset (zi->odr); + zi->errCode = 0; positions[0] = q->number; - records = resultSetSysnoGet (&server_info, q->setname, 1, positions); + records = resultSetSysnoGet (zi, q->setname, 1, positions); if (!records) { logf (LOG_DEBUG, "resultSetRecordGet, error"); - r.errcode = 13; - register_unlock (&server_info); - return &r; + r->errcode = 13; + register_unlock (zi); + return r; } if (!records[0].sysno) { - r.errcode = 13; + r->errcode = 13; logf (LOG_DEBUG, "Out of range. pos=%d", q->number); - register_unlock (&server_info); - return &r; + register_unlock (zi); + return r; } - r.errcode = record_fetch (&server_info, records[0].sysno, + r->errcode = record_fetch (zi, records[0].sysno, records[0].score, q->stream, q->format, - q->comp, &r.format, &r.record, &r.len, - &r.basename); - resultSetSysnoDel (&server_info, records, 1); - register_unlock (&server_info); - return &r; + q->comp, &r->format, &r->record, &r->len, + &r->basename); + resultSetSysnoDel (zi, records, 1); + register_unlock (zi); + return r; } bend_deleteresult *bend_delete (void *handle, bend_deleterequest *q, int *num) { - register_lock (&server_info); - register_unlock (&server_info); + ZServerInfo *zi = handle; + register_lock (zi); + register_unlock (zi); return 0; } bend_scanresult *bend_scan (void *handle, bend_scanrequest *q, int *num) { - static bend_scanresult r; + ZServerInfo *zi = handle; + bend_scanresult *r = odr_malloc (q->stream, sizeof(*r)); int status; - register_lock (&server_info); - odr_reset (server_info.odr); - server_info.errCode = 0; - server_info.errString = 0; + register_lock (zi); + odr_reset (zi->odr); + zi->errCode = 0; + zi->errString = 0; - r.term_position = q->term_position; - r.num_entries = q->num_entries; - r.errcode = rpn_scan (&server_info, q->term, + r->term_position = q->term_position; + r->num_entries = q->num_entries; + r->errcode = rpn_scan (zi, q->term, q->attributeset, q->num_bases, q->basenames, - &r.term_position, - &r.num_entries, &r.entries, &status); - r.errstring = server_info.errString; - r.status = status; - register_unlock (&server_info); - return &r; + &r->term_position, + &r->num_entries, &r->entries, &status); + r->errstring = zi->errString; + r->status = status; + register_unlock (zi); + return r; } void bend_close (void *handle) { - if (server_info.records) + ZServerInfo *zi = handle; + if (zi->records) { - resultSetDestroy (&server_info); - dict_close (server_info.dict); - if (server_info.isam) - is_close (server_info.isam); - if (server_info.isamc) - isc_close (server_info.isamc); - rec_close (&server_info.records); - register_unlock (&server_info); + resultSetDestroy (zi); + dict_close (zi->dict); + if (zi->isam) + is_close (zi->isam); + if (zi->isamc) + isc_close (zi->isamc); + rec_close (&zi->records); + register_unlock (zi); } + bfs_destroy (zi->bfs); + data1_destroy (zi->dh); return; } diff --git a/index/zserver.h b/index/zserver.h index d2874a4..f2c014d 100644 --- a/index/zserver.h +++ b/index/zserver.h @@ -1,10 +1,14 @@ /* - * Copyright (C) 1994-1996, Index Data I/S + * Copyright (C) 1994-1997, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: zserver.h,v $ - * Revision 1.23 1996-12-23 15:30:46 adam + * Revision 1.24 1997-09-17 12:19:19 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.23 1996/12/23 15:30:46 adam * Work on truncation. * Bug fix: result sets weren't deleted after server shut down. * @@ -110,6 +114,10 @@ typedef struct { char *errString; ODR odr; ZebTargetInfo *zti; + data1_handle dh; + data1_attset *registered_sets; + BFiles bfs; + Res res; } ZServerInfo; int rpn_search (ZServerInfo *zi, @@ -134,6 +142,14 @@ ZServerSetSysno *resultSetSysnoGet (ZServerInfo *zi, const char *name, void resultSetSysnoDel (ZServerInfo *zi, ZServerSetSysno *records, int num); void zlog_rpn (Z_RPNQuery *rpn); -int zebraServerLock (int lockCommit); +int zebraServerLock (Res res, int lockCommit); void zebraServerUnlock (int commitPhase); -int zebraServerLockGetState (time_t *timep); +int zebraServerLockGetState (Res res, time_t *timep); + +typedef struct attent +{ + int attset_ordinal; + data1_local_attribute *local_attributes; +} attent; + +int att_getentbyatt(ZServerInfo *zi, attent *res, oid_value set, int att); diff --git a/isam/Makefile b/isam/Makefile index 21fa8c9..9737347 100644 --- a/isam/Makefile +++ b/isam/Makefile @@ -1,13 +1,13 @@ -# Copyright (C) 1994, Index Data I/S +# Copyright (C) 1994-1997, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.20 1996-10-29 13:56:51 adam Exp $ +# $Id: Makefile,v 1.21 1997-09-17 12:19:20 adam Exp $ SHELL=/bin/sh RANLIB=ranlib -YAZLIB=-lyaz -YAZINC= +YAZLIB=../../yaz/lib/libyaz.a +YAZINC=-I../../yaz/include INCLUDE=-I../include $(YAZINC) DEFS=$(INCLUDE) diff --git a/isam/isam.c b/isam/isam.c index 380ccec..eaffdbc 100644 --- a/isam/isam.c +++ b/isam/isam.c @@ -1,10 +1,14 @@ /* - * Copyright (C) 1994, Index Data I/S + * Copyright (C) 1994-1997, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: isam.c,v $ - * Revision 1.22 1996-10-29 13:56:53 adam + * Revision 1.23 1997-09-17 12:19:20 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.22 1996/10/29 13:56:53 adam * Include of zebrautl.h instead of alexutil.h. * * Revision 1.21 1996/03/29 14:11:47 quinn @@ -79,7 +83,6 @@ #include #include #include -#include #include "isutil.h" #include "rootblk.h" #include "keyops.h" @@ -149,8 +152,9 @@ static int splitargs(const char *s, char *bf[], int max) * Open isam file. * Process resources. */ -ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2), - int writeflag, int keysize) +ISAM is_open(BFiles bfs, const char *name, + int (*cmp)(const void *p1, const void *p2), + int writeflag, int keysize, Res res) { ISAM new; char *nm, *r, *pp[IS_MAX_BLOCKTYPES+1], m[2]; @@ -181,8 +185,9 @@ ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2), new->types[i].index = 0; /* dummy */ /* determine number and size of blocktypes */ - if (!(r = res_get_def(common_resource, nm = strconcat(name, ".", - "blocktypes", 0), "64 512 4K 32K")) || + if (!(r = res_get_def(res, + nm = strconcat(name, ".", + "blocktypes", 0), "64 512 4K 32K")) || !(num = splitargs(r, pp, IS_MAX_BLOCKTYPES))) { logf (LOG_FATAL, "Failed to locate resource %s", nm); @@ -213,7 +218,7 @@ ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2), new->types[i].dbuf = xmalloc(new->types[i].blocksize); m[0] = 'A' + i; m[1] = '\0'; - if (!(new->types[i].bf = bf_open(strconcat(name, m, 0), + if (!(new->types[i].bf = bf_open(bfs, strconcat(name, m, 0), new->types[i].blocksize, writeflag))) { logf (LOG_FATAL, "bf_open failed"); @@ -245,9 +250,8 @@ ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2), new->keysize = keysize; else { - if (!(r = res_get_def(common_resource, nm = strconcat(name, ".", - "keysize", - 0), "4"))) + if (!(r = res_get_def(res, nm = strconcat(name, ".", + "keysize", 0), "4"))) { logf (LOG_FATAL, "Failed to locate resource %s", nm); return 0; @@ -260,8 +264,8 @@ ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2), } /* determine repack percent */ - if (!(r = res_get_def(common_resource, nm = strconcat(name, ".", "repack", - 0), IS_DEF_REPACK_PERCENT))) + if (!(r = res_get_def(res, nm = strconcat(name, ".", "repack", + 0), IS_DEF_REPACK_PERCENT))) { logf (LOG_FATAL, "Failed to locate resource %s", nm); return 0; @@ -269,9 +273,10 @@ ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2), new->repack = atoi(r); /* determine max keys/blocksize */ - if (!(r = res_get_def(common_resource, nm = strconcat(name, ".", - "maxkeys", 0), "50 640 10000")) || !(num = splitargs(r, pp, - IS_MAX_BLOCKTYPES))) + if (!(r = res_get_def(res, + nm = strconcat(name, ".", + "maxkeys", 0), "50 640 10000")) || + !(num = splitargs(r, pp, IS_MAX_BLOCKTYPES))) { logf (LOG_FATAL, "Failed to locate resource %s", nm); return 0; @@ -312,9 +317,10 @@ ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2), } /* determine nice fill rates */ - if (!(r = res_get_def(common_resource, nm = strconcat(name, ".", - "nicefill", 0), "90 90 90 95")) || !(num = splitargs(r, pp, - IS_MAX_BLOCKTYPES))) + if (!(r = res_get_def(res, + nm = strconcat(name, ".", + "nicefill", 0), "90 90 90 95")) || + !(num = splitargs(r, pp, IS_MAX_BLOCKTYPES))) { logf (LOG_FATAL, "Failed to locate resource %s", nm); return 0; diff --git a/isamc/isamc.c b/isamc/isamc.c index e276a07..6d64d79 100644 --- a/isamc/isamc.c +++ b/isamc/isamc.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: isamc.c,v $ - * Revision 1.7 1997-02-12 20:42:43 adam + * Revision 1.8 1997-09-17 12:19:20 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.7 1997/02/12 20:42:43 adam * Bug fix: during isc_merge operations, some pages weren't marked dirty * even though they should be. At this point the merge operation marks * a page dirty if the previous page changed at all. A better approach is @@ -74,7 +78,7 @@ ISAMC_M isc_getmethod (void) } -ISAMC isc_open (const char *name, int writeflag, ISAMC_M method) +ISAMC isc_open (BFiles bfs, const char *name, int writeflag, ISAMC_M method) { ISAMC is; ISAMC_filecat filecat; @@ -123,7 +127,7 @@ ISAMC isc_open (const char *name, int writeflag, ISAMC_M method) char fname[512]; sprintf (fname, "%s%c", name, i+'A'); - is->files[i].bf = bf_open (fname, is->method->filecat[i].bsize, + is->files[i].bf = bf_open (bfs, fname, is->method->filecat[i].bsize, writeflag); is->files[i].head_is_dirty = 0; if (!bf_read (is->files[i].bf, 0, 0, sizeof(ISAMC_head), diff --git a/recctrl/grsread.h b/recctrl/grsread.h index 247c615..1e522b9 100644 --- a/recctrl/grsread.h +++ b/recctrl/grsread.h @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: grsread.h,v $ - * Revision 1.3 1997-09-04 13:54:40 adam + * Revision 1.4 1997-09-17 12:19:21 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.3 1997/09/04 13:54:40 adam * Added MARC filter - type grs.marc. where syntax refers * to abstract syntax. New method tellf in retrieve/extract method. * @@ -29,6 +33,7 @@ struct grs_read_info { off_t offset; char type[80]; NMEM mem; + data1_handle dh; }; data1_node *grs_read_regx (struct grs_read_info *p); diff --git a/recctrl/marcread.c b/recctrl/marcread.c index 3f09254..44d93f5 100644 --- a/recctrl/marcread.c +++ b/recctrl/marcread.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: marcread.c,v $ - * Revision 1.1 1997-09-04 13:54:40 adam + * Revision 1.2 1997-09-17 12:19:21 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.1 1997/09/04 13:54:40 adam * Added MARC filter - type grs.marc. where syntax refers * to abstract syntax. New method tellf in retrieve/extract method. * @@ -18,9 +22,9 @@ #include #include "grsread.h" -data1_node *data1_mk_node_wp (NMEM mem, data1_node *parent) +data1_node *data1_mk_node_wp (data1_handle dh, NMEM mem, data1_node *parent) { - data1_node *res = data1_mk_node (mem); + data1_node *res = data1_mk_node (dh, mem); if (!parent) res->root = res; @@ -44,10 +48,10 @@ static void destroy_data (struct data1_node *n) xfree (n->u.data.data); } -data1_node *data1_mk_node_text (NMEM mem, data1_node *parent, +data1_node *data1_mk_node_text (data1_handle dh, NMEM mem, data1_node *parent, const char *buf, size_t len) { - data1_node *res = data1_mk_node_wp (mem, parent); + data1_node *res = data1_mk_node_wp (dh, mem, parent); res->which = DATA1N_data; res->u.data.formatted_text = 0; res->u.data.what = DATA1I_text; @@ -62,16 +66,16 @@ data1_node *data1_mk_node_text (NMEM mem, data1_node *parent, return res; } -data1_node *data1_mk_node_tag (NMEM mem, data1_node *parent, +data1_node *data1_mk_node_tag (data1_handle dh, NMEM mem, data1_node *parent, const char *tag, size_t len) { data1_element *elem = NULL; - data1_node *partag = get_parent_tag(parent); + data1_node *partag = get_parent_tag(dh, parent); data1_node *res; data1_element *e = NULL; int localtag = 0; - res = data1_mk_node_wp (mem, parent); + res = data1_mk_node_wp (dh, mem, parent); res->which = DATA1N_tag; res->u.tag.tag = res->lbuf; @@ -89,7 +93,7 @@ data1_node *data1_mk_node_tag (NMEM mem, data1_node *parent, if (!(e = partag->u.tag.element)) localtag = 1; - elem = data1_getelementbytagname (res->root->u.root.absyn, e, + elem = data1_getelementbytagname (dh, res->root->u.root.absyn, e, res->u.tag.tag); res->u.tag.element = elem; res->u.tag.node_selected = 0; @@ -144,12 +148,12 @@ data1_node *grs_read_marc (struct grs_read_info *p) } absynName = p->type; logf (LOG_DEBUG, "absynName = %s", absynName); - if (!(absyn = data1_get_absyn (absynName))) + if (!(absyn = data1_get_absyn (p->dh, absynName))) { logf (LOG_WARN, "Unknown abstract syntax: %s", absynName); return NULL; } - res_root = data1_mk_node_wp (p->mem, NULL); + res_root = data1_mk_node_wp (p->dh, p->mem, NULL); res_root->u.root.type = nmem_malloc (p->mem, strlen(absynName)+1); strcpy (res_root->u.root.type, absynName); res_root->u.root.absyn = absyn; @@ -182,7 +186,7 @@ data1_node *grs_read_marc (struct grs_read_info *p) tag[3] = '\0'; /* generate field node */ - res = data1_mk_node_tag (p->mem, res_root, tag, 3); + res = data1_mk_node_tag (p->dh, p->mem, res_root, tag, 3); #if MARC_DEBUG fprintf (outf, "%s ", tag); @@ -200,7 +204,8 @@ data1_node *grs_read_marc (struct grs_read_info *p) #if MARC_DEBUG int j; #endif - res = data1_mk_node_tag (p->mem, res, buf+i, indicator_length); + res = data1_mk_node_tag (p->dh, p->mem, res, buf+i, + indicator_length); #if MARC_DEBUG for (j = 0; jmem, parent, buf+i+1, - identifier_length-1); + data1_node *res = + data1_mk_node_tag (p->dh, p->mem, parent, + buf+i+1, identifier_length-1); #if MARC_DEBUG fprintf (outf, " $"); for (j = 1; jmem, res, buf + i0, i - i0); + data1_mk_node_text (p->dh, p->mem, res, buf + i0, i - i0); i0 = i; } else @@ -245,8 +251,9 @@ data1_node *grs_read_marc (struct grs_read_info *p) } if (i > i0) { - data1_node *res = data1_mk_node_tag (p->mem, parent, "@", 1); - data1_mk_node_text (p->mem, res, buf + i0, i - i0); + data1_node *res = data1_mk_node_tag (p->dh, p->mem, + parent, "@", 1); + data1_mk_node_text (p->dh, p->mem, res, buf + i0, i - i0); } #if MARC_DEBUG fprintf (outf, "\n"); diff --git a/recctrl/recgrs.c b/recctrl/recgrs.c index 1531b04..d4cf58c 100644 --- a/recctrl/recgrs.c +++ b/recctrl/recgrs.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: recgrs.c,v $ - * Revision 1.8 1997-09-09 13:38:14 adam + * Revision 1.9 1997-09-17 12:19:21 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.8 1997/09/09 13:38:14 adam * Partial port to WIN95/NT. * * Revision 1.7 1997/09/05 15:30:10 adam @@ -322,7 +326,7 @@ static int dumpkeys(data1_node *n, struct recExtractCtrl *p, int level) if (n->which == DATA1N_data) { - data1_node *par = get_parent_tag(n); + data1_node *par = get_parent_tag(p->dh, n); data1_termlist *tlist = 0; if (p->flagShowRecords) @@ -346,7 +350,7 @@ static int dumpkeys(data1_node *n, struct recExtractCtrl *p, int level) */ while (!par->u.tag.element) - if (!par->parent || !(par = get_parent_tag(par->parent))) + if (!par->parent || !(par = get_parent_tag(p->dh, par->parent))) break; if (!par) tlist = 0; @@ -404,16 +408,17 @@ static int grs_extract(struct recExtractCtrl *p) gri.fh = p->fh; gri.offset = p->offset; gri.mem = mem; + gri.dh = p->dh; n = read_grs_type (&gri, p->subType); if (!n) return -1; if (dumpkeys(n, p, 0) < 0) { - data1_free_tree(n); + data1_free_tree(p->dh, n); return -2; } - data1_free_tree(n); + data1_free_tree(p->dh, n); nmem_destroy(mem); return 0; } @@ -421,7 +426,7 @@ static int grs_extract(struct recExtractCtrl *p) /* * Return: -1: Nothing done. 0: Ok. >0: Bib-1 diagnostic. */ -static int process_comp(data1_node *n, Z_RecordComposition *c) +static int process_comp(data1_handle dh, data1_node *n, Z_RecordComposition *c) { data1_esetname *eset; Z_Espec1 *espec = 0; @@ -432,7 +437,7 @@ static int process_comp(data1_node *n, Z_RecordComposition *c) case Z_RecordComp_simple: if (c->u.simple->which != Z_ElementSetNames_generic) return 26; /* only generic form supported. Fix this later */ - if (!(eset = data1_getesetbyname(n->u.root.absyn, + if (!(eset = data1_getesetbyname(dh, n->u.root.absyn, c->u.simple->u.generic))) { logf(LOG_LOG, "Unknown esetname '%s'", c->u.simple->u.generic); @@ -450,8 +455,10 @@ static int process_comp(data1_node *n, Z_RecordComposition *c) switch (p->which) { case Z_ElementSpec_elementSetName: - if (!(eset = data1_getesetbyname(n->u.root.absyn, - p->u.elementSetName))) + if (!(eset = + data1_getesetbyname(dh, + n->u.root.absyn, + p->u.elementSetName))) { logf(LOG_LOG, "Unknown esetname '%s'", p->u.elementSetName); @@ -479,7 +486,7 @@ static int process_comp(data1_node *n, Z_RecordComposition *c) return 26; /* fix */ } if (espec) - return data1_doespec1(n, espec); + return data1_doespec1(dh, n, espec); else return -1; } @@ -500,23 +507,26 @@ static int grs_retrieve(struct recRetrieveCtrl *p) gri.fh = p->fh; gri.offset = 0; gri.mem = mem; + gri.dh = p->dh; node = read_grs_type (&gri, p->subType); -/* node = data1_read_record(p->readf, p->fh, mem); */ if (!node) { p->diagnostic = 2; return 0; } - if (p->score >= 0 && (new = data1_insert_taggeddata(node, node, "rank", - mem))) + if (p->score >= 0 && (new = + data1_insert_taggeddata(p->dh, node, + node, "rank", + mem))) { new->u.data.what = DATA1I_num; new->u.data.data = new->u.data.lbuf; sprintf(new->u.data.data, "%d", p->score); new->u.data.len = strlen(new->u.data.data); } - if ((new = data1_insert_taggeddata(node, node, "localControlNumber", mem))) + if ((new = data1_insert_taggeddata(p->dh, node, node, + "localControlNumber", mem))) { new->u.data.what = DATA1I_text; new->u.data.data = new->u.data.lbuf; @@ -536,6 +546,7 @@ static int grs_retrieve(struct recRetrieveCtrl *p) if ((oid = oid_getoidbyent(&oe))) { char tmp[128]; + data1_handle dh = p->dh; char *p = tmp; int *ii; @@ -548,8 +559,8 @@ static int grs_retrieve(struct recRetrieveCtrl *p) } *(p++) = '\0'; - if ((new = data1_insert_taggeddata(node, node, "schemaIdentifier", - mem))) + if ((new = data1_insert_taggeddata(dh, node, node, + "schemaIdentifier", mem))) { new->u.data.what = DATA1I_oid; new->u.data.data = nmem_malloc(mem, p - tmp); @@ -570,7 +581,7 @@ static int grs_retrieve(struct recRetrieveCtrl *p) if (map->target_absyn_ref == p->input_format) { onode = node; - if (!(node = data1_map_record(onode, map, mem))) + if (!(node = data1_map_record(p->dh, onode, map, mem))) { p->diagnostic = 14; return 0; @@ -579,12 +590,12 @@ static int grs_retrieve(struct recRetrieveCtrl *p) break; } - if (p->comp && (res = process_comp(node, p->comp)) > 0) + if (p->comp && (res = process_comp(p->dh, node, p->comp)) > 0) { p->diagnostic = res; if (onode) - data1_free_tree(onode); - data1_free_tree(node); + data1_free_tree(p->dh, onode); + data1_free_tree(p->dh, node); nmem_destroy(mem); return 0; } @@ -599,25 +610,28 @@ static int grs_retrieve(struct recRetrieveCtrl *p) case VAL_GRS1: dummy = 0; - if (!(p->rec_buf = data1_nodetogr(node, selected, p->odr, &dummy))) + if (!(p->rec_buf = data1_nodetogr(p->dh, node, selected, + p->odr, &dummy))) p->diagnostic = 2; /* this should be better specified */ else p->rec_len = -1; break; case VAL_EXPLAIN: - if (!(p->rec_buf = data1_nodetoexplain(node, selected, p->odr))) + if (!(p->rec_buf = data1_nodetoexplain(p->dh, node, selected, + p->odr))) p->diagnostic = 2; /* this should be better specified */ else p->rec_len = -1; break; case VAL_SUMMARY: - if (!(p->rec_buf = data1_nodetosummary(node, selected, p->odr))) + if (!(p->rec_buf = data1_nodetosummary(p->dh, node, selected, + p->odr))) p->diagnostic = 2; else p->rec_len = -1; break; case VAL_SUTRS: - if (!(p->rec_buf = data1_nodetobuf(node, selected, + if (!(p->rec_buf = data1_nodetobuf(p->dh, node, selected, (int*)&p->rec_len))) { p->diagnostic = 2; @@ -625,8 +639,8 @@ static int grs_retrieve(struct recRetrieveCtrl *p) } break; case VAL_SOIF: - if (!(p->rec_buf = data1_nodetosoif(node, selected, - (int*)&p->rec_len))) + if (!(p->rec_buf = data1_nodetosoif(p->dh, node, selected, + (int*)&p->rec_len))) { p->diagnostic = 2; break; @@ -642,17 +656,18 @@ static int grs_retrieve(struct recRetrieveCtrl *p) p->diagnostic = 227; break; } - if (!(p->rec_buf = data1_nodetomarc(marctab, node, selected, - (int*)&p->rec_len))) + if (!(p->rec_buf = data1_nodetomarc(p->dh, marctab, node, + selected, + (int*)&p->rec_len))) { p->diagnostic = 2; break; } } if (node) - data1_free_tree(node); + data1_free_tree(p->dh, node); if (onode) - data1_free_tree(onode); + data1_free_tree(p->dh, onode); nmem_destroy(mem); return 0; } diff --git a/recctrl/regxread.c b/recctrl/regxread.c index e65ce84..5effd18 100644 --- a/recctrl/regxread.c +++ b/recctrl/regxread.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: regxread.c,v $ - * Revision 1.7 1997-07-15 16:33:07 adam + * Revision 1.8 1997-09-17 12:19:22 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.7 1997/07/15 16:33:07 adam * Check for zero length in execData. * * Revision 1.6 1997/02/24 10:41:51 adam @@ -165,6 +169,7 @@ struct lexSpec { struct lexTrans trans; int lineNo; NMEM m; + data1_handle dh; void *f_win_fh; void (*f_win_ef)(void *, off_t); @@ -504,7 +509,8 @@ int readFileSpec (struct lexSpec *spec) lineBuf = xmalloc (1+lineSize); logf (LOG_LOG, "reading regx filter %s.flt", spec->name); sprintf (lineBuf, "%s.flt", spec->name); - if (!(spec_inf = yaz_path_fopen (data1_get_tabpath(), lineBuf, "r"))) + if (!(spec_inf = yaz_path_fopen (data1_get_tabpath(spec->dh), + lineBuf, "r"))) { logf (LOG_ERRNO|LOG_WARN, "cannot read spec file %s", spec->name); xfree (lineBuf); @@ -618,7 +624,7 @@ static void execData (struct lexSpec *spec, } else { - res = data1_mk_node (spec->m); + res = data1_mk_node (spec->dh, spec->m); res->parent = parent; res->which = DATA1N_data; res->u.data.what = DATA1I_text; @@ -658,7 +664,7 @@ static void tagBegin (struct lexSpec *spec, { struct data1_node *parent = d1_stack[*d1_level -1]; data1_element *elem = NULL; - data1_node *partag = get_parent_tag(parent); + data1_node *partag = get_parent_tag(spec->dh, parent); data1_node *res; data1_element *e = NULL; int localtag = 0; @@ -669,7 +675,7 @@ static void tagBegin (struct lexSpec *spec, return ; } - res = data1_mk_node (spec->m); + res = data1_mk_node (spec->dh, spec->m); res->parent = parent; res->which = DATA1N_tag; res->u.tag.tag = res->lbuf; @@ -690,8 +696,8 @@ static void tagBegin (struct lexSpec *spec, if (!(e = partag->u.tag.element)) localtag = 1; - elem = data1_getelementbytagname (d1_stack[0]->u.root.absyn, e, - res->u.tag.tag); + elem = data1_getelementbytagname (spec->dh, d1_stack[0]->u.root.absyn, + e, res->u.tag.tag); res->u.tag.element = elem; res->u.tag.node_selected = 0; @@ -914,13 +920,13 @@ static int execCode (struct lexSpec *spec, #if REGX_DEBUG logf (LOG_DEBUG, "begin record %s", absynName); #endif - if (!(absyn = data1_get_absyn (absynName))) + if (!(absyn = data1_get_absyn (spec->dh, absynName))) logf (LOG_WARN, "Unknown tagset: %s", absynName); else { data1_node *res; - res = data1_mk_node (spec->m); + res = data1_mk_node (spec->dh, spec->m); res->which = DATA1N_root; res->u.root.type = absynName; res->u.root.absyn = absyn; @@ -1322,6 +1328,7 @@ data1_node *grs_read_regx (struct grs_read_info *p) curLexSpec->f_win_size = 500000; } curLexSpec->m = p->mem; + curLexSpec->dh = p->dh; n = lexRoot (curLexSpec, p->offset); return n; } diff --git a/recctrl/sgmlread.c b/recctrl/sgmlread.c index f75a1c5..0e7513f 100644 --- a/recctrl/sgmlread.c +++ b/recctrl/sgmlread.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: sgmlread.c,v $ - * Revision 1.3 1997-09-04 13:54:41 adam + * Revision 1.4 1997-09-17 12:19:22 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.3 1997/09/04 13:54:41 adam * Added MARC filter - type grs.marc. where syntax refers * to abstract syntax. New method tellf in retrieve/extract method. * @@ -21,5 +25,5 @@ data1_node *grs_read_sgml (struct grs_read_info *p) { - return data1_read_record (p->readf, p->fh, p->mem); + return data1_read_record (p->dh, p->readf, p->fh, p->mem); } diff --git a/rset/rsrel.c b/rset/rsrel.c index a2e87a9..cfde324 100644 --- a/rset/rsrel.c +++ b/rset/rsrel.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rsrel.c,v $ - * Revision 1.15 1997-09-09 13:38:16 adam + * Revision 1.16 1997-09-17 12:19:23 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.15 1997/09/09 13:38:16 adam * Partial port to WIN95/NT. * * Revision 1.14 1996/11/08 11:15:58 adam @@ -205,6 +209,20 @@ static void relevance (struct rset_rel_info *info, rset_relevance_parms *parms) } logf (LOG_DEBUG, "max tf %d = %d", i, max_tf[i]); } +#if 0 + while (1) + { + int min = -1; + int pos = 0; + for (i = 0; ino_isam_positions; i++) + if (isam_r[i] && + (min < 0 || + (r = (*parms->cmp)(isam_buf[i], isam_buf[min])) < 1)) + min = i; + if (min < 0) + break; + pos = (*parms->get_pos)(isam_buf[min]); +#else while (1) { int min = -1, i, r; @@ -262,6 +280,7 @@ static void relevance (struct rset_rel_info *info, rset_relevance_parms *parms) /* if value is in the top score, then save it - don't emit yet */ add_rec (info, score/parms->no_terms, isam_tmp_buf); } +#endif for (i = 0; ino_rec; i++) info->sysno_idx[i] = i; qsort_info = info; diff --git a/rset/rstemp.c b/rset/rstemp.c index aa7b9b1..f5df094 100644 --- a/rset/rstemp.c +++ b/rset/rstemp.c @@ -1,10 +1,14 @@ /* - * Copyright (C) 1994-1995, Index Data I/S + * Copyright (C) 1994-1997, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: rstemp.c,v $ - * Revision 1.20 1997-09-09 13:38:17 adam + * Revision 1.21 1997-09-17 12:19:23 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.20 1997/09/09 13:38:17 adam * Partial port to WIN95/NT. * * Revision 1.19 1997/09/04 13:58:57 adam @@ -99,9 +103,6 @@ static int r_read (RSFD rfd, void *buf); static int r_write (RSFD rfd, const void *buf); static int r_score (RSFD rfd, int *score); -static int temppath_init = 0; -static char *temppath_root = NULL; - static const rset_control control = { "temp", @@ -129,6 +130,7 @@ struct rset_temp_info { size_t pos_buf; /* position of first byte in window */ size_t pos_border; /* position of last byte+1 in window */ int dirty; /* window is dirty */ + char *temp_path; }; struct rset_temp_rfd { @@ -151,12 +153,14 @@ static void *r_create(const struct rset_control *sel, void *parms, int *flags) info->pos_end = 0; info->pos_buf = 0; info->dirty = 0; - - if (!temppath_init) + if (!temp_parms->temp_path) + info->temp_path = NULL; + else { - temppath_init = 1; - temppath_root = res_get (common_resource, "setTmpDir"); + info->temp_path = xmalloc (strlen(temp_parms->temp_path)+1); + strcpy (info->temp_path, temp_parms->temp_path); } + return info; } @@ -193,7 +197,7 @@ static void r_flush (RSFD rfd, int mk) if (!info->fname && mk) { - char *s = (char*) tempnam (temppath_root, "zrs"); + char *s = (char*) tempnam (info->temp_path, "zrs"); info->fname = xmalloc (strlen(s)+1); strcpy (info->fname, s); @@ -249,15 +253,17 @@ static void r_delete (RSET ct) if (info->fname) unlink (info->fname); - free (info->buf_mem); + xfree (info->buf_mem); logf (LOG_DEBUG, "r_delete: set size %ld", (long) info->pos_end); if (info->fname) { logf (LOG_DEBUG, "r_delete: unlink %s", info->fname); unlink (info->fname); - free (info->fname); + xfree (info->fname); } - free (info); + if (info->temp_path) + xfree (info->temp_path); + xfree (info); } /* r_reread: diff --git a/util/Makefile b/util/Makefile index f30d2b4..3281cf5 100644 --- a/util/Makefile +++ b/util/Makefile @@ -1,7 +1,7 @@ # Copyright (C) 1994-1996, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.25 1996-10-29 13:48:13 adam Exp $ +# $Id: Makefile,v 1.26 1997-09-17 12:19:23 adam Exp $ SHELL=/bin/sh RANLIB=ranlib @@ -14,7 +14,7 @@ TPROG=opt-test DEFS=$(INCLUDE) CPP=$(CC) -E LIB=../lib/zebrautl.a -PO = res.o common.o charmap.o +PO = res.o charmap.o all: $(LIB) diff --git a/util/dirent.c b/util/dirent.c index 047c930..908a450 100644 --- a/util/dirent.c +++ b/util/dirent.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 1997, Index Data I/S + * All rights reserved. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: dirent.c,v $ + * Revision 1.2 1997-09-17 12:19:24 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * + * + * This utility implements a opendir/readdir/close on Windows. + */ #ifdef WINDOWS #include diff --git a/util/res.c b/util/res.c index 78457d5..deb1785 100644 --- a/util/res.c +++ b/util/res.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: res.c,v $ - * Revision 1.17 1997-09-09 13:38:19 adam + * Revision 1.18 1997-09-17 12:19:24 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.17 1997/09/09 13:38:19 adam * Partial port to WIN95/NT. * * Revision 1.16 1996/10/29 13:47:49 adam @@ -282,8 +286,8 @@ void res_put (Res r, const char *name, const char *value) re->value = xstrdup (value); } -void res_trav (Res r, const char *prefix, - void (*f)(const char *name, const char *value)) +void res_trav (Res r, const char *prefix, void *p, + void (*f)(void *p, const char *name, const char *value)) { struct res_entry *re; int l = 0; @@ -296,7 +300,7 @@ void res_trav (Res r, const char *prefix, for (re = r->first; re; re=re->next) if (re->value) if (l==0 || !memcmp (re->name, prefix, l)) - (*f)(re->name, re->value); + (*f)(p, re->name, re->value); } -- 1.7.10.4