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