Added support of CharacterSetandLanguageNegotiation-3
[yaz-moved-to-github.git] / client / client.c
index 07b00d9..4aa5ea6 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2002, Index Data
  * See the file LICENSE for details.
  *
- * $Id: client.c,v 1.148 2002-04-08 11:40:41 adam Exp $
+ * $Id: client.c,v 1.152 2002-05-18 09:52:37 oleg Exp $
  */
 
 #include <stdio.h>
@@ -20,6 +20,7 @@
 #include <yaz/marcdisp.h>
 #include <yaz/diagbib1.h>
 #include <yaz/otherinfo.h>
+#include <yaz/charneg.h>
 
 #include <yaz/pquery.h>
 #include <yaz/sortspec.h>
@@ -72,6 +73,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;
@@ -89,11 +92,12 @@ static QueryType queryType = QueryType_Prefix;
 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 +207,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_charset_and_lang(out, CLASS_NEGOT, VAL_CHARNEG3,
+                               (const char**)&yazCharset, (yazCharset)?1:0,
+                               (const char**)&yazLang, (yazLang)?1:0);
+       }
+    }
+    
     send_apdu(apdu);
     printf("Sent initrequest.\n");
 }
@@ -2055,6 +2076,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 +2090,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 +2557,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},
@@ -2606,7 +2665,7 @@ void process_cmd_line(char* line)
     {
         printf("Unknown command: %s.\n", word);
         cmd_help ("");
-
+        res = 1;
     }
 
     if(apdu_file) fflush(apdu_file);
@@ -2644,7 +2703,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 +2734,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);