2 * Copyright (C) 1995-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1999-08-27 09:40:33 adam
8 * Renamed logf function to yaz_log. Removed VC++ project files.
10 * Revision 1.1 1999/06/08 10:10:16 adam
11 * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
13 * Revision 1.1 1998/11/16 16:02:35 adam
14 * Added loggin utilies, log_rpn_query and log_scan_term. These used
15 * to be part of Zebra.
19 * Old logs from zlogs.c:
21 * Revision 1.9 1998/10/13 20:36:02 adam
22 * Changed "indent" format string in log messages.
24 * Revision 1.8 1998/04/02 14:35:29 adam
25 * First version of Zebra that works with compiled ASN.1.
27 * Revision 1.7 1998/01/29 13:40:11 adam
28 * Better logging for scan service.
30 * Revision 1.6 1997/09/29 09:06:41 adam
31 * Removed static var to make this module thread safe.
33 * Revision 1.5 1997/04/30 08:56:07 quinn
36 * Revision 1.4 1996/10/08 09:41:25 quinn
39 * Revision 1.3 1996/03/20 09:36:40 adam
40 * Function dict_lookup_grep got extra parameter, init_pos, which marks
41 * from which position in pattern approximate pattern matching should occur.
42 * Approximate pattern matching is used in relevance=re-2.
44 * Revision 1.2 1996/01/03 16:22:11 quinn
47 * Revision 1.1 1995/11/16 17:00:55 adam
48 * Better logging of rpn query.
57 static void attrStr (int type, int value, enum oid_value ast, char *str)
74 sprintf (str, "relation=Less than");
77 sprintf (str, "relation=Less than or equal");
80 sprintf (str, "relation=Equal");
83 sprintf (str, "relation=Greater or equal");
86 sprintf (str, "relation=Greater than");
89 sprintf (str, "relation=Not equal");
92 sprintf (str, "relation=Phonetic");
95 sprintf (str, "relation=Stem");
98 sprintf (str, "relation=Relevance");
101 sprintf (str, "relation=AlwaysMatches");
104 sprintf (str, "relation");
111 sprintf (str, "position=First in field");
114 sprintf (str, "position=First in any subfield");
117 sprintf (str, "position=Any position in field");
120 sprintf (str, "position");
127 sprintf (str, "structure=Phrase");
130 sprintf (str, "structure=Word");
133 sprintf (str, "structure=Key");
136 sprintf (str, "structure=Year");
139 sprintf (str, "structure=Date");
142 sprintf (str, "structure=Word list");
145 sprintf (str, "structure=Date (un)");
148 sprintf (str, "structure=Name (norm)");
151 sprintf (str, "structure=Name (un)");
154 sprintf (str, "structure=Structure");
157 sprintf (str, "structure=urx");
160 sprintf (str, "structure=free-form-text");
163 sprintf (str, "structure=document-text");
166 sprintf (str, "structure=local-number");
169 sprintf (str, "structure=string");
172 sprintf (str, "structure=numeric string");
175 sprintf (str, "structure");
182 sprintf (str, "truncation=Right");
185 sprintf (str, "truncation=Left");
188 sprintf (str, "truncation=Left&right");
191 sprintf (str, "truncation=Do not truncate");
194 sprintf (str, "truncation=Process #");
197 sprintf (str, "truncation=re-1");
200 sprintf (str, "truncation=re-2");
203 sprintf (str, "truncation");
210 sprintf (str, "completeness=Incomplete subfield");
213 sprintf (str, "completeness=Complete subfield");
216 sprintf (str, "completeness=Complete field");
219 sprintf (str, "completeness");
228 sprintf (str + strlen(str), " (%d=%d)", type, value);
230 sprintf (str, "%d=%d", type, value);
234 * zlog_attributes: print attributes of term
236 static void zlog_attributes (Z_AttributesPlusTerm *t, int level,
242 int num_attributes = t->attributes->num_attributes;
244 int num_attributes = t->num_attributes;
247 for (of = 0; of < num_attributes; of++)
249 const char *attset_name = "";
250 Z_AttributeElement *element;
252 element = t->attributes->attributes[of];
254 element = t->attributeList[of];
256 if (element->attributeSet)
259 attrset = oid_getentbyoid (element->attributeSet);
260 attset_name = attrset->desc;
262 switch (element->which)
264 case Z_AttributeValue_numeric:
265 attrStr (*element->attributeType,
266 *element->value.numeric, ast, str);
267 yaz_log (LOG_LOG, "%*.0s%s %s", level, "", attset_name, str);
269 case Z_AttributeValue_complex:
270 yaz_log (LOG_LOG, "%*.0s%s attributeType=%d complex",
271 level, "", attset_name, *element->attributeType);
272 for (i = 0; i<element->value.complex->num_list; i++)
274 if (element->value.complex->list[i]->which ==
275 Z_StringOrNumeric_string)
276 yaz_log (LOG_LOG, "%*.0s string: '%s'", level, "",
277 element->value.complex->list[i]->u.string);
278 else if (element->value.complex->list[i]->which ==
279 Z_StringOrNumeric_numeric)
280 yaz_log (LOG_LOG, "%*.0s numeric: '%d'", level, "",
281 *element->value.complex->list[i]->u.numeric);
285 yaz_log (LOG_LOG, "%.*s%s attribute unknown",
286 level, "", attset_name);
291 static void zlog_structure (Z_RPNStructure *zs, int level, enum oid_value ast)
293 if (zs->which == Z_RPNStructure_complex)
295 switch (zs->u.complex->roperator->which)
298 yaz_log (LOG_LOG, "%*.0s and", level, "");
301 yaz_log (LOG_LOG, "%*.0s or", level, "");
303 case Z_Operator_and_not:
304 yaz_log (LOG_LOG, "%*.0s and-not", level, "");
307 yaz_log (LOG_LOG, "%*.0s unknown complex", level, "");
310 zlog_structure (zs->u.complex->s1, level+2, ast);
311 zlog_structure (zs->u.complex->s2, level+2, ast);
313 else if (zs->which == Z_RPNStructure_simple)
315 if (zs->u.simple->which == Z_Operand_APT)
317 Z_AttributesPlusTerm *zapt = zs->u.simple->u.attributesPlusTerm;
319 if (zapt->term->which == Z_Term_general)
321 yaz_log (LOG_LOG, "%*.0s term '%.*s' (general)", level, "",
322 zapt->term->u.general->len,
323 zapt->term->u.general->buf);
327 yaz_log (LOG_LOG, "%*.0s term (not general)", level, "");
329 zlog_attributes (zapt, level+2, ast);
331 else if (zs->u.simple->which == Z_Operand_resultSetId)
333 yaz_log (LOG_LOG, "%*.0s set '%s'", level, "",
334 zs->u.simple->u.resultSetId);
337 yaz_log (LOG_LOG, "%*.0s unknown simple structure", level, "");
340 yaz_log (LOG_LOG, "%*.0s unknown structure", level, "");
343 void log_rpn_query (Z_RPNQuery *rpn)
348 attrset = oid_getentbyoid (rpn->attributeSetId);
351 ast = attrset->value;
352 yaz_log (LOG_LOG, "RPN query. Type: %s", attrset->desc);
357 yaz_log (LOG_LOG, "RPN query. Unknown type");
359 zlog_structure (rpn->RPNStructure, 0, ast);
362 void log_scan_term (Z_AttributesPlusTerm *zapt, oid_value ast)
365 if (zapt->term->which == Z_Term_general)
367 yaz_log (LOG_LOG, "%*.0s term '%.*s' (general)", level, "",
368 zapt->term->u.general->len, zapt->term->u.general->buf);
371 yaz_log (LOG_LOG, "%*.0s term (not general)", level, "");
372 zlog_attributes (zapt, level+2, ast);