From: Adam Dickmeiss Date: Wed, 17 Sep 1997 12:10:26 +0000 (+0000) Subject: YAZ version 1.4. X-Git-Tag: YAZ.1.8~605 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=6517fa53d35512887780fd07de5667940da18a9e;p=yaz-moved-to-github.git YAZ version 1.4. --- diff --git a/CHANGELOG b/CHANGELOG index 4d6670d..dd45c63 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,7 +2,29 @@ Possible compatibility problems with earlier versions marked with '*'. --- XXXXX -New windows 95/NT port using MSV5.0. +Added NT Services interface for Z39.50 Server. + +Windows 95/NT port using MSV5.0. Project files are included in +the distribution. + +* Defined new 'global' handle for the retrieval (data1) system. The +new handled, data1_handle, describes the state of the data1 system. +This handle is passed as first argument to virtually all +data1 related routines. The functions data1_create and data1_destroy +creates and destroys a data1 handle respectively. + +Added ODR encode stream member to all backend request structures +init, search, scan etc. This stream should be used to allocate all +memory used for the response when thread safe operation is needed. + +Changed the comstack utility, cs_addstr, to be thread safe. The +returned hostname string returned by the function is now part the +COMSTACK instance. + +Added comstack utility, cs_straddr, which replaces the tcpip_strtoaddr +function. The cs_straddr takes a COMSTACK handle as argument, so this +function must be used after cs_create and before bind/connect. +This function is thread safe. Moved test server to 'ztest' directory - generic server code still in 'server' directory. diff --git a/Makefile b/Makefile index ae27375..e8411ce 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # Copyright (C) 1995-1997, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.34 1997-09-05 09:50:55 adam Exp $ +# $Id: Makefile,v 1.35 1997-09-17 12:10:27 adam Exp $ # Uncomment the lines below to enable mOSI communcation. #ODEFS=-DUSE_XTIMOSI @@ -9,7 +9,7 @@ #LIBMOSI=../../xtimosi/src/libmosi.a ../lib/librfc.a #XMOSI=xmosi.o -CDEFS=$(ODEFS) +CDEFS=$(ODEFS) # -DYAZ_UNICODE=0 #CC= SHELL=/bin/sh MAKE=make @@ -29,11 +29,12 @@ YAZDIR=/usr/local/lib/yaz all: for i in $(SUBDIR); do cd $$i; if $(MAKE) $(CONTROL) \ - CFLAGS="$(CFLAGS) $(CDEFS)" LIBMOSI="$(LIBMOSI)" XMOSI="$(XMOSI)";\ + CFLAGS="$(CFLAGS)" CDEFS="$(CDEFS)" LIBMOSI="$(LIBMOSI)" XMOSI="$(XMOSI)";\ then cd ..; else exit 1; fi; done dep depend: - for i in $(SUBDIR); do cd $$i; if $(MAKE) depend; then cd ..; else exit 1; fi; done + for i in $(SUBDIR); do cd $$i; if $(MAKE) CDEFS="$(CDEFS)" depend;\ + then cd ..; else exit 1; fi; done clean: for i in $(SUBDIR); do (cd $$i; $(MAKE) clean); done diff --git a/README b/README index 36934ac..01aab1e 100644 --- a/README +++ b/README @@ -3,14 +3,17 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss -Compilation and installation +Compilation and installation for YAZ The primary output of the source here is the lib/libyaz.a library, which contains support functions for implementing the server or client role of Z39.50/SR. +Windows programmers: refer to the file MSVC.txt which describes +how to compile the software using Microsoft Visual C++. + Two test-programs of interest are generated when you type 'make' at -the top level. server/ztest and client/client. Ztest is a dummy database +the top level: ztest/ztest and client/client. Ztest is a dummy database server which returns canned responses to all queries. It's good for verifying that the protocol works ok, and ztest.c shows a minimalistic implementation of the 'backend' interface. diff --git a/TODO b/TODO new file mode 100644 index 0000000..6812d2c --- /dev/null +++ b/TODO @@ -0,0 +1,8 @@ +YAZ TODO $Id: TODO,v 1.1 1997-09-17 12:10:27 adam Exp $ + +NMEM has to be thread safe. + +Unicode support. + +Complete EXPLAIN support in retrieval module. + diff --git a/asn/Makefile b/asn/Makefile index 83bae77..e28ec38 100644 --- a/asn/Makefile +++ b/asn/Makefile @@ -1,13 +1,13 @@ # Copyright (C) 1994, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.24 1996-10-09 15:54:54 quinn Exp $ +# $Id: Makefile,v 1.25 1997-09-17 12:10:28 adam Exp $ SHELL=/bin/sh INCLUDE=-I../include -I. LIBDIR=../lib LIBINCLUDE=-L$(LIBDIR) -DEFS=$(INCLUDE) +DEFS=$(INCLUDE) $(CDEFS) LIB=$(LIBDIR)/libasn.a LIBS=-lodr -lasn PO = proto.o diagbib1.o zget.o prt-rsc.o prt-acc.o prt-exp.o prt-ext.o \ @@ -41,7 +41,7 @@ depend1: mv -f Makefile.tmp Makefile depend2: - $(CPP) $(INCLUDE) -M *.c >.depend + $(CPP) $(DEFS) -M *.c >.depend ifeq (.depend,$(wildcard .depend)) include .depend diff --git a/ccl/Makefile b/ccl/Makefile index 0d6c79c..6ffb4f6 100644 --- a/ccl/Makefile +++ b/ccl/Makefile @@ -2,7 +2,10 @@ # Europagate, 1995 # # $Log: Makefile,v $ -# Revision 1.7 1997-04-30 08:52:05 quinn +# Revision 1.8 1997-09-17 12:10:28 adam +# YAZ version 1.4. +# +# Revision 1.7 1997/04/30 08:52:05 quinn # Null # # Revision 1.6 1996/10/11 15:00:24 adam @@ -49,7 +52,7 @@ TPROG1=cclsh LIB=../lib/ccl.a PO=cclfind.o ccltoken.o cclerrms.o cclqual.o cclptree.o cclqfile.o cclstr.o CPP=$(CC) -E -DEFS=$(INCLUDE) +DEFS=$(INCLUDE) $(CDEFS) all: $(LIB) diff --git a/client/Makefile b/client/Makefile index 14a5c6e..5a18bc1 100644 --- a/client/Makefile +++ b/client/Makefile @@ -1,7 +1,7 @@ # Copyright (C) 1994, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.11 1996-10-07 15:29:01 quinn Exp $ +# $Id: Makefile,v 1.12 1997-09-17 12:10:28 adam Exp $ LIBDIR=../lib @@ -10,7 +10,7 @@ LIBDIR=../lib SHELL=/bin/sh INCLUDE=-I../include -I. -I../../xtimosi/src LIBINCLUDE=-L$(LIBDIR) -DEFS=$(INCLUDE) -DCCL2RPN=1 +DEFS=$(INCLUDE) $(CDEFS) -DCCL2RPN=1 LIBS=$(LIBDIR)/libasn.a $(LIBDIR)/libodr.a \ $(LIBDIR)/libcomstack.a ../lib/ccl.a $(LIBMOSI) $(LIBDIR)/libutil.a $(ELIBS) CPP=$(CC) -E @@ -44,7 +44,7 @@ depend1: mv -f Makefile.tmp Makefile depend2: - $(CPP) $(INCLUDE) -M *.c >.depend + $(CPP) $(DEFS) -M *.c >.depend ifeq (.depend,$(wildcard .depend)) include .depend diff --git a/client/client.c b/client/client.c index 3022b3f..18d2cfc 100644 --- a/client/client.c +++ b/client/client.c @@ -1,11 +1,13 @@ - /* - * Copyright (c) 1995-1996, Index Data. + * Copyright (c) 1995-1997, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: client.c,v $ - * Revision 1.49 1997-09-04 13:45:17 adam + * Revision 1.50 1997-09-17 12:10:29 adam + * YAZ version 1.4. + * + * Revision 1.49 1997/09/04 13:45:17 adam * Added UNImarc to list of available syntaxes. * * Revision 1.48 1997/09/01 08:48:44 adam @@ -315,39 +317,34 @@ int cmd_open(char *arg) fprintf(stderr, "Usage: open (osi|tcp) ':' [tsel '/']host[':'port]\n"); return 0; } + if (!strcmp(type, "tcp")) + { + t = tcpip_type; + protocol = PROTO_Z3950; + } + else #ifdef USE_XTIMOSI if (!strcmp(type, "osi")) { - if (!(add = mosi_strtoaddr(addr))) - { - perror(arg); - return 0; - } t = mosi_type; protocol = PROTO_SR; } else #endif - if (!strcmp(type, "tcp")) { - if (!(add = tcpip_strtoaddr(addr))) - { - perror(arg); - return 0; - } - t = tcpip_type; - protocol = PROTO_Z3950; - } - else - { - fprintf(stderr, "Bad type: %s\n", type); - return 0; + fprintf(stderr, "Bad type: %s\n", type); + return 0; } if (!(conn = cs_create(t, 1, protocol))) { perror("cs_create"); return 0; } + if (!(add = cs_straddr(conn, addr))) + { + perror(arg); + return 0; + } printf("Connecting..."); fflush(stdout); if (cs_connect(conn, add) < 0) diff --git a/comstack/Makefile b/comstack/Makefile index 9979cc9..2b8ec70 100644 --- a/comstack/Makefile +++ b/comstack/Makefile @@ -1,7 +1,7 @@ # Copyright (C) 1994, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.5 1996-05-22 08:35:46 adam Exp $ +# $Id: Makefile,v 1.6 1997-09-17 12:10:30 adam Exp $ LIBDIR=../lib @@ -12,7 +12,7 @@ LIBDIR=../lib SHELL=/bin/sh INCLUDE=-I../include -I. -I../../xtimosi/src LIBINCLUDE=-L$(LIBDIR) -L../../xtimosi/src -DEFS=$(INCLUDE) # -DTRACE_TCPIP +DEFS=$(INCLUDE) $(CDEFS) # -DTRACE_TCPIP LIB= $(LIBDIR)/libcomstack.a LIBS=$(LIBDIR)/libasn.a $(LIBDIR)/libodr.a $(LIBDIR)/libcomstack.a \ ../lib/ccl.a $(LIBDIR)/libutil.a $(LIBMOSI) @@ -49,7 +49,7 @@ depend1: mv -f Makefile.tmp Makefile depend2: - $(CPP) $(INCLUDE) -M *.c >.depend + $(CPP) $(DEFS) -M *.c >.depend ifeq (.depend,$(wildcard .depend)) include .depend diff --git a/comstack/tcpip.c b/comstack/tcpip.c index 3cbf108..add3791 100644 --- a/comstack/tcpip.c +++ b/comstack/tcpip.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data + * Copyright (c) 1995-1997, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: tcpip.c,v $ - * Revision 1.16 1997-09-01 08:49:14 adam + * Revision 1.17 1997-09-17 12:10:30 adam + * YAZ version 1.4. + * + * Revision 1.16 1997/09/01 08:49:14 adam * New windows NT/95 port using MSV5.0. Minor changes only. * * Revision 1.15 1997/05/14 06:53:33 adam @@ -140,6 +143,7 @@ int tcpip_bind(COMSTACK h, void *address, int mode); int tcpip_listen(COMSTACK h, char *addrp, int *addrlen); COMSTACK tcpip_accept(COMSTACK h); char *tcpip_addrstr(COMSTACK h); +void *tcpip_straddr(COMSTACK h, const char *str); /* * Determine length/completeness of incoming packages @@ -162,6 +166,8 @@ typedef struct tcpip_state int written; /* -1 if we aren't writing */ int towrite; /* to verify against user input */ int (*complete)(unsigned char *buf, int len); /* length/completeness */ + struct sockaddr_in addr; /* returned by cs_straddr */ + char buf[128]; /* returned by cs_addrstr */ } tcpip_state; #ifdef WINDOWS @@ -243,6 +249,7 @@ COMSTACK tcpip_type(int s, int blocking, int protocol) p->f_listen = tcpip_listen; p->f_accept = tcpip_accept; p->f_addrstr = tcpip_addrstr; + p->f_straddr = tcpip_straddr; p->state = new_socket ? CS_UNBND : CS_IDLE; /* state of line */ p->event = CS_NONE; @@ -263,9 +270,8 @@ COMSTACK tcpip_type(int s, int blocking, int protocol) return p; } -struct sockaddr_in *tcpip_strtoaddr(const char *str) +static int tcpip_strtoaddr_ex(const char *str, struct sockaddr_in *add) { - static struct sockaddr_in add; struct hostent *hp; char *p, buf[512]; short int port = 210; @@ -274,29 +280,48 @@ struct sockaddr_in *tcpip_strtoaddr(const char *str) if (!tcpip_init ()) return 0; TRC(fprintf(stderr, "tcpip_strtoaddress: %s\n", str ? str : "NULL")); - add.sin_family = AF_INET; + add->sin_family = AF_INET; strcpy(buf, str); if ((p = strchr(buf, ':'))) { *p = 0; port = atoi(p + 1); } - add.sin_port = htons(port); + add->sin_port = htons(port); if (!strcmp("@", buf)) - add.sin_addr.s_addr = INADDR_ANY; + add->sin_addr.s_addr = INADDR_ANY; else if ((hp = gethostbyname(buf))) - memcpy(&add.sin_addr.s_addr, *hp->h_addr_list, sizeof(struct in_addr)); + memcpy(&add->sin_addr.s_addr, *hp->h_addr_list, + sizeof(struct in_addr)); else if ((tmpadd = (unsigned) inet_addr(buf)) != 0) - memcpy(&add.sin_addr.s_addr, &tmpadd, sizeof(struct in_addr)); + memcpy(&add->sin_addr.s_addr, &tmpadd, sizeof(struct in_addr)); else return 0; + return 1; +} + +void *tcpip_straddr(COMSTACK h, const char *str) +{ + tcpip_state *sp = h->cprivate; + + if (!tcpip_strtoaddr_ex (str, &sp->addr)) + return 0; + return &sp->addr; +} + +struct sockaddr_in *tcpip_strtoaddr(const char *str) +{ + static struct sockaddr_in add; + + if (!tcpip_strtoaddr_ex (str, &add)) + return 0; return &add; } int tcpip_more(COMSTACK h) { tcpip_state *sp = h->cprivate; - + return sp->altlen && (*sp->complete)((unsigned char *) sp->altbuf, sp->altlen); } @@ -576,11 +601,11 @@ int tcpip_close(COMSTACK h) char *tcpip_addrstr(COMSTACK h) { struct sockaddr_in addr; - static char buf[64]; - char *r; + tcpip_state *sp = h->cprivate; + char *r, *buf = sp->buf; int len; struct hostent *host; - + len = sizeof(addr); if (getpeername(h->iofile, (struct sockaddr*) &addr, &len) < 0) { @@ -588,7 +613,7 @@ char *tcpip_addrstr(COMSTACK h) return 0; } if ((host = gethostbyaddr((char*)&addr.sin_addr, sizeof(addr.sin_addr), - AF_INET))) + AF_INET))) r = (char*) host->h_name; else r = inet_ntoa(addr.sin_addr); diff --git a/comstack/xmosi.c b/comstack/xmosi.c index ea8a71b..132de6c 100644 --- a/comstack/xmosi.c +++ b/comstack/xmosi.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: xmosi.c,v $ - * Revision 1.15 1997-05-14 06:53:34 adam + * Revision 1.16 1997-09-17 12:10:30 adam + * YAZ version 1.4. + * + * Revision 1.15 1997/05/14 06:53:34 adam * C++ support. * * Revision 1.14 1996/07/26 12:34:07 quinn @@ -111,16 +114,8 @@ #include #include -<<<<<<< 1.13 -#include -#include -#include -#include -#include -======= #define YNETINCLUDE #include ->>>>>>> /tmp/T4a00144 #include #include @@ -137,6 +132,7 @@ int mosi_bind(COMSTACK h, void *address, int mode); int mosi_listen(COMSTACK h, char *addrp, int *addrlen); COMSTACK mosi_accept(COMSTACK h); char *mosi_addrstr(COMSTACK h); +void *mosi_straddr(COMSTACK h, const char *str); typedef struct mosi_state { @@ -144,6 +140,7 @@ typedef struct mosi_state struct t_call *call; int hasread; /* how many bytes read of current PDU */ int haswrit; /* how many bytes have we written */ + struct netbuf netbuf; } mosi_state; static char *oidtostr(int *o) @@ -209,6 +206,7 @@ COMSTACK mosi_type(int s, int blocking, int protocol) r->f_listen = mosi_listen; r->f_accept = mosi_accept; r->f_addrstr = mosi_addrstr; + r->r_straddr = mosi_straddr; if (!blocking) flags |= O_NONBLOCK; @@ -240,9 +238,9 @@ int hex2oct(char *hex, char *oct) * addressing specific to our hack of OSI transport. A sockaddr_in wrapped * up in a t_mosiaddr in a netbuf (on a stick). */ -struct netbuf MDF *mosi_strtoaddr(const char *str) + +int MDF *mosi_strtoaddr_ex(const char *str, struct netbuf *ret) { - struct netbuf *ret = xmalloc(sizeof(struct netbuf)); struct sockaddr_in *add = xmalloc(sizeof(struct sockaddr_in)); struct t_mosiaddr *mosiaddr = xmalloc(sizeof(struct t_mosiaddr)); struct hostent *hp; @@ -311,6 +309,31 @@ struct netbuf MDF *mosi_strtoaddr(const char *str) ret->buf = (char*)mosiaddr; ret->len = ret->maxlen = 100 /* sizeof(*mosiaddr) */ ; + return 1; +} + +struct netbuf MDF *mosi_strtoaddr(const char *str) +{ + struct netbuf *ret = xmalloc(sizeof(struct netbuf)); + + if (!mosi_strtoaddr_ex (str, ret)) + { + xfree (ret); + return 0; + } + return ret; +} + +struct netbuf MDF *mosi_straddr(COMSTACK h, const char *str) +{ + mosi_state *st = h->cprivate; + struct netbuf *ret = &st->netbuf; + + if (!mosi_strtoaddr_ex (str, ret)) + { + xfree (ret); + return 0; + } return ret; } diff --git a/include/backend.h b/include/backend.h index d9c5fc6..b4ffc12 100644 --- a/include/backend.h +++ b/include/backend.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1997, Index Data. * * Permission to use, copy, modify, distribute, and sell this software and * its documentation, in whole or in part, for any purpose, is hereby granted, @@ -23,6 +23,10 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * + * $Log: backend.h,v $ + * Revision 1.16 1997-09-17 12:10:31 adam + * YAZ version 1.4. + * */ #ifndef BACKEND_H @@ -40,6 +44,7 @@ typedef struct bend_initrequest { char *configname; Z_IdAuthentication *auth; + ODR stream; /* encoding stream */ } bend_initrequest; typedef struct bend_initresult diff --git a/include/comstack.h b/include/comstack.h index ef2c1dd..354b345 100644 --- a/include/comstack.h +++ b/include/comstack.h @@ -24,7 +24,10 @@ * OF THIS SOFTWARE. * * $Log: comstack.h,v $ - * Revision 1.17 1997-09-01 08:49:47 adam + * Revision 1.18 1997-09-17 12:10:31 adam + * YAZ version 1.4. + * + * Revision 1.17 1997/09/01 08:49:47 adam * New windows NT/95 port using MSV5.0. To export DLL functions the * YAZ_EXPORT modifier was added. Defined in yconfig.h. * @@ -170,6 +173,7 @@ struct comstack COMSTACK (*f_accept)(COMSTACK handle); int (*f_close)(COMSTACK handle); char *(*f_addrstr)(COMSTACK handle); + void *(*f_straddr)(COMSTACK handle, const char *str); }; #define cs_put(handle, buf, size) ((*(handle)->f_put)(handle, buf, size)) @@ -191,6 +195,7 @@ struct comstack #define cs_errno(handle) ((handle)->cerrno) #define cs_getproto(handle) ((handle)->protocol) #define cs_addrstr(handle) ((*(handle)->f_addrstr)(handle)) +#define cs_straddr(handle, str) ((*(handle)->f_straddr)(handle, str)) YAZ_EXPORT const char *cs_strerror(COMSTACK h); YAZ_EXPORT const char *cs_errmsg(int n); diff --git a/include/d1_attset.h b/include/d1_attset.h index 6989b82..93e6ec7 100644 --- a/include/d1_attset.h +++ b/include/d1_attset.h @@ -70,8 +70,11 @@ typedef struct data1_attset struct data1_attset *next; /* sibling */ } data1_attset; -YAZ_EXPORT data1_att *data1_getattbyname(data1_attset *s, char *name); -YAZ_EXPORT data1_attset *data1_read_attset(char *file); +typedef struct data1_handle_info *data1_handle; + +YAZ_EXPORT data1_att *data1_getattbyname(data1_handle dh, data1_attset *s, + char *name); +YAZ_EXPORT data1_attset *data1_read_attset(data1_handle dh, char *file); #ifdef __cplusplus } diff --git a/include/data1.h b/include/data1.h index 8f94a32..9a3a4af 100644 --- a/include/data1.h +++ b/include/data1.h @@ -24,7 +24,10 @@ * OF THIS SOFTWARE. * * $Log: data1.h,v $ - * Revision 1.25 1997-09-05 09:50:55 adam + * Revision 1.26 1997-09-17 12:10:32 adam + * YAZ version 1.4. + * + * Revision 1.25 1997/09/05 09:50:55 adam * Removed global data1_tabpath - uses data1_get_tabpath() instead. * * Revision 1.24 1997/09/01 09:30:39 adam @@ -154,6 +157,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -169,6 +173,8 @@ typedef struct data1_name struct data1_name *next; } data1_name; +typedef struct data1_absyn_cache_info *data1_absyn_cache; + typedef enum data1_datatype { DATA1K_structured = 1, @@ -388,51 +394,74 @@ typedef struct data1_node struct data1_node *root; } data1_node; -YAZ_EXPORT data1_node *get_parent_tag(data1_node *n); -YAZ_EXPORT data1_node *data1_read_node(char **buf, data1_node *parent, +YAZ_EXPORT data1_handle data1_create (void); +YAZ_EXPORT void data1_destroy(data1_handle dh); +YAZ_EXPORT data1_node *get_parent_tag(data1_handle dh, data1_node *n); +YAZ_EXPORT data1_node *data1_read_node(data1_handle dh, char **buf, + data1_node *parent, int *line, data1_absyn *absyn, NMEM m); -YAZ_EXPORT data1_node *data1_read_record(int (*rf)(void *, char *, size_t), +YAZ_EXPORT data1_node *data1_read_record(data1_handle dh, + int (*rf)(void *, char *, size_t), void *fh, NMEM m); -YAZ_EXPORT data1_absyn *data1_read_absyn(char *file); -YAZ_EXPORT data1_tag *data1_gettagbynum(data1_tagset *s, int type, int value); -YAZ_EXPORT data1_tagset *data1_read_tagset(char *file); -YAZ_EXPORT data1_element *data1_getelementbytagname(data1_absyn *abs, +YAZ_EXPORT data1_absyn *data1_read_absyn(data1_handle dh, const char *file); +YAZ_EXPORT data1_tag *data1_gettagbynum(data1_handle dh, data1_tagset *s, + int type, int value); +YAZ_EXPORT data1_tagset *data1_read_tagset(data1_handle dh, char *file); +YAZ_EXPORT data1_element *data1_getelementbytagname(data1_handle dh, + data1_absyn *abs, data1_element *parent, char *tagname); -YAZ_EXPORT Z_GenericRecord *data1_nodetogr(data1_node *n, int select, ODR o, +YAZ_EXPORT Z_GenericRecord *data1_nodetogr(data1_handle dh, data1_node *n, + int select, ODR o, int *len); -YAZ_EXPORT data1_tag *data1_gettagbyname(data1_tagset *s, char *name); -YAZ_EXPORT void data1_free_tree(data1_node *t); -YAZ_EXPORT char *data1_nodetobuf(data1_node *n, int select, int *len); -YAZ_EXPORT data1_node *data1_insert_taggeddata(data1_node *root, +YAZ_EXPORT data1_tag *data1_gettagbyname(data1_handle dh, data1_tagset *s, + char *name); +YAZ_EXPORT void data1_free_tree(data1_handle dh, data1_node *t); +YAZ_EXPORT char *data1_nodetobuf(data1_handle dh, data1_node *n, + int select, int *len); +YAZ_EXPORT data1_node *data1_insert_taggeddata(data1_handle dh, + data1_node *root, data1_node *at, char *tagname, NMEM m); -YAZ_EXPORT data1_datatype data1_maptype(char *t); -YAZ_EXPORT data1_varset *data1_read_varset(char *file); -YAZ_EXPORT data1_vartype *data1_getvartypebyct(data1_varset *set, +YAZ_EXPORT data1_datatype data1_maptype(data1_handle dh, char *t); +YAZ_EXPORT data1_varset *data1_read_varset(data1_handle dh, const char *file); +YAZ_EXPORT data1_vartype *data1_getvartypebyct(data1_handle dh, + data1_varset *set, char *zclass, char *type); -YAZ_EXPORT Z_Espec1 *data1_read_espec1(char *file, ODR o); -YAZ_EXPORT int data1_doespec1(data1_node *n, Z_Espec1 *e); -YAZ_EXPORT data1_esetname *data1_getesetbyname(data1_absyn *a, char *name); -YAZ_EXPORT data1_element *data1_getelementbyname(data1_absyn *absyn, +YAZ_EXPORT Z_Espec1 *data1_read_espec1(data1_handle dh, const char *file, + ODR o); +YAZ_EXPORT int data1_doespec1(data1_handle dh, data1_node *n, Z_Espec1 *e); +YAZ_EXPORT data1_esetname *data1_getesetbyname(data1_handle dh, + data1_absyn *a, char *name); +YAZ_EXPORT data1_element *data1_getelementbyname(data1_handle dh, + data1_absyn *absyn, char *name); -YAZ_EXPORT data1_node *data1_mk_node(NMEM m); -YAZ_EXPORT data1_absyn *data1_get_absyn(char *name); -YAZ_EXPORT data1_maptab *data1_read_maptab(char *file); -YAZ_EXPORT data1_node *data1_map_record(data1_node *n, data1_maptab *map, - NMEM m); -YAZ_EXPORT data1_marctab *data1_read_marctab(char *file); -YAZ_EXPORT char *data1_nodetomarc(data1_marctab *p, data1_node *n, - int selected, int *len); -YAZ_EXPORT char *data1_nodetoidsgml(data1_node *n, int select, int *len); -YAZ_EXPORT Z_ExplainRecord *data1_nodetoexplain(data1_node *n, int select, +YAZ_EXPORT data1_node *data1_mk_node(data1_handle dh, NMEM m); +YAZ_EXPORT data1_absyn *data1_get_absyn(data1_handle dh, char *name); +YAZ_EXPORT data1_maptab *data1_read_maptab(data1_handle dh, const char *file); +YAZ_EXPORT data1_node *data1_map_record(data1_handle dh, data1_node *n, + data1_maptab *map, NMEM m); +YAZ_EXPORT data1_marctab *data1_read_marctab (data1_handle dh, + const char *file); +YAZ_EXPORT char *data1_nodetomarc(data1_handle dh, data1_marctab *p, + data1_node *n, int selected, int *len); +YAZ_EXPORT char *data1_nodetoidsgml(data1_handle dh, data1_node *n, + int select, int *len); +YAZ_EXPORT Z_ExplainRecord *data1_nodetoexplain(data1_handle dh, + data1_node *n, int select, ODR o); -YAZ_EXPORT Z_BriefBib *data1_nodetosummary(data1_node *n, int select, +YAZ_EXPORT Z_BriefBib *data1_nodetosummary(data1_handle dh, + data1_node *n, int select, ODR o); -YAZ_EXPORT char *data1_nodetosoif(data1_node *n, int select, +YAZ_EXPORT char *data1_nodetosoif(data1_handle dh, data1_node *n, int select, int *len); -YAZ_EXPORT void data1_set_tabpath(const char *path); -YAZ_EXPORT const char *data1_get_tabpath(void); +YAZ_EXPORT void data1_set_tabpath(data1_handle dh, const char *path); +YAZ_EXPORT const char *data1_get_tabpath(data1_handle dh); + +YAZ_EXPORT WRBUF data1_get_wrbuf (data1_handle dp); +YAZ_EXPORT char **data1_get_read_buf (data1_handle dp, int **lenp); +YAZ_EXPORT data1_absyn_cache *data1_absyn_cache_get (data1_handle dh); +YAZ_EXPORT NMEM data1_nmem_get (data1_handle dh); #ifdef __cplusplus } diff --git a/include/nmem.h b/include/nmem.h index 601770b..111b1e9 100644 --- a/include/nmem.h +++ b/include/nmem.h @@ -55,6 +55,7 @@ YAZ_EXPORT void *nmem_malloc(NMEM n, int size); YAZ_EXPORT int nmem_total(NMEM n); YAZ_EXPORT NMEM nmem_create(void); YAZ_EXPORT void nmem_destroy(NMEM n); +YAZ_EXPORT char *nmem_strdup (NMEM mem, const char *src); #ifdef __cplusplus } diff --git a/include/prt.h b/include/prt.h index 5e9ee28..20187e8 100644 --- a/include/prt.h +++ b/include/prt.h @@ -58,7 +58,6 @@ YAZ_EXPORT Odr_oid *odr_getoidbystr(ODR o, char *str); YAZ_EXPORT int odr_initmember(ODR o, void *p, int size); YAZ_EXPORT int odr_peektag(ODR o, int *zclass, int *tag, int *cons); YAZ_EXPORT void odr_setlenlen(ODR o, int len); - #ifdef __cplusplus } #endif diff --git a/include/wrbuf.h b/include/wrbuf.h index 7a686ac..70e5d48 100644 --- a/include/wrbuf.h +++ b/include/wrbuf.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1997, Index Data. * * Permission to use, copy, modify, distribute, and sell this software and * its documentation, in whole or in part, for any purpose, is hereby granted, @@ -23,6 +23,10 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * + * $Log: wrbuf.h,v $ + * Revision 1.5 1997-09-17 12:10:32 adam + * YAZ version 1.4. + * */ #ifndef WRBUF_H diff --git a/include/yaz-version.h b/include/yaz-version.h index ee4f7bf..266a516 100644 --- a/include/yaz-version.h +++ b/include/yaz-version.h @@ -2,7 +2,10 @@ * Current software version. * * $Log: yaz-version.h,v $ - * Revision 1.14 1997-04-30 08:52:09 quinn + * Revision 1.15 1997-09-17 12:10:33 adam + * YAZ version 1.4. + * + * Revision 1.14 1997/04/30 08:52:09 quinn * Null * * Revision 1.13 1996/10/11 15:06:55 quinn @@ -68,5 +71,5 @@ */ #ifndef YAZ_VERSION -#define YAZ_VERSION "1.3" +#define YAZ_VERSION "1.4" #endif diff --git a/odr/Makefile b/odr/Makefile index dbd5542..54071a9 100644 --- a/odr/Makefile +++ b/odr/Makefile @@ -1,19 +1,20 @@ # Copyright (C) 1994, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.25 1996-08-12 14:09:54 adam Exp $ +# $Id: Makefile,v 1.26 1997-09-17 12:10:33 adam Exp $ SHELL=/bin/sh INCLUDE=-I../include -I. LIBDIR=../lib LIBINCLUDE=-L$(LIBDIR) -DEFS=$(INCLUDE) # -DODR_DEBUG +DEFS=$(INCLUDE) $(CDEFS) # -DODR_DEBUG LIB=$(LIBDIR)/libodr.a LIBS=-lodr PO = odr_bool.o ber_bool.o ber_len.o ber_tag.o odr_util.o odr_null.o \ ber_null.o odr_int.o ber_int.o odr_tag.o odr_cons.o odr_seq.o\ odr_oct.o ber_oct.o odr_bit.o ber_bit.o odr_oid.o ber_oid.o odr_use.o \ - odr_choice.o odr_any.o ber_any.o odr.o odr_mem.o dumpber.o + odr_choice.o odr_any.o ber_any.o odr.o odr_mem.o dumpber.o \ + odr_unicode.o CPP=$(CC) -E RANLIB=ranlib @@ -46,7 +47,7 @@ depend1: mv -f Makefile.tmp Makefile depend2: - $(CPP) $(INCLUDE) -M *.c >.depend + $(CPP) $(DEFS) -M *.c >.depend ifeq (.depend,$(wildcard .depend)) include .depend diff --git a/odr/ber_tag.c b/odr/ber_tag.c index 9e6d362..9e7291a 100644 --- a/odr/ber_tag.c +++ b/odr/ber_tag.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data + * Copyright (c) 1995-1997, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: ber_tag.c,v $ - * Revision 1.15 1997-09-01 08:51:06 adam + * Revision 1.16 1997-09-17 12:10:33 adam + * YAZ version 1.4. + * + * Revision 1.15 1997/09/01 08:51:06 adam * New windows NT/95 port using MSV5.0. Had to avoid a few static * variables used in function ber_tag. These are now part of the * ODR structure. @@ -66,13 +69,9 @@ * else leave pointer unchanged. Return 0. * * Should perhaps be odr_tag? -*/ + */ int ber_tag(ODR o, void *p, int zclass, int tag, int *constructed, int opt) { -#if 0 - static int lclass = -1, ltag, br, lcons; /* save t&c rather than - decoding twice */ -#endif Odr_ber_tag *odr_ber_tag = &o->odr_ber_tag; int rd; char **pp = p; diff --git a/retrieval/Makefile b/retrieval/Makefile index be43b46..8fb3da3 100644 --- a/retrieval/Makefile +++ b/retrieval/Makefile @@ -1,11 +1,11 @@ -# $Id: Makefile,v 1.8 1996-10-07 15:29:32 quinn Exp $ +# $Id: Makefile,v 1.9 1997-09-17 12:10:34 adam Exp $ SHELL=/bin/sh RANLIB=ranlib INCLUDE=-I../include -I. -DEFS=$(INCLUDE) +DEFS=$(INCLUDE) $(CDEFS) LIB=../lib/libret.a -PO = d1_read.o d1_attset.o d1_tagset.o d1_absyn.o d1_grs.o \ +PO = d1_handle.o d1_read.o d1_attset.o d1_tagset.o d1_absyn.o d1_grs.o \ d1_sutrs.o d1_varset.o d1_espec.o \ d1_doespec.o d1_map.o d1_marc.o d1_write.o d1_expout.o d1_sumout.o \ d1_soif.o @@ -33,11 +33,11 @@ depend: depend2 depend1: mv Makefile Makefile.tmp sed '/^#Depend/q' Makefile - $(CPP) $(INCLUDE) -M *.c >>Makefile + $(CPP) $(DEFS) -M *.c >>Makefile -rm Makefile.tmp depend2: - $(CPP) $(INCLUDE) -M *.c >.depend + $(CPP) $(DEFS) -M *.c >.depend ifeq (.depend,$(wildcard .depend)) include .depend diff --git a/retrieval/d1_absyn.c b/retrieval/d1_absyn.c index 7cf36d5..ab1b3ac 100644 --- a/retrieval/d1_absyn.c +++ b/retrieval/d1_absyn.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1997, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_absyn.c,v $ - * Revision 1.11 1997-09-05 09:50:55 adam + * Revision 1.12 1997-09-17 12:10:34 adam + * YAZ version 1.4. + * + * Revision 1.11 1997/09/05 09:50:55 adam * Removed global data1_tabpath - uses data1_get_tabpath() instead. * * Revision 1.10 1997/05/14 06:54:01 adam @@ -47,7 +50,6 @@ #include #include -#include #include #include #include @@ -55,39 +57,54 @@ #include #define D1_MAX_NESTING 128 -#define DATA1_MAX_SYNTAXES 30 /* max no of syntaxes to handle in one session */ -static struct /* cache of abstract syntaxes */ +struct data1_absyn_cache_info { char *name; data1_absyn *absyn; -} syntaxes[DATA1_MAX_SYNTAXES] = {{0,0}}; + data1_absyn_cache next; +}; -data1_absyn *data1_get_absyn(char *name) +data1_absyn *data1_absyn_search (data1_handle dh, const char *name) { - char fname[512]; - int i; - - for (i = 0; syntaxes[i].name; i++) - if (!strcmp(name, syntaxes[i].name)) - return syntaxes[i].absyn; + data1_absyn_cache p = *data1_absyn_cache_get (dh); - if (i >= DATA1_MAX_SYNTAXES - 1) + while (p) { - logf(LOG_WARN, "Too many abstract syntaxes loaded"); - return 0; + if (!strcmp (name, p->name)) + return p->absyn; + p = p->next; } + return NULL; +} + +data1_absyn *data1_absyn_add (data1_handle dh, const char *name) +{ + char fname[512]; + NMEM mem = data1_nmem_get (dh); + + data1_absyn_cache p = nmem_malloc (mem, sizeof(*p)); + data1_absyn_cache *pp = data1_absyn_cache_get (dh); + sprintf(fname, "%s.abs", name); - if (!(syntaxes[i].absyn = data1_read_absyn(fname))) - return 0; - if (!(syntaxes[i].name = xmalloc(strlen(name)+1))) - abort(); - strcpy(syntaxes[i].name, name); - syntaxes[i+1].name = 0; - return syntaxes[i].absyn; + p->absyn = data1_read_absyn (dh, fname); + p->name = nmem_strdup (mem, name); + p->next = *pp; + *pp = p; + return p->absyn; } -data1_esetname *data1_getesetbyname(data1_absyn *a, char *name) +data1_absyn *data1_get_absyn (data1_handle dh, char *name) +{ + data1_absyn *absyn; + + if (!(absyn = data1_absyn_search (dh, name))) + absyn = data1_absyn_add (dh, name); + return absyn; +} + +data1_esetname *data1_getesetbyname(data1_handle dh, data1_absyn *a, + char *name) { data1_esetname *r; @@ -97,8 +114,9 @@ data1_esetname *data1_getesetbyname(data1_absyn *a, char *name) return 0; } -data1_element *data1_getelementbytagname(data1_absyn *abs, - data1_element *parent, char *tagname) +data1_element *data1_getelementbytagname (data1_handle dh, data1_absyn *abs, + data1_element *parent, + char *tagname) { data1_element *r; @@ -117,7 +135,8 @@ data1_element *data1_getelementbytagname(data1_absyn *abs, return 0; } -data1_element *data1_getelementbyname(data1_absyn *absyn, char *name) +data1_element *data1_getelementbyname (data1_handle dh, data1_absyn *absyn, + char *name) { data1_element *r; @@ -127,7 +146,7 @@ data1_element *data1_getelementbyname(data1_absyn *absyn, char *name) return 0; } -data1_absyn *data1_read_absyn(char *file) +data1_absyn *data1_read_absyn (data1_handle dh, const char *file) { char line[512], *r, cmd[512], args[512]; data1_absyn *res = 0; @@ -139,14 +158,13 @@ data1_absyn *data1_read_absyn(char *file) data1_termlist *all = 0; int level = 0; - if (!(f = yaz_path_fopen(data1_get_tabpath(), file, "r"))) + if (!(f = yaz_path_fopen(data1_get_tabpath (dh), file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; } - if (!(res = xmalloc(sizeof(*res)))) - abort(); + res = nmem_malloc(data1_nmem_get(dh), sizeof(*res)); res->name = 0; res->reference = VAL_NONE; res->tagset = 0; @@ -210,8 +228,8 @@ data1_absyn *data1_read_absyn(char *file) return 0; } level = i; - if (!(new_element = cur[level] = *ppl[level] = xmalloc(sizeof(*new_element)))) - abort; + new_element = cur[level] = *ppl[level] = + nmem_malloc(data1_nmem_get(dh), sizeof(*new_element)); new_element->next = new_element->children = 0; new_element->tag = 0; new_element->termlists = 0; @@ -219,7 +237,7 @@ data1_absyn *data1_read_absyn(char *file) tp = &new_element->termlists; ppl[level] = &new_element->next; ppl[level+1] = &new_element->children; - + /* well-defined tag */ if (sscanf(p, "(%d,%d)", &type, &value) == 2) { @@ -229,7 +247,8 @@ data1_absyn *data1_read_absyn(char *file) fclose(f); return 0; } - if (!(new_element->tag = data1_gettagbynum(res->tagset, type, value))) + if (!(new_element->tag = data1_gettagbynum (dh, res->tagset, + type, value))) { logf(LOG_WARN, "Couldn't find tag %s in tagset in %s", p, file); @@ -240,10 +259,13 @@ data1_absyn *data1_read_absyn(char *file) /* private tag */ else if (*p) { - data1_tag *nt = new_element->tag = xmalloc(sizeof(*new_element->tag)); + data1_tag *nt = + new_element->tag = nmem_malloc(data1_nmem_get (dh), + sizeof(*new_element->tag)); nt->which = DATA1T_string; nt->value.string = xstrdup(p); - nt->names = xmalloc(sizeof(*new_element->tag->names)); + nt->names = nmem_malloc(data1_nmem_get(dh), + sizeof(*new_element->tag->names)); nt->names->name = nt->value.string; nt->names->next = 0; nt->kind = DATA1K_string; @@ -284,12 +306,13 @@ data1_absyn *data1_read_absyn(char *file) } if (*attname == '!') strcpy(attname, name); - *tp = xmalloc(sizeof(**tp)); - if (!((*tp)->att = data1_getattbyname(res->attset, - attname))) + *tp = nmem_malloc(data1_nmem_get(dh), sizeof(**tp)); + (*tp)->next = 0; + if (!((*tp)->att = data1_getattbyname(dh, res->attset, + attname))) { logf(LOG_WARN, "Couldn't find att '%s' in attset", - attname); + attname); fclose(f); return 0; } @@ -300,7 +323,6 @@ data1_absyn *data1_read_absyn(char *file) else if (!data1_matchstr(structure, "p")) (*tp)->structure = DATA1S_phrase; - (*tp)->next = 0; tp = &(*tp)->next; } while ((p = strchr(p, ',')) && *(++p)); @@ -341,12 +363,12 @@ data1_absyn *data1_read_absyn(char *file) fclose(f); return 0; } - *tp = xmalloc(sizeof(**tp)); - if (!((*tp)->att = data1_getattbyname(res->attset, - attname))) + *tp = nmem_malloc(data1_nmem_get(dh), sizeof(**tp)); + if (!((*tp)->att = data1_getattbyname (dh, res->attset, + attname))) { logf(LOG_WARN, "Couldn't find att '%s' in attset", - attname); + attname); fclose(f); return 0; } @@ -356,7 +378,7 @@ data1_absyn *data1_read_absyn(char *file) (*tp)->structure = DATA1S_word; else if (!data1_matchstr(structure, "p")) (*tp)->structure = DATA1S_phrase; - + (*tp)->next = 0; tp = &(*tp)->next; } @@ -372,9 +394,7 @@ data1_absyn *data1_read_absyn(char *file) fclose(f); return 0; } - if (!(res->name = xmalloc(strlen(args)+1))) - abort(); - strcpy(res->name, name); + res->name = nmem_strdup(data1_nmem_get(dh), args); } else if (!strcmp(cmd, "reference")) { @@ -403,7 +423,7 @@ data1_absyn *data1_read_absyn(char *file) fclose(f); return 0; } - if (!(res->attset = data1_read_attset(name))) + if (!(res->attset = data1_read_attset (dh, name))) { logf(LOG_WARN, "Attset failed in %s", file); fclose(f); @@ -420,7 +440,7 @@ data1_absyn *data1_read_absyn(char *file) fclose(f); return 0; } - if (!(res->tagset = data1_read_tagset(name))) + if (!(res->tagset = data1_read_tagset (dh, name))) { logf(LOG_WARN, "Tagset failed in %s", file); fclose(f); @@ -437,7 +457,7 @@ data1_absyn *data1_read_absyn(char *file) fclose(f); return 0; } - if (!(res->varset = data1_read_varset(name))) + if (!(res->varset = data1_read_varset (dh, name))) { logf(LOG_WARN, "Varset failed in %s", file); fclose(f); @@ -454,18 +474,17 @@ data1_absyn *data1_read_absyn(char *file) fclose(f); return 0; } - *esetpp = xmalloc(sizeof(**esetpp)); - (*esetpp)->name = xmalloc(strlen(name)+1); - strcpy((*esetpp)->name, name); + *esetpp = nmem_malloc(data1_nmem_get(dh), sizeof(**esetpp)); + (*esetpp)->name = nmem_strdup(data1_nmem_get(dh), name); + (*esetpp)->next = 0; if (*fname == '@') (*esetpp)->spec = 0; - else if (!((*esetpp)->spec = data1_read_espec1(fname, 0))) + else if (!((*esetpp)->spec = data1_read_espec1 (dh, fname, 0))) { logf(LOG_WARN, "%s: Espec-1 read failed", file); fclose(f); return 0; } - (*esetpp)->next = 0; esetpp = &(*esetpp)->next; } else if (!strcmp(cmd, "maptab")) @@ -478,7 +497,7 @@ data1_absyn *data1_read_absyn(char *file) file); continue; } - if (!(*maptabp = data1_read_maptab(name))) + if (!(*maptabp = data1_read_maptab (dh, name))) { logf(LOG_WARN, "%s: Failed to read maptab."); continue; @@ -495,7 +514,7 @@ data1_absyn *data1_read_absyn(char *file) file); continue; } - if (!(*marcp = data1_read_marctab(name))) + if (!(*marcp = data1_read_marctab (dh, name))) { logf(LOG_WARN, "%s: Failed to read marctab."); continue; diff --git a/retrieval/d1_attset.c b/retrieval/d1_attset.c index b045f7e..b747942 100644 --- a/retrieval/d1_attset.c +++ b/retrieval/d1_attset.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1997, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_attset.c,v $ - * Revision 1.6 1997-09-05 09:50:56 adam + * Revision 1.7 1997-09-17 12:10:34 adam + * YAZ version 1.4. + * + * Revision 1.6 1997/09/05 09:50:56 adam * Removed global data1_tabpath - uses data1_get_tabpath() instead. * * Revision 1.5 1996/05/09 07:27:43 quinn @@ -30,13 +33,12 @@ #include #include -#include #include #include #include #include -data1_att *data1_getattbyname(data1_attset *s, char *name) +data1_att *data1_getattbyname(data1_handle dh, data1_attset *s, char *name) { data1_att *r; @@ -47,27 +49,27 @@ data1_att *data1_getattbyname(data1_attset *s, char *name) if (!data1_matchstr(r->name, name)) return r; /* scan included sets */ - if (s->children && (r = data1_getattbyname(s->children, name))) + if (s->children && (r = data1_getattbyname (dh, s->children, name))) return r; } return 0; } -data1_attset *data1_read_attset(char *file) +data1_attset *data1_read_attset(data1_handle dh, char *file) { char line[512], *r, cmd[512], args[512]; data1_attset *res = 0, **childp; data1_att **attp; FILE *f; + NMEM mem = data1_nmem_get (dh); - if (!(f = yaz_path_fopen(data1_get_tabpath(), file, "r"))) + if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; } - if (!(res = xmalloc(sizeof(*res)))) - abort(); + res = nmem_malloc(mem, sizeof(*res)); res->name = 0; res->reference = VAL_NONE; res->ordinal = -1; @@ -108,7 +110,7 @@ data1_attset *data1_read_attset(char *file) } if (rr < 3) /* no local attributes given */ { - locals = xmalloc(sizeof(*locals)); + locals = nmem_malloc(mem, sizeof(*locals)); locals->local = num; locals->next = 0; } @@ -118,19 +120,16 @@ data1_attset *data1_read_attset(char *file) data1_local_attribute **ap = &locals; do { - *ap = xmalloc(sizeof(**ap)); + *ap = nmem_malloc(mem, sizeof(**ap)); (*ap)->local = atoi(p); (*ap)->next = 0; ap = &(*ap)->next; } while ((p = strchr(p, ',')) && *(++p)); } - if (!(t = *attp = xmalloc(sizeof(*t)))) - abort(); + t = *attp = nmem_malloc(mem, sizeof(*t)); t->parent = res; - if (!(t->name = xmalloc(strlen(name)+1))) - abort(); - strcpy(t->name, name); + t->name = nmem_strdup(mem, name); t->value = num; t->locals = locals; t->next = 0; @@ -146,9 +145,7 @@ data1_attset *data1_read_attset(char *file) fclose(f); return 0; } - if (!(res->name = xmalloc(strlen(args)+1))) - abort(); - strcpy(res->name, name); + res->name = nmem_strdup(mem, args); } else if (!strcmp(cmd, "reference")) { @@ -186,7 +183,7 @@ data1_attset *data1_read_attset(char *file) fclose(f); return 0; } - if (!(*childp = data1_read_attset(name))) + if (!(*childp = data1_read_attset (dh, name))) { logf(LOG_WARN, "Inclusion failed in %s", file); fclose(f); diff --git a/retrieval/d1_doespec.c b/retrieval/d1_doespec.c index 29a6df4..3627072 100644 --- a/retrieval/d1_doespec.c +++ b/retrieval/d1_doespec.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_doespec.c,v $ - * Revision 1.8 1997-05-14 06:54:02 adam + * Revision 1.9 1997-09-17 12:10:35 adam + * YAZ version 1.4. + * + * Revision 1.8 1997/05/14 06:54:02 adam * C++ support. * * Revision 1.7 1997/04/30 08:52:11 quinn @@ -235,7 +238,7 @@ static int match_children(data1_node *n, Z_Espec1 *e, int i, Z_ETagUnit **t, return res; } -int data1_doespec1(data1_node *n, Z_Espec1 *e) +int data1_doespec1 (data1_handle dh, data1_node *n, Z_Espec1 *e) { int i; diff --git a/retrieval/d1_espec.c b/retrieval/d1_espec.c index cb1f532..d164908 100644 --- a/retrieval/d1_espec.c +++ b/retrieval/d1_espec.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_espec.c,v $ - * Revision 1.8 1997-09-05 09:50:56 adam + * Revision 1.9 1997-09-17 12:10:35 adam + * YAZ version 1.4. + * + * Revision 1.8 1997/09/05 09:50:56 adam * Removed global data1_tabpath - uses data1_get_tabpath() instead. * * Revision 1.7 1997/05/14 06:54:02 adam @@ -213,14 +216,14 @@ static Z_ETagUnit *read_tagunit(char *buf, ODR o) * Read an element-set specification from a file. * NOTE: If !o, memory is allocated directly from the heap by odr_malloc(). */ -Z_Espec1 *data1_read_espec1(char *file, ODR o) +Z_Espec1 *data1_read_espec1 (data1_handle dh, const char *file, ODR o) { FILE *f; int argc, size_esn = 0; char *argv[50], line[512]; Z_Espec1 *res = odr_malloc(o, sizeof(*res)); - if (!(f = yaz_path_fopen(data1_get_tabpath(), file, "r"))) + if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; diff --git a/retrieval/d1_expout.c b/retrieval/d1_expout.c index caddf2c..ed6ce3d 100644 --- a/retrieval/d1_expout.c +++ b/retrieval/d1_expout.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_expout.c,v $ - * Revision 1.2 1995-12-14 16:28:30 quinn + * Revision 1.3 1997-09-17 12:10:36 adam + * YAZ version 1.4. + * + * Revision 1.2 1995/12/14 16:28:30 quinn * More explain stuff. * * Revision 1.1 1995/12/14 11:09:51 quinn @@ -181,14 +184,15 @@ static Z_TargetInfo *f_targetInfo(data1_node *n, int select, ODR o) { Z_TargetInfo *res = odr_malloc(o, sizeof(*res)); data1_node *c; - static bool_t fl = 0; + bool_t *fl = odr_malloc(o,sizeof(*fl)); + *fl = 0; res->commonInfo = 0; res->name = 0; res->recentNews = 0; res->icon = 0; - res->namedResultSets = &fl; - res->multipleDbSearch = &fl; + res->namedResultSets = fl; + res->multipleDbSearch = fl; res->maxResultSets = 0; res->maxResultSize = 0; res->maxTerms = 0; @@ -249,16 +253,19 @@ static Z_DatabaseInfo *f_databaseInfo(data1_node *n, int select, ODR o) { Z_DatabaseInfo *res = odr_malloc(o, sizeof(*res)); data1_node *c; - static bool_t fl = 0, tr = 1; + bool_t *fl = odr_malloc(o,sizeof(*fl)); + bool_t *tr = odr_malloc(o,sizeof(*tr)); + *fl = 0; + *tr = 1; res->commonInfo = 0; res->name = 0; res->explainDatabase = 0; res->num_nicknames = 0; res->nicknames = 0; res->icon = 0; - res->userFee = &fl; - res->available = &tr; + res->userFee = fl; + res->available = tr; res->titleString = 0; res->num_keywords = 0; res->keywords = 0; @@ -334,7 +341,8 @@ static Z_DatabaseInfo *f_databaseInfo(data1_node *n, int select, ODR o) return res; } -Z_ExplainRecord *data1_nodetoexplain(data1_node *n, int select, ODR o) +Z_ExplainRecord *data1_nodetoexplain (data1_handle dh, data1_node *n, + int select, ODR o) { Z_ExplainRecord *res = odr_malloc(o, sizeof(*res)); diff --git a/retrieval/d1_grs.c b/retrieval/d1_grs.c index 1a9d313..46b34ae 100644 --- a/retrieval/d1_grs.c +++ b/retrieval/d1_grs.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_grs.c,v $ - * Revision 1.9 1997-05-14 06:54:03 adam + * Revision 1.10 1997-09-17 12:10:36 adam + * YAZ version 1.4. + * + * Revision 1.9 1997/05/14 06:54:03 adam * C++ support. * * Revision 1.8 1996/12/05 13:17:49 quinn @@ -44,8 +47,6 @@ #define D1_VARIANTARRAY 20 /* fixed max length on sup'd variant-list. Lazy me */ -Z_GenericRecord *data1_nodetogr(data1_node *n, int select, ODR o, int *len); - static Z_ElementMetaData *get_ElementMetaData(ODR o) { Z_ElementMetaData *r = odr_malloc(o, sizeof(*r)); @@ -145,8 +146,9 @@ static int traverse_triples(data1_node *n, int level, Z_ElementMetaData *m, return 0; } -static Z_ElementData *nodetoelementdata(data1_node *n, int select, int leaf, - ODR o, int *len) +static Z_ElementData *nodetoelementdata(data1_handle dh, data1_node *n, + int select, int leaf, + ODR o, int *len) { Z_ElementData *res = odr_malloc(o, sizeof(*res)); @@ -197,14 +199,15 @@ static Z_ElementData *nodetoelementdata(data1_node *n, int select, int leaf, else { res->which = Z_ElementData_subtree; - if (!(res->u.subtree = data1_nodetogr(n->parent, select, o, len))) + if (!(res->u.subtree = data1_nodetogr (dh, n->parent, select, o, len))) return 0; } return res; } -static Z_TaggedElement *nodetotaggedelement(data1_node *n, int select, ODR o, - int *len) +static Z_TaggedElement *nodetotaggedelement(data1_handle dh, data1_node *n, + int select, ODR o, + int *len) { Z_TaggedElement *res = odr_malloc(o, sizeof(*res)); data1_tag *tag = 0; @@ -224,8 +227,8 @@ static Z_TaggedElement *nodetotaggedelement(data1_node *n, int select, ODR o, */ else if (n->which == DATA1N_data || n->which == DATA1N_variant) { - if (!(tag = data1_gettagbyname(n->root->u.root.absyn->tagset, - "wellKnown"))) + if (!(tag = data1_gettagbyname (dh, n->root->u.root.absyn->tagset, + "wellKnown"))) { logf(LOG_WARN, "Unable to locate tag for 'wellKnown'"); return 0; @@ -287,13 +290,15 @@ static Z_TaggedElement *nodetotaggedelement(data1_node *n, int select, ODR o, res->content->which = Z_ElementData_noDataRequested; res->content->u.noDataRequested = ODR_NULLVAL; } - else if (!(res->content = nodetoelementdata(data, select, leaf, o, len))) + else if (!(res->content = nodetoelementdata (dh, data, select, leaf, + o, len))) return 0; *len += 10; return res; } -Z_GenericRecord *data1_nodetogr(data1_node *n, int select, ODR o, int *len) +Z_GenericRecord *data1_nodetogr(data1_handle dh, data1_node *n, + int select, ODR o, int *len) { Z_GenericRecord *res = odr_malloc(o, sizeof(*res)); data1_node *c; @@ -305,7 +310,7 @@ Z_GenericRecord *data1_nodetogr(data1_node *n, int select, ODR o, int *len) if (c->which == DATA1N_tag && select && !c->u.tag.node_selected) continue; if (!(res->elements[res->num_elements++] = - nodetotaggedelement(c, select, o, len))) + nodetotaggedelement (dh, c, select, o, len))) return 0; } return res; diff --git a/retrieval/d1_map.c b/retrieval/d1_map.c index f01b837..7a5a323 100644 --- a/retrieval/d1_map.c +++ b/retrieval/d1_map.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1997, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_map.c,v $ - * Revision 1.10 1997-09-05 09:50:56 adam + * Revision 1.11 1997-09-17 12:10:36 adam + * YAZ version 1.4. + * + * Revision 1.10 1997/09/05 09:50:56 adam * Removed global data1_tabpath - uses data1_get_tabpath() instead. * * Revision 1.9 1996/06/10 08:56:02 quinn @@ -44,7 +47,6 @@ #include #include -#include #include #include @@ -52,16 +54,17 @@ #include #include -data1_maptab *data1_read_maptab(char *file) +data1_maptab *data1_read_maptab (data1_handle dh, const char *file) { - data1_maptab *res = xmalloc(sizeof(*res)); + NMEM mem = data1_nmem_get (dh); + data1_maptab *res = nmem_malloc(mem, sizeof(*res)); FILE *f; int argc; char *argv[50], line[512]; data1_mapunit **mapp; int local_numeric = 0; - if (!(f = yaz_path_fopen(data1_get_tabpath(), file, "r"))) + if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; @@ -96,7 +99,7 @@ data1_maptab *data1_read_maptab(char *file) file); continue; } - res->target_absyn_name = xmalloc(strlen(argv[1])+1); + res->target_absyn_name = nmem_malloc(mem, strlen(argv[1])+1); strcpy(res->target_absyn_name, argv[1]); } else if (!yaz_matchstr(argv[0], "localnumeric")) @@ -109,7 +112,7 @@ data1_maptab *data1_read_maptab(char *file) file); continue; } - res->name = xmalloc(strlen(argv[1])+1); + res->name = nmem_malloc(mem, strlen(argv[1])+1); strcpy(res->name, argv[1]); } else if (!strcmp(argv[0], "map")) @@ -123,13 +126,13 @@ data1_maptab *data1_read_maptab(char *file) file); continue; } - *mapp = xmalloc(sizeof(**mapp)); + *mapp = nmem_malloc(mem, sizeof(**mapp)); (*mapp)->next = 0; if (argc > 3 && !data1_matchstr(argv[3], "nodata")) (*mapp)->no_data = 1; else (*mapp)->no_data = 0; - (*mapp)->source_element_name = xmalloc(strlen(argv[1])+1); + (*mapp)->source_element_name = nmem_malloc(mem, strlen(argv[1])+1); strcpy((*mapp)->source_element_name, argv[1]); mtp = &(*mapp)->target_path; if (*path == '/') @@ -150,7 +153,7 @@ data1_maptab *data1_read_maptab(char *file) fclose(f); return 0; } - *mtp = xmalloc(sizeof(**mtp)); + *mtp = nmem_malloc(mem, sizeof(**mtp)); (*mtp)->next = 0; (*mtp)->type = type; if (np > 2 && !data1_matchstr(parm, "new")) @@ -165,7 +168,7 @@ data1_maptab *data1_read_maptab(char *file) else { (*mtp)->which = D1_MAPTAG_string; - (*mtp)->value.string = xmalloc(strlen(valstr)+1); + (*mtp)->value.string = nmem_malloc(mem, strlen(valstr)+1); strcpy((*mtp)->value.string, valstr); } mtp = &(*mtp)->next; @@ -244,8 +247,8 @@ static int tagmatch(data1_node *n, data1_maptag *t) return 1; } -static int map_children(data1_node *n, data1_maptab *map, data1_node *res, - NMEM mem) +static int map_children(data1_handle dh, data1_node *n, data1_maptab *map, + data1_node *res, NMEM mem) { data1_node *c; data1_mapunit *m; @@ -271,7 +274,7 @@ static int map_children(data1_node *n, data1_maptab *map, data1_node *res, { if (!cur || mt->new_field || !tagmatch(cur, mt)) { - cur = data1_mk_node(mem); + cur = data1_mk_node (dh, mem); cur->which = DATA1N_tag; cur->u.tag.element = 0; cur->u.tag.tag = mt->value.string; @@ -301,7 +304,7 @@ static int map_children(data1_node *n, data1_maptab *map, data1_node *res, break; } } - if (map_children(c, map, res, mem) < 0) + if (map_children(dh, c, map, res, mem) < 0) return -1; } return 0; @@ -312,13 +315,14 @@ static int map_children(data1_node *n, data1_maptab *map, data1_node *res, * table. The new copy will refer back to the data of the original record, * which should not be discarded during the lifetime of the copy. */ -data1_node *data1_map_record(data1_node *n, data1_maptab *map, NMEM m) +data1_node *data1_map_record (data1_handle dh, data1_node *n, + data1_maptab *map, NMEM m) { - data1_node *res = data1_mk_node(m); + data1_node *res = data1_mk_node(dh, m); res->which = DATA1N_root; res->u.root.type = map->target_absyn_name; - if (!(res->u.root.absyn = data1_get_absyn(map->target_absyn_name))) + if (!(res->u.root.absyn = data1_get_absyn(dh, map->target_absyn_name))) { logf(LOG_WARN, "%s: Failed to load target absyn '%s'", map->name, map->target_absyn_name); @@ -326,9 +330,9 @@ data1_node *data1_map_record(data1_node *n, data1_maptab *map, NMEM m) res->parent = 0; res->root = res; - if (map_children(n, map, res, m) < 0) + if (map_children(dh, n, map, res, m) < 0) { - data1_free_tree(res); + data1_free_tree(dh, res); return 0; } return res; diff --git a/retrieval/d1_marc.c b/retrieval/d1_marc.c index 6c3d0a1..69a06d6 100644 --- a/retrieval/d1_marc.c +++ b/retrieval/d1_marc.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_marc.c,v $ - * Revision 1.7 1997-09-05 09:50:57 adam + * Revision 1.8 1997-09-17 12:10:37 adam + * YAZ version 1.4. + * + * Revision 1.7 1997/09/05 09:50:57 adam * Removed global data1_tabpath - uses data1_get_tabpath() instead. * * Revision 1.6 1997/09/04 13:51:58 adam @@ -42,14 +45,15 @@ #include #include -data1_marctab *data1_read_marctab(char *file) +data1_marctab *data1_read_marctab (data1_handle dh, const char *file) { FILE *f; - data1_marctab *res = xmalloc(sizeof(*res)); + NMEM mem = data1_nmem_get (dh); + data1_marctab *res = nmem_malloc(mem, sizeof(*res)); char line[512], *argv[50]; int argc; - if (!(f = yaz_path_fopen(data1_get_tabpath(), file, "r"))) + if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; @@ -77,8 +81,7 @@ data1_marctab *data1_read_marctab(char *file) logf(LOG_WARN, "%s: Bad name directive"); continue; } - res->name = xmalloc(strlen(argv[1])+1); - strcpy(res->name, argv[1]); + res->name = nmem_strdup(mem, argv[1]); } else if (!strcmp(argv[0], "reference")) { @@ -162,7 +165,7 @@ static char *get_data(data1_node *n, int *len) static void memint (char *p, int val, int len) { - static char buf[9]; + char buf[10]; if (len == 1) *p = val + '0'; @@ -303,11 +306,12 @@ static int nodetomarc(data1_marctab *p, data1_node *n, int selected, return len; } -char *data1_nodetomarc(data1_marctab *p, data1_node *n, int selected, int *len) +char *data1_nodetomarc(data1_handle dh, data1_marctab *p, data1_node *n, + int selected, int *len) { - static char *buf = 0; - static int size = 0; + int *size; + char **buf = data1_get_read_buf (dh, &size); - *len = nodetomarc(p, n, selected, &buf, &size); - return buf; + *len = nodetomarc(p, n, selected, buf, size); + return *buf; } diff --git a/retrieval/d1_read.c b/retrieval/d1_read.c index d4a14bd..1ed0285 100644 --- a/retrieval/d1_read.c +++ b/retrieval/d1_read.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1997, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_read.c,v $ - * Revision 1.15 1997-09-05 09:50:57 adam + * Revision 1.16 1997-09-17 12:10:37 adam + * YAZ version 1.4. + * + * Revision 1.15 1997/09/05 09:50:57 adam * Removed global data1_tabpath - uses data1_get_tabpath() instead. * * Revision 1.14 1997/05/14 06:54:04 adam @@ -104,33 +107,11 @@ #include #include -static char *data1_tabpath = 0; /* global path for tables */ - -void data1_set_tabpath(const char *p) -{ - if (data1_tabpath) - { - xfree (data1_tabpath); - data1_tabpath = NULL; - } - if (p) - { - data1_tabpath = xmalloc (strlen(p)+1); - strcpy (data1_tabpath, p); - } -} - -const char *data1_get_tabpath (void) -{ - return data1_tabpath; -} - - /* * get the tag which is the immediate parent of this node (this may mean * traversing intermediate things like variants and stuff. */ -data1_node *get_parent_tag(data1_node *n) +data1_node *get_parent_tag (data1_handle dh, data1_node *n) { for (; n && n->which != DATA1N_root; n = n->parent) if (n->which == DATA1N_tag) @@ -138,7 +119,7 @@ data1_node *get_parent_tag(data1_node *n) return 0; } -data1_node *data1_mk_node(NMEM m) +data1_node *data1_mk_node (data1_handle dh, NMEM m) { data1_node *r; @@ -149,14 +130,14 @@ data1_node *data1_mk_node(NMEM m) return r; } -void data1_free_tree(data1_node *t) +void data1_free_tree (data1_handle dh, data1_node *t) { data1_node *p = t->child, *pn; while (p) { pn = p->next; - data1_free_tree(p); + data1_free_tree (dh, p); p = pn; } if (t->destroy) @@ -168,10 +149,11 @@ void data1_free_tree(data1_node *t) * which should be root or tag itself). Returns pointer to the data node, * which can then be modified. */ -data1_node *data1_insert_taggeddata(data1_node *root, data1_node *at, - char *tagname, NMEM m) +data1_node *data1_insert_taggeddata(data1_handle dh, data1_node *root, + data1_node *at, + char *tagname, NMEM m) { - data1_node *tagn = data1_mk_node(m); + data1_node *tagn = data1_mk_node (dh, m); data1_node *datn; tagn->which = DATA1N_tag; @@ -181,10 +163,11 @@ data1_node *data1_insert_taggeddata(data1_node *root, data1_node *at, tagn->u.tag.make_variantlist = 0; tagn->u.tag.no_data_requested = 0; tagn->u.tag.get_bytes = -1; - if (!(tagn->u.tag.element = data1_getelementbytagname(root->u.root.absyn, - 0, tagname))) + if (!(tagn->u.tag.element = data1_getelementbytagname (dh, + root->u.root.absyn, + 0, tagname))) return 0; - tagn->child = datn = data1_mk_node(m); + tagn->child = datn = data1_mk_node (dh, m); tagn->num_children = 1; datn->parent = tagn; datn->root = root; @@ -201,8 +184,9 @@ data1_node *data1_insert_taggeddata(data1_node *root, data1_node *at, * Ugh. Sometimes functions just grow and grow on you. This one reads a * 'node' and its children. */ -data1_node *data1_read_node(char **buf, data1_node *parent, int *line, - data1_absyn *absyn, NMEM m) +data1_node *data1_read_node (data1_handle dh, char **buf, + data1_node *parent, int *line, + data1_absyn *absyn, NMEM m) { data1_node *res; @@ -271,13 +255,13 @@ data1_node *data1_read_node(char **buf, data1_node *parent, int *line, if (!absyn) /* parent node - what are we? */ { - if (!(absyn = data1_get_absyn(tag))) + if (!(absyn = data1_get_absyn (dh, tag))) { logf(LOG_WARN, "Unable to acquire abstract syntax for '%s'", tag); return 0; } - res = data1_mk_node(m); + res = data1_mk_node (dh, m); res->which = DATA1N_root; res->u.root.type = tag; res->u.root.absyn = absyn; @@ -296,7 +280,7 @@ data1_node *data1_read_node(char **buf, data1_node *parent, int *line, logf(LOG_WARN, "Malformed variant triple at '%s'", tag); return 0; } - if (!(tp = data1_getvartypebyct(parent->root->u.root.absyn->varset, + if (!(tp = data1_getvartypebyct(dh, parent->root->u.root.absyn->varset, tclass, type))) return 0; @@ -306,7 +290,7 @@ data1_node *data1_read_node(char **buf, data1_node *parent, int *line, */ if (parent->which != DATA1N_variant) { - res = data1_mk_node(m); + res = data1_mk_node (dh, m); res->which = DATA1N_variant; res->u.variant.type = 0; res->u.variant.value = 0; @@ -329,7 +313,7 @@ data1_node *data1_read_node(char **buf, data1_node *parent, int *line, return 0; } - res = data1_mk_node(m); + res = data1_mk_node (dh, m); res->which = DATA1N_variant; res->root = parent->root; res->u.variant.type = tp; @@ -339,7 +323,7 @@ data1_node *data1_read_node(char **buf, data1_node *parent, int *line, } else /* tag.. acquire our element in the abstract syntax */ { - data1_node *partag = get_parent_tag(parent); + data1_node *partag = get_parent_tag (dh, parent); data1_element *e = 0; int localtag = 0; @@ -362,9 +346,9 @@ data1_node *data1_read_node(char **buf, data1_node *parent, int *line, return 0; } #else - elem = data1_getelementbytagname(absyn, e, tag); + elem = data1_getelementbytagname(dh, absyn, e, tag); #endif - res = data1_mk_node(m); + res = data1_mk_node (dh, m); res->which = DATA1N_tag; res->u.tag.element = elem; res->u.tag.tag = tag; @@ -383,7 +367,7 @@ data1_node *data1_read_node(char **buf, data1_node *parent, int *line, /* * Read child nodes. */ - while ((*pp = data1_read_node(buf, res, line, absyn, m))) + while ((*pp = data1_read_node(dh, buf, res, line, absyn, m))) { res->last_child = *pp; res->num_children++; @@ -415,7 +399,7 @@ data1_node *data1_read_node(char **buf, data1_node *parent, int *line, } while (isspace(data[len-1])) len--; - res = data1_mk_node(m); + res = data1_mk_node(dh, m); res->parent = parent; res->which = DATA1N_data; res->u.data.what = DATA1I_text; @@ -430,28 +414,29 @@ data1_node *data1_read_node(char **buf, data1_node *parent, int *line, /* * Read a record in the native syntax. */ -data1_node *data1_read_record(int (*rf)(void *, char *, size_t), void *fh, +data1_node *data1_read_record(data1_handle dh, + int (*rf)(void *, char *, size_t), void *fh, NMEM m) { - static char *buf = 0; + int *size; + char **buf = data1_get_read_buf (dh, &size); char *bp; - static int size; int rd = 0, res; int line = 0; - - if (!buf && !(buf = xmalloc(size = 4096))) - abort(); - + + if (!*buf) + *buf = xmalloc(*size = 4096); + for (;;) { - if (rd + 4096 > size && !(buf =xrealloc(buf, size *= 2))) + if (rd + 4096 > *size && !(*buf =xrealloc(*buf, *size *= 2))) abort(); - if ((res = (*rf)(fh, buf + rd, 4096)) <= 0) + if ((res = (*rf)(fh, *buf + rd, 4096)) <= 0) { if (!res) { - bp = buf; - return data1_read_node(&bp, 0, &line, 0, m); + bp = *buf; + return data1_read_node(dh, &bp, 0, &line, 0, m); } else return 0; diff --git a/retrieval/d1_soif.c b/retrieval/d1_soif.c index 4565516..e67d671 100644 --- a/retrieval/d1_soif.c +++ b/retrieval/d1_soif.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_soif.c,v $ - * Revision 1.2 1997-04-30 08:52:11 quinn + * Revision 1.3 1997-09-17 12:10:37 adam + * YAZ version 1.4. + * + * Revision 1.2 1997/04/30 08:52:11 quinn * Null * * Revision 1.1 1996/10/08 10:43:20 quinn @@ -65,15 +68,12 @@ static int nodetoelement(data1_node *n, int select, char *prefix, WRBUF b) return 0; } -char *data1_nodetosoif(data1_node *n, int select, int *len) +char *data1_nodetosoif (data1_handle dh, data1_node *n, int select, int *len) { - static WRBUF b = 0; + WRBUF b = data1_get_wrbuf (dh); char buf[128]; - if (!b) - b = wrbuf_alloc(); - else - wrbuf_rewind(b); + wrbuf_rewind(b); if (n->which != DATA1N_root) return 0; diff --git a/retrieval/d1_sumout.c b/retrieval/d1_sumout.c index fbe5e64..7f1eac1 100644 --- a/retrieval/d1_sumout.c +++ b/retrieval/d1_sumout.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_sumout.c,v $ - * Revision 1.1 1996-06-10 08:56:03 quinn + * Revision 1.2 1997-09-17 12:10:38 adam + * YAZ version 1.4. + * + * Revision 1.1 1996/06/10 08:56:03 quinn * Work on Summary. * * @@ -44,7 +47,8 @@ static char *f_string(data1_node *c, ODR o) return r; } -Z_BriefBib *data1_nodetosummary(data1_node *n, int select, ODR o) +Z_BriefBib *data1_nodetosummary (data1_handle dh, data1_node *n, + int select, ODR o) { Z_BriefBib *res = odr_malloc(o, sizeof(*res)); data1_node *c; diff --git a/retrieval/d1_sutrs.c b/retrieval/d1_sutrs.c index 2a56f26..504007f 100644 --- a/retrieval/d1_sutrs.c +++ b/retrieval/d1_sutrs.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1997, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_sutrs.c,v $ - * Revision 1.3 1995-12-15 16:57:11 quinn + * Revision 1.4 1997-09-17 12:10:38 adam + * YAZ version 1.4. + * + * Revision 1.3 1995/12/15 16:57:11 quinn * Added formatted-text. * * Revision 1.2 1995/11/01 13:54:49 quinn @@ -18,8 +21,6 @@ #include -#include - #include #define NTOBUF_INDENT 2 @@ -134,14 +135,11 @@ static int nodetobuf(data1_node *n, int select, WRBUF b, int indent, int col) * need changing. */ -char *data1_nodetobuf(data1_node *n, int select, int *len) +char *data1_nodetobuf (data1_handle dh, data1_node *n, int select, int *len) { - static WRBUF b = 0; + WRBUF b = data1_get_wrbuf (dh); - if (!b) - b = wrbuf_alloc(); - else - wrbuf_rewind(b); + wrbuf_rewind(b); if (nodetobuf(n, select, b, 0, 0)) return 0; wrbuf_putc(b, '\n'); diff --git a/retrieval/d1_tagset.c b/retrieval/d1_tagset.c index 0fbec96..00b09ad 100644 --- a/retrieval/d1_tagset.c +++ b/retrieval/d1_tagset.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1997, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_tagset.c,v $ - * Revision 1.5 1997-09-05 09:50:57 adam + * Revision 1.6 1997-09-17 12:10:38 adam + * YAZ version 1.4. + * + * Revision 1.5 1997/09/05 09:50:57 adam * Removed global data1_tabpath - uses data1_get_tabpath() instead. * * Revision 1.4 1995/11/13 09:27:38 quinn @@ -27,7 +30,6 @@ #include #include -#include #include #include @@ -38,7 +40,7 @@ * functions eventually. */ -data1_datatype data1_maptype(char *t) +data1_datatype data1_maptype (data1_handle dh, char *t) { static struct { @@ -66,7 +68,8 @@ data1_datatype data1_maptype(char *t) return 0; } -data1_tag *data1_gettagbynum(data1_tagset *s, int type, int value) +data1_tag *data1_gettagbynum (data1_handle dh, data1_tagset *s, + int type, int value) { data1_tag *r; @@ -78,13 +81,14 @@ data1_tag *data1_gettagbynum(data1_tagset *s, int type, int value) if (r->which == DATA1T_numeric && r->value.numeric == value) return r; /* scan included sets */ - if (s->children && (r = data1_gettagbynum(s->children, type, value))) + if (s->children && (r = data1_gettagbynum (dh, s->children, + type, value))) return r; } return 0; } -data1_tag *data1_gettagbyname(data1_tagset *s, char *name) +data1_tag *data1_gettagbyname (data1_handle dh, data1_tagset *s, char *name) { data1_tag *r; @@ -100,27 +104,27 @@ data1_tag *data1_gettagbyname(data1_tagset *s, char *name) return r; } /* scan included sets */ - if (s->children && (r = data1_gettagbyname(s->children, name))) + if (s->children && (r = data1_gettagbyname (dh, s->children, name))) return r; } return 0; } -data1_tagset *data1_read_tagset(char *file) +data1_tagset *data1_read_tagset (data1_handle dh, char *file) { + NMEM mem = data1_nmem_get (dh); char line[512], *r, cmd[512], args[512]; data1_tagset *res = 0, **childp; data1_tag **tagp; FILE *f; - if (!(f = yaz_path_fopen(data1_get_tabpath(), file, "r"))) + if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; } - if (!(res = xmalloc(sizeof(*res)))) - abort(); + res = nmem_malloc(mem, sizeof(*res)); res->name = 0; res->type = 0; res->tags = 0; @@ -159,9 +163,7 @@ data1_tagset *data1_read_tagset(char *file) fclose(f); return 0; } - if (!(rr = *tagp = xmalloc(sizeof(*rr)))) - abort(); - + rr = *tagp = nmem_malloc(mem, sizeof(*rr)); rr->tagset = res; rr->next = 0; rr->which = DATA1T_numeric; @@ -170,7 +172,7 @@ data1_tagset *data1_read_tagset(char *file) * how to deal with local numeric tags? */ - if (!(rr->kind = data1_maptype(type))) + if (!(rr->kind = data1_maptype(dh, type))) { logf(LOG_WARN, "Unknown datatype %s in %s", type, file); fclose(f); @@ -184,13 +186,10 @@ data1_tagset *data1_read_tagset(char *file) { char *e; - if (!(*npp = xmalloc(sizeof(**npp)))) - abort(); + *npp = nmem_malloc(mem, sizeof(**npp)); if ((e = strchr(nm, '/'))) *(e++) = '\0'; - if (!((*npp)->name = xmalloc(strlen(nm)+1))) - abort(); - strcpy((*npp)->name, nm); + (*npp)->name = nmem_strdup(mem, nm); (*npp)->next = 0; npp = &(*npp)->next; nm = e; @@ -208,9 +207,7 @@ data1_tagset *data1_read_tagset(char *file) fclose(f); return 0; } - if (!(res->name = xmalloc(strlen(args)+1))) - abort(); - strcpy(res->name, name); + res->name = nmem_strdup(mem, args); } else if (!strcmp(cmd, "reference")) { @@ -248,7 +245,7 @@ data1_tagset *data1_read_tagset(char *file) fclose(f); return 0; } - if (!(*childp = data1_read_tagset(name))) + if (!(*childp = data1_read_tagset (dh, name))) { logf(LOG_WARN, "Inclusion failed in %s", file); fclose(f); diff --git a/retrieval/d1_varset.c b/retrieval/d1_varset.c index e6ec042..ced2c26 100644 --- a/retrieval/d1_varset.c +++ b/retrieval/d1_varset.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1997, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_varset.c,v $ - * Revision 1.5 1997-09-05 09:50:58 adam + * Revision 1.6 1997-09-17 12:10:39 adam + * YAZ version 1.4. + * + * Revision 1.5 1997/09/05 09:50:58 adam * Removed global data1_tabpath - uses data1_get_tabpath() instead. * * Revision 1.4 1997/05/14 06:54:04 adam @@ -32,7 +35,8 @@ #include #include -data1_vartype *data1_getvartypebyct(data1_varset *set, char *zclass, char *type) +data1_vartype *data1_getvartypebyct (data1_handle dh, data1_varset *set, + char *zclass, char *type) { data1_varclass *c; data1_vartype *t; @@ -50,9 +54,10 @@ data1_vartype *data1_getvartypebyct(data1_varset *set, char *zclass, char *type) return 0; } -data1_varset *data1_read_varset(char *file) +data1_varset *data1_read_varset (data1_handle dh, const char *file) { - data1_varset *res = xmalloc(sizeof(*res)); + NMEM mem = data1_nmem_get (dh); + data1_varset *res = nmem_malloc(mem, sizeof(*res)); data1_varclass **classp = &res->classes, *zclass = 0; data1_vartype **typep = 0; FILE *f; @@ -63,7 +68,7 @@ data1_varset *data1_read_varset(char *file) res->reference = VAL_NONE; res->classes = 0; - if (!(f = yaz_path_fopen(data1_get_tabpath(), file, "r"))) + if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; @@ -79,11 +84,10 @@ data1_varset *data1_read_varset(char *file) fclose(f); return 0; } - *classp = r = zclass = xmalloc(sizeof(*r)); + *classp = r = zclass = nmem_malloc(mem, sizeof(*r)); r->set = res; r->zclass = atoi(argv[1]); - r->name = xmalloc(strlen(argv[2])+1); - strcpy(r->name, argv[2]); + r->name = nmem_strdup(mem, argv[2]); r->types = 0; typep = &r->types; r->next = 0; @@ -105,12 +109,11 @@ data1_varset *data1_read_varset(char *file) fclose(f); return 0; } - *typep = r = xmalloc(sizeof(*r)); - r->name = xmalloc(strlen(argv[2])+1); - strcpy(r->name, argv[2]); + *typep = r = nmem_malloc(mem, sizeof(*r)); + r->name = nmem_strdup(mem, argv[2]); r->zclass = zclass; r->type = atoi(argv[1]); - if (!(r->datatype = data1_maptype(argv[3]))) + if (!(r->datatype = data1_maptype (dh, argv[3]))) { logf(LOG_WARN, "%s: Unknown datatype '%s'", file, argv[3]); fclose(f); @@ -127,8 +130,7 @@ data1_varset *data1_read_varset(char *file) fclose(f); return 0; } - res->name = xmalloc(strlen(argv[1])+1); - strcpy(res->name, argv[1]); + res->name = nmem_strdup(mem, argv[1]); } else if (!strcmp(argv[0], "reference")) { diff --git a/retrieval/d1_write.c b/retrieval/d1_write.c index 66e8b26..6a7d2c0 100644 --- a/retrieval/d1_write.c +++ b/retrieval/d1_write.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1997, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_write.c,v $ - * Revision 1.2 1995-12-13 17:14:27 quinn + * Revision 1.3 1997-09-17 12:10:39 adam + * YAZ version 1.4. + * + * Revision 1.2 1995/12/13 17:14:27 quinn * *** empty log message *** * * Revision 1.1 1995/12/13 15:38:43 quinn @@ -120,15 +123,12 @@ static int nodetoidsgml(data1_node *n, int select, WRBUF b, int col) return 0; } -char *data1_nodetoidsgml(data1_node *n, int select, int *len) +char *data1_nodetoidsgml (data1_handle dh, data1_node *n, int select, int *len) { - static WRBUF b = 0; + WRBUF b = data1_get_wrbuf (dh); char line[1024]; - if (!b) - b = wrbuf_alloc(); - else - wrbuf_rewind(b); + wrbuf_rewind(b); sprintf(line, "<%s>\n", n->u.root.type); wrbuf_write(b, line, strlen(line)); diff --git a/server/Makefile b/server/Makefile index c222307..34c4356 100644 --- a/server/Makefile +++ b/server/Makefile @@ -1,7 +1,7 @@ # Copyright (C) 1994-1997, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.32 1997-09-01 08:52:58 adam Exp $ +# $Id: Makefile,v 1.33 1997-09-17 12:10:39 adam Exp $ LIBDIR=../lib @@ -10,7 +10,7 @@ LIBDIR=../lib SHELL=/bin/sh INCLUDE=-I../include -I. -I../../xtimosi/src LIBINCLUDE=-L$(LIBDIR) -DEFS=$(INCLUDE) +DEFS=$(INCLUDE) $(CDEFS) LIB=$(LIBDIR)/libserver.a LIBS=$(LIBDIR)/libserver.a $(LIBDIR)/libasn.a $(LIBDIR)/libodr.a \ $(LIBDIR)/libcomstack.a $(LIBMOSI) $(LIBDIR)/libutil.a $(ELIBS) @@ -42,7 +42,7 @@ depend1: mv -f Makefile.tmp Makefile depend2: - $(CPP) $(INCLUDE) -M *.c >.depend + $(CPP) $(DEFS) -M *.c >.depend ifeq (.depend,$(wildcard .depend)) include .depend diff --git a/server/seshigh.c b/server/seshigh.c index c74de0c..953d08d 100644 --- a/server/seshigh.c +++ b/server/seshigh.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: seshigh.c,v $ - * Revision 1.66 1997-09-05 15:26:44 adam + * Revision 1.67 1997-09-17 12:10:40 adam + * YAZ version 1.4. + * + * Revision 1.66 1997/09/05 15:26:44 adam * Added ODR encode in search and scen bend request structures. * Fixed a few enums that caused trouble with C++. * @@ -670,6 +673,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) if (req->implementationVersion) logf(LOG_LOG, "Version: %s", req->implementationVersion); + binitreq.stream = assoc->encode; binitreq.configname = "default-config"; binitreq.auth = req->idAuthentication; if (!(binitres = bend_init(&binitreq))) diff --git a/server/statserv.c b/server/statserv.c index 03822ef..8e63fb7 100644 --- a/server/statserv.c +++ b/server/statserv.c @@ -7,7 +7,10 @@ * Chas Woodfield, Fretwell Downing Datasystem. * * $Log: statserv.c,v $ - * Revision 1.39 1997-09-09 10:10:19 adam + * Revision 1.40 1997-09-17 12:10:41 adam + * YAZ version 1.4. + * + * Revision 1.39 1997/09/09 10:10:19 adam * Another MSV5.0 port. Changed projects to include proper * library/include paths. * Server starts server in test-mode when no options are given. @@ -614,32 +617,24 @@ static void add_listener(char *where, int what) if (!where || sscanf(where, "%[^:]:%s", mode, addr) != 2) { - fprintf(stderr, "%s: Address format: ('tcp'|'osi')':'
.\n", - me); + logf (LOG_WARN, "%s: Address format: ('tcp'|'osi')':'
", me); + return; } if (!strcmp(mode, "tcp")) - { - if (!(ap = tcpip_strtoaddr(addr))) - { - fprintf(stderr, "Address resolution failed for TCP.\n"); - } type = tcpip_type; - } else if (!strcmp(mode, "osi")) { #ifdef USE_XTIMOSI - if (!(ap = mosi_strtoaddr(addr))) - { - fprintf(stderr, "Address resolution failed for TCP.\n"); - } type = mosi_type; #else - fprintf(stderr, "OSI Transport not allowed by configuration.\n"); + logf (LOG_WARN, "OSI Transport not allowed by configuration."); + return; #endif } else { - fprintf(stderr, "You must specify either 'osi:' or 'tcp:'.\n"); + logf (LOG_WARN, "You must specify either 'osi:' or 'tcp:'"); + return; } logf(LOG_LOG, "Adding %s %s listener on %s", control_block.dynamic ? "dynamic" : "static", @@ -648,6 +643,13 @@ static void add_listener(char *where, int what) { logf(LOG_FATAL|LOG_ERRNO, "Failed to create listener"); } + ap = cs_straddr (l, addr); + if (!ap) + { + fprintf(stderr, "Address resolution failed.\n"); + cs_close (l); + return; + } if (cs_bind(l, ap, CS_SERVER) < 0) { logf(LOG_FATAL|LOG_ERRNO, "Failed to bind to %s", where); diff --git a/tab/bib1.att b/tab/bib1.att index 0d7b489..2883303 100644 --- a/tab/bib1.att +++ b/tab/bib1.att @@ -81,7 +81,7 @@ att 1012 Date/time-last-modified att 1013 Authority/format-id att 1014 Concept-text att 1015 Concept-reference -att 1016 Any +att 1016 Any 4,1005,62 att 1017 Server-choice att 1018 Publisher att 1019 Record-source diff --git a/tab/gils.abs b/tab/gils.abs index 5152772..e0f0811 100644 --- a/tab/gils.abs +++ b/tab/gils.abs @@ -20,7 +20,7 @@ esetname G gils-g.est esetname W gils-b.est # We don't really do bodyOfDisplay yet. esetname F @ -all Any +#all Any elm (1,1) schemaIdentifier - elm (1,10) rank - diff --git a/util/Makefile b/util/Makefile index 0ded9c3..0a1b90d 100644 --- a/util/Makefile +++ b/util/Makefile @@ -1,17 +1,17 @@ # Copyright (C) 1994-1997, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.23 1997-09-04 07:59:29 adam Exp $ +# $Id: Makefile,v 1.24 1997-09-17 12:10:42 adam Exp $ SHELL=/bin/sh INCLUDE=-I../include -I. LIBDIR=../lib LIBINCLUDE=-L$(LIBDIR) -DEFS=$(INCLUDE) +DEFS=$(INCLUDE) $(CDEFS) #DEFS=$(INCLUDE) -DTRACE_XMALLOC=1 LIB=$(LIBDIR)/libutil.a LIBS= -PO = options.o log.o marcdisp.o yaz-ccl.o pquery.o oid.o wrbuf.o \ +PO = options.o log.o marcdisp.o yaz-ccl.o pquery.o oid.o wrbuf.o nmemsdup.o \ xmalloc.o readconf.o tpath.o nmem.o yaz-util.o atoin.o # dmalloc.o CPP=$(CC) -E RANLIB=ranlib @@ -48,7 +48,7 @@ depend1: mv -f Makefile.tmp Makefile depend2: - $(CPP) $(INCLUDE) -M *.c >.depend + $(CPP) $(DEFS) -M *.c >.depend ifeq (.depend,$(wildcard .depend)) include .depend diff --git a/util/nmemsdup.c b/util/nmemsdup.c new file mode 100644 index 0000000..a17f9cf --- /dev/null +++ b/util/nmemsdup.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 1997, Index Data. + * See the file LICENSE for details. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: nmemsdup.c,v $ + * Revision 1.1 1997-09-17 12:10:42 adam + * YAZ version 1.4. + * + */ + +#include +#include + +char *nmem_strdup (NMEM mem, const char *src) +{ + char *dst = nmem_malloc (mem, strlen(src)+1); + strcpy (dst, src); + return dst; +} diff --git a/util/pquery.c b/util/pquery.c index 9aa98e3..80d1031 100644 --- a/util/pquery.c +++ b/util/pquery.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995-1996, Index Data. + * Copyright (c) 1995-1997, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: pquery.c,v $ - * Revision 1.12 1997-09-01 08:54:13 adam + * Revision 1.13 1997-09-17 12:10:42 adam + * YAZ version 1.4. + * + * Revision 1.12 1997/09/01 08:54:13 adam * New windows NT/95 port using MSV5.0. Made prefix query handling * thread safe. The function options ignores empty arguments when met. * @@ -64,6 +67,7 @@ struct lex_info { char *left_sep; char *right_sep; int escape_char; + int term_type; }; static Z_RPNStructure *rpn_structure (struct lex_info *li, ODR o, oid_proto, @@ -81,6 +85,15 @@ static int query_oid_getvalbyname (struct lex_info *li) return oid_getvalbyname (buf); } +static int compare_term (struct lex_info *li, const char *src, int off) +{ + size_t len=strlen(src); + + if (li->lex_len == len && !memcmp (li->lex_buf+off, src, len-off)) + return 1; + return 0; +} + static int query_token (struct lex_info *li) { const char *sep_match; @@ -116,20 +129,22 @@ static int query_token (struct lex_info *li) } if (li->lex_len >= 1 && li->lex_buf[0] == li->escape_char) { - if (li->lex_len == 4 && !memcmp (li->lex_buf+1, "and", 3)) - return 'a'; - if (li->lex_len == 3 && !memcmp (li->lex_buf+1, "or", 2)) + if (compare_term (li, "and", 1)) + return 'a'; + if (compare_term (li, "or", 1)) return 'o'; - if (li->lex_len == 4 && !memcmp (li->lex_buf+1, "not", 3)) + if (compare_term (li, "not", 1)) return 'n'; - if (li->lex_len == 5 && !memcmp (li->lex_buf+1, "attr", 4)) + if (compare_term (li, "attr", 1)) return 'l'; - if (li->lex_len == 4 && !memcmp (li->lex_buf+1, "set", 3)) + if (compare_term (li, "set", 1)) return 's'; - if (li->lex_len == 8 && !memcmp (li->lex_buf+1, "attrset", 7)) + if (compare_term (li, "attrset", 1)) return 'r'; - if (li->lex_len == 5 && !memcmp (li->lex_buf+1, "prox", 4)) + if (compare_term (li, "prox", 1)) return 'p'; + if (compare_term (li, "term", 1)) + return 'y'; } return 't'; } @@ -386,6 +401,26 @@ static Z_RPNStructure *rpn_structure (struct lex_info *li, ODR o, return rpn_structure (li, o, proto, num_attr, max_attr, attr_list, attr_set); + case 'y': + lex (li); + if (!li->query_look) + return NULL; + if (compare_term (li, "general", 0)) + li->term_type = Z_Term_general; + else if (compare_term (li, "numeric", 0)) + li->term_type = Z_Term_numeric; + else if (compare_term (li, "string", 0)) + li->term_type = Z_Term_characterString; + else if (compare_term (li, "oid", 0)) + li->term_type = Z_Term_oid; + else if (compare_term (li, "datetime", 0)) + li->term_type = Z_Term_dateTime; + else if (compare_term (li, "null", 0)) + li->term_type = Z_Term_null; + lex (li); + return + rpn_structure (li, o, proto, num_attr, max_attr, attr_list, + attr_set); case 0: /* operator/operand expected! */ return NULL; } @@ -436,6 +471,7 @@ Z_RPNQuery *p_query_rpn (ODR o, oid_proto proto, li.left_sep = "{\""; li.right_sep = "}\""; li.escape_char = '@'; + li.term_type = Z_Term_general; li.query_buf = qbuf; return p_query_rpn_mk (o, &li, proto, qbuf); } @@ -514,6 +550,7 @@ Z_AttributesPlusTerm *p_query_scan (ODR o, oid_proto proto, li.left_sep = "{\""; li.right_sep = "}\""; li.escape_char = '@'; + li.term_type = Z_Term_general; li.query_buf = qbuf; return p_query_scan_mk (&li, o, proto, attributeSetP, qbuf); diff --git a/yaz.dsp b/yaz.dsp index da411b3..b73d401 100644 --- a/yaz.dsp +++ b/yaz.dsp @@ -62,7 +62,7 @@ TargetName=yaz SOURCE=$(InputPath) PostBuild_Desc=Copy Lib and Dll PostBuild_Cmds=copy $(OutDir)\$(TargetName).lib $(ProjDir)\lib copy\ - $(OutDir)\$(TargetName).dll $(ProjDir)\lib + $(OutDir)\$(TargetName).dll $(ProjDir)\lib # End Special Build Tool !ELSEIF "$(CFG)" == "yaz - Win32 Debug" @@ -79,7 +79,7 @@ PostBuild_Cmds=copy $(OutDir)\$(TargetName).lib $(ProjDir)\lib copy\ # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c -# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D WINDOWS=1 /FR /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D WINDOWS=1 /FR /FD /c # SUBTRACT CPP /YX # ADD BASE MTL /nologo /D "_DEBUG" /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 @@ -99,7 +99,7 @@ TargetName=yaz SOURCE=$(InputPath) PostBuild_Desc=Copy Lib and Dll PostBuild_Cmds=copy $(OutDir)\$(TargetName).lib $(ProjDir)\lib copy\ - $(OutDir)\$(TargetName).dll $(ProjDir)\lib + $(OutDir)\$(TargetName).dll $(ProjDir)\lib # End Special Build Tool !ENDIF @@ -425,6 +425,10 @@ SOURCE=.\retrieval\d1_grs.c # End Source File # Begin Source File +SOURCE=.\retrieval\d1_handle.c +# End Source File +# Begin Source File + SOURCE=.\retrieval\d1_map.c !IF "$(CFG)" == "yaz - Win32 Release" @@ -620,6 +624,10 @@ SOURCE=.\util\nmem.c # End Source File # Begin Source File +SOURCE=.\util\nmemsdup.c +# End Source File +# Begin Source File + SOURCE=.\odr\odr.c !IF "$(CFG)" == "yaz - Win32 Release" diff --git a/ztest/Makefile b/ztest/Makefile index 3ac8627..3b6be6f 100644 --- a/ztest/Makefile +++ b/ztest/Makefile @@ -1,7 +1,7 @@ # Copyright (C) 1995-1997, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.1 1997-09-01 08:55:52 adam Exp $ +# $Id: Makefile,v 1.2 1997-09-17 12:10:43 adam Exp $ LIBDIR=../lib @@ -10,7 +10,7 @@ LIBDIR=../lib SHELL=/bin/sh INCLUDE=-I../include -I. -I../../xtimosi/src LIBINCLUDE=-L$(LIBDIR) -DEFS=$(INCLUDE) +DEFS=$(INCLUDE) $(CDEFS) LIB=$(LIBDIR)/libserver.a LIBS=$(LIBDIR)/libserver.a $(LIBDIR)/libasn.a $(LIBDIR)/libodr.a \ $(LIBDIR)/libcomstack.a $(LIBMOSI) $(LIBDIR)/libutil.a $(ELIBS) @@ -40,7 +40,7 @@ depend1: mv -f Makefile.tmp Makefile depend2: - $(CPP) $(INCLUDE) -M *.c >.depend + $(CPP) $(DEFS) -M *.c >.depend ifeq (.depend,$(wildcard .depend)) include .depend diff --git a/ztest/ztest.c b/ztest/ztest.c index 52ea666..d8b1555 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -7,7 +7,10 @@ * Chas Woodfield, Fretwell Downing Datasystems. * * $Log: ztest.c,v $ - * Revision 1.3 1997-09-09 10:10:20 adam + * Revision 1.4 1997-09-17 12:10:43 adam + * YAZ version 1.4. + * + * Revision 1.3 1997/09/09 10:10:20 adam * Another MSV5.0 port. Changed projects to include proper * library/include paths. * Server starts server in test-mode when no options are given. @@ -37,24 +40,24 @@ Z_GenericRecord *read_grs1(FILE *f, ODR o); bend_initresult *bend_init(bend_initrequest *q) { - static bend_initresult r; + bend_initresult *r = odr_malloc (q->stream, sizeof(*r)); static char *dummy = "Hej fister"; - r.errcode = 0; - r.errstring = 0; - r.handle = dummy; - return &r; + r->errcode = 0; + r->errstring = 0; + r->handle = dummy; + return r; } bend_searchresult *bend_search(void *handle, bend_searchrequest *q, int *fd) { - static bend_searchresult r; + bend_searchresult *r = odr_malloc (q->stream, sizeof(*r)); - r.errcode = 0; - r.errstring = 0; - r.hits = rand() % 22; + r->errcode = 0; + r->errstring = 0; + r->hits = rand() % 22; - return &r; + return r; } static int atoin (const char *buf, int n) @@ -142,47 +145,47 @@ static Z_GenericRecord *dummy_grs_record (int num, ODR o) bend_fetchresult *bend_fetch(void *handle, bend_fetchrequest *q, int *num) { - static bend_fetchresult r; + bend_fetchresult *r = odr_malloc (q->stream, sizeof(*r)); static char *bbb = 0; - r.errstring = 0; - r.last_in_set = 0; - r.basename = "DUMMY"; + r->errstring = 0; + r->last_in_set = 0; + r->basename = "DUMMY"; if (bbb) { xfree(bbb); bbb = 0; } - r.format = q->format; + r->format = q->format; if (q->format == VAL_SUTRS) { char buf[100]; sprintf(buf, "This is dummy SUTRS record number %d\n", q->number); - assert(r.record = bbb = xmalloc(strlen(buf)+1)); + assert(r->record = bbb = xmalloc(strlen(buf)+1)); strcpy(bbb, buf); - r.len = strlen(buf); + r->len = strlen(buf); } else if (q->format == VAL_GRS1) { - r.len = -1; - r.record = (char*) dummy_grs_record(q->number, q->stream); - if (!r.record) + r->len = -1; + r->record = (char*) dummy_grs_record(q->number, q->stream); + if (!r->record) { - r.errcode = 13; - return &r; + r->errcode = 13; + return r; } } - else if (!(r.record = bbb = dummy_database_record(q->number))) + else if (!(r->record = bbb = dummy_database_record(q->number))) { - r.errcode = 13; - r.format = VAL_USMARC; - return &r; + r->errcode = 13; + r->format = VAL_USMARC; + return r; } else - r.len = strlen(r.record); - r.errcode = 0; - return &r; + r->len = strlen(r->record); + r->errcode = 0; + return r; } bend_deleteresult *bend_delete(void *handle, bend_deleterequest *q, int *num) @@ -217,7 +220,7 @@ bend_scanresult *bend_scan(void *handle, bend_scanrequest *q, int *num) */ bend_scanresult *bend_scan(void *handle, bend_scanrequest *q, int *num) { - static bend_scanresult r; + bend_scanresult *r = odr_malloc (q->stream, sizeof(*r)); static FILE *f = 0; static struct scan_entry list[200]; static char entries[200][80]; @@ -225,9 +228,9 @@ bend_scanresult *bend_scan(void *handle, bend_scanrequest *q, int *num) char term[80], *p; int i, pos; - r.errstring = 0; - r.entries = list; - r.status = BEND_SCAN_SUCCESS; + r->errstring = 0; + r->entries = list; + r->status = BEND_SCAN_SUCCESS; if (!f && !(f = fopen("dummy-words", "r"))) { perror("dummy-words"); @@ -235,18 +238,18 @@ bend_scanresult *bend_scan(void *handle, bend_scanrequest *q, int *num) } if (q->term->term->which != Z_Term_general) { - r.errcode = 229; /* unsupported term type */ - return &r; + r->errcode = 229; /* unsupported term type */ + return r; } if (q->term->term->u.general->len >= 80) { - r.errcode = 11; /* term too long */ - return &r; + r->errcode = 11; /* term too long */ + return r; } if (q->num_entries > 200) { - r.errcode = 31; - return &r; + r->errcode = 31; + return r; } memcpy(term, q->term->term->u.general->buf, q->term->term->u.general->len); term[q->term->term->u.general->len] = '\0'; @@ -255,40 +258,40 @@ bend_scanresult *bend_scan(void *handle, bend_scanrequest *q, int *num) *p = toupper(*p); fseek(f, 0, 0); - r.num_entries = 0; + r->num_entries = 0; for (i = 0, pos = 0; fscanf(f, " %79[^:]:%d", entries[pos], &hits[pos]) == 2; i++, pos < 199 ? pos++ : (pos = 0)) { - if (!r.num_entries && strcmp(entries[pos], term) >= 0) /* s-point fnd */ + if (!r->num_entries && strcmp(entries[pos], term) >= 0) /* s-point fnd */ { - if ((r.term_position = q->term_position) > i + 1) + if ((r->term_position = q->term_position) > i + 1) { - r.term_position = i + 1; - r.status = BEND_SCAN_PARTIAL; + r->term_position = i + 1; + r->status = BEND_SCAN_PARTIAL; } - for (; r.num_entries < r.term_position; r.num_entries++) + for (; r->num_entries < r->term_position; r->num_entries++) { int po; - po = pos - r.term_position + r.num_entries + 1; /* find pos */ + po = pos - r->term_position + r->num_entries + 1; /* find pos */ if (po < 0) po += 200; - list[r.num_entries].term = entries[po]; - list[r.num_entries].occurrences = hits[po]; + list[r->num_entries].term = entries[po]; + list[r->num_entries].occurrences = hits[po]; } } - else if (r.num_entries) + else if (r->num_entries) { - list[r.num_entries].term = entries[pos]; - list[r.num_entries].occurrences = hits[pos]; - r.num_entries++; + list[r->num_entries].term = entries[pos]; + list[r->num_entries].occurrences = hits[pos]; + r->num_entries++; } - if (r.num_entries >= q->num_entries) + if (r->num_entries >= q->num_entries) break; } if (feof(f)) - r.status = BEND_SCAN_PARTIAL; - return &r; + r->status = BEND_SCAN_PARTIAL; + return r; } #endif @@ -298,6 +301,17 @@ void bend_close(void *handle) return; } +#ifndef WINDOWS +/* UNIX version */ +int main(int argc, char **argv) +{ + statserv_main(argc, argv); + statserv_closedown(); + exit (0); +} +#else +/* Windows version with Service support */ + typedef struct _Args { char **argv; @@ -324,22 +338,8 @@ int main(int argc, char **argv) ArgDetails.argc = argc; ArgDetails.argv = argv; -#ifdef WIN32 - /* Now setup the service with the service controller */ SetupService(argc, argv, &ArgDetails, SZAPPNAME, SZSERVICENAME, SZSERVICEDISPLAYNAME, SZDEPENDENCIES); - -#else /* WIN32 */ - - /* The service controller does the following for us under windows */ - if (StartAppService(NULL, argc, argv)) - RunAppService(&ArgDetails); - - /* Ensure the service has been stopped */ - StopAppService(NULL); - -#endif /* WIN32 */ - return(0); } @@ -362,3 +362,4 @@ void StopAppService(void *pHandle) /* Stops the app */ statserv_closedown(); } +#endif