summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--acconfig.h14
-rw-r--r--configure.in18
-rw-r--r--curs_lib.c2
-rw-r--r--gettext.c14
-rw-r--r--help.c6
-rw-r--r--iconv/iconv.c3
-rw-r--r--mbyte.c87
-rw-r--r--mbyte.h20
-rw-r--r--mutt.h3
-rw-r--r--pager.c5
-rw-r--r--wcwidth.c8
11 files changed, 100 insertions, 80 deletions
diff --git a/acconfig.h b/acconfig.h
index f038d19c..8c93576d 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -179,3 +179,17 @@
* This define will have value `sig_atomic_t' or `volatile sig_atomic_t'
* accordingly. */
#undef SIG_ATOMIC_VOLATILE_T
+
+/* Define to 'int' if system headers don't define. */
+#undef wchar_t
+
+/* Define to 'int' if system headers don't define. */
+#undef wint_t
+
+/* Define to 'int' if system headers don't define. */
+#undef mbstate_t
+
+/* Define if we are using the system's wchar_t functions. */
+#undef HAVE_WC_FUNCS
+
+
diff --git a/configure.in b/configure.in
index c6fc283c..a07ed0d9 100644
--- a/configure.in
+++ b/configure.in
@@ -708,6 +708,22 @@ if test "$mutt_cv_wchar_t" = no; then
AC_DEFINE(wchar_t, int)
fi
+AC_CACHE_CHECK([for wint_t], mutt_cv_wint_t,
+ AC_TRY_COMPILE([
+#include <stddef.h>
+#include <stdlib.h>
+#ifdef HAVE_WCHAR_H
+#include <wchar.h>
+#endif
+int main() { wint_t wc; return 0; }
+ ],
+ mutt_cv_wint_t=yes,
+ mutt_cv_wint_t=no))
+
+if test "$mutt_cv_wint_t" = no; then
+ AC_DEFINE(wint_t, int)
+fi
+
AC_CACHE_CHECK([for mbstate_t], mutt_cv_mbstate_t,
AC_TRY_COMPILE([
#include <stddef.h>
@@ -715,7 +731,7 @@ AC_CACHE_CHECK([for mbstate_t], mutt_cv_mbstate_t,
#ifdef HAVE_WCHAR_H
#include <wchar.h>
#endif
-int main() { mbstate_t wc; return 0; }
+int main() { mbstate_t s; return 0; }
],
mutt_cv_mbstate_t=yes,
mutt_cv_mbstate_t=no))
diff --git a/curs_lib.c b/curs_lib.c
index 104b929f..de0f72e9 100644
--- a/curs_lib.c
+++ b/curs_lib.c
@@ -470,7 +470,7 @@ int mutt_addwch (wchar_t wc)
char buf[6]; /* FIXME */
int n;
- n = mutt_wctomb (buf, wc);
+ n = wctomb (buf, wc);
if (n == -1)
return n;
else
diff --git a/gettext.c b/gettext.c
index 338e7c5d..19ae7d13 100644
--- a/gettext.c
+++ b/gettext.c
@@ -61,26 +61,18 @@ char *mutt_gettext (const char *message)
if (t != po_charset &&
(!t || !po_charset || strcmp (t, po_charset)))
{
- free (po_charset);
+ safe_free ((void **) &po_charset);
po_charset = t;
change_cd = 1;
}
else
- free (t);
+ safe_free ((void **) &t);
}
if (message_charset != Charset &&
(!message_charset || !Charset || strcmp (message_charset, Charset)))
{
- free (message_charset);
- if (Charset)
- {
- int n = strlen (Charset);
- message_charset = safe_malloc (n+1);
- memcpy (message_charset, Charset, n+1);
- }
- else
- message_charset = 0;
+ mutt_str_replace (&message_charset, Charset);
outrepl = mutt_is_utf8 (message_charset) ? "\357\277\275" : "?";
change_cd = 1;
}
diff --git a/help.c b/help.c
index 52ee3cb3..9c5a8eb8 100644
--- a/help.c
+++ b/help.c
@@ -92,16 +92,16 @@ static int print_macro (FILE *f, int maxwidth, const char **macro)
for (;;)
{
- if ((k = mutt_mbtowc (&wc, *macro, -1)) <= 0)
+ if ((k = mbtowc (&wc, *macro, -1)) <= 0)
break;
- if ((w = mutt_wcwidth (wc)) >= 0)
+ if ((w = wcwidth (wc)) >= 0)
{
if (w > n)
break;
n -= w;
{
char tb[7];
- int m = mutt_wctomb (tb, wc);
+ int m = wctomb (tb, wc);
if (0 < m && m < 7)
tb[m] = '\0', fprintf (f, "%s", tb);
}
diff --git a/iconv/iconv.c b/iconv/iconv.c
index af391c3d..c80db52d 100644
--- a/iconv/iconv.c
+++ b/iconv/iconv.c
@@ -843,12 +843,13 @@ size_t iconv (iconv_t _cd, const char **inbuf, size_t *inbytesleft,
}
else if (cd && !cd->chs_from && cd->chs_to && !unicode_init ())
{
- mbstate_t mbstate = 0;
+ mbstate_t mbstate;
unsigned int wc;
int k;
char c;
CHARDESC *d;
+ memset(&mbstate, 0, sizeof(mbstate));
n = 0;
while (ibl && obl)
{
diff --git a/mbyte.c b/mbyte.c
index 4ce59a94..272c1045 100644
--- a/mbyte.c
+++ b/mbyte.c
@@ -1,16 +1,10 @@
-/*
- * This file provides functions that are just like the C library ones,
- * except that they behave according to mutt's Charset instead of
- * according to the locale.
- */
-
-#include <errno.h>
-
#include "mutt.h"
#include "mbyte.h"
#include "charset.h"
+#include <errno.h>
+
#ifndef EILSEQ
#define EILSEQ EINVAL
#endif
@@ -22,10 +16,12 @@ void mutt_set_charset (char *charset)
Charset_is_utf8 = mutt_is_utf8 (charset);
}
+#ifndef HAVE_WC_FUNCS
+
int wctomb (char *s, wchar_t wc)
{
if (Charset_is_utf8)
- return mutt_wctoutf8(s, wc);
+ return mutt_wctoutf8 (s, wc);
else if (wc < 0x100)
{
if (s)
@@ -38,17 +34,53 @@ int wctomb (char *s, wchar_t wc)
int mbtowc (wchar_t *pwc, const char *s, size_t n)
{
- mbstate_t state = 0;
- int result = mbrtowc (pwc, s, n, &state);
+ mbstate_t state;
+ int result;
+ memset(&state, 0, sizeof(state));
+ result = mbrtowc (pwc, s, n, &state);
if (result >= 0)
return result;
else
return -1;
}
-size_t utf8rtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
+size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
+{
+ static mbstate_t mbstate;
+
+ if (!ps)
+ ps = &mbstate;
+
+ if (Charset_is_utf8)
+ return utf8rtowc (pwc, s, n, ps);
+ else
+ {
+ if (!s)
+ {
+ memset(ps, 0, sizeof(*ps));
+ return 0;
+ }
+ if (!n)
+ return (size_t)-2;
+ if (pwc)
+ *pwc = (wchar_t)(unsigned char)*s;
+ return (*s != 0);
+ }
+}
+
+int iswprint (wint_t wc)
{
- static mbstate_t mbstate = 0;
+ return ((0x20 <= wc && wc < 0x7f) || 0xa0 <= wc);
+}
+
+#endif /* HAVE_MBYTE */
+
+#if !defined(HAVE_MBYTE) || !defined(HAVE_ICONV)
+
+size_t utf8rtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *_ps)
+{
+ static wchar_t mbstate;
+ wchar_t *ps = (wchar_t *)_ps;
size_t k = 1;
unsigned char c;
wchar_t wc;
@@ -132,34 +164,7 @@ size_t utf8rtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
return (size_t)-2;
}
-size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
-{
- static mbstate_t mbstate = 0;
-
- if (!ps)
- ps = &mbstate;
-
- if (Charset_is_utf8)
- return utf8rtowc (pwc, s, n, ps);
- else
- {
- if (!s)
- {
- *ps = 0;
- return 0;
- }
- if (!n)
- return (size_t)-2;
- if (pwc)
- *pwc = (wchar_t)(unsigned char)*s;
- return (*s != 0);
- }
-}
-
-int iswprint (wchar_t wc)
-{
- return ((0x20 <= wc && wc < 0x7f) || 0xa0 <= wc);
-}
+#endif /* !defined(HAVE_MBYTE) || !defined(HAVE_ICONV) */
wchar_t replacement_char ()
{
diff --git a/mbyte.h b/mbyte.h
index 3f45d0ec..d3b24652 100644
--- a/mbyte.h
+++ b/mbyte.h
@@ -1,28 +1,14 @@
#ifndef _MBYTE_H
#define _MBYTE_H
-/* This is necessary because we may be redefining wchar_t, etc */
-#include <stdlib.h>
-
-#define wchar_t mutt_wchar_t
-#define mbstate_t mutt_mbstate_t
-
-typedef unsigned int wchar_t;
-typedef unsigned int mbstate_t;
-
-#define wctomb mutt_wctomb
-#define mbtowc mutt_mbtowc
-#define mbrtowc mutt_mbrtowc
-#define iswprint mutt_iswprint
-#define wcwidth mutt_wcwidth
-
void mutt_set_charset (char *charset);
+size_t utf8rtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *_ps);
+
int wctomb (char *s, wchar_t wc);
int mbtowc (wchar_t *pwc, const char *s, size_t n);
-size_t utf8rtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
-int iswprint (wchar_t wc);
+int iswprint (wint_t wc);
int wcwidth (wchar_t wc);
wchar_t replacement_char (void);
diff --git a/mutt.h b/mutt.h
index 09a42f41..f8656118 100644
--- a/mutt.h
+++ b/mutt.h
@@ -28,6 +28,9 @@
#include <limits.h>
#include <stdarg.h>
#include <signal.h>
+#ifdef HAVE_WCHAR_H
+#include <wchar.h>
+#endif
#ifndef _POSIX_PATH_MAX
#include <posix1_lim.h>
diff --git a/pager.c b/pager.c
index 219546ac..f7d956d9 100644
--- a/pager.c
+++ b/pager.c
@@ -978,7 +978,10 @@ static int format_line (struct line_t **lineInfo, int n, unsigned char *buf,
int col = option (OPTMARKERS) ? (*lineInfo)[n].continuation : 0;
int ch, vch, k, special = 0, t;
wchar_t wc;
- mbstate_t mbstate = 0; /* FIXME: this should come from lineInfo */
+ mbstate_t mbstate;
+
+ /* FIXME: this should come from lineInfo */
+ memset(&mbstate, 0, sizeof(mbstate));
for (ch = 0, vch = 0; ch < cnt; ch += k, vch += k)
{
diff --git a/wcwidth.c b/wcwidth.c
index 15817e8a..217de459 100644
--- a/wcwidth.c
+++ b/wcwidth.c
@@ -6,11 +6,10 @@
* Markus Kuhn -- 2000-02-08 -- public domain
*/
-#if 0 /* original */
-#include <wchar.h>
-#else /* Mutt */
+#include "mutt.h"
#include "mbyte.h"
-#endif
+
+#ifndef HAVE_WC_FUNCS
/* These functions define the column width of an ISO 10646 character
* as follows:
@@ -117,6 +116,7 @@ int wcwidth(wchar_t ucs)
(ucs >= 0xffe0 && ucs <= 0xffe6));
}
+#endif /* HAVE_WCWIDTH */
#if 0 /* original */
int wcswidth(const wchar_t *pwcs, size_t n)