many simplifications, copyright statements.
authorPierre Habouzit <madcoder@debian.org>
Tue, 14 Nov 2006 23:26:24 +0000 (00:26 +0100)
committerPierre Habouzit <madcoder@debian.org>
Tue, 14 Nov 2006 23:26:24 +0000 (00:26 +0100)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
charset.c
charset.def
charset.h
copy.c
help.c
lib-mime/rfc2047.c
lib-ui/curs_lib.c
pager.c
sendlib.c

index 8cea280..9a80d31 100644 (file)
--- a/charset.c
+++ b/charset.c
@@ -1,3 +1,21 @@
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or (at
+ *  your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ *
+ *  Copyright © 2006 Pierre Habouzit
+ */
 /*
  * Copyright notice from original mutt:
  * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
@@ -37,8 +55,9 @@
 #  define EILSEQ EINVAL
 #endif
 
-char *Charset = NULL;
+char *Charset;
 int Charset_is_utf8 = 0;
+wchar_t CharsetReplacement = '?';
 
 void charset_initialize(void)
 {
@@ -47,25 +66,27 @@ void charset_initialize(void)
     char buff2[LONG_STRING];
 
     m_strcpy(buff, sizeof(buff), nl_langinfo(CODESET));
-    mutt_canonical_charset(buff2, sizeof(buff2), buff);
+    charset_canonicalize(buff2, sizeof(buff2), buff);
 
     /* finally, set $charset */
     if (!m_strisempty(buff2)) {
         m_strreplace(&Charset, buff2);
     } else
 #endif
+    {
         m_strreplace(&Charset, "iso-8859-1");
+    }
+
+    Charset_is_utf8    = !strcmp(Charset, "utf-8");
+    CharsetReplacement = Charset_is_utf8 ? 0xfffd : '?';
 
-    Charset_is_utf8 = !strcmp(Charset, "utf-8");
 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
     bind_textdomain_codeset(PACKAGE, Charset);
 #endif
 }
 
-
 #include "charset.gperf"
-
-void mutt_canonical_charset(char *dest, ssize_t dlen, const char *name)
+void charset_canonicalize(char *dest, ssize_t dlen, const char *name)
 {
     const struct cset_pair *cp;
     char scratch[LONG_STRING];
@@ -80,7 +101,7 @@ void mutt_canonical_charset(char *dest, ssize_t dlen, const char *name)
     }
     scratch[i] = '\0';
 
-    cp = mutt_canonical_charset_aux(scratch, strlen(scratch));
+    cp = charset_canonicalize_aux(scratch, strlen(scratch));
     if (cp) {
         m_strcpy(dest, dlen, cp->pref);
     } else {
@@ -96,7 +117,7 @@ static int mutt_chscmp(const char *s, const char *chs)
     if (!s)
         return 0;
 
-    mutt_canonical_charset(buffer, sizeof(buffer), s);
+    charset_canonicalize(buffer, sizeof(buffer), s);
     return !strcmp(buffer, chs);
 }
 
@@ -124,17 +145,17 @@ iconv_t mutt_iconv_open (const char *tocode, const char *fromcode, int flags)
 
   iconv_t cd;
 
-  mutt_canonical_charset (tocode1, sizeof (tocode1), tocode);
+  charset_canonicalize (tocode1, sizeof (tocode1), tocode);
 
 #ifdef M_ICONV_HOOK_TO
   /* Not used. */
   if ((flags & M_ICONV_HOOK_TO) && (tmp = mutt_charset_hook (tocode1)))
-    mutt_canonical_charset (tocode1, sizeof (tocode1), tmp);
+    charset_canonicalize (tocode1, sizeof (tocode1), tmp);
 #endif
 
-  mutt_canonical_charset (fromcode1, sizeof (fromcode1), fromcode);
+  charset_canonicalize (fromcode1, sizeof (fromcode1), fromcode);
   if ((flags & M_ICONV_HOOK_FROM) && (tmp = mutt_charset_hook (fromcode1)))
-    mutt_canonical_charset (fromcode1, sizeof (fromcode1), tmp);
+    charset_canonicalize (fromcode1, sizeof (fromcode1), tmp);
 
   if ((cd = iconv_open (tocode1, fromcode1)) != (iconv_t) - 1)
     return cd;
@@ -469,8 +490,3 @@ int mutt_convert_nonmime_string (char **ps)
   }
   return -1;
 }
