1 /* $Id: cqlutil.c,v 1.3 2003-03-03 19:57:35 adam Exp $
2 Copyright (C) 2002-2003
5 This file is part of the YAZ toolkit.
15 void cql_fputs(const char *buf, void *client_data)
17 FILE *f = (FILE *) client_data;
21 struct cql_node *cql_node_dup (struct cql_node *cp)
23 struct cql_node *cn = 0;
30 cn = cql_node_mk_sc(cp->u.st.index,
33 cn->u.st.modifiers = cql_node_dup(cp->u.st.modifiers);
34 cn->u.st.prefixes = cql_node_dup(cp->u.st.prefixes);
37 cn = cql_node_mk_mod(cp->u.mod.name,
39 cn->u.mod.next = cql_node_dup(cp->u.mod.next);
42 cn = cql_node_mk_boolean(cp->u.boolean.value);
43 cn->u.boolean.left = cql_node_dup(cp->u.boolean.left);
44 cn->u.boolean.right = cql_node_dup(cp->u.boolean.right);
45 cn->u.boolean.prefixes = cql_node_dup(cp->u.boolean.prefixes);
50 struct cql_node *cql_node_mk_sc(const char *index,
54 struct cql_node *p = (struct cql_node *) malloc(sizeof(*p));
55 p->which = CQL_NODE_ST;
58 p->u.st.index = strdup(index);
61 p->u.st.term = strdup(term);
64 p->u.st.relation = strdup(relation);
65 p->u.st.modifiers = 0;
70 struct cql_node *cql_node_mk_mod(const char *name,
73 struct cql_node *p = (struct cql_node *) malloc(sizeof(*p));
74 p->which = CQL_NODE_MOD;
78 p->u.mod.name = strdup(name);
81 p->u.mod.value = strdup(value);
86 struct cql_node *cql_node_mk_boolean(const char *op)
88 struct cql_node *p = (struct cql_node *) malloc(sizeof(*p));
89 p->which = CQL_NODE_BOOL;
90 p->u.boolean.value = 0;
92 p->u.boolean.value = strdup(op);
93 p->u.boolean.left = 0;
94 p->u.boolean.right = 0;
95 p->u.boolean.modifiers = 0;
96 p->u.boolean.prefixes = 0;
100 struct cql_node *cql_node_prefix(struct cql_node *n, const char *prefix,
103 struct cql_node **cpp = 0;
104 if (n->which == CQL_NODE_ST)
106 cpp = &n->u.st.prefixes;
108 else if (n->which == CQL_NODE_BOOL)
110 cpp = &n->u.boolean.prefixes;
114 struct cql_node *cp = cql_node_mk_mod(prefix, uri);
115 cp->u.mod.next = *cpp;
121 struct cql_node *cql_node_mk_proxargs(const char *relation,
122 const char *distance,
124 const char *ordering)
126 struct cql_node *m = 0, *m1;
128 if (ordering && *ordering)
129 m = cql_node_mk_mod("ordering", ordering);
132 m1 = cql_node_mk_mod("unit", unit);
136 if (distance && *distance)
138 m1 = cql_node_mk_mod("distance", distance);
142 if (relation && *relation)
144 m1 = cql_node_mk_mod("relation", relation);
151 void cql_node_destroy(struct cql_node *cn)
158 free (cn->u.st.index);
159 free (cn->u.st.relation);
160 free (cn->u.st.term);
161 cql_node_destroy(cn->u.st.modifiers);
162 cql_node_destroy(cn->u.st.prefixes);
165 free (cn->u.mod.name);
166 free (cn->u.mod.value);
167 cql_node_destroy(cn->u.mod.next);
170 free (cn->u.boolean.value);
171 cql_node_destroy(cn->u.boolean.left);
172 cql_node_destroy(cn->u.boolean.right);
173 cql_node_destroy(cn->u.boolean.prefixes);