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