Moved back to a single log.h, with the new #define YAZ_USE_NEW_LOG
[yaz-moved-to-github.git] / client / client.c
index 3a3cc7e..5791eac 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2004, Index Data
  * See the file LICENSE for details.
  *
- * $Id: client.c,v 1.255 2004-11-02 11:37:21 heikki Exp $
+ * $Id: client.c,v 1.261 2004-12-13 14:21:54 heikki Exp $
  */
 
 #include <stdio.h>
@@ -2987,7 +2987,11 @@ int cmd_marccharset(const char *arg)
 
     *l1 = 0;
     if (sscanf(arg, "%29s", l1) < 1)
+    {
+       printf("MARC character set is `%s'\n", 
+               marcCharset ? marcCharset: "none");
         return 1;
+    }
     xfree (marcCharset);
     marcCharset = 0;
     if (strcmp(l1, "-"))
@@ -2995,50 +2999,76 @@ int cmd_marccharset(const char *arg)
     return 1;
 }
 
-int cmd_charset(const char* arg)
+int cmd_displaycharset(const char *arg)
 {
-    char l1[30], l2[30];
+    char l1[30];
 
-    *l1 = *l2 = 0;
-    if (sscanf(arg, "%29s %29s", l1, l2) < 1)
+    *l1 = 0;
+    if (sscanf(arg, "%29s", l1) < 1)
     {
-       printf("Current negotiation character set is `%s'\n", 
-               negotiationCharset ? negotiationCharset: "none");
-       printf("Current output character set is `%s'\n", 
+       printf("Display character set is `%s'\n", 
                outputCharset ? outputCharset: "none");
-       return 1;
-    }
-    xfree (negotiationCharset);
-    negotiationCharset = NULL;
-    if (*l1 && strcmp(l1, "-"))
-    {
-        negotiationCharset = xstrdup(l1);
-        printf ("Character set negotiation : %s\n", negotiationCharset);
     }
     else
-        printf ("Character set negotiation disabled\n");
-    if (*l2)
     {
         xfree (outputCharset);
         outputCharset = 0;
-        if (!strcmp(l2, "auto") && codeset)
+        if (!strcmp(l1, "auto") && codeset)
         {
             if (codeset)
             {
-                printf ("output charset: %s\n", codeset);
+                printf ("Display character set: %s\n", codeset);
                 outputCharset = xstrdup(codeset);
-
-
             }
             else
                 printf ("No codeset found on this system\n");
         }
-        else if (strcmp(l2, "-"))
-            outputCharset = xstrdup(l2);
-        else
-            printf ("Output charset conversion disabled\n");
+        else if (strcmp(l1, "-") && strcmp(l1, "none"))
+            outputCharset = xstrdup(l1);
     } 
+    return 1;
+}
 
+int cmd_negcharset(const char *arg)
+{
+    char l1[30];
+
+    *l1 = 0;
+    if (sscanf(arg, "%29s", l1) < 1)
+    {
+       printf("Current negotiation character set is `%s'\n", 
+               negotiationCharset ? negotiationCharset: "none");
+       return 1;
+    }
+    xfree (negotiationCharset);
+    negotiationCharset = NULL;
+    if (*l1 && strcmp(l1, "-") && strcmp(l1, "none"))
+    {
+        negotiationCharset = xstrdup(l1);
+        printf ("Character set negotiation : %s\n", negotiationCharset);
+    }
+    return 1;
+}
+
+int cmd_charset(const char* arg)
+{
+    char l1[30], l2[30], l3[30];
+
+    *l1 = *l2 = *l3 = 0;
+    if (sscanf(arg, "%29s %29s %29s", l1, l2, l3) < 1)
+    {
+       cmd_negcharset("");
+       cmd_displaycharset("");
+       cmd_marccharset("");
+    }
+    else
+    {
+       cmd_negcharset(l1);
+       if (*l2)
+           cmd_displaycharset(l2);
+       if (*l3)
+           cmd_marccharset(l3);
+    }
     return 1;
 }
 
@@ -3055,7 +3085,7 @@ int cmd_lang(const char* arg)
     return 1;
 }
 
-int cmd_source(const char* arg) 
+int cmd_source(const char* arg, int echo ) 
 {
     /* first should open the file and read one line at a time.. */
     FILE* includeFile;
@@ -3082,7 +3112,10 @@ int cmd_source(const char* arg)
         
         if ((cp = strrchr (line, '\n')))
             *cp = '\0';
-        
+       
+       if( echo ) {
+           printf( "processing line: %s\n",line );
+       };
         process_cmd_line(line);
     }
     
@@ -3093,6 +3126,19 @@ int cmd_source(const char* arg)
     return 1;
 }
 
+int cmd_source_echo(const char* arg)
+{ 
+    cmd_source(arg, 1);
+    return 1;
+}
+
+int cmd_source_noecho(const char* arg)
+{
+    cmd_source(arg, 0);
+    return 1;
+}
+
+
 int cmd_subshell(const char* args)
 {
     if(strlen(args)) 
@@ -3306,17 +3352,19 @@ void source_rcfile()
     struct stat statbuf;
     char buffer[1000];
     char* homedir=getenv("HOME");
-    
-    if(!homedir) return;
-    
-    sprintf(buffer,"%s/.yazclientrc",homedir);
-    
-    if(stat(buffer,&statbuf)==0) {
-        cmd_source(buffer);
-    }
+
+    if( homedir ) {
+       
+       sprintf(buffer,"%s/.yazclientrc",homedir);
+
+       if(stat(buffer,&statbuf)==0) {
+           cmd_source(buffer, 0 );
+       }
+       
+    };
     
     if(stat(".yazclientrc",&statbuf)==0) {
-        cmd_source(".yazclientrc");
+        cmd_source(".yazclientrc", 0 );
     }
 }
 
@@ -3901,9 +3949,11 @@ static struct {
     {"packagename", cmd_packagename, "<packagename>",NULL,0,NULL},
     {"proxy", cmd_proxy, "[('tcp'|'ssl')]<host>[':'<port>]",NULL,0,NULL},
     {"charset", cmd_charset, "<nego_charset> <output_charset>",NULL,0,NULL},
+    {"negcharset", cmd_negcharset, "<nego_charset>",NULL,0,NULL},
+    {"displaycharset", cmd_displaycharset, "<output_charset>",NULL,0,NULL},
     {"marccharset", cmd_marccharset, "<charset_name>",NULL,0,NULL},
     {"lang", cmd_lang, "<language_code>",NULL,0,NULL},
-    {".", cmd_source, "<filename>",NULL,1,NULL},
+    {".", cmd_source_echo, "<filename>",NULL,1,NULL},
     {"!", cmd_subshell, "Subshell command",NULL,1,NULL},
     {"set_apdufile", cmd_set_apdufile, "<filename>",NULL,1,NULL},
     {"set_berfile", cmd_set_berfile, "<filename>",NULL,1,NULL},