]> granicus.if.org Git - neomutt/commitdiff
refactor: separate get from set Charset 1120/head
authorRichard Russon <rich@flatcap.org>
Sat, 31 Mar 2018 18:07:28 +0000 (19:07 +0100)
committerRichard Russon <rich@flatcap.org>
Tue, 3 Apr 2018 02:38:53 +0000 (03:38 +0100)
init.c
mutt/charset.c
mutt/charset.h

diff --git a/init.c b/init.c
index fac1ac7b0568abd2a46332377f0df24aa8e1451c..af04193ce7660bab329811fea0fd210b8bad5786 100644 (file)
--- a/init.c
+++ b/init.c
@@ -3780,7 +3780,7 @@ int mutt_init(int skip_sys_rc, struct ListHead *commands)
   if (p)
     From = mutt_addr_parse_list(NULL, p);
 
-  mutt_ch_set_langinfo_charset();
+  Charset = mutt_ch_get_langinfo_charset();
   mutt_ch_set_charset(Charset);
 
   Matches = mutt_mem_calloc(MatchesListsize, sizeof(char *));
index 730834e217a86be977f0833aa4644a13de27e057..657827cf732099e0dfb88c47d62d61f38334ee13 100644 (file)
@@ -409,22 +409,22 @@ char *mutt_ch_get_default_charset(void)
 }
 
 /**
- * mutt_ch_set_langinfo_charset - Set the user's choice of character set
+ * mutt_ch_get_langinfo_charset - Get the user's choice of character set
+ * @retval ptr Charset string
  *
- * Lookup the character map used by the user's locale and store it in Charset.
+ * Get the canonical character set used by the user's locale.
+ * The caller must free the returned string.
  */
-void mutt_ch_set_langinfo_charset(void)
+char *mutt_ch_get_langinfo_charset(void)
 {
-  char buf[LONG_STRING];
-  char buf2[LONG_STRING];
+  char buf[LONG_STRING] = "";
 
-  mutt_str_strfcpy(buf, nl_langinfo(CODESET), sizeof(buf));
-  mutt_ch_canonical_charset(buf2, sizeof(buf2), buf);
+  mutt_ch_canonical_charset(buf, sizeof(buf), nl_langinfo(CODESET));
 
-  /* finally, set $charset */
-  Charset = mutt_str_strdup(buf2);
-  if (!Charset)
-    Charset = mutt_str_strdup("iso-8859-1");
+  if (buf[0] != '\0')
+    return mutt_str_strdup(buf);
+
+  return mutt_str_strdup("iso-8859-1");
 }
 
 /**
index 13c44a8c66fb52826558c876b4acd93ed6cdb5c7..1c585d19e424c7871f265e27e1c035c62125a0ce 100644 (file)
@@ -85,7 +85,7 @@ extern const struct MimeNames PreferredMIMENames[];
 void             mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name);
 int              mutt_ch_chscmp(const char *cs1, const char *cs2);
 char *           mutt_ch_get_default_charset(void);
-void             mutt_ch_set_langinfo_charset(void);
+char *           mutt_ch_get_langinfo_charset(void);
 void             mutt_ch_set_charset(char *charset);
 
 bool             mutt_ch_lookup_add(enum LookupType type, const char *pat, const char *replace, struct Buffer *err);