schema mapping supports duplicate maps (copy instead of pointer swap)
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 28 May 2002 21:09:44 +0000 (21:09 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 28 May 2002 21:09:44 +0000 (21:09 +0000)
retrieval/d1_grs.c
retrieval/d1_map.c
retrieval/d1_marc.c

index 774b188..ece3781 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: d1_grs.c,v $
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: d1_grs.c,v $
- * Revision 1.20  2002-05-13 14:13:37  adam
+ * Revision 1.21  2002-05-28 21:09:44  adam
+ * schema mapping supports duplicate maps (copy instead of pointer swap)
+ *
+ * Revision 1.20  2002/05/13 14:13:37  adam
  * XML reader for data1 (EXPAT)
  *
  * Revision 1.19  2002/04/15 09:06:30  adam
  * XML reader for data1 (EXPAT)
  *
  * Revision 1.19  2002/04/15 09:06:30  adam
@@ -199,32 +202,32 @@ static Z_ElementData *nodetoelementdata(data1_handle dh, data1_node *n,
 
        switch (n->u.data.what)
        {
 
        switch (n->u.data.what)
        {
-           case DATA1I_num:
-               res->which = Z_ElementData_numeric;
-               res->u.numeric = (int *)odr_malloc(o, sizeof(int));
-               *res->u.numeric = atoi(n->u.data.data);
-               *len += 4;
-               break;
-           case DATA1I_text:
-               toget = n->u.data.len;
-               if (p && p->u.tag.get_bytes > 0 && p->u.tag.get_bytes < toget)
-                   toget = p->u.tag.get_bytes;
-               res->which = Z_ElementData_string;
-               res->u.string = (char *)odr_malloc(o, toget+1);
-               memcpy(res->u.string, n->u.data.data, toget);
-               res->u.string[toget] = '\0';
-               *len += toget;
-               break;
-           case DATA1I_oid:
-               res->which = Z_ElementData_oid;
-               strncpy(str, n->u.data.data, n->u.data.len);
-               str[n->u.data.len] = '\0';
-               res->u.oid = odr_getoidbystr(o, str);
-               *len += n->u.data.len;
-               break;
-           default:
-               yaz_log(LOG_WARN, "Can't handle datatype.");
-               return 0;
+        case DATA1I_num:
+            res->which = Z_ElementData_numeric;
+            res->u.numeric = (int *)odr_malloc(o, sizeof(int));
+            *res->u.numeric = atoi(n->u.data.data);
+            *len += 4;
+            break;
+        case DATA1I_text:
+            toget = n->u.data.len;
+            if (p && p->u.tag.get_bytes > 0 && p->u.tag.get_bytes < toget)
+                toget = p->u.tag.get_bytes;
+            res->which = Z_ElementData_string;
+            res->u.string = (char *)odr_malloc(o, toget+1);
+            memcpy(res->u.string, n->u.data.data, toget);
+            res->u.string[toget] = '\0';
+            *len += toget;
+            break;
+        case DATA1I_oid:
+            res->which = Z_ElementData_oid;
+            strncpy(str, n->u.data.data, n->u.data.len);
+            str[n->u.data.len] = '\0';
+            res->u.oid = odr_getoidbystr(o, str);
+            *len += n->u.data.len;
+            break;
+        default:
+            yaz_log(LOG_WARN, "Can't handle datatype.");
+            return 0;
        }
     }
     else
        }
     }
     else
