Qualifiers are read from a file now.
[egate.git] / ccl / cclsh.c
1 /* CCL shell.
2  * Europagate 1995
3  *
4  * $Log: cclsh.c,v $
5  * Revision 1.5  1995/02/14 16:20:57  adam
6  * Qualifiers are read from a file now.
7  *
8  * Revision 1.4  1995/02/14  14:12:42  adam
9  * Ranges for ordered qualfiers implemented (e.g. pd=1980-1990).
10  *
11  * Revision 1.3  1995/02/14  10:25:57  adam
12  * The constructions 'qualifier rel term ...' implemented.
13  *
14  * Revision 1.2  1995/02/13  15:15:07  adam
15  * Added handling of qualifiers. Not finished yet.
16  *
17  * Revision 1.1  1995/02/13  12:35:21  adam
18  * First version of CCL. Qualifiers aren't handled yet.
19  *
20  */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <assert.h>
25
26 #include "ccl.h"
27
28 static int debug = 0;
29 static char *prog;
30
31 static int ti_attr[] = {
32     CCL_BIB1_USE, 4,
33     CCL_BIB1_STR, CCL_BIB1_STR_WP
34 };
35
36 static int au_attr[] = {
37     CCL_BIB1_USE, 1,
38     CCL_BIB1_STR, CCL_BIB1_STR_WP
39 };
40
41 static int pd_attr[] = {
42     CCL_BIB1_USE, 31,
43     CCL_BIB1_REL, CCL_BIB1_REL_ORDER
44 };
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);
117             putchar ('\n');
118         }
119     }
120     putchar ('\n');
121     return 0;
122 }