2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.38 1996-03-26 16:01:14 adam
8 * New setting lockPath: directory of various lock files.
10 * Revision 1.37 1996/03/19 12:43:26 adam
11 * Bug fix: File update traversal didn't handle trailing slashes correctly.
12 * Bug fix: Update of sub directory groups wasn't handled correctly.
14 * Revision 1.36 1996/02/12 18:45:37 adam
15 * New fileVerboseFlag in record group control.
17 * Revision 1.35 1996/02/12 15:56:11 adam
18 * New code command: unread.
20 * Revision 1.34 1996/02/07 14:06:39 adam
21 * Better progress report during register merge.
22 * New command: clean - removes temporary shadow files.
24 * Revision 1.33 1996/02/06 17:11:18 adam
27 * Revision 1.32 1996/02/01 20:50:04 adam
28 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
29 * was never called - happens when no commands are specified.
31 * Revision 1.31 1996/01/08 19:15:46 adam
32 * New input filter that works!
34 * Revision 1.30 1995/12/12 16:00:59 adam
35 * System call sync(2) used after update/commit.
36 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
39 * Revision 1.29 1995/12/11 11:43:30 adam
40 * Locking based on fcntl instead of flock.
41 * Setting commitEnable removed. Command line option -n can be used to
42 * prevent commit if commit setting is defined in the configuration file.
44 * Revision 1.28 1995/12/08 16:22:56 adam
45 * Work on update while servers are running. Three lock files introduced.
46 * The servers reload their registers when necessary, but they don't
47 * reestablish result sets yet.
49 * Revision 1.27 1995/12/07 17:38:47 adam
50 * Work locking mechanisms for concurrent updates/commit.
52 * Revision 1.26 1995/12/06 12:41:23 adam
53 * New command 'stat' for the index program.
54 * Filenames can be read from stdin by specifying '-'.
55 * Bug fix/enhancement of the transformation from terms to regular
56 * expressons in the search engine.
58 * Revision 1.25 1995/12/01 16:24:39 adam
59 * Commit files use separate meta file area.
61 * Revision 1.24 1995/11/30 17:01:38 adam
62 * New setting commitCache: points to commit directories/files.
63 * New command commit: commits at the end of a zebraidx run.
65 * Revision 1.23 1995/11/30 08:34:31 adam
66 * Started work on commit facility.
67 * Changed a few malloc/free to xmalloc/xfree.
69 * Revision 1.22 1995/11/28 09:09:42 adam
70 * Zebra config renamed.
71 * Use setting 'recordId' to identify record now.
72 * Bug fix in recindex.c: rec_release_blocks was invokeded even
73 * though the blocks were already released.
74 * File traversal properly deletes records when needed.
76 * Revision 1.21 1995/11/27 14:27:39 adam
77 * Renamed 'update' command to 'dir'.
79 * Revision 1.20 1995/11/27 13:58:53 adam
80 * New option -t. storeStore data implemented in server.
82 * Revision 1.19 1995/11/25 10:24:06 adam
83 * More record fields - they are enumerated now.
84 * New options: flagStoreData flagStoreKey.
86 * Revision 1.18 1995/11/22 17:19:17 adam
87 * Record management uses the bfile system.
89 * Revision 1.17 1995/11/21 15:01:16 adam
90 * New general match criteria implemented.
91 * New feature: document groups.
93 * Revision 1.16 1995/11/20 11:56:27 adam
94 * Work on new traversal.
96 * Revision 1.15 1995/11/01 16:25:51 quinn
97 * *** empty log message ***
99 * Revision 1.14 1995/10/17 18:02:09 adam
100 * New feature: databases. Implemented as prefix to words in dictionary.
102 * Revision 1.13 1995/10/10 12:24:39 adam
103 * Temporary sort files are compressed.
105 * Revision 1.12 1995/10/04 16:57:20 adam
106 * Key input and merge sort in one pass.
108 * Revision 1.11 1995/09/29 14:01:45 adam
111 * Revision 1.10 1995/09/28 14:22:57 adam
112 * Sort uses smaller temporary files.
114 * Revision 1.9 1995/09/14 07:48:24 adam
115 * Record control management.
117 * Revision 1.8 1995/09/06 16:11:18 adam
118 * Option: only one word key per file.
120 * Revision 1.7 1995/09/05 15:28:39 adam
121 * More work on search engine.
123 * Revision 1.6 1995/09/04 12:33:43 adam
124 * Various cleanup. YAZ util used instead.
126 * Revision 1.5 1995/09/04 09:10:39 adam
127 * More work on index add/del/update.
128 * Merge sort implemented.
129 * Initial work on z39 server.
131 * Revision 1.4 1995/09/01 14:06:36 adam
132 * Split of work into more files.
134 * Revision 1.3 1995/09/01 10:57:07 adam
137 * Revision 1.2 1995/09/01 10:30:24 adam
138 * More work on indexing. Not working yet.
140 * Revision 1.1 1995/08/31 14:50:24 adam
141 * New simple file index tool.
148 #include <alexutil.h>
153 size_t mem_max = 4*1024*1024;
154 extern char *data1_tabpath;
156 static void abort_func (int level, const char *msg, void *info)
158 if (level & LOG_FATAL)
162 int main (int argc, char **argv)
167 char *configName = NULL;
169 int disableCommit = 0;
171 struct recordGroup rGroupDef;
173 rGroupDef.groupName = NULL;
174 rGroupDef.databaseName = NULL;
175 rGroupDef.path = NULL;
176 rGroupDef.recordId = NULL;
177 rGroupDef.recordType = NULL;
178 rGroupDef.flagStoreData = -1;
179 rGroupDef.flagStoreKeys = -1;
180 rGroupDef.fileVerboseFlag = 1;
185 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
187 " update <dir> Update index with files below <dir>.\n"
188 " If <dir> is empty filenames are read from stdin.\n"
189 " delete <dir> Delete index with files below <dir>.\n"
190 " commit Commit changes\n"
191 " clean Clean shadow files\n"
193 " -t <type> Index files as <type> (grs or text).\n"
194 " -c <config> Read configuration file <config>.\n"
195 " -g <group> Index files according to group settings.\n"
196 " -d <database> Records belong to Z39.50 database <database>.\n"
197 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
198 " -n Don't use shadow system\n"
199 " -v <level> Set logging to <level>.\n");
202 log_event_end (abort_func, NULL);
203 while ((ret = options ("t:c:g:d:m:v:n", argv, argc, &arg)) != -2)
208 if(cmd == 0) /* command */
210 if (!common_resource)
212 common_resource = res_open (configName ?
213 configName : FNAME_CONFIG);
214 if (!common_resource)
216 logf (LOG_FATAL, "Cannot open resource `%s'",
220 data1_tabpath = res_get (common_resource, "profilePath");
221 bf_lockDir (res_get (common_resource, "lockPath"));
223 if (!strcmp (arg, "update"))
225 else if (!strcmp (arg, "dump"))
227 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
229 else if (!strcmp (arg, "commit"))
232 rval = res_get (common_resource, "shadow");
237 logf (LOG_FATAL, "Cannot perform commit");
238 logf (LOG_FATAL, "No shadow area defined");
241 if (bf_commitExists ())
243 logf (LOG_LOG, "Commit start");
244 zebraIndexLockMsg ("c");
246 logf (LOG_LOG, "Commit execute");
249 zebraIndexLockMsg ("d");
251 logf (LOG_LOG, "Commit clean");
255 logf (LOG_LOG, "Nothing to commit");
257 else if (!strcmp (arg, "clean"))
260 if (bf_commitExists ())
262 zebraIndexLockMsg ("d");
264 logf (LOG_LOG, "Commit clean");
268 logf (LOG_LOG, "Nothing to clean");
270 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
273 rval = res_get (common_resource, "shadow");
277 zebraIndexLockMsg ("r");
283 logf (LOG_FATAL, "Unknown command: %s", arg);
289 struct recordGroup rGroup;
292 rval = res_get (common_resource, "shadow");
293 if (rval && *rval && !disableCommit)
296 zebraIndexLockMsg ("r");
301 zebraIndexLockMsg ("w");
305 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
310 logf (LOG_LOG, "Updating %s", rGroup.path);
311 repositoryUpdate (&rGroup);
315 logf (LOG_LOG, "Deleting %s", rGroup.path);
316 repositoryDelete (&rGroup);
320 logf (LOG_LOG, "Dumping %s", rGroup.path);
321 repositoryShow (&rGroup);
325 nsections = key_close ();
328 logf (LOG_LOG, "Merging with index");
329 key_input (FNAME_WORD_DICT, FNAME_WORD_ISAM, nsections,
337 log_init (log_mask_str(arg), prog, NULL);
341 mem_max = 1024*1024*atoi(arg);
345 rGroupDef.databaseName = arg;
349 rGroupDef.groupName = arg;
354 rGroupDef.recordType = arg;
359 logf (LOG_FATAL, "Unknown option '-%s'", arg);