/* CCL print rpn tree - infix notation
* Europagate, 1995
*
- * $Id: cclptree.c,v 1.13 2003-06-23 10:22:21 adam Exp $
+ * $Id: cclptree.c,v 1.14 2003-06-24 23:03:04 adam Exp $
*
* Old Europagate Log:
*
}
+static void ccl_pquery_complex (WRBUF w, struct ccl_rpn_node *p)
+{
+ switch (p->kind)
+ {
+ case CCL_RPN_AND:
+ wrbuf_puts(w, "@and ");
+ break;
+ case CCL_RPN_OR:
+ wrbuf_puts(w, "@or ");
+ break;
+ case CCL_RPN_NOT:
+ wrbuf_puts(w, "@not ");
+ break;
+ case CCL_RPN_PROX:
+ if (p->u.p[2] && p->u.p[2]->kind == CCL_RPN_TERM)
+ {
+ const char *cp = p->u.p[2]->u.t.term;
+ /* exlusion distance ordered relation which-code unit-code */
+ if (*cp == '!')
+ {
+ /* word order specified */
+ if (isdigit(cp[1]))
+ wrbuf_printf(w, "@prox 0 %s 1 2 k 2 ", cp+1);
+ else
+ wrbuf_printf(w, "@prox 0 1 1 2 k 2 ");
+ }
+ else if (*cp == '%')
+ {
+ /* word order not specified */
+ if (isdigit(cp[1]))
+ wrbuf_printf(w, "@prox 0 %s 0 2 k 2 ", cp+1);
+ else
+ wrbuf_printf(w, "@prox 0 1 0 2 k 2 ");
+ }
+ }
+ else
+ wrbuf_puts(w, "@prox 0 2 0 1 k 2 ");
+ break;
+ default:
+ wrbuf_puts(w, "@ bad op (unknown) ");
+ }
+ ccl_pquery(w, p->u.p[0]);
+ ccl_pquery(w, p->u.p[1]);
+}
+
+void ccl_pquery (WRBUF w, struct ccl_rpn_node *p)
+{
+ struct ccl_rpn_attr *att;
+ const char *cp;
+
+ switch (p->kind)
+ {
+ case CCL_RPN_AND:
+ case CCL_RPN_OR:
+ case CCL_RPN_NOT:
+ case CCL_RPN_PROX:
+ ccl_pquery_complex (w, p);
+ break;
+ case CCL_RPN_SET:
+ wrbuf_puts (w, "@set ");
+ wrbuf_puts (w, p->u.setname);
+ wrbuf_puts (w, " ");
+ break;
+ case CCL_RPN_TERM:
+ for (att = p->u.t.attr_list; att; att = att->next)
+ {
+ char tmpattr[128];
+ wrbuf_puts (w, "@attr ");
+ if (att->set)
+ {
+ wrbuf_puts (w, att->set);
+ wrbuf_puts (w, " ");
+ }
+ switch(att->kind)
+ {
+ case CCL_RPN_ATTR_NUMERIC:
+ sprintf(tmpattr, "%d=%d ", att->type, att->value.numeric);
+ wrbuf_puts (w, tmpattr);
+ break;
+ case CCL_RPN_ATTR_STRING:
+ sprintf(tmpattr, "%d=", att->type);
+ wrbuf_puts (w, tmpattr);
+ wrbuf_puts(w, att->value.str);
+ wrbuf_puts (w, " ");
+ break;
+ }
+ }
+ for (cp = p->u.t.term; *cp; cp++)
+ {
+ if (*cp == ' ' || *cp == '\\')
+ wrbuf_putc (w, '\\');
+ wrbuf_putc (w, *cp);
+ }
+ wrbuf_puts (w, " ");
+ break;
+ }
+}
+
/*
* Local variables:
* tab-width: 4
* Copyright (c) 2002-2003, Index Data
* See the file LICENSE for details.
*
- * $Id: tstccl.c,v 1.1 2003-06-23 10:22:21 adam Exp $
+ * $Id: tstccl.c,v 1.2 2003-06-24 23:03:04 adam Exp $
*/
/* CCL test */
#include <yaz/ccl.h>
-static char *query_str[] = {
- "x1",
- "x1 and x2",
- "ti=x3",
- "dc.title=x4",
- 0
+struct ccl_tst {
+ char *query;
+ char *result;
+};
+
+static struct ccl_tst query_str[] = {
+ { "x1", "@attr 4=2 @attr 1=1016 x1 "},
+ { "(((((x1)))))", "@attr 4=2 @attr 1=1016 x1 "},
+ {"x1 and x2", "@and @attr 4=2 @attr 1=1016 x1 @attr 4=2 @attr 1=1016 x2 "},
+ { "ti=x3", "@attr 4=2 @attr 1=4 x3 "},
+ { "dc.title=x4", "@attr 1=/my/title x4 "},
+ { "x1 and", 0},
+ { "tix=x5", 0},
+ {0, 0}
};
void tst1(void)
parser->bibset = bibset;
- for (i = 0; query_str[i]; i++)
+ for (i = 0; query_str[i].query; i++)
{
struct ccl_token *token_list =
- ccl_parser_tokenize(parser, query_str[i]);
+ ccl_parser_tokenize(parser, query_str[i].query);
struct ccl_rpn_node *rpn = ccl_parser_find(parser, token_list);
ccl_token_del (token_list);
if (rpn)
{
+ WRBUF wrbuf = wrbuf_alloc();
+ ccl_pquery(wrbuf, rpn);
+
+ if (!query_str[i].result)
+ {
+ printf ("Failed %s\n", query_str[i].query);
+ printf (" got:%s:\n", wrbuf_buf(wrbuf));
+ printf (" expected failure\n");
+ exit(3);
+ }
+ else if (strcmp(wrbuf_buf(wrbuf), query_str[i].result))
+ {
+ printf ("Failed %s\n", query_str[i].query);
+ printf (" got:%s:\n", wrbuf_buf(wrbuf));
+ printf (" expected:%s:\n", query_str[i].result);
+ exit(2);
+ }
ccl_rpn_delete(rpn);
+ wrbuf_free(wrbuf, 1);
}
- else
+ else if (query_str[i].result)
{
- printf ("failed %s\n", query_str[i]);
- exit(1+i);
+ printf ("Failed %s\n", query_str[i].query);
+ printf (" got failure\n");
+ printf (" expected:%s:\n", query_str[i].result);
+ exit(4);
}
}
ccl_parser_destroy (parser);
/*
* CCL - header file
*
- * $Id: ccl.h,v 1.14 2003-06-23 10:22:21 adam Exp $
+ * $Id: ccl.h,v 1.15 2003-06-24 23:03:04 adam Exp $
*
* Old Europagate Log:
*
#include <yaz/yconfig.h>
#include <stdio.h>
#include <yaz/xmalloc.h>
+#include <yaz/wrbuf.h>
YAZ_BEGIN_CDECL
YAZ_EXPORT const char *ccl_qual_search_special (CCL_bibset b,
const char *name);
+YAZ_EXPORT void ccl_pquery (WRBUF w, struct ccl_rpn_node *p);
+
#ifndef ccl_assert
#define ccl_assert(x) ;
#endif
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*
- * $Id: yaz-ccl.h,v 1.5 2003-03-03 19:57:35 adam Exp $
+ * $Id: yaz-ccl.h,v 1.6 2003-06-24 23:03:04 adam Exp $
*/
#ifndef YAZ_CCL_H
#include <yaz/proto.h>
#include <yaz/ccl.h>
#include <yaz/odr.h>
-#include <yaz/wrbuf.h>
YAZ_BEGIN_CDECL
YAZ_EXPORT Z_RPNQuery *ccl_rpn_query (ODR o, struct ccl_rpn_node *p);
YAZ_EXPORT Z_AttributesPlusTerm *ccl_scan_query (ODR o, struct ccl_rpn_node *p);
-YAZ_EXPORT void ccl_pquery (WRBUF w, struct ccl_rpn_node *p);
-
YAZ_END_CDECL
#endif
* Copyright (c) 1996-2003, Index Data.
* See the file LICENSE for details.
*
- * $Id: yaz-ccl.c,v 1.22 2003-06-23 12:41:44 adam Exp $
+ * $Id: yaz-ccl.c,v 1.23 2003-06-24 23:03:04 adam Exp $
*/
#include <stdio.h>
return q;
}
-static void ccl_pquery_complex (WRBUF w, struct ccl_rpn_node *p)
-{
- switch (p->kind)
- {
- case CCL_RPN_AND:
- wrbuf_puts(w, "@and ");
- break;
- case CCL_RPN_OR:
- wrbuf_puts(w, "@or ");
- break;
- case CCL_RPN_NOT:
- wrbuf_puts(w, "@not ");
- break;
- case CCL_RPN_PROX:
- if (p->u.p[2] && p->u.p[2]->kind == CCL_RPN_TERM)
- {
- const char *cp = p->u.p[2]->u.t.term;
- /* exlusion distance ordered relation which-code unit-code */
- if (*cp == '!')
- {
- /* word order specified */
- if (isdigit(cp[1]))
- wrbuf_printf(w, "@prox 0 %s 1 2 k 2 ", cp+1);
- else
- wrbuf_printf(w, "@prox 0 1 1 2 k 2 ");
- }
- else if (*cp == '%')
- {
- /* word order not specified */
- if (isdigit(cp[1]))
- wrbuf_printf(w, "@prox 0 %s 0 2 k 2 ", cp+1);
- else
- wrbuf_printf(w, "@prox 0 1 0 2 k 2 ");
- }
- }
- else
- wrbuf_puts(w, "@prox 0 2 0 1 k 2 ");
- break;
- default:
- wrbuf_puts(w, "@ bad op (unknown) ");
- };
- ccl_pquery(w, p->u.p[0]);
- ccl_pquery(w, p->u.p[1]);
-}
-
-void ccl_pquery (WRBUF w, struct ccl_rpn_node *p)
-{
- struct ccl_rpn_attr *att;
- const char *cp;
-
- switch (p->kind)
- {
- case CCL_RPN_AND:
- case CCL_RPN_OR:
- case CCL_RPN_NOT:
- case CCL_RPN_PROX:
- ccl_pquery_complex (w, p);
- break;
- case CCL_RPN_SET:
- wrbuf_puts (w, "@set ");
- wrbuf_puts (w, p->u.setname);
- wrbuf_puts (w, " ");
- break;
- case CCL_RPN_TERM:
- for (att = p->u.t.attr_list; att; att = att->next)
- {
- char tmpattr[128];
- wrbuf_puts (w, "@attr ");
- if (att->set)
- {
- wrbuf_puts (w, att->set);
- wrbuf_puts (w, " ");
- }
- switch(att->kind)
- {
- case CCL_RPN_ATTR_NUMERIC:
- sprintf(tmpattr, "%d=%d ", att->type, att->value.numeric);
- wrbuf_puts (w, tmpattr);
- break;
- case CCL_RPN_ATTR_STRING:
- sprintf(tmpattr, "%d=", att->type);
- wrbuf_puts (w, tmpattr);
- wrbuf_puts(w, att->value.str);
- wrbuf_puts (w, " ");
- break;
- }
- }
- for (cp = p->u.t.term; *cp; cp++)
- {
- if (*cp == ' ' || *cp == '\\')
- wrbuf_putc (w, '\\');
- wrbuf_putc (w, *cp);
- }
- wrbuf_puts (w, " ");
- break;
- }
-}