Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/idzebra
[idzebra-moved-to-github.git] / index / zebraidx.c
index 0ec053c..db31bb7 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the Zebra server.
-   Copyright (C) 1994-2011 Index Data
+   Copyright (C) Index Data
 
 Zebra is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -17,6 +17,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 */
 
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -54,12 +57,11 @@ int main(int argc, char **argv)
     int cmd = 0;
     char *arg;
     char *configName = 0;
-    int nsections = 0;
     int enable_commit = 1;
     char *database = 0;
     Res res = res_open(0, 0);
     Res default_res = res_open(0, 0);
-    
+
     int trans_started = 0;
 #ifndef WIN32
     char nbuf[100];
@@ -84,7 +86,7 @@ int main(int argc, char **argv)
         " drop <db>     Drop database <db>\n"
         " commit        Commit changes\n"
         " clean         Clean shadow files\n"
-        " check:mode    Check register; mode is one of: default, full, quick\n"
+        " check mode    Check register; mode is one of: default, full, quick\n"
         "Options:\n"
        " -t <type>     Index files as <type> (grs or text).\n"
        " -c <config>   Read configuration file <config>.\n"
@@ -107,7 +109,7 @@ int main(int argc, char **argv)
     {
         if (ret == 0)
         {
-            if(cmd == 0) /* command */
+            if (cmd == 0) /* command */
             {
                 if (!zs)
                 {
@@ -117,7 +119,7 @@ int main(int argc, char **argv)
                     {
                        yaz_log(YLOG_FATAL, "Cannot read config %s", config);
                         exit(1);
-                   }   
+                   }
                     zh = zebra_open(zs, 0);
                    zebra_shadow_enable(zh, enable_commit);
                 }
@@ -178,20 +180,9 @@ int main(int argc, char **argv)
                 {
                     show_filters(zs);
                 }
-               else if (!strncmp(arg, "check", 5))
+               else if (!strcmp(arg, "check"))
                {
-                    const char *spec = 0;
-                    if (arg[5] == ':')
-                        spec = arg + 6;
-                    else if (arg[5] != '\0')
-                    {
-                        yaz_log(YLOG_FATAL, "missing colon after check");
-                        exit(1);
-                    }
-                    if (zebra_register_check(zh, spec) != ZEBRA_OK)
-                    {
-                        yaz_log(YLOG_WARN, "zebra_register_check failed");
-                    }
+                    cmd = 'K';
                }
                 else
                 {
@@ -204,12 +195,15 @@ int main(int argc, char **argv)
                ZEBRA_RES res = ZEBRA_OK;
                if (!trans_started)
                {
-                   trans_started=1;
+                   trans_started = 1;
                     if (zebra_begin_trans(zh, 1) != ZEBRA_OK)
                         exit(1);
                }
                 switch (cmd)
                 {
+                case 'K':
+                    res = zebra_register_check(zh, arg);
+                    break;
                 case 'u':
                     res = zebra_repository_index(zh, arg, action_update);
                     break;
@@ -221,7 +215,6 @@ int main(int argc, char **argv)
                     break;
                 case 's':
                     res = zebra_repository_show(zh, arg);
-                    nsections = 0;
                     break;
                case 'C':
                    res = zebra_create_database(zh, arg);
@@ -229,15 +222,13 @@ int main(int argc, char **argv)
                case 'D':
                    res = zebra_drop_database(zh, arg);
                    break;
-                default:
-                    nsections = 0;
                 }
                if (res != ZEBRA_OK)
                {
                     const char *add = zebra_errAdd(zh);
                    yaz_log(YLOG_FATAL, "Operation failed: %s %s",
                             zebra_errString(zh), add ? add : "");
-                    
+
                     if (trans_started)
                         if (zebra_end_trans(zh) != ZEBRA_OK)
                             yaz_log(YLOG_WARN, "zebra_end_trans failed");
@@ -257,7 +248,7 @@ int main(int argc, char **argv)
             zebra_get_version(version_str, sys_str);
 
             printf("Zebra %s\n", version_str);
-           printf("(C) 1994-2010, Index Data ApS\n");
+           printf("(C) 1994-2014, Index Data\n");
             printf("Zebra is free software, covered by the GNU General Public License, and you are\n");
             printf("welcome to change it and/or distribute copies of it under certain conditions.\n");
             printf("SHA1 ID: %s\n", sys_str);
@@ -293,16 +284,20 @@ int main(int argc, char **argv)
             yaz_log(YLOG_WARN, "unknown option '-%s'", arg);
     } /* while arg */
 
+    ret = 0;
     if (trans_started)
         if (zebra_end_trans(zh) != ZEBRA_OK)
+        {
             yaz_log(YLOG_WARN, "zebra_end_trans failed");
+            ret = 1;
+        }
 
     zebra_close(zh);
     zebra_stop(zs);
 
     res_close(res);
     res_close(default_res);
-    exit(0);
+    exit(ret);
     return 0;
 }