X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=index%2Fmain.c;h=3508f2ad1233495c0d02eee2808e5cdc95fe6ab4;hp=389585d28b4dc1621ce8d73bce80bbdeb3fe8011;hb=7e75317bed8eecabcb57e59b16093a32238738e2;hpb=a02c4cf957603c707fe9f4fde94a468f1d030dfb diff --git a/index/main.c b/index/main.c index 389585d..3508f2a 100644 --- a/index/main.c +++ b/index/main.c @@ -1,33 +1,23 @@ /* - * Copyright (C) 1995, Index Data I/S + * Copyright (C) 1994-2002, Index Data * All rights reserved. - * Sebastian Hammer, Adam Dickmeiss - * - * $Log: main.c,v $ - * Revision 1.5 1995-09-04 09:10:39 adam - * More work on index add/del/update. - * Merge sort implemented. - * Initial work on z39 server. - * - * Revision 1.4 1995/09/01 14:06:36 adam - * Split of work into more files. - * - * Revision 1.3 1995/09/01 10:57:07 adam - * Minor changes. - * - * Revision 1.2 1995/09/01 10:30:24 adam - * More work on indexing. Not working yet. - * - * Revision 1.1 1995/08/31 14:50:24 adam - * New simple file index tool. * + * $Id: main.c,v 1.82 2002-02-20 17:30:01 adam Exp $ */ #include +#include #include +#ifdef WIN32 +#include +#else #include +#endif -#include +#include +#include "zebraapi.h" +#include "zserver.h" #include "index.h" +#include "recindex.h" char *prog; @@ -36,76 +26,191 @@ int main (int argc, char **argv) int ret; int cmd = 0; char *arg; - char *base_name = NULL; - char *base_path = NULL; + char *configName = 0; + int nsections = 0; + int disableCommit = 0; + size_t mem_max = 0; +#ifndef WIN32 + char nbuf[100]; +#endif + struct recordGroup rGroupDef; + ZebraService zs = 0; + ZebraHandle zh = 0; + + nmem_init (); + +#ifdef WIN32 +#else + sprintf(nbuf, "%.40s(%d)", *argv, getpid()); + yaz_log_init_prefix (nbuf); +#endif + + rGroupDef.groupName = NULL; + rGroupDef.databaseName = NULL; + rGroupDef.path = NULL; + rGroupDef.recordId = NULL; + rGroupDef.recordType = NULL; + rGroupDef.flagStoreData = -1; + rGroupDef.flagStoreKeys = -1; + rGroupDef.flagRw = 1; + rGroupDef.databaseNamePath = 0; + rGroupDef.explainDatabase = 0; + rGroupDef.fileVerboseLimit = 100000; prog = *argv; - while ((ret = options ("r:v:", argv, argc, &arg)) != -2) + if (argc < 2) + { + fprintf (stderr, "%s [options] command ...\n" + "Commands:\n" + " update Update index with files below .\n" + " If is empty filenames are read from stdin.\n" + " delete Delete index with files below .\n" + " commit Commit changes\n" + " clean Clean shadow files\n" + "Options:\n" + " -t Index files as (grs or text).\n" + " -c Read configuration file .\n" + " -g Index files according to group settings.\n" + " -d Records belong to Z39.50 database .\n" + " -m Use before flushing keys to disk.\n" + " -n Don't use shadow system.\n" + " -s Show analysis on stdout, but do no work.\n" + " -v Set logging to .\n" + " -l Write log to .\n" + " -f Display information for the first records.\n" + " -V Show version.\n", *argv + ); + exit (1); + } + while ((ret = options ("sVt:c:g:d:m:v:nf:l:" + , argv, argc, &arg)) != -2) { if (ret == 0) { - if (!base_name) + if(cmd == 0) /* command */ { - base_name = arg; + if (!zs) + { +#if ZMBOL + logf (LOG_LOG, "zmbol version %s %s", + ZEBRAVER, ZEBRADATE); +#else + logf (LOG_LOG, "zebra version %s %s", + ZEBRAVER, ZEBRADATE); +#endif + zs = zebra_start (configName ? configName : FNAME_CONFIG); - common_resource = res_open (base_name); - if (!common_resource) + zh = zebra_open (zs); + } + if (!strcmp (arg, "update")) + cmd = 'u'; + else if (!strcmp (arg, "update1")) + cmd = 'U'; + else if (!strcmp (arg, "update2")) + cmd = 'm'; + else if (!strcmp (arg, "dump")) + cmd = 's'; + else if (!strcmp (arg, "del") || !strcmp(arg, "delete")) + cmd = 'd'; + else if (!strcmp (arg, "init")) + { + zebra_init (zh); + } + else if (!strcmp (arg, "commit")) { - log (LOG_FATAL, "Cannot open resource `%s'", base_name); - exit (1); + zebra_commit (zh); } - } - else if(cmd == 0) /* command */ - { - if (!strcmp (arg, "add")) + else if (!strcmp (arg, "clean")) { - cmd = 'a'; + assert (!"todo"); } - else if (!strcmp (arg, "del")) + else if (!strcmp (arg, "stat") || !strcmp (arg, "status")) { - cmd = 'd'; + assert (!"todo"); + } + else if (!strcmp (arg, "compact")) + { + zebra_compact (zh); } else { - log (LOG_FATAL, "Unknown command: %s", arg); + logf (LOG_FATAL, "unknown command: %s", arg); exit (1); } } - else + else { - unlink ("keys.tmp"); - key_open ("keys.tmp"); - repository (cmd, arg, base_path); + memcpy (&zh->rGroup, &rGroupDef, sizeof(rGroupDef)); + zebra_begin_trans (zh); + + zh->rGroup.path = arg; + switch (cmd) + { + case 'u': + zebra_repository_update (zh); + break; + case 'd': + zebra_repository_delete (zh); + break; + case 's': + logf (LOG_LOG, "dumping %s", zh->rGroup.path); + zebra_repository_show (zh); + nsections = 0; + break; + default: + nsections = 0; + } cmd = 0; + zebra_end_trans (zh); + log_event_end (NULL, NULL); } } - else if (ret == 'v') - { - log_init (log_mask_str(arg), prog, NULL); - } - else if (ret == 'r') + else if (ret == 'V') { - base_path = arg; +#if ZMBOL + fprintf (stderr, "Z'mbol %s %s\n", ZEBRAVER, ZEBRADATE); +#else + fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE); +#endif + fprintf (stderr, " (C) 1994-2002, Index Data ApS\n"); +#ifdef WIN32 +#ifdef _DEBUG + fprintf (stderr, " WIN32 Debug\n"); +#else + fprintf (stderr, " WIN32 Release\n"); +#endif +#endif +#if HAVE_BZLIB_H + fprintf (stderr, "libbzip2\n" + " (C) 1996-1999 Julian R Seward. All rights reserved.\n"); +#endif } + else if (ret == 'v') + yaz_log_init_level (yaz_log_mask_str(arg)); + else if (ret == 'l') + yaz_log_init_file (arg); + else if (ret == 'm') + mem_max = 1024*1024*atoi(arg); + else if (ret == 'd') + rGroupDef.databaseName = arg; + else if (ret == 's') + rGroupDef.flagRw = 0; + else if (ret == 'g') + rGroupDef.groupName = arg; + else if (ret == 'f') + rGroupDef.fileVerboseLimit = atoi(arg); + else if (ret == 'c') + configName = arg; + else if (ret == 't') + rGroupDef.recordType = arg; + else if (ret == 'n') + disableCommit = 1; else - { - log (LOG_FATAL, "Unknown option '-%s'", arg); - exit (1); - } + logf (LOG_WARN, "unknown option '-%s'", arg); } - if (!base_name) - { - fprintf (stderr, "index [-v log] [-r repository] " - "base cmd1 dir1 cmd2 dir2 ...\n"); - exit (1); - } - key_flush (); - if (!key_close ()) - exit (0); - log (LOG_DEBUG, "Sorting"); - if (!key_sort ("keys.tmp", 1000000)) - exit (0); - log (LOG_DEBUG, "Input"); - key_input ("dictinv", "isaminv", "keys.tmp", 50); + zebra_close (zh); + zebra_stop (zs); exit (0); + return 0; } +