-
-wchar_t replacement_char(void)
-{
-    return Charset_is_utf8 ? 0xfffd : '?';
-}
index ea534d5..60070e0 100644 (file)
@@ -1,4 +1,4 @@
-cat <<EOF | gperf -Nmutt_canonical_charset_aux -m16 -l -t -C -F", NULL"
+cat <<EOF | gperf -Ncharset_canonicalize_aux -m16 -l -t -C -F", NULL"
 %{
 /*
  *  This program is free software; you can redistribute it and/or modify
index b27a5c6..dd44047 100644 (file)
--- a/charset.h
+++ b/charset.h
@@ -1,3 +1,21 @@
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or (at
+ *  your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ *
+ *  Copyright © 2006 Pierre Habouzit
+ */
 /*
  * Copyright notice from original mutt:
  * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
 #  include "config.h"
 #endif
 
-
-#define M_ICONV_HOOK_FROM 1
-#define M_ICONV_HOOK_TO   2
+/****************************************************************************/
+/* charset functions                                                        */
+/****************************************************************************/
 
 extern char *Charset;
 extern int Charset_is_utf8;
+extern wchar_t CharsetReplacement;
 
 void charset_initialize(void);
-void mutt_canonical_charset(char *, ssize_t, const char *);
-
+void charset_canonicalize(char *, ssize_t, const char *);
 int charset_is_utf8(const char *s);
 int charset_is_us_ascii(const char *s);
 
+
+/****************************************************************************/
+/* iconv-line functions                                                     */
+/****************************************************************************/
+
 #ifdef HAVE_ICONV_H
 #  include <iconv.h>
 
@@ -42,6 +65,9 @@ my_iconv(iconv_t ict, const char **in, ssize_t *il, char **out, ssize_t *ol) {
 #  define iconv_close(a)       0
 #endif
 
+#define M_ICONV_HOOK_FROM 1
+#define M_ICONV_HOOK_TO   2
+
 int mutt_convert_string (char **, const char *, const char *, int);
 const char *mutt_get_first_charset (const char *);
 int mutt_convert_nonmime_string (char **);
@@ -50,6 +76,11 @@ iconv_t mutt_iconv_open (const char *, const char *, int);
 ssize_t mutt_iconv (iconv_t, const char **, ssize_t *, char **, ssize_t *,
                     const char **, const char *);
 
+
+/****************************************************************************/
+/* fgetconv functions                                                       */
+/****************************************************************************/
+
 typedef void *FGETCONV;
 
 FGETCONV *fgetconv_open (FILE *, const char *, const char *, int);
@@ -57,6 +88,4 @@ int fgetconv (FGETCONV *);
 char *fgetconvs (char *, ssize_t, FGETCONV *);
 void fgetconv_close (FGETCONV **);
 
-wchar_t replacement_char(void);
-
 #endif /* _CHARSET_H */
diff --git a/copy.c b/copy.c
index d658ffc..42543d3 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -346,7 +346,7 @@ mutt_copy_header (FILE * in, HEADER * h, FILE * out, int flags,
     fputs ("MIME-Version: 1.0\n", out);
     fputs ("Content-Transfer-Encoding: 8bit\n", out);
     fputs ("Content-Type: text/plain; charset=", out);
-    mutt_canonical_charset (chsbuf, sizeof (chsbuf),
+    charset_canonicalize (chsbuf, sizeof (chsbuf),
                             Charset ? Charset : "us-ascii");
     rfc822_strcpy(buffer, sizeof(buffer), chsbuf, MimeSpecials);
     fputs (buffer, out);
diff --git a/help.c b/help.c
index 67d8855..a0d85c8 100644 (file)
--- a/help.c
+++ b/help.c
@@ -98,7 +98,7 @@ static int print_macro (FILE * f, int maxwidth, const char **macro)
        *macro += k, len -= k) {
     if (k == -1 || k == -2) {
       k = (k == -1) ? 1 : len;
-      wc = replacement_char ();
+      wc = CharsetReplacement;
     }
     /* glibc-2.1.3's wcwidth() returns 1 for unprintable chars! */
     if (IsWPrint (wc) && (w = wcwidth (wc)) >= 0) {
index 4900d7c..7162b47 100644 (file)
@@ -157,7 +157,7 @@ char *mutt_choose_charset(const char *fromcode, const char *charsets,
             p_delete(&res);
         }
 
-        mutt_canonical_charset(buf, sizeof(buf), tocode);
+        charset_canonicalize(buf, sizeof(buf), tocode);
         m_strreplace(&tocode, buf);
     }
 
index 0bbe168..125e5ca 100644 (file)
@@ -594,7 +594,7 @@ void mutt_format_string (char *dest, ssize_t destlen,
   for (; n && (k = mbrtowc (&wc, s, n, &mbstate1)); s += k, n -= k) {
     if (k == -1 || k == -2) {
       k = (k == -1) ? 1 : n;
-      wc = replacement_char ();
+      wc = CharsetReplacement;
     }
     if (arboreal && wc < M_TREE_MAX)
       w = 1;                    /* hack */
@@ -689,7 +689,7 @@ void mutt_paddstr (int n, const char *s)
   for (; len && (k = mbrtowc (&wc, s, len, &mbstate)); s += k, len -= k) {
     if (k == -1 || k == -2) {
       k = (k == -1) ? 1 : len;
-      wc = replacement_char ();
+      wc = CharsetReplacement;
     }
     if (!IsWPrint (wc))
       wc = '?';
@@ -726,7 +726,7 @@ int mutt_strwidth (const char *s)
   for (w = 0; n && (k = mbrtowc (&wc, s, n, &mbstate)); s += k, n -= k) {
     if (k == -1 || k == -2) {
       k = (k == -1) ? 1 : n;
-      wc = replacement_char ();
+      wc = CharsetReplacement;
     }
     if (!IsWPrint (wc))
       wc = '?';
diff --git a/pager.c b/pager.c
index ea3ec2b..a3ee8c6 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -1093,7 +1093,7 @@ static int format_line (struct line_t **lineInfo, int n, unsigned char *buf,
         break;
       ++col;
       if (pa)
-        addch (replacement_char ());
+        addch (CharsetReplacement);
     }
   }
   *pspace = space;
index c185101..3551aaf 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -826,7 +826,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY * b)
         convert_file_from_to (fp, fchs, chs ? chs : SendCharset,
                               &fromcode, &tocode, info) != -1) {
       if (!chs) {
-        mutt_canonical_charset (chsbuf, sizeof (chsbuf), tocode);
+        charset_canonicalize (chsbuf, sizeof (chsbuf), tocode);
         mutt_set_parameter ("charset", chsbuf, &b->parameter);
       }
       b->file_charset = fromcode;
@@ -1136,7 +1136,7 @@ char *mutt_get_body_charset (char *d, ssize_t dlen, BODY * b)
     p = mutt_get_parameter ("charset", b->parameter);
 
   if (p)
-    mutt_canonical_charset (d, dlen, NONULL (p));
+    charset_canonicalize (d, dlen, NONULL (p));
   else
     m_strcpy(d, dlen, "us-ascii");