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