1 /* $Id: zebraidx.c,v 1.7 2007-10-22 13:05:22 adam Exp $
2 Copyright (C) 1995-2007
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 this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include <yaz/icu_I18N.h>
36 #include <yaz/options.h>
37 #include <idzebra/version.h>
38 #include <idzebra/api.h>
42 static void filter_cb(void *cd, const char *name)
47 static void show_filters(ZebraService zs)
49 zebra_filter_info(zs, 0, filter_cb);
52 int main (int argc, char **argv)
59 int enable_commit = 1;
61 Res res = res_open(0, 0);
62 Res default_res = res_open(0, 0);
64 int trans_started = 0;
73 sprintf(nbuf, "%.40s(%ld)", *argv, (long) getpid());
74 yaz_log_init_prefix (nbuf);
79 fprintf (stderr, "%s [options] command <dir> ...\n"
81 " update <dir> Update index with files below <dir>.\n"
82 " If <dir> is empty filenames are read from stdin.\n"
83 " delete <dir> Delete index with files below <dir>.\n"
84 " create <db> Create database <db>\n"
85 " drop <db> Drop database <db>\n"
86 " commit Commit changes\n"
87 " clean Clean shadow files\n"
89 " -t <type> Index files as <type> (grs or text).\n"
90 " -c <config> Read configuration file <config>.\n"
91 " -g <group> Index files according to group settings.\n"
92 " -d <database> Records belong to Z39.50 database <database>.\n"
93 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
94 " -n Don't use shadow system.\n"
95 " -s Show analysis on stdout, but do no work.\n"
96 " -v <level> Set logging to <level>.\n"
97 " -l <file> Write log to <file>.\n"
98 " -L Don't follow symbolic links.\n"
99 " -f <n> Display information for the first <n> records.\n"
100 " -V Show version.\n", *argv
104 res_set(default_res, "profilePath", DEFAULT_PROFILE_PATH);
105 res_set(default_res, "modulePath", DEFAULT_MODULE_PATH);
106 while ((ret = options("sVt:c:g:d:m:v:nf:l:L", argv, argc, &arg)) != -2)
110 if(cmd == 0) /* command */
114 const char *config = configName ? configName : "zebra.cfg";
115 zs = zebra_start_res(config, default_res, res);
118 yaz_log (YLOG_FATAL, "Cannot read config %s", config);
121 zh = zebra_open (zs, 0);
122 zebra_shadow_enable (zh, enable_commit);
126 zebra_select_database (zh, database) == ZEBRA_FAIL)
128 yaz_log(YLOG_FATAL, "Could not select database %s "
130 database, zebra_errCode(zh) );
133 if (!strcmp (arg, "update"))
135 else if (!strcmp (arg, "update1"))
137 else if (!strcmp (arg, "update2"))
139 else if (!strcmp (arg, "dump"))
141 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
143 else if (!strcmp (arg, "init"))
147 else if (!strcmp(arg, "drop"))
151 else if (!strcmp(arg, "create"))
155 else if (!strcmp (arg, "commit"))
159 else if (!strcmp (arg, "clean"))
163 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
165 zebra_register_statistics (zh,0);
167 else if (!strcmp (arg, "dumpdict"))
169 zebra_register_statistics (zh,1);
171 else if (!strcmp (arg, "compact"))
175 else if (!strcmp (arg, "filters"))
181 yaz_log (YLOG_FATAL, "unknown command: %s", arg);
187 ZEBRA_RES res = ZEBRA_OK;
191 if (zebra_begin_trans (zh, 1) != ZEBRA_OK)
197 res = zebra_repository_update (zh, arg);
200 res = zebra_repository_delete (zh, arg);
203 res = zebra_repository_show (zh, arg);
207 res = zebra_create_database(zh, arg);
210 res = zebra_drop_database(zh, arg);
217 const char *add = zebra_errAdd(zh);
218 yaz_log(YLOG_FATAL, "Operation failed: %s %s",
219 zebra_errString(zh), add ? add : "");
222 if (zebra_end_trans (zh) != ZEBRA_OK)
223 yaz_log (YLOG_WARN, "zebra_end_trans failed");
230 log_event_end (NULL, NULL);
235 char version_str[20];
237 zebra_get_version(version_str, sys_str);
239 printf("Zebra %s\n", version_str);
240 printf("(C) 1994-2007, Index Data ApS\n");
241 printf("Zebra is free software, covered by the GNU General Public License, and you are\n");
242 printf("welcome to change it and/or distribute copies of it under certain conditions.\n");
243 printf("Configured as: %s\n", sys_str);
244 if (strcmp(version_str, ZEBRAVER))
245 printf("zebraidx compiled version %s\n", ZEBRAVER);
247 printf("Using ICU\n");
251 yaz_log_init_level (yaz_log_mask_str(arg));
253 yaz_log_init_file (arg);
255 res_set(res, "memMax", arg);
259 res_set(res, "openRW", "0");
261 res_set(res, "group", arg);
263 res_set(res, "fileVerboseLimit", arg);
267 res_set(res, "recordType", arg);
271 res_set(res, "followLinks", "0");
273 yaz_log (YLOG_WARN, "unknown option '-%s'", arg);
277 if (zebra_end_trans (zh) != ZEBRA_OK)
278 yaz_log (YLOG_WARN, "zebra_end_trans failed");
284 res_close(default_res);
292 * indent-tabs-mode: nil
294 * vim: shiftwidth=4 tabstop=8 expandtab