2 * Copyright (C) 1995-2004, Index Data
5 * $Id: logrpn.c,v 1.3 2004-10-15 00:19:00 adam Exp $
10 * \brief Implements Z39.50 Query Printing
16 #include <yaz/logrpn.h>
18 static const char *relToStr(int v)
23 case 1: str = "Less than"; break;
24 case 2: str = "Less than or equal"; break;
25 case 3: str = "Equal"; break;
26 case 4: str = "Greater or equal"; break;
27 case 5: str = "Greater than"; break;
28 case 6: str = "Not equal"; break;
29 case 100: str = "Phonetic"; break;
30 case 101: str = "Stem"; break;
31 case 102: str = "Relevance"; break;
32 case 103: str = "AlwaysMatches"; break;
36 static void attrStr (int type, int value, enum oid_value ast, char *str)
51 rstr = relToStr(value);
53 sprintf (str, "relation=%s", rstr);
55 sprintf (str, "relation=%d", value);
61 sprintf (str, "position=First in field");
64 sprintf (str, "position=First in any subfield");
67 sprintf (str, "position=Any position in field");
70 sprintf (str, "position");
77 sprintf (str, "structure=Phrase");
80 sprintf (str, "structure=Word");
83 sprintf (str, "structure=Key");
86 sprintf (str, "structure=Year");
89 sprintf (str, "structure=Date");
92 sprintf (str, "structure=Word list");
95 sprintf (str, "structure=Date (un)");
98 sprintf (str, "structure=Name (norm)");
101 sprintf (str, "structure=Name (un)");
104 sprintf (str, "structure=Structure");
107 sprintf (str, "structure=urx");
110 sprintf (str, "structure=free-form-text");
113 sprintf (str, "structure=document-text");
116 sprintf (str, "structure=local-number");
119 sprintf (str, "structure=string");
122 sprintf (str, "structure=numeric string");
125 sprintf (str, "structure");
132 sprintf (str, "truncation=Right");
135 sprintf (str, "truncation=Left");
138 sprintf (str, "truncation=Left&right");
141 sprintf (str, "truncation=Do not truncate");
144 sprintf (str, "truncation=Process #");
147 sprintf (str, "truncation=re-1");
150 sprintf (str, "truncation=re-2");
153 sprintf (str, "truncation=CCL");
156 sprintf (str, "truncation");
163 sprintf (str, "completeness=Incomplete subfield");
166 sprintf (str, "completeness=Complete subfield");
169 sprintf (str, "completeness=Complete field");
172 sprintf (str, "completeness");
181 sprintf (str + strlen(str), " (%d=%d)", type, value);
183 sprintf (str, "%d=%d", type, value);
187 * zlog_attributes: print attributes of term
189 static void zlog_attributes (Z_AttributesPlusTerm *t, int level,
194 int num_attributes = t->attributes->num_attributes;
196 for (of = 0; of < num_attributes; of++)
198 const char *attset_name = "";
199 Z_AttributeElement *element;
200 element = t->attributes->attributes[of];
201 if (element->attributeSet)
204 attrset = oid_getentbyoid (element->attributeSet);
205 attset_name = attrset->desc;
207 switch (element->which)
209 case Z_AttributeValue_numeric:
210 attrStr (*element->attributeType,
211 *element->value.numeric, ast, str);
212 yaz_log (LOG_LOG, "%*.0s%s %s", level, "", attset_name, str);
214 case Z_AttributeValue_complex:
215 yaz_log (LOG_LOG, "%*.0s%s attributeType=%d complex",
216 level, "", attset_name, *element->attributeType);
217 for (i = 0; i<element->value.complex->num_list; i++)
219 if (element->value.complex->list[i]->which ==
220 Z_StringOrNumeric_string)
221 yaz_log (LOG_LOG, "%*.0s string: '%s'", level, "",
222 element->value.complex->list[i]->u.string);
223 else if (element->value.complex->list[i]->which ==
224 Z_StringOrNumeric_numeric)
225 yaz_log (LOG_LOG, "%*.0s numeric: '%d'", level, "",
226 *element->value.complex->list[i]->u.numeric);
230 yaz_log (LOG_LOG, "%.*s%s attribute unknown",
231 level, "", attset_name);
236 static void zlog_structure (Z_RPNStructure *zs, int level, enum oid_value ast)
238 if (zs->which == Z_RPNStructure_complex)
240 Z_Operator *op = zs->u.complex->roperator;
241 const char *rstr = 0;
242 const char *unit = "private";
246 yaz_log (LOG_LOG, "%*.0s and", level, "");
249 yaz_log (LOG_LOG, "%*.0s or", level, "");
251 case Z_Operator_and_not:
252 yaz_log (LOG_LOG, "%*.0s and-not", level, "");
254 case Z_Operator_prox:
255 if (op->u.prox->which == Z_ProximityOperator_known)
257 switch(*op->u.prox->u.known)
259 case Z_ProxUnit_character: unit = "character"; break;
260 case Z_ProxUnit_word: unit = "word"; break;
261 case Z_ProxUnit_sentence: unit = "sentence"; break;
262 case Z_ProxUnit_paragraph: unit = "paragraph"; break;
263 case Z_ProxUnit_section: unit = "section"; break;
264 case Z_ProxUnit_chapter: unit = "chapter"; break;
265 case Z_ProxUnit_document: unit = "document"; break;
266 case Z_ProxUnit_element: unit = "element"; break;
267 case Z_ProxUnit_subelement: unit = "subelement"; break;
268 case Z_ProxUnit_elementType: unit = "elementType"; break;
269 case Z_ProxUnit_byte: unit = "byte"; break;
270 default: unit = "unknown"; break;
273 rstr = relToStr(*op->u.prox->relationType);
274 yaz_log (LOG_LOG, "%*.0s prox excl=%s dist=%d order=%s "
276 level, "", op->u.prox->exclusion ?
277 (*op->u.prox->exclusion ? "T" : "F") : "N",
278 *op->u.prox->distance,
279 *op->u.prox->ordered ? "T" : "F",
280 rstr ? rstr : "unknown",
284 yaz_log (LOG_LOG, "%*.0s unknown complex", level, "");
287 zlog_structure (zs->u.complex->s1, level+2, ast);
288 zlog_structure (zs->u.complex->s2, level+2, ast);
290 else if (zs->which == Z_RPNStructure_simple)
292 if (zs->u.simple->which == Z_Operand_APT)
294 Z_AttributesPlusTerm *zapt = zs->u.simple->u.attributesPlusTerm;
296 switch (zapt->term->which)
299 yaz_log (LOG_LOG, "%*.0s term '%.*s' (general)", level, "",
300 zapt->term->u.general->len,
301 zapt->term->u.general->buf);
303 case Z_Term_characterString:
304 yaz_log (LOG_LOG, "%*.0s term '%s' (string)", level, "",
305 zapt->term->u.characterString);
308 yaz_log (LOG_LOG, "%*.0s term '%d' (numeric)", level, "",
309 *zapt->term->u.numeric);
312 yaz_log (LOG_LOG, "%*.0s term (null)", level, "");
315 yaz_log (LOG_LOG, "%*.0s term (not general)", level, "");
317 zlog_attributes (zapt, level+2, ast);
319 else if (zs->u.simple->which == Z_Operand_resultSetId)
321 yaz_log (LOG_LOG, "%*.0s set '%s'", level, "",
322 zs->u.simple->u.resultSetId);
325 yaz_log (LOG_LOG, "%*.0s unknown simple structure", level, "");
328 yaz_log (LOG_LOG, "%*.0s unknown structure", level, "");
331 void log_rpn_query (Z_RPNQuery *rpn)
336 attrset = oid_getentbyoid (rpn->attributeSetId);
339 ast = attrset->value;
340 yaz_log (LOG_LOG, "RPN query. Type: %s", attrset->desc);
345 yaz_log (LOG_LOG, "RPN query. Unknown type");
347 zlog_structure (rpn->RPNStructure, 0, ast);
350 void log_scan_term (Z_AttributesPlusTerm *zapt, oid_value ast)
353 if (zapt->term->which == Z_Term_general)
355 yaz_log (LOG_LOG, "%*.0s term '%.*s' (general)", level, "",
356 zapt->term->u.general->len, zapt->term->u.general->buf);
359 yaz_log (LOG_LOG, "%*.0s term (not general)", level, "");
360 zlog_attributes (zapt, level+2, ast);
363 void yaz_log_zquery (Z_Query *q)
367 case Z_Query_type_1: case Z_Query_type_101:
368 log_rpn_query (q->u.type_1);
371 yaz_log(LOG_LOG, "CCL: %.*s", q->u.type_2->len, q->u.type_2->buf);
373 case Z_Query_type_100:
374 yaz_log(LOG_LOG, "Z39.58: %.*s", q->u.type_100->len,
377 case Z_Query_type_104:
378 if (q->u.type_104->which == Z_External_CQL)
379 yaz_log (LOG_LOG, "CQL: %s", q->u.type_104->u.cql);