--- ./mdxfile.c.org Mon Mar 20 23:22:09 2006 +++ ./mdxfile.c Tue May 16 13:38:50 2006 @@ -417,22 +417,39 @@ char* rr = NULL; size_t remain=0, oremain=0; char* cur = NULL; - const char* loc = (const char *)"UTF-8"; + const char* loc = (const char *)"SHIFT-JIS"; unsigned char src[3]; unsigned char dst[7]; int ptr = 0; size_t sl=0; size_t dl=0; - cur = setlocale(LC_CTYPE, ""); - if (strstr(cur, "eucJP")) { - loc = (const char *)"EUC-JP"; + cur = getenv("LANG"); + if(cur != NULL){ + if (strcasestr(cur, "SJIS")) { + goto error_end; + } else if (strcasestr(cur, "EUC")) { + loc = (const char *)"EUCJP-MS"; + //loc = (const char *)"EUC-JP"; + } else if (strcasestr(cur, "UTF-8")) { + loc = (const char *)"UTF-8"; + } else { + goto error_end; + } + } else { + goto error_end; } - fd = iconv_open(loc, "SHIFT-JIS"); + fd = iconv_open(loc, "CP932"); + if (fd<0) { + if (strcasestr(cur, "EUC")) { + loc = (const char *)"EUC-JP"; + } + fd = iconv_open(loc, "CP932"); if (fd<0) { goto error_end; } + } /* enough for store utf8 */ remain = strlen(str); @@ -447,6 +464,9 @@ memset((void *)result, 0, oremain); rr = result; + string_cleaning(str); + +#if 1 ptr=0; /* to omit X68k specific chars, process charconv one by one */ do { @@ -460,7 +480,7 @@ c = src[0] = (unsigned char)str[ptr++]; sl=1; if (!c) break; - if (c==0x80 || (c>=0x81 && c<=0x84) || (c>=0x88 && c<=0x9f) || + if (c==0x80 || (c>=0x81 && c<=0x84) || (c>=0x87 && c<=0x9f) || (c>=0xe0 && c<=0xea) || (c>=0xf0 && c<=0xf3) || c==0xf6) { src[1] = (unsigned char)str[ptr++]; if (!src[1]) { @@ -481,6 +501,12 @@ strcat(result, (char *)dst); } } while (1); +#else + len = iconv(fd, &str, &remain, &rr, &oremain); + if (len==(size_t)(-1)) { + goto error_end; + } +#endif iconv_close(fd); return result; @@ -513,7 +539,7 @@ message = strdup(mdx->data_title); #endif if ( message != NULL ) { - fprintf(stderr,_("Title:\t%s\n"),message); + fprintf(stderr,_("[ %s ]\n"),message); free(message); } @@ -527,4 +553,28 @@ error_end(_("Invalid mdx file.")); #else /* HAVE_SYMBIAN_SUPPORT */ #endif +} + +int string_cleaning(const char *str){ + int i, len = strlen(str); + + const int num_tbl = 2; + const char tbl[][3] = { + { 0xEC, 0x7A, 0x00 }, { 0x87, 0x54, 0x00 }, // ‡T + { 0xEC, 0x7B, 0x00 }, { 0x87, 0x55, 0x00 }, // ‡U + { 0xEC, 0x7C, 0x00 }, { 0x87, 0x56, 0x00 }, // ‡V + { 0xEC, 0x7D, 0x00 }, { 0x87, 0x57, 0x00 }, // ‡W + { 0xEC, 0x7E, 0x00 }, { 0x87, 0x58, 0x00 }, // ‡X + { 0xEC, 0x7F, 0x00 }, { 0x87, 0x59, 0x00 }, // ‡Y + { 0xEC, 0x80, 0x00 }, { 0x87, 0x5A, 0x00 }, // ‡Z + { 0xEC, 0x81, 0x00 }, { 0x87, 0x5B, 0x00 }, // ‡[ + { 0xEC, 0x82, 0x00 }, { 0x87, 0x5C, 0x00 }, // ‡\ + { 0xEC, 0x83, 0x00 }, { 0x87, 0x5D, 0x00 }, // ‡] + }; + + for (i=0; i