b4e332f113c6f0afddd513e04b246602da814a93
[idzebra-moved-to-github.git] / index / zlogs.c
1 /*
2  * Copyright (C) 1994-1995, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: zlogs.c,v $
7  * Revision 1.1  1995-11-16 17:00:55  adam
8  * Better logging of rpn query.
9  *
10  */
11 #include <stdio.h>
12 #include <assert.h>
13
14
15 #include "zserver.h"
16
17 static char *attrStr (int type, int value, enum oid_value ast)
18 {
19     static char str[80];
20
21     switch (ast)
22     {
23     case VAL_BIB1:
24     case VAL_EXP1:
25     case VAL_GILS:
26         switch (type)
27         {
28         case 1:
29             sprintf (str, "use=%d", value);
30             return str;
31         case 2:
32             sprintf (str, "relation=%d", value);
33             return str;
34         case 3:
35             sprintf (str, "position=%d", value);
36             return str;
37         case 4:
38             sprintf (str, "structure=%d", value);
39             return str;
40         case 5:
41             sprintf (str, "truncation=%d", value);
42             return str;
43         case 6:
44             sprintf (str, "completeness=%d", value);
45             return str;
46         }
47         break;
48     default:
49         break;
50     }
51     sprintf (str, "%d=%d", type, value);
52     return str;
53 }
54
55 /*
56  * zlog_attributes: print attributes of term
57  */
58 static void zlog_attributes (Z_AttributesPlusTerm *t, int level,
59                              enum oid_value ast)
60 {
61     int of, i;
62     for (of = 0; of < t->num_attributes; of++)
63     {
64         Z_AttributeElement *element;
65         element = t->attributeList[of];
66
67         switch (element->which) 
68         {
69         case Z_AttributeValue_numeric:
70             logf (LOG_LOG, "%*.s %s", level, "",
71                   attrStr (*element->attributeType, *element->value.numeric, ast));
72             break;
73         case Z_AttributeValue_complex:
74             logf (LOG_LOG, "%*.s attributeType=%d complex", level, "",
75                   *element->attributeType);
76             for (i = 0; i<element->value.complex->num_list; i++)
77             {
78                 if (element->value.complex->list[i]->which ==
79                     Z_StringOrNumeric_string)
80                     logf (LOG_LOG, "%*.s  string: '%s'", level, "",
81                           element->value.complex->list[i]->u.string);
82                 else if (element->value.complex->list[i]->which ==
83                          Z_StringOrNumeric_numeric)
84                     logf (LOG_LOG, "%*.s  numeric: '%d'", level, "",
85                           *element->value.complex->list[i]->u.numeric);
86             }
87             break;
88         default:
89             logf (LOG_LOG, "%.*s attribute unknown", level, "");
90         }
91     }
92 }
93
94 static void zlog_structure (Z_RPNStructure *zs, int level, enum oid_value ast)
95 {
96     if (zs->which == Z_RPNStructure_complex)
97     {
98         switch (zs->u.complex->operator->which)
99         {
100         case Z_Operator_and:
101             logf (LOG_LOG, "%*.s and", level, "");
102             break;
103         case Z_Operator_or:
104             logf (LOG_LOG, "%*.s or", level, "");
105             break;
106         case Z_Operator_and_not:
107             logf (LOG_LOG, "%*.s and", level, "");
108             break;
109         default:
110             logf (LOG_LOG, "%*.s unknown complex", level, "");
111             return;
112         }
113         zlog_structure (zs->u.complex->s1, level+2, ast);
114         zlog_structure (zs->u.complex->s2, level+2, ast);
115     }
116     else if (zs->which == Z_RPNStructure_simple)
117     {
118         if (zs->u.simple->which == Z_Operand_APT)
119         {
120             Z_AttributesPlusTerm *zapt = zs->u.simple->u.attributesPlusTerm;
121
122             if (zapt->term->which == Z_Term_general) 
123             {
124                 logf (LOG_LOG, "%*.s term '%.*s' (general)", level, "",
125                       zapt->term->u.general->len, zapt->term->u.general->buf);
126             }
127             else
128             {
129                 logf (LOG_LOG, "%*.s term (not general)", level, "");
130             }
131             zlog_attributes (zapt, level+2, ast);
132         }
133         else if (zs->u.simple->which == Z_Operand_resultSetId)
134         {
135             logf (LOG_LOG, "%*.s set '%s'", level, "",
136                   zs->u.simple->u.resultSetId);
137         }
138         else
139             logf (LOG_LOG, "%*.s unknown simple structure", level, "");
140     }
141     else
142         logf (LOG_LOG, "%*.s unknown structure", level, "");
143 }
144
145 void zlog_rpn (Z_RPNQuery *rpn)
146 {
147     oident *attrset = oid_getentbyoid (rpn->attributeSetId);
148     enum oid_value ast;
149
150     ast = attrset->value;
151     logf (LOG_LOG, "RPN query. Type: %s", attrset->desc);
152     zlog_structure (rpn->RPNStructure, 0, ast);
153 }