Remove --enable-module option
[yaz-moved-to-github.git] / client / client.c
index ff43888..0c67a87 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2002, Index Data
  * See the file LICENSE for details.
  *
- * $Id: client.c,v 1.149 2002-04-13 18:09:01 adam Exp $
+ * $Id: client.c,v 1.156 2002-06-02 21:34:45 adam Exp $
  */
 
 #include <stdio.h>
 #include <yaz/marcdisp.h>
 #include <yaz/diagbib1.h>
 #include <yaz/otherinfo.h>
+#include <yaz/charneg.h>
 
 #include <yaz/pquery.h>
 #include <yaz/sortspec.h>
 
-#if YAZ_MODULE_ill
 #include <yaz/ill.h>
-#endif
 
-#if YAZ_MODULE_ccl
 #include <yaz/yaz-ccl.h>
-#endif
 
 #if HAVE_READLINE_READLINE_H
 #include <readline/readline.h>
@@ -72,6 +69,8 @@ static char ccl_fields[512] = "default.bib";
 static char* esPackageName = 0;
 static char* yazProxy = 0;
 static int kilobytes = 1024;
+static char* yazCharset = 0;
+static char* yazLang = 0;
 
 static char last_cmd[32] = "?";
 static FILE *marcdump = 0;
@@ -85,15 +84,14 @@ typedef enum {
 
 static QueryType queryType = QueryType_Prefix;
 
-#if YAZ_MODULE_ccl
 static CCL_bibset bibset;               /* CCL bibset handle */
-#endif
 
-#if HAVE_READLINE_READLINE_H
-#ifndef RL_READLINE_VERSION
+#if HAVE_READLINE_COMPLETION_OVER
+
+#else
+/* readline doesn't have this var. Define it ourselves. */
 int rl_attempted_completion_over = 0;
 #endif
-#endif
 
 /* set this one to 1, to avoid decode of unknown MARCs  */
 #define AVOID_MARC_DECODE 1
@@ -203,6 +201,23 @@ static void send_initRequest(const char* type_and_host)
         yaz_oi_set_string_oidval(&req->otherInfo, out, VAL_PROXY,
         1, type_and_host);
     
+    if (yazCharset || yazLang) {
+       Z_OtherInformation **p;
+       Z_OtherInformationUnit *p0;
+       
+       yaz_oi_APDU(apdu, &p);
+       
+       if (p0=yaz_oi_update(p, out, NULL, 0, 0)) {
+               ODR_MASK_SET(req->options, Z_Options_negotiationModel);
+               
+               p0->which = Z_OtherInfo_externallyDefinedInfo;
+               p0->information.externallyDefinedInfo =
+                       yaz_set_proposal_charneg(out,
+                               (const char**)&yazCharset, (yazCharset)?1:0,
+                               (const char**)&yazLang, (yazLang)?1:0, 1);
+       }
+    }
+    
     send_apdu(apdu);
     printf("Sent initrequest.\n");
 }
@@ -280,6 +295,24 @@ static int process_initResponse(Z_InitResponse *res)
     if (ODR_MASK_GET(res->options, Z_Options_queryType104))
         printf (" queryType104");
     printf ("\n");
+    
+    if (ODR_MASK_GET(res->options, Z_Options_negotiationModel)) {
+    
+       Z_CharSetandLanguageNegotiation *p =
+               yaz_get_charneg_record(res->otherInfo);
+       
+       if (p) {
+       
+               char *charset=NULL, *lang=NULL;
+               int selected;
+               
+               yaz_get_response_charneg(session_mem, p, &charset, &lang, &selected);
+               
+               printf("Accepted character set : `%s'\n", charset);
+               printf("Accepted code language : `%s'\n", lang);
+               printf("Accepted records in ...: %d\n", selected );
+       }
+    }
     fflush (stdout);
     return 0;
 }
@@ -403,6 +436,7 @@ int cmd_authentication(char *arg)
 }
 
 /* SEARCH SERVICE ------------------------------ */
+static void display_record(Z_External *r);
 
 static void display_variant(Z_Variant *v, int level)
 {
@@ -424,7 +458,9 @@ static void display_grs1(Z_GenericRecord *r, int level)
     int i;
 
     if (!r)
+    {
         return;
+    }
     for (i = 0; i < r->num_elements; i++)
     {
         Z_TaggedElement *t;
@@ -442,8 +478,13 @@ static void display_grs1(Z_GenericRecord *r, int level)
             printf("%s) ", t->tagValue->u.string);
         if (t->content->which == Z_ElementData_subtree)
         {
-            printf("\n");
-            display_grs1(t->content->u.subtree, level+1);
+            if (!t->content->u.subtree)
+                printf (" (no subtree)\n");
+            else
+            {
+                printf("\n");
+                display_grs1(t->content->u.subtree, level+1);
+            }
         }
         else if (t->content->which == Z_ElementData_string)
             printf("%s\n", t->content->u.string);
@@ -470,8 +511,15 @@ static void display_grs1(Z_GenericRecord *r, int level)
             printf("[Element empty]\n");
         else if (t->content->which == Z_ElementData_elementNotThere)
             printf("[Element not there]\n");
+        else if (t->content->which == Z_ElementData_date)
+            printf("Date: %s\n", t->content->u.date);
+        else if (t->content->which == Z_ElementData_ext)
+        {
+            printf ("External\n");
+            display_record (t->content->u.ext);
+        } 
         else
-            printf("??????\n");
+            printf("? type = %d\n",t->content->which);
         if (t->appliedVariant)
             display_variant(t->appliedVariant, level+1);
         if (t->metaData && t->metaData->supportedVariants)
@@ -548,6 +596,8 @@ static void display_record(Z_External *r)
             r->which = type->what;
         }
     }
