Enlightenment CVS committal Author : mej Project : eterm Module : Eterm
Dir : eterm/Eterm/src Modified Files: command.c screen.c screen.h Log Message: Fri Dec 17 16:35:31 2004 Michael Jennings (mej) Another attempt (and failure) at UTF-8 support. Disabled until someone can help me out. If you know iconv(), please have a look at the FIXME_BLOCK starting at line 3509 of src/command.c. ---------------------------------------------------------------------- =================================================================== RCS file: /cvsroot/enlightenment/eterm/Eterm/src/command.c,v retrieving revision 1.101 retrieving revision 1.102 diff -u -3 -r1.101 -r1.102 --- command.c 14 Dec 2004 23:24:24 -0000 1.101 +++ command.c 17 Dec 2004 21:37:37 -0000 1.102 @@ -34,7 +34,7 @@ * he guarantee anything whatsoever. *----------------------------------------------------------------------*/ -static const char cvs_ident[] = "$Id: command.c,v 1.101 2004/12/14 23:24:24 mej Exp $"; +static const char cvs_ident[] = "$Id: command.c,v 1.102 2004/12/17 21:37:37 mej Exp $"; /* includes: */ #include "config.h" @@ -111,6 +111,7 @@ # include <locale.h> # include <langinfo.h> # include <iconv.h> +# include <wchar.h> #endif /* Eterm-specific Headers */ @@ -3505,29 +3506,45 @@ } D_SCREEN(("Adding %d lines (%d chars); str == %8p, cmdbuf_ptr == %8p, cmdbuf_endp == %8p\n", nlines, cmdbuf_ptr - str, str, cmdbuf_ptr, cmdbuf_endp)); -#ifdef MULTI_CHARSET +#if FIXME_BLOCK + /* + * iconv() is not my friend. :-( I've tried various things + * to make this work (including UCS2, SJIS, EUCJ, and + * WCHAR_T), but nothing has worked. I'm obviously + * missing something, so if you know what, kindly throw me + * a clue. :-) -- mej + */ if (!strcmp(nl_langinfo(CODESET), "UTF-8")) { iconv_t handle; - handle = iconv_open("UTF-8", "UCS2"); + if (encoding_method != UCS2) { + set_multichar_encoding("utf8"); + } + handle = iconv_open("UTF-8", "WCHAR_T"); if (handle == SPIF_CAST_C(iconv_t) -1) { - print_error("Unable to decode UTF-8 locale %s to UCS-2. Defaulting to portable C locale.\n", + print_error("Unable to decode UTF-8 locale %s to WCHAR_T. Defaulting to portable C locale.\n", setlocale(LC_ALL, "")); setlocale(LC_ALL, "C"); + scr_add_lines(str, nlines, (cmdbuf_ptr - str)); } else { char *outbuff, *pinbuff, *poutbuff; + wchar_t *wcbuff; + mbstate_t mbs; size_t bufflen, outlen = 0, retval; pinbuff = (char *) str; bufflen = cmdbuf_ptr - str; - poutbuff = outbuff = SPIF_CAST_C(char *) MALLOC(bufflen * 6); + outlen = bufflen * 6; + poutbuff = outbuff = SPIF_CAST_C(char *) MALLOC(outlen); errno = 0; + D_VT(("Allocated output buffer of %lu chars at %010p against input buffer of %lu\n", bufflen * 6, outbuff, bufflen)); + print_warning("Moo: %s\n", safe_print_string(str, bufflen)); retval = iconv(handle, &pinbuff, &bufflen, &poutbuff, &outlen); if (retval != (size_t) -1) { errno = 0; } if (errno == E2BIG) { - print_error("My UTF-8 decode buffer was too small by %lu bytes?!", bufflen); + print_error("My UTF-8 decode buffer was too small by %lu bytes?!\n", bufflen); } else if (errno == EILSEQ) { print_error("Illegal multibyte sequence encountered at \'%c\' (0x%02x); skipping.\n", *pinbuff, *pinbuff); @@ -3535,12 +3552,33 @@ pinbuff++; } else if (errno == EINVAL) { D_VT(("Incomplete multibyte sequence encountered.\n")); + print_warning("Converted %lu input chars to %lu output chars before incomplete sequence.\n", (cmdbuf_ptr - str), outlen); + } else { + print_warning("Converted %lu input chars to %lu output chars.\n", (cmdbuf_ptr - str), outlen); } - if (pinbuff > (char *) str) { - cmdbuf_ptr = (unsigned char *) pinbuff; - scr_add_lines(str, nlines, (cmdbuf_ptr - str)); + print_warning("Moo2: %s\n", safe_print_string(outbuff, outlen)); + MEMSET(outbuff + outlen, 0, sizeof(wchar_t)); + wcbuff = SPIF_CAST_C(wchar_t *) outbuff; + MEMSET(&mbs, 0, sizeof(mbstate_t)); + outlen = wcsrtombs(NULL, &wcbuff, 0, &mbs) + 1; + if (outlen > 0) { + outbuff = SPIF_CAST_C(char *) MALLOC(outlen); + outlen = wcsrtombs(outbuff, &wcbuff, outlen, &mbs); + if ((long)outlen >= 0) { + FREE(wcbuff); + print_error("I win!\n"); + } else { + print_error("wcsrtombs() returned %ld (errno is %d (%s))\n", (unsigned long) outlen, errno, strerror(errno)); + } + if (pinbuff > (char *) str) { + cmdbuf_ptr = (unsigned char *) pinbuff; + scr_add_lines(outbuff, nlines, outlen); + } + } else { + print_error("wcsrtombs(NULL, %10p, 0) returned %ld (errno is %d (%s))\n", wcbuff, (unsigned long) outlen, errno, strerror(errno)); } + FREE(outbuff); } } else #endif =================================================================== RCS file: /cvsroot/enlightenment/eterm/Eterm/src/screen.c,v retrieving revision 1.78 retrieving revision 1.79 diff -u -3 -r1.78 -r1.79 --- screen.c 14 Dec 2004 23:24:30 -0000 1.78 +++ screen.c 17 Dec 2004 21:37:38 -0000 1.79 @@ -3,7 +3,7 @@ * */ -static const char cvs_ident[] = "$Id: screen.c,v 1.78 2004/12/14 23:24:30 mej Exp $"; +static const char cvs_ident[] = "$Id: screen.c,v 1.79 2004/12/17 21:37:38 mej Exp $"; #include "config.h" #include "feature.h" @@ -1450,7 +1450,10 @@ { #ifdef MULTI_CHARSET if (str && *str) { - if (!strcasecmp(str, "sjis")) { + if (!strcasecmp(str, "utf8") || !strcasecmp(str, "ucs2")) { + encoding_method = UCS2; + multichar_decode = latin1; + } else if (!strcasecmp(str, "sjis")) { encoding_method = SJIS; multichar_decode = sjis2jis; } else if (!strcasecmp(str, "eucj") || !strcasecmp(str, "euckr") || !strcasecmp(str, "gb")) { =================================================================== RCS file: /cvsroot/enlightenment/eterm/Eterm/src/screen.h,v retrieving revision 1.30 retrieving revision 1.31 diff -u -3 -r1.30 -r1.31 --- screen.h 20 Jan 2004 02:04:04 -0000 1.30 +++ screen.h 17 Dec 2004 21:37:39 -0000 1.31 @@ -165,7 +165,7 @@ SELECTION_DONE } selection_op_t; typedef enum { - LATIN1 = 0, EUCJ, EUCKR = EUCJ, GB = EUCJ, SJIS, BIG5 + LATIN1 = 0, UCS2, EUCJ, EUCKR = EUCJ, GB = EUCJ, SJIS, BIG5 } encoding_t; typedef struct { short row, col; ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/ _______________________________________________ enlightenment-cvs mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs