1 /* $Id: main.c,v 1.105 2003-06-30 19:37:12 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
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
35 #include <sys/times.h>
43 int main (int argc, char **argv)
50 int disableCommit = 0;
55 struct tms tms1, tms2;
56 struct timeval start_time, end_time;
62 struct recordGroup rGroupDef;
70 sprintf(nbuf, "%.40s(%d)", *argv, getpid());
71 yaz_log_init_prefix (nbuf);
75 gettimeofday(&start_time, 0);
78 rGroupDef.groupName = NULL;
79 rGroupDef.databaseName = NULL;
80 rGroupDef.path = NULL;
81 rGroupDef.recordId = NULL;
82 rGroupDef.recordType = NULL;
83 rGroupDef.flagStoreData = -1;
84 rGroupDef.flagStoreKeys = -1;
86 rGroupDef.databaseNamePath = 0;
87 rGroupDef.explainDatabase = 0;
88 rGroupDef.fileVerboseLimit = 100000;
89 rGroupDef.followLinks = -1;
94 fprintf (stderr, "%s [options] command <dir> ...\n"
96 " update <dir> Update index with files below <dir>.\n"
97 " If <dir> is empty filenames are read from stdin.\n"
98 " delete <dir> Delete index with files below <dir>.\n"
99 " create <db> Create database <db>\n"
100 " drop <db> Drop database <db>\n"
101 " commit Commit changes\n"
102 " clean Clean shadow files\n"
104 " -t <type> Index files as <type> (grs or text).\n"
105 " -c <config> Read configuration file <config>.\n"
106 " -g <group> Index files according to group settings.\n"
107 " -d <database> Records belong to Z39.50 database <database>.\n"
108 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
109 " -n Don't use shadow system.\n"
110 " -s Show analysis on stdout, but do no work.\n"
111 " -v <level> Set logging to <level>.\n"
112 " -l <file> Write log to <file>.\n"
113 " -L Don't follow symbolic links.\n"
114 " -f <n> Display information for the first <n> records.\n"
115 " -V Show version.\n", *argv
119 while ((ret = options ("sVt:c:g:d:m:v:nf:l:L"
120 , argv, argc, &arg)) != -2)
124 if(cmd == 0) /* command */
128 const char *config = configName ? configName : "zebra.cfg";
129 logf (LOG_LOG, "Zebra version %s %s",
130 ZEBRAVER, ZEBRADATE);
131 zs = zebra_start (config);
134 yaz_log (LOG_FATAL, "Cannot read config %s", config);
137 zh = zebra_open (zs);
139 zebra_shadow_enable (zh, 0);
142 if (rGroupDef.databaseName)
144 if (zebra_select_database (zh, rGroupDef.databaseName))
146 logf(LOG_FATAL, "Could not select database %s errCode=%d",
147 rGroupDef.databaseName, zebra_errCode(zh) );
153 if (zebra_select_database (zh, "Default"))
155 logf(LOG_FATAL, "Could not select database Default errCode=%d",
161 zebra_set_resource(zh, "memmax",mem_max);
163 if (!strcmp (arg, "update"))
165 else if (!strcmp (arg, "update1"))
167 else if (!strcmp (arg, "update2"))
169 else if (!strcmp (arg, "dump"))
171 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
173 else if (!strcmp (arg, "init"))
177 else if (!strcmp(arg, "drop"))
181 else if (!strcmp(arg, "create"))
185 else if (!strcmp (arg, "commit"))
189 else if (!strcmp (arg, "clean"))
193 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
195 zebra_register_statistics (zh,0);
197 else if (!strcmp (arg, "dumpdict"))
199 zebra_register_statistics (zh,1);
201 else if (!strcmp (arg, "compact"))
207 logf (LOG_FATAL, "unknown command: %s", arg);
213 rGroupDef.path = arg;
214 zebra_set_group (zh, &rGroupDef);
218 if (zebra_begin_trans (zh, 1))
224 zebra_repository_update (zh);
227 zebra_repository_delete (zh);
230 logf (LOG_LOG, "dumping %s", rGroupDef.path);
231 zebra_repository_show (zh);
235 zebra_create_database(zh, rGroupDef.path);
238 zebra_drop_database(zh, rGroupDef.path);
243 log_event_end (NULL, NULL);
248 printf("Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
249 printf(" (C) 1994-2002, Index Data ApS\n");
252 printf(" WIN32 Debug\n");
254 printf(" WIN32 Release\n");
259 " (C) 1996-1999 Julian R Seward. All rights reserved.\n");
263 yaz_log_init_level (yaz_log_mask_str(arg));
265 yaz_log_init_file (arg);
269 rGroupDef.databaseName = arg;
271 rGroupDef.flagRw = 0;
273 rGroupDef.groupName = arg;
275 rGroupDef.fileVerboseLimit = atoi(arg);
279 rGroupDef.recordType = arg;
283 rGroupDef.followLinks = 0;
285 logf (LOG_WARN, "unknown option '-%s'", arg);
289 zebra_end_trans (zh);
296 gettimeofday(&end_time, 0);
297 usec = (end_time.tv_sec - start_time.tv_sec) * 1000000L +
298 end_time.tv_usec - start_time.tv_usec;
300 yaz_log (LOG_LOG, "zebraidx times: %5.2f %5.2f %5.2f",
301 (double) usec / 1000000.0,
302 (double) (tms2.tms_utime - tms1.tms_utime)/100,
303 (double) (tms2.tms_stime - tms1.tms_stime)/100);