2 * Copyright (C) 1994-2002, Index Data
5 * $Id: main.c,v 1.91 2002-06-19 13:19:43 adam 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);
156 else if (!strcmp (arg, "compact"))
162 logf (LOG_FATAL, "unknown command: %s", arg);
168 rGroupDef.path = arg;
169 zebra_set_group (zh, &rGroupDef);
170 zebra_begin_trans (zh);
175 zebra_repository_update (zh);
178 zebra_repository_delete (zh);
181 logf (LOG_LOG, "dumping %s", rGroupDef.path);
182 zebra_repository_show (zh);
189 zebra_end_trans (zh);
190 log_event_end (NULL, NULL);
196 fprintf (stderr, "Z'mbol %s %s\n", ZEBRAVER, ZEBRADATE);
198 fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
200 fprintf (stderr, " (C) 1994-2002, Index Data ApS\n");
203 fprintf (stderr, " WIN32 Debug\n");
205 fprintf (stderr, " WIN32 Release\n");
209 fprintf (stderr, "libbzip2\n"
210 " (C) 1996-1999 Julian R Seward. All rights reserved.\n");
214 yaz_log_init_level (yaz_log_mask_str(arg));
216 yaz_log_init_file (arg);
218 mem_max = 1024*1024*atoi(arg);
220 rGroupDef.databaseName = arg;
222 rGroupDef.flagRw = 0;
224 rGroupDef.groupName = arg;
226 rGroupDef.fileVerboseLimit = atoi(arg);
230 rGroupDef.recordType = arg;
234 logf (LOG_WARN, "unknown option '-%s'", arg);
239 gettimeofday(&end_time, 0);
240 usec = (end_time.tv_sec - start_time.tv_sec) * 1000000L +
241 end_time.tv_usec - start_time.tv_usec;
243 yaz_log (LOG_LOG, "zebraidx times: %5.2f %5.2f %5.2f",
244 (double) usec / 1000000.0,
245 (double) (tms2.tms_utime - tms1.tms_utime)/100,
246 (double) (tms2.tms_stime - tms1.tms_stime)/100);