createAndWriteFile creates weird files on Linux

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Donner
Posts: 87
Joined: Fri May 18, 2007 11:27 am

createAndWriteFile creates weird files on Linux

Post by Donner »

Hi,

when I create a File using the createAndWriteFile-Method of IFileSystem, i get a file which I can't open with gedit because it says that it can't find out the charset (I'm using Ubuntu 10.10 and the latest Irrlicht release).

Using emacs i can open the file, bit it seems weird: between every letter there is a "^@" which i don't know how it gets there... it almost looks like a binary file or something like that,

Using Windows it worked just fine.
Why does Irrlicht create such weird files? I just want a normal text file that I can open with a normal text editor...

Thank you,
D.
CuteAlien
Admin
Posts: 9687
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

It sounds like you write widechar (wchar_t) strings into the file. Those are 4 bytes on Linux, but despite that most Linux editors don't seem to be able to handle utf-32 (which would be needed).
2 solutions - either don't write wchar_t but convert to char first or convert the file afterward with iconv like:

iconv -f UTF-32 -t UTF-8 yourfile > targetfile
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Donner
Posts: 87
Joined: Fri May 18, 2007 11:27 am

Post by Donner »

ok thanks!

but IXMLWriter::writeElement only takes a wchar_t as parameter, not a char... so how can i create utf8-xml-files with irrlicht?
CuteAlien
Admin
Posts: 9687
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Ah XML... yes, that's a problem. I found no solution for that myself so far and have to use iconv every time on files written by Irrlicht in Linux :-( Which is one of the main reasons I still use tinyXML instead of irrXML whenever I can.

Allowing to write other text-formats with xml is very high on the wishlist and Nalin even has written a utf8-string-class some weeks/months ago and adapted the xml-writer to allow doing that. I had wished to include that in Irrlicht 1.8, but didn't find time the last months due to another time consuming project.

So right now ... use iconv or find any way to work with utf-32 in a Linux editor. People occasionally tell me that they can do that on their Linux system, but so far no one managed to help me to get any editor on my Linux system (debian) really working with utf-32. If you figure it out please tell me.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

If you really need UTF-8 XML files, here are my Irrlicht patches that CuteAlien alluded to:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=37296

All you will need is the ustring class and the XML reading/writing files and patches. You will need to modify your Irrlicht project file / makefile in order to add CXMLWriterUTF8.cpp to the Irrlicht project.
Post Reply