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