1 /* $Id: main.c,v 1.94 2002-08-05 14:08:08 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
35 #include <sys/times.h>
38 #include <yaz/data1.h>
43 int main (int argc, char **argv)
50 int disableCommit = 0;
53 struct tms tms1, tms2;
54 struct timeval start_time, end_time;
60 struct recordGroup rGroupDef;
68 sprintf(nbuf, "%.40s(%d)", *argv, getpid());
69 yaz_log_init_prefix (nbuf);
73 gettimeofday(&start_time, 0);
76 rGroupDef.groupName = NULL;
77 rGroupDef.databaseName = NULL;
78 rGroupDef.path = NULL;
79 rGroupDef.recordId = NULL;
80 rGroupDef.recordType = NULL;
81 rGroupDef.flagStoreData = -1;
82 rGroupDef.flagStoreKeys = -1;
84 rGroupDef.databaseNamePath = 0;
85 rGroupDef.explainDatabase = 0;
86 rGroupDef.fileVerboseLimit = 100000;
91 fprintf (stderr, "%s [options] command <dir> ...\n"
93 " update <dir> Update index with files below <dir>.\n"
94 " If <dir> is empty filenames are read from stdin.\n"
95 " delete <dir> Delete index with files below <dir>.\n"
96 " commit Commit changes\n"
97 " clean Clean shadow files\n"
99 " -t <type> Index files as <type> (grs or text).\n"
100 " -c <config> Read configuration file <config>.\n"
101 " -g <group> Index files according to group settings.\n"
102 " -d <database> Records belong to Z39.50 database <database>.\n"
103 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
104 " -n Don't use shadow system.\n"
105 " -s Show analysis on stdout, but do no work.\n"
106 " -v <level> Set logging to <level>.\n"
107 " -l <file> Write log to <file>.\n"
108 " -f <n> Display information for the first <n> records.\n"
109 " -V Show version.\n", *argv
113 while ((ret = options ("sVt:c:g:d:m:v:nf:l:"
114 , argv, argc, &arg)) != -2)
118 if(cmd == 0) /* command */
122 logf (LOG_LOG, "Zebra version %s %s",
123 ZEBRAVER, ZEBRADATE);
124 zs = zebra_start (configName ? configName : "zebra.cfg");
127 zh = zebra_open (zs);
129 zebra_shadow_enable (zh, 0);
131 if (rGroupDef.databaseName)
133 if (zebra_select_database (zh, rGroupDef.databaseName))
138 if (zebra_select_database (zh, "Default"))
142 if (!strcmp (arg, "update"))
144 else if (!strcmp (arg, "update1"))
146 else if (!strcmp (arg, "update2"))
148 else if (!strcmp (arg, "dump"))
150 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
152 else if (!strcmp (arg, "init"))
156 else if (!strcmp (arg, "commit"))
160 else if (!strcmp (arg, "clean"))
164 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
166 zebra_register_statistics (zh,0);
168 else if (!strcmp (arg, "dump") || !strcmp (arg, "dumpdict"))
170 zebra_register_statistics (zh,1);
172 else if (!strcmp (arg, "compact"))
178 logf (LOG_FATAL, "unknown command: %s", arg);
184 rGroupDef.path = arg;
185 zebra_set_group (zh, &rGroupDef);
186 zebra_begin_trans (zh);
191 zebra_repository_update (zh);
194 zebra_repository_delete (zh);
197 logf (LOG_LOG, "dumping %s", rGroupDef.path);
198 zebra_repository_show (zh);
205 zebra_end_trans (zh);
206 log_event_end (NULL, NULL);
211 fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
212 fprintf (stderr, " (C) 1994-2002, Index Data ApS\n");
215 fprintf (stderr, " WIN32 Debug\n");
217 fprintf (stderr, " WIN32 Release\n");
221 fprintf (stderr, "libbzip2\n"
222 " (C) 1996-1999 Julian R Seward. All rights reserved.\n");
226 yaz_log_init_level (yaz_log_mask_str(arg));
228 yaz_log_init_file (arg);
230 mem_max = 1024*1024*atoi(arg);
232 rGroupDef.databaseName = arg;
234 rGroupDef.flagRw = 0;
236 rGroupDef.groupName = arg;
238 rGroupDef.fileVerboseLimit = atoi(arg);
242 rGroupDef.recordType = arg;
246 logf (LOG_WARN, "unknown option '-%s'", arg);
251 gettimeofday(&end_time, 0);
252 usec = (end_time.tv_sec - start_time.tv_sec) * 1000000L +
253 end_time.tv_usec - start_time.tv_usec;
255 yaz_log (LOG_LOG, "zebraidx times: %5.2f %5.2f %5.2f",
256 (double) usec / 1000000.0,
257 (double) (tms2.tms_utime - tms1.tms_utime)/100,
258 (double) (tms2.tms_stime - tms1.tms_stime)/100);