<<< Date Index >>>     <<< Thread Index >>>

[patch] config_charset variable (wishlist #1642)



  Attached is a patch for the wishlist bug #1642. It adds a variable
config_charset that one may define in a rc file that contains non ascii
characters (aliases files for instance). Where a rc file is sourced, the
commands are converted from this encoding, so that it works well if you
are used to working in UTF8 xterms but sometimes have to use a
latin-encoded terminal.

-- 
Joël Riou

diff -u mutt/globals.h mutt.new/globals.h
--- mutt/globals.h      2004-01-17 20:12:25.000000000 +0100
+++ mutt.new/globals.h  2004-01-17 20:13:17.000000000 +0100
@@ -37,6 +37,7 @@
 WHERE char *AttachFormat;
 WHERE char *Charset;
 WHERE char *ComposeFormat;
+WHERE char *ConfigCharset;
 WHERE char *ContentType;
 WHERE char *DefaultHook;
 WHERE char *DateFmt;
diff -u mutt/init.c mutt.new/init.c
--- mutt/init.c 2004-01-17 20:12:20.000000000 +0100
+++ mutt.new/init.c     2004-01-17 20:25:35.000000000 +0100
@@ -1249,9 +1249,10 @@
 static int source_rc (const char *rcfile, BUFFER *err)
 {
   FILE *f;
-  int line = 0, rc = 0;
+  int line = 0, rc = 0, conv = 0;
   BUFFER token;
   char *linebuf = NULL;
+  char *currentline = NULL;
   size_t buflen;
   pid_t pid;
 
@@ -1264,15 +1265,26 @@
   memset (&token, 0, sizeof (token));
   while ((linebuf = mutt_read_line (linebuf, &buflen, f, &line)) != NULL)
   {
-    if (mutt_parse_rc_line (linebuf, &token, err) == -1)
+    conv=ConfigCharset && (*ConfigCharset) && Charset;
+    if (conv) {
+      currentline=safe_strdup(linebuf);
+      if (!currentline) continue;
+      mutt_convert_string(&currentline, ConfigCharset, Charset, 0);
+    } else currentline=linebuf;
+    if (mutt_parse_rc_line (currentline, &token, err) == -1)
     {
       mutt_error (_("Error in %s, line %d: %s"), rcfile, line, err->data);
-      if (--rc < -MAXERRS)
+      if (--rc < -MAXERRS) {
+        if (conv) FREE(&currentline);
         break;
+      }
     }
     else
+    {
       if (rc < 0)
         rc = -1;
+    }
+    if (conv) FREE(&currentline);
   }
   FREE (&token.data);
   FREE (&linebuf);
diff -u mutt/init.h mutt.new/init.h
--- mutt/init.h 2004-01-17 20:12:54.000000000 +0100
+++ mutt.new/init.h     2004-01-17 20:13:15.000000000 +0100
@@ -329,6 +329,12 @@
   ** See the text describing the ``$$status_format'' option for more 
   ** information on how to set ``$$compose_format''.
   */
+  { "config_charset",  DT_STR,  R_NONE, UL &ConfigCharset, UL 0 },
+  /*
+  ** .pp
+  ** When defined, Mutt will recode commands in rc files from this
+  ** encoding.
+  */
   { "confirmappend",   DT_BOOL, R_NONE, OPTCONFIRMAPPEND, 1 },
   /*
   ** .pp