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