Solved

Cross-platform code page identifier.

Posted on 2003-11-12
5
421 Views
Last Modified: 2010-04-15
I need a way to record the default (encoding) codepage for text and store this off in a file.  This must work on windows, Mac OS X and Linux/Solaris.

Ideally they would be comparable to each other, but, if the identifier is only comparable to other "codepages" on the same system, that is, Windows to Windows, Mac to Mac, etc, then that will be okay too.

In other words, I just need to know how on each platform to get the current default codepage for text input.  Ideally, I would like to store this in a platform agnostic way.

I don't necessarily need code snippets, just pointers to web resources, that basically outline how to do this for each platform...

Anyway, I hope someone can help.
0
Comment
Question by:frogger1999
5 Comments
 
LVL 17

Accepted Solution

by:
rstaveley earned 250 total points
ID: 9740091
In a Win32 console, you can use the command "chcp" to get the codepage. I'm really up to speed on i18n (I hope a more knowledgeable expert chips in), but I don't think life is so easy on other platforms.

You are probably best off reading the locale from getenv("LANG") on POSIX systems, and using a look-up to get the codepage e.g. http://www.cryer.co.uk/brian/windows/info_windows_locale_table.htm. Having said that, I've just spotted from chcp on my Windows XP PC that my codepage is 437 and yet my locale is en-gb/en_GB which ought to have a codepage of 1252/850 ... so perhaps there's more to this :-(
0
 
LVL 5

Assisted Solution

by:g0rath
g0rath earned 250 total points
ID: 9740150

linux:

#include <locale.h>

setlocale(LC_ALL, NULL); // Returns current locale
setlocale(LC_ALL,"C");
setlocale(LC_ALL,"POSIX");

LC_ALL
    for all of the locale.
LC_COLLATE
    for regular expression matching (it determines the meaning of range expressions and equivalence classes) and string
    collation.
LC_CTYPE
    for regular expression matching, character classification, conversion, case-sensitive comparison, and wide character    
    functions.
LC_MESSAGES
    for localizable natural-language messages.
LC_MONETARY
    for monetary formatting.
LC_NUMERIC
    for number formatting (such as the decimal point and the thousands separator).
LC_TIME
    for time and date formatting.


getenv("LANG");
getenv("LC_ALL");

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best UNIX-compatible free C compiler for Windows or Mac 6 252
C dll call freezes 5 107
An API detour question 7 93
How to translate this 2-line while loop into C from Perl? 8 118
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question