Removed stupid line. Work on insertion in dictionary. Not finished yet.
[idzebra-moved-to-github.git] / dict / dicttest.c
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: dicttest.c,v $
7  * Revision 1.4  1994-09-01 17:49:37  adam
8  * Removed stupid line. Work on insertion in dictionary. Not finished yet.
9  *
10  * Revision 1.3  1994/09/01  17:44:06  adam
11  * depend include change.
12  *
13  * Revision 1.2  1994/08/18  12:40:54  adam
14  * Some development of dictionary. Not finished at all!
15  *
16  * Revision 1.1  1994/08/16  16:26:47  adam
17  * Added dict.
18  *
19  */
20
21 #include <stdlib.h>
22 #include <string.h>
23 #include <stdio.h>
24
25 #include <dict.h>
26
27 char *prog;
28 Dict dict;
29
30 int main (int argc, char **argv)
31 {
32     const char *name = NULL;
33     const char *inputfile = NULL;
34     const char *base = NULL;
35     int rw = 0;
36     int infosize = 2;
37     int cache = 10;
38     int ret;
39     char *arg;
40     
41     prog = argv[0];
42     if (argc < 2)
43     {
44         fprintf (stderr, "usage:\n"
45                  "  %s [-s n] [-v n] [-i f] [-w] [-c n] base file\n",
46                  prog);
47         exit (1);
48     }
49     while ((ret = options ("s:v:i:wc:", argv, argc, &arg)) != -2)
50     {
51         if (ret == 0)
52         {
53             if (!base)
54                 base = arg;
55             else if (!name)
56                 name = arg;
57             else
58             {
59                 log (LOG_FATAL, "too many files specified\n");
60                 exit (1);
61             }
62         }
63         else if (ret == 'c')
64         {
65             cache = atoi(arg);
66             if (cache<2)
67                 cache = 2;
68         }
69         else if (ret == 'w')
70             rw = 1;
71         else if (ret == 'i')
72         {
73             inputfile = arg;
74             rw = 1;
75         }
76         else if (ret == 's')
77         {
78             infosize = atoi(arg);
79         }
80         else if (ret == 'v')
81         {
82             log_init (atoi(arg), prog, NULL);
83         }
84         else
85         {
86             log (LOG_FATAL, "unknown option");
87             exit (1);
88         }
89     }
90     if (!base || !name)
91     {
92         log (LOG_FATAL, "no base and/or dictionary specified");
93         exit (1);
94     }
95     common_resource = res_open (base);
96     if (!common_resource)
97     {
98         log (LOG_FATAL, "cannot open resource `%s'", base);
99         exit (1);
100     }
101     dict = dict_open (name, cache, rw);
102     if (!dict)
103     {
104         log (LOG_FATAL, "dict_open fail of `%s'", name);
105         exit (1);
106     }
107     if (inputfile)
108     {
109         FILE *ipf;
110         char ipf_buf[256];
111         char word[256];
112         int line = 1;
113         char infobytes[120];
114         memset (infobytes, 0, 120);
115
116         if (!(ipf = fopen(inputfile, "r")))
117         {
118             log (LOG_FATAL|LOG_ERRNO, "cannot open %s", inputfile);
119             exit (1);
120         }
121         
122         while (fgets (ipf_buf, 255, ipf))
123         {
124             if (sscanf (ipf_buf, "%s", word) == 1)
125             {
126                 sprintf (infobytes, "%d", line);
127                 dict_insert (dict, word, infosize, infobytes);
128             }
129             ++line;
130         }
131         fclose (ipf);
132     }
133     dict_close (dict);
134     res_close (common_resource);
135     return 0;
136 }