gcc: How to print to stdout text in Russian (win1251 encoding)?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

gcc: How to print to stdout text in Russian (win1251 encoding)?

Alexey Lyubimov
Hello!
I found out, that it was impossible to print to stdout text in Russian language
(encoding 1251) from console application under Win98SE:
  printf("some_text_string_in_russian");
prints characters on the screen in wrong encoding (may be in CP866 or KOI-8R).

Can anybody suggest a workaround? Any hints (tips or tricks)?

--
Thank you.
Alexey Lyubimov


------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.
Reply | Threaded
Open this post in threaded view
|

Re: How to print to stdout text in Russian (win1251encoding)?

Роман Донченко

"Alexey Lyubimov" <[hidden email]>
сообщил/сообщила в новостях следующее:
news:[hidden email]...
> Hello!
> I found out, that it was impossible to print to stdout text in Russian
> language
> (encoding 1251) from console application under Win98SE:
>  printf("some_text_string_in_russian");
> prints characters on the screen in wrong encoding (may be in CP866 or
> KOI-8R).
>
> Can anybody suggest a workaround? Any hints (tips or tricks)?

Either change the encoding the console uses, or the encoding your
application uses. The former can be done from outside ("chcp 1251"; I'm not
sure if Win98 supports it, maybe you'll have to use "mode con cp
select=1251") or from inside your program (via SetConsoleOutputCP). If you
use the second approach, you'll need to restore it back before the program
exits, or it'll persist; so I don't like it much.

The way the latter can be done depends on your needs. Maybe a suitable
solution will be to just convert your strings to the current output code
page (don't hardcode it) before outputting.

Roman.

--
Manually typed signature.



------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.
Reply | Threaded
Open this post in threaded view
|

Re: How to print to stdout text in Russian (win1251encoding)?

Roumen Petrov
Роман Донченко wrote:

> "Alexey Lyubimov" <[hidden email]>
> сообщил/сообщила в новостях следующее:
> news:[hidden email]...
>> Hello!
>> I found out, that it was impossible to print to stdout text in Russian
>> language
>> (encoding 1251) from console application under Win98SE:
>>  printf("some_text_string_in_russian");
>> prints characters on the screen in wrong encoding (may be in CP866 or
>> KOI-8R).
>>
>> Can anybody suggest a workaround? Any hints (tips or tricks)?
>
> Either change the encoding the console uses, or the encoding your
> application uses. The former can be done from outside ("chcp 1251"; I'm not
> sure if Win98 supports it, maybe you'll have to use "mode con cp
> select=1251") or from inside your program (via SetConsoleOutputCP). If you
> use the second approach, you'll need to restore it back before the program
> exits, or it'll persist; so I don't like it much.
>
> The way the latter can be done depends on your needs. Maybe a suitable
> solution will be to just convert your strings to the current output code
> page (don't hardcode it) before outputting.
>
> Roman.

May be IBM866 (on console) is for versions after Win98SE - ME,W2k.
Win98SE may use IBM855. If I remember well Microsoft CP1251 is supported
on console first in NT5.1(XP).

What about to use libiconv to convert to code page on host OS ?
It has to support conversion between CP1251 and IBM855/866 in both
directions.

Roumen



------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.
Reply | Threaded
Open this post in threaded view
|

Re: How to print to stdout text in Russian (win1251encoding)?

Alexey Lyubimov
In reply to this post by Роман Донченко
Роман Донченко <DXDragon@...> writes:


> Either change the encoding the console uses, or the encoding your
> application uses. The former can be done from outside ("chcp 1251"; I'm not
> sure if Win98 supports it, maybe you'll have to use "mode con cp
> select=1251") or from inside your program (via SetConsoleOutputCP). If you
> use the second approach, you'll need to restore it back before the program
> exits, or it'll persist; so I don't like it much.
>
> The way the latter can be done depends on your needs. Maybe a suitable
> solution will be to just convert your strings to the current output code
> page (don't hardcode it) before outputting.
>
> Roman.
>

Nothing from your tips worked fo me :-(
SetConsoleOutputCP() - does not work in Win98SE (returns ERROR);
chcp - needs an argument with template "yyy" (3 digits);
mode con cp select= - also needs an argument with template "yyy" (3 digits);
Anyway, thanks for your support.



------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.
Reply | Threaded
Open this post in threaded view
|

Re: How to print to stdout text in Russian (win1251encoding)?

Alexey Lyubimov
In reply to this post by Roumen Petrov
Roumen Petrov <bugtrack@...> writes:


> What about to use libiconv to convert to code page on host OS ?
> It has to support conversion between CP1251 and IBM855/866 in both
> directions.
>
> Roumen

Can you send me a simple example of practical usage of libiconv with C-program,
please?

--
Thank you





------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.
Reply | Threaded
Open this post in threaded view
|

Re: How to print to stdout text in Russian (win1251encoding)?

Роман Донченко
In reply to this post by Alexey Lyubimov
> Nothing from your tips worked fo me :-(
> SetConsoleOutputCP() - does not work in Win98SE (returns ERROR);
> chcp - needs an argument with template "yyy" (3 digits);
> mode con cp select= - also needs an argument with template "yyy" (3
> digits);

Ouch. I used to have a higher opinion of Win9x. 8=]

If you want to use charset conversion, an alternative to iconv is to use
MultiByteToWideChar to convert from CP_ACP and then WideCharToMultiByte to
convert to GetConsoleOutputCP().

Another approach is to actually use strings in OEM encoding so no conversion
is required. SetFileApisToOEM will certainly be helpful. However, this
should be used with discretion since if you need to interface with programs
that expect ANSI encoding it will get messy.

Roman.

--
Manually typed signature.



------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.
Reply | Threaded
Open this post in threaded view
|

Re: How to print to stdout text in Russian (win1251encoding)?

Roumen Petrov
In reply to this post by Alexey Lyubimov
Alexey,
I'm sorry for late reply.

Alexey Lyubimov wrote:

> Roumen Petrov <bugtrack@...> writes:
>> What about to use libiconv to convert to code page on host OS ?
>> It has to support conversion between CP1251 and IBM855/866 in both
>> directions.
>>
>> Roumen
>
> Can you send me a simple example of practical usage of libiconv with C-program,
> please?
>
> --
> Thank you

I try to find some samples or test cases on my disks but without
success. The iconv is with only three functions. You may look into
libiconv sources - tests subdirectory. Libxml is another project that
use libiconv.
And the Роман suggestion is worth to test.

Румен

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) HTML/MIME encoded mail
3) Improper quoting
4) Improper trimming