Version 5.8.0
[yaz-moved-to-github.git] / util / srwtst.c
index 31a362e..e7411c5 100644 (file)
@@ -1,9 +1,10 @@
-/*
- * Copyright (C) 1995-2007, Index Data ApS
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) Index Data
  * See the file LICENSE for details.
- *
- * $Id: srwtst.c,v 1.8 2007-05-06 20:12:20 adam Exp $
  */
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <stdlib.h>
 #include <yaz/srw.h>
@@ -19,7 +20,6 @@ int main(int argc, char **argv)
     char buf[163840];
     char *content_buf = buf;
     int content_len;
-    int ret;
     size_t no;
     Z_SOAP *soap_package = 0;
     ODR decode, encode;
@@ -36,8 +36,8 @@ int main(int argc, char **argv)
     decode = odr_createmem(ODR_DECODE);
     encode = odr_createmem(ODR_ENCODE);
     content_len = no;
-    ret = z_soap_codec(decode, &soap_package, 
-                       &content_buf, &content_len, h);
+    z_soap_codec(decode, &soap_package,
+                 &content_buf, &content_len, h);
     if (!soap_package)
     {
         fprintf(stderr, "Decoding seriously failed\n");
@@ -51,20 +51,9 @@ int main(int argc, char **argv)
         {
             Z_SRW_PDU *sr = (Z_SRW_PDU *) soap_package->u.generic->p;
             if (sr->which == Z_SRW_searchRetrieve_request)
-            { 
+            {
                 Z_SRW_searchRetrieveRequest *req = sr->u.request;
-                switch(req->query_type)
-                {
-                case Z_SRW_query_type_cql:
-                    fprintf(stderr, "CQL: %s\n", req->query.cql);
-                    break;
-                case Z_SRW_query_type_xcql:
-                    fprintf(stderr, "XCQL\n");
-                    break;
-                case Z_SRW_query_type_pqf:
-                    fprintf(stderr, "PQF: %s\n", req->query.pqf);
-                    break;
-                }
+                fprintf(stderr, "%s: %s\n", req->queryType, req->query);
             }
             else if (sr->which == Z_SRW_searchRetrieve_response)
             {
@@ -76,18 +65,22 @@ int main(int argc, char **argv)
                     {
                         fprintf (stderr, "%d\n", i);
                         if (res->records[i].recordData_buf)
-                            fwrite(res->records[i].recordData_buf, 1,
-                                   res->records[i].recordData_len, stderr);
+                        {
+                            fprintf(stderr, "%.*s",
+                                    res->records[i].recordData_len,
+                                    res->records[i].recordData_buf);
+                        }
                     }
                 }
             }
 
         }
     }
-    ret = z_soap_codec(encode, &soap_package,
-                       &content_buf, &content_len, h);
+    z_soap_codec(encode, &soap_package, &content_buf, &content_len, h);
     if (content_buf && content_len)
-        fwrite (content_buf, content_len, 1, stdout);
+    {
+        printf("%.*s", content_len, content_buf);
+    }
     else
     {
         fprintf(stderr, "No output!\n");
@@ -107,6 +100,7 @@ int main(int argc, char **argv)
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab