2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.44 1996-10-29 14:09:48 adam
8 * Use of cisam system - enabled if setting isamc is 1.
10 * Revision 1.43 1996/06/06 12:08:42 quinn
11 * Added showRecord function
13 * Revision 1.42 1996/05/31 09:07:01 quinn
14 * Work on character-set handling
16 * Revision 1.41 1996/05/14 14:04:34 adam
17 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
20 * Revision 1.40 1996/04/26 10:00:23 adam
21 * Added option -V to zebraidx to display version information.
22 * Removed stupid warnings from file update.
24 * Revision 1.39 1996/04/09 10:05:21 adam
25 * Bug fix: prev_name buffer possibly too small; allocated in key_file_init.
27 * Revision 1.38 1996/03/26 16:01:14 adam
28 * New setting lockPath: directory of various lock files.
30 * Revision 1.37 1996/03/19 12:43:26 adam
31 * Bug fix: File update traversal didn't handle trailing slashes correctly.
32 * Bug fix: Update of sub directory groups wasn't handled correctly.
34 * Revision 1.36 1996/02/12 18:45:37 adam
35 * New fileVerboseFlag in record group control.
37 * Revision 1.35 1996/02/12 15:56:11 adam
38 * New code command: unread.
40 * Revision 1.34 1996/02/07 14:06:39 adam
41 * Better progress report during register merge.
42 * New command: clean - removes temporary shadow files.
44 * Revision 1.33 1996/02/06 17:11:18 adam
47 * Revision 1.32 1996/02/01 20:50:04 adam
48 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
49 * was never called - happens when no commands are specified.
51 * Revision 1.31 1996/01/08 19:15:46 adam
52 * New input filter that works!
54 * Revision 1.30 1995/12/12 16:00:59 adam
55 * System call sync(2) used after update/commit.
56 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
59 * Revision 1.29 1995/12/11 11:43:30 adam
60 * Locking based on fcntl instead of flock.
61 * Setting commitEnable removed. Command line option -n can be used to
62 * prevent commit if commit setting is defined in the configuration file.
64 * Revision 1.28 1995/12/08 16:22:56 adam
65 * Work on update while servers are running. Three lock files introduced.
66 * The servers reload their registers when necessary, but they don't
67 * reestablish result sets yet.
69 * Revision 1.27 1995/12/07 17:38:47 adam
70 * Work locking mechanisms for concurrent updates/commit.
72 * Revision 1.26 1995/12/06 12:41:23 adam
73 * New command 'stat' for the index program.
74 * Filenames can be read from stdin by specifying '-'.
75 * Bug fix/enhancement of the transformation from terms to regular
76 * expressons in the search engine.
78 * Revision 1.25 1995/12/01 16:24:39 adam
79 * Commit files use separate meta file area.
81 * Revision 1.24 1995/11/30 17:01:38 adam
82 * New setting commitCache: points to commit directories/files.
83 * New command commit: commits at the end of a zebraidx run.
85 * Revision 1.23 1995/11/30 08:34:31 adam
86 * Started work on commit facility.
87 * Changed a few malloc/free to xmalloc/xfree.
89 * Revision 1.22 1995/11/28 09:09:42 adam
90 * Zebra config renamed.
91 * Use setting 'recordId' to identify record now.
92 * Bug fix in recindex.c: rec_release_blocks was invokeded even
93 * though the blocks were already released.
94 * File traversal properly deletes records when needed.
96 * Revision 1.21 1995/11/27 14:27:39 adam
97 * Renamed 'update' command to 'dir'.
99 * Revision 1.20 1995/11/27 13:58:53 adam
100 * New option -t. storeStore data implemented in server.
102 * Revision 1.19 1995/11/25 10:24:06 adam
103 * More record fields - they are enumerated now.
104 * New options: flagStoreData flagStoreKey.
106 * Revision 1.18 1995/11/22 17:19:17 adam
107 * Record management uses the bfile system.
109 * Revision 1.17 1995/11/21 15:01:16 adam
110 * New general match criteria implemented.
111 * New feature: document groups.
113 * Revision 1.16 1995/11/20 11:56:27 adam
114 * Work on new traversal.
116 * Revision 1.15 1995/11/01 16:25:51 quinn
117 * *** empty log message ***
119 * Revision 1.14 1995/10/17 18:02:09 adam
120 * New feature: databases. Implemented as prefix to words in dictionary.
122 * Revision 1.13 1995/10/10 12:24:39 adam
123 * Temporary sort files are compressed.
125 * Revision 1.12 1995/10/04 16:57:20 adam
126 * Key input and merge sort in one pass.
128 * Revision 1.11 1995/09/29 14:01:45 adam
131 * Revision 1.10 1995/09/28 14:22:57 adam
132 * Sort uses smaller temporary files.
134 * Revision 1.9 1995/09/14 07:48:24 adam
135 * Record control management.
137 * Revision 1.8 1995/09/06 16:11:18 adam
138 * Option: only one word key per file.
140 * Revision 1.7 1995/09/05 15:28:39 adam
141 * More work on search engine.
143 * Revision 1.6 1995/09/04 12:33:43 adam
144 * Various cleanup. YAZ util used instead.
146 * Revision 1.5 1995/09/04 09:10:39 adam
147 * More work on index add/del/update.
148 * Merge sort implemented.
149 * Initial work on z39 server.
151 * Revision 1.4 1995/09/01 14:06:36 adam
152 * Split of work into more files.
154 * Revision 1.3 1995/09/01 10:57:07 adam
157 * Revision 1.2 1995/09/01 10:30:24 adam
158 * More work on indexing. Not working yet.
160 * Revision 1.1 1995/08/31 14:50:24 adam
161 * New simple file index tool.
174 static void abort_func (int level, const char *msg, void *info)
176 if (level & LOG_FATAL)
180 int main (int argc, char **argv)
185 char *configName = NULL;
187 int disableCommit = 0;
189 struct recordGroup rGroupDef;
191 rGroupDef.groupName = NULL;
192 rGroupDef.databaseName = NULL;
193 rGroupDef.path = NULL;
194 rGroupDef.recordId = NULL;
195 rGroupDef.recordType = NULL;
196 rGroupDef.flagStoreData = -1;
197 rGroupDef.flagStoreKeys = -1;
198 rGroupDef.flagShowRecords = 0;
199 rGroupDef.fileVerboseFlag = 1;
204 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
206 " update <dir> Update index with files below <dir>.\n"
207 " If <dir> is empty filenames are read from stdin.\n"
208 " delete <dir> Delete index with files below <dir>.\n"
209 " commit Commit changes\n"
210 " clean Clean shadow files\n"
212 " -t <type> Index files as <type> (grs or text).\n"
213 " -c <config> Read configuration file <config>.\n"
214 " -g <group> Index files according to group settings.\n"
215 " -d <database> Records belong to Z39.50 database <database>.\n"
216 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
217 " -n Don't use shadow system\n"
218 " -s Show analysis on stdout, but do no work\n"
219 " -v <level> Set logging to <level>\n"
224 log_event_end (abort_func, NULL);
225 while ((ret = options ("sVt:c:g:d:m:v:n", argv, argc, &arg)) != -2)
230 if(cmd == 0) /* command */
232 if (!common_resource)
234 common_resource = res_open (configName ?
235 configName : FNAME_CONFIG);
236 if (!common_resource)
238 logf (LOG_FATAL, "Cannot open resource `%s'",
242 data1_set_tabpath (res_get (common_resource,
244 bf_lockDir (res_get (common_resource, "lockDir"));
247 if (!strcmp (arg, "update"))
249 else if (!strcmp (arg, "update1"))
251 else if (!strcmp (arg, "update2"))
253 else if (!strcmp (arg, "dump"))
255 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
257 else if (!strcmp (arg, "commit"))
260 rval = res_get (common_resource, "shadow");
265 logf (LOG_FATAL, "Cannot perform commit");
266 logf (LOG_FATAL, "No shadow area defined");
269 if (bf_commitExists ())
271 logf (LOG_LOG, "Commit start");
272 zebraIndexLockMsg ("c");
274 logf (LOG_LOG, "Commit execute");
277 zebraIndexLockMsg ("d");
279 logf (LOG_LOG, "Commit clean");
283 logf (LOG_LOG, "Nothing to commit");
285 else if (!strcmp (arg, "clean"))
288 if (bf_commitExists ())
290 zebraIndexLockMsg ("d");
292 logf (LOG_LOG, "Commit clean");
296 logf (LOG_LOG, "Nothing to clean");
298 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
301 rval = res_get (common_resource, "shadow");
305 zebraIndexLockMsg ("r");
308 inv_prstat (FNAME_DICT, FNAME_ISAM);
312 logf (LOG_FATAL, "Unknown command: %s", arg);
318 struct recordGroup rGroup;
321 rval = res_get (common_resource, "shadow");
322 if (rval && *rval && !disableCommit)
325 zebraIndexLockMsg ("r");
330 zebraIndexLockMsg ("w");
334 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
340 logf (LOG_LOG, "Updating %s", rGroup.path);
341 repositoryUpdate (&rGroup);
342 nsections = key_close ();
346 logf (LOG_LOG, "Updating (pass 1) %s", rGroup.path);
347 repositoryUpdate (&rGroup);
353 logf (LOG_LOG, "Deleting %s", rGroup.path);
354 repositoryDelete (&rGroup);
355 nsections = key_close ();
358 logf (LOG_LOG, "Dumping %s", rGroup.path);
359 repositoryShow (&rGroup);
371 logf (LOG_LOG, "Merging with index");
372 key_input (nsections, 60);
379 fprintf (stderr, "Zebra %s %s\n",
380 ZEBRAVER, ZEBRADATE);
384 log_init (log_mask_str(arg), prog, NULL);
388 mem_max = 1024*1024*atoi(arg);
392 rGroupDef.databaseName = arg;
396 rGroupDef.flagShowRecords = 1;
400 rGroupDef.groupName = arg;
405 rGroupDef.recordType = arg;
410 logf (LOG_FATAL, "Unknown option '-%s'", arg);