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