2 * Copyright (C) 1994-1997, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.49 1997-09-17 12:19:15 adam
8 * Zebra version corresponds to YAZ version 1.4.
9 * Changed Zebra server so that it doesn't depend on global common_resource.
11 * Revision 1.48 1997/09/09 13:38:08 adam
12 * Partial port to WIN95/NT.
14 * Revision 1.47 1997/02/12 20:39:46 adam
15 * Implemented options -f <n> that limits the log to the first <n>
17 * Changed some log messages also.
19 * Revision 1.46 1997/02/10 10:20:13 adam
20 * Flag fileVerboseFlag set to 0 (default).
22 * Revision 1.45 1996/11/08 11:10:26 adam
23 * Buffers used during file match got bigger.
24 * Compressed ISAM support everywhere.
25 * Bug fixes regarding masking characters in queries.
26 * Redesigned Regexp-2 queries.
28 * Revision 1.44 1996/10/29 14:09:48 adam
29 * Use of cisam system - enabled if setting isamc is 1.
31 * Revision 1.43 1996/06/06 12:08:42 quinn
32 * Added showRecord function
34 * Revision 1.42 1996/05/31 09:07:01 quinn
35 * Work on character-set handling
37 * Revision 1.41 1996/05/14 14:04:34 adam
38 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
41 * Revision 1.40 1996/04/26 10:00:23 adam
42 * Added option -V to zebraidx to display version information.
43 * Removed stupid warnings from file update.
45 * Revision 1.39 1996/04/09 10:05:21 adam
46 * Bug fix: prev_name buffer possibly too small; allocated in key_file_init.
48 * Revision 1.38 1996/03/26 16:01:14 adam
49 * New setting lockPath: directory of various lock files.
51 * Revision 1.37 1996/03/19 12:43:26 adam
52 * Bug fix: File update traversal didn't handle trailing slashes correctly.
53 * Bug fix: Update of sub directory groups wasn't handled correctly.
55 * Revision 1.36 1996/02/12 18:45:37 adam
56 * New fileVerboseFlag in record group control.
58 * Revision 1.35 1996/02/12 15:56:11 adam
59 * New code command: unread.
61 * Revision 1.34 1996/02/07 14:06:39 adam
62 * Better progress report during register merge.
63 * New command: clean - removes temporary shadow files.
65 * Revision 1.33 1996/02/06 17:11:18 adam
68 * Revision 1.32 1996/02/01 20:50:04 adam
69 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
70 * was never called - happens when no commands are specified.
72 * Revision 1.31 1996/01/08 19:15:46 adam
73 * New input filter that works!
75 * Revision 1.30 1995/12/12 16:00:59 adam
76 * System call sync(2) used after update/commit.
77 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
80 * Revision 1.29 1995/12/11 11:43:30 adam
81 * Locking based on fcntl instead of flock.
82 * Setting commitEnable removed. Command line option -n can be used to
83 * prevent commit if commit setting is defined in the configuration file.
85 * Revision 1.28 1995/12/08 16:22:56 adam
86 * Work on update while servers are running. Three lock files introduced.
87 * The servers reload their registers when necessary, but they don't
88 * reestablish result sets yet.
90 * Revision 1.27 1995/12/07 17:38:47 adam
91 * Work locking mechanisms for concurrent updates/commit.
93 * Revision 1.26 1995/12/06 12:41:23 adam
94 * New command 'stat' for the index program.
95 * Filenames can be read from stdin by specifying '-'.
96 * Bug fix/enhancement of the transformation from terms to regular
97 * expressons in the search engine.
99 * Revision 1.25 1995/12/01 16:24:39 adam
100 * Commit files use separate meta file area.
102 * Revision 1.24 1995/11/30 17:01:38 adam
103 * New setting commitCache: points to commit directories/files.
104 * New command commit: commits at the end of a zebraidx run.
106 * Revision 1.23 1995/11/30 08:34:31 adam
107 * Started work on commit facility.
108 * Changed a few malloc/free to xmalloc/xfree.
110 * Revision 1.22 1995/11/28 09:09:42 adam
111 * Zebra config renamed.
112 * Use setting 'recordId' to identify record now.
113 * Bug fix in recindex.c: rec_release_blocks was invokeded even
114 * though the blocks were already released.
115 * File traversal properly deletes records when needed.
117 * Revision 1.21 1995/11/27 14:27:39 adam
118 * Renamed 'update' command to 'dir'.
120 * Revision 1.20 1995/11/27 13:58:53 adam
121 * New option -t. storeStore data implemented in server.
123 * Revision 1.19 1995/11/25 10:24:06 adam
124 * More record fields - they are enumerated now.
125 * New options: flagStoreData flagStoreKey.
127 * Revision 1.18 1995/11/22 17:19:17 adam
128 * Record management uses the bfile system.
130 * Revision 1.17 1995/11/21 15:01:16 adam
131 * New general match criteria implemented.
132 * New feature: document groups.
134 * Revision 1.16 1995/11/20 11:56:27 adam
135 * Work on new traversal.
137 * Revision 1.15 1995/11/01 16:25:51 quinn
138 * *** empty log message ***
140 * Revision 1.14 1995/10/17 18:02:09 adam
141 * New feature: databases. Implemented as prefix to words in dictionary.
143 * Revision 1.13 1995/10/10 12:24:39 adam
144 * Temporary sort files are compressed.
146 * Revision 1.12 1995/10/04 16:57:20 adam
147 * Key input and merge sort in one pass.
149 * Revision 1.11 1995/09/29 14:01:45 adam
152 * Revision 1.10 1995/09/28 14:22:57 adam
153 * Sort uses smaller temporary files.
155 * Revision 1.9 1995/09/14 07:48:24 adam
156 * Record control management.
158 * Revision 1.8 1995/09/06 16:11:18 adam
159 * Option: only one word key per file.
161 * Revision 1.7 1995/09/05 15:28:39 adam
162 * More work on search engine.
164 * Revision 1.6 1995/09/04 12:33:43 adam
165 * Various cleanup. YAZ util used instead.
167 * Revision 1.5 1995/09/04 09:10:39 adam
168 * More work on index add/del/update.
169 * Merge sort implemented.
170 * Initial work on z39 server.
172 * Revision 1.4 1995/09/01 14:06:36 adam
173 * Split of work into more files.
175 * Revision 1.3 1995/09/01 10:57:07 adam
178 * Revision 1.2 1995/09/01 10:30:24 adam
179 * More work on indexing. Not working yet.
181 * Revision 1.1 1995/08/31 14:50:24 adam
182 * New simple file index tool.
199 Res common_resource = 0;
201 static void abort_func (int level, const char *msg, void *info)
203 if (level & LOG_FATAL)
207 int main (int argc, char **argv)
212 char *configName = NULL;
214 int disableCommit = 0;
216 struct recordGroup rGroupDef;
218 rGroupDef.groupName = NULL;
219 rGroupDef.databaseName = NULL;
220 rGroupDef.path = NULL;
221 rGroupDef.recordId = NULL;
222 rGroupDef.recordType = NULL;
223 rGroupDef.flagStoreData = -1;
224 rGroupDef.flagStoreKeys = -1;
225 rGroupDef.flagShowRecords = 0;
226 rGroupDef.fileVerboseLimit = 100000;
227 rGroupDef.dh = data1_create ();
232 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
234 " update <dir> Update index with files below <dir>.\n"
235 " If <dir> is empty filenames are read from stdin.\n"
236 " delete <dir> Delete index with files below <dir>.\n"
237 " commit Commit changes\n"
238 " clean Clean shadow files\n"
240 " -t <type> Index files as <type> (grs or text).\n"
241 " -c <config> Read configuration file <config>.\n"
242 " -g <group> Index files according to group settings.\n"
243 " -d <database> Records belong to Z39.50 database <database>.\n"
244 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
245 " -n Don't use shadow system.\n"
246 " -s Show analysis on stdout, but do no work.\n"
247 " -v <level> Set logging to <level>.\n"
248 " -f <n> Display information for the first <n> records.\n"
249 " -V Show version.\n"
253 while ((ret = options ("sVt:c:g:d:m:v:nf:", argv, argc, &arg)) != -2)
258 if(cmd == 0) /* command */
260 if (!common_resource)
262 logf (LOG_LOG, "zebra version %s %s",
263 ZEBRAVER, ZEBRADATE);
264 common_resource = res_open (configName ?
265 configName : FNAME_CONFIG);
266 if (!common_resource)
268 logf (LOG_FATAL, "cannot open resource `%s'",
272 data1_set_tabpath (rGroupDef.dh, res_get (common_resource,
276 bfs_create (res_get (common_resource, "register"));
278 bf_lockDir (rGroupDef.bfs,
279 res_get (common_resource, "lockDir"));
280 init_charmap(common_resource);
282 if (!strcmp (arg, "update"))
284 else if (!strcmp (arg, "update1"))
286 else if (!strcmp (arg, "update2"))
288 else if (!strcmp (arg, "dump"))
290 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
292 else if (!strcmp (arg, "commit"))
294 rval = res_get (common_resource, "shadow");
295 zebraIndexLock (rGroupDef.bfs, 1, rval);
297 bf_cache (rGroupDef.bfs, rval);
300 logf (LOG_FATAL, "Cannot perform commit");
301 logf (LOG_FATAL, "No shadow area defined");
304 if (bf_commitExists (rGroupDef.bfs))
306 logf (LOG_LOG, "commit start");
307 zebraIndexLockMsg ("c");
309 logf (LOG_LOG, "commit execute");
310 bf_commitExec (rGroupDef.bfs);
312 zebraIndexLockMsg ("d");
314 logf (LOG_LOG, "commit clean");
315 bf_commitClean (rGroupDef.bfs, rval);
318 logf (LOG_LOG, "cothing to commit");
320 else if (!strcmp (arg, "clean"))
322 rval = res_get (common_resource, "shadow");
323 zebraIndexLock (rGroupDef.bfs, 1, rval);
324 if (bf_commitExists (rGroupDef.bfs))
326 zebraIndexLockMsg ("d");
328 logf (LOG_LOG, "commit clean");
329 bf_commitClean (rGroupDef.bfs, rval);
332 logf (LOG_LOG, "nothing to clean");
334 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
336 rval = res_get (common_resource, "shadow");
337 zebraIndexLock (rGroupDef.bfs, 0, rval);
340 bf_cache (rGroupDef.bfs, rval);
341 zebraIndexLockMsg ("r");
344 inv_prstat (rGroupDef.bfs);
348 logf (LOG_FATAL, "unknown command: %s", arg);
354 struct recordGroup rGroup;
356 log_event_end (abort_func, NULL);
357 rval = res_get (common_resource, "shadow");
358 zebraIndexLock (rGroupDef.bfs, 0, rval);
359 if (rval && *rval && !disableCommit)
361 bf_cache (rGroupDef.bfs, rval);
362 zebraIndexLockMsg ("r");
366 bf_cache (rGroupDef.bfs, 0);
367 zebraIndexLockMsg ("w");
371 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
376 key_open (rGroup.bfs, mem_max);
377 logf (LOG_LOG, "updating %s", rGroup.path);
378 repositoryUpdate (&rGroup);
379 nsections = key_close ();
382 key_open (rGroup.bfs,mem_max);
383 logf (LOG_LOG, "updating (pass 1) %s", rGroup.path);
384 repositoryUpdate (&rGroup);
389 key_open (rGroup.bfs,mem_max);
390 logf (LOG_LOG, "deleting %s", rGroup.path);
391 repositoryDelete (&rGroup);
392 nsections = key_close ();
395 logf (LOG_LOG, "dumping %s", rGroup.path);
396 repositoryShow (&rGroup);
408 logf (LOG_LOG, "merging with index");
409 key_input (rGroup.bfs, nsections, 60);
412 log_event_end (NULL, NULL);
417 fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
420 log_init (log_mask_str(arg), prog, NULL);
422 mem_max = 1024*1024*atoi(arg);
424 rGroupDef.databaseName = arg;
426 rGroupDef.flagShowRecords = 1;
428 rGroupDef.groupName = arg;
430 rGroupDef.fileVerboseLimit = atoi(arg);
434 rGroupDef.recordType = arg;
439 logf (LOG_FATAL, "unknown option '-%s'", arg);
446 bfs_destroy (rGroupDef.bfs);
448 data1_destroy (rGroupDef.dh);