Split YAZ library into two libs : libyaz.la and libyaz_server.la.
[yaz-moved-to-github.git] / zoom / zoomsh.c
index 111f629..8b790f1 100644 (file)
@@ -1,11 +1,13 @@
 /*
- * Copyright (C) 1995-2005, Index Data ApS
+ * Copyright (C) 1995-2007, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: zoomsh.c,v 1.37 2005-06-25 15:46:08 adam Exp $
+ * $Id: zoomsh.c,v 1.47 2007-04-17 20:26:19 adam Exp $
  */
 
-/* ZOOM-C Shell */
+/** \file zoomsh.c
+    \brief ZOOM C command line tool (shell)
+*/
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -26,7 +28,6 @@
 #include <yaz/log.h>
 #include <yaz/nmem.h>
 #include <yaz/zoom.h>
-#include <yaz/oid.h>
 
 #define MAX_CON 100
 
@@ -122,6 +123,30 @@ static void cmd_get (ZOOM_connection *c, ZOOM_resultset *r,
     }
 }
 
+static void cmd_rget(ZOOM_connection *c, ZOOM_resultset *r,
+                     ZOOM_options options,
+                     const char **args)
+{
+    char key[40];
+    if (next_token_copy (args, key, sizeof(key)) < 0)
+    {
+        printf ("missing argument for get\n");
+    }
+    else
+    {
+        int i;
+        for (i = 0; i<MAX_CON; i++)
+        {
+            const char *val;
+            if (!r[i])
+                continue;
+            
+            val = ZOOM_resultset_option_get(r[i], key);
+            printf ("%s = %s\n", key, val ? val : "<null>");
+        }
+    }
+}
+
 static void cmd_close (ZOOM_connection *c, ZOOM_resultset *r,
                        ZOOM_options options,
                        const char **args)
@@ -158,22 +183,34 @@ static void display_records (ZOOM_connection c,
         int pos = i + start;
         ZOOM_record rec = ZOOM_resultset_record (r, pos);
         const char *db = ZOOM_record_get (rec, "database", 0);
-        int len, opac_len;
-        const char *render = ZOOM_record_get (rec, "render", &len);
-        const char *opac_render = ZOOM_record_get (rec, "opac", &opac_len);
-        const char *syntax = ZOOM_record_get (rec, "syntax", 0);
-        /* if rec is non-null, we got a record for display */
-        if (rec)
+        
+        if (ZOOM_record_error(rec, 0, 0, 0))
         {
-            char oidbuf[100];
-            (void) oid_name_to_dotstring(CLASS_RECSYN, syntax, oidbuf);
-            printf ("%d %s %s (%s)\n",
-                    pos+1, (db ? db : "unknown"), syntax, oidbuf);
-            if (render)
-                fwrite (render, 1, len, stdout);
-            printf ("\n");
-            if (opac_render)
-                fwrite (opac_render, 1, opac_len, stdout);
+            const char *msg;
+            const char *addinfo;
+            const char *diagset;
+            int error = ZOOM_record_error(rec, &msg, &addinfo, &diagset);
+            
+            printf("%d %s: %s (%s:%d) %s\n", pos, (db ? db : "unknown"),
+                   msg, diagset, error, addinfo);
+        }
+        else
+        {
+            int len, opac_len;
+            const char *render = ZOOM_record_get (rec, "render", &len);
+            const char *opac_render = ZOOM_record_get (rec, "opac", &opac_len);
+            const char *syntax = ZOOM_record_get (rec, "syntax", 0);
+            /* if rec is non-null, we got a record for display */
+            if (rec)
+            {
+                printf ("%d %s %s\n",
+                        pos, (db ? db : "unknown"), syntax);
+                if (render)
+                    fwrite (render, 1, len, stdout);
+                printf ("\n");
+                if (opac_render)
+                    fwrite (opac_render, 1, opac_len, stdout);
+            }
         }
             
     }
@@ -330,8 +367,8 @@ static void cmd_search (ZOOM_connection *c, ZOOM_resultset *r,
             int start = ZOOM_options_get_int (options, "start", 0);
             int count = ZOOM_options_get_int (options, "count", 0);
 
-            printf ("%s: %d hits\n", ZOOM_connection_option_get(c[i], "host"),
-                    ZOOM_resultset_size(r[i]));
+            printf ("%s: %ld hits\n", ZOOM_connection_option_get(c[i], "host"),
+                    (long) ZOOM_resultset_size(r[i]));
             /* and display */
             display_records (c[i], r[i], start, count);
         }
@@ -488,6 +525,8 @@ static int cmd_parse (ZOOM_connection *c, ZOOM_resultset *r,
         cmd_set (c, r, options, buf);
     else if (is_command ("get", cmd_str, cmd_len))
         cmd_get (c, r, options, buf);
+    else if (is_command ("rget", cmd_str, cmd_len))
+        cmd_rget (c, r, options, buf);
     else if (is_command ("connect", cmd_str, cmd_len))
         cmd_connect (c, r, options, buf);
     else if (is_command ("open", cmd_str, cmd_len))
@@ -605,9 +644,7 @@ int main(int argc, char **argv)
         int mask = yaz_log_mask_str(maskstr);
         yaz_log_init_level(mask);
     }
-    nmem_init();
     zoomsh(argc, argv);
-    nmem_exit();
     exit (0);
 }
 /*