2 * Copyright (C) 1994-2002, Index Data
5 * $Id: main.c,v 1.92 2002-07-11 13:03:01 heikki Exp $
18 #include <sys/times.h>
21 #include <yaz/data1.h>
26 int main (int argc, char **argv)
33 int disableCommit = 0;
36 struct tms tms1, tms2;
37 struct timeval start_time, end_time;
43 struct recordGroup rGroupDef;
51 sprintf(nbuf, "%.40s(%d)", *argv, getpid());
52 yaz_log_init_prefix (nbuf);
56 gettimeofday(&start_time, 0);
59 rGroupDef.groupName = NULL;
60 rGroupDef.databaseName = NULL;
61 rGroupDef.path = NULL;
62 rGroupDef.recordId = NULL;
63 rGroupDef.recordType = NULL;
64 rGroupDef.flagStoreData = -1;
65 rGroupDef.flagStoreKeys = -1;
67 rGroupDef.databaseNamePath = 0;
68 rGroupDef.explainDatabase = 0;
69 rGroupDef.fileVerboseLimit = 100000;
74 fprintf (stderr, "%s [options] command <dir> ...\n"
76 " update <dir> Update index with files below <dir>.\n"
77 " If <dir> is empty filenames are read from stdin.\n"
78 " delete <dir> Delete index with files below <dir>.\n"
79 " commit Commit changes\n"
80 " clean Clean shadow files\n"
82 " -t <type> Index files as <type> (grs or text).\n"
83 " -c <config> Read configuration file <config>.\n"
84 " -g <group> Index files according to group settings.\n"
85 " -d <database> Records belong to Z39.50 database <database>.\n"
86 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
87 " -n Don't use shadow system.\n"
88 " -s Show analysis on stdout, but do no work.\n"
89 " -v <level> Set logging to <level>.\n"
90 " -l <file> Write log to <file>.\n"
91 " -f <n> Display information for the first <n> records.\n"
92 " -V Show version.\n", *argv
96 while ((ret = options ("sVt:c:g:d:m:v:nf:l:"
97 , argv, argc, &arg)) != -2)
101 if(cmd == 0) /* command */
106 logf (LOG_LOG, "Z'mbol version %s %s",
107 ZEBRAVER, ZEBRADATE);
109 logf (LOG_LOG, "Zebra version %s %s",
110 ZEBRAVER, ZEBRADATE);
112 zs = zebra_start (configName ? configName : "zebra.cfg");
115 zh = zebra_open (zs);
117 zebra_shadow_enable (zh, 0);
119 if (rGroupDef.databaseName)
121 if (zebra_select_database (zh, rGroupDef.databaseName))
126 if (zebra_select_database (zh, "Default"))
130 if (!strcmp (arg, "update"))
132 else if (!strcmp (arg, "update1"))
134 else if (!strcmp (arg, "update2"))
136 else if (!strcmp (arg, "dump"))
138 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
140 else if (!strcmp (arg, "init"))
144 else if (!strcmp (arg, "commit"))
148 else if (!strcmp (arg, "clean"))
152 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
154 zebra_register_statistics (zh,0);
156 else if (!strcmp (arg, "dump") || !strcmp (arg, "dumpdict"))
158 zebra_register_statistics (zh,1);
160 else if (!strcmp (arg, "compact"))
166 logf (LOG_FATAL, "unknown command: %s", arg);
172 rGroupDef.path = arg;
173 zebra_set_group (zh, &rGroupDef);
174 zebra_begin_trans (zh);
179 zebra_repository_update (zh);
182 zebra_repository_delete (zh);
185 logf (LOG_LOG, "dumping %s", rGroupDef.path);
186 zebra_repository_show (zh);
193 zebra_end_trans (zh);
194 log_event_end (NULL, NULL);
200 fprintf (stderr, "Z'mbol %s %s\n", ZEBRAVER, ZEBRADATE);
202 fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
204 fprintf (stderr, " (C) 1994-2002, Index Data ApS\n");
207 fprintf (stderr, " WIN32 Debug\n");
209 fprintf (stderr, " WIN32 Release\n");
213 fprintf (stderr, "libbzip2\n"
214 " (C) 1996-1999 Julian R Seward. All rights reserved.\n");
218 yaz_log_init_level (yaz_log_mask_str(arg));
220 yaz_log_init_file (arg);
222 mem_max = 1024*1024*atoi(arg);
224 rGroupDef.databaseName = arg;
226 rGroupDef.flagRw = 0;
228 rGroupDef.groupName = arg;
230 rGroupDef.fileVerboseLimit = atoi(arg);
234 rGroupDef.recordType = arg;
238 logf (LOG_WARN, "unknown option '-%s'", arg);
243 gettimeofday(&end_time, 0);
244 usec = (end_time.tv_sec - start_time.tv_sec) * 1000000L +
245 end_time.tv_usec - start_time.tv_usec;
247 yaz_log (LOG_LOG, "zebraidx times: %5.2f %5.2f %5.2f",
248 (double) usec / 1000000.0,
249 (double) (tms2.tms_utime - tms1.tms_utime)/100,
250 (double) (tms2.tms_stime - tms1.tms_stime)/100);