Smallish.
[yaz-moved-to-github.git] / client / client.c
index ee1de6d..5dbe876 100644 (file)
@@ -4,7 +4,25 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: client.c,v $
- * Revision 1.1  1995-05-22 11:30:31  quinn
+ * Revision 1.7  1995-06-02 09:50:09  quinn
+ * Smallish.
+ *
+ * Revision 1.6  1995/05/31  08:29:21  quinn
+ * Nothing significant.
+ *
+ * Revision 1.5  1995/05/29  08:10:47  quinn
+ * Moved oid.c to util.
+ *
+ * Revision 1.4  1995/05/22  15:30:13  adam
+ * Client uses prefix query notation.
+ *
+ * Revision 1.3  1995/05/22  15:06:53  quinn
+ * *** empty log message ***
+ *
+ * Revision 1.2  1995/05/22  14:56:40  quinn
+ * *** empty log message ***
+ *
+ * Revision 1.1  1995/05/22  11:30:31  quinn
  * Added prettier client.
  *
  *
 #endif
 
 #include <proto.h>
-#include <oid.h>
 
 #include <marcdisp.h>
+
+#ifdef RPN_QUERY
+#ifdef PREFIX_QUERY
+#include <pquery.h>
+#else
 #include <yaz-ccl.h>
+#endif
+#endif
+
 #include "../version.h"
 
 #define C_PROMPT "Z> "
@@ -45,7 +70,11 @@ static int largeSetLowerBound = 1;
 static int mediumSetPresentNumber = 0;
 static int setno = 1;                   /* current set offset */
 static int protocol = PROTO_Z3950;      /* current app protocol */
+#ifdef RPN_QUERY
+#ifndef PREFIX_QUERY
 static CCL_bibset bibset;               /* CCL bibset handle */
+#endif
+#endif
 
 static void send_apdu(Z_APDU *a)
 {
@@ -76,9 +105,8 @@ static void send_initRequest()
     ODR_MASK_SET(req->options, Z_Options_search);
     ODR_MASK_SET(req->options, Z_Options_present);
 
-    ODR_MASK_SET(req->protocolVersion, 0);
-    ODR_MASK_SET(req->protocolVersion, 1);
-    ODR_MASK_SET(req->protocolVersion, 2);
+    ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_1);
+    ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_2);
 
     req->idAuthentication = auth;
 
@@ -160,7 +188,7 @@ int cmd_open(char *arg)
        fprintf(stderr, "Bad type: %s\n", type);
        return 0;
     }
-    if (!(conn = cs_create(t, 1, CS_Z3950)))
+    if (!(conn = cs_create(t, 1, protocol)))
     {
        perror("cs_create");
        return 0;
@@ -174,7 +202,7 @@ int cmd_open(char *arg)
        conn = 0;
        return 0;
     }
-    printf("Ok!\n");
+    printf("Ok.\n");
     send_initRequest();
     return 2;
 }
@@ -283,16 +311,22 @@ static int send_searchRequest(char *arg)
     Z_SearchRequest *req = apdu->u.searchRequest;
     char *databaseNames = database;
     Z_Query query;
+#ifdef RPN_QUERY
+#ifndef PREFIX_QUERY
+    struct ccl_rpn_node *rpn;
     int error, pos;
+#endif
+#endif
     char setstring[100];
+#ifdef RPN_QUERY
     Z_RPNQuery *RPNquery;
     oident bib1;
-    struct ccl_rpn_node *rpn;
-#ifndef RPN_QUERY
+#else
     Odr_oct ccl_query;
 #endif
 
 #ifdef RPN_QUERY
+#ifndef PREFIX_QUERY
     rpn = ccl_find_str(bibset, arg, &error, &pos);
     if (error)
     {
@@ -300,6 +334,7 @@ static int send_searchRequest(char *arg)
        return 0;
     }
 #endif
+#endif
 
     if (!strcmp(arg, "@big")) /* strictly for troublemaking */
     {
@@ -328,7 +363,17 @@ static int send_searchRequest(char *arg)
 
 #ifdef RPN_QUERY
     query.which = Z_Query_type_1;
+
+#ifndef PREFIX_QUERY
     assert((RPNquery = ccl_rpn_query(rpn)));
+#else
+    RPNquery = p_query_rpn (out, arg);
+    if (!RPNquery)
+    {
+        printf("Prefix query error\n");
+        return 0;
+    }
+#endif
     bib1.proto = protocol;
     bib1.class = CLASS_ATTSET;
     bib1.value = VAL_BIB1;
@@ -432,7 +477,7 @@ static int cmd_setnames(char *arg)
        printf("Set numbering disabled.\n");
        setnumber = -1;
     }
-    return 2;
+    return 1;
 }
 
 /* PRESENT SERVICE ----------------------------- */
@@ -480,7 +525,11 @@ int cmd_quit(char *arg)
 
 static void initialize(void)
 {
+#ifdef RPN_QUERY
+#ifndef PREFIX_QUERY
     FILE *inf;
+#endif
+#endif
 
     if (!(out = odr_createmem(ODR_ENCODE)) ||
        !(in = odr_createmem(ODR_DECODE)) ||
@@ -491,6 +540,8 @@ static void initialize(void)
     }
     setvbuf(stdout, 0, _IONBF, 0);
 
+#ifdef RPN_QUERY
+#ifndef PREFIX_QUERY
     bibset = ccl_qual_mk (); 
     inf = fopen ("default.bib", "r");
     if (inf)
@@ -498,6 +549,8 @@ static void initialize(void)
        ccl_qual_file (bibset, inf);
        fclose (inf);
     }
+#endif
+#endif
 }
 
 static int client(void)
@@ -525,7 +578,6 @@ static int client(void)
     int i;
     Z_APDU *apdu;
 
-    printf(C_PROMPT);
     while (1)
     {
        int res;
@@ -637,5 +689,7 @@ int main(int argc, char **argv)
     initialize();
     if (argc > 1)
        cmd_open(argv[1]);
+    else
+       printf(C_PROMPT);
     return client();
 }