Fidgeting.
[yaz-moved-to-github.git] / client / client.c
index 9f24bd4..90438a6 100644 (file)
@@ -4,7 +4,13 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: client.c,v $
- * Revision 1.28  1995-12-14 11:09:31  quinn
+ * Revision 1.30  1996-02-12 18:18:09  quinn
+ * Fidgeting.
+ *
+ * Revision 1.29  1996/01/02  08:57:25  quinn
+ * Changed enums in the ASN.1 .h files to #defines. Changed oident.class to oclass
+ *
+ * Revision 1.28  1995/12/14  11:09:31  quinn
  * Added Explain record syntax to the format command.
  *
  * Revision 1.27  1995/12/12  16:37:02  quinn
@@ -145,6 +151,10 @@ static ODR_MEM session_mem;                /* memory handle for init-response */
 static Z_InitResponse *session = 0;        /* session parameters */
 static char last_scan[512] = "0";
 static char last_cmd[100] = "?";
+static oid_value attributeset = VAL_BIB1;
+static FILE *marcdump = 0;
+static char marcdump_file[512] = "marc.out";
+
 #ifdef RPN_QUERY
 #ifndef PREFIX_QUERY
 static CCL_bibset bibset;               /* CCL bibset handle */
@@ -398,7 +408,29 @@ static void display_record(Z_DatabaseRecord *p)
         }
     }
     if (r->which == Z_External_octet && p->u.octet_aligned->len)
+    {
+#if 0
+       if (marcdump)
+           fwrite(p->u.octet_aligned->buf, p->u.octet_aligned->len, 1,
+               marcdump);
+#endif
+        static count = 0;
+        FILE *f;
+        char buf[256];
+
+        sprintf(buf, "marc.%d", count++);
+        if (!(f = fopen(buf, "w")))
+        {
+            perror(buf);
+            exit(1);
+
+        }
+        fwrite(p->u.octet_aligned->buf, p->u.octet_aligned->len, 1, f);
+        fclose(f);
+
+
         marc_display ((char*)p->u.octet_aligned->buf, stdout);
+    }
     else if (ent->value == VAL_SUTRS)
     {
         if (r->which != Z_External_sutrs)
@@ -448,7 +480,7 @@ static void display_diagrec(Z_DiagRec *p)
         r = p->u.defaultFormat;
 #endif
     if (!(ent = oid_getentbyoid(r->diagnosticSetId)) ||
-        ent->class != CLASS_DIAGSET || ent->value != VAL_BIB1)
+        ent->oclass != CLASS_DIAGSET || ent->value != VAL_BIB1)
         printf("Missing or unknown diagset\n");
     printf("    [%d] %s", *r->condition, diagbib1_str(*r->condition));
     if (r->addinfo && *r->addinfo)
@@ -538,7 +570,7 @@ static int send_searchRequest(char *arg)
         oident prefsyn;
 
         prefsyn.proto = protocol;
-        prefsyn.class = CLASS_RECSYN;
+        prefsyn.oclass = CLASS_RECSYN;
         prefsyn.value = recordsyntax;
         req->preferredRecordSyntax = odr_oiddup(out, oid_getoidbyent(&prefsyn));
         req->smallSetElementSetNames =
@@ -563,7 +595,7 @@ static int send_searchRequest(char *arg)
     }
 #endif
     bib1.proto = protocol;
-    bib1.class = CLASS_ATTSET;
+    bib1.oclass = CLASS_ATTSET;
     bib1.value = VAL_BIB1;
     RPNquery->attributeSetId = oid_getoidbyent(&bib1);
     query.u.type_1 = RPNquery;
@@ -696,7 +728,7 @@ static int send_presentRequest(char *arg)
     req->resultSetStartPoint = &setno;
     req->numberOfRecordsRequested = &nos;
     prefsyn.proto = protocol;
-    prefsyn.class = CLASS_RECSYN;
+    prefsyn.oclass = CLASS_RECSYN;
     prefsyn.value = recordsyntax;
     req->preferredRecordSyntax = oid_getoidbyent(&prefsyn);
     if (elementSetNames)
@@ -790,7 +822,7 @@ int send_scanrequest(char *string, int pp, int num)
     req->num_databaseNames = 1;
     req->databaseNames = &db;
     attset.proto = protocol;
-    attset.class = CLASS_ATTSET;
+    attset.oclass = CLASS_ATTSET;
     attset.value = VAL_BIB1;
     req->attributeSet = oid_getoidbyent(&attset);
     req->termListAndStartPoint = p_query_scan(out, string);
@@ -924,6 +956,26 @@ int cmd_elements(char *arg)
     return 1;
 }
 
+int cmd_attributeset(char *arg)
+{
+    char what[100];
+    oid_value v;
+
+    if (!arg || !*arg)
+    {
+       printf("Usage: attributeset <setname>\n");
+       return 0;
+    }
+    sscanf(arg, "%s", what);
+    if ((v = oid_getvalbyname(what)) == VAL_NONE)
+    {
+       printf("Unknown attribute set name\n");
+       return 0;
+    }
+    attributeset = v;
+    return 1;
+}
+
 int cmd_close(char *arg)
 {
     Z_APDU *apdu = zget_APDU(out, Z_APDU_close);
@@ -989,6 +1041,7 @@ static int client(void)
         {"format", cmd_format, "<recordsyntax>"},
         {"elements", cmd_elements, "<elementSetName>"},
         {"close", cmd_close, ""},
+       {"attributeset", cmd_attributeset, "<attrset>"},
         {0,0}
     };
     char *netbuffer= 0;
@@ -1121,5 +1174,10 @@ int main(int argc, char **argv)
         cmd_open(argv[1]);
     else
         printf(C_PROMPT);
+    if (*marcdump_file && !(marcdump = fopen(marcdump_file, "a")))
+    {
+       perror(marcdump_file);
+       exit(1);
+    }
     return client();
 }