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