Re: [AD] Windows unicode filename support

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


Can we use wchar_t? This wouldn't introduce compatibility problems (eg:
VC++, BCC or Watcom) or issues like "allegro must be C89"?

Victor

--- Chris <chris.kcat@xxxxxxxxxx> escreveu:

> Since I made a patch for Unix a while ago to support UTF-8/Unicode
> filenames, 
> it'd only be fair for Windows to support Unicode filenames too. I
> don't 
> believe Windows' _stat/_findfirst/etc would work properly with UTF-8
> names 
> like the similar routines seem to in Unix, so I opted to change it to
> use the 
> wide-char/UTF-16 equivilants (_wstat/_wfindfirst/etc).
> 
> I had a Windows user test it and it seems to work in his app.
> > Index: src/win/wfile.c
> ===================================================================
> --- src/win/wfile.c	(revision 5781)
> +++ src/win/wfile.c	(working copy)
> @@ -51,7 +51,8 @@
>     struct _stat s;
>     char tmp[1024];
>  
> -   if (_stat(uconvert_toascii(filename, tmp), &s) != 0) {
> +   if (_wstat((wchar_t*)uconvert(filename, U_CURRENT, tmp,
> U_UNICODE,
> +              sizeof(tmp)), &s) != 0) {
>        *allegro_errno = errno;
>        return 0;
>     }
> @@ -69,7 +70,8 @@
>     struct _stat s;
>     char tmp[1024];
>  
> -   if (_stat(uconvert_toascii(filename, tmp), &s) != 0) {
> +   if (_wstat((wchar_t*)uconvert(filename, U_CURRENT, tmp,
> U_UNICODE,
> +              sizeof(tmp)), &s) != 0) {
>        *allegro_errno = errno;
>        return 0;
>     }
> @@ -82,7 +84,7 @@
>  /* structure for use by the directory scanning routines */
>  struct FF_DATA
>  {
> -   struct _finddata_t data;
> +   struct _wfinddata_t data;
>     long handle;
>     int attrib;
>  };
> @@ -100,7 +102,8 @@
>     info->time = ff_data->data.time_write;
>     info->size = ff_data->data.size;
>  
> -   do_uconvert(ff_data->data.name, U_ASCII, info->name, U_CURRENT,
> sizeof(info->name));
> +   do_uconvert((const char*)ff_data->data.name, U_UNICODE,
> info->name, U_CURRENT,
> +               sizeof(info->name));
>  }
>  
>  
> @@ -141,7 +144,8 @@
>     /* start the search */
>     errno = *allegro_errno = 0;
>  
> -   ff_data->handle = _findfirst(uconvert_toascii(pattern, tmp),
> &ff_data->data);
> +   ff_data->handle = _wfindfirst((wchar_t*)uconvert(pattern,
> U_CURRENT, tmp,
> +                                 U_UNICODE, sizeof(tmp)),
> &ff_data->data);
>  
>     if (ff_data->handle < 0) {
>        *allegro_errno = errno;
> @@ -173,7 +177,7 @@
>     struct FF_DATA *ff_data = (struct FF_DATA *) info->ff_data;
>  
>     do {
> -      if (_findnext(ff_data->handle, &ff_data->data) != 0) {
> +      if (_wfindnext(ff_data->handle, &ff_data->data) != 0) {
>           *allegro_errno = errno;
>           return -1;
>        }
> @@ -227,10 +231,10 @@
>   */
>  void _al_getdcwd(int drive, char *buf, int size)
>  {
> -   char tmp[1024];
> +   wchar_t tmp[1024];
>  
> -   if (_getdcwd(drive+1, tmp, sizeof(tmp)))
> -      do_uconvert(tmp, U_ASCII, buf, U_CURRENT, size);
> +   if (_wgetdcwd(drive+1, tmp, sizeof(tmp)/sizeof(tmp[0])))
> +      do_uconvert((const char*)tmp, U_UNICODE, buf, U_CURRENT,
> size);
>     else
>        usetc(buf, 0);
>  }
> 



		
_______________________________________________________ 
Abra sua conta no Yahoo! Mail: 1GB de espaço, alertas de e-mail no celular e anti-spam realmente eficaz. 
http://br.info.mail.yahoo.com/




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