2 * Copyright (C) 1995-2008, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: cclsh.c,v 1.9 2008-01-09 21:32:28 adam Exp $
12 #include <yaz/ccl_xml.h>
13 #include <yaz/options.h>
15 #if HAVE_READLINE_READLINE_H
16 #include <readline/readline.h>
18 #if HAVE_READLINE_HISTORY_H
19 #include <readline/history.h>
26 void usage(const char *prog)
28 fprintf(stderr, "%s: [-d] [-b configfile] [-x xmlconfig]\n", prog);
32 int main(int argc, char **argv)
46 bibset = ccl_qual_mk();
48 while ((ret = options("db:x:", argv, argc, &arg)) != -2)
57 bib_inf = fopen(bib_fname, "r");
60 fprintf(stderr, "%s: cannot open %s\n", prog,
64 ccl_qual_file(bibset, bib_inf);
69 doc = xmlParseFile(arg);
72 fprintf(stderr, "%s: could not read %s\n", prog, arg);
75 if (ccl_xml_config(bibset, xmlDocGetRootElement(doc), &addinfo))
77 fprintf(stderr, "%s: error in %s: %s\n", prog, arg, addinfo);
85 wrbuf_puts(q_wrbuf, " ");
87 q_wrbuf = wrbuf_alloc();
88 wrbuf_puts(q_wrbuf, arg);
96 CCL_parser cclp = ccl_parser_create(bibset);
98 struct ccl_rpn_node *rpn;
100 rpn = ccl_parser_find_str(cclp, wrbuf_cstr(q_wrbuf));
102 error = ccl_parser_get_error(cclp, 0);
106 printf("%s\n", ccl_err_msg(error));
112 ccl_pr_tree(rpn, stdout);
116 ccl_parser_destroy(cclp);
119 wrbuf_destroy(q_wrbuf);
126 struct ccl_rpn_node *rpn;
128 #if HAVE_READLINE_READLINE_H
130 line_in=readline("CCLSH>");
133 #if HAVE_READLINE_HISTORY_H
135 add_history(line_in);
137 if (strlen(line_in) > 999) {
138 fprintf(stderr,"Input line to long\n");
144 printf("CCLSH>"); fflush(stdout);
145 if (!fgets(buf, 999, stdin))
149 for (i = 0; i<1; i++)
151 CCL_parser cclp = ccl_parser_create(bibset);
154 rpn = ccl_parser_find_str(cclp, buf);
156 error = ccl_parser_get_error(cclp, &pos);
160 printf("%*s^ - ", 6+pos, " ");
161 printf("%s\n", ccl_err_msg(error));
167 ccl_stop_words_t csw = ccl_stop_words_create();
170 ccl_pr_tree(rpn, stdout);
171 if (ccl_stop_words_tree(csw, bibset, &rpn))
174 ccl_pr_tree(rpn, stdout);
177 for (idx = 0; ; idx++)
181 if (!ccl_stop_words_info(csw, idx,
184 printf("Removed from %s: %s\n",
185 qname ? qname : "none", term);
188 ccl_stop_words_destroy(csw);
191 ccl_parser_destroy(cclp);
197 ccl_qual_rm(&bibset);
203 * indent-tabs-mode: nil
205 * vim: shiftwidth=4 tabstop=8 expandtab