473,799 Members | 3,132 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Internationaliz ation - Unicode - Format used for command line arguments?

Hi!

For example:

1)
I want to open a file in a Chinese locale and print it.

2)
The program takes the file name as a command line argument.

Chinese characters are multibyte but I don't know what particular
encoding is used in the argv vector of main.

Once I get an answer to this I expect that the ICU package can help me
sort out the rest.

Any comments are appreciated.

BRs
/Sune

Dec 16 '05 #1
7 3252
Sune wrote:
Hi!

For example:

1)
I want to open a file in a Chinese locale and print it.

2)
The program takes the file name as a command line argument.

Chinese characters are multibyte but I don't know what particular
encoding is used in the argv vector of main.


The way locales and filenames work depends on your platform. For
example, it is different on Windows and Linux.

If you are using the standard form of main:
int main(int argc, char **argv)
{
}
then the argv array probably contains strings in the current locale's
encoding. If the system is actually set to a Chinese locale, this is
likely to be one of GBK, GB2312, BIG5 or UTF-8. On Windows, it will be
GBK for Simplified Chinese, or BIG5 for Traditional Chinese. On Linux,
it may be UTF-8 if your system is quite recent, otherwise will probably
be either GB2312 or Big5.

In addition, filenames may be stored in different encodings.

Windows typically uses Unicode (UTF-16) to store filenames, though you
need platform specific functions to actually open a file using a Unicode
filename. If the filename contains characters that are not in the system
locale's encoding, then you cannot use fopen to open the file.

Linux uses multibyte strings as filenames, and you can always use fopen
to open them. These days they are often UTF-8, but may also be in a
legacy encoding such as GB2312 or BIG5.

Getting to the point: there is unfortunately no way to tell what
encoding is being used, from the point of view of portable standard C.
You may have to insert some conditional code for each platform.

--
Simon.
Dec 16 '05 #2
Hi,

