X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=retrieval%2Fd1_grs.c;h=30397c95850f6f1f16ca7801d81e4a5e4c82d657;hb=7674cd40af86e353235cb1b509f4b4687167cdf2;hp=9033c4d3bb92b30166bf96b9980079757569cf60;hpb=bc33b8b53697bcc10a02f7e7456fd75b2c3473ef;p=yaz-moved-to-github.git diff --git a/retrieval/d1_grs.c b/retrieval/d1_grs.c index 9033c4d..30397c9 100644 --- a/retrieval/d1_grs.c +++ b/retrieval/d1_grs.c @@ -1,10 +1,26 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1997, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_grs.c,v $ - * Revision 1.6 1996-07-06 19:58:34 quinn + * Revision 1.11 1997-11-18 09:51:09 adam + * Removed element num_children from data1_node. Minor changes in + * data1 to Explain. + * + * Revision 1.10 1997/09/17 12:10:36 adam + * YAZ version 1.4. + * + * Revision 1.9 1997/05/14 06:54:03 adam + * C++ support. + * + * Revision 1.8 1996/12/05 13:17:49 quinn + * Fixed GRS-1 null-ref + * + * Revision 1.7 1996/10/11 11:57:23 quinn + * Smallish + * + * Revision 1.6 1996/07/06 19:58:34 quinn * System headerfiles gathered in yconfig * * Revision 1.5 1996/06/03 09:46:42 quinn @@ -35,8 +51,6 @@ #define D1_VARIANTARRAY 20 /* fixed max length on sup'd variant-list. Lazy me */ -Z_GenericRecord *data1_nodetogr(data1_node *n, int select, ODR o); - static Z_ElementMetaData *get_ElementMetaData(ODR o) { Z_ElementMetaData *r = odr_malloc(o, sizeof(*r)); @@ -83,8 +97,8 @@ static Z_Variant *make_variant(data1_node *n, int num, ODR o) assert(p->which == DATA1N_variant); t = v->triples[num] = odr_malloc(o, sizeof(*t)); t->variantSetId = 0; - t->class = odr_malloc(o, sizeof(int)); - *t->class = p->u.variant.type->class->class; + t->zclass = odr_malloc(o, sizeof(int)); + *t->zclass = p->u.variant.type->zclass->zclass; t->type = odr_malloc(o, sizeof(int)); *t->type = p->u.variant.type->type; @@ -136,24 +150,25 @@ static int traverse_triples(data1_node *n, int level, Z_ElementMetaData *m, return 0; } -static Z_ElementData *nodetoelementdata(data1_node *n, int select, int leaf, - ODR o) +static Z_ElementData *nodetoelementdata(data1_handle dh, data1_node *n, + int select, int leaf, + ODR o, int *len) { Z_ElementData *res = odr_malloc(o, sizeof(*res)); - data1_node *p; - - for (p = n->parent; p && p->which != DATA1N_tag; p = p->parent) - ; if (!n) { res->which = Z_ElementData_elementNotThere; res->u.elementNotThere = ODR_NULLVAL; } - else if (n->which == DATA1N_data && (leaf || n->parent->num_children == 1)) + else if (n->which == DATA1N_data && (leaf || n->next == NULL)) { char str[512]; int toget; + data1_node *p; + + for (p = n->parent; p && p->which != DATA1N_tag; p = p->parent) + ; switch (n->u.data.what) { @@ -161,6 +176,7 @@ static Z_ElementData *nodetoelementdata(data1_node *n, int select, int leaf, res->which = Z_ElementData_numeric; res->u.numeric = odr_malloc(o, sizeof(int)); *res->u.numeric = atoi(n->u.data.data); + *len += 4; break; case DATA1I_text: toget = n->u.data.len; @@ -170,12 +186,14 @@ static Z_ElementData *nodetoelementdata(data1_node *n, int select, int leaf, res->u.string = 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: logf(LOG_WARN, "Can't handle datatype."); @@ -185,13 +203,15 @@ static Z_ElementData *nodetoelementdata(data1_node *n, int select, int leaf, else { res->which = Z_ElementData_subtree; - if (!(res->u.subtree = data1_nodetogr(n->parent, select, o))) + if (!(res->u.subtree = data1_nodetogr (dh, n->parent, select, o, len))) return 0; } return res; } -static Z_TaggedElement *nodetotaggedelement(data1_node *n, int select, ODR o) +static Z_TaggedElement *nodetotaggedelement(data1_handle dh, data1_node *n, + int select, ODR o, + int *len) { Z_TaggedElement *res = odr_malloc(o, sizeof(*res)); data1_tag *tag = 0; @@ -211,8 +231,8 @@ static Z_TaggedElement *nodetotaggedelement(data1_node *n, int select, ODR o) */ else if (n->which == DATA1N_data || n->which == DATA1N_variant) { - if (!(tag = data1_gettagbyname(n->root->u.root.absyn->tagset, - "wellKnown"))) + if (!(tag = data1_gettagbyname (dh, n->root->u.root.absyn->tagset, + "wellKnown"))) { logf(LOG_WARN, "Unable to locate tag for 'wellKnown'"); return 0; @@ -252,7 +272,7 @@ static Z_TaggedElement *nodetotaggedelement(data1_node *n, int select, ODR o) res->appliedVariant = 0; res->metaData = 0; if (n->which == DATA1N_variant || (data && data->which == - DATA1N_variant && data->parent->num_children == 1)) + DATA1N_variant && data->next == NULL)) { int nvars = 0; @@ -274,24 +294,31 @@ static Z_TaggedElement *nodetotaggedelement(data1_node *n, int select, ODR o) res->content->which = Z_ElementData_noDataRequested; res->content->u.noDataRequested = ODR_NULLVAL; } - else if (!(res->content = nodetoelementdata(data, select, leaf, o))) + else if (!(res->content = nodetoelementdata (dh, data, select, leaf, + o, len))) return 0; + *len += 10; return res; } -Z_GenericRecord *data1_nodetogr(data1_node *n, int select, ODR o) +Z_GenericRecord *data1_nodetogr(data1_handle dh, data1_node *n, + int select, ODR o, int *len) { Z_GenericRecord *res = odr_malloc(o, sizeof(*res)); data1_node *c; + int num_children = 0; + + for (c = n->child; c; c = c->next) + num_children++; - res->elements = odr_malloc(o, sizeof(Z_TaggedElement *) * n->num_children); + res->elements = odr_malloc(o, sizeof(Z_TaggedElement *) * num_children); res->num_elements = 0; for (c = n->child; c; c = c->next) { if (c->which == DATA1N_tag && select && !c->u.tag.node_selected) continue; if (!(res->elements[res->num_elements++] = - nodetotaggedelement(c, select, o))) + nodetotaggedelement (dh, c, select, o, len))) return 0; } return res;