|
From: | YX Hao |
Subject: | Re: [Bug-wget] Patch: Fix printing mutibyte characters as unprintable characters on Windows |
Date: | Fri, 3 Nov 2017 20:14:02 +0800 |
Hi Eli and maintainers, > From: Eli Zaretskii [mailto:address@hidden > Sent: 2017年11月3日 0:15 > > I'm not Tim, but I have a few questions about your patches. I thought just Tim is active, by my previous experiences. :) Thanks for your work and answers. > > > 1. setlocale > Can you explain why you needed this? wget already calls setlocale Of course. Here are the details: First, my compilation is: MS Windows; -cares +digest -gpgme +https +ipv6 +iri-iconv -iri-idn2 +large-file -metalink -nls +ntlm +opie -psl +ssl/openssl. I didn't have gnu-gettext, so without gnu-NLS feature. MS Windows has its own NLS support. Second, as my test, 'setlocale' is needed for the gnu printf related functions to work correctly on mutibyte characters. You can see that as attached screensots: setlocale_936.png setlocale_empty.png setlocale_omitted-OCP-0.png, the 3 results are the same Third, the order of 'log_init' is moved before all use of 'logprintf', because of that in 'main' and in downloading function won't get the correct result at the old condition, that 'log_init' is in the middle, one is before, the others are after. Without 'log_init' NOR 'setlocale', 'logprintf' can work well; with 'log_init' AND 'setlocale', 'logprintf' can work well. The modifications are going to make the printing functions work well with multibyte characters. > > Your change calls setlocale with a different value, does that even when One tricky situation: one PC is all set to United States, except the multibyte code page is 936, for example. So, '_getmbcp' is used. > ENABLE_NLS is not defined, and also runs the risk of using a wrong codepage, if > _getmbcp returns zero (as MSDN says it could). You are right. New patch is attached. I have improved my code: static void i18n_initialize (void) { +#if defined(WINDOWS) && !defined(ENABLE_NLS) + char MBCP[8] = ""; + int CP; +#endif + /* ENABLE_NLS implies existence of functions invoked here. */ #ifdef ENABLE_NLS /* Set the current locale. */ setlocale (LC_ALL, ""); /* Set the text message domain. */ bindtextdomain ("wget", LOCALEDIR); textdomain ("wget"); #endif /* ENABLE_NLS */ + +#if defined(WINDOWS) && !defined(ENABLE_NLS) + CP = _getmbcp(); /* Consider it's different from default. */ + if (CP > 0) + sprintf(MBCP, ".%d", CP); + setlocale(LC_ALL, MBCP); +#endif } At last, one more thing, I'm wondering if it could print correct on multibyte characters with GNU-NLS linked but without 'setlocale'? Best Regards, YX Hao
setlocale_empty.png
Description: PNG image
setlocale_936.png
Description: PNG image
setlocale_omitted-OCP-0.png
Description: PNG image
wget_v1.9.2_Fix printing mutibyte characters as unprintable characters o....patch
Description: Binary data
[Prev in Thread] | Current Thread | [Next in Thread] |