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