1 /* $Id: main.c,v 1.114 2004-09-26 20:38:50 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
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>
47 #include <idzebra/api.h>
51 int main (int argc, char **argv)
58 int enable_commit = 1;
59 char *database = "Default";
60 Res res = res_open(0, 0, 0);
64 struct tms tms1, tms2;
65 struct timeval start_time, end_time;
78 sprintf(nbuf, "%.40s(%d)", *argv, getpid());
79 yaz_log_init_prefix (nbuf);
83 gettimeofday(&start_time, 0);
88 fprintf (stderr, "%s [options] command <dir> ...\n"
90 " update <dir> Update index with files below <dir>.\n"
91 " If <dir> is empty filenames are read from stdin.\n"
92 " delete <dir> Delete index with files below <dir>.\n"
93 " create <db> Create database <db>\n"
94 " drop <db> Drop database <db>\n"
95 " commit Commit changes\n"
96 " clean Clean shadow files\n"
98 " -t <type> Index files as <type> (grs or text).\n"
99 " -c <config> Read configuration file <config>.\n"
100 " -g <group> Index files according to group settings.\n"
101 " -d <database> Records belong to Z39.50 database <database>.\n"
102 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
103 " -n Don't use shadow system.\n"
104 " -s Show analysis on stdout, but do no work.\n"
105 " -v <level> Set logging to <level>.\n"
106 " -l <file> Write log to <file>.\n"
107 " -L Don't follow symbolic links.\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:L"
114 , argv, argc, &arg)) != -2)
118 if(cmd == 0) /* command */
122 const char *config = configName ? configName : "zebra.cfg";
123 logf (LOG_LOG, "Zebra version %s %s",
124 ZEBRAVER, ZEBRADATE);
125 zs = zebra_start_res (config, 0, res);
128 yaz_log (LOG_FATAL, "Cannot read config %s", config);
131 zh = zebra_open (zs);
132 zebra_shadow_enable (zh, enable_commit);
135 if (zebra_select_database (zh, database))
137 logf(LOG_FATAL, "Could not select database %s errCode=%d",
138 database, zebra_errCode(zh) );
141 if (!strcmp (arg, "update"))
143 else if (!strcmp (arg, "update1"))
145 else if (!strcmp (arg, "update2"))
147 else if (!strcmp (arg, "dump"))
149 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
151 else if (!strcmp (arg, "init"))
155 else if (!strcmp(arg, "drop"))
159 else if (!strcmp(arg, "create"))
163 else if (!strcmp (arg, "commit"))
167 else if (!strcmp (arg, "clean"))
171 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
173 zebra_register_statistics (zh,0);
175 else if (!strcmp (arg, "dumpdict"))
177 zebra_register_statistics (zh,1);
179 else if (!strcmp (arg, "compact"))
185 logf (LOG_FATAL, "unknown command: %s", arg);
194 if (zebra_begin_trans (zh, 1))
200 zebra_repository_update (zh, arg);
203 zebra_repository_delete (zh, arg);
206 zebra_repository_show (zh, arg);
210 zebra_create_database(zh, arg);
213 zebra_drop_database(zh, arg);
218 log_event_end (NULL, NULL);
223 printf("Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
224 printf(" (C) 1994-2004, Index Data ApS\n");
227 printf(" WIN32 Debug\n");
229 printf(" WIN32 Release\n");
233 printf("Using: libbzip2, (C) 1996-1999 Julian R Seward. All rights reserved.\n");
236 printf("Using: Tcl %s\n", TCL_VERSION);
241 XML_Expat_Version v = XML_ExpatVersionInfo();
242 printf ("Using: Expat %d.%d.%d\n",
243 v.major, v.minor, v.micro);
248 yaz_log_init_level (yaz_log_mask_str(arg));
250 yaz_log_init_file (arg);
252 res_set(res, "memMax", arg);
256 res_set(res, "openRW", "0");
258 res_set(res, "group", arg);
260 res_set(res, "fileVerboseLimit", arg);
264 res_set(res, "recordType", arg);
268 res_set(res, "followLinks", "0");
270 logf (LOG_WARN, "unknown option '-%s'", arg);
274 zebra_end_trans (zh);
281 gettimeofday(&end_time, 0);
282 usec = (end_time.tv_sec - start_time.tv_sec) * 1000000.0 +
283 end_time.tv_usec - start_time.tv_usec;
285 yaz_log (LOG_LOG, "zebraidx times: %5.2f %5.2f %5.2f",
287 (double) (tms2.tms_utime - tms1.tms_utime)/100,
288 (double) (tms2.tms_stime - tms1.tms_stime)/100);