1 /* $Id: main.c,v 1.102 2003-03-04 23:30:20 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
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 " commit Commit changes\n"
100 " clean Clean shadow files\n"
102 " -t <type> Index files as <type> (grs or text).\n"
103 " -c <config> Read configuration file <config>.\n"
104 " -g <group> Index files according to group settings.\n"
105 " -d <database> Records belong to Z39.50 database <database>.\n"
106 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
107 " -n Don't use shadow system.\n"
108 " -s Show analysis on stdout, but do no work.\n"
109 " -v <level> Set logging to <level>.\n"
110 " -l <file> Write log to <file>.\n"
111 " -L Don't follow symbolic links.\n"
112 " -f <n> Display information for the first <n> records.\n"
113 " -V Show version.\n", *argv
117 while ((ret = options ("sVt:c:g:d:m:v:nf:l:L"
118 , argv, argc, &arg)) != -2)
122 if(cmd == 0) /* command */
126 const char *config = configName ? configName : "zebra.cfg";
127 logf (LOG_LOG, "Zebra version %s %s",
128 ZEBRAVER, ZEBRADATE);
129 zs = zebra_start (config);
132 yaz_log (LOG_FATAL, "Cannot read config %s", config);
135 zh = zebra_open (zs);
137 zebra_shadow_enable (zh, 0);
140 if (rGroupDef.databaseName)
142 if (zebra_select_database (zh, rGroupDef.databaseName))
144 logf(LOG_FATAL, "Could not select database %s errCode=%d",
145 rGroupDef.databaseName, zebra_errCode(zh) );
151 if (zebra_select_database (zh, "Default"))
153 logf(LOG_FATAL, "Could not select database Default errCode=%d",
159 zebra_set_resource(zh, "memmax",mem_max);
161 if (!strcmp (arg, "update"))
163 else if (!strcmp (arg, "update1"))
165 else if (!strcmp (arg, "update2"))
167 else if (!strcmp (arg, "dump"))
169 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
171 else if (!strcmp (arg, "init"))
175 else if (!strcmp (arg, "commit"))
179 else if (!strcmp (arg, "clean"))
183 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
185 zebra_register_statistics (zh,0);
187 else if (!strcmp (arg, "dump") || !strcmp (arg, "dumpdict"))
189 zebra_register_statistics (zh,1);
191 else if (!strcmp (arg, "compact"))
197 logf (LOG_FATAL, "unknown command: %s", arg);
203 rGroupDef.path = arg;
204 zebra_set_group (zh, &rGroupDef);
208 zebra_begin_trans (zh, 1);
214 zebra_repository_update (zh);
217 zebra_repository_delete (zh);
220 logf (LOG_LOG, "dumping %s", rGroupDef.path);
221 zebra_repository_show (zh);
227 log_event_end (NULL, NULL);
232 printf("Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
233 printf(" (C) 1994-2002, Index Data ApS\n");
236 printf(" WIN32 Debug\n");
238 printf(" WIN32 Release\n");
243 " (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);
253 rGroupDef.databaseName = arg;
255 rGroupDef.flagRw = 0;
257 rGroupDef.groupName = arg;
259 rGroupDef.fileVerboseLimit = atoi(arg);
263 rGroupDef.recordType = arg;
267 rGroupDef.followLinks = 0;
269 logf (LOG_WARN, "unknown option '-%s'", arg);
273 zebra_end_trans (zh);
280 gettimeofday(&end_time, 0);
281 usec = (end_time.tv_sec - start_time.tv_sec) * 1000000L +
282 end_time.tv_usec - start_time.tv_usec;
284 yaz_log (LOG_LOG, "zebraidx times: %5.2f %5.2f %5.2f",
285 (double) usec / 1000000.0,
286 (double) (tms2.tms_utime - tms1.tms_utime)/100,
287 (double) (tms2.tms_stime - tms1.tms_stime)/100);