X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=retrieval%2Fd1_map.c;h=d3c79e5482e7d48280b71eb384794a8e7cbc82e0;hb=6866fce7b026f5ce8b75945f72a844d7b44abd85;hp=e40b67825d48de7a0406a5b5dd154ea93f156186;hpb=98f0cc2d7eeed27912edb88bf16512bb622b19ee;p=yaz-moved-to-github.git diff --git a/retrieval/d1_map.c b/retrieval/d1_map.c index e40b678..d3c79e5 100644 --- a/retrieval/d1_map.c +++ b/retrieval/d1_map.c @@ -1,77 +1,9 @@ /* - * Copyright (c) 1995-2000, Index Data. + * Copyright (c) 1995-2002, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: d1_map.c,v $ - * 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. - * - * Revision 1.17 1999/11/30 13:47:12 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.16 1999/10/21 12:06:29 adam - * Retrieval module no longer uses ctype.h - functions. - * - * Revision 1.15 1999/08/27 09:40:32 adam - * Renamed logf function to yaz_log. Removed VC++ project files. - * - * Revision 1.14 1998/10/13 16:09:50 adam - * Added support for arbitrary OID's for tagsets, schemas and attribute sets. - * Added support for multiple attribute set references and tagset references - * from an abstract syntax file. - * Fixed many bad logs-calls in routines that read the various - * specifications regarding data1 (*.abs,*.att,...) and made the messages - * consistent whenever possible. - * Added extra 'lineno' argument to function readconf_line. - * - * Revision 1.13 1998/02/11 11:53:35 adam - * Changed code so that it compiles as C++. - * - * Revision 1.12 1997/11/18 09:51:09 adam - * Removed element num_children from data1_node. Minor changes in - * data1 to Explain. - * - * 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 - * Work on Summary. - * - * Revision 1.8 1996/05/01 12:45:31 quinn - * Support use of local tag names in abs file. - * - * Revision 1.7 1995/12/13 13:44:31 quinn - * Modified Data1-system to use nmem - * - * Revision 1.6 1995/12/12 16:37:08 quinn - * Added destroy element to data1_node. - * - * Revision 1.5 1995/12/12 14:11:31 quinn - * More work on the large-record problem. - * - * Revision 1.4 1995/12/11 15:22:37 quinn - * Added last_child field to the node. - * Rewrote schema-mapping. - * - * 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 - * Added Retrieval (data management) functions en masse. - * - * + * $Id: d1_map.c,v 1.25 2002-09-24 08:05:41 adam Exp $ */ #include @@ -180,7 +112,7 @@ data1_maptab *data1_read_maptab (data1_handle dh, const char *file) if (ep) ep++; - if ((np = sscanf(path, "(%d,%[^)]):%[^/]", &type, valstr, + if ((np = sscanf(path, "(%d,%511[^)]):%511[^/]", &type, valstr, parm)) < 2) { yaz_log(LOG_WARN, "%s:%d: Syntax error in map " @@ -284,6 +216,27 @@ static int tagmatch(data1_node *n, data1_maptag *t) return 1; } +static data1_node *dup_child (data1_handle dh, data1_node *n, + data1_node **last, NMEM mem, + data1_node *parent) +{ + data1_node *first = 0; + data1_node **m = &first; + + for (; n; n = n->next) + { + *last = *m = (data1_node *) nmem_malloc (mem, sizeof(**m)); + memcpy (*m, n, sizeof(**m)); + + (*m)->parent = parent; + (*m)->root = parent->root; + (*m)->child = dup_child(dh, n->child, &(*m)->last_child, mem, *m); + m = &(*m)->next; + } + *m = 0; + return first; +} + static int map_children(data1_handle dh, data1_node *n, data1_maptab *map, data1_node *res, NMEM mem) { @@ -311,29 +264,19 @@ static int map_children(data1_handle dh, data1_node *n, data1_maptab *map, { if (!cur || mt->new_field || !tagmatch(cur, mt)) { - cur = data1_mk_node_type (dh, mem, DATA1N_tag); + cur = data1_mk_node2 (dh, mem, DATA1N_tag, pn); cur->u.tag.tag = mt->value.string; - - cur->parent = pn; - cur->root = pn->root; - if (!pn->child) - pn->child = cur; - if (pn->last_child) - pn->last_child->next = cur; - pn->last_child = cur; } if (mt->next) pn = cur; else if (!m->no_data) { - cur->child = c->child; - cur->last_child = c->last_child; - c->child = 0; - c->last_child = 0; + cur->child = + dup_child (dh, c->child, + &cur->last_child, mem, cur); } } - break; } } if (map_children(dh, c, map, res, mem) < 0) @@ -350,7 +293,7 @@ static int map_children(data1_handle dh, data1_node *n, data1_maptab *map, data1_node *data1_map_record (data1_handle dh, data1_node *n, data1_maptab *map, NMEM m) { - data1_node *res = data1_mk_node(dh, m); + data1_node *res1, *res = data1_mk_node2 (dh, m, DATA1N_root, 0); res->which = DATA1N_root; res->u.root.type = map->target_absyn_name; @@ -359,10 +302,17 @@ 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); } - res->parent = 0; - res->root = 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, res, m) < 0) + if (map_children(dh, n, map, res1, m) < 0) { data1_free_tree(dh, res); return 0;