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