Using readdir and Spanish Dir Names

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

Using readdir and Spanish Dir Names

Post by theHobbit »

Hi, I'm having some trouble reading and displaying file names that contain spanish chars like: México and Sueño.

All I wan't to know is how do I get the correct value for chars é and ñ.
When I run the program in Windows using DevC++ I can display those chars correctly but it doesn't work on psp.

I'm using the SDL SFont Suite library for displaying unicode strings.

Here is my code:

DIR *dhandle;
struct dirent *entry;

if((dhandle = opendir("ms0:/")) == NULL) {
pspDebugScreenPrintf("Error: couldn't open directory\n");
return 0;
}


int done = 0;
int y = 20;
while( !done ) {
entry = readdir(dhandle);
if( entry != 0 ) {
SFontSuiteText(screen,
10, 10, entry->d_name, 255);
}
else done = 1;
}

When I printf the hex value of the char é in DevC++ I obtain [e9] but in the psp i'm always getting [81 a1] for any char like á é í ó ú ñ, etc.

Well I hope anyone can help, Thanks
cooleyes
Posts: 123
Joined: Thu May 18, 2006 3:30 pm

Re: Using readdir and Spanish Dir Names

Post by cooleyes »

theHobbit wrote:Hi, I'm having some trouble reading and displaying file names that contain spanish chars like: México and Sueño.

All I wan't to know is how do I get the correct value for chars é and ñ.
When I run the program in Windows using DevC++ I can display those chars correctly but it doesn't work on psp.

I'm using the SDL SFont Suite library for displaying unicode strings.

Here is my code:

DIR *dhandle;
struct dirent *entry;

if((dhandle = opendir("ms0:/")) == NULL) {
pspDebugScreenPrintf("Error: couldn't open directory\n");
return 0;
}


int done = 0;
int y = 20;
while( !done ) {
entry = readdir(dhandle);
if( entry != 0 ) {
SFontSuiteText(screen,
10, 10, entry->d_name, 255);
}
else done = 1;
}

When I printf the hex value of the char é in DevC++ I obtain [e9] but in the psp i'm always getting [81 a1] for any char like á é í ó ú ñ, etc.

Well I hope anyone can help, Thanks
because the filenam(dirname) saved in MS use Unicode,
so when you create a dir or a new file, It will do a convert(spanish -> unicode) .
but when you use readdir to get the filename(dirname), it do a stupid thing, it use a convert ( unicode -> shift-jis).
so you get a wrong name string.

what you can do :
1. do a convert( shift-jis -> spanish), but it still have some wrong char.
2. read the MS's fat direct, get the unicode filename, and do a convert (unicode -> spanish), it is perfect.
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

Re: Using readdir and Spanish Dir Names

Post by theHobbit »

"cooleyes
because the filenam(dirname) saved in MS use Unicode,
so when you create a dir or a new file, It will do a convert(spanish -> unicode) .
but when you use readdir to get the filename(dirname), it do a stupid thing, it use a convert ( unicode -> shift-jis).
so you get a wrong name string.

what you can do :
1. do a convert( shift-jis -> spanish), but it still have some wrong char.
2. read the MS's fat direct, get the unicode filename, and do a convert (unicode -> spanish), it is perfect.
Thanks, searching the net I found this app eReader, it seems it uses the second option so i will give it a try!!
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

Re: Using readdir and Spanish Dir Names

Post by theHobbit »

Yep, problem fixed. Well I used the fat code from the eReader source, and yes all I had to do was convert the unicode to spanish like cooleyes said. So thanks :)
cooleyes
Posts: 123
Joined: Thu May 18, 2006 3:30 pm

Re: Using readdir and Spanish Dir Names

Post by cooleyes »

theHobbit wrote:Yep, problem fixed. Well I used the fat code from the eReader source, and yes all I had to do was convert the unicode to spanish like cooleyes said. So thanks :)
the "fat.c" in eReader have a bug, when it run at a 4G MS.
you can get the fixed "fat.c" in my project PPA( pmplayer advance) , it fixed the bug when use a 4G MS

http://files.cngba.com/cooleyes/PPA/PPA ... 070331.rar
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

Re: Using readdir and Spanish Dir Names

Post by theHobbit »

the "fat.c" in eReader have a bug, when it run at a 4G MS.
you can get the fixed "fat.c" in my project PPA( pmplayer advance) , it fixed the bug when use a 4G MS

http://files.cngba.com/cooleyes/PPA/PPA ... 070331.rar
Wow thanks again man, i will give it a try then.
Post Reply