From 32ff7687bdfe5b972d54b1ba4f3078cee011fadf Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 29 Jul 2002 20:04:08 +0000 Subject: [PATCH] created data1_createx and compatibility --- include/yaz/data1.h | 8 +++++++- retrieval/d1_handle.c | 14 +++++++++++++- retrieval/d1_map.c | 15 ++++++++++----- retrieval/d1_read.c | 39 ++++++++++++++++++++++++++++++--------- retrieval/d1_write.c | 14 +++++++++++++- 5 files changed, 73 insertions(+), 17 deletions(-) diff --git a/include/yaz/data1.h b/include/yaz/data1.h index b8c78a5..ad65e15 100644 --- a/include/yaz/data1.h +++ b/include/yaz/data1.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: data1.h,v 1.14 2002-07-25 12:52:53 adam Exp $ + * $Id: data1.h,v 1.15 2002-07-29 20:04:08 adam Exp $ */ #ifndef DATA1_H @@ -294,6 +294,10 @@ typedef struct data1_node } data1_node; YAZ_EXPORT data1_handle data1_create (void); + +#define DATA1_FLAG_XML 1 +YAZ_EXPORT data1_handle data1_createx (int flags); + 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, const char **buf, @@ -476,6 +480,8 @@ YAZ_EXPORT int data1_iconv (data1_handle dh, NMEM m, data1_node *n, YAZ_EXPORT const char *data1_get_encoding (data1_handle dh, data1_node *n); +YAZ_EXPORT int data1_is_xmlmode(data1_handle dh); + YAZ_END_CDECL #endif diff --git a/retrieval/d1_handle.c b/retrieval/d1_handle.c index 541ee84..51cf971 100644 --- a/retrieval/d1_handle.c +++ b/retrieval/d1_handle.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data. * See the file LICENSE for details. * - * $Id: d1_handle.c,v 1.8 2002-04-05 12:46:07 adam Exp $ + * $Id: d1_handle.c,v 1.9 2002-07-29 20:04:08 adam Exp $ */ #include @@ -26,10 +26,16 @@ struct data1_handle_info { int map_len; NMEM mem; + int flags; }; data1_handle data1_create (void) { + return data1_createx(0); +} + +data1_handle data1_createx (int flags) +{ data1_handle p = (data1_handle)xmalloc (sizeof(*p)); if (!p) return NULL; @@ -43,6 +49,7 @@ data1_handle data1_create (void) p->absyn_cache = NULL; p->attset_cache = NULL; p->mem = nmem_create (); + p->flags = flags; return p; } @@ -130,3 +137,8 @@ FILE *data1_path_fopen (data1_handle dh, const char *file, const char *mode) const char *root = data1_get_tabroot(dh); return yaz_fopen (path, file, "r", root); } + +int data1_is_xmlmode(data1_handle dh) +{ + return dh->flags & DATA1_FLAG_XML; +} diff --git a/retrieval/d1_map.c b/retrieval/d1_map.c index 3befe06..d648e6e 100644 --- a/retrieval/d1_map.c +++ b/retrieval/d1_map.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: d1_map.c,v 1.23 2002-07-03 14:09:34 adam Exp $ + * $Id: d1_map.c,v 1.24 2002-07-29 20:04:08 adam Exp $ */ #include @@ -302,10 +302,15 @@ data1_node *data1_map_record (data1_handle dh, data1_node *n, yaz_log(LOG_WARN, "%s: Failed to load target absyn '%s'", map->name, map->target_absyn_name); } - n = n->child; - if (!n) - return 0; - res1 = data1_mk_tag (dh, m, map->target_absyn_name, 0, res); + if (data1_is_xmlmode(dh)) + { + n = n->child; + if (!n) + return 0; + res1 = data1_mk_tag (dh, m, map->target_absyn_name, 0, res); + } + else + res1 = res; if (map_children(dh, n, map, res1, m) < 0) { diff --git a/retrieval/d1_read.c b/retrieval/d1_read.c index 4926ec1..539c915 100644 --- a/retrieval/d1_read.c +++ b/retrieval/d1_read.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: d1_read.c,v 1.46 2002-07-25 12:52:53 adam Exp $ + * $Id: d1_read.c,v 1.47 2002-07-29 20:04:08 adam Exp $ */ #include @@ -24,9 +24,12 @@ data1_node *data1_get_root_tag (data1_handle dh, data1_node *n) { if (!n) return 0; - n = n->child; - while (n && n->which != DATA1N_tag) - n = n->next; + if (data1_is_xmlmode(dh)) + { + n = n->child; + while (n && n->which != DATA1N_tag) + n = n->next; + } return n; } @@ -622,8 +625,16 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m, break; } } - if (level <= 1) - return d1_stack[0]; + if (data1_is_xmlmode(dh)) + { + if (level <= 1) + return d1_stack[0]; + } + else + { + if (level <= 0) + return d1_stack[0]; + } continue; } else if (!strcmp(tag, "var")) @@ -676,10 +687,20 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m, if (level == 0) { parent = data1_mk_root (dh, m, tag); - d1_stack[level++] = parent; + res = d1_stack[level] = parent; + + if (data1_is_xmlmode(dh)) + { + level++; + res = data1_mk_tag (dh, m, tag, 0 /* attr */, parent); + res->u.tag.attributes = xattr; + } + } + else + { + res = data1_mk_tag (dh, m, tag, 0 /* attr */, parent); + res->u.tag.attributes = xattr; } - res = data1_mk_tag (dh, m, tag, 0 /* attr */, parent); - res->u.tag.attributes = xattr; } d1_stack[level] = res; d1_stack[level+1] = 0; diff --git a/retrieval/d1_write.c b/retrieval/d1_write.c index 69d8db6..cba4ae9 100644 --- a/retrieval/d1_write.c +++ b/retrieval/d1_write.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: d1_write.c,v 1.15 2002-07-25 12:52:53 adam Exp $ + * $Id: d1_write.c,v 1.16 2002-07-29 20:04:08 adam Exp $ */ #include @@ -220,8 +220,20 @@ char *data1_nodetoidsgml (data1_handle dh, data1_node *n, int select, int *len) wrbuf_rewind(b); + if (!data1_is_xmlmode (dh)) + { + wrbuf_puts (b, "<"); + wrbuf_puts (b, n->u.root.type); + wrbuf_puts (b, ">\n"); + } if (nodetoidsgml(n, select, b, 0, 0 /* no pretty format */)) return 0; + if (!data1_is_xmlmode (dh)) + { + wrbuf_puts (b, "u.root.type); + wrbuf_puts (b, ">\n"); + } *len = wrbuf_len(b); return wrbuf_buf(b); } -- 1.7.10.4