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