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