X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fcqlutil.c;h=ba477de410a000f1e07f8544bc2e4ef00fcca0ee;hp=836d8407e52abcdf376febe8a3e84c11a45b5caf;hb=176adcd5ec7f2340fb6f0f625a727498db9c04c4;hpb=783114bd4cf6e26e1743ce131d3e7f00af63ec50 diff --git a/src/cqlutil.c b/src/cqlutil.c index 836d840..ba477de 100644 --- a/src/cqlutil.c +++ b/src/cqlutil.c @@ -1,16 +1,14 @@ -/* $Id: cqlutil.c,v 1.12 2008-01-06 13:08:09 adam Exp $ - Copyright (C) 1995-2007, Index Data ApS - Index Data Aps - -This file is part of the YAZ toolkit. - -See the file LICENSE for details. -*/ - +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2013 Index Data + * See the file LICENSE for details. + */ /** * \file cqlutil.c * \brief Implements CQL tree node utilities. */ +#if HAVE_CONFIG_H +#include +#endif #include #include @@ -23,7 +21,7 @@ void cql_fputs(const char *buf, void *client_data) fputs(buf, f); } -struct cql_node *cql_node_dup (NMEM nmem, struct cql_node *cp) +struct cql_node *cql_node_dup(NMEM nmem, struct cql_node *cp) { struct cql_node *cn = 0; @@ -36,7 +34,7 @@ struct cql_node *cql_node_dup (NMEM nmem, struct cql_node *cp) cp->u.st.relation, cp->u.st.term); cn->u.st.modifiers = cql_node_dup(nmem, cp->u.st.modifiers); - cn->u.st.index_uri = cp->u.st.index_uri ? + cn->u.st.index_uri = cp->u.st.index_uri ? nmem_strdup(nmem, cp->u.st.index_uri) : 0; cn->u.st.relation_uri = cp->u.st.relation_uri ? nmem_strdup(nmem, cp->u.st.relation_uri) : 0; @@ -45,6 +43,11 @@ struct cql_node *cql_node_dup (NMEM nmem, struct cql_node *cp) cn = cql_node_mk_boolean(nmem, cp->u.boolean.value); cn->u.boolean.left = cql_node_dup(nmem, cp->u.boolean.left); cn->u.boolean.right = cql_node_dup(nmem, cp->u.boolean.right); + break; + case CQL_NODE_SORT: + cn = cql_node_mk_sort(nmem, cp->u.sort.index, cp->u.sort.modifiers); + cn->u.sort.next = cql_node_dup(nmem, cp->u.sort.next); + cn->u.sort.search = cql_node_dup(nmem, cp->u.sort.search); } return cn; } @@ -68,6 +71,7 @@ struct cql_node *cql_node_mk_sc(NMEM nmem, p->u.st.relation = nmem_strdup(nmem, relation); p->u.st.relation_uri = 0; p->u.st.modifiers = 0; + p->u.st.extra_terms = 0; return p; } @@ -84,6 +88,20 @@ struct cql_node *cql_node_mk_boolean(NMEM nmem, const char *op) return p; } +struct cql_node *cql_node_mk_sort(NMEM nmem, const char *index, + struct cql_node *modifiers) +{ + struct cql_node *p = (struct cql_node *) nmem_malloc(nmem, sizeof(*p)); + p->which = CQL_NODE_SORT; + p->u.sort.index = 0; + if (index) + p->u.sort.index = nmem_strdup(nmem, index); + p->u.sort.modifiers = modifiers; + p->u.sort.next = 0; + p->u.sort.search = 0; + return p; +} + const char *cql_uri(void) { return "info:srw/cql-context-set/1/cql-v1.2"; @@ -98,7 +116,7 @@ struct cql_node *cql_apply_prefix(NMEM nmem, if (!n->u.st.index_uri && n->u.st.index) { /* not yet resolved.. */ const char *cp = strchr(n->u.st.index, '.'); - if (prefix && cp && + if (prefix && cp && strlen(prefix) == (size_t) (cp - n->u.st.index) && !cql_strncmp(n->u.st.index, prefix, strlen(prefix))) { @@ -129,6 +147,10 @@ struct cql_node *cql_apply_prefix(NMEM nmem, cql_apply_prefix(nmem, n->u.boolean.left, prefix, uri); cql_apply_prefix(nmem, n->u.boolean.right, prefix, uri); } + else if (n->which == CQL_NODE_SORT) + { + cql_apply_prefix(nmem, n->u.sort.search, prefix, uri); + } return n; } @@ -145,6 +167,11 @@ void cql_node_destroy(struct cql_node *cn) cql_node_destroy(cn->u.boolean.left); cql_node_destroy(cn->u.boolean.right); cql_node_destroy(cn->u.boolean.modifiers); + break; + case CQL_NODE_SORT: + cql_node_destroy(cn->u.sort.search); + cql_node_destroy(cn->u.sort.next); + cql_node_destroy(cn->u.sort.modifiers); } } @@ -186,6 +213,7 @@ int cql_strncmp(const char *s1, const char *s2, size_t n) /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab