2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.47 1997-02-12 20:39:46 adam
8 * Implemented options -f <n> that limits the log to the first <n>
10 * Changed some log messages also.
12 * Revision 1.46 1997/02/10 10:20:13 adam
13 * Flag fileVerboseFlag set to 0 (default).
15 * Revision 1.45 1996/11/08 11:10:26 adam
16 * Buffers used during file match got bigger.
17 * Compressed ISAM support everywhere.
18 * Bug fixes regarding masking characters in queries.
19 * Redesigned Regexp-2 queries.
21 * Revision 1.44 1996/10/29 14:09:48 adam
22 * Use of cisam system - enabled if setting isamc is 1.
24 * Revision 1.43 1996/06/06 12:08:42 quinn
25 * Added showRecord function
27 * Revision 1.42 1996/05/31 09:07:01 quinn
28 * Work on character-set handling
30 * Revision 1.41 1996/05/14 14:04:34 adam
31 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
34 * Revision 1.40 1996/04/26 10:00:23 adam
35 * Added option -V to zebraidx to display version information.
36 * Removed stupid warnings from file update.
38 * Revision 1.39 1996/04/09 10:05:21 adam
39 * Bug fix: prev_name buffer possibly too small; allocated in key_file_init.
41 * Revision 1.38 1996/03/26 16:01:14 adam
42 * New setting lockPath: directory of various lock files.
44 * Revision 1.37 1996/03/19 12:43:26 adam
45 * Bug fix: File update traversal didn't handle trailing slashes correctly.
46 * Bug fix: Update of sub directory groups wasn't handled correctly.
48 * Revision 1.36 1996/02/12 18:45:37 adam
49 * New fileVerboseFlag in record group control.
51 * Revision 1.35 1996/02/12 15:56:11 adam
52 * New code command: unread.
54 * Revision 1.34 1996/02/07 14:06:39 adam
55 * Better progress report during register merge.
56 * New command: clean - removes temporary shadow files.
58 * Revision 1.33 1996/02/06 17:11:18 adam
61 * Revision 1.32 1996/02/01 20:50:04 adam
62 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
63 * was never called - happens when no commands are specified.
65 * Revision 1.31 1996/01/08 19:15:46 adam
66 * New input filter that works!
68 * Revision 1.30 1995/12/12 16:00:59 adam
69 * System call sync(2) used after update/commit.
70 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
73 * Revision 1.29 1995/12/11 11:43:30 adam
74 * Locking based on fcntl instead of flock.
75 * Setting commitEnable removed. Command line option -n can be used to
76 * prevent commit if commit setting is defined in the configuration file.
78 * Revision 1.28 1995/12/08 16:22:56 adam
79 * Work on update while servers are running. Three lock files introduced.
80 * The servers reload their registers when necessary, but they don't
81 * reestablish result sets yet.
83 * Revision 1.27 1995/12/07 17:38:47 adam
84 * Work locking mechanisms for concurrent updates/commit.
86 * Revision 1.26 1995/12/06 12:41:23 adam
87 * New command 'stat' for the index program.
88 * Filenames can be read from stdin by specifying '-'.
89 * Bug fix/enhancement of the transformation from terms to regular
90 * expressons in the search engine.
92 * Revision 1.25 1995/12/01 16:24:39 adam
93 * Commit files use separate meta file area.
95 * Revision 1.24 1995/11/30 17:01:38 adam
96 * New setting commitCache: points to commit directories/files.
97 * New command commit: commits at the end of a zebraidx run.
99 * Revision 1.23 1995/11/30 08:34:31 adam
100 * Started work on commit facility.
101 * Changed a few malloc/free to xmalloc/xfree.
103 * Revision 1.22 1995/11/28 09:09:42 adam
104 * Zebra config renamed.
105 * Use setting 'recordId' to identify record now.
106 * Bug fix in recindex.c: rec_release_blocks was invokeded even
107 * though the blocks were already released.
108 * File traversal properly deletes records when needed.
110 * Revision 1.21 1995/11/27 14:27:39 adam
111 * Renamed 'update' command to 'dir'.
113 * Revision 1.20 1995/11/27 13:58:53 adam
114 * New option -t. storeStore data implemented in server.
116 * Revision 1.19 1995/11/25 10:24:06 adam
117 * More record fields - they are enumerated now.
118 * New options: flagStoreData flagStoreKey.
120 * Revision 1.18 1995/11/22 17:19:17 adam
121 * Record management uses the bfile system.
123 * Revision 1.17 1995/11/21 15:01:16 adam
124 * New general match criteria implemented.
125 * New feature: document groups.
127 * Revision 1.16 1995/11/20 11:56:27 adam
128 * Work on new traversal.
130 * Revision 1.15 1995/11/01 16:25:51 quinn
131 * *** empty log message ***
133 * Revision 1.14 1995/10/17 18:02:09 adam
134 * New feature: databases. Implemented as prefix to words in dictionary.
136 * Revision 1.13 1995/10/10 12:24:39 adam
137 * Temporary sort files are compressed.
139 * Revision 1.12 1995/10/04 16:57:20 adam
140 * Key input and merge sort in one pass.
142 * Revision 1.11 1995/09/29 14:01:45 adam
145 * Revision 1.10 1995/09/28 14:22:57 adam
146 * Sort uses smaller temporary files.
148 * Revision 1.9 1995/09/14 07:48:24 adam
149 * Record control management.
151 * Revision 1.8 1995/09/06 16:11:18 adam
152 * Option: only one word key per file.
154 * Revision 1.7 1995/09/05 15:28:39 adam
155 * More work on search engine.
157 * Revision 1.6 1995/09/04 12:33:43 adam
158 * Various cleanup. YAZ util used instead.
160 * Revision 1.5 1995/09/04 09:10:39 adam
161 * More work on index add/del/update.
162 * Merge sort implemented.
163 * Initial work on z39 server.
165 * Revision 1.4 1995/09/01 14:06:36 adam
166 * Split of work into more files.
168 * Revision 1.3 1995/09/01 10:57:07 adam
171 * Revision 1.2 1995/09/01 10:30:24 adam
172 * More work on indexing. Not working yet.
174 * Revision 1.1 1995/08/31 14:50:24 adam
175 * New simple file index tool.
188 static void abort_func (int level, const char *msg, void *info)
190 if (level & LOG_FATAL)
194 int main (int argc, char **argv)
199 char *configName = NULL;
201 int disableCommit = 0;
203 struct recordGroup rGroupDef;
205 rGroupDef.groupName = NULL;
206 rGroupDef.databaseName = NULL;
207 rGroupDef.path = NULL;
208 rGroupDef.recordId = NULL;
209 rGroupDef.recordType = NULL;
210 rGroupDef.flagStoreData = -1;
211 rGroupDef.flagStoreKeys = -1;
212 rGroupDef.flagShowRecords = 0;
213 rGroupDef.fileVerboseLimit = 100000;
218 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
220 " update <dir> Update index with files below <dir>.\n"
221 " If <dir> is empty filenames are read from stdin.\n"
222 " delete <dir> Delete index with files below <dir>.\n"
223 " commit Commit changes\n"
224 " clean Clean shadow files\n"
226 " -t <type> Index files as <type> (grs or text).\n"
227 " -c <config> Read configuration file <config>.\n"
228 " -g <group> Index files according to group settings.\n"
229 " -d <database> Records belong to Z39.50 database <database>.\n"
230 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
231 " -n Don't use shadow system.\n"
232 " -s Show analysis on stdout, but do no work.\n"
233 " -v <level> Set logging to <level>.\n"
234 " -f <n> Display information for the first <n> records.\n"
235 " -V Show version.\n"
239 while ((ret = options ("sVt:c:g:d:m:v:nf:", argv, argc, &arg)) != -2)
244 if(cmd == 0) /* command */
246 if (!common_resource)
248 logf (LOG_LOG, "zebra version %s %s",
249 ZEBRAVER, ZEBRADATE);
250 common_resource = res_open (configName ?
251 configName : FNAME_CONFIG);
252 if (!common_resource)
254 logf (LOG_FATAL, "cannot open resource `%s'",
258 data1_set_tabpath (res_get (common_resource,
260 bf_lockDir (res_get (common_resource, "lockDir"));
263 if (!strcmp (arg, "update"))
265 else if (!strcmp (arg, "update1"))
267 else if (!strcmp (arg, "update2"))
269 else if (!strcmp (arg, "dump"))
271 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
273 else if (!strcmp (arg, "commit"))
276 rval = res_get (common_resource, "shadow");
281 logf (LOG_FATAL, "Cannot perform commit");
282 logf (LOG_FATAL, "No shadow area defined");
285 if (bf_commitExists ())
287 logf (LOG_LOG, "commit start");
288 zebraIndexLockMsg ("c");
290 logf (LOG_LOG, "commit execute");
293 zebraIndexLockMsg ("d");
295 logf (LOG_LOG, "commit clean");
299 logf (LOG_LOG, "cothing to commit");
301 else if (!strcmp (arg, "clean"))
304 if (bf_commitExists ())
306 zebraIndexLockMsg ("d");
308 logf (LOG_LOG, "commit clean");
312 logf (LOG_LOG, "nothing to clean");
314 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
317 rval = res_get (common_resource, "shadow");
321 zebraIndexLockMsg ("r");
328 logf (LOG_FATAL, "unknown command: %s", arg);
334 struct recordGroup rGroup;
336 log_event_end (abort_func, NULL);
338 rval = res_get (common_resource, "shadow");
339 if (rval && *rval && !disableCommit)
342 zebraIndexLockMsg ("r");
347 zebraIndexLockMsg ("w");
351 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
357 logf (LOG_LOG, "updating %s", rGroup.path);
358 repositoryUpdate (&rGroup);
359 nsections = key_close ();
363 logf (LOG_LOG, "updating (pass 1) %s", rGroup.path);
364 repositoryUpdate (&rGroup);
370 logf (LOG_LOG, "deleting %s", rGroup.path);
371 repositoryDelete (&rGroup);
372 nsections = key_close ();
375 logf (LOG_LOG, "dumping %s", rGroup.path);
376 repositoryShow (&rGroup);
388 logf (LOG_LOG, "merging with index");
389 key_input (nsections, 60);
392 log_event_end (NULL, NULL);
397 fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
400 log_init (log_mask_str(arg), prog, NULL);
402 mem_max = 1024*1024*atoi(arg);
404 rGroupDef.databaseName = arg;
406 rGroupDef.flagShowRecords = 1;
408 rGroupDef.groupName = arg;
410 rGroupDef.fileVerboseLimit = atoi(arg);
414 rGroupDef.recordType = arg;
419 logf (LOG_FATAL, "unknown option '-%s'", arg);