+/* ### Could cache `bibset' */
+static char *ccl2pqf(ZOOM_connection c, const char *ccl)
+{
+ const char *cclfile;
+ CCL_bibset bibset;
+ struct ccl_rpn_node *node;
+ int errorcode;
+ int errorpos;
+ WRBUF w;
+ char *pqf;
+
+ if ((cclfile = ZOOM_connection_option_get(c, "cclfile")) == 0) {
+ set_ZOOM_error(c, ZOOM_ERROR_CCL_CONFIG, "no CCL qualifier file");
+ return 0;
+ }
+
+ bibset = ccl_qual_mk();
+ if (ccl_qual_fname(bibset, cclfile) < 0) {
+ char buf[512];
+ ccl_qual_rm(&bibset);
+ sprintf(buf, "can't open CCL qualifier file '%.200s': %.200s",
+ cclfile, strerror(errno));
+ set_ZOOM_error(c, ZOOM_ERROR_CCL_CONFIG, buf);
+ return 0;
+ }
+
+ node = ccl_find_str (bibset, ccl, &errorcode, &errorpos);
+ ccl_qual_rm(&bibset);
+ if (node == 0) {
+ /* code is one of the CCL_ERR_* constants; pos is unused here */
+ set_ZOOM_error(c, ZOOM_ERROR_CCL_PARSE, ccl_err_msg(errorcode));
+ return 0;
+ }
+
+ w = wrbuf_alloc();
+ ccl_pquery(w, node);
+ ccl_rpn_delete(node);
+ pqf = xstrdup(wrbuf_buf(w));
+ wrbuf_free(w, 1);
+
+ return pqf;
+}
+
+