+
+
+/*
+ * Returns an xmalloc()d string containing RPN that corresponds to the
+ * CQL passed in. On error, sets the Connection object's error state
+ * and returns a null pointer.
+ * ### We could cache CQL parser and/or transformer in Connection.
+ */
+static char *cql2pqf(ZOOM_connection c, const char *cql)
+{
+ CQL_parser parser;
+ int error;
+ struct cql_node *node;
+ const char *cqlfile;
+ static cql_transform_t trans;
+ char pqfbuf[512];
+
+ parser = cql_parser_create();
+ /*printf("*** got CQL parser %p\n", parser);*/
+ if ((error = cql_parser_string(parser, cql)) != 0) {
+ cql_parser_destroy(parser);
+ set_ZOOM_error(c, ZOOM_ERROR_CQL_PARSE, cql);
+ return 0;
+ }
+
+ node = cql_parser_result(parser);
+ /*printf("*** got CQL node %p\n", node);*/
+ /* ### Do not call cql_parser_destroy() yet: it destroys `node'! */
+
+ cqlfile = ZOOM_connection_option_get(c, "cqlfile");
+ /*printf("*** cqlfile is %p\n", cqlfile);*/
+ if (cqlfile == 0) {
+ /*printf("*** cqlfile is null\n");*/
+ cql_parser_destroy(parser);
+ cql_node_destroy(node);
+ /*printf("*** destroyed node\n");*/
+ set_ZOOM_error(c, ZOOM_ERROR_CQL_TRANSFORM, "no CQL transform file");
+ /*printf("*** set ZOOM_error\n");*/
+ return 0;
+ }
+ /*printf("*** got CQL file %s\n", cqlfile);*/
+
+ if ((trans = cql_transform_open_fname(cqlfile)) == 0) {
+ char buf[512];
+ cql_parser_destroy(parser);
+ cql_node_destroy(node);
+ sprintf(buf, "can't open CQL transform file '%.200s': %.200s",
+ cqlfile, strerror(errno));
+ set_ZOOM_error(c, ZOOM_ERROR_CQL_TRANSFORM, buf);
+ return 0;
+ }
+
+ /*printf("*** got trans %p\n", trans);*/
+ error = cql_transform_buf(trans, node, pqfbuf, sizeof pqfbuf);
+ cql_parser_destroy(parser);
+ /*printf("*** destroyed parser\n");*/
+ /*printf("*** got cql_transform_buf() retval %d\n", error);*/
+ cql_node_destroy(node);
+ if (error != 0) {
+ char buf[512];
+ const char *addinfo;
+ error = cql_transform_error(trans, &addinfo);
+ cql_transform_close(trans);
+ sprintf(buf, "%.200s (addinfo=%.200s)", cql_strerror(error), addinfo);
+ set_ZOOM_error(c, ZOOM_ERROR_CQL_TRANSFORM, buf);
+ return 0;
+ }
+
+ cql_transform_close(trans);
+ {
+ char *s = xstrdup(pqfbuf);
+ /*printf("*** translated '%s' to '%s'\n", cql, s);*/
+ return s;
+ }
+}
+
+