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