From abfbb8adfc5e2cbc048b623d41eaf36f05cf8bd9 Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Thu, 14 Dec 1995 11:09:43 +0000 Subject: [PATCH] Work on Explain --- include/data1.h | 6 +- include/prt-exp.h | 4 +- retrieval/Makefile | 4 +- retrieval/d1_expout.c | 194 +++++++++++++++++++++++++++++++++++++++++++++++++ server/seshigh.c | 6 +- tab/explain.abs | 2 +- 6 files changed, 210 insertions(+), 6 deletions(-) create mode 100644 retrieval/d1_expout.c diff --git a/include/data1.h b/include/data1.h index 91dbf9a..0e1542a 100644 --- a/include/data1.h +++ b/include/data1.h @@ -24,7 +24,10 @@ * OF THIS SOFTWARE. * * $Log: data1.h,v $ - * Revision 1.9 1995-12-13 15:32:47 quinn + * Revision 1.10 1995-12-14 11:09:43 quinn + * Work on Explain + * + * Revision 1.9 1995/12/13 15:32:47 quinn * Added sgml-output. * * Revision 1.8 1995/12/13 13:44:23 quinn @@ -345,5 +348,6 @@ data1_node *data1_map_record(data1_node *n, data1_maptab *map, NMEM m); data1_marctab *data1_read_marctab(char *file); char *data1_nodetomarc(data1_marctab *p, data1_node *n, int selected, int *len); char *data1_nodetoidsgml(data1_node *n, int select, int *len); +Z_ExplainRecord *data1_nodetoexplain(data1_node *n, int select, ODR o); #endif diff --git a/include/prt-exp.h b/include/prt-exp.h index eda1d9b..3549cf5 100644 --- a/include/prt-exp.h +++ b/include/prt-exp.h @@ -30,6 +30,8 @@ #include +#define multipleDbSearch multipleDBsearch + typedef struct Z_CommonInfo { char *dateAdded; /* OPTIONAL */ @@ -335,7 +337,7 @@ typedef struct Z_TargetInfo Z_HumanString *recentNews; /* OPTIONAL */ Z_IconObject *icon; /* OPTIONAL */ bool_t *namedResultSets; - bool_t *multipleDBsearch; + bool_t *multipleDbSearch; int *maxResultSets; /* OPTIONAL */ int *maxResultSize; /* OPTIONAL */ int *maxTerms; /* OPTIONAL */ diff --git a/retrieval/Makefile b/retrieval/Makefile index d813cb4..bf296ef 100644 --- a/retrieval/Makefile +++ b/retrieval/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.3 1995-12-13 15:32:53 quinn Exp $ +# $Id: Makefile,v 1.4 1995-12-14 11:09:50 quinn Exp $ SHELL=/bin/sh RANLIB=ranlib @@ -8,7 +8,7 @@ DEFS=$(INCLUDE) LIB=../lib/libret.a PO = d1_read.o d1_attset.o d1_tagset.o d1_absyn.o d1_grs.o \ d1_matchstr.o d1_sutrs.o d1_varset.o d1_espec.o \ - d1_doespec.o d1_map.o d1_marc.o d1_write.o + d1_doespec.o d1_map.o d1_marc.o d1_write.o d1_expout.o CPP=$(CC) -E all: $(LIB) diff --git a/retrieval/d1_expout.c b/retrieval/d1_expout.c new file mode 100644 index 0000000..03d86a2 --- /dev/null +++ b/retrieval/d1_expout.c @@ -0,0 +1,194 @@ +/* + * Copyright (c) 1995, Index Data. + * See the file LICENSE for details. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: d1_expout.c,v $ + * Revision 1.1 1995-12-14 11:09:51 quinn + * Work on Explain + * + * + */ + +#include +#include +#include + +#include +#include +#include + +static int *f_integer(data1_node *c, ODR o) +{ + int *r; + char intbuf[64]; + + if (!c->child || c->child->which != DATA1N_data || + c->child->u.data.len > 63) + return 0; + r = odr_malloc(o, sizeof(*r)); + sprintf(intbuf, "%.*s", 63, c->child->u.data.data); + *r = atoi(intbuf); + return r; +} + +static char *f_string(data1_node *c, ODR o) +{ + char *r; + + if (!c->child || c->child->which != DATA1N_data) + return 0; + r = odr_malloc(o, c->child->u.data.len+1); + memcpy(r, c->child->u.data.data, c->child->u.data.len); + r[c->child->u.data.len] = '\0'; + return r; +} + +static bool_t *f_bool(data1_node *c, ODR o) +{ + return 0; +} + +static Z_IntUnit *f_intunit(data1_node *c, ODR o) +{ + return 0; +} + +static Z_HumanString *f_humstring(data1_node *c, ODR o) +{ + Z_HumanString *r; + Z_HumanStringUnit *u; + + if (!c->child || c->child->which != DATA1N_data) + return 0; + r = odr_malloc(o, sizeof(*r)); + r->num_strings = 1; + r->strings = odr_malloc(o, sizeof(Z_HumanStringUnit*)); + r->strings[0] = u = odr_malloc(o, sizeof(*u)); + u->language = 0; + u->text = odr_malloc(o, c->child->u.data.len+1); + memcpy(u->text, c->child->u.data.data, c->child->u.data.len); + u->text[c->child->u.data.len] = '\0'; + return r; +} + +static Z_CommonInfo *f_commonInfo(data1_node *n, int select, ODR o) +{ + return 0; +} + +static Z_AccessInfo *f_accessInfo(data1_node *n, int select, ODR o) +{ + return 0; +} + +static Z_ContactInfo *f_contactInfo(data1_node *n, ODR o) +{ + return 0; +} + +static Z_TargetInfo *f_targetInfo(data1_node *n, int select, ODR o) +{ + Z_TargetInfo *res = odr_malloc(o, sizeof(*res)); + data1_node *c; + static bool_t fl = 0; + + res->commonInfo = 0; + res->name = 0; + res->recentNews = 0; + res->icon = 0; + res->namedResultSets = &fl; + res->multipleDbSearch = &fl; + res->maxResultSets = 0; + res->maxResultSize = 0; + res->maxTerms = 0; + res->timeoutInterval = 0; + res->welcomeMessage = 0; + res->contactInfo = 0; + res->description = 0; + res->num_nicknames = 0; + res->nicknames = 0; + res->usageRest = 0; + res->paymentAddr = 0; + res->hours = 0; + res->num_dbCombinations = 0; + res->dbCombinations = 0; + res->num_addresses = 0; + res->addresses = 0; + res->commonAccessInfo = 0; + + for (c = n->child; c; c = c->next) + { + if (c->which != DATA1N_tag || !c->u.tag.element) + { + logf(LOG_WARN, "Malformed explain record"); + return 0; + } + if (select && !c->u.tag.node_selected) + continue; + switch (c->u.tag.element->tag->value.numeric) + { + case 600: res->commonInfo = f_commonInfo(c, select, o);break; + case 102: res->name = f_string(c, o); break; + case 103: res->recentNews = f_humstring(c, o); break; + case 104: break; /* icon */ + case 105: res->namedResultSets = f_bool(c, o); break; + case 106: res->multipleDbSearch = f_bool(c, o); break; + case 107: res->maxResultSets = f_integer(c, o); break; + case 108: res->maxResultSize = f_integer(c, o); break; + case 109: res->maxTerms = f_integer(c, o); break; + case 110: res->timeoutInterval = f_intunit(c, o); break; + case 111: res->welcomeMessage = f_humstring(c, o); break; + case 112: res->contactInfo = f_contactInfo(c, o); break; + case 113: res->description = f_humstring(c, o); break; + case 114: break; /* nicknames */ + case 115: res->usageRest = f_humstring(c, o); break; + case 116: res->paymentAddr = f_humstring(c, o); break; + case 117: res->hours = f_humstring(c, o); break; + case 118: break; /* dbcombinations */ + case 119: break; /* addresses */ + case 500: res->commonAccessInfo = f_accessInfo(c, select, o); break; + default: + logf(LOG_WARN, "Unknown target-info element"); + } + } + return res; +} + +static Z_DatabaseInfo *f_databaseInfo(data1_node *n, int select, ODR o) +{ + return 0; +} + +Z_ExplainRecord *data1_nodetoexplain(data1_node *n, int select, ODR o) +{ + Z_ExplainRecord *res = odr_malloc(o, sizeof(*res)); + + assert(n->which == DATA1N_root); + if (strcmp(n->u.root.type, "explain")) + { + logf(LOG_WARN, "Attempt to convert a non-Explain record"); + return 0; + } + if (n->num_children != 1 || n->child->which != DATA1N_tag || + !n->u.tag.element) + { + logf(LOG_WARN, "Explain record should have one exactly one child"); + return 0; + } + switch (n->child->u.tag.element->tag->value.numeric) + { + case 0: res->which = Z_Explain_targetInfo; + if (!(res->u.targetInfo = f_targetInfo(n->child, select, o))) + return 0; + break; + case 1: res->which = Z_Explain_databaseInfo; + if (!(res->u.databaseInfo = f_databaseInfo(n->child, select, o))) + return 0; + break; + default: + logf(LOG_WARN, "Unknown explain category"); + return 0; + } + return res; +} diff --git a/server/seshigh.c b/server/seshigh.c index 0082e71..6866f98 100644 --- a/server/seshigh.c +++ b/server/seshigh.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: seshigh.c,v $ - * Revision 1.55 1995-11-08 17:41:37 quinn + * Revision 1.56 1995-12-14 11:09:57 quinn + * Work on Explain + * + * Revision 1.55 1995/11/08 17:41:37 quinn * Smallish. * * Revision 1.54 1995/11/08 15:11:29 quinn @@ -576,6 +579,7 @@ static int process_response(association *assoc, request *req, Z_APDU *res) { logf(LOG_WARN, "ODR error when encoding response: %s", odr_errlist[odr_geterror(assoc->decode)]); + odr_reset(assoc->encode); return -1; } req->response = odr_getbuf(assoc->encode, &req->len_response, diff --git a/tab/explain.abs b/tab/explain.abs index 3e60302..eaf2743 100644 --- a/tab/explain.abs +++ b/tab/explain.abs @@ -30,7 +30,7 @@ elm (4,0)/(4,115) usageRest - elm (4,0)/(4,116) paymentAddr - elm (4,0)/(4,117) hours - elm (4,0)/(4,118) dbCombinations - -elm (4,0)/(4,119) address - +elm (4,0)/(4,119) addresses - elm (4,0)/(4,500) commonAccessInfo - elm (4,0)/(4,500)/(4,501) queryTypesSupported - elm (4,0)/(4,500)/(4,503) diagnosticSets - -- 1.7.10.4