From 3ffa5dbc563e15bccb012f3d3d00a993f87ace82 Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Wed, 1 Nov 1995 16:34:52 +0000 Subject: [PATCH] Making data1 look for tables in data1_tabpath --- include/data1.h | 7 ++++++- include/tpath.h | 28 ++++++++++++++++++++++++++++ retrieval/d1_absyn.c | 8 ++++++-- retrieval/d1_attset.c | 9 +++++++-- retrieval/d1_espec.c | 9 +++++++-- retrieval/d1_map.c | 8 ++++++-- retrieval/d1_marc.c | 8 ++++++-- retrieval/d1_read.c | 10 +++++++++- retrieval/d1_tagset.c | 8 ++++++-- retrieval/d1_varset.c | 8 ++++++-- util/Makefile | 4 ++-- util/tpath.c | 37 +++++++++++++++++++++++++++++++++++++ 12 files changed, 126 insertions(+), 18 deletions(-) create mode 100644 include/tpath.h create mode 100644 util/tpath.c diff --git a/include/data1.h b/include/data1.h index bd0747d..51fff44 100644 --- a/include/data1.h +++ b/include/data1.h @@ -24,7 +24,10 @@ * OF THIS SOFTWARE. * * $Log: data1.h,v $ - * Revision 1.2 1995-11-01 13:54:35 quinn + * Revision 1.3 1995-11-01 16:34:52 quinn + * Making data1 look for tables in data1_tabpath + * + * Revision 1.2 1995/11/01 13:54:35 quinn * Minor adjustments * * Revision 1.1 1995/11/01 13:07:18 quinn @@ -83,6 +86,8 @@ #include #include +extern char *data1_tabpath; /* global path for tables */ + #define DATA1_MAX_SYMBOL 31 typedef struct data1_name diff --git a/include/tpath.h b/include/tpath.h new file mode 100644 index 0000000..94c50c9 --- /dev/null +++ b/include/tpath.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1995, 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, + * provided that: + * + * 1. This copyright and permission notice appear in all copies of the + * software and its documentation. Notices of copyright or attribution + * which appear at the beginning of any file must remain unchanged. + * + * 2. The names of Index Data or the individual authors may not be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR + * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + * + */ + +FILE *yaz_path_fopen(char *path, char *name, char *mode); diff --git a/retrieval/d1_absyn.c b/retrieval/d1_absyn.c index 1322132..142b998 100644 --- a/retrieval/d1_absyn.c +++ b/retrieval/d1_absyn.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_absyn.c,v $ - * Revision 1.2 1995-11-01 13:54:44 quinn + * Revision 1.3 1995-11-01 16:34:55 quinn + * Making data1 look for tables in data1_tabpath + * + * Revision 1.2 1995/11/01 13:54:44 quinn * Minor adjustments * * Revision 1.1 1995/11/01 11:56:06 quinn @@ -22,6 +25,7 @@ #include #include #include +#include #include @@ -109,7 +113,7 @@ data1_absyn *data1_read_absyn(char *file) data1_marctab **marcp; int level = 0; - if (!(f = fopen(file, "r"))) + if (!(f = yaz_path_fopen(data1_tabpath, file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; diff --git a/retrieval/d1_attset.c b/retrieval/d1_attset.c index 44dec99..2165004 100644 --- a/retrieval/d1_attset.c +++ b/retrieval/d1_attset.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_attset.c,v $ - * Revision 1.1 1995-11-01 11:56:07 quinn + * Revision 1.2 1995-11-01 16:34:55 quinn + * Making data1 look for tables in data1_tabpath + * + * Revision 1.1 1995/11/01 11:56:07 quinn * Added Retrieval (data management) functions en masse. * * @@ -18,6 +21,8 @@ #include #include #include +#include +#include data1_att *data1_getattbyname(data1_attset *s, char *name) { @@ -43,7 +48,7 @@ data1_attset *data1_read_attset(char *file) data1_att **attp; FILE *f; - if (!(f = fopen(file, "r"))) + if (!(f = yaz_path_fopen(data1_tabpath, file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; diff --git a/retrieval/d1_espec.c b/retrieval/d1_espec.c index 181e256..dd27c11 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.1 1995-11-01 11:56:07 quinn + * Revision 1.2 1995-11-01 16:34:56 quinn + * Making data1 look for tables in data1_tabpath + * + * Revision 1.1 1995/11/01 11:56:07 quinn * Added Retrieval (data management) functions en masse. * * @@ -20,6 +23,8 @@ #include #include #include +#include +#include /* * Read an element-set specification from a file. If !o, use xmalloc for @@ -32,7 +37,7 @@ Z_Espec1 *data1_read_espec1(char *file, ODR o) char *argv[50], line[512]; Z_Espec1 *res = odr_malloc(o, sizeof(*res)); - if (!(f = fopen(file, "r"))) + if (!(f = yaz_path_fopen(data1_tabpath, file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; diff --git a/retrieval/d1_map.c b/retrieval/d1_map.c index cec007e..d508330 100644 --- a/retrieval/d1_map.c +++ b/retrieval/d1_map.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_map.c,v $ - * Revision 1.2 1995-11-01 13:54:46 quinn + * Revision 1.3 1995-11-01 16:34:56 quinn + * Making data1 look for tables in data1_tabpath + * + * Revision 1.2 1995/11/01 13:54:46 quinn * Minor adjustments * * Revision 1.1 1995/11/01 11:56:08 quinn @@ -22,6 +25,7 @@ #include #include +#include #include #include "d1_map.h" @@ -33,7 +37,7 @@ data1_maptab *data1_read_maptab(char *file) char *argv[50], line[512]; data1_mapunit **mapp; - if (!(f = fopen(file, "r"))) + if (!(f = yaz_path_fopen(data1_tabpath, file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; diff --git a/retrieval/d1_marc.c b/retrieval/d1_marc.c index 786f2da..67329ed 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.2 1995-11-01 13:54:48 quinn + * Revision 1.3 1995-11-01 16:34:57 quinn + * Making data1 look for tables in data1_tabpath + * + * Revision 1.2 1995/11/01 13:54:48 quinn * Minor adjustments * * Revision 1.1 1995/11/01 11:56:08 quinn @@ -23,6 +26,7 @@ #include #include #include +#include #define ISO2709_RS 035 #define ISO2709_FS 036 @@ -35,7 +39,7 @@ data1_marctab *data1_read_marctab(char *file) char line[512], *argv[50]; int argc; - if (!(f = fopen(file, "r"))) + if (!(f = yaz_path_fopen(data1_tabpath, file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; diff --git a/retrieval/d1_read.c b/retrieval/d1_read.c index 633ed62..01b1a09 100644 --- a/retrieval/d1_read.c +++ b/retrieval/d1_read.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_read.c,v $ - * Revision 1.2 1995-11-01 13:54:48 quinn + * Revision 1.3 1995-11-01 16:34:57 quinn + * Making data1 look for tables in data1_tabpath + * + * Revision 1.2 1995/11/01 13:54:48 quinn * Minor adjustments * * Revision 1.1 1995/11/01 11:56:09 quinn @@ -63,6 +66,11 @@ #include #include +char *data1_tabpath = 0; /* global path for tables */ + +void data1_set_tabpath(char *p) +{ data1_tabpath = p; } + static data1_node *freelist = 0; /* diff --git a/retrieval/d1_tagset.c b/retrieval/d1_tagset.c index a8e4570..b3a8439 100644 --- a/retrieval/d1_tagset.c +++ b/retrieval/d1_tagset.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_tagset.c,v $ - * Revision 1.2 1995-11-01 13:54:49 quinn + * Revision 1.3 1995-11-01 16:34:58 quinn + * Making data1 look for tables in data1_tabpath + * + * Revision 1.2 1995/11/01 13:54:49 quinn * Minor adjustments * * Revision 1.1 1995/11/01 11:56:09 quinn @@ -20,6 +23,7 @@ #include #include +#include #include @@ -102,7 +106,7 @@ data1_tagset *data1_read_tagset(char *file) data1_tag **tagp; FILE *f; - if (!(f = fopen(file, "r"))) + if (!(f = yaz_path_fopen(data1_tabpath, file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; diff --git a/retrieval/d1_varset.c b/retrieval/d1_varset.c index bbea607..f132610 100644 --- a/retrieval/d1_varset.c +++ b/retrieval/d1_varset.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_varset.c,v $ - * Revision 1.2 1995-11-01 13:54:50 quinn + * Revision 1.3 1995-11-01 16:34:58 quinn + * Making data1 look for tables in data1_tabpath + * + * Revision 1.2 1995/11/01 13:54:50 quinn * Minor adjustments * * Revision 1.1 1995/11/01 11:56:09 quinn @@ -20,6 +23,7 @@ #include #include +#include #include data1_vartype *data1_getvartypebyct(data1_varset *set, char *class, char *type) @@ -53,7 +57,7 @@ data1_varset *data1_read_varset(char *file) res->reference = VAL_NONE; res->classes = 0; - if (!(f = fopen(file, "r"))) + if (!(f = yaz_path_fopen(data1_tabpath, file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; diff --git a/util/Makefile b/util/Makefile index 00b5723..c096cf5 100644 --- a/util/Makefile +++ b/util/Makefile @@ -1,7 +1,7 @@ # Copyright (C) 1994, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.15 1995-11-01 13:55:04 quinn Exp $ +# $Id: Makefile,v 1.16 1995-11-01 16:34:59 quinn Exp $ SHELL=/bin/sh INCLUDE=-I../include -I. @@ -12,7 +12,7 @@ DEFS=$(INCLUDE) LIB=$(LIBDIR)/libutil.a LIBS= PO = options.o log.o marcdisp.o yaz-ccl.o pquery.o oid.o wrbuf.o \ - xmalloc.o readconf.o # dmalloc.o + xmalloc.o readconf.o tpath.o # dmalloc.o CPP=$(CC) -E RANLIB=ranlib diff --git a/util/tpath.c b/util/tpath.c new file mode 100644 index 0000000..ec4e981 --- /dev/null +++ b/util/tpath.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 1995, Index Data. + * See the file LICENSE for details. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: tpath.c,v $ + * Revision 1.1 1995-11-01 16:35:00 quinn + * Making data1 look for tables in data1_tabpath + * + * + */ + +#include +#include + +FILE *yaz_path_fopen(char *path, char *name, char *mode) +{ + char spath[512] = ""; + + if (!path) + return fopen(name, mode); + + do + { + FILE *f; + + if (sscanf(path, "%511[^:]", spath) < 1) + return 0; + sprintf(spath + strlen(spath), "/%s", name); + if ((f = fopen(spath, mode))) + return f; + if ((path = strchr(path, ':'))) + path++; + } + while (path); + return 0; +} -- 1.7.10.4