2 * Copyright (C) 1994-2002, Index Data
5 * $Id: main.c,v 1.90 2002-06-19 11:37:11 adam Exp $
17 #include <sys/times.h>
20 #include <yaz/data1.h>
25 int main (int argc, char **argv)
32 int disableCommit = 0;
35 struct tms tms1, tms2;
36 struct timeval start_time, end_time;
42 struct recordGroup rGroupDef;
50 sprintf(nbuf, "%.40s(%d)", *argv, getpid());
51 yaz_log_init_prefix (nbuf);
55 gettimeofday(&start_time, 0);
58 rGroupDef.groupName = NULL;
59 rGroupDef.databaseName = NULL;
60 rGroupDef.path = NULL;
61 rGroupDef.recordId = NULL;
62 rGroupDef.recordType = NULL;
63 rGroupDef.flagStoreData = -1;
64 rGroupDef.flagStoreKeys = -1;
66 rGroupDef.databaseNamePath = 0;
67 rGroupDef.explainDatabase = 0;
68 rGroupDef.fileVerboseLimit = 100000;
73 fprintf (stderr, "%s [options] command <dir> ...\n"
75 " update <dir> Update index with files below <dir>.\n"
76 " If <dir> is empty filenames are read from stdin.\n"
77 " delete <dir> Delete index with files below <dir>.\n"
78 " commit Commit changes\n"
79 " clean Clean shadow files\n"
81 " -t <type> Index files as <type> (grs or text).\n"
82 " -c <config> Read configuration file <config>.\n"
83 " -g <group> Index files according to group settings.\n"
84 " -d <database> Records belong to Z39.50 database <database>.\n"
85 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
86 " -n Don't use shadow system.\n"
87 " -s Show analysis on stdout, but do no work.\n"
88 " -v <level> Set logging to <level>.\n"
89 " -l <file> Write log to <file>.\n"
90 " -f <n> Display information for the first <n> records.\n"
91 " -V Show version.\n", *argv
95 while ((ret = options ("sVt:c:g:d:m:v:nf:l:"
96 , argv, argc, &arg)) != -2)
100 if(cmd == 0) /* command */
105 logf (LOG_LOG, "Z'mbol version %s %s",
106 ZEBRAVER, ZEBRADATE);
108 logf (LOG_LOG, "Zebra version %s %s",
109 ZEBRAVER, ZEBRADATE);
111 zs = zebra_start (configName ? configName : "zebra.cfg");
114 zh = zebra_open (zs);
116 zebra_shadow_enable (zh, 0);
118 if (rGroupDef.databaseName)
120 if (zebra_select_database (zh, rGroupDef.databaseName))
125 if (zebra_select_database (zh, "Default"))
129 if (!strcmp (arg, "update"))
131 else if (!strcmp (arg, "update1"))
133 else if (!strcmp (arg, "update2"))
135 else if (!strcmp (arg, "dump"))
137 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
139 else if (!strcmp (arg, "init"))
143 else if (!strcmp (arg, "commit"))
147 else if (!strcmp (arg, "clean"))
151 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
153 zebra_register_statistics (zh);
155 else if (!strcmp (arg, "compact"))
161 logf (LOG_FATAL, "unknown command: %s", arg);
167 rGroupDef.path = arg;
168 zebra_set_group (zh, &rGroupDef);
169 zebra_begin_trans (zh);
174 zebra_repository_update (zh);
177 zebra_repository_delete (zh);
180 logf (LOG_LOG, "dumping %s", rGroupDef.path);
181 zebra_repository_show (zh);
188 zebra_end_trans (zh);
189 log_event_end (NULL, NULL);
195 fprintf (stderr, "Z'mbol %s %s\n", ZEBRAVER, ZEBRADATE);
197 fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
199 fprintf (stderr, " (C) 1994-2002, Index Data ApS\n");
202 fprintf (stderr, " WIN32 Debug\n");
204 fprintf (stderr, " WIN32 Release\n");
208 fprintf (stderr, "libbzip2\n"
209 " (C) 1996-1999 Julian R Seward. All rights reserved.\n");
213 yaz_log_init_level (yaz_log_mask_str(arg));
215 yaz_log_init_file (arg);
217 mem_max = 1024*1024*atoi(arg);
219 rGroupDef.databaseName = arg;
221 rGroupDef.flagRw = 0;
223 rGroupDef.groupName = arg;
225 rGroupDef.fileVerboseLimit = atoi(arg);
229 rGroupDef.recordType = arg;
233 logf (LOG_WARN, "unknown option '-%s'", arg);
238 gettimeofday(&end_time, 0);
239 usec = (end_time.tv_sec - start_time.tv_sec) * 1000000L +
240 end_time.tv_usec - start_time.tv_usec;
242 yaz_log (LOG_LOG, "zebraidx times: %5.2f %5.2f %5.2f",
243 (double) usec / 1000000.0,
244 (double) (tms2.tms_utime - tms1.tms_utime)/100,
245 (double) (tms2.tms_stime - tms1.tms_stime)/100);