Add new API function ZOOM_diag_str(), which maps error code to
authorMike Taylor <mike@indexdata.com>
Sat, 30 Nov 2002 22:30:51 +0000 (22:30 +0000)
committerMike Taylor <mike@indexdata.com>
Sat, 30 Nov 2002 22:30:51 +0000 (22:30 +0000)
human-readable message.  It uses code lifted from ZOOM_connection_error()
(which now calls it) to map the ZOOM-specific errors by hand, and fall
back to diagbib1_str() for others.  I did this because I need the new
function in ZOOM-C++, for reasons which would be otiose, for the moment,
to rehearse.

include/yaz/zoom.h
zutil/zoom-c.c

index 5775453..0937a20 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Public header for ZOOM C.
- * $Id: zoom.h,v 1.13 2002-06-02 21:27:17 adam Exp $
+ * $Id: zoom.h,v 1.14 2002-11-30 22:30:51 mike Exp $
  */
 
 #include <yaz/yconfig.h>
@@ -75,6 +75,9 @@ ZOOM_connection_errmsg (ZOOM_connection c);
 /* returns additional info */
 ZOOM_API(const char *)
 ZOOM_connection_addinfo (ZOOM_connection c);
+/* translates error code into human-readable string */
+ZOOM_API(const char *)
+ZOOM_diag_str (int error);
 
 #define ZOOM_ERROR_NONE 0
 #define ZOOM_ERROR_CONNECT 10000
index 995b263..c62a08a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: zoom-c.c,v 1.7 2002-11-15 10:38:37 adam Exp $
+ * $Id: zoom-c.c,v 1.8 2002-11-30 22:30:51 mike Exp $
  *
  * ZOOM layer for C, connections, result sets, queries.
  */
@@ -2244,6 +2244,34 @@ ZOOM_connection_addinfo (ZOOM_connection c)
     return addinfo;
 }
 
+ZOOM_API(const char *)
+ZOOM_diag_str (int error)
+{
+    switch (error)
+    {
+    case ZOOM_ERROR_NONE:
+       return "No error";
+    case ZOOM_ERROR_CONNECT:
+       return "Connect failed";
+    case ZOOM_ERROR_MEMORY:
+       return "Out of memory";
+    case ZOOM_ERROR_ENCODE:
+       return "Encoding failed";
+    case ZOOM_ERROR_DECODE:
+       return "Decoding failed";
+    case ZOOM_ERROR_CONNECTION_LOST:
+       return "Connection lost";
+    case ZOOM_ERROR_INIT:
+       return "Init rejected";
+    case ZOOM_ERROR_INTERNAL:
+       return "Internal failure";
+    case ZOOM_ERROR_TIMEOUT:
+       return "Timeout";
+    default:
+       return diagbib1_str (error);
+    }
+}
+
 ZOOM_API(int)
 ZOOM_connection_error (ZOOM_connection c, const char **cp,
                            const char **addinfo)
@@ -2251,29 +2279,7 @@ ZOOM_connection_error (ZOOM_connection c, const char **cp,
     int error = c->error;
     if (cp)
     {
-       switch (error)
-       {
-       case ZOOM_ERROR_NONE:
-           *cp = "No error"; break;
-       case ZOOM_ERROR_CONNECT:
-           *cp = "Connect failed"; break;
-       case ZOOM_ERROR_MEMORY:
-           *cp = "Out of memory"; break;
-       case ZOOM_ERROR_ENCODE:
-           *cp = "Encoding failed"; break;
-       case ZOOM_ERROR_DECODE:
-           *cp = "Decoding failed"; break;
-       case ZOOM_ERROR_CONNECTION_LOST:
-           *cp = "Connection lost"; break;
-       case ZOOM_ERROR_INIT:
-           *cp = "Init rejected"; break;
-       case ZOOM_ERROR_INTERNAL:
-           *cp = "Internal failure"; break;
-       case ZOOM_ERROR_TIMEOUT:
-           *cp = "Timeout"; break;
-       default:
-           *cp = diagbib1_str (error);
-       }
+       *cp = ZOOM_diag_str(error);
     }
     if (addinfo)
     {