Added copy of CCL.
[yaz-moved-to-github.git] / ccl / cclsh.c
1 /* CCL shell.
2  * Europagate 1995
3  *
4  * $Log: cclsh.c,v $
5  * Revision 1.1  1995-04-10 10:28:21  quinn
6  * Added copy of CCL.
7  *
8  * Revision 1.9  1995/02/23  08:32:00  adam
9  * Changed header.
10  *
11  * Revision 1.7  1995/02/15  17:42:16  adam
12  * Minor changes of the api of this module. FILE* argument added
13  * to ccl_pr_tree.
14  *
15  * Revision 1.6  1995/02/14  19:55:13  adam
16  * Header files ccl.h/cclp.h are gone! They have been merged an
17  * moved to ../include/ccl.h.
18  * Node kind(s) in ccl_rpn_node have changed names.
19  *
20  * Revision 1.5  1995/02/14  16:20:57  adam
21  * Qualifiers are read from a file now.
22  *
23  * Revision 1.4  1995/02/14  14:12:42  adam
24  * Ranges for ordered qualfiers implemented (e.g. pd=1980-1990).
25  *
26  * Revision 1.3  1995/02/14  10:25:57  adam
27  * The constructions 'qualifier rel term ...' implemented.
28  *
29  * Revision 1.2  1995/02/13  15:15:07  adam
30  * Added handling of qualifiers. Not finished yet.
31  *
32  * Revision 1.1  1995/02/13  12:35:21  adam
33  * First version of CCL. Qualifiers aren't handled yet.
34  *
35  */
36
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <assert.h>
40
41 #include <ccl.h>
42
43 static int debug = 0;
44 static char *prog;
45
46 int main (int argc, char **argv)
47 {
48     CCL_bibset bibset;
49     FILE *bib_inf;
50     char *bib_fname;
51
52     prog = *argv;
53     bibset = ccl_qual_mk ();    
54     while (--argc > 0)
55     {
56         if (**++argv == '-')
57         {
58             switch (argv[0][1])
59             {
60             case 'd':
61                 debug = 1;
62                 break;
63             case 'b':
64                 if (argv[0][2])
65                     bib_fname = argv[0]+2;
66                 else if (argc > 0)
67                 {
68                     --argc;
69                     bib_fname = *++argv;
70                 }
71                 else
72                 {
73                     fprintf (stderr, "%s: missing bib filename\n", prog);
74                     exit (1);
75                 }
76                 bib_inf = fopen (bib_fname, "r");
77                 if (!bib_inf)
78                 {
79                     fprintf (stderr, "%s: cannot open %s\n", prog,
80                              bib_fname);
81                     exit (1);
82                 }
83                 ccl_qual_file (bibset, bib_inf);
84                 fclose (bib_inf);
85                 break;
86             default:
87                 fprintf (stderr, "%s: unknown option '%s'\n",
88                     prog, *argv);
89                 exit (1);
90             }
91         }
92         else
93         {
94             fprintf (stderr, "%s: no filenames, please\n", prog);
95             exit (1);
96         }
97     }
98     while (1)
99     {
100         char buf[80];
101         int error, pos;
102         struct ccl_rpn_node *rpn;
103
104         printf ("CCLSH>"); fflush (stdout);
105         if (!fgets (buf, 79, stdin))
106             break;
107         rpn = ccl_find_str (bibset, buf, &error, &pos);
108         if (error)
109         {
110             printf ("%*s^ - ", 6+pos, " ");
111             printf ("%s\n", ccl_err_msg (error));
112         }
113         else
114         {
115             assert (rpn);
116             ccl_pr_tree (rpn, stdout);
117             putchar ('\n');
118         }
119     }
120     putchar ('\n');
121     return 0;
122 }