From 4aee8993113119c95924d9be4ed2707d5034348c Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Sat, 25 Oct 2008 22:08:47 +0200 Subject: [PATCH] Added yaz_encode_pqf_term to encode PQF strings. Added yaz_encode_pqf_term to encode PQF strings. This function is used by yaz_rpnquery_to_wrbuf and CCL to PQF conversion utilities (ccl_pquery, ccl_pr_tree). --- include/yaz/querytowrbuf.h | 1 + src/cclptree.c | 15 ++------------- src/querytowrbuf.c | 16 ++++++++-------- test/tstccl.c | 4 ++-- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/include/yaz/querytowrbuf.h b/include/yaz/querytowrbuf.h index 000787b..7a08880 100644 --- a/include/yaz/querytowrbuf.h +++ b/include/yaz/querytowrbuf.h @@ -44,6 +44,7 @@ YAZ_EXPORT void yaz_scan_to_wrbuf(WRBUF b, const Z_AttributesPlusTerm *zapt, YAZ_EXPORT void yaz_rpnquery_to_wrbuf(WRBUF b, const Z_RPNQuery *rpn); YAZ_EXPORT void wrbuf_diags(WRBUF b, int num_diagnostics,Z_DiagRec **diags); +YAZ_EXPORT void yaz_encode_pqf_term(WRBUF b, const char *term, int len); YAZ_END_CDECL #endif diff --git a/src/cclptree.c b/src/cclptree.c index 55d8ef8..7e38624 100644 --- a/src/cclptree.c +++ b/src/cclptree.c @@ -14,6 +14,7 @@ #include #include +#include #include static void ccl_pquery_indent(WRBUF w, struct ccl_rpn_node *p, int indent); @@ -68,19 +69,7 @@ static void ccl_pquery_complex(WRBUF w, struct ccl_rpn_node *p, int indent) static void ccl_prterm(WRBUF w, const char *term) { - if (!*term) - wrbuf_puts(w, "\"\""); - else - { - const char *cp = term; - for (; *cp; cp++) - { - if (*cp == ' ' || *cp == '\\') - wrbuf_putc(w, '\\'); - wrbuf_putc(w, *cp); - } - } - wrbuf_puts(w, " "); + yaz_encode_pqf_term(w, term, strlen(term)); } static void ccl_pquery_indent(WRBUF w, struct ccl_rpn_node *p, int indent) diff --git a/src/querytowrbuf.c b/src/querytowrbuf.c index 3a0847a..a120e88 100644 --- a/src/querytowrbuf.c +++ b/src/querytowrbuf.c @@ -4,7 +4,7 @@ */ /** \file querytowrbuf.c - \brief Query to WRBUF (to strings) + \brief Convert Z39.50 Z_Query to PQF (as WRBUF string) */ #include @@ -14,7 +14,7 @@ #include #include -static void yaz_term_to_wrbuf(WRBUF b, const char *term, int len) +void yaz_encode_pqf_term(WRBUF b, const char *term, int len) { int i; for (i = 0; i < len; i++) @@ -108,13 +108,13 @@ static void yaz_apt_to_wrbuf(WRBUF b, const Z_AttributesPlusTerm *zapt) switch (zapt->term->which) { case Z_Term_general: - yaz_term_to_wrbuf(b, (const char *)zapt->term->u.general->buf, - zapt->term->u.general->len); + yaz_encode_pqf_term(b, (const char *)zapt->term->u.general->buf, + zapt->term->u.general->len); break; case Z_Term_characterString: wrbuf_printf(b, "@term string "); - yaz_term_to_wrbuf(b, zapt->term->u.characterString, - strlen(zapt->term->u.characterString)); + yaz_encode_pqf_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); @@ -172,8 +172,8 @@ static void yaz_rpnstructure_to_wrbuf(WRBUF b, const Z_RPNStructure *zs) else if (zs->u.simple->which == Z_Operand_resultSetId) { wrbuf_printf(b, "@set "); - yaz_term_to_wrbuf(b, zs->u.simple->u.resultSetId, - strlen(zs->u.simple->u.resultSetId)); + yaz_encode_pqf_term(b, zs->u.simple->u.resultSetId, + strlen(zs->u.simple->u.resultSetId)); } else wrbuf_printf (b, "(unknown simple structure)"); diff --git a/test/tstccl.c b/test/tstccl.c index daf2fb6..d8252b0 100644 --- a/test/tstccl.c +++ b/test/tstccl.c @@ -194,9 +194,9 @@ void tst1(int pass) YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990", "@attr 2=3 234-1990 ")); YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 ")); YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b", "@attr 4=1 @attr 1=4 a,b ")); - YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b", "@attr 4=1 @attr 1=4 a,\\ b ")); + YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b", "@attr 4=1 @attr 1=4 \"a, b\" ")); YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b", "@attr 4=2 @attr 1=4 a-b ")); - YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b", "@attr 4=1 @attr 1=4 a\\ -\\ b ")); + YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b", "@attr 4=1 @attr 1=4 \"a - b\" ")); ccl_qual_rm(&bibset); } -- 1.7.10.4