X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Flogrpn.c;h=379dad0928a856032d9152b3fca717d30d3670ca;hp=06c675e1dcb7d859b3f687a92ab91c682eab994b;hb=8cb8947e3a7bff4dbf8f124871cb4905df1adce7;hpb=46767b31f38d6b9a1964319c5473c948dbb10c1d diff --git a/src/logrpn.c b/src/logrpn.c index 06c675e..379dad0 100644 --- a/src/logrpn.c +++ b/src/logrpn.c @@ -1,12 +1,14 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2010 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ - /** * \file logrpn.c * \brief Implements Z39.50 Query Printing */ +#if HAVE_CONFIG_H +#include +#endif #include #include @@ -34,21 +36,21 @@ static const char *relToStr(Odr_int v) return str; } -static void attrStr (Odr_int type, Odr_int value, char *str) +static void attrStr(Odr_int type, Odr_int value, char *str) { const char *rstr; *str = '\0'; switch (type) { case 1: - sprintf (str, "use"); + sprintf(str, "use"); break; case 2: rstr = relToStr(value); if (rstr) sprintf(str, "relation=%s", rstr); else - sprintf(str, "relation=%d", value); + sprintf(str, "relation=" ODR_INT_PRINTF, value); break; case 3: switch (value) @@ -170,9 +172,10 @@ static void attrStr (Odr_int type, Odr_int value, char *str) break; } if (*str) - sprintf(str + strlen(str), " (%d=%d)", type, value); + sprintf(str + strlen(str), " (" ODR_INT_PRINTF "=" ODR_INT_PRINTF")", + type, value); else - sprintf(str, "%d=%d", type, value); + sprintf(str, ODR_INT_PRINTF "=" ODR_INT_PRINTF, type, value); } /* @@ -184,7 +187,7 @@ static void zlog_attributes(Z_AttributesPlusTerm *t, int depth, int of, i; char str[80]; int num_attributes = t->attributes->num_attributes; - + for (of = 0; of < num_attributes; of++) { char attset_name_buf[OID_STR_MAX]; @@ -198,32 +201,32 @@ static void zlog_attributes(Z_AttributesPlusTerm *t, int depth, } if (!attset_name) attset_name = ""; - switch (element->which) + switch (element->which) { case Z_AttributeValue_numeric: - attrStr (*element->attributeType, + attrStr(*element->attributeType, *element->value.numeric, str); - yaz_log (loglevel, "%*.0s%s %s", depth, "", attset_name, str); + yaz_log(loglevel, "%*.0s%s %s", depth, "", attset_name, str); break; case Z_AttributeValue_complex: - yaz_log (loglevel, "%*.0s%s attributeType=" ODR_INT_PRINTF + yaz_log(loglevel, "%*.0s%s attributeType=" ODR_INT_PRINTF " complex", depth, "", attset_name, *element->attributeType); for (i = 0; ivalue.complex->num_list; i++) { if (element->value.complex->list[i]->which == Z_StringOrNumeric_string) - yaz_log (loglevel, "%*.0s string: '%s'", depth, "", + yaz_log(loglevel, "%*.0s string: '%s'", depth, "", element->value.complex->list[i]->u.string); else if (element->value.complex->list[i]->which == Z_StringOrNumeric_numeric) - yaz_log (loglevel, "%*.0s numeric: '" ODR_INT_PRINTF + yaz_log(loglevel, "%*.0s numeric: '" ODR_INT_PRINTF " '", depth, "", *element->value.complex->list[i]->u.numeric); } break; default: - yaz_log (loglevel, "%.*s%s attribute unknown", + yaz_log(loglevel, "%.*s%s attribute unknown", depth, "", attset_name); } } @@ -246,7 +249,7 @@ static char *complex_op_name(Z_Operator *op) } } -static char *prox_unit_name(Z_ProximityOperator *op) +char *yaz_prox_unit_name(Z_ProximityOperator *op) { if (op->which!=Z_ProximityOperator_known) return "private"; @@ -267,7 +270,7 @@ static char *prox_unit_name(Z_ProximityOperator *op) } } -static void zlog_structure(Z_RPNStructure *zs, int depth, +static void zlog_structure(Z_RPNStructure *zs, int depth, const Odr_oid *ast, int loglevel) { if (zs->which == Z_RPNStructure_complex) @@ -278,26 +281,26 @@ static void zlog_structure(Z_RPNStructure *zs, int depth, case Z_Operator_and: case Z_Operator_or: case Z_Operator_and_not: - yaz_log (loglevel, "%*.0s %s", depth, "", complex_op_name(op) ); + yaz_log(loglevel, "%*.0s %s", depth, "", complex_op_name(op) ); break; case Z_Operator_prox: - yaz_log (loglevel, "%*.0s prox excl=%s dist=" ODR_INT_PRINTF + yaz_log(loglevel, "%*.0s prox excl=%s dist=" ODR_INT_PRINTF " order=%s " "rel=%s unit=%s", depth, "", op->u.prox->exclusion ? - (*op->u.prox->exclusion ? "T" : "F") : "N", + (*op->u.prox->exclusion ? "T" : "F") : "N", *op->u.prox->distance, *op->u.prox->ordered ? "T" : "F", relToStr(*op->u.prox->relationType), - prox_unit_name(op->u.prox) ); + yaz_prox_unit_name(op->u.prox) ); break; default: - yaz_log (loglevel, "%*.0s unknown complex", depth, ""); + yaz_log(loglevel, "%*.0s unknown complex", depth, ""); return; } - zlog_structure (zs->u.complex->s1, depth+2, ast, loglevel); - zlog_structure (zs->u.complex->s2, depth+2, ast, loglevel); - } + zlog_structure(zs->u.complex->s1, depth+2, ast, loglevel); + zlog_structure(zs->u.complex->s2, depth+2, ast, loglevel); + } else if (zs->which == Z_RPNStructure_simple) { if (zs->u.simple->which == Z_Operand_APT) @@ -307,40 +310,40 @@ static void zlog_structure(Z_RPNStructure *zs, int depth, switch (zapt->term->which) { case Z_Term_general: - yaz_log (loglevel, "%*.0s term '%.*s' (general)", depth, "", + yaz_log(loglevel, "%*.0s term '%.*s' (general)", depth, "", zapt->term->u.general->len, zapt->term->u.general->buf); break; case Z_Term_characterString: - yaz_log (loglevel, "%*.0s term '%s' (string)", depth, "", + yaz_log(loglevel, "%*.0s term '%s' (string)", depth, "", zapt->term->u.characterString); break; case Z_Term_numeric: - yaz_log (loglevel, "%*.0s term '" ODR_INT_PRINTF + yaz_log(loglevel, "%*.0s term '" ODR_INT_PRINTF "' (numeric)", depth, "", *zapt->term->u.numeric); break; case Z_Term_null: - yaz_log (loglevel, "%*.0s term (null)", depth, ""); + yaz_log(loglevel, "%*.0s term (null)", depth, ""); break; default: - yaz_log (loglevel, "%*.0s term (not general)", depth, ""); + yaz_log(loglevel, "%*.0s term (not general)", depth, ""); } zlog_attributes(zapt, depth+2, ast, loglevel); } else if (zs->u.simple->which == Z_Operand_resultSetId) { - yaz_log (loglevel, "%*.0s set '%s'", depth, "", + yaz_log(loglevel, "%*.0s set '%s'", depth, "", zs->u.simple->u.resultSetId); } else - yaz_log (loglevel, "%*.0s unknown simple structure", depth, ""); + yaz_log(loglevel, "%*.0s unknown simple structure", depth, ""); } else - yaz_log (loglevel, "%*.0s unknown structure", depth, ""); + yaz_log(loglevel, "%*.0s unknown structure", depth, ""); } -void log_rpn_query_level (int loglevel, Z_RPNQuery *rpn) +void log_rpn_query_level(int loglevel, Z_RPNQuery *rpn) { zlog_structure(rpn->RPNStructure, 0, rpn->attributeSetId, loglevel); } @@ -350,35 +353,35 @@ void log_rpn_query(Z_RPNQuery *rpn) log_rpn_query_level(YLOG_LOG, rpn); } -void log_scan_term_level(int loglevel, +void log_scan_term_level(int loglevel, Z_AttributesPlusTerm *zapt, const Odr_oid *ast) { int depth = 0; if (!loglevel) return; - if (zapt->term->which == Z_Term_general) + if (zapt->term->which == Z_Term_general) { - yaz_log (loglevel, "%*.0s term '%.*s' (general)", depth, "", + yaz_log(loglevel, "%*.0s term '%.*s' (general)", depth, "", zapt->term->u.general->len, zapt->term->u.general->buf); } else - yaz_log (loglevel, "%*.0s term (not general)", depth, ""); + yaz_log(loglevel, "%*.0s term (not general)", depth, ""); zlog_attributes(zapt, depth+2, ast, loglevel); } void log_scan_term(Z_AttributesPlusTerm *zapt, const Odr_oid *ast) { - log_scan_term_level (YLOG_LOG, zapt, ast); + log_scan_term_level(YLOG_LOG, zapt, ast); } -void yaz_log_zquery_level (int loglevel, Z_Query *q) +void yaz_log_zquery_level(int loglevel, Z_Query *q) { if (!loglevel) - return; + return; switch (q->which) { case Z_Query_type_1: case Z_Query_type_101: - log_rpn_query_level (loglevel, q->u.type_1); + log_rpn_query_level(loglevel, q->u.type_1); break; case Z_Query_type_2: yaz_log(loglevel, "CCL: %.*s", q->u.type_2->len, q->u.type_2->buf); @@ -389,11 +392,11 @@ void yaz_log_zquery_level (int loglevel, Z_Query *q) break; case Z_Query_type_104: if (q->u.type_104->which == Z_External_CQL) - yaz_log (loglevel, "CQL: %s", q->u.type_104->u.cql); + yaz_log(loglevel, "CQL: %s", q->u.type_104->u.cql); } } -void yaz_log_zquery (Z_Query *q) +void yaz_log_zquery(Z_Query *q) { yaz_log_zquery_level(YLOG_LOG, q); }