[AD] filename encoding again

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


Following what was said in the meeting, here's a patch which makes
filename encoding detection independent of the system driver. I simply
added a function _al_detect_filename_encoding which is called from
install_allegro, even if the driver is SYSTEM_NONE (and hence removed
detection from all the system drivers themselves).

I also renamed file_encoding to filename_encoding.

I have no idea about the outstanding windows issues, so before applying,
someone needs to look at those..

-- 
Elias Pschernig <elias@xxxxxxxxxx>
Index: src/win/wsystem.c
===================================================================
--- src/win/wsystem.c	(revision 8114)
+++ src/win/wsystem.c	(working copy)
@@ -208,10 +208,6 @@
    if (init_directx_window() != 0)
       goto Error;
 
-   if (_al_win_unicode_filenames) {
-      set_file_encoding(U_UNICODE);
-   }
-
    return 0;
 
  Error:
Index: src/win/wfile.c
===================================================================
--- src/win/wfile.c	(revision 8114)
+++ src/win/wfile.c	(working copy)
@@ -50,6 +50,19 @@
 
 
 
+/* _al_detect_filename_encoding:
+ *  Platform specific function to detect the filename encoding. This is called
+ *  after setting a system driver, and even if this driver is SYSTEM_NONE.
+ */
+void _al_detect_filename_encoding(void)
+{
+   if (_al_win_unicode_filenames) {
+      set_filename_encoding(U_UNICODE);
+   }
+}
+
+
+
 /* _al_file_size_ex:
  *  Measures the size of the specified file.
  */
Index: src/linux/lsystem.c
===================================================================
--- src/linux/lsystem.c	(revision 8114)
+++ src/linux/lsystem.c	(working copy)
@@ -171,8 +171,6 @@
 	_unix_read_os_type();
 	if (os_type != OSTYPE_LINUX) return -1; /* FWIW */
 
-   _unix_guess_file_encoding();
-
 	/* This is the only bit that needs root privileges.  First
 	 * we attempt to set our euid to 0, in case this is the
 	 * second time we've been called. */
Index: src/unix/ufile.c
===================================================================
--- src/unix/ufile.c	(revision 8114)
+++ src/unix/ufile.c	(working copy)
@@ -497,7 +497,7 @@
 
 
 
-void _unix_guess_file_encoding(void)
+void _al_detect_filename_encoding(void)
 {
    char const *encoding = "unknown";
    char *locale = getenv("LC_ALL");
@@ -514,7 +514,7 @@
           strstr(locale, "utf-8") ||
           strstr(locale, "UTF8")) {
          /* Note: UTF8 is default anyway. */
-         set_file_encoding(U_UTF8);
+         set_filename_encoding(U_UTF8);
          encoding = "UTF8";
       }
       /* TODO: detect other encodings, and support them in Allegro */
Index: src/allegro.c
===================================================================
--- src/allegro.c	(revision 8114)
+++ src/allegro.c	(working copy)
@@ -400,6 +400,9 @@
 
    /* detect CPU type */
    check_cpu();
+   
+   /* detect filename encoding used by libc */
+   _al_detect_filename_encoding();
 
    /* set up screensaver policy */
    _screensaver_policy = get_config_int(uconvert_ascii("system", tmp1),
Index: src/qnx/qsystem.c
===================================================================
--- src/qnx/qsystem.c	(revision 8114)
+++ src/qnx/qsystem.c	(working copy)
@@ -338,8 +338,6 @@
    int spolicy;
    char tmp[WINDOW_TITLE_SIZE];
 
-   _unix_guess_file_encoding();
-
    /* install emergency-exit signal handlers */
    old_sig_abrt = signal(SIGABRT, qnx_signal_handler);
    old_sig_fpe  = signal(SIGFPE,  qnx_signal_handler);
Index: src/macosx/system.m
===================================================================
--- src/macosx/system.m	(revision 8114)
+++ src/macosx/system.m	(working copy)
@@ -411,8 +411,6 @@
       return -1;
    }
 
