+static void wrbuf_apt(WRBUF b, Z_AttributesPlusTerm *zapt)
+{
+ int num_attributes = zapt->attributes->num_attributes;
+ int i;
+ for (i = 0; i<num_attributes; i++)
+ wrbuf_attr(b,zapt->attributes->attributes[i]);
+
+ switch (zapt->term->which)
+ {
+ case Z_Term_general:
+ wrbuf_term(b, (const char *)zapt->term->u.general->buf,
+ zapt->term->u.general->len);
+ break;
+ case Z_Term_characterString:
+ wrbuf_printf(b, "@term string ");
+ wrbuf_term (b, zapt->term->u.characterString,
+ strlen(zapt->term->u.characterString));
+ break;
+ case Z_Term_numeric:
+ wrbuf_printf(b, "@term numeric %d ", *zapt->term->u.numeric);
+ break;
+ case Z_Term_null:
+ wrbuf_printf(b, "@term null x");
+ break;
+ default:
+ wrbuf_printf(b, "@term null unknown%d ", zapt->term->which);
+ }
+}
+
+static void wrbuf_structure (WRBUF b, Z_RPNStructure *zs, enum oid_value ast)
+{
+ if (zs->which == Z_RPNStructure_complex)
+ {
+ Z_Operator *op = zs->u.complex->roperator;
+ wrbuf_printf(b, "@%s ", complex_op_name(op) );
+ if (op->which== Z_Operator_prox)
+ {
+ if (!op->u.prox->exclusion)
+ wrbuf_putc(b, 'n');
+ else if (*op->u.prox->exclusion)
+ wrbuf_putc(b, '1');
+ else
+ wrbuf_putc(b, '0');
+
+ wrbuf_printf(b, " %d %d %d ", *op->u.prox->distance,
+ *op->u.prox->ordered,
+ *op->u.prox->relationType);
+
+ switch(op->u.prox->which)
+ {
+ case Z_ProximityOperator_known:
+ wrbuf_putc(b, 'k');
+ break;
+ case Z_ProximityOperator_private:
+ wrbuf_putc(b, 'p');
+ break;
+ default:
+ wrbuf_printf(b, "%d", op->u.prox->which);
+ }
+ if (op->u.prox->u.known)
+ wrbuf_printf(b, " %d ", *op->u.prox->u.known);
+ else
+ wrbuf_printf(b, " 0 ");
+ }
+ wrbuf_structure (b,zs->u.complex->s1, ast);
+ wrbuf_structure (b,zs->u.complex->s2, ast);
+ }
+ else if (zs->which == Z_RPNStructure_simple)
+ {
+ if (zs->u.simple->which == Z_Operand_APT)
+ wrbuf_apt(b, zs->u.simple->u.attributesPlusTerm);
+ else if (zs->u.simple->which == Z_Operand_resultSetId)
+ {
+ wrbuf_printf(b, "@set ");
+ wrbuf_term(b, zs->u.simple->u.resultSetId,
+ strlen(zs->u.simple->u.resultSetId));
+ }
+ else
+ wrbuf_printf (b, "(unknown simple structure)");
+ }
+ else
+ wrbuf_puts(b, "(unknown structure)");
+}
+
+void log_rpn_query_level (int loglevel, Z_RPNQuery *rpn)