cygwin + GetConsoleOutputCP

Erwin Waterlander waterlan@xs4all.nl
Mon Mar 21 14:31:00 GMT 2011


On 03/21/2011 01:37 PM, Andy Koppe wrote:
> On 21 March 2011 11:17, Corinna Vinschen wrote:
>> Well, I'm not sure about that.  The complexity of codepage settings on a
>> Windows system makes the whole afair a guesswork which will always tend
>> to do the wrong thing anyway.  There are the following codepages available:
>>
>> - The current input console codepage, GetConsoleCP().
>>
>> - The current output console codepage, GetConsoleOutputCP().
>>
>> - The current OEM codepage, GetOEMCP().
>>
>> - The current ANSI codepage, GetACP().
>>
>> - The default OEM codepage of the default system locale,
>>   GetLocaleInfo (LOCALE_SYSTEM_DEFAULT, LOCALE_IDEFAULTCODEPAGE, ...).
>>
>> - The default ANSI codepage of the default system locale,
>>   GetLocaleInfo (LOCALE_SYSTEM_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE, ...).
>>
>> - The default OEM codepage of the current user or process,
>>   GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_IDEFAULTCODEPAGE, ...).
>>
>> - The default ANSI codepage of the current user or process,
>>   GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE, ...).
>>
>> - The default OEM codepage used for system invariant operations,
>>   GetLocaleInfo (LOCALE_INVARIANT, LOCALE_IDEFAULTCODEPAGE, ...).
>>
>> - The default ANSI codepage used for system invariant operations,
>>   GetLocaleInfo (LOCALE_INVARIANT, LOCALE_IDEFAULTANSICODEPAGE, ...).
>>
>> Which is the right one?
> GetACP(), which "retrieves the current Windows ANSI code page
> identifier for the operating system". That's what programs using the
> non-Unicode APIs get. It's also the default in Notepad and other
> editors.

Hi,

I was doubting between GetACP and GetConsoleOutputCP on Windows. On a 
Western regional Windows the format of a text file is most likely CP1252.
But the tool is named *dos*2unix, not *windows*2unix, therefore my 
choice was GetConsoleOutputCP.

Note that this tool is used by people who use the command-line. If you 
use 'edit' (in cmd.exe) to create a text file, it will use the console's 
DOS code page. Windows GUI users most probably don't even know what the 
Command Prompt is, so they will not use dos2unix at all.
I forgot what the standard code page was under Cygwin 1.5.
Under cygwin 1.7 this functionality is not really needed. Perhaps it's 
handy to have in special cases, if you know what you are doing.


>> In theory the option is not useful and should just go away. If you
>> have to keep it for backward compatibility, stick to the current
>> behaviour and outlaw its use, perhaps be printing a nagging warning
>> to stderr.
> ... and pointing them at iconv (which, to be fair, the -iso
> description already does).
>

That is what the dos2unix manual page does, point to iconv. The 
functionality is only there for backward compatibility and to be 
compatible with SunOS dos2unix, after which the utility was modelled. 
The original author only implemented cp437 vs iso8859-1 conversion. I 
finished his job and also added the missing ones, and I added 1252 for 
ease of use. I'm aware that on Cygwin and modern Linuxes these 
conversions make not much sense. This version of dos2unix is also used 
on DOS (16 and 32 bit), old Windows versions and even OS/2 Warp. The DOS 
and Windows versions are quite popular.

There is no intention to add other conversions. And I don't plan to 
remove the options in the near future.

Erwin


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list