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