[AD] UTF-8 in ufile.c?

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


I ran into this issue while browsing some of my files that have korean 
characters. Konsole, and just about everything else in Linux shows the file 
names properly, but Allegro's file selector not only shows them wrong, it 
also gets the number of characters wrong. Looking through ufile.c, it appears 
to assume that Unix will only use ASCII names.

I tried this as a test, and made ufile.c convert to/from UTF-8 instead. Now 
when looking at those files with the file selector, it shows the proper 
amount of chars (though don't know if the characters are actually right, 
since I don't have a unicode font Allegro can use. it just shows the standard 
missing '^' character). This patch isn't fully complete, and could be 
improved a bit (the calls I changed to use uconvert still use the explicit 
before.. they could probably use the internal static one instead), but it's a 
starting point to test make sure I'm not breaking anything.

And even if it's only certain Unix systems that can use UTF-8 characters, it 
shouldn't be hard to make a constructor that checks and sets a global format 
variable to U_UTF8 or U_ASCII, depending.
Index: src/unix/ufile.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/unix/ufile.c,v
retrieving revision 1.4
diff -u -r1.4 ufile.c
--- src/unix/ufile.c	2 Jul 2004 16:25:42 -0000	1.4
+++ src/unix/ufile.c	12 Sep 2005 00:42:20 -0000
@@ -74,7 +74,7 @@
    struct stat s;
    char tmp[1024];
 
-   if (stat(uconvert_toascii(filename, tmp), &s) != 0) {
+   if (stat(uconvert(filename, U_CURRENT, tmp, U_UTF8, sizeof(tmp)), &s) != 0) {
       *allegro_errno = errno;
       return 0;
    }
@@ -92,7 +92,7 @@
    struct stat s;
    char tmp[1024];
 
-   if (stat(uconvert_toascii(filename, tmp), &s) != 0) {
+   if (stat(uconvert(filename, U_CURRENT, tmp, U_UTF8, sizeof(tmp)), &s) != 0) {
       *allegro_errno = errno;
       return 0;
    }
@@ -316,15 +316,15 @@
    char *p;
 
    /* if the pattern contains no wildcard, we use stat() */
-   if (!ustrpbrk(pattern, uconvert_ascii("?*", tmp))) {
+   if (!ustrpbrk(pattern, uconvert("?*", U_ASCII, tmp, U_CURRENT, sizeof(tmp)))) {
       info->ff_data = NULL;
 
       /* start the search */
       errno = *allegro_errno = 0;
 
-      if (stat(uconvert_toascii(pattern, tmp), &s) == 0) {
+      if (stat(uconvert(pattern, U_CURRENT, tmp, U_UTF8, sizeof(tmp)), &s) == 0) {
          /* get file attributes */
-         actual_attrib = ff_get_attrib(ff_get_filename(uconvert_toascii(pattern, tmp)), &s);
+         actual_attrib = ff_get_attrib(ff_get_filename(uconvert(pattern, U_CURRENT, tmp, U_UTF8, sizeof(tmp))), &s);
 
          /* does it match ? */
          if ((actual_attrib & ~attrib) == 0) {
@@ -354,7 +354,7 @@
    /* initialize it */
    ff_data->attrib = attrib;
 
-   do_uconvert(pattern, U_CURRENT, ff_data->dirname, U_ASCII, sizeof(ff_data->dirname));
+   do_uconvert(pattern, U_CURRENT, ff_data->dirname, U_UTF8, sizeof(ff_data->dirname));
    p = ff_get_filename(ff_data->dirname);
    _al_sane_strncpy(ff_data->pattern, p, sizeof(ff_data->pattern));
    if (p == ff_data->dirname)
@@ -443,7 +443,7 @@
    info->time = s.st_mtime;
    info->size = s.st_size;
 
-   do_uconvert(tempname, U_ASCII, info->name, U_CURRENT, sizeof(info->name));
+   do_uconvert(tempname, U_UTF8, info->name, U_CURRENT, sizeof(info->name));
 
    return 0;
 }
@@ -477,7 +477,7 @@
    char tmp[1024];
 
    if (getcwd(tmp, sizeof(tmp)))
-      do_uconvert(tmp, U_ASCII, buf, U_CURRENT, size);
+      do_uconvert(tmp, U_UTF8, buf, U_CURRENT, size);
    else
       usetc(buf, 0);
 }


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/