1 /* $Id: main.c,v 1.112.2.5 2006-02-23 14:30:03 adam Exp $
2 Copyright (C) 1995-2005
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
36 #include <sys/times.h>
52 int main (int argc, char **argv)
59 int enable_commit = 1;
61 Res res = res_open(0, 0, 0);
65 struct tms tms1, tms2;
66 struct timeval start_time, end_time;
79 sprintf(nbuf, "%.40s(%d)", *argv, getpid());
80 yaz_log_init_prefix (nbuf);
84 gettimeofday(&start_time, 0);
89 fprintf (stderr, "%s [options] command <dir> ...\n"
91 " update <dir> Update index with files below <dir>.\n"
92 " If <dir> is empty filenames are read from stdin.\n"
93 " delete <dir> Delete index with files below <dir>.\n"
94 " create <db> Create database <db>\n"
95 " drop <db> Drop database <db>\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 " -L Don't follow symbolic links.\n"
109 " -f <n> Display information for the first <n> records.\n"
110 " -V Show version.\n", *argv
114 while ((ret = options ("sVt:c:g:d:m:v:nf:l:L"
115 , argv, argc, &arg)) != -2)
119 if(cmd == 0) /* command */
123 const char *config = configName ? configName : "zebra.cfg";
124 zs = zebra_start_res (config, 0, res);
127 yaz_log (LOG_FATAL, "Cannot read config %s", config);
130 zh = zebra_open (zs);
131 zebra_shadow_enable (zh, enable_commit);
134 if (database && zebra_select_database (zh, database))
136 logf(LOG_FATAL, "Could not select database %s errCode=%d",
137 database, zebra_errCode(zh) );
140 if (!strcmp (arg, "update"))
142 else if (!strcmp (arg, "update1"))
144 else if (!strcmp (arg, "update2"))
146 else if (!strcmp (arg, "dump"))
148 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
150 else if (!strcmp (arg, "init"))
154 else if (!strcmp(arg, "drop"))
158 else if (!strcmp(arg, "create"))
162 else if (!strcmp (arg, "commit"))
166 else if (!strcmp (arg, "clean"))
170 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
172 zebra_register_statistics (zh,0);
174 else if (!strcmp (arg, "dumpdict"))
176 zebra_register_statistics (zh,1);
178 else if (!strcmp (arg, "compact"))
184 logf (LOG_FATAL, "unknown command: %s", arg);
193 if (zebra_begin_trans (zh, 1))
199 zebra_repository_update (zh, arg);
202 zebra_repository_delete (zh, arg);
205 zebra_repository_show (zh, arg);
209 zebra_create_database(zh, arg);
212 zebra_drop_database(zh, arg);
217 log_event_end (NULL, NULL);
222 printf("Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
223 printf(" (C) 1994-2005, Index Data ApS\n");
226 printf(" WIN32 Debug\n");
228 printf(" WIN32 Release\n");
232 printf("Using: libbzip2, (C) 1996-1999 Julian R Seward. All rights reserved.\n");
235 printf("Using: Tcl %s\n", TCL_VERSION);
240 XML_Expat_Version v = XML_ExpatVersionInfo();
241 printf ("Using: Expat %d.%d.%d\n",
242 v.major, v.minor, v.micro);
247 yaz_log_init_level (yaz_log_mask_str(arg));
249 yaz_log_init_file (arg);
251 res_set(res, "memMax", arg);
255 res_set(res, "openRW", "0");
257 res_set(res, "group", arg);
259 res_set(res, "fileVerboseLimit", arg);
263 res_set(res, "recordType", arg);
267 res_set(res, "followLinks", "0");
269 logf (LOG_WARN, "unknown option '-%s'", arg);
273 zebra_end_trans (zh);
280 gettimeofday(&end_time, 0);
281 usec = (end_time.tv_sec - start_time.tv_sec) * 1000000.0 +
282 end_time.tv_usec - start_time.tv_usec;
284 yaz_log (LOG_LOG, "zebraidx times: %5.2f %5.2f %5.2f",
286 (double) (tms2.tms_utime - tms1.tms_utime)/100,
287 (double) (tms2.tms_stime - tms1.tms_stime)/100);