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