2 * Copyright (C) 1994-1997, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.51 1997-10-27 14:33:05 adam
8 * Moved towards generic character mapping depending on "structure"
9 * field in abstract syntax file. Fixed a few memory leaks. Fixed
10 * bug with negative integers when doing searches with relational
13 * Revision 1.50 1997/09/25 14:55:52 adam
16 * Revision 1.49 1997/09/17 12:19:15 adam
17 * Zebra version corresponds to YAZ version 1.4.
18 * Changed Zebra server so that it doesn't depend on global common_resource.
20 * Revision 1.48 1997/09/09 13:38:08 adam
21 * Partial port to WIN95/NT.
23 * Revision 1.47 1997/02/12 20:39:46 adam
24 * Implemented options -f <n> that limits the log to the first <n>
26 * Changed some log messages also.
28 * Revision 1.46 1997/02/10 10:20:13 adam
29 * Flag fileVerboseFlag set to 0 (default).
31 * Revision 1.45 1996/11/08 11:10:26 adam
32 * Buffers used during file match got bigger.
33 * Compressed ISAM support everywhere.
34 * Bug fixes regarding masking characters in queries.
35 * Redesigned Regexp-2 queries.
37 * Revision 1.44 1996/10/29 14:09:48 adam
38 * Use of cisam system - enabled if setting isamc is 1.
40 * Revision 1.43 1996/06/06 12:08:42 quinn
41 * Added showRecord function
43 * Revision 1.42 1996/05/31 09:07:01 quinn
44 * Work on character-set handling
46 * Revision 1.41 1996/05/14 14:04:34 adam
47 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
50 * Revision 1.40 1996/04/26 10:00:23 adam
51 * Added option -V to zebraidx to display version information.
52 * Removed stupid warnings from file update.
54 * Revision 1.39 1996/04/09 10:05:21 adam
55 * Bug fix: prev_name buffer possibly too small; allocated in key_file_init.
57 * Revision 1.38 1996/03/26 16:01:14 adam
58 * New setting lockPath: directory of various lock files.
60 * Revision 1.37 1996/03/19 12:43:26 adam
61 * Bug fix: File update traversal didn't handle trailing slashes correctly.
62 * Bug fix: Update of sub directory groups wasn't handled correctly.
64 * Revision 1.36 1996/02/12 18:45:37 adam
65 * New fileVerboseFlag in record group control.
67 * Revision 1.35 1996/02/12 15:56:11 adam
68 * New code command: unread.
70 * Revision 1.34 1996/02/07 14:06:39 adam
71 * Better progress report during register merge.
72 * New command: clean - removes temporary shadow files.
74 * Revision 1.33 1996/02/06 17:11:18 adam
77 * Revision 1.32 1996/02/01 20:50:04 adam
78 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
79 * was never called - happens when no commands are specified.
81 * Revision 1.31 1996/01/08 19:15:46 adam
82 * New input filter that works!
84 * Revision 1.30 1995/12/12 16:00:59 adam
85 * System call sync(2) used after update/commit.
86 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
89 * Revision 1.29 1995/12/11 11:43:30 adam
90 * Locking based on fcntl instead of flock.
91 * Setting commitEnable removed. Command line option -n can be used to
92 * prevent commit if commit setting is defined in the configuration file.
94 * Revision 1.28 1995/12/08 16:22:56 adam
95 * Work on update while servers are running. Three lock files introduced.
96 * The servers reload their registers when necessary, but they don't
97 * reestablish result sets yet.
99 * Revision 1.27 1995/12/07 17:38:47 adam
100 * Work locking mechanisms for concurrent updates/commit.
102 * Revision 1.26 1995/12/06 12:41:23 adam
103 * New command 'stat' for the index program.
104 * Filenames can be read from stdin by specifying '-'.
105 * Bug fix/enhancement of the transformation from terms to regular
106 * expressons in the search engine.
108 * Revision 1.25 1995/12/01 16:24:39 adam
109 * Commit files use separate meta file area.
111 * Revision 1.24 1995/11/30 17:01:38 adam
112 * New setting commitCache: points to commit directories/files.
113 * New command commit: commits at the end of a zebraidx run.
115 * Revision 1.23 1995/11/30 08:34:31 adam
116 * Started work on commit facility.
117 * Changed a few malloc/free to xmalloc/xfree.
119 * Revision 1.22 1995/11/28 09:09:42 adam
120 * Zebra config renamed.
121 * Use setting 'recordId' to identify record now.
122 * Bug fix in recindex.c: rec_release_blocks was invokeded even
123 * though the blocks were already released.
124 * File traversal properly deletes records when needed.
126 * Revision 1.21 1995/11/27 14:27:39 adam
127 * Renamed 'update' command to 'dir'.
129 * Revision 1.20 1995/11/27 13:58:53 adam
130 * New option -t. storeStore data implemented in server.
132 * Revision 1.19 1995/11/25 10:24:06 adam
133 * More record fields - they are enumerated now.
134 * New options: flagStoreData flagStoreKey.
136 * Revision 1.18 1995/11/22 17:19:17 adam
137 * Record management uses the bfile system.
139 * Revision 1.17 1995/11/21 15:01:16 adam
140 * New general match criteria implemented.
141 * New feature: document groups.
143 * Revision 1.16 1995/11/20 11:56:27 adam
144 * Work on new traversal.
146 * Revision 1.15 1995/11/01 16:25:51 quinn
147 * *** empty log message ***
149 * Revision 1.14 1995/10/17 18:02:09 adam
150 * New feature: databases. Implemented as prefix to words in dictionary.
152 * Revision 1.13 1995/10/10 12:24:39 adam
153 * Temporary sort files are compressed.
155 * Revision 1.12 1995/10/04 16:57:20 adam
156 * Key input and merge sort in one pass.
158 * Revision 1.11 1995/09/29 14:01:45 adam
161 * Revision 1.10 1995/09/28 14:22:57 adam
162 * Sort uses smaller temporary files.
164 * Revision 1.9 1995/09/14 07:48:24 adam
165 * Record control management.
167 * Revision 1.8 1995/09/06 16:11:18 adam
168 * Option: only one word key per file.
170 * Revision 1.7 1995/09/05 15:28:39 adam
171 * More work on search engine.
173 * Revision 1.6 1995/09/04 12:33:43 adam
174 * Various cleanup. YAZ util used instead.
176 * Revision 1.5 1995/09/04 09:10:39 adam
177 * More work on index add/del/update.
178 * Merge sort implemented.
179 * Initial work on z39 server.
181 * Revision 1.4 1995/09/01 14:06:36 adam
182 * Split of work into more files.
184 * Revision 1.3 1995/09/01 10:57:07 adam
187 * Revision 1.2 1995/09/01 10:30:24 adam
188 * More work on indexing. Not working yet.
190 * Revision 1.1 1995/08/31 14:50:24 adam
191 * New simple file index tool.
208 Res common_resource = 0;
210 static void abort_func (int level, const char *msg, void *info)
212 if (level & LOG_FATAL)
216 int main (int argc, char **argv)
221 char *configName = NULL;
223 int disableCommit = 0;
225 struct recordGroup rGroupDef;
227 rGroupDef.groupName = NULL;
228 rGroupDef.databaseName = NULL;
229 rGroupDef.path = NULL;
230 rGroupDef.recordId = NULL;
231 rGroupDef.recordType = NULL;
232 rGroupDef.flagStoreData = -1;
233 rGroupDef.flagStoreKeys = -1;
234 rGroupDef.flagShowRecords = 0;
235 rGroupDef.fileVerboseLimit = 100000;
236 rGroupDef.zebra_maps = NULL;
237 rGroupDef.dh = data1_create ();
242 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
244 " update <dir> Update index with files below <dir>.\n"
245 " If <dir> is empty filenames are read from stdin.\n"
246 " delete <dir> Delete index with files below <dir>.\n"
247 " commit Commit changes\n"
248 " clean Clean shadow files\n"
250 " -t <type> Index files as <type> (grs or text).\n"
251 " -c <config> Read configuration file <config>.\n"
252 " -g <group> Index files according to group settings.\n"
253 " -d <database> Records belong to Z39.50 database <database>.\n"
254 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
255 " -n Don't use shadow system.\n"
256 " -s Show analysis on stdout, but do no work.\n"
257 " -v <level> Set logging to <level>.\n"
258 " -f <n> Display information for the first <n> records.\n"
259 " -V Show version.\n"
263 while ((ret = options ("sVt:c:g:d:m:v:nf:", argv, argc, &arg)) != -2)
268 if(cmd == 0) /* command */
270 if (!common_resource)
272 logf (LOG_LOG, "zebra version %s %s",
273 ZEBRAVER, ZEBRADATE);
274 common_resource = res_open (configName ?
275 configName : FNAME_CONFIG);
276 if (!common_resource)
278 logf (LOG_FATAL, "cannot open resource `%s'",
282 data1_set_tabpath (rGroupDef.dh, res_get (common_resource,
286 bfs_create (res_get (common_resource, "register"));
288 bf_lockDir (rGroupDef.bfs,
289 res_get (common_resource, "lockDir"));
290 rGroupDef.zebra_maps = zebra_maps_open (res_get(
291 common_resource, "profilePath"));
293 if (!strcmp (arg, "update"))
295 else if (!strcmp (arg, "update1"))
297 else if (!strcmp (arg, "update2"))
299 else if (!strcmp (arg, "dump"))
301 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
303 else if (!strcmp (arg, "commit"))
305 rval = res_get (common_resource, "shadow");
306 zebraIndexLock (rGroupDef.bfs, 1, rval);
308 bf_cache (rGroupDef.bfs, rval);
311 logf (LOG_FATAL, "Cannot perform commit");
312 logf (LOG_FATAL, "No shadow area defined");
315 if (bf_commitExists (rGroupDef.bfs))
317 logf (LOG_LOG, "commit start");
318 zebraIndexLockMsg ("c");
320 logf (LOG_LOG, "commit execute");
321 bf_commitExec (rGroupDef.bfs);
325 zebraIndexLockMsg ("d");
327 logf (LOG_LOG, "commit clean");
328 bf_commitClean (rGroupDef.bfs, rval);
331 logf (LOG_LOG, "cothing to commit");
333 else if (!strcmp (arg, "clean"))
335 rval = res_get (common_resource, "shadow");
336 zebraIndexLock (rGroupDef.bfs, 1, rval);
337 if (bf_commitExists (rGroupDef.bfs))
339 zebraIndexLockMsg ("d");
341 logf (LOG_LOG, "commit clean");
342 bf_commitClean (rGroupDef.bfs, rval);
345 logf (LOG_LOG, "nothing to clean");
347 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
349 rval = res_get (common_resource, "shadow");
350 zebraIndexLock (rGroupDef.bfs, 0, rval);
353 bf_cache (rGroupDef.bfs, rval);
354 zebraIndexLockMsg ("r");
357 inv_prstat (rGroupDef.bfs);
361 logf (LOG_FATAL, "unknown command: %s", arg);
367 struct recordGroup rGroup;
369 log_event_end (abort_func, NULL);
370 rval = res_get (common_resource, "shadow");
371 zebraIndexLock (rGroupDef.bfs, 0, rval);
372 if (rval && *rval && !disableCommit)
374 bf_cache (rGroupDef.bfs, rval);
375 zebraIndexLockMsg ("r");
379 bf_cache (rGroupDef.bfs, 0);
380 zebraIndexLockMsg ("w");
384 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
389 key_open (rGroup.bfs, mem_max);
390 logf (LOG_LOG, "updating %s", rGroup.path);
391 repositoryUpdate (&rGroup);
392 nsections = key_close ();
395 key_open (rGroup.bfs,mem_max);
396 logf (LOG_LOG, "updating (pass 1) %s", rGroup.path);
397 repositoryUpdate (&rGroup);
402 key_open (rGroup.bfs,mem_max);
403 logf (LOG_LOG, "deleting %s", rGroup.path);
404 repositoryDelete (&rGroup);
405 nsections = key_close ();
408 logf (LOG_LOG, "dumping %s", rGroup.path);
409 repositoryShow (&rGroup);
421 logf (LOG_LOG, "merging with index");
422 key_input (rGroup.bfs, nsections, 60);
427 log_event_end (NULL, NULL);
432 fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
435 log_init (log_mask_str(arg), prog, NULL);
437 mem_max = 1024*1024*atoi(arg);
439 rGroupDef.databaseName = arg;
441 rGroupDef.flagShowRecords = 1;
443 rGroupDef.groupName = arg;
445 rGroupDef.fileVerboseLimit = atoi(arg);
449 rGroupDef.recordType = arg;
454 logf (LOG_FATAL, "unknown option '-%s'", arg);
461 bfs_destroy (rGroupDef.bfs);
463 data1_destroy (rGroupDef.dh);