-   _unix_guess_file_encoding();
-
    /* Install emergency-exit signal handlers */
    old_sig_abrt = signal(SIGABRT, osx_signal_handler);
    old_sig_fpe  = signal(SIGFPE,  osx_signal_handler);
Index: src/file.c
===================================================================
--- src/file.c	(revision 8114)
+++ src/file.c	(working copy)
@@ -74,7 +74,7 @@
 
 static PACKFILE *pack_fopen_special_file(AL_CONST char *filename, AL_CONST char *mode);
 
-static int file_encoding = U_ASCII;
+static int filename_encoding = U_ASCII;
 
 
 #define FA_DAT_FLAGS  (FA_RDONLY | FA_ARCH)
@@ -672,22 +672,22 @@
  ***************************************************/
 
 
-/* set_file_encoding:
+/* set_filename_encoding:
  *  Sets the encoding to use for filenames. By default, UTF8 is assumed.
  */
-void set_file_encoding(int encoding)
+void set_filename_encoding(int encoding)
 {
-    file_encoding = encoding;
+    filename_encoding = encoding;
 }
 
 
 
-/* get_file_encoding:
+/* get_filename_encoding:
  *  Returns the encoding currently assumed for filenames.
  */
-int get_file_encoding(void)
+int get_filename_encoding(void)
 {
-    return file_encoding ;
+    return filename_encoding ;
 }
 
 
Index: src/x/xsystem.c
===================================================================
--- src/x/xsystem.c	(revision 8114)
+++ src/x/xsystem.c	(working copy)
@@ -167,8 +167,6 @@
 
    _unix_read_os_type();
 
-   _unix_guess_file_encoding();
-
    /* install emergency-exit signal handlers */
    old_sig_abrt = signal(SIGABRT, _xwin_signal_handler);
    old_sig_fpe  = signal(SIGFPE,  _xwin_signal_handler);
Index: include/allegro/platform/aintunix.h
===================================================================
--- include/allegro/platform/aintunix.h	(revision 8114)
+++ include/allegro/platform/aintunix.h	(working copy)
@@ -74,11 +74,6 @@
    AL_FUNC(void, _unix_register_digi_driver, (int id, DIGI_DRIVER *driver, int autodetect, int priority));
    AL_FUNC(void, _unix_register_midi_driver, (int id, MIDI_DRIVER *driver, int autodetect, int priority));
 
-
-   /* File system helpers */
-   AL_FUNC(void, _unix_guess_file_encoding, (void));
-
-
    /* Get size of a memory page in bytes */
    AL_FUNC(size_t, _unix_get_page_size, (void));
 
Index: include/allegro/internal/aintern.h
===================================================================
--- include/allegro/internal/aintern.h	(revision 8114)
+++ include/allegro/internal/aintern.h	(working copy)
@@ -126,6 +126,8 @@
 AL_FUNC(int, _al_getdrive, (void));
 AL_FUNC(void, _al_getdcwd, (int drive, char *buf, int size));
 
+AL_FUNC(void, _al_detect_filename_encoding, (void));
+
 /* obsolete; only exists for binary compatibility with 4.2.0 */
 AL_FUNC(long, _al_file_size, (AL_CONST char *filename));
 
Index: include/allegro/file.h
===================================================================
--- include/allegro/file.h	(revision 8114)
+++ include/allegro/file.h	(working copy)
@@ -138,10 +138,10 @@
 };
 
 
-#define uconvert_tofilename(s, buf)      uconvert(s, U_CURRENT, buf, get_file_encoding(), sizeof(buf))
+#define uconvert_tofilename(s, buf)      uconvert(s, U_CURRENT, buf, get_filename_encoding(), sizeof(buf))
 
-AL_FUNC(void, set_file_encoding, (int encoding));
-AL_FUNC(int, get_file_encoding, (void));
+AL_FUNC(void, set_filename_encoding, (int encoding));
+AL_FUNC(int, get_filename_encoding, (void));
 
 AL_FUNC(void, packfile_password, (AL_CONST char *password));
 AL_FUNC(PACKFILE *, pack_fopen, (AL_CONST char *filename, AL_CONST char *mode));


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