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