1 /* $Id: main.c,v 1.128 2006-03-31 15:58:04 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
38 #include <sys/times.h>
42 #include <yaz/options.h>
43 #include <idzebra/api.h>
47 static void filter_cb(void *cd, const char *name)
52 static void show_filters(ZebraService zs)
54 zebra_filter_info(zs, 0, filter_cb);
57 int main (int argc, char **argv)
64 int enable_commit = 1;
66 Res res = res_open(0, 0);
70 struct tms tms1, tms2;
74 struct timeval start_time, end_time;
86 sprintf(nbuf, "%.40s(%ld)", *argv, (long) getpid());
87 yaz_log_init_prefix (nbuf);
93 gettimeofday(&start_time, 0);
98 fprintf (stderr, "%s [options] command <dir> ...\n"
100 " update <dir> Update index with files below <dir>.\n"
101 " If <dir> is empty filenames are read from stdin.\n"
102 " delete <dir> Delete index with files below <dir>.\n"
103 " create <db> Create database <db>\n"
104 " drop <db> Drop database <db>\n"
105 " commit Commit changes\n"
106 " clean Clean shadow files\n"
108 " -t <type> Index files as <type> (grs or text).\n"
109 " -c <config> Read configuration file <config>.\n"
110 " -g <group> Index files according to group settings.\n"
111 " -d <database> Records belong to Z39.50 database <database>.\n"
112 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
113 " -n Don't use shadow system.\n"
114 " -s Show analysis on stdout, but do no work.\n"
115 " -v <level> Set logging to <level>.\n"
116 " -l <file> Write log to <file>.\n"
117 " -L Don't follow symbolic links.\n"
118 " -f <n> Display information for the first <n> records.\n"
119 " -V Show version.\n", *argv
123 while ((ret = options("sVt:c:g:d:m:v:nf:l:L", argv, argc, &arg)) != -2)
127 if(cmd == 0) /* command */
131 const char *config = configName ? configName : "zebra.cfg";
132 zs = zebra_start_res (config, 0, res);
135 yaz_log (YLOG_FATAL, "Cannot read config %s", config);
138 zh = zebra_open (zs, 0);
139 zebra_shadow_enable (zh, enable_commit);
143 zebra_select_database (zh, database) == ZEBRA_FAIL)
145 yaz_log(YLOG_FATAL, "Could not select database %s "
147 database, zebra_errCode(zh) );
150 if (!strcmp (arg, "update"))
152 else if (!strcmp (arg, "update1"))
154 else if (!strcmp (arg, "update2"))
156 else if (!strcmp (arg, "dump"))
158 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
160 else if (!strcmp (arg, "init"))
164 else if (!strcmp(arg, "drop"))
168 else if (!strcmp(arg, "create"))
172 else if (!strcmp (arg, "commit"))
176 else if (!strcmp (arg, "clean"))
180 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
182 zebra_register_statistics (zh,0);
184 else if (!strcmp (arg, "dumpdict"))
186 zebra_register_statistics (zh,1);
188 else if (!strcmp (arg, "compact"))
192 else if (!strcmp (arg, "filters"))
198 yaz_log (YLOG_FATAL, "unknown command: %s", arg);
204 ZEBRA_RES res = ZEBRA_OK;
208 if (zebra_begin_trans (zh, 1) != ZEBRA_OK)
214 res = zebra_repository_update (zh, arg);
217 res = zebra_repository_delete (zh, arg);
220 res = zebra_repository_show (zh, arg);
224 res = zebra_create_database(zh, arg);
227 res = zebra_drop_database(zh, arg);
234 yaz_log(YLOG_WARN, "Operation failed");
237 log_event_end (NULL, NULL);
242 printf("Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
243 printf(" (C) 1994-2005, Index Data ApS\n");
246 printf(" WIN32 Debug\n");
248 printf(" WIN32 Release\n");
252 printf("Using: libbzip2, (C) 1996-1999 Julian R Seward. All rights reserved.\n");
256 yaz_log_init_level (yaz_log_mask_str(arg));
258 yaz_log_init_file (arg);
260 res_set(res, "memMax", arg);
264 res_set(res, "openRW", "0");
266 res_set(res, "group", arg);
268 res_set(res, "fileVerboseLimit", arg);
272 res_set(res, "recordType", arg);
276 res_set(res, "followLinks", "0");
278 yaz_log (YLOG_WARN, "unknown option '-%s'", arg);
282 if (zebra_end_trans (zh) != ZEBRA_OK)
283 yaz_log (YLOG_WARN, "zebra_end_trans failed");
291 gettimeofday(&end_time, 0);
292 usec = (end_time.tv_sec - start_time.tv_sec) * 1000000.0 +
293 end_time.tv_usec - start_time.tv_usec;
295 yaz_log (YLOG_LOG, "zebraidx times: %5.2f %5.2f %5.2f",
297 (double) (tms2.tms_utime - tms1.tms_utime)/100,
298 (double) (tms2.tms_stime - tms1.tms_stime)/100);