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