1 /* $Id: zebraidx.c,v 1.5 2007-04-17 20:27:14 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
35 #include <yaz/options.h>
36 #include <idzebra/api.h>
40 static void filter_cb(void *cd, const char *name)
45 static void show_filters(ZebraService zs)
47 zebra_filter_info(zs, 0, filter_cb);
50 int main (int argc, char **argv)
57 int enable_commit = 1;
59 Res res = res_open(0, 0);
60 Res default_res = res_open(0, 0);
62 int trans_started = 0;
71 sprintf(nbuf, "%.40s(%ld)", *argv, (long) getpid());
72 yaz_log_init_prefix (nbuf);
77 fprintf (stderr, "%s [options] command <dir> ...\n"
79 " update <dir> Update index with files below <dir>.\n"
80 " If <dir> is empty filenames are read from stdin.\n"
81 " delete <dir> Delete index with files below <dir>.\n"
82 " create <db> Create database <db>\n"
83 " drop <db> Drop database <db>\n"
84 " commit Commit changes\n"
85 " clean Clean shadow files\n"
87 " -t <type> Index files as <type> (grs or text).\n"
88 " -c <config> Read configuration file <config>.\n"
89 " -g <group> Index files according to group settings.\n"
90 " -d <database> Records belong to Z39.50 database <database>.\n"
91 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
92 " -n Don't use shadow system.\n"
93 " -s Show analysis on stdout, but do no work.\n"
94 " -v <level> Set logging to <level>.\n"
95 " -l <file> Write log to <file>.\n"
96 " -L Don't follow symbolic links.\n"
97 " -f <n> Display information for the first <n> records.\n"
98 " -V Show version.\n", *argv
102 res_set(default_res, "profilePath", DEFAULT_PROFILE_PATH);
103 res_set(default_res, "modulePath", DEFAULT_MODULE_PATH);
104 while ((ret = options("sVt:c:g:d:m:v:nf:l:L", argv, argc, &arg)) != -2)
108 if(cmd == 0) /* command */
112 const char *config = configName ? configName : "zebra.cfg";
113 zs = zebra_start_res(config, default_res, res);
116 yaz_log (YLOG_FATAL, "Cannot read config %s", config);
119 zh = zebra_open (zs, 0);
120 zebra_shadow_enable (zh, enable_commit);
124 zebra_select_database (zh, database) == ZEBRA_FAIL)
126 yaz_log(YLOG_FATAL, "Could not select database %s "
128 database, zebra_errCode(zh) );
131 if (!strcmp (arg, "update"))
133 else if (!strcmp (arg, "update1"))
135 else if (!strcmp (arg, "update2"))
137 else if (!strcmp (arg, "dump"))
139 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
141 else if (!strcmp (arg, "init"))
145 else if (!strcmp(arg, "drop"))
149 else if (!strcmp(arg, "create"))
153 else if (!strcmp (arg, "commit"))
157 else if (!strcmp (arg, "clean"))
161 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
163 zebra_register_statistics (zh,0);
165 else if (!strcmp (arg, "dumpdict"))
167 zebra_register_statistics (zh,1);
169 else if (!strcmp (arg, "compact"))
173 else if (!strcmp (arg, "filters"))
179 yaz_log (YLOG_FATAL, "unknown command: %s", arg);
185 ZEBRA_RES res = ZEBRA_OK;
189 if (zebra_begin_trans (zh, 1) != ZEBRA_OK)
195 res = zebra_repository_update (zh, arg);
198 res = zebra_repository_delete (zh, arg);
201 res = zebra_repository_show (zh, arg);
205 res = zebra_create_database(zh, arg);
208 res = zebra_drop_database(zh, arg);
215 const char *add = zebra_errAdd(zh);
216 yaz_log(YLOG_FATAL, "Operation failed: %s %s",
217 zebra_errString(zh), add ? add : "");
220 if (zebra_end_trans (zh) != ZEBRA_OK)
221 yaz_log (YLOG_WARN, "zebra_end_trans failed");
228 log_event_end (NULL, NULL);
233 printf("Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
234 printf(" (C) 1994-2007, Index Data ApS\n");
237 printf(" WIN32 Debug\n");
239 printf(" WIN32 Release\n");
243 printf("Using: libbzip2, (C) 1996-1999 Julian R Seward. All rights reserved.\n");
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 yaz_log (YLOG_WARN, "unknown option '-%s'", arg);
273 if (zebra_end_trans (zh) != ZEBRA_OK)
274 yaz_log (YLOG_WARN, "zebra_end_trans failed");
280 res_close(default_res);
288 * indent-tabs-mode: nil
290 * vim: shiftwidth=4 tabstop=8 expandtab