2 * Copyright (C) 1994-2002, Index Data
5 * $Id: main.c,v 1.88 2002-04-23 18:09:05 adam Exp $
16 #include <sys/times.h>
19 #include <yaz/data1.h>
24 int main (int argc, char **argv)
31 int disableCommit = 0;
34 struct tms tms1, tms2;
39 struct recordGroup rGroupDef;
47 sprintf(nbuf, "%.40s(%d)", *argv, getpid());
48 yaz_log_init_prefix (nbuf);
54 rGroupDef.groupName = NULL;
55 rGroupDef.databaseName = NULL;
56 rGroupDef.path = NULL;
57 rGroupDef.recordId = NULL;
58 rGroupDef.recordType = NULL;
59 rGroupDef.flagStoreData = -1;
60 rGroupDef.flagStoreKeys = -1;
62 rGroupDef.databaseNamePath = 0;
63 rGroupDef.explainDatabase = 0;
64 rGroupDef.fileVerboseLimit = 100000;
69 fprintf (stderr, "%s [options] command <dir> ...\n"
71 " update <dir> Update index with files below <dir>.\n"
72 " If <dir> is empty filenames are read from stdin.\n"
73 " delete <dir> Delete index with files below <dir>.\n"
74 " commit Commit changes\n"
75 " clean Clean shadow files\n"
77 " -t <type> Index files as <type> (grs or text).\n"
78 " -c <config> Read configuration file <config>.\n"
79 " -g <group> Index files according to group settings.\n"
80 " -d <database> Records belong to Z39.50 database <database>.\n"
81 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
82 " -n Don't use shadow system.\n"
83 " -s Show analysis on stdout, but do no work.\n"
84 " -v <level> Set logging to <level>.\n"
85 " -l <file> Write log to <file>.\n"
86 " -f <n> Display information for the first <n> records.\n"
87 " -V Show version.\n", *argv
91 while ((ret = options ("sVt:c:g:d:m:v:nf:l:"
92 , argv, argc, &arg)) != -2)
96 if(cmd == 0) /* command */
101 logf (LOG_LOG, "Z'mbol version %s %s",
102 ZEBRAVER, ZEBRADATE);
104 logf (LOG_LOG, "Zebra version %s %s",
105 ZEBRAVER, ZEBRADATE);
107 zs = zebra_start (configName ? configName : "zebra.cfg");
110 zh = zebra_open (zs);
112 zebra_shadow_enable (zh, 0);
114 if (rGroupDef.databaseName)
116 if (zebra_select_database (zh, rGroupDef.databaseName))
121 if (zebra_select_database (zh, "Default"))
125 if (!strcmp (arg, "update"))
127 else if (!strcmp (arg, "update1"))
129 else if (!strcmp (arg, "update2"))
131 else if (!strcmp (arg, "dump"))
133 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
135 else if (!strcmp (arg, "init"))
139 else if (!strcmp (arg, "commit"))
143 else if (!strcmp (arg, "clean"))
147 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
151 else if (!strcmp (arg, "compact"))
157 logf (LOG_FATAL, "unknown command: %s", arg);
163 rGroupDef.path = arg;
164 zebra_set_group (zh, &rGroupDef);
165 zebra_begin_trans (zh);
170 zebra_repository_update (zh);
173 zebra_repository_delete (zh);
176 logf (LOG_LOG, "dumping %s", rGroupDef.path);
177 zebra_repository_show (zh);
184 zebra_end_trans (zh);
185 log_event_end (NULL, NULL);
191 fprintf (stderr, "Z'mbol %s %s\n", ZEBRAVER, ZEBRADATE);
193 fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
195 fprintf (stderr, " (C) 1994-2002, Index Data ApS\n");
198 fprintf (stderr, " WIN32 Debug\n");
200 fprintf (stderr, " WIN32 Release\n");
204 fprintf (stderr, "libbzip2\n"
205 " (C) 1996-1999 Julian R Seward. All rights reserved.\n");
209 yaz_log_init_level (yaz_log_mask_str(arg));
211 yaz_log_init_file (arg);
213 mem_max = 1024*1024*atoi(arg);
215 rGroupDef.databaseName = arg;
217 rGroupDef.flagRw = 0;
219 rGroupDef.groupName = arg;
221 rGroupDef.fileVerboseLimit = atoi(arg);
225 rGroupDef.recordType = arg;
229 logf (LOG_WARN, "unknown option '-%s'", arg);
235 yaz_log (LOG_LOG, "zebraidx user/system: %ld/%ld",
236 (long) tms2.tms_utime - tms1.tms_utime,
237 (long) tms2.tms_stime - tms1.tms_stime);