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