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