2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.40 1996-04-26 10:00:23 adam
8 * Added option -V to zebraidx to display version information.
9 * Removed stupid warnings from file update.
11 * Revision 1.39 1996/04/09 10:05:21 adam
12 * Bug fix: prev_name buffer possibly too small; allocated in key_file_init.
14 * Revision 1.38 1996/03/26 16:01:14 adam
15 * New setting lockPath: directory of various lock files.
17 * Revision 1.37 1996/03/19 12:43:26 adam
18 * Bug fix: File update traversal didn't handle trailing slashes correctly.
19 * Bug fix: Update of sub directory groups wasn't handled correctly.
21 * Revision 1.36 1996/02/12 18:45:37 adam
22 * New fileVerboseFlag in record group control.
24 * Revision 1.35 1996/02/12 15:56:11 adam
25 * New code command: unread.
27 * Revision 1.34 1996/02/07 14:06:39 adam
28 * Better progress report during register merge.
29 * New command: clean - removes temporary shadow files.
31 * Revision 1.33 1996/02/06 17:11:18 adam
34 * Revision 1.32 1996/02/01 20:50:04 adam
35 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
36 * was never called - happens when no commands are specified.
38 * Revision 1.31 1996/01/08 19:15:46 adam
39 * New input filter that works!
41 * Revision 1.30 1995/12/12 16:00:59 adam
42 * System call sync(2) used after update/commit.
43 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
46 * Revision 1.29 1995/12/11 11:43:30 adam
47 * Locking based on fcntl instead of flock.
48 * Setting commitEnable removed. Command line option -n can be used to
49 * prevent commit if commit setting is defined in the configuration file.
51 * Revision 1.28 1995/12/08 16:22:56 adam
52 * Work on update while servers are running. Three lock files introduced.
53 * The servers reload their registers when necessary, but they don't
54 * reestablish result sets yet.
56 * Revision 1.27 1995/12/07 17:38:47 adam
57 * Work locking mechanisms for concurrent updates/commit.
59 * Revision 1.26 1995/12/06 12:41:23 adam
60 * New command 'stat' for the index program.
61 * Filenames can be read from stdin by specifying '-'.
62 * Bug fix/enhancement of the transformation from terms to regular
63 * expressons in the search engine.
65 * Revision 1.25 1995/12/01 16:24:39 adam
66 * Commit files use separate meta file area.
68 * Revision 1.24 1995/11/30 17:01:38 adam
69 * New setting commitCache: points to commit directories/files.
70 * New command commit: commits at the end of a zebraidx run.
72 * Revision 1.23 1995/11/30 08:34:31 adam
73 * Started work on commit facility.
74 * Changed a few malloc/free to xmalloc/xfree.
76 * Revision 1.22 1995/11/28 09:09:42 adam
77 * Zebra config renamed.
78 * Use setting 'recordId' to identify record now.
79 * Bug fix in recindex.c: rec_release_blocks was invokeded even
80 * though the blocks were already released.
81 * File traversal properly deletes records when needed.
83 * Revision 1.21 1995/11/27 14:27:39 adam
84 * Renamed 'update' command to 'dir'.
86 * Revision 1.20 1995/11/27 13:58:53 adam
87 * New option -t. storeStore data implemented in server.
89 * Revision 1.19 1995/11/25 10:24:06 adam
90 * More record fields - they are enumerated now.
91 * New options: flagStoreData flagStoreKey.
93 * Revision 1.18 1995/11/22 17:19:17 adam
94 * Record management uses the bfile system.
96 * Revision 1.17 1995/11/21 15:01:16 adam
97 * New general match criteria implemented.
98 * New feature: document groups.
100 * Revision 1.16 1995/11/20 11:56:27 adam
101 * Work on new traversal.
103 * Revision 1.15 1995/11/01 16:25:51 quinn
104 * *** empty log message ***
106 * Revision 1.14 1995/10/17 18:02:09 adam
107 * New feature: databases. Implemented as prefix to words in dictionary.
109 * Revision 1.13 1995/10/10 12:24:39 adam
110 * Temporary sort files are compressed.
112 * Revision 1.12 1995/10/04 16:57:20 adam
113 * Key input and merge sort in one pass.
115 * Revision 1.11 1995/09/29 14:01:45 adam
118 * Revision 1.10 1995/09/28 14:22:57 adam
119 * Sort uses smaller temporary files.
121 * Revision 1.9 1995/09/14 07:48:24 adam
122 * Record control management.
124 * Revision 1.8 1995/09/06 16:11:18 adam
125 * Option: only one word key per file.
127 * Revision 1.7 1995/09/05 15:28:39 adam
128 * More work on search engine.
130 * Revision 1.6 1995/09/04 12:33:43 adam
131 * Various cleanup. YAZ util used instead.
133 * Revision 1.5 1995/09/04 09:10:39 adam
134 * More work on index add/del/update.
135 * Merge sort implemented.
136 * Initial work on z39 server.
138 * Revision 1.4 1995/09/01 14:06:36 adam
139 * Split of work into more files.
141 * Revision 1.3 1995/09/01 10:57:07 adam
144 * Revision 1.2 1995/09/01 10:30:24 adam
145 * More work on indexing. Not working yet.
147 * Revision 1.1 1995/08/31 14:50:24 adam
148 * New simple file index tool.
155 #include <alexutil.h>
160 size_t mem_max = 4*1024*1024;
161 extern char *data1_tabpath;
163 static void abort_func (int level, const char *msg, void *info)
165 if (level & LOG_FATAL)
169 int main (int argc, char **argv)
174 char *configName = NULL;
176 int disableCommit = 0;
178 struct recordGroup rGroupDef;
180 rGroupDef.groupName = NULL;
181 rGroupDef.databaseName = NULL;
182 rGroupDef.path = NULL;
183 rGroupDef.recordId = NULL;
184 rGroupDef.recordType = NULL;
185 rGroupDef.flagStoreData = -1;
186 rGroupDef.flagStoreKeys = -1;
187 rGroupDef.fileVerboseFlag = 1;
192 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
194 " update <dir> Update index with files below <dir>.\n"
195 " If <dir> is empty filenames are read from stdin.\n"
196 " delete <dir> Delete index with files below <dir>.\n"
197 " commit Commit changes\n"
198 " clean Clean shadow files\n"
200 " -t <type> Index files as <type> (grs or text).\n"
201 " -c <config> Read configuration file <config>.\n"
202 " -g <group> Index files according to group settings.\n"
203 " -d <database> Records belong to Z39.50 database <database>.\n"
204 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
205 " -n Don't use shadow system\n"
206 " -v <level> Set logging to <level>\n"
211 log_event_end (abort_func, NULL);
212 while ((ret = options ("Vt:c:g:d:m:v:n", argv, argc, &arg)) != -2)
217 if(cmd == 0) /* command */
219 if (!common_resource)
221 common_resource = res_open (configName ?
222 configName : FNAME_CONFIG);
223 if (!common_resource)
225 logf (LOG_FATAL, "Cannot open resource `%s'",
229 data1_tabpath = res_get (common_resource, "profilePath");
230 bf_lockDir (res_get (common_resource, "lockPath"));
232 if (!strcmp (arg, "update"))
234 else if (!strcmp (arg, "update1"))
236 else if (!strcmp (arg, "update2"))
238 else if (!strcmp (arg, "dump"))
240 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
242 else if (!strcmp (arg, "commit"))
245 rval = res_get (common_resource, "shadow");
250 logf (LOG_FATAL, "Cannot perform commit");
251 logf (LOG_FATAL, "No shadow area defined");
254 if (bf_commitExists ())
256 logf (LOG_LOG, "Commit start");
257 zebraIndexLockMsg ("c");
259 logf (LOG_LOG, "Commit execute");
262 zebraIndexLockMsg ("d");
264 logf (LOG_LOG, "Commit clean");
268 logf (LOG_LOG, "Nothing to commit");
270 else if (!strcmp (arg, "clean"))
273 if (bf_commitExists ())
275 zebraIndexLockMsg ("d");
277 logf (LOG_LOG, "Commit clean");
281 logf (LOG_LOG, "Nothing to clean");
283 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
286 rval = res_get (common_resource, "shadow");
290 zebraIndexLockMsg ("r");
296 logf (LOG_FATAL, "Unknown command: %s", arg);
302 struct recordGroup rGroup;
305 rval = res_get (common_resource, "shadow");
306 if (rval && *rval && !disableCommit)
309 zebraIndexLockMsg ("r");
314 zebraIndexLockMsg ("w");
318 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
324 logf (LOG_LOG, "Updating %s", rGroup.path);
325 repositoryUpdate (&rGroup);
326 nsections = key_close ();
330 logf (LOG_LOG, "Updating (pass 1) %s", rGroup.path);
331 repositoryUpdate (&rGroup);
337 logf (LOG_LOG, "Deleting %s", rGroup.path);
338 repositoryDelete (&rGroup);
339 nsections = key_close ();
342 logf (LOG_LOG, "Dumping %s", rGroup.path);
343 repositoryShow (&rGroup);
355 logf (LOG_LOG, "Merging with index");
356 key_input (FNAME_WORD_DICT, FNAME_WORD_ISAM, nsections,
364 fprintf (stderr, "Zebra %s %s\n",
365 ZEBRAVER, ZEBRADATE);
369 log_init (log_mask_str(arg), prog, NULL);
373 mem_max = 1024*1024*atoi(arg);
377 rGroupDef.databaseName = arg;
381 rGroupDef.groupName = arg;
386 rGroupDef.recordType = arg;
391 logf (LOG_FATAL, "Unknown option '-%s'", arg);