+    if (ent && ent->oclass != CLASS_RECSYN)
+        return;
     if (ent && ent->value == VAL_SOIF)
         print_record((const unsigned char *) r->u.octet_aligned->buf,
                      r->u.octet_aligned->len);
@@ -734,15 +784,12 @@ static int send_searchRequest(char *arg)
     Z_SearchRequest *req = apdu->u.searchRequest;
     Z_Query query;
     int oid[OID_SIZE];
-#if YAZ_MODULE_ccl
     struct ccl_rpn_node *rpn = NULL;
     int error, pos;
-#endif
     char setstring[100];
     Z_RPNQuery *RPNquery;
     Odr_oct ccl_query;
 
-#if YAZ_MODULE_ccl
     if (queryType == QueryType_CCL2RPN)
     {
         rpn = ccl_find_str(bibset, arg, &error, &pos);
@@ -752,7 +799,6 @@ static int send_searchRequest(char *arg)
             return 0;
         }
     }
-#endif
     req->referenceId = set_refid (out);
     if (!strcmp(arg, "@big")) /* strictly for troublemaking */
     {
@@ -810,7 +856,6 @@ static int send_searchRequest(char *arg)
         ccl_query.buf = (unsigned char*) arg;
         ccl_query.len = strlen(arg);
         break;
-#if YAZ_MODULE_ccl
     case QueryType_CCL2RPN:
         query.which = Z_Query_type_1;
         RPNquery = ccl_rpn_query(out, rpn);
@@ -822,7 +867,6 @@ static int send_searchRequest(char *arg)
         query.u.type_1 = RPNquery;
         ccl_rpn_delete (rpn);
         break;
-#endif
     default:
         printf ("Unsupported query type\n");
         return 0;
@@ -1135,8 +1179,6 @@ void process_ESResponse(Z_ExtendedServicesResponse *res)
     }
 }
 
-#if YAZ_MODULE_ill
-
 const char *get_ill_element (void *clientData, const char *element)
 {
     return 0;
@@ -1198,9 +1240,7 @@ static Z_External *create_external_itemRequest()
     }
     return r;
 }
-#endif
 
-#ifdef YAZ_MODULE_ill
 static Z_External *create_external_ILL_APDU(int which)
 {
     struct ill_get_ctl ctl;
@@ -1256,7 +1296,6 @@ static Z_External *create_external_ILL_APDU(int which)
     }
     return r;
 }
-#endif
 
 
 static Z_External *create_ItemOrderExternal(const char *type, int itemno)
@@ -2055,6 +2094,10 @@ int cmd_packagename(char* arg)
 
 int cmd_proxy(char* arg)
 {
+    if (*arg == '\0') {
+       printf("Current proxy is `%s'\n", (yazCharset)?yazProxy:NULL);
+       return 1;
+    }
     xfree (yazProxy);
     yazProxy = NULL;
     if (*arg)
@@ -2065,6 +2108,38 @@ int cmd_proxy(char* arg)
     return 1;
 }
 
+int cmd_charset(char* arg)
+{
+    if (*arg == '\0') {
+       printf("Current character set is `%s'\n", (yazCharset)?yazCharset:NULL);
+       return 1;
+    }
+    xfree (yazCharset);
+    yazCharset = NULL;
+    if (*arg)
+    {
+        yazCharset = (char *) xmalloc (strlen(arg)+1);
+        strcpy (yazCharset, arg);
+    } 
+    return 1;
+}
+
+int cmd_lang(char* arg)
+{
+    if (*arg == '\0') {
+       printf("Current language is `%s'\n", (yazLang)?yazLang:NULL);
+       return 1;
+    }
+    xfree (yazLang);
+    yazLang = NULL;
+    if (*arg)
+    {
+        yazLang = (char *) xmalloc (strlen(arg)+1);
+        strcpy (yazLang, arg);
+    } 
+    return 1;
+}
+
 int cmd_source(char* arg) 
 {
     /* first should open the file and read one line at a time.. */
@@ -2500,6 +2575,8 @@ static struct {
     {"update", cmd_update, "<item>",NULL,0},
     {"packagename", cmd_packagename, "<packagename>",NULL,0},
     {"proxy", cmd_proxy, "[('tcp'|'ssl')]<host>[':'<port>]",NULL,0},
+    {"charset", cmd_charset, "<charset_name>",NULL,0},
+    {"lang", cmd_lang, "<language_code>",NULL,0},
     {".", cmd_source, "<filename>",NULL,1},
     {"!", cmd_subshell, "Subshell command",NULL,0},
     {"set_apdufile", cmd_set_apdufile, "<filename>",NULL,0},
@@ -2644,7 +2721,7 @@ char ** readline_completer(char *text, int start, int end) {
 #if HAVE_READLINE_READLINE_H
 
     if(start == 0) {
-#ifdef RL_READLINE_VERSION
+#if HAVE_READLINE_RL_COMPLETION_MATCHES
         char** res=rl_completion_matches(text,
                                       command_generator); 
 #else
@@ -2675,7 +2752,7 @@ char ** readline_completer(char *text, int start, int end) {
         if(!cmd[i].complete_filenames) 
             rl_attempted_completion_over = 1;    
         if(cmd[i].rl_completerfunction) {
-#ifdef RL_READLINE_VERSION
+#ifdef HAVE_READLINE_RL_COMPLETION_MATCHES
             char** res=
                 rl_completion_matches(text,
                                    cmd[i].rl_completerfunction);