int i;
const char *ns = cn->u.st.index_uri;
int process_term = !has_modifier(cn, "regexp");
- char *z3958_mem = 0;
+ int z3958_mode = 0;
assert(cn->which == CQL_NODE_ST);
}
else if (first_wc)
{
- /* We have one or more wildcard characters, but not in a
- * way that can be dealt with using only the standard
- * left-, right- and both-truncation attributes. We need
- * to translate the pattern into a Z39.58-type pattern,
- * which has been supported in BIB-1 since 1996. If
- * there's no configuration element for "truncation.z3958"
- * we indicate this as error 28 "Masking character not
- * supported".
- */
- int i;
+ z3958_mode = 1;
cql_pr_attr(ct, "truncation", "z3958", 0,
pr, client_data, YAZ_SRW_MASKING_CHAR_UNSUPP);
- z3958_mem = (char *) xmalloc(length+1);
- for (i = 0; i < length; i++)
- {
- if (i > 0 && term[i-1] == '\\')
- z3958_mem[i] = term[i];
- else if (term[i] == '*')
- z3958_mem[i] = '?';
- else if (term[i] == '?')
- z3958_mem[i] = '#';
- else
- z3958_mem[i] = term[i];
- }
- z3958_mem[length] = '\0';
- term = z3958_mem;
}
- else {
+ else
+ {
/* No masking characters. Use "truncation.none" if given. */
cql_pr_attr(ct, "truncation", "none", 0,
pr, client_data, 0);
}
}
+ /* produce only \-sequences if:
+ 1) the output is a Z39.58-trunc reserved character
+ 2) the output is a PQF reserved character (\\, \")
+ */
(*pr)("\"", client_data);
for (i = 0; i < length; i++)
{
- /* pr(int) each character */
- /* we do not need to deal with \-sequences because the
- CQL and PQF terms have same \-format, bug #1988 */
- char buf[2];
-
- buf[0] = term[i];
- buf[1] = '\0';
- (*pr)(buf, client_data);
+ char x[3]; /* temp buffer */
+ if (i > 0 && term[i-1] == '\\')
+ {
+ if (term[i] == '\"' || term[i] == '\\')
+ pr("\\", client_data);
+ if (z3958_mode && strchr("#?", term[i]))
+ pr("\\\\", client_data); /* double \\ to survive PQF parse */
+ x[0] = term[i];
+ x[1] = '\0';
+ pr(x, client_data);
+ }
+ else if (z3958_mode && term[i] == '*')
+ {
+ pr("?", client_data);
+ /* avoid ?n sequences output (n=[0-9]) because that has
+ different semantics than just a single ? in Z39.58
+ */
+ if (i < length - 1 && yaz_isdigit(term[i+1]))
+ pr("\\\\", client_data); /* double \\ to survive PQF parse */
+ }
+ else if (z3958_mode && term[i] == '?')
+ pr("#", client_data);
+ else if (term[i] != '\\')
+ {
+ if (term[i] == '\"')
+ pr("\\", client_data);
+ if (z3958_mode && strchr("#?", term[i]))
+ pr("\\\\", client_data); /* double \\ to survive PQF parse */
+ x[0] = term[i];
+ x[1] = '\0';
+ pr(x, client_data);
+ }
}
(*pr)("\" ", client_data);
- xfree(z3958_mem);
}
static void emit_terms(cql_transform_t ct,
+Parsing CQL a
@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "a"
+Parsing CQL a b
@attr 6=1 @attr 2=3 @attr 4=1 @and @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "a" @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "b"
+Parsing CQL "a b"
@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "a b"
+Parsing CQL title = fish
@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=4 "fish"
+Parsing CQL dc.title = fish
@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=4 "fish"
+Parsing CQL cat or dog
@or @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "cat" @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "dog"
+Parsing CQL cat and fish
@and @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "cat" @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "fish"
+Parsing CQL cat not frog
@not @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "cat" @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "frog"
+Parsing CQL (cat not frog)
@not @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "cat" @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "frog"
+Parsing CQL "cat" not "fish food"
@not @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "cat" @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "fish food"
+Parsing CQL xml and "prox///"
@and @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "xml" @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "prox///"
+Parsing CQL fred and any
@and @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "fred" @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "any"
+Parsing CQL ((fred or all))
@or @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "fred" @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "all"
+Parsing CQL a or b and c not d
@not @and @or @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "a" @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "b" @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "c" @attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "d"
--- /dev/null
+Parsing CQL *a
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=2 @attr 1=1016 "a"
--- /dev/null
+Parsing CQL *a#
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=2 @attr 1=1016 "a#"
--- /dev/null
+Parsing CQL a#a*
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=1 @attr 1=1016 "a#a"
--- /dev/null
+Parsing CQL a*3
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=104 @attr 1=1016 "a?\\3"
--- /dev/null
+Parsing CQL a*
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=1 @attr 1=1016 "a"
--- /dev/null
+Parsing CQL *a*
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=3 @attr 1=1016 "a"
--- /dev/null
+Parsing CQL a*a
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=104 @attr 1=1016 "a?a"
--- /dev/null
+Parsing CQL ?a
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=104 @attr 1=1016 "#a"
--- /dev/null
+Parsing CQL a?
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=104 @attr 1=1016 "a#"
--- /dev/null
+Parsing CQL ?a?
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=104 @attr 1=1016 "#a#"
--- /dev/null
+Parsing CQL a?a
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=104 @attr 1=1016 "a#a"
--- /dev/null
+Parsing CQL a#a?
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=104 @attr 1=1016 "a\\#a#"
--- /dev/null
+Parsing CQL a*\3
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=104 @attr 1=1016 "a?3"
--- /dev/null
+Parsing CQL \*a#
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "*a#"
--- /dev/null
+Parsing CQL \*a*b#
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=104 @attr 1=1016 "*a?b\\#"
--- /dev/null
+Parsing CQL \"
+@attr 6=1 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "\""
# CQL queries for testing.
-# from http://www.loc.gov/z3950/agency/zing/cql/sample-queries.html
+# Read by test_cql2pqf.sh
+# No blank lines!
+#
# Simple Term
-
a
a b
"a b"
-
# Index Relation Term
-
title = fish
dc.title = fish
-
# Simple Boolean
-
cat or dog
cat and fish
cat not frog
fred and any
((fred or all))
a or b and c not d
-
+# Masking/Truncation
+*a
+a*
+*a*
+a*a
+?a
+a?
+?a?
+a?a
+a#a?
+*a#
+a#a*
+a*3
+# Escape sequences (sh reads one slash, though)
+a*\\3
+\\*a#
+\\*a*b#
+\\"
ecode=0
test -f ${srcdir}/cql2pqfsample || exit 1
test -d cql2pqf || mkdir cql2pqf
-for f in `cat ${srcdir}/cql2pqfsample`; do
+while read f; do
if echo $f | grep '^#' >/dev/null; then
comment=1
else
OUT2=cql2pqf/$secno.$testno.out.tmp
ERR2=cql2pqf/$secno.$testno.err.tmp
DIFF=cql2pqf/$secno.$testno.diff
- ../util/cql2pqf ${srcdir}/../etc/pqf.properties "$f" >$OUT2 2>$ERR2
+ ../util/cql2pqf -v ${srcdir}/../etc/pqf.properties "$f" >$OUT2 2>$ERR2
if test -f $OUT1 -a -f $ERR1; then
if diff $OUT1 $OUT2 >$DIFF; then
rm $DIFF
ecode=1
fi
fi
-done
+done < cql2pqfsample
IFS="$oIFS"
exit $ecode
char *query = 0;
char *fname = 0;
int reverse = 0;
+ int verbose = 1;
int ret;
char *arg;
- while ((ret = options("n:r", argv, argc, &arg)) != -2)
+ while ((ret = options("n:rv", argv, argc, &arg)) != -2)
{
switch (ret)
{
else
query = arg;
break;
+ case 'n':
+ iterations = atoi(arg);
+ break;
case 'r':
reverse = 1;
break;
- case 'n':
- iterations = atoi(arg);
+ case 'v':
+ verbose = 1;
break;
default:
usage();
if (query)
{
+ if (verbose)
+ printf("Parsing CQL %s\n", query);
for (i = 0; i<iterations; i++)
r = cql_parser_string(cp, query);
}