* 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
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);
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
/*
- * 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,
* 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 $
*
*/
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
* 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
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;
* 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
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);
* 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 <stdlib.h>
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;
/*
- * 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 <stdio.h>
struct data1_handle_info {
WRBUF wrbuf;
char *tab_path;
+ char *tab_root;
char *read_buf;
int read_len;
if (!p)
return NULL;
p->tab_path = NULL;
+ p->tab_root = NULL;
p->wrbuf = wrbuf_alloc();
p->read_buf = NULL;
p->read_len = 0;
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)
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)
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);
+}
* 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.
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;
* 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
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;
* 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
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;
* 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
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;
/*
- * 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 <config.h>
#endif
+
#include <stdio.h>
#include <string.h>
+#include <ctype.h>
#include <yaz/tpath.h>
+#include <yaz/log.h>
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(;;)
{
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
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;
+}