From: Adam Dickmeiss Date: Thu, 4 Apr 2002 20:49:46 +0000 (+0000) Subject: New functions yaz_is_abspath, yaz_path_fopen_base X-Git-Tag: YAZ.1.8.7.CCL~31 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=98f0cc2d7eeed27912edb88bf16512bb622b19ee;p=yaz-moved-to-github.git New functions yaz_is_abspath, yaz_path_fopen_base --- diff --git a/include/yaz/data1.h b/include/yaz/data1.h index 25d9400..31490e1 100644 --- a/include/yaz/data1.h +++ b/include/yaz/data1.h @@ -24,7 +24,10 @@ * OF THIS SOFTWARE. * * $Log: data1.h,v $ - * Revision 1.6 2000-12-05 12:21:45 adam + * Revision 1.7 2002-04-04 20:49:46 adam + * New functions yaz_is_abspath, yaz_path_fopen_base + * + * Revision 1.6 2000/12/05 12:21:45 adam * Added termlist source for data1 system. * * Revision 1.5 2000/11/29 14:22:47 adam @@ -571,7 +574,9 @@ YAZ_EXPORT Z_BriefBib *data1_nodetosummary(data1_handle dh, YAZ_EXPORT char *data1_nodetosoif(data1_handle dh, data1_node *n, int select, int *len); YAZ_EXPORT void data1_set_tabpath(data1_handle dh, const char *path); +YAZ_EXPORT void data1_set_tabroot (data1_handle dp, const char *p); YAZ_EXPORT const char *data1_get_tabpath(data1_handle dh); +YAZ_EXPORT const char *data1_get_tabroot(data1_handle dh); YAZ_EXPORT WRBUF data1_get_wrbuf (data1_handle dp); YAZ_EXPORT char **data1_get_read_buf (data1_handle dp, int **lenp); @@ -599,6 +604,9 @@ YAZ_EXPORT char *data1_getNodeValue(data1_node* node, char* pTagPath); YAZ_EXPORT data1_node *data1_LookupNode(data1_node* node, char* pTagPath); YAZ_EXPORT int data1_CountOccurences(data1_node* node, char* pTagPath); +YAZ_EXPORT FILE *data1_path_fopen (data1_handle dh, const char *file, + const char *mode); + YAZ_END_CDECL #endif diff --git a/include/yaz/tpath.h b/include/yaz/tpath.h index da4f785..425687e 100644 --- a/include/yaz/tpath.h +++ b/include/yaz/tpath.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995-2000, Index Data. + * Copyright (c) 1995-2002, 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,17 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Log: tpath.h,v $ - * Revision 1.2 2000-02-28 11:20:06 adam - * Using autoconf. New definitions: YAZ_BEGIN_CDECL/YAZ_END_CDECL. - * - * Revision 1.1 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.4 1997/10/31 12:20:08 adam - * Improved memory debugging for xmalloc/nmem.c. References to NMEM - * instead of ODR in n ESPEC-1 handling in source d1_espec.c. - * Bug fix: missing fclose in data1_read_espec1. + * $Id: tpath.h,v 1.3 2002-04-04 20:49:46 adam Exp $ * */ @@ -44,8 +34,12 @@ YAZ_BEGIN_CDECL -YAZ_EXPORT FILE *yaz_path_fopen(const char *path, - const char *name, const char *mode); +YAZ_EXPORT FILE *yaz_path_fopen_base(const char *path, const char *name, + const char *mode, const char *base); +YAZ_EXPORT FILE *yaz_path_fopen(const char *path, const char *name, + const char *mode); + +YAZ_EXPORT int yaz_is_abspath (const char *p); YAZ_END_CDECL diff --git a/retrieval/d1_absyn.c b/retrieval/d1_absyn.c index 75f69bd..6d9bb23 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.30 2000-12-05 19:07:24 adam + * Revision 1.31 2002-04-04 20:49:46 adam + * New functions yaz_is_abspath, yaz_path_fopen_base + * + * Revision 1.30 2000/12/05 19:07:24 adam * Fixed problem with element level in reading of abstract syntax. * * Revision 1.29 2000/12/05 14:34:49 adam @@ -416,7 +419,7 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file) int argc; char *argv[50], line[512]; - if (!(f = yaz_path_fopen(data1_get_tabpath (dh), file, "r"))) + if (!(f = data1_path_fopen(dh, file, "r"))) { yaz_log(LOG_WARN|LOG_ERRNO, "Couldn't open %s", file); return 0; diff --git a/retrieval/d1_attset.c b/retrieval/d1_attset.c index 2009647..72d271c 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.14 1999-11-30 13:47:12 adam + * Revision 1.15 2002-04-04 20:49:46 adam + * New functions yaz_is_abspath, yaz_path_fopen_base + * + * Revision 1.14 1999/11/30 13:47:12 adam * Improved installation. Moved header files to include/yaz. * * Revision 1.13 1999/10/21 12:06:29 adam @@ -108,7 +111,7 @@ data1_attset *data1_read_attset(data1_handle dh, const char *file) int argc; char *argv[50], line[512]; - if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r"))) + if (!(f = data1_path_fopen(dh, file, "r"))) return NULL; res = data1_empty_attset (dh); diff --git a/retrieval/d1_espec.c b/retrieval/d1_espec.c index 59dd3d7..a530bd2 100644 --- a/retrieval/d1_espec.c +++ b/retrieval/d1_espec.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: d1_espec.c,v 1.20 2001-09-30 20:15:49 adam Exp $ + * $Id: d1_espec.c,v 1.21 2002-04-04 20:49:46 adam Exp $ */ #include @@ -202,7 +202,7 @@ Z_Espec1 *data1_read_espec1 (data1_handle dh, const char *file) char *argv[50], line[512]; Z_Espec1 *res = (Z_Espec1 *)nmem_malloc(nmem, sizeof(*res)); - if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r"))) + if (!(f = data1_path_fopen(dh, file, "r"))) { yaz_log(LOG_WARN|LOG_ERRNO, "%s", file); return 0; diff --git a/retrieval/d1_handle.c b/retrieval/d1_handle.c index 966eaae..d1c7f95 100644 --- a/retrieval/d1_handle.c +++ b/retrieval/d1_handle.c @@ -1,29 +1,8 @@ /* - * Copyright (c) 1995-1999, Index Data. + * Copyright (c) 1995-2002, Index Data. * See the file LICENSE for details. - * Sebastian Hammer, Adam Dickmeiss - * - * $Log: d1_handle.c,v $ - * Revision 1.6 1999-11-30 13:47:12 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.5 1999/08/27 09:40:32 adam - * Renamed logf function to yaz_log. Removed VC++ project files. - * - * Revision 1.4 1998/05/18 13:07:05 adam - * Changed the way attribute sets are handled by the retriaval module. - * Extended Explain conversion / schema. - * Modified server and client to work with ASN.1 compiled protocol handlers. - * - * Revision 1.3 1998/02/11 11:53:35 adam - * Changed code so that it compiles as C++. - * - * Revision 1.2 1997/09/30 11:50:04 adam - * Added handler data1_get_map_buf that is used by data1_nodetomarc. - * - * Revision 1.1 1997/09/17 12:28:24 adam - * Introduced new 'global' data1 handle. * + * $Id: d1_handle.c,v 1.7 2002-04-04 20:49:46 adam Exp $ */ #include @@ -35,6 +14,7 @@ struct data1_handle_info { WRBUF wrbuf; char *tab_path; + char *tab_root; char *read_buf; int read_len; @@ -54,6 +34,7 @@ data1_handle data1_create (void) if (!p) return NULL; p->tab_path = NULL; + p->tab_root = NULL; p->wrbuf = wrbuf_alloc(); p->read_buf = NULL; p->read_len = 0; @@ -87,6 +68,8 @@ void data1_destroy (data1_handle dh) wrbuf_free (dh->wrbuf, 1); if (dh->tab_path) xfree (dh->tab_path); + if (dh->tab_root) + xfree (dh->tab_root); if (dh->read_buf) xfree (dh->read_buf); if (dh->map_buf) @@ -117,16 +100,18 @@ char **data1_get_map_buf (data1_handle dp, int **lenp) void data1_set_tabpath (data1_handle dp, const char *p) { - if (dp->tab_path) - { - xfree (dp->tab_path); - dp->tab_path = NULL; - } + xfree (dp->tab_path); + dp->tab_path = NULL; if (p) - { - dp->tab_path = (char *)xmalloc (strlen(p)+1); - strcpy (dp->tab_path, p); - } + dp->tab_path = xstrdup (p); +} + +void data1_set_tabroot (data1_handle dp, const char *p) +{ + xfree (dp->tab_root); + dp->tab_root = NULL; + if (p) + dp->tab_root = xstrdup (p); } const char *data1_get_tabpath (data1_handle dp) @@ -134,3 +119,14 @@ const char *data1_get_tabpath (data1_handle dp) return dp->tab_path; } +const char *data1_get_tabroot (data1_handle dp) +{ + return dp->tab_root; +} + +FILE *data1_path_fopen (data1_handle dh, const char *file, const char *mode) +{ + const char *path = data1_get_tabpath(dh); + const char *root = data1_get_tabroot(dh); + return yaz_path_fopen_base (path, file, "r", root); +} diff --git a/retrieval/d1_map.c b/retrieval/d1_map.c index 15d14cb..e40b678 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.18 2000-11-29 14:22:47 adam + * Revision 1.19 2002-04-04 20:49:46 adam + * New functions yaz_is_abspath, yaz_path_fopen_base + * + * Revision 1.18 2000/11/29 14:22:47 adam * Implemented XML/SGML attributes for data1 so that d1_read reads them * and d1_write generates proper attributes for XML/SGML records. Added * register locking for threaded version. @@ -93,7 +96,7 @@ data1_maptab *data1_read_maptab (data1_handle dh, const char *file) data1_mapunit **mapp; int local_numeric = 0; - if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r"))) + if (!(f = data1_path_fopen(dh, file, "r"))) { yaz_log(LOG_WARN|LOG_ERRNO, "%s", file); return 0; diff --git a/retrieval/d1_marc.c b/retrieval/d1_marc.c index 0bf408f..2f06142 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.16 1999-11-30 13:47:12 adam + * Revision 1.17 2002-04-04 20:49:46 adam + * New functions yaz_is_abspath, yaz_path_fopen_base + * + * Revision 1.16 1999/11/30 13:47:12 adam * Improved installation. Moved header files to include/yaz. * * Revision 1.15 1999/10/21 12:06:29 adam @@ -83,7 +86,7 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file) int lineno = 0; int argc; - if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r"))) + if (!(f = data1_path_fopen(dh, file, "r"))) { yaz_log(LOG_WARN|LOG_ERRNO, "%s", file); return 0; diff --git a/retrieval/d1_tagset.c b/retrieval/d1_tagset.c index 2a1a330..1abd9fe 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.14 1999-11-30 13:47:12 adam + * Revision 1.15 2002-04-04 20:49:46 adam + * New functions yaz_is_abspath, yaz_path_fopen_base + * + * Revision 1.14 1999/11/30 13:47:12 adam * Improved installation. Moved header files to include/yaz. * * Revision 1.13 1999/10/21 12:06:29 adam @@ -165,7 +168,7 @@ data1_tagset *data1_read_tagset (data1_handle dh, const char *file, int type) int argc; char *argv[50], line[512]; - if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r"))) + if (!(f = data1_path_fopen(dh, file, "r"))) { yaz_log(LOG_WARN|LOG_ERRNO, "%s", file); return 0; diff --git a/retrieval/d1_varset.c b/retrieval/d1_varset.c index 6332a56..dbd1321 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.10 1999-11-30 13:47:12 adam + * Revision 1.11 2002-04-04 20:49:46 adam + * New functions yaz_is_abspath, yaz_path_fopen_base + * + * Revision 1.10 1999/11/30 13:47:12 adam * Improved installation. Moved header files to include/yaz. * * Revision 1.9 1999/08/27 09:40:32 adam @@ -85,7 +88,7 @@ data1_varset *data1_read_varset (data1_handle dh, const char *file) res->reference = VAL_NONE; res->classes = 0; - if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r"))) + if (!(f = data1_path_fopen(dh, file, "r"))) { yaz_log(LOG_WARN|LOG_ERRNO, "%s", file); return 0; diff --git a/util/tpath.c b/util/tpath.c index 1f37514..b8f0794 100644 --- a/util/tpath.c +++ b/util/tpath.c @@ -1,37 +1,30 @@ /* - * Copyright (c) 1995-2000, Index Data. + * Copyright (c) 1995-2002, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: tpath.c,v $ - * Revision 1.5 2000-12-05 19:03:19 adam - * WIN32 fixes for drive specifications. - * - * Revision 1.4 2000/02/29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.3 1999/11/30 13:47:12 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.2 1996/10/29 13:36:26 adam - * Added header. - * - * Revision 1.1 1995/11/01 16:35:00 quinn - * Making data1 look for tables in data1_tabpath - * - * + * $Id: tpath.c,v 1.6 2002-04-04 20:49:46 adam Exp $ */ #if HAVE_CONFIG_H #include #endif + #include #include +#include #include +#include FILE *yaz_path_fopen(const char *path, const char *name, const char *mode) { - char spath[512]; + return yaz_path_fopen_base (path, name, mode, 0); +} + +FILE *yaz_path_fopen_base(const char *path, const char *name, const char *mode, + const char *base) +{ + char spath[1024]; for(;;) { @@ -39,7 +32,9 @@ FILE *yaz_path_fopen(const char *path, const char *name, const char *mode) const char *path_sep = 0; size_t len = 0; + size_t slen = 0; + *spath = '\0'; if (path) { /* somewhat dirty since we have to consider Windows @@ -55,22 +50,37 @@ FILE *yaz_path_fopen(const char *path, const char *name, const char *mode) len = path_sep - path; else len = strlen(path); - if (len > 255) - len = 255; - memcpy (spath, path, len); - if (!strchr("/\\", spath[len-1])) + if (!strchr ("/\\", *path) && base) { - strcpy (spath+len, "/"); - len++; + strcpy (spath, base); + slen = strlen(spath); + spath[slen++] = '/'; } + memcpy (spath+slen, path, len); + slen += len; + if (!strchr("/\\", spath[slen-1])) + spath[slen++] = '/'; } - sprintf (spath+len, "%.255s", name); + strcpy (spath+slen, name); if ((f = fopen(spath, mode))) return f; - + if (!path_sep) break; path = path_sep+1; } return 0; } + +int yaz_is_abspath (const char *p) +{ + if (*p == '/') + return 1; +#ifdef WIN32 + if (*p == '\\') + return 1; + if (*p && p[1] == ':' && isalpha(*p)) + return 1; +#endif + return 0; +}