+
+Z_AttributeTypeDetails *f_attributeTypeDetails (ExpHandle *eh, data1_node *n)
+{
+ Z_AttributeTypeDetails *res = (Z_AttributeTypeDetails *)
+ odr_malloc(eh->o, sizeof(*res));
+ data1_node *c;
+ res->attributeType = 0;
+ res->defaultIfOmitted = 0;
+ res->num_attributeValues = 0;
+ res->attributeValues = 0;
+ for (c = n->child; c; c = c->next)
+ {
+ int i = 0;
+ switch (is_numeric_tag (eh, c))
+ {
+ case 704: res->attributeType = f_integer (eh, c); break;
+ case 705:
+ res->defaultIfOmitted = f_omittedAttributeInterpretation (eh, c);
+ break;
+ case 708:
+ for (n = c->child; n; n = n->next)
+ {
+ if (is_numeric_tag(eh, n) != 709)
+ continue;
+ (res->num_attributeValues)++;
+ }
+ if (res->num_attributeValues)
+ res->attributeValues =
+ (Z_AttributeValue **)
+ odr_malloc (eh->o, res->num_attributeValues
+ * sizeof(*res->attributeValues));
+ for (n = c->child; n; n = n->next)
+ {
+ if (is_numeric_tag(eh, n) != 709)
+ continue;
+ res->attributeValues[i++] = f_attributeValue (eh, n);
+ }
+ break;
+ }
+ }
+ return res;
+}
+
+Z_AttributeSetDetails *f_attributeSetDetails (ExpHandle *eh, data1_node *n)
+{
+ Z_AttributeSetDetails *res = (Z_AttributeSetDetails *)
+ odr_malloc(eh->o, sizeof(*res));
+ data1_node *c;
+
+ res->attributeSet = 0;
+ res->num_attributesByType = 0;
+ res->attributesByType = 0;
+ for (c = n->child; c; c = c->next)
+ {
+ int i = 0;
+ switch (is_numeric_tag (eh, c))
+ {
+ case 1000: res->attributeSet = f_oid(eh, c, CLASS_ATTSET); break;
+ case 702:
+ for (n = c->child; n; n = n->next)
+ {
+ if (is_numeric_tag(eh, n) != 703)
+ continue;
+ (res->num_attributesByType)++;
+ }
+ if (res->num_attributesByType)
+ res->attributesByType =
+ (Z_AttributeTypeDetails **)
+ odr_malloc (eh->o, res->num_attributesByType
+ * sizeof(*res->attributesByType));
+ for (n = c->child; n; n = n->next)
+ {
+ if (is_numeric_tag(eh, n) != 703)
+ continue;
+ res->attributesByType[i++] = f_attributeTypeDetails (eh, n);
+ }
+ break;
+ }
+ }
+ return res;
+}
+
+Z_AttributeValueList *f_attributeValueList (ExpHandle *eh, data1_node *n)
+{
+ Z_AttributeValueList *res = (Z_AttributeValueList *)
+ odr_malloc (eh->o, sizeof(*res));
+ data1_node *c;
+ int i = 0;
+
+ res->num_attributes = 0;
+ res->attributes = 0;
+ for (c = n->child; c; c = c->next)
+ if (is_numeric_tag (eh, c) == 710)
+ (res->num_attributes)++;
+ if (res->num_attributes)
+ {
+ res->attributes = (Z_StringOrNumeric **)
+ odr_malloc (eh->o, res->num_attributes * sizeof(*res->attributes));
+ }
+ for (c = n->child; c; c = c->next)
+ if (is_numeric_tag(eh, c) == 710)
+ res->attributes[i++] = f_stringOrNumeric (eh, c);
+ return res;
+}
+
+Z_AttributeOccurrence *f_attributeOccurrence (ExpHandle *eh, data1_node *n)
+{
+ Z_AttributeOccurrence *res = (Z_AttributeOccurrence *)
+ odr_malloc (eh->o, sizeof(*res));
+ data1_node *c;
+
+ res->attributeSet = 0;
+ res->attributeType = 0;
+ res->mustBeSupplied = 0;
+ res->which = Z_AttributeOcc_any_or_none;
+ res->attributeValues.any_or_none = odr_nullval ();
+
+ for (c = n->child; c; c = c->next)
+ {
+ switch (is_numeric_tag (eh, c))
+ {
+ case 1000:
+ res->attributeSet = f_oid (eh, c, CLASS_ATTSET); break;
+ case 704:
+ res->attributeType = f_integer (eh, c); break;
+ case 720:
+ res->mustBeSupplied = odr_nullval (); break;
+ case 721:
+ res->which = Z_AttributeOcc_any_or_none;
+ res->attributeValues.any_or_none = odr_nullval ();
+ break;
+ case 722:
+ res->which = Z_AttributeOcc_specific;
+ res->attributeValues.specific = f_attributeValueList (eh, c);
+ break;
+ }
+ }
+ return res;
+}
+
+Z_AttributeCombination *f_attributeCombination (ExpHandle *eh, data1_node *n)
+{
+ Z_AttributeCombination *res = (Z_AttributeCombination *)
+ odr_malloc (eh->o, sizeof(*res));
+ data1_node *c;
+ int i = 0;
+
+ res->num_occurrences = 0;
+ res->occurrences = 0;
+ for (c = n->child; c; c = c->next)
+ if (is_numeric_tag (eh, c) == 719)
+ (res->num_occurrences)++;
+ if (res->num_occurrences)
+ {
+ res->occurrences = (Z_AttributeOccurrence **)
+ odr_malloc (eh->o, res->num_occurrences * sizeof(*res->occurrences));
+ }
+ for (c = n->child; c; c = c->next)
+ if (is_numeric_tag(eh, c) == 719)
+ res->occurrences[i++] = f_attributeOccurrence (eh, c);
+ assert (res->num_occurrences);
+ return res;
+}
+
+Z_AttributeCombinations *f_attributeCombinations (ExpHandle *eh, data1_node *n)
+{
+ Z_AttributeCombinations *res = (Z_AttributeCombinations *)
+ odr_malloc (eh->o, sizeof(*res));
+ data1_node *c;
+ res->defaultAttributeSet = 0;
+ res->num_legalCombinations = 0;
+ res->legalCombinations = 0;
+
+ for (c = n->child; c; c = c->next)
+ {
+ int i = 0;
+ switch (is_numeric_tag (eh, c))
+ {
+ case 1000:
+ res->defaultAttributeSet = f_oid (eh, c, CLASS_ATTSET);
+ break;
+ case 717:
+ for (n = c->child; n; n = n->next)
+ {
+ if (is_numeric_tag(eh, n) != 718)
+ continue;
+ (res->num_legalCombinations)++;
+ }
+ if (res->num_legalCombinations)
+ res->legalCombinations =
+ (Z_AttributeCombination **)
+ odr_malloc (eh->o, res->num_legalCombinations
+ * sizeof(*res->legalCombinations));
+ for (n = c->child; n; n = n->next)
+ {
+ if (is_numeric_tag(eh, n) != 718)
+ continue;
+ res->legalCombinations[i++] = f_attributeCombination (eh, n);
+ }
+ break;
+ }
+ }
+ assert (res->num_legalCombinations);
+ return res;
+}
+
+Z_AttributeDetails *f_attributeDetails (ExpHandle *eh, data1_node *n)
+{
+ Z_AttributeDetails *res = (Z_AttributeDetails *)
+ odr_malloc(eh->o, sizeof(*res));
+ data1_node *c;
+
+ res->commonInfo = 0;
+ res->databaseName = 0;
+ res->num_attributesBySet = 0;
+ res->attributesBySet = NULL;
+ res->attributeCombinations = NULL;
+
+ for (c = n->child; c; c = c->next)
+ {
+ int i = 0;
+ switch (is_numeric_tag (eh, c))
+ {
+ case 600: res->commonInfo = f_commonInfo(eh, c); break;
+ case 102: res->databaseName = f_string (eh, c); break;
+ case 700:
+ for (n = c->child; n; n = n->next)
+ {
+ if (is_numeric_tag(eh, n) != 701)
+ continue;
+ (res->num_attributesBySet)++;
+ }
+ if (res->num_attributesBySet)
+ res->attributesBySet =
+ (Z_AttributeSetDetails **)
+ odr_malloc (eh->o, res->num_attributesBySet
+ * sizeof(*res->attributesBySet));
+ for (n = c->child; n; n = n->next)
+ {
+ if (is_numeric_tag(eh, n) != 701)
+ continue;
+ res->attributesBySet[i++] = f_attributeSetDetails (eh, n);
+ }
+ break;
+ case 716:
+ res->attributeCombinations = f_attributeCombinations (eh, c);
+ break;
+ }
+ }
+ return res;
+}
+
+Z_ExplainRecord *data1_nodetoexplain (data1_handle dh, data1_node *n,
+ int select, ODR o)
+{
+ ExpHandle eh;
+ Z_ExplainRecord *res = (Z_ExplainRecord *)odr_malloc(o, sizeof(*res));
+
+ eh.dh = dh;
+ eh.select = select;
+ eh.o = o;
+ eh.false_value = (int *)odr_malloc(eh.o, sizeof(eh.false_value));
+ *eh.false_value = 0;
+ eh.true_value = (int *)odr_malloc(eh.o, sizeof(eh.true_value));
+ *eh.true_value = 1;
+
+ assert(n->which == DATA1N_root);
+ if (strcmp(n->u.root.type, "explain"))
+ {
+ yaz_log(LOG_WARN, "Attempt to convert a non-Explain record");
+ return 0;
+ }
+ for (n = n->child; n; n = n->next)
+ {
+ switch (is_numeric_tag (&eh, n))
+ {
+ case 1:
+ res->which = Z_Explain_categoryList;
+ if (!(res->u.categoryList = f_categoryList(&eh, n)))
+ return 0;
+ return res;
+ case 2:
+ res->which = Z_Explain_targetInfo;
+ if (!(res->u.targetInfo = f_targetInfo(&eh, n)))
+ return 0;
+ return res;
+ case 3:
+ res->which = Z_Explain_databaseInfo;
+ if (!(res->u.databaseInfo = f_databaseInfo(&eh, n)))
+ return 0;
+ return res;
+ case 7:
+ res->which = Z_Explain_attributeSetInfo;
+ if (!(res->u.attributeSetInfo = f_attributeSetInfo(&eh, n)))
+ return 0;
+ return res;
+ case 10:
+ res->which = Z_Explain_attributeDetails;
+ if (!(res->u.attributeDetails = f_attributeDetails(&eh, n)))
+ return 0;
+ return res;
+ }
+ }
+ yaz_log(LOG_WARN, "No category in Explain record");
+ return 0;
+}