2 * Copyright (C) 1994-1997, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.53 1997-11-18 10:05:08 adam
8 * Changed character map facility so that admin can specify character
9 * mapping files for each register type, w, p, etc.
11 * Revision 1.52 1997/10/31 12:34:04 adam
12 * Added missing nmem_init.
14 * Revision 1.51 1997/10/27 14:33:05 adam
15 * Moved towards generic character mapping depending on "structure"
16 * field in abstract syntax file. Fixed a few memory leaks. Fixed
17 * bug with negative integers when doing searches with relational
20 * Revision 1.50 1997/09/25 14:55:52 adam
23 * Revision 1.49 1997/09/17 12:19:15 adam
24 * Zebra version corresponds to YAZ version 1.4.
25 * Changed Zebra server so that it doesn't depend on global common_resource.
27 * Revision 1.48 1997/09/09 13:38:08 adam
28 * Partial port to WIN95/NT.
30 * Revision 1.47 1997/02/12 20:39:46 adam
31 * Implemented options -f <n> that limits the log to the first <n>
33 * Changed some log messages also.
35 * Revision 1.46 1997/02/10 10:20:13 adam
36 * Flag fileVerboseFlag set to 0 (default).
38 * Revision 1.45 1996/11/08 11:10:26 adam
39 * Buffers used during file match got bigger.
40 * Compressed ISAM support everywhere.
41 * Bug fixes regarding masking characters in queries.
42 * Redesigned Regexp-2 queries.
44 * Revision 1.44 1996/10/29 14:09:48 adam
45 * Use of cisam system - enabled if setting isamc is 1.
47 * Revision 1.43 1996/06/06 12:08:42 quinn
48 * Added showRecord function
50 * Revision 1.42 1996/05/31 09:07:01 quinn
51 * Work on character-set handling
53 * Revision 1.41 1996/05/14 14:04:34 adam
54 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
57 * Revision 1.40 1996/04/26 10:00:23 adam
58 * Added option -V to zebraidx to display version information.
59 * Removed stupid warnings from file update.
61 * Revision 1.39 1996/04/09 10:05:21 adam
62 * Bug fix: prev_name buffer possibly too small; allocated in key_file_init.
64 * Revision 1.38 1996/03/26 16:01:14 adam
65 * New setting lockPath: directory of various lock files.
67 * Revision 1.37 1996/03/19 12:43:26 adam
68 * Bug fix: File update traversal didn't handle trailing slashes correctly.
69 * Bug fix: Update of sub directory groups wasn't handled correctly.
71 * Revision 1.36 1996/02/12 18:45:37 adam
72 * New fileVerboseFlag in record group control.
74 * Revision 1.35 1996/02/12 15:56:11 adam
75 * New code command: unread.
77 * Revision 1.34 1996/02/07 14:06:39 adam
78 * Better progress report during register merge.
79 * New command: clean - removes temporary shadow files.
81 * Revision 1.33 1996/02/06 17:11:18 adam
84 * Revision 1.32 1996/02/01 20:50:04 adam
85 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
86 * was never called - happens when no commands are specified.
88 * Revision 1.31 1996/01/08 19:15:46 adam
89 * New input filter that works!
91 * Revision 1.30 1995/12/12 16:00:59 adam
92 * System call sync(2) used after update/commit.
93 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
96 * Revision 1.29 1995/12/11 11:43:30 adam
97 * Locking based on fcntl instead of flock.
98 * Setting commitEnable removed. Command line option -n can be used to
99 * prevent commit if commit setting is defined in the configuration file.
101 * Revision 1.28 1995/12/08 16:22:56 adam
102 * Work on update while servers are running. Three lock files introduced.
103 * The servers reload their registers when necessary, but they don't
104 * reestablish result sets yet.
106 * Revision 1.27 1995/12/07 17:38:47 adam
107 * Work locking mechanisms for concurrent updates/commit.
109 * Revision 1.26 1995/12/06 12:41:23 adam
110 * New command 'stat' for the index program.
111 * Filenames can be read from stdin by specifying '-'.
112 * Bug fix/enhancement of the transformation from terms to regular
113 * expressons in the search engine.
115 * Revision 1.25 1995/12/01 16:24:39 adam
116 * Commit files use separate meta file area.
118 * Revision 1.24 1995/11/30 17:01:38 adam
119 * New setting commitCache: points to commit directories/files.
120 * New command commit: commits at the end of a zebraidx run.
122 * Revision 1.23 1995/11/30 08:34:31 adam
123 * Started work on commit facility.
124 * Changed a few malloc/free to xmalloc/xfree.
126 * Revision 1.22 1995/11/28 09:09:42 adam
127 * Zebra config renamed.
128 * Use setting 'recordId' to identify record now.
129 * Bug fix in recindex.c: rec_release_blocks was invokeded even
130 * though the blocks were already released.
131 * File traversal properly deletes records when needed.
133 * Revision 1.21 1995/11/27 14:27:39 adam
134 * Renamed 'update' command to 'dir'.
136 * Revision 1.20 1995/11/27 13:58:53 adam
137 * New option -t. storeStore data implemented in server.
139 * Revision 1.19 1995/11/25 10:24:06 adam
140 * More record fields - they are enumerated now.
141 * New options: flagStoreData flagStoreKey.
143 * Revision 1.18 1995/11/22 17:19:17 adam
144 * Record management uses the bfile system.
146 * Revision 1.17 1995/11/21 15:01:16 adam
147 * New general match criteria implemented.
148 * New feature: document groups.
150 * Revision 1.16 1995/11/20 11:56:27 adam
151 * Work on new traversal.
153 * Revision 1.15 1995/11/01 16:25:51 quinn
154 * *** empty log message ***
156 * Revision 1.14 1995/10/17 18:02:09 adam
157 * New feature: databases. Implemented as prefix to words in dictionary.
159 * Revision 1.13 1995/10/10 12:24:39 adam
160 * Temporary sort files are compressed.
162 * Revision 1.12 1995/10/04 16:57:20 adam
163 * Key input and merge sort in one pass.
165 * Revision 1.11 1995/09/29 14:01:45 adam
168 * Revision 1.10 1995/09/28 14:22:57 adam
169 * Sort uses smaller temporary files.
171 * Revision 1.9 1995/09/14 07:48:24 adam
172 * Record control management.
174 * Revision 1.8 1995/09/06 16:11:18 adam
175 * Option: only one word key per file.
177 * Revision 1.7 1995/09/05 15:28:39 adam
178 * More work on search engine.
180 * Revision 1.6 1995/09/04 12:33:43 adam
181 * Various cleanup. YAZ util used instead.
183 * Revision 1.5 1995/09/04 09:10:39 adam
184 * More work on index add/del/update.
185 * Merge sort implemented.
186 * Initial work on z39 server.
188 * Revision 1.4 1995/09/01 14:06:36 adam
189 * Split of work into more files.
191 * Revision 1.3 1995/09/01 10:57:07 adam
194 * Revision 1.2 1995/09/01 10:30:24 adam
195 * More work on indexing. Not working yet.
197 * Revision 1.1 1995/08/31 14:50:24 adam
198 * New simple file index tool.
215 Res common_resource = 0;
217 static void abort_func (int level, const char *msg, void *info)
219 if (level & LOG_FATAL)
223 int main (int argc, char **argv)
228 char *configName = NULL;
230 int disableCommit = 0;
232 struct recordGroup rGroupDef;
236 rGroupDef.groupName = NULL;
237 rGroupDef.databaseName = NULL;
238 rGroupDef.path = NULL;
239 rGroupDef.recordId = NULL;
240 rGroupDef.recordType = NULL;
241 rGroupDef.flagStoreData = -1;
242 rGroupDef.flagStoreKeys = -1;
243 rGroupDef.flagShowRecords = 0;
244 rGroupDef.fileVerboseLimit = 100000;
245 rGroupDef.zebra_maps = NULL;
246 rGroupDef.dh = data1_create ();
251 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
253 " update <dir> Update index with files below <dir>.\n"
254 " If <dir> is empty filenames are read from stdin.\n"
255 " delete <dir> Delete index with files below <dir>.\n"
256 " commit Commit changes\n"
257 " clean Clean shadow files\n"
259 " -t <type> Index files as <type> (grs or text).\n"
260 " -c <config> Read configuration file <config>.\n"
261 " -g <group> Index files according to group settings.\n"
262 " -d <database> Records belong to Z39.50 database <database>.\n"
263 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
264 " -n Don't use shadow system.\n"
265 " -s Show analysis on stdout, but do no work.\n"
266 " -v <level> Set logging to <level>.\n"
267 " -f <n> Display information for the first <n> records.\n"
268 " -V Show version.\n"
272 while ((ret = options ("sVt:c:g:d:m:v:nf:", argv, argc, &arg)) != -2)
277 if(cmd == 0) /* command */
279 if (!common_resource)
281 logf (LOG_LOG, "zebra version %s %s",
282 ZEBRAVER, ZEBRADATE);
283 common_resource = res_open (configName ?
284 configName : FNAME_CONFIG);
285 if (!common_resource)
287 logf (LOG_FATAL, "cannot open resource `%s'",
291 data1_set_tabpath (rGroupDef.dh, res_get (common_resource,
295 bfs_create (res_get (common_resource, "register"));
297 bf_lockDir (rGroupDef.bfs,
298 res_get (common_resource, "lockDir"));
299 rGroupDef.zebra_maps = zebra_maps_open (res_get(
300 common_resource, "profilePath"), common_resource);
302 if (!strcmp (arg, "update"))
304 else if (!strcmp (arg, "update1"))
306 else if (!strcmp (arg, "update2"))
308 else if (!strcmp (arg, "dump"))
310 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
312 else if (!strcmp (arg, "commit"))
314 rval = res_get (common_resource, "shadow");
315 zebraIndexLock (rGroupDef.bfs, 1, rval);
317 bf_cache (rGroupDef.bfs, rval);
320 logf (LOG_FATAL, "Cannot perform commit");
321 logf (LOG_FATAL, "No shadow area defined");
324 if (bf_commitExists (rGroupDef.bfs))
326 logf (LOG_LOG, "commit start");
327 zebraIndexLockMsg ("c");
329 logf (LOG_LOG, "commit execute");
330 bf_commitExec (rGroupDef.bfs);
334 zebraIndexLockMsg ("d");
336 logf (LOG_LOG, "commit clean");
337 bf_commitClean (rGroupDef.bfs, rval);
340 logf (LOG_LOG, "cothing to commit");
342 else if (!strcmp (arg, "clean"))
344 rval = res_get (common_resource, "shadow");
345 zebraIndexLock (rGroupDef.bfs, 1, rval);
346 if (bf_commitExists (rGroupDef.bfs))
348 zebraIndexLockMsg ("d");
350 logf (LOG_LOG, "commit clean");
351 bf_commitClean (rGroupDef.bfs, rval);
354 logf (LOG_LOG, "nothing to clean");
356 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
358 rval = res_get (common_resource, "shadow");
359 zebraIndexLock (rGroupDef.bfs, 0, rval);
362 bf_cache (rGroupDef.bfs, rval);
363 zebraIndexLockMsg ("r");
366 inv_prstat (rGroupDef.bfs);
370 logf (LOG_FATAL, "unknown command: %s", arg);
376 struct recordGroup rGroup;
378 log_event_end (abort_func, NULL);
379 rval = res_get (common_resource, "shadow");
380 zebraIndexLock (rGroupDef.bfs, 0, rval);
381 if (rval && *rval && !disableCommit)
383 bf_cache (rGroupDef.bfs, rval);
384 zebraIndexLockMsg ("r");
388 bf_cache (rGroupDef.bfs, 0);
389 zebraIndexLockMsg ("w");
393 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
398 key_open (rGroup.bfs, mem_max);
399 logf (LOG_LOG, "updating %s", rGroup.path);
400 repositoryUpdate (&rGroup);
401 nsections = key_close ();
404 key_open (rGroup.bfs,mem_max);
405 logf (LOG_LOG, "updating (pass 1) %s", rGroup.path);
406 repositoryUpdate (&rGroup);
411 key_open (rGroup.bfs,mem_max);
412 logf (LOG_LOG, "deleting %s", rGroup.path);
413 repositoryDelete (&rGroup);
414 nsections = key_close ();
417 logf (LOG_LOG, "dumping %s", rGroup.path);
418 repositoryShow (&rGroup);
430 logf (LOG_LOG, "merging with index");
431 key_input (rGroup.bfs, nsections, 60);
436 log_event_end (NULL, NULL);
441 fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
444 log_init (log_mask_str(arg), prog, NULL);
446 mem_max = 1024*1024*atoi(arg);
448 rGroupDef.databaseName = arg;
450 rGroupDef.flagShowRecords = 1;
452 rGroupDef.groupName = arg;
454 rGroupDef.fileVerboseLimit = atoi(arg);
458 rGroupDef.recordType = arg;
463 logf (LOG_FATAL, "unknown option '-%s'", arg);
470 bfs_destroy (rGroupDef.bfs);
472 data1_destroy (rGroupDef.dh);