@@ -243,7 +246,7 @@ static Z_TaggedElement *nodetotaggedelement(data1_handle dh, data1_node *n,
     Z_TaggedElement *res = (Z_TaggedElement *)odr_malloc(o, sizeof(*res));
     data1_tag *tag = 0;
     data1_node *data;
     Z_TaggedElement *res = (Z_TaggedElement *)odr_malloc(o, sizeof(*res));
     data1_tag *tag = 0;
     data1_node *data;
-    int leaf;
+    int leaf = 0;
 
     if (n->which == DATA1N_tag)
     {
 
     if (n->which == DATA1N_tag)
     {
@@ -339,7 +342,8 @@ Z_GenericRecord *data1_nodetogr(data1_handle dh, data1_node *n,
     for (c = n->child; c; c = c->next)
        num_children++;
 
     for (c = n->child; c; c = c->next)
        num_children++;
 
-    res->elements = (Z_TaggedElement **)odr_malloc(o, sizeof(Z_TaggedElement *) * num_children);
+    res->elements = (Z_TaggedElement **)
+        odr_malloc(o, sizeof(Z_TaggedElement *) * num_children);
     res->num_elements = 0;
     for (c = n->child; c; c = c->next)
     {
     res->num_elements = 0;
     for (c = n->child; c; c = c->next)
     {
index e3b9c3a..8331e6a 100644 (file)
@@ -1,83 +1,9 @@
 /*
 /*
- * Copyright (c) 1995-2000, Index Data.
+ * Copyright (c) 1995-2002, Index Data.
  * See the file LICENSE for details.
  * Sebastian Hammer, Adam Dickmeiss
  *
  * See the file LICENSE for details.
  * Sebastian Hammer, Adam Dickmeiss
  *
- * $Log: d1_map.c,v $
- * Revision 1.21  2002-05-07 11:02:56  adam
- * data1 backwards compatibility
- *
- * Revision 1.20  2002/05/03 13:48:27  adam
- * data1 cleanup
- *
- * 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.22 2002-05-28 21:09:44 adam Exp $
  */
 
 #include <stdio.h>
  */
 
 #include <stdio.h>
@@ -290,6 +216,27 @@ static int tagmatch(data1_node *n, data1_maptag *t)
     return 1;
 }
 
     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 = 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)
 {
 static int map_children(data1_handle dh, data1_node *n, data1_maptab *map,
                        data1_node *res, NMEM mem)
 {
@@ -325,13 +272,11 @@ static int map_children(data1_handle dh, data1_node *n, data1_maptab *map,
                            pn = cur;
                        else if (!m->no_data)
                        {
                            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)
                }
            }
            if (map_children(dh, c, map, res, mem) < 0)
index 1900855..75acbb9 100644 (file)
@@ -1,70 +1,9 @@
 /*
 /*
- * Copyright (c) 1995-1999, Index Data.
+ * Copyright (c) 1995-2002, Index Data.
  * See the file LICENSE for details.
  * Sebastian Hammer, Adam Dickmeiss
  *
  * See the file LICENSE for details.
  * Sebastian Hammer, Adam Dickmeiss
  *
- * $Log: d1_marc.c,v $
- * Revision 1.18  2002-05-27 12:34:24  adam
- * Fixed is_indicator
- *
- * 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
- * Retrieval module no longer uses ctype.h - functions.
- *
- * Revision 1.14  1999/08/27 09:40:32  adam
- * Renamed logf function to yaz_log. Removed VC++ project files.
- *
- * Revision 1.13  1998/10/13 16:09:52  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.12  1998/02/23 10:57:09  adam
- * Take care of integer data nodes as well in conversion.
- *
- * Revision 1.11  1998/02/11 11:53:35  adam
- * Changed code so that it compiles as C++.
- *
- * Revision 1.10  1997/09/30 11:50:04  adam
- * Added handler data1_get_map_buf that is used by data1_nodetomarc.
- *
- * Revision 1.9  1997/09/24 13:35:45  adam
- * Added two members to data1_marctab to ease reading of weird MARC records.
- *
- * Revision 1.8  1997/09/17 12:10:37  adam
- * YAZ version 1.4.
- *
- * Revision 1.7  1997/09/05 09:50:57  adam
- * Removed global data1_tabpath - uses data1_get_tabpath() instead.
- *
- * Revision 1.6  1997/09/04 13:51:58  adam
- * Added data1 to marc conversion with indicators.
- *
- * Revision 1.5  1997/09/04 13:48:04  adam
- * Added data1 to marc conversion.
- *
- * Revision 1.4  1996/03/25 10:18:03  quinn
- * Removed trailing whitespace from data elements
- *
- * 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
- * Added Retrieval (data management) functions en masse.
- *
- *
+ * $Id: d1_marc.c,v 1.19 2002-05-28 21:09:44 adam Exp $
  */
 
 
  */
 
 
@@ -268,6 +207,8 @@ static int nodetomarc(data1_marctab *p, data1_node *n, int selected,
     yaz_log (LOG_DEBUG, "nodetomarc");
     for (field = n->child; field; field = field->next)
     {
     yaz_log (LOG_DEBUG, "nodetomarc");
     for (field = n->child; field; field = field->next)
     {
+        int is00X = 0;
+
        if (field->which != DATA1N_tag)
        {
            yaz_log(LOG_WARN, "Malformed field composition for marc output.");
        if (field->which != DATA1N_tag)
        {
            yaz_log(LOG_WARN, "Malformed field composition for marc output.");
@@ -279,23 +220,20 @@ static int nodetomarc(data1_marctab *p, data1_node *n, int selected,
             + p->length_implementation;
         base_address += 3 + p->length_data_entry + p->length_starting
             + p->length_implementation;
             + p->length_implementation;
         base_address += 3 + p->length_data_entry + p->length_starting
             + p->length_implementation;
-       if (strncmp(field->u.tag.tag, "00", 2))
-            len += p->indicator_length;      /* this is fairly bogus */
        subf = field->child;
        subf = field->child;
+
+       if (subf->which == DATA1N_data)
+            is00X = 1;
        
        
+        if (!is00X)
+            len += p->indicator_length;  
        /*  we'll allow no indicator if length is not 2 */
        if (is_indicator (p, subf))
            subf = subf->child;
 
         for (; subf; subf = subf->next)
         {
        /*  we'll allow no indicator if length is not 2 */
        if (is_indicator (p, subf))
            subf = subf->child;
 
         for (; subf; subf = subf->next)
         {
-           if (subf->which != DATA1N_tag)
-           {
-               yaz_log(LOG_WARN,
-                   "Malformed subfield composition for marc output.");
-               return -1;
-           }
-            if (strncmp(field->u.tag.tag, "00", 2))
+            if (!is00X)
                 len += p->identifier_length;
            get_data(subf, &dlen);
             len += dlen;
                 len += p->identifier_length;
            get_data(subf, &dlen);
             len += dlen;
@@ -325,6 +263,8 @@ static int nodetomarc(data1_marctab *p, data1_node *n, int selected,
 
     for (field = n->child; field; field = field->next)
     {
 
     for (field = n->child; field; field = field->next)
     {
+        int is00X = 0;
+
         int data_0 = data_p;
        char *indicator_data = "    ";
        if (selected && !field->u.tag.node_selected)
         int data_0 = data_p;
        char *indicator_data = "    ";
        if (selected && !field->u.tag.node_selected)
@@ -332,12 +272,15 @@ static int nodetomarc(data1_marctab *p, data1_node *n, int selected,
 
        subf = field->child;
 
 
        subf = field->child;
 
+        if (subf->which == DATA1N_data)
+            is00X = 1;
+
        if (is_indicator (p, subf))
        {
             indicator_data = subf->u.tag.tag;
            subf = subf->child;
        }
        if (is_indicator (p, subf))
        {
             indicator_data = subf->u.tag.tag;
            subf = subf->child;
        }
-        if (strncmp(field->u.tag.tag, "00", 2))   /* bogus */
+        if (!is00X)
         {
             memcpy (op + data_p, indicator_data, p->indicator_length);
             data_p += p->indicator_length;
         {
             memcpy (op + data_p, indicator_data, p->indicator_length);
             data_p += p->indicator_length;
@@ -346,10 +289,15 @@ static int nodetomarc(data1_marctab *p, data1_node *n, int selected,
         {
            char *data;
 
         {
            char *data;
 
-            if (strncmp(field->u.tag.tag, "00", 2))
+            if (!is00X)
             {
             {
+                const char *identifier = "a";
+                if (subf->which != DATA1N_tag)
+                    yaz_log(LOG_WARN, "Malformed fields for marc output.");
+                else
+                    identifier = subf->u.tag.tag;
                 op[data_p] = ISO2709_IDFS;
                 op[data_p] = ISO2709_IDFS;
-                memcpy (op + data_p+1, subf->u.tag.tag, p->identifier_length-1);
+                memcpy (op + data_p+1, identifier, p->identifier_length-1);
                 data_p += p->identifier_length;
             }
            data = get_data(subf, &dlen);
                 data_p += p->identifier_length;
             }
            data = get_data(subf, &dlen);