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