1 /* $Id: main.c,v 1.108 2003-11-24 12:58:00 mike 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>
51 int main (int argc, char **argv)
58 int disableCommit = 0;
63 struct tms tms1, tms2;
64 struct timeval start_time, end_time;
70 struct recordGroup rGroupDef;
78 sprintf(nbuf, "%.40s(%d)", *argv, getpid());
79 yaz_log_init_prefix (nbuf);
83 gettimeofday(&start_time, 0);
86 rGroupDef.groupName = NULL;
87 rGroupDef.databaseName = NULL;
88 rGroupDef.path = NULL;
89 rGroupDef.recordId = NULL;
90 rGroupDef.recordType = NULL;
91 rGroupDef.flagStoreData = -1;
92 rGroupDef.flagStoreKeys = -1;
94 rGroupDef.databaseNamePath = 0;
95 rGroupDef.explainDatabase = 0;
96 rGroupDef.fileVerboseLimit = 100000;
97 rGroupDef.followLinks = -1;
102 fprintf (stderr, "%s [options] command <dir> ...\n"
104 " update <dir> Update index with files below <dir>.\n"
105 " If <dir> is empty filenames are read from stdin.\n"
106 " delete <dir> Delete index with files below <dir>.\n"
107 " create <db> Create database <db>\n"
108 " drop <db> Drop database <db>\n"
109 " commit Commit changes\n"
110 " clean Clean shadow files\n"
112 " -t <type> Index files as <type> (grs or text).\n"
113 " -c <config> Read configuration file <config>.\n"
114 " -g <group> Index files according to group settings.\n"
115 " -d <database> Records belong to Z39.50 database <database>.\n"
116 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
117 " -n Don't use shadow system.\n"
118 " -s Show analysis on stdout, but do no work.\n"
119 " -v <level> Set logging to <level>.\n"
120 " -l <file> Write log to <file>.\n"
121 " -L Don't follow symbolic links.\n"
122 " -f <n> Display information for the first <n> records.\n"
123 " -V Show version.\n", *argv
127 while ((ret = options ("sVt:c:g:d:m:v:nf:l:L"
128 , argv, argc, &arg)) != -2)
132 if(cmd == 0) /* command */
136 const char *config = configName ? configName : "zebra.cfg";
137 logf (LOG_LOG, "Zebra version %s %s",
138 ZEBRAVER, ZEBRADATE);
139 zs = zebra_start (config);
142 yaz_log (LOG_FATAL, "Cannot read config %s", config);
145 zh = zebra_open (zs);
147 zebra_shadow_enable (zh, 0);
150 if (rGroupDef.databaseName)
152 if (zebra_select_database (zh, rGroupDef.databaseName))
154 logf(LOG_FATAL, "Could not select database %s errCode=%d",
155 rGroupDef.databaseName, zebra_errCode(zh) );
161 if (zebra_select_database (zh, "Default"))
163 logf(LOG_FATAL, "Could not select database Default errCode=%d",
169 zebra_set_resource(zh, "memmax",mem_max);
171 if (!strcmp (arg, "update"))
173 else if (!strcmp (arg, "update1"))
175 else if (!strcmp (arg, "update2"))
177 else if (!strcmp (arg, "dump"))
179 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
181 else if (!strcmp (arg, "init"))
185 else if (!strcmp(arg, "drop"))
189 else if (!strcmp(arg, "create"))
193 else if (!strcmp (arg, "commit"))
197 else if (!strcmp (arg, "clean"))
201 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
203 zebra_register_statistics (zh,0);
205 else if (!strcmp (arg, "dumpdict"))
207 zebra_register_statistics (zh,1);
209 else if (!strcmp (arg, "compact"))
215 logf (LOG_FATAL, "unknown command: %s", arg);
221 rGroupDef.path = arg;
222 zebra_set_group (zh, &rGroupDef);
226 if (zebra_begin_trans (zh, 1))
232 zebra_repository_update (zh);
235 zebra_repository_delete (zh);
238 logf (LOG_LOG, "dumping %s", rGroupDef.path);
239 zebra_repository_show (zh);
243 zebra_create_database(zh, rGroupDef.path);
246 zebra_drop_database(zh, rGroupDef.path);
251 log_event_end (NULL, NULL);
256 printf("Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
257 printf(" (C) 1994-2003, Index Data ApS\n");
260 printf(" WIN32 Debug\n");
262 printf(" WIN32 Release\n");
266 printf("Using: libbzip2, (C) 1996-1999 Julian R Seward. All rights reserved.\n");
269 printf("Using: Tcl %s\n", TCL_VERSION);
274 XML_Expat_Version v = XML_ExpatVersionInfo();
275 printf ("Using: Expat %d.%d.%d\n",
276 v.major, v.minor, v.micro);
281 yaz_log_init_level (yaz_log_mask_str(arg));
283 yaz_log_init_file (arg);
287 rGroupDef.databaseName = arg;
289 rGroupDef.flagRw = 0;
291 rGroupDef.groupName = arg;
293 rGroupDef.fileVerboseLimit = atoi(arg);
297 rGroupDef.recordType = arg;
301 rGroupDef.followLinks = 0;
303 logf (LOG_WARN, "unknown option '-%s'", arg);
307 zebra_end_trans (zh);
314 gettimeofday(&end_time, 0);
315 usec = (end_time.tv_sec - start_time.tv_sec) * 1000000.0 +
316 end_time.tv_usec - start_time.tv_usec;
318 yaz_log (LOG_LOG, "zebraidx times: %5.2f %5.2f %5.2f",
320 (double) (tms2.tms_utime - tms1.tms_utime)/100,
321 (double) (tms2.tms_stime - tms1.tms_stime)/100);