[w3m-dev 04036] NLS message charset selection
WATANABE Katsuyuki <[email protected]>
| Newsgroups | gmane.comp.web.w3m.devel |
|---|---|
| Message-ID | <[email protected]> |
渡邉です。 NLS message の charset の選択をちょっと改善するパッチです。 SystemCharset が Shift_JIS な環境で、OUTPUT_CHARSET を設定している 場合などに効果があるはずです。 # iconv の info を眺めてみましたが、gettext() で文字列を取ってくる # ときに charset を変換させない方法がよくわかりませんでした。 NLS message の charset として、グローバル変数 MessageCharset を 追加しています。 あとは w3mhelperpanel, w3mbookmark を NLS 化しないといけませんね。 #if defined( __CYGWIN__) && LANG == JA な条件もなんとかしたいところ ですが、うまくいかなかったという意見しか見当たらないので、まだ調査 中です... -- WATANABE Katsuyuki / 渡邉勝之 [email protected]
w3m-cvs-1.890-nls-4.diff
(text/plain, 4.1 KB)
diff -urN -X ../ignore.list w3m-1.890/fm.h w3m-1.890-nls/fm.h
--- w3m-1.890/fm.h 2003-10-16 12:29:24.000000000 +0900
+++ w3m-1.890-nls/fm.h 2003-12-04 00:40:11.000000000 +0900
@@ -458,6 +458,8 @@
#ifdef USE_M17N
wc_ces document_charset;
wc_uint8 auto_detect;
+#else
+ char document_charset;
#endif
TextList *document_header;
FormItemList *form_submit;
@@ -1018,6 +1020,7 @@
global wc_ces DisplayCharset init(DISPLAY_CHARSET);
global wc_ces DocumentCharset init(DOCUMENT_CHARSET);
global wc_ces SystemCharset init(SYSTEM_CHARSET);
+global wc_ces MessageCharset init(SYSTEM_CHARSET);
global char ExtHalfdump init(FALSE);
global char FollowLocale init(TRUE);
global char UseContentCharset init(TRUE);
diff -urN -X ../ignore.list w3m-1.890/main.c w3m-1.890-nls/main.c
--- w3m-1.890/main.c 2003-10-10 12:49:13.000000000 +0900
+++ w3m-1.890-nls/main.c 2003-12-04 00:41:34.000000000 +0900
@@ -11,6 +11,9 @@
#include <sys/wait.h>
#endif
#include <time.h>
+#ifdef ENABLE_NLS
+#include <libintl.h>
+#endif
#include "terms.h"
#include "myctype.h"
#include "regex.h"
@@ -108,13 +111,17 @@
fversion(FILE * f)
{
fprintf(f, "w3m version %s, options %s\n", w3m_version,
+#ifdef USE_M17N
+ "m17n"
+#ifdef ENABLE_NLS
+ ",nls"
+#endif
+#else
#if LANG == JA
"lang=ja"
#else
"lang=en"
#endif
-#ifdef USE_M17N
- ",m17n"
#endif
#ifdef USE_IMAGE
",image"
@@ -358,6 +365,37 @@
return hs;
}
+#ifdef ENABLE_NLS
+void
+guess_nlsmsg_charset(const char *domainname)
+{
+ char *p;
+ wc_ces message_charset = 0;
+
+ {
+ p = gettext("");
+ if ((p = strcasestr(p, "charset")) != NULL) {
+ p += 7;
+ SKIP_BLANKS(p);
+ if (*p == '=') {
+ p++;
+ SKIP_BLANKS(p);
+ if (*p == '"')
+ p++;
+ }
+ message_charset = wc_guess_charset(p, 0);
+ }
+ }
+ if ((p = bind_textdomain_codeset(domainname, NULL)) != NULL) {
+ message_charset = wc_guess_charset(p, message_charset);
+ }
+ if ((p = getenv("OUTPUT_CHARSET")) != NULL) {
+ message_charset = wc_guess_charset(p, message_charset);
+ }
+ MessageCharset = message_charset;
+}
+#endif
+
int
main(int argc, char **argv, char **envp)
{
@@ -383,9 +421,12 @@
wc_ces CodePage;
#endif
#endif
+#ifdef ENABLE_NLS
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
+ guess_nlsmsg_charset(PACKAGE);
+#endif
#ifndef HAVE_SYS_ERRLIST
prepare_sys_errlist();
diff -urN -X ../ignore.list w3m-1.890/menu.c w3m-1.890-nls/menu.c
--- w3m-1.890/menu.c 2003-10-10 12:49:14.000000000 +0900
+++ w3m-1.890-nls/menu.c 2003-12-04 00:40:11.000000000 +0900
@@ -257,8 +257,7 @@
static Menu MainMenu;
#ifdef USE_M17N
-/* FIXME: gettextize here */
-static wc_ces MainMenuCharset = WC_CES_US_ASCII; /* FIXME: charset of source code */
+static wc_ces MainMenuCharset = WC_CES_US_ASCII;
static int MainMenuEncode = FALSE;
#endif
@@ -1725,8 +1724,7 @@
if (!MainMenuEncode) {
MenuItem *item;
#if ENABLE_NLS
- /* FIXME: charset that gettext(3) returns */
- MainMenuCharset = SystemCharset;
+ MainMenuCharset = MessageCharset;
#endif
for (item = MainMenuItem; item->type != MENU_END; item++)
item->label =
diff -urN -X ../ignore.list w3m-1.890/rc.c w3m-1.890-nls/rc.c
--- w3m-1.890/rc.c 2003-10-10 12:49:14.000000000 +0900
+++ w3m-1.890-nls/rc.c 2003-12-04 00:40:11.000000000 +0900
@@ -53,7 +53,7 @@
/* FIXME: gettextize here */
#ifdef USE_M17N
-static wc_ces OptionCharset = WC_CES_US_ASCII; /* FIXME: charset of source code */
+static wc_ces OptionCharset = WC_CES_US_ASCII;
static int OptionEncode = FALSE;
#endif
@@ -837,9 +837,8 @@
char *cmt;
#if ENABLE_NLS
- OptionCharset = SystemCharset; /* FIXME */
+ OptionCharset = MessageCharset;
#endif
-
fputs("\nconfiguration parameters\n", fp);
for (j = 0; sections[j].name != NULL; j++) {
#ifdef USE_M17N
@@ -1362,7 +1361,7 @@
optionpanel_str = Sprintf(optionpanel_src1, w3m_version,
html_quote(localCookie()->ptr), CMT_HELPER);
#if ENABLE_NLS
- OptionCharset = SystemCharset; /* FIXME */
+ OptionCharset = MessageCharset;
#endif
#ifdef USE_M17N
if (!OptionEncode) {