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