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

multibyte handling patch



The latest daily build of mutt fails to link on old systems where
HAVE_WC_FUNCS is not defined due to missing functions fgetwc, ungetwc and
fputws.  Attached is a half-baked patch to address this. It's barely tested
(it compiles fine!) and only attempts multibyte conversion on the output
side (the get side just uses the non-multibyte functions), but at least
it's here before the Monday deadline!

>>> Dan
-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
--- mbyte.h.orig        Sat Jan  3 21:23:47 2009
+++ mbyte.h     Sun Jan  4 00:40:04 2009
@@ -37,6 +37,12 @@
 wint_t towupper (wint_t wc);
 wint_t towlower (wint_t wc);
 int wcwidth (wchar_t wc);
+
+#define fgetwc(f) ((wint_t)(fgetc(f)))
+#define ungetwc(c,f) ((wint_t)(ungetc((int)(c),f)))
+
+wint_t fputwc(wchar_t wc, FILE *stream);
+int fputws(const wchar_t *ws, FILE *stream);
 # endif /* !HAVE_WC_FUNCS */
 
 
--- mbyte.c.orig        Sat Nov 22 00:00:04 2008
+++ mbyte.c     Sun Jan  4 00:43:09 2009
@@ -516,6 +516,28 @@
   return (size_t)-2;
 }
 
+wint_t fputwc(wchar_t wc, FILE *stream)
+{
+       char buf[MB_LEN_MAX];
+       size_t l = wcrtomb(buf, wc, NULL);
+       if (fprintf(stream, "%.*s", (int)l, buf) < 0)
+               return -1;
+       return wc;
+}
+
+int fputws(const wchar_t *ws, FILE *stream)
+{
+       int c = 0;
+       while (*ws) {
+               wint_t rc = fputwc(*ws,stream);
+               if (rc < 0)
+                       return rc;
+               ++ws;
+               ++c;
+       }
+       return c;
+}
+
 #endif /* !HAVE_WC_FUNCS */
 
 wchar_t replacement_char (void)

Attachment: pgpZLltn5Z3cS.pgp
Description: PGP signature