2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.46 1997-02-10 10:20:13 adam
8 * Flag fileVerboseFlag set to 0 (default).
10 * Revision 1.45 1996/11/08 11:10:26 adam
11 * Buffers used during file match got bigger.
12 * Compressed ISAM support everywhere.
13 * Bug fixes regarding masking characters in queries.
14 * Redesigned Regexp-2 queries.
16 * Revision 1.44 1996/10/29 14:09:48 adam
17 * Use of cisam system - enabled if setting isamc is 1.
19 * Revision 1.43 1996/06/06 12:08:42 quinn
20 * Added showRecord function
22 * Revision 1.42 1996/05/31 09:07:01 quinn
23 * Work on character-set handling
25 * Revision 1.41 1996/05/14 14:04:34 adam
26 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
29 * Revision 1.40 1996/04/26 10:00:23 adam
30 * Added option -V to zebraidx to display version information.
31 * Removed stupid warnings from file update.
33 * Revision 1.39 1996/04/09 10:05:21 adam
34 * Bug fix: prev_name buffer possibly too small; allocated in key_file_init.
36 * Revision 1.38 1996/03/26 16:01:14 adam
37 * New setting lockPath: directory of various lock files.
39 * Revision 1.37 1996/03/19 12:43:26 adam
40 * Bug fix: File update traversal didn't handle trailing slashes correctly.
41 * Bug fix: Update of sub directory groups wasn't handled correctly.
43 * Revision 1.36 1996/02/12 18:45:37 adam
44 * New fileVerboseFlag in record group control.
46 * Revision 1.35 1996/02/12 15:56:11 adam
47 * New code command: unread.
49 * Revision 1.34 1996/02/07 14:06:39 adam
50 * Better progress report during register merge.
51 * New command: clean - removes temporary shadow files.
53 * Revision 1.33 1996/02/06 17:11:18 adam
56 * Revision 1.32 1996/02/01 20:50:04 adam
57 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
58 * was never called - happens when no commands are specified.
60 * Revision 1.31 1996/01/08 19:15:46 adam
61 * New input filter that works!
63 * Revision 1.30 1995/12/12 16:00:59 adam
64 * System call sync(2) used after update/commit.
65 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
68 * Revision 1.29 1995/12/11 11:43:30 adam
69 * Locking based on fcntl instead of flock.
70 * Setting commitEnable removed. Command line option -n can be used to
71 * prevent commit if commit setting is defined in the configuration file.
73 * Revision 1.28 1995/12/08 16:22:56 adam
74 * Work on update while servers are running. Three lock files introduced.
75 * The servers reload their registers when necessary, but they don't
76 * reestablish result sets yet.
78 * Revision 1.27 1995/12/07 17:38:47 adam
79 * Work locking mechanisms for concurrent updates/commit.
81 * Revision 1.26 1995/12/06 12:41:23 adam
82 * New command 'stat' for the index program.
83 * Filenames can be read from stdin by specifying '-'.
84 * Bug fix/enhancement of the transformation from terms to regular
85 * expressons in the search engine.
87 * Revision 1.25 1995/12/01 16:24:39 adam
88 * Commit files use separate meta file area.
90 * Revision 1.24 1995/11/30 17:01:38 adam
91 * New setting commitCache: points to commit directories/files.
92 * New command commit: commits at the end of a zebraidx run.
94 * Revision 1.23 1995/11/30 08:34:31 adam
95 * Started work on commit facility.
96 * Changed a few malloc/free to xmalloc/xfree.
98 * Revision 1.22 1995/11/28 09:09:42 adam
99 * Zebra config renamed.
100 * Use setting 'recordId' to identify record now.
101 * Bug fix in recindex.c: rec_release_blocks was invokeded even
102 * though the blocks were already released.
103 * File traversal properly deletes records when needed.
105 * Revision 1.21 1995/11/27 14:27:39 adam
106 * Renamed 'update' command to 'dir'.
108 * Revision 1.20 1995/11/27 13:58:53 adam
109 * New option -t. storeStore data implemented in server.
111 * Revision 1.19 1995/11/25 10:24:06 adam
112 * More record fields - they are enumerated now.
113 * New options: flagStoreData flagStoreKey.
115 * Revision 1.18 1995/11/22 17:19:17 adam
116 * Record management uses the bfile system.
118 * Revision 1.17 1995/11/21 15:01:16 adam
119 * New general match criteria implemented.
120 * New feature: document groups.
122 * Revision 1.16 1995/11/20 11:56:27 adam
123 * Work on new traversal.
125 * Revision 1.15 1995/11/01 16:25:51 quinn
126 * *** empty log message ***
128 * Revision 1.14 1995/10/17 18:02:09 adam
129 * New feature: databases. Implemented as prefix to words in dictionary.
131 * Revision 1.13 1995/10/10 12:24:39 adam
132 * Temporary sort files are compressed.
134 * Revision 1.12 1995/10/04 16:57:20 adam
135 * Key input and merge sort in one pass.
137 * Revision 1.11 1995/09/29 14:01:45 adam
140 * Revision 1.10 1995/09/28 14:22:57 adam
141 * Sort uses smaller temporary files.
143 * Revision 1.9 1995/09/14 07:48:24 adam
144 * Record control management.
146 * Revision 1.8 1995/09/06 16:11:18 adam
147 * Option: only one word key per file.
149 * Revision 1.7 1995/09/05 15:28:39 adam
150 * More work on search engine.
152 * Revision 1.6 1995/09/04 12:33:43 adam
153 * Various cleanup. YAZ util used instead.
155 * Revision 1.5 1995/09/04 09:10:39 adam
156 * More work on index add/del/update.
157 * Merge sort implemented.
158 * Initial work on z39 server.
160 * Revision 1.4 1995/09/01 14:06:36 adam
161 * Split of work into more files.
163 * Revision 1.3 1995/09/01 10:57:07 adam
166 * Revision 1.2 1995/09/01 10:30:24 adam
167 * More work on indexing. Not working yet.
169 * Revision 1.1 1995/08/31 14:50:24 adam
170 * New simple file index tool.
183 static void abort_func (int level, const char *msg, void *info)
185 if (level & LOG_FATAL)
189 int main (int argc, char **argv)
194 char *configName = NULL;
196 int disableCommit = 0;
198 struct recordGroup rGroupDef;
200 rGroupDef.groupName = NULL;
201 rGroupDef.databaseName = NULL;
202 rGroupDef.path = NULL;
203 rGroupDef.recordId = NULL;
204 rGroupDef.recordType = NULL;
205 rGroupDef.flagStoreData = -1;
206 rGroupDef.flagStoreKeys = -1;
207 rGroupDef.flagShowRecords = 0;
208 rGroupDef.fileVerboseFlag = 0;
213 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
215 " update <dir> Update index with files below <dir>.\n"
216 " If <dir> is empty filenames are read from stdin.\n"
217 " delete <dir> Delete index with files below <dir>.\n"
218 " commit Commit changes\n"
219 " clean Clean shadow files\n"
221 " -t <type> Index files as <type> (grs or text).\n"
222 " -c <config> Read configuration file <config>.\n"
223 " -g <group> Index files according to group settings.\n"
224 " -d <database> Records belong to Z39.50 database <database>.\n"
225 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
226 " -n Don't use shadow system\n"
227 " -s Show analysis on stdout, but do no work\n"
228 " -v <level> Set logging to <level>\n"
233 log_event_end (abort_func, NULL);
234 while ((ret = options ("sVt:c:g:d:m:v:n", argv, argc, &arg)) != -2)
239 if(cmd == 0) /* command */
241 if (!common_resource)
243 common_resource = res_open (configName ?
244 configName : FNAME_CONFIG);
245 if (!common_resource)
247 logf (LOG_FATAL, "Cannot open resource `%s'",
251 data1_set_tabpath (res_get (common_resource,
253 bf_lockDir (res_get (common_resource, "lockDir"));
256 if (!strcmp (arg, "update"))
258 else if (!strcmp (arg, "update1"))
260 else if (!strcmp (arg, "update2"))
262 else if (!strcmp (arg, "dump"))
264 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
266 else if (!strcmp (arg, "commit"))
269 rval = res_get (common_resource, "shadow");
274 logf (LOG_FATAL, "Cannot perform commit");
275 logf (LOG_FATAL, "No shadow area defined");
278 if (bf_commitExists ())
280 logf (LOG_LOG, "Commit start");
281 zebraIndexLockMsg ("c");
283 logf (LOG_LOG, "Commit execute");
286 zebraIndexLockMsg ("d");
288 logf (LOG_LOG, "Commit clean");
292 logf (LOG_LOG, "Nothing to commit");
294 else if (!strcmp (arg, "clean"))
297 if (bf_commitExists ())
299 zebraIndexLockMsg ("d");
301 logf (LOG_LOG, "Commit clean");
305 logf (LOG_LOG, "Nothing to clean");
307 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
310 rval = res_get (common_resource, "shadow");
314 zebraIndexLockMsg ("r");
321 logf (LOG_FATAL, "Unknown command: %s", arg);
327 struct recordGroup rGroup;
330 rval = res_get (common_resource, "shadow");
331 if (rval && *rval && !disableCommit)
334 zebraIndexLockMsg ("r");
339 zebraIndexLockMsg ("w");
343 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
349 logf (LOG_LOG, "Updating %s", rGroup.path);
350 repositoryUpdate (&rGroup);
351 nsections = key_close ();
355 logf (LOG_LOG, "Updating (pass 1) %s", rGroup.path);
356 repositoryUpdate (&rGroup);
362 logf (LOG_LOG, "Deleting %s", rGroup.path);
363 repositoryDelete (&rGroup);
364 nsections = key_close ();
367 logf (LOG_LOG, "Dumping %s", rGroup.path);
368 repositoryShow (&rGroup);
380 logf (LOG_LOG, "Merging with index");
381 key_input (nsections, 60);
388 fprintf (stderr, "Zebra %s %s\n",
389 ZEBRAVER, ZEBRADATE);
393 log_init (log_mask_str(arg), prog, NULL);
397 mem_max = 1024*1024*atoi(arg);
401 rGroupDef.databaseName = arg;
405 rGroupDef.flagShowRecords = 1;
406 rGroupDef.fileVerboseFlag = 1;
410 rGroupDef.groupName = arg;
415 rGroupDef.recordType = arg;
420 logf (LOG_FATAL, "Unknown option '-%s'", arg);