1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2008 Index Data
3 * See the file LICENSE for details.
7 * \brief Implements CCL parse tree printing
9 * This source file implements functions to parse and print
10 * a CCL node tree (as a result of parsing).
19 static void ccl_pquery_indent(WRBUF w, struct ccl_rpn_node *p, int indent);
21 static void ccl_pquery_complex(WRBUF w, struct ccl_rpn_node *p, int indent)
23 int sep_char = indent == -1 ? ' ' : '\n';
24 int next_indent = indent == -1 ? indent : indent+1;
28 wrbuf_puts(w, "@and");
34 wrbuf_puts(w, "@not");
37 if (p->u.p[2] && p->u.p[2]->kind == CCL_RPN_TERM)
39 const char *cp = p->u.p[2]->u.t.term;
40 /* exlusion distance ordered relation which-code unit-code */
43 /* word order specified */
44 if (isdigit(((const unsigned char *) cp)[1]))
45 wrbuf_printf(w, "@prox 0 %s 1 2 k 2", cp+1);
47 wrbuf_printf(w, "@prox 0 1 1 2 k 2");
51 /* word order not specified */
52 if (isdigit(((const unsigned char *) cp)[1]))
53 wrbuf_printf(w, "@prox 0 %s 0 2 k 2", cp+1);
55 wrbuf_printf(w, "@prox 0 1 0 2 k 2");
59 wrbuf_puts(w, "@prox 0 2 0 1 k 2");
62 wrbuf_puts(w, "@ bad op (unknown)");
64 wrbuf_putc(w, sep_char);
65 ccl_pquery_indent(w, p->u.p[0], next_indent);
66 ccl_pquery_indent(w, p->u.p[1], next_indent);
69 static void ccl_prterm(WRBUF w, const char *term)
72 wrbuf_puts(w, "\"\"");
75 const char *cp = term;
78 if (*cp == ' ' || *cp == '\\')
86 static void ccl_pquery_indent(WRBUF w, struct ccl_rpn_node *p, int indent)
88 struct ccl_rpn_attr *att;
95 for (i = 0; i < indent; i++)
104 ccl_pquery_complex(w, p, indent);
107 wrbuf_puts(w, "@set ");
108 ccl_prterm(w, p->u.setname);
113 for (att = p->u.t.attr_list; att; att = att->next)
116 wrbuf_puts(w, "@attr ");
119 wrbuf_puts(w, att->set);
124 case CCL_RPN_ATTR_NUMERIC:
125 sprintf(tmpattr, "%d=%d ", att->type, att->value.numeric);
126 wrbuf_puts(w, tmpattr);
128 case CCL_RPN_ATTR_STRING:
129 sprintf(tmpattr, "%d=", att->type);
130 wrbuf_puts(w, tmpattr);
131 wrbuf_puts(w, att->value.str);
136 ccl_prterm(w, p->u.t.term);
143 void ccl_pquery(WRBUF w, struct ccl_rpn_node *p)
145 ccl_pquery_indent(w, p, -1);
148 void ccl_pr_tree(struct ccl_rpn_node *rpn, FILE *fd_out)
150 WRBUF w = wrbuf_alloc();
152 ccl_pquery_indent(w, rpn, 0);
154 fputs(wrbuf_cstr(w), fd_out);
161 * indent-tabs-mode: nil
163 * vim: shiftwidth=4 tabstop=8 expandtab