thanks for being clear and to the point. My conclusion is that I will
have to rely on ICU (IBM's International Components for Unicode) in the
sense that: locales and character sets that ICU can detect and turn
into Unicode (if necessary) will be the locales I support. Going
further doesn't seem feasible. Is this considered bad style/laziness?
Is there any other way?

You seem to be well informed on the subject, so could you please
provide a link where I can find all locales and their supported
characters? What I want to find out is if the so-called invariants are
part of the character set of all locales, or if I will mess things up
if I try to add a file extension such as '.xml' to a processed file?
E.g. a succeeding fopen will fail (as you pointed out earlier) if the
locale is Chinese.

Thanks again
/Sune

Dec 16 '05 #3
Sune wrote:
Hi,

thanks for being clear and to the point. My conclusion is that I will
have to rely on ICU (IBM's International Components for Unicode) in the
sense that: locales and character sets that ICU can detect and turn
into Unicode (if necessary) will be the locales I support. Going
further doesn't seem feasible. Is this considered bad style/laziness?
Is there any other way?

You seem to be well informed on the subject, so could you please
provide a link where I can find all locales and their supported
characters? What I want to find out is if the so-called invariants are
part of the character set of all locales, or if I will mess things up
if I try to add a file extension such as '.xml' to a processed file?
E.g. a succeeding fopen will fail (as you pointed out earlier) if the
locale is Chinese.


Character encodings can be divided into those which are based around
ASCII, where ASCII text is valid in that encoding, and those which do
not allow plain ASCII text to exist unchanged.

ASCII-based encodings:

ISO-8859-1 has 1 byte per character
UTF-8 has 1, 2, 3, or 4 bytes per character
Big5 has 1 or 2 bytes per character
GB2312 has 1 or 2 bytes per character
GBK has 1 or 2 bytes per character
GB18030 has 1, 2 or 4 bytes per character

Non-ASCII-based encodings:

UTF-16 has 2 or 4 bytes per character
UTF-32 has 4 bytes per character

You can usually use a C string (zero-terminated array of char) to store
any of the ASCII-based encodings. The problem with UTF-16 and UTF-32 is
that they have embedded zero bytes, so you could instead use an array of
uint16_t or uint32_t respectively.

wchar_t is 2 bytes on most C implementations on Windows, and is used to
contain strings in UTF-16. wchar_t is 4 bytes on most C implementations
on Linux, and is used to contain strings in UTF-32.

For one of the ASCII-based encodings, you can append ".xml" to the
string using strcat, and not break the encoding.

For one of the non-ASCII based encodings, you need to convert your
".xml" into the correct Unicode format before appending it to the string.

UTF-16 LE: (uint16_t *)(char[]) {'.',0, 'x',0, 'm',0, 'l',0, 0,0}

UTF-16 BE: (uint16_t *)(char[]) { 0,'.', 0,'x', 0,'m', 0,'l', 0,0}

UTF-32 LE: (uint32_t *)(char[]) { 0,0,0,'.', 0,0,0,'x', 0,0,0,'m',
0,0,0,'l', 0,0,0,0 }

UTF-32 BE: (uint32_t *)(char[]) {'.',0,0,0, 'x',0,0,0, 'm',0,0,0,
'l',0,0,0, 0,0,0,0 }

On most systems, L".xml" is equivalent to one of the four above. Which
one it is equivalent to depends on the choices made by your platform's C
compiler and library implementors.

--
Simon.
Dec 17 '05 #4
Simon,

this made me get the part of the picture I was missing. It also made my
program a lot smaller.

Thanks for your patience
/Sune

Dec 17 '05 #5
On 17 Dec 2005 07:31:58 -0800, in comp.lang.c , "Sune"
<su**********@h otmail.com> wrote:

(a contextless answer).

Sune, can you please take note of this:

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 17 '05 #6
Simon Biber wrote:
[...]
For one of the non-ASCII based encodings, you need to convert your
".xml" into the correct Unicode format before appending it to the string.

UTF-16 LE: (uint16_t *)(char[]) {'.',0, 'x',0, 'm',0, 'l',0, 0,0}

UTF-16 BE: (uint16_t *)(char[]) { 0,'.', 0,'x', 0,'m', 0,'l', 0,0}

UTF-32 LE: (uint32_t *)(char[]) { 0,0,0,'.', 0,0,0,'x', 0,0,0,'m',
0,0,0,'l', 0,0,0,0 }

UTF-32 BE: (uint32_t *)(char[]) {'.',0,0,0, 'x',0,0,0, 'm',0,0,0,
'l',0,0,0, 0,0,0,0 }


Replying to myself here.

I got UTF-32 LE and BE mixed around. {0,0,0,'.'} is actually big-endian
UTF-32, and {'.',0,0,0} is little-endian UTF-32.

Also remember that these shortcuts assume that your character constants
are in ASCII (or ISO-8859-1), and will not work on an EBCDIC machine.

--
Simon.
Dec 18 '05 #7
Simon Biber <ne**@ralmin.cc > wrote:

# Also remember that these shortcuts assume that your character constants
# are in ASCII (or ISO-8859-1), and will not work on an EBCDIC machine.

Any poor wretch using an EBCDIC machine has enough problems
without Unicode.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Death is the worry of the living. The dead, like myself,
only worry about decay and necrophiliacs.
Dec 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
26646
by: ..... | last post by:
I have an established program that I am changing to allow users to select one of eight languages and have all the label captions change accordingly. I have no problems with English, French, Dutch, German, Spanish or Italian. The Polish language is causing me trouble. From what I have read, VB supports UNICODE, in fact it uses UNICODE internally, which means that ANY character in pretty much any language should be readable from a UNICODE...
8
7091
by: sebastien.hugues | last post by:
Hi I would like to retrieve the application data directory path of the logged user on windows XP. To achieve this goal i use the environment variable APPDATA. The logged user has this name: sébastien. The second character is not an ascii one and when i try to encode the path that contains this name in utf-8,
9
2029
by: Brian Kelley | last post by:
I have been using gettext and various utilities to provide internationalization for a wxPython application and have not really been liking the process. Essentially it uses a macro-style notation to indicate which strings should be internationalized. Essentially, everything looks like this _("STRING") A good description of this system is located here http://wiki.wxpython.org/index.cgi/Internationalization
10
2411
by: Dumbkiwi | last post by:
I'm trying to get python, unicode and kdialog to play nicely together. This is a linux machine, and kdialog is a way to generate dialog boxes in kde with which users can interact (for example input text), and you can use the outputted text in your script. Anyway, what I'm doing is reading from a utf-8 encoded text file using the codecs module, and using the following: data = codecs.open('file', 'r', 'utf-8')
2
9766
by: Bernd Lambertz | last post by:
I have a problem with bcp and format files. We changed our databases from varchar to nvarchar to support unicode. No problems so fare with that. It is working fine. But now I need a format file for the customer table and and it is not working. It is working fine with the old DB with varchar, but with nvarchar I'm not able to copy the data. The biggest problem is, that I got no error message. BCP starts copying to table and finished...
48
4648
by: Zenobia | last post by:
Recently I was editing a document in GoLive 6. I like GoLive because it has some nice features such as: * rewrite source code * check syntax * global search & replace (through several files at once) * regular expression search & replace. Normally my documents are encoded with the ISO setting. Recently I was writing an XHTML document. After changing the encoding to UTF-8 I used the
3
13865
by: GM | last post by:
Dear all, Could you all give me some guide on how to convert my big5 string to unicode using python? I already knew that I might use cjkcodecs or python 2.4 but I still don't have idea on what exactly I should do. Please give me some sample code if you could. Thanks a lot Regards, Gary
18
620
by: Chameleon | last post by:
I am trying to #define this: #ifdef UNICODE_STRINGS #define UC16 L typedef wstring String; #else #define UC16 typedef string String; #endif ....
4
2261
by: laxmikiran.bachu | last post by:
Can we have change a unicode string Type object to a Tuple type object.. If so how ????
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10247
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10214
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2935
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.