1 /* $Id: main.c,v 1.120 2005-01-03 19:33:22 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
34 #include <sys/times.h>
38 #include <yaz/options.h>
39 #include <idzebra/api.h>
43 static void filter_cb(void *cd, const char *name)
48 static void show_filters(ZebraService zs)
50 zebra_filter_info(zs, 0, filter_cb);
53 int main (int argc, char **argv)
60 int enable_commit = 1;
61 char *database = "Default";
62 Res res = res_open(0, 0, 0);
66 struct tms tms1, tms2;
67 struct timeval start_time, end_time;
80 sprintf(nbuf, "%.40s(%ld)", *argv, (long) getpid());
81 yaz_log_init_prefix (nbuf);
85 gettimeofday(&start_time, 0);
90 fprintf (stderr, "%s [options] command <dir> ...\n"
92 " update <dir> Update index with files below <dir>.\n"
93 " If <dir> is empty filenames are read from stdin.\n"
94 " delete <dir> Delete index with files below <dir>.\n"
95 " create <db> Create database <db>\n"
96 " drop <db> Drop database <db>\n"
97 " commit Commit changes\n"
98 " clean Clean shadow files\n"
100 " -t <type> Index files as <type> (grs or text).\n"
101 " -c <config> Read configuration file <config>.\n"
102 " -g <group> Index files according to group settings.\n"
103 " -d <database> Records belong to Z39.50 database <database>.\n"
104 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
105 " -n Don't use shadow system.\n"
106 " -s Show analysis on stdout, but do no work.\n"
107 " -v <level> Set logging to <level>.\n"
108 " -l <file> Write log to <file>.\n"
109 " -L Don't follow symbolic links.\n"
110 " -f <n> Display information for the first <n> records.\n"
111 " -V Show version.\n", *argv
115 while ((ret = options ("sVt:c:g:d:m:v:nf:l:L"
116 , argv, argc, &arg)) != -2)
120 if(cmd == 0) /* command */
124 const char *config = configName ? configName : "zebra.cfg";
125 yaz_log (YLOG_LOG, "Zebra version %s %s",
126 ZEBRAVER, ZEBRADATE);
127 zs = zebra_start_res (config, 0, res);
130 yaz_log (YLOG_FATAL, "Cannot read config %s", config);
133 zh = zebra_open (zs);
134 zebra_shadow_enable (zh, enable_commit);
137 if (zebra_select_database (zh, database))
139 yaz_log(YLOG_FATAL, "Could not select database %s errCode=%d",
140 database, zebra_errCode(zh) );
143 if (!strcmp (arg, "update"))
145 else if (!strcmp (arg, "update1"))
147 else if (!strcmp (arg, "update2"))
149 else if (!strcmp (arg, "dump"))
151 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
153 else if (!strcmp (arg, "init"))
157 else if (!strcmp(arg, "drop"))
161 else if (!strcmp(arg, "create"))
165 else if (!strcmp (arg, "commit"))
169 else if (!strcmp (arg, "clean"))
173 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
175 zebra_register_statistics (zh,0);
177 else if (!strcmp (arg, "dumpdict"))
179 zebra_register_statistics (zh,1);
181 else if (!strcmp (arg, "compact"))
185 else if (!strcmp (arg, "filters"))
191 yaz_log (YLOG_FATAL, "unknown command: %s", arg);
200 if (zebra_begin_trans (zh, 1))
206 zebra_repository_update (zh, arg);
209 zebra_repository_delete (zh, arg);
212 zebra_repository_show (zh, arg);
216 zebra_create_database(zh, arg);
219 zebra_drop_database(zh, arg);
224 log_event_end (NULL, NULL);
229 printf("Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
230 printf(" (C) 1994-2004, Index Data ApS\n");
233 printf(" WIN32 Debug\n");
235 printf(" WIN32 Release\n");
239 printf("Using: libbzip2, (C) 1996-1999 Julian R Seward. All rights reserved.\n");
243 yaz_log_init_level (yaz_log_mask_str(arg));
245 yaz_log_init_file (arg);
247 res_set(res, "memMax", arg);
251 res_set(res, "openRW", "0");
253 res_set(res, "group", arg);
255 res_set(res, "fileVerboseLimit", arg);
259 res_set(res, "recordType", arg);
263 res_set(res, "followLinks", "0");
265 yaz_log (YLOG_WARN, "unknown option '-%s'", arg);
269 zebra_end_trans (zh);
276 gettimeofday(&end_time, 0);
277 usec = (end_time.tv_sec - start_time.tv_sec) * 1000000.0 +
278 end_time.tv_usec - start_time.tv_usec;
280 yaz_log (YLOG_LOG, "zebraidx times: %5.2f %5.2f %5.2f",
282 (double) (tms2.tms_utime - tms1.tms_utime)/100,
283 (double) (tms2.tms_stime - tms1.tms_stime)/100);