New general match criteria implemented.
[idzebra-moved-to-github.git] / index / main.c
1 /*
2  * Copyright (C) 1994-1995, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: main.c,v $
7  * Revision 1.17  1995-11-21 15:01:16  adam
8  * New general match criteria implemented.
9  * New feature: document groups.
10  *
11  * Revision 1.16  1995/11/20  11:56:27  adam
12  * Work on new traversal.
13  *
14  * Revision 1.15  1995/11/01  16:25:51  quinn
15  * *** empty log message ***
16  *
17  * Revision 1.14  1995/10/17  18:02:09  adam
18  * New feature: databases. Implemented as prefix to words in dictionary.
19  *
20  * Revision 1.13  1995/10/10  12:24:39  adam
21  * Temporary sort files are compressed.
22  *
23  * Revision 1.12  1995/10/04  16:57:20  adam
24  * Key input and merge sort in one pass.
25  *
26  * Revision 1.11  1995/09/29  14:01:45  adam
27  * Bug fixes.
28  *
29  * Revision 1.10  1995/09/28  14:22:57  adam
30  * Sort uses smaller temporary files.
31  *
32  * Revision 1.9  1995/09/14  07:48:24  adam
33  * Record control management.
34  *
35  * Revision 1.8  1995/09/06  16:11:18  adam
36  * Option: only one word key per file.
37  *
38  * Revision 1.7  1995/09/05  15:28:39  adam
39  * More work on search engine.
40  *
41  * Revision 1.6  1995/09/04  12:33:43  adam
42  * Various cleanup. YAZ util used instead.
43  *
44  * Revision 1.5  1995/09/04  09:10:39  adam
45  * More work on index add/del/update.
46  * Merge sort implemented.
47  * Initial work on z39 server.
48  *
49  * Revision 1.4  1995/09/01  14:06:36  adam
50  * Split of work into more files.
51  *
52  * Revision 1.3  1995/09/01  10:57:07  adam
53  * Minor changes.
54  *
55  * Revision 1.2  1995/09/01  10:30:24  adam
56  * More work on indexing. Not working yet.
57  *
58  * Revision 1.1  1995/08/31  14:50:24  adam
59  * New simple file index tool.
60  *
61  */
62 #include <stdio.h>
63 #include <assert.h>
64 #include <unistd.h>
65
66 #include <alexutil.h>
67 #include <data1.h>
68 #include "index.h"
69
70 char *prog;
71 size_t mem_max = 4*1024*1024;
72 extern char *data1_tabpath;
73
74 int main (int argc, char **argv)
75 {
76     int ret;
77     int cmd = 0;
78     char *arg;
79     char *configName = NULL;
80     int nsections;
81     int key_open_flag = 0;
82
83     struct recordGroup rGroup;
84     
85     rGroup.groupName = NULL;
86     rGroup.databaseName = NULL;
87     rGroup.path = NULL;
88
89     prog = *argv;
90     if (argc < 2)
91     {
92         fprintf (stderr, "index [-v log] [-m meg] [-c config] [-d base]"
93                  " [-g group] cmd1 dir1 cmd2 dir2 ...\n");
94         exit (1);
95     }
96     while ((ret = options ("c:g:v:m:d:", argv, argc, &arg)) != -2)
97     {
98         if (ret == 0)
99         {
100             if(cmd == 0) /* command */
101             {
102                 if (!strcmp (arg, "add"))
103                 {
104                     cmd = 'a';
105                 }
106                 else if (!strcmp (arg, "del"))
107                 {
108                     cmd = 'd';
109                 }
110                 else if (!strcmp (arg, "update"))
111                 {
112                     cmd = 'u';
113                 }
114                 else
115                 {
116                     logf (LOG_FATAL, "Unknown command: %s", arg);
117                     exit (1);
118                 }
119             }
120             else
121             {
122                 if (!common_resource)
123                 {
124                     common_resource = res_open (configName ?
125                                                 configName : "base");
126                     if (!common_resource)
127                     {
128                         logf (LOG_FATAL, "Cannot open resource `%s'",
129                               configName);
130                         exit (1);
131                     }
132                     data1_tabpath = res_get (common_resource, "data1_tabpath");
133                     assert (data1_tabpath);
134                 }
135                 if (!key_open_flag)
136                 {
137                     key_open (mem_max);
138                     key_open_flag = 1;
139                 }
140                 rGroup.path = arg;
141                 if (cmd == 'u')
142                     repositoryUpdate (&rGroup);
143                 else if (cmd == 'a')
144                     repositoryExtract (&rGroup);
145                 else if (cmd == 'd')
146                 {
147                     logf (LOG_FATAL, "Not implemented yet.");
148                     exit (1);
149                 }
150                 cmd = 0;
151             }
152         }
153         else if (ret == 'v')
154         {
155             log_init (log_mask_str(arg), prog, NULL);
156         }
157         else if (ret == 'm')
158         {
159             mem_max = 1024*1024*atoi(arg);
160         }
161         else if (ret == 'd')
162         {
163             rGroup.databaseName = arg;
164         }
165         else if (ret == 'g')
166         {
167             rGroup.groupName = arg;
168         }
169         else if (ret == 'c')
170             configName = arg;
171         else
172         {
173             logf (LOG_FATAL, "Unknown option '-%s'", arg);
174             exit (1);
175         }
176     }
177     if (!key_open_flag)
178         exit (0);
179     nsections = key_close ();
180     if (!nsections)
181         exit (0);
182     logf (LOG_LOG, "Input");
183     key_input (FNAME_WORD_DICT, FNAME_WORD_ISAM, nsections, 60);
184     exit (0);
185 }
186