1 /* This file is part of the Zebra server.
2 Copyright (C) 2004-2013 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
38 #include <yaz/options.h>
39 #include <idzebra/version.h>
40 #include <idzebra/api.h>
44 static void filter_cb(void *cd, const char *name)
49 static void show_filters(ZebraService zs)
51 zebra_filter_info(zs, 0, filter_cb);
54 int main(int argc, char **argv)
61 int enable_commit = 1;
63 Res res = res_open(0, 0);
64 Res default_res = res_open(0, 0);
66 int trans_started = 0;
75 sprintf(nbuf, "%.40s(%ld)", *argv, (long) getpid());
76 yaz_log_init_prefix(nbuf);
81 fprintf(stderr, "%s [options] command <dir> ...\n"
83 " update <dir> Update index with files below <dir>.\n"
84 " If <dir> is empty filenames are read from stdin.\n"
85 " delete <dir> Delete index with files below <dir>.\n"
86 " create <db> Create database <db>\n"
87 " drop <db> Drop database <db>\n"
88 " commit Commit changes\n"
89 " clean Clean shadow files\n"
90 " check:mode Check register; mode is one of: default, full, quick\n"
92 " -t <type> Index files as <type> (grs or text).\n"
93 " -c <config> Read configuration file <config>.\n"
94 " -g <group> Index files according to group settings.\n"
95 " -d <database> Records belong to Z39.50 database <database>.\n"
96 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
97 " -n Don't use shadow system.\n"
98 " -s Show analysis on stdout, but do no work.\n"
99 " -v <level> Set logging to <level>.\n"
100 " -l <file> Write log to <file>.\n"
101 " -L Don't follow symbolic links.\n"
102 " -f <n> Display information for the first <n> records.\n"
103 " -V Show version.\n", *argv
107 res_set(default_res, "profilePath", DEFAULT_PROFILE_PATH);
108 res_set(default_res, "modulePath", DEFAULT_MODULE_PATH);
109 while ((ret = options("sVt:c:g:d:m:v:nf:l:L", argv, argc, &arg)) != -2)
113 if(cmd == 0) /* command */
117 const char *config = configName ? configName : "zebra.cfg";
118 zs = zebra_start_res(config, default_res, res);
121 yaz_log(YLOG_FATAL, "Cannot read config %s", config);
124 zh = zebra_open(zs, 0);
125 zebra_shadow_enable(zh, enable_commit);
129 zebra_select_database(zh, database) == ZEBRA_FAIL)
131 yaz_log(YLOG_FATAL, "Could not select database %s "
133 database, zebra_errCode(zh) );
136 if (!strcmp(arg, "update"))
138 else if (!strcmp(arg, "update1"))
140 else if (!strcmp(arg, "update2"))
142 else if (!strcmp(arg, "dump"))
144 else if (!strcmp(arg, "del") || !strcmp(arg, "delete"))
146 else if (!strcmp(arg, "adelete"))
148 else if (!strcmp(arg, "init"))
152 else if (!strcmp(arg, "drop"))
156 else if (!strcmp(arg, "create"))
160 else if (!strcmp(arg, "commit"))
164 else if (!strcmp(arg, "clean"))
168 else if (!strcmp(arg, "stat") || !strcmp(arg, "status"))
170 zebra_register_statistics(zh, 0);
172 else if (!strcmp(arg, "dumpdict"))
174 zebra_register_statistics(zh, 1);
176 else if (!strcmp(arg, "compact"))
180 else if (!strcmp(arg, "filters"))
184 else if (!strncmp(arg, "check", 5))
186 const char *spec = 0;
189 else if (arg[5] != '\0')
191 yaz_log(YLOG_FATAL, "missing colon after check");
194 if (zebra_register_check(zh, spec) != ZEBRA_OK)
196 yaz_log(YLOG_WARN, "zebra_register_check failed");
201 yaz_log(YLOG_FATAL, "unknown command: %s", arg);
207 ZEBRA_RES res = ZEBRA_OK;
211 if (zebra_begin_trans(zh, 1) != ZEBRA_OK)
217 res = zebra_repository_index(zh, arg, action_update);
220 res = zebra_repository_index(zh, arg, action_delete);
223 res = zebra_repository_index(zh, arg, action_a_delete);
226 res = zebra_repository_show(zh, arg);
230 res = zebra_create_database(zh, arg);
233 res = zebra_drop_database(zh, arg);
240 const char *add = zebra_errAdd(zh);
241 yaz_log(YLOG_FATAL, "Operation failed: %s %s",
242 zebra_errString(zh), add ? add : "");
245 if (zebra_end_trans(zh) != ZEBRA_OK)
246 yaz_log(YLOG_WARN, "zebra_end_trans failed");
253 log_event_end(NULL, NULL);
258 char version_str[20];
260 zebra_get_version(version_str, sys_str);
262 printf("Zebra %s\n", version_str);
263 printf("(C) 1994-2013, Index Data ApS\n");
264 printf("Zebra is free software, covered by the GNU General Public License, and you are\n");
265 printf("welcome to change it and/or distribute copies of it under certain conditions.\n");
266 printf("SHA1 ID: %s\n", sys_str);
267 if (strcmp(version_str, ZEBRAVER))
268 printf("zebraidx compiled version %s\n", ZEBRAVER);
270 printf("Using ICU\n");
274 yaz_log_init_level(yaz_log_mask_str(arg));
276 yaz_log_init_file(arg);
278 res_set(res, "memMax", arg);
282 res_set(res, "openRW", "0");
284 res_set(res, "group", arg);
286 res_set(res, "fileVerboseLimit", arg);
290 res_set(res, "recordType", arg);
294 res_set(res, "followLinks", "0");
296 yaz_log(YLOG_WARN, "unknown option '-%s'", arg);
300 if (zebra_end_trans(zh) != ZEBRA_OK)
301 yaz_log(YLOG_WARN, "zebra_end_trans failed");
307 res_close(default_res);
315 * c-file-style: "Stroustrup"
316 * indent-tabs-mode: nil
318 * vim: shiftwidth=4 tabstop=8 expandtab