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