projects
/
yaz-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Minor refactor in tcpip code
[yaz-moved-to-github.git]
/
src
/
cql2ccl.c
diff --git
a/src/cql2ccl.c
b/src/cql2ccl.c
index
99c90c4
..
d08536f
100644
(file)
--- a/
src/cql2ccl.c
+++ b/
src/cql2ccl.c
@@
-1,5
+1,5
@@
/* This file is part of the YAZ toolkit.
/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2011 Index Data
+ * Copyright (C) Index Data
* See the file LICENSE for details.
*/
/**
* See the file LICENSE for details.
*/
/**
@@
-16,80
+16,74
@@
#include <yaz/cql.h>
#include <yaz/cql.h>
-static int cql_to_ccl_r(struct cql_node *cn,
+static int cql_to_ccl_r(struct cql_node *cn,
void (*pr)(const char *buf, void *client_data),
void *client_data);
void (*pr)(const char *buf, void *client_data),
void *client_data);
-static void pr_term(struct cql_node *cn,
+static void pr_term(const char **cpp, int stop_at_space,
void (*pr)(const char *buf, void *client_data),
void *client_data)
{
void (*pr)(const char *buf, void *client_data),
void *client_data)
{
- while (cn)
+ const char *cp;
+ int quote_mode = 0;
+ for (cp = *cpp; *cp; cp++)
{
{
- if (! *cn->u.st.term) /* empty term special case */
- pr("\"\"", client_data);
- else
+ char x[4];
+
+ if (*cp == '\\' && cp[1])
{
{
- const char *cp;
- int quote_mode = 0;
- for (cp = cn->u.st.term; *cp; cp++)
+ if (!quote_mode)
{
{
- char x[4];
-
- if (*cp == '\\' && cp[1])
- {
- if (!quote_mode)
- {
- pr("\"", client_data);
- quote_mode = 1;
- }
- cp++;
- if (*cp == '\"' || *cp == '\\')
- pr("\\", client_data);
- x[0] = *cp;
- x[1] = '\0';
- pr(x, client_data);
- }
- else if (*cp == '*')
- {
- if (quote_mode)
- {
- pr("\"", client_data);
- quote_mode = 0;
- }
- pr("?", client_data);
- }
- else if (*cp == '?')
- {
- if (quote_mode)
- {
- pr("\"", client_data);
- quote_mode = 0;
- }
- pr("#", client_data);
- }
- else
- {
- if (!quote_mode)
- {
- pr("\"", client_data);
- quote_mode = 1;
- }
- x[0] = *cp;
- x[1] = '\0';
- pr(x, client_data);
- }
+ pr("\"", client_data);
+ quote_mode = 1;
+ }
+ cp++;
+ if (*cp == '\"' || *cp == '\\')
+ pr("\\", client_data);
+ x[0] = *cp;
+ x[1] = '\0';
+ pr(x, client_data);
+ }
+ else if (*cp == '*')
+ {
+ if (quote_mode)
+ {
+ pr("\"", client_data);
+ quote_mode = 0;
}
}
+ pr("?", client_data);
+ }
+ else if (*cp == '?')
+ {
if (quote_mode)
if (quote_mode)
+ {
pr("\"", client_data);
pr("\"", client_data);
+ quote_mode = 0;
+ }
+ pr("#", client_data);
+ }
+ else if (*cp == ' ' && stop_at_space)
+ break;
+ else
+ {
+ if (!quote_mode)
+ {
+ pr("\"", client_data);
+ quote_mode = 1;
+ }
+ x[0] = *cp;
+ x[1] = '\0';
+ pr(x, client_data);
}
}
- if (cn->u.st.extra_terms)
- pr(" ", client_data);
- cn = cn->u.st.extra_terms;
}
}
+ if (quote_mode)
+ pr("\"", client_data);
+ if (cp == *cpp)
+ pr("\"\"", client_data);
+ *cpp = cp;
}
}
-static int node(struct cql_node *cn,
+static int node(struct cql_node *cn,
void (*pr)(const char *buf, void *client_data),
void *client_data)
{
void (*pr)(const char *buf, void *client_data),
void *client_data)
{
@@
-127,53
+121,45
@@
static int node(struct cql_node *cn,
/* unsupported relation */
return -1;
}
/* unsupported relation */
return -1;
}
- if (!split_op)
- {
- if (ccl_field && ccl_rel)
- {
- pr(ccl_field, client_data);
- pr(ccl_rel, client_data);
- }
- pr_term(cn, pr, client_data);
- }
- else
+ for (; cn; cn = cn->u.st.extra_terms)
{
const char *cp = cn->u.st.term;
{
const char *cp = cn->u.st.term;
-
while (1)
{
while (1)
{
- if (*cp == '\0')
- break;
if (ccl_field && ccl_rel)
{
pr(ccl_field, client_data);
pr(ccl_rel, client_data);
if (ccl_field && ccl_rel)
{
pr(ccl_field, client_data);
pr(ccl_rel, client_data);
+ if (!split_op)
+ ccl_rel = 0;
}
}
- while (*cp && *cp != ' ')
- {
- char x[2];
- if (*cp == '*')
- x[0] = '?';
- else
- x[0] = *cp;
- x[1] = '\0';
- pr(x, client_data);
- cp++;
- }
+ pr_term(&cp, split_op ? 1 : 0, pr, client_data);
while (*cp == ' ')
cp++;
if (*cp == '\0')
break;
pr(" ", client_data);
while (*cp == ' ')
cp++;
if (*cp == '\0')
break;
pr(" ", client_data);
- pr(split_op, client_data);
- pr(" ", client_data);
+ if (split_op)
+ {
+ pr(split_op, client_data);
+ pr(" ", client_data);
+ }
+ }
+ if (cn->u.st.extra_terms)
+ {
+ pr(" ", client_data);
+ if (split_op)
+ {
+ pr(split_op, client_data);
+ pr(" ", client_data);
+ }
}
}
return 0;
}
}
}
return 0;
}
-static int bool(struct cql_node *cn,
+static int bool(struct cql_node *cn,
void (*pr)(const char *buf, void *client_data),
void *client_data)
{
void (*pr)(const char *buf, void *client_data),
void *client_data)
{
@@
-184,8
+170,8
@@
static int bool(struct cql_node *cn,
r = cql_to_ccl_r(cn->u.boolean.left, pr, client_data);
if (r)
return r;
r = cql_to_ccl_r(cn->u.boolean.left, pr, client_data);
if (r)
return r;
-
- pr(" ", client_data);
+
+ pr(") ", client_data);
if (strcmp(value, "prox"))
{ /* not proximity. assuming boolean */
if (strcmp(value, "prox"))
{ /* not proximity. assuming boolean */
@@
-234,14
+220,14
@@
static int bool(struct cql_node *cn,
pr(x, client_data);
}
}
pr(x, client_data);
}
}
- pr(" ", client_data);
+ pr(" (", client_data);
r = cql_to_ccl_r(cn->u.boolean.right, pr, client_data);
pr(")", client_data);
return r;
}
r = cql_to_ccl_r(cn->u.boolean.right, pr, client_data);
pr(")", client_data);
return r;
}
-static int cql_to_ccl_r(struct cql_node *cn,
+static int cql_to_ccl_r(struct cql_node *cn,
void (*pr)(const char *buf, void *client_data),
void *client_data)
{
void (*pr)(const char *buf, void *client_data),
void *client_data)
{
@@
-260,7
+246,7
@@
static int cql_to_ccl_r(struct cql_node *cn,
return -1;
}
return -1;
}
-int cql_to_ccl(struct cql_node *cn,
+int cql_to_ccl(struct cql_node *cn,
void (*pr)(const char *buf, void *client_data),
void *client_data)
{
void (*pr)(const char *buf, void *client_data),
void *client_data)
{