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