Commit a3f23a32 authored by Thomas Roessler's avatar Thomas Roessler

wide-character related patches. From Edmund Grimley Evans.

parent 507c8764
......@@ -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
......@@ -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))
......
......@@ -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
......
......@@ -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;
}
......
......@@ -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);
}
......
......@@ -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)
{
......
/*
* 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 ()
{
......
#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);
......
......@@ -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>
......
......@@ -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)
{
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment