Fixed in record_fetch. Minor updates to API.
[idzebra-moved-to-github.git] / index / zinfo.c
index df6bb41..31f35b8 100644 (file)
@@ -1,10 +1,23 @@
 /*
- * Copyright (C) 1994-1998, Index Data I/S 
+ * Copyright (C) 1994-1999, Index Data
  * All rights reserved.
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: zinfo.c,v $
- * Revision 1.11  1998-06-09 12:16:48  adam
+ * Revision 1.15  1999-01-25 13:47:54  adam
+ * Fixed bug.
+ *
+ * Revision 1.14  1998/11/04 16:31:32  adam
+ * Fixed bug regarding recordBytes in databaseInfo.
+ *
+ * Revision 1.13  1998/11/03 10:17:09  adam
+ * Fixed bug regarding creation of some data1 nodes for Explain records.
+ *
+ * Revision 1.12  1998/10/13 20:37:11  adam
+ * Changed the way attribute sets are saved in Explain database to
+ * reflect "dynamic" OIDs.
+ *
+ * Revision 1.11  1998/06/09 12:16:48  adam
  * Implemented auto-generation of CategoryList records.
  *
  * Revision 1.10  1998/06/08 14:43:15  adam
@@ -267,9 +280,9 @@ static data1_node *data1_make_tagdata_text (data1_handle dh, data1_node *at,
     {
        data1_node *node_data = node->child;
        node_data->u.data.what = DATA1I_text;
-       node_data->u.data.data = node_data->lbuf;
-       strcpy (node_data->u.data.data, str);
-       node_data->u.data.len = strlen (node_data->u.data.data);
+       node_data->u.data.len = strlen (str);
+       node_data->u.data.data = data1_insert_string (dh, node_data,
+                                                     nmem, str);
        return node_data;
     }
 }
@@ -627,6 +640,9 @@ static void zebraExplain_readAttributeDetails (ZebraExplainInfo zei,
        data1_node *node_use = NULL;
        data1_node *node_ordinal = NULL;
        data1_node *np2;
+       char oid_str[128];
+       int oid_str_len;
+
        if (np->which != DATA1N_tag || strcmp (np->u.tag.tag, "attr"))
            continue;
        for (np2 = np->child; np2; np2 = np2->next)
@@ -642,10 +658,16 @@ static void zebraExplain_readAttributeDetails (ZebraExplainInfo zei,
                node_ordinal = np2->child;
        }
        assert (node_set && node_use && node_ordinal);
+
+       oid_str_len = node_set->u.data.len;
+       if (oid_str_len >= sizeof(oid_str))
+           oid_str_len = sizeof(oid_str)-1;
+       memcpy (oid_str, node_set->u.data.data, oid_str_len);
+       oid_str[oid_str_len] = '\0';
        
         *zsuip = nmem_malloc (zei->nmem, sizeof(**zsuip));
-       (*zsuip)->info.set = atoi_n (node_set->u.data.data,
-                                    node_set->u.data.len);
+       (*zsuip)->info.set = oid_getvalbyname (oid_str);
+
        (*zsuip)->info.use = atoi_n (node_use->u.data.data,
                                     node_use->u.data.len);
        (*zsuip)->info.ordinal = atoi_n (node_ordinal->u.data.data,
@@ -676,9 +698,10 @@ static void zebraExplain_readDatabase (ZebraExplainInfo zei,
 
     node_zebra = data1_search_tag (zei->dh, node_dbinfo->child,
                                 "zebraInfo");
-    np  = data1_search_tag (zei->dh, node_dbinfo->child,
-                           "recordBytes");
-    if (np && np->child && np->child->which == DATA1N_data)
+    if (node_zebra
+       && (np = data1_search_tag (zei->dh, node_zebra->child,
+                                  "recordBytes")) 
+       && np->child && np->child->which == DATA1N_data)
        zdi->recordBytes = atoi_n (np->child->u.data.data,
                                   np->child->u.data.len);
     if ((np = data1_search_tag (zei->dh, node_dbinfo->child,
@@ -937,7 +960,7 @@ static void zebraExplain_writeCategoryList (ZebraExplainInfo zei,
 
     /* convert to "SGML" and write it */
 #if ZINFO_DEBUG
-    data1_pr_tree (zei->dh, zad->data1_tree, stderr);
+    data1_pr_tree (zei->dh, node_categoryList, stderr);
 #endif
     sgml_buf = data1_nodetoidsgml(zei->dh, node_categoryList,
                                  0, &sgml_len);
@@ -1022,15 +1045,15 @@ static void zebraExplain_writeAttributeDetails (ZebraExplainInfo zei,
                data1_node *node_abt, *node_atd, *node_atvs;
                data1_add_tagdata_oid (zei->dh, node_asd, "oid",
                                       oid, zei->nmem);
-
+               
                node_abt = data1_add_tag (zei->dh, node_asd,
                                          "attributesByType", zei->nmem);
                node_atd = data1_add_tag (zei->dh, node_abt,
                                          "attributeTypeDetails", zei->nmem);
                data1_add_tagdata_int (zei->dh, node_atd,
-                                       "type", 1, zei->nmem);
+                                      "type", 1, zei->nmem);
                node_atvs = data1_add_tag (zei->dh, node_atd, 
-                                         "attributeValues", zei->nmem);
+                                          "attributeValues", zei->nmem);
                writeAttributeValueDetails (zei, zad, node_atvs, attset);
            }
        }
@@ -1042,15 +1065,23 @@ static void zebraExplain_writeAttributeDetails (ZebraExplainInfo zei,
                                 "attrlist", zei->nmem);
     for (zsui = zad->SUInfo; zsui; zsui = zsui->next)
     {
+       struct oident oident;
+       int oid[OID_SIZE];
        data1_node *node_attr;
-       node_attr = data1_add_tag (zei->dh, node_list,
-                                     "attr", zei->nmem);
-       data1_add_tagdata_int (zei->dh, node_attr, "set",
-                                 zsui->info.set, zei->nmem);
+       
+       node_attr = data1_add_tag (zei->dh, node_list, "attr", zei->nmem);
+       
+       oident.proto = PROTO_Z3950;
+       oident.oclass = CLASS_ATTSET;
+       oident.value = zsui->info.set;
+       oid_ent_to_oid (&oident, oid);
+       
+       data1_add_tagdata_text (zei->dh, node_attr, "set",
+                               oident.desc, zei->nmem);
        data1_add_tagdata_int (zei->dh, node_attr, "use",
-                                 zsui->info.use, zei->nmem);
+                              zsui->info.use, zei->nmem);
        data1_add_tagdata_int (zei->dh, node_attr, "ordinal",
-                                 zsui->info.ordinal, zei->nmem);
+                              zsui->info.ordinal, zei->nmem);
     }
     /* convert to "SGML" and write it */
 #if ZINFO_DEBUG