Hackish workaround so that emelfm2 can cope with files on a locale-less system. - Daniel Drake diff -urNp emelfm2-0.0.8/src/dialogs/e2_mkdir_dialog.c emelfm2-dsd/src/dialogs/e2_mkdir_dialog.c --- emelfm2-0.0.8/src/dialogs/e2_mkdir_dialog.c 2004-04-26 23:37:51.000000000 +0100 +++ emelfm2-dsd/src/dialogs/e2_mkdir_dialog.c 2004-06-22 14:37:38.000972944 +0100 @@ -74,7 +74,7 @@ static gchar *find_dir (const gchar *dir if (dir == NULL) dir = _("new directory"); //the absolute directory name consists of 4 parts - gchar *str = _UTF2STR (dir); + gchar *str = _UTF2STR ((gchar*)dir); //parent directory in case the entered string is not absolute gchar *part1 = g_path_is_absolute (str) ? g_strdup ("") : _UTF2STR (rt->path); @@ -259,7 +259,7 @@ static void update_labels (E2_MkdirDialo const gchar *dir = gtk_entry_get_text (GTK_ENTRY (GTK_BIN (rt->combo)->child)); - gchar *path = _UTF2STR (dir); + gchar *path = _UTF2STR ((gchar*)dir); gchar *reason = NULL; rt->creation_possible = TRUE; @@ -384,7 +384,7 @@ static void create_dir (GtkWidget *entry if (*dir == '\0') return; - gchar *path = _UTF2STR (dir); + gchar *path = _UTF2STR ((gchar*)dir); if (!g_path_is_absolute (path)) { gchar *free = path; diff -urNp emelfm2-0.0.8/src/e2_main.c emelfm2-dsd/src/e2_main.c --- emelfm2-0.0.8/src/e2_main.c 2004-04-25 16:18:15.000000000 +0100 +++ emelfm2-dsd/src/e2_main.c 2004-06-22 14:34:24.802343600 +0100 @@ -168,19 +168,17 @@ static void check_locale () { printd (DEBUG, "check_locale ()"); gchar *locale = gtk_set_locale (); - printd (NOTICE, "current locale is '%s'", locale); + printf ("current locale is '%s'\n", locale); + const gchar *broken = g_getenv ("G_BROKEN_FILENAMES"); if (broken != NULL && STREQ (locale, "C")) { - printd (ERROR, "cannot convert broken filenames with 'C' locale"); - printf - (_( - "\nThe error above usually means that you've set the environment variable\n" - "G_BROKEN_FILENAMES to something. Then GTK+2 is suppossed to work with file names\n" - "in your locale. Though, it is impossible to do this without a known locale.\n" - "To prevent crashes please either unset G_BROKEN_FILENAMES or adjust your locale.\n\n" - )); - exit (1); + printf("You have set the environment variable G_BROKEN_FILENAMES. GTK+ is\n" + "supposed to now treat filenames if they are in the system locale.\n" + "However, you have not set a system locale. We will default to ISO-8859-1\n" + "when reading filenames. If this produces odd behaviour when handling filenames\n" + "with non-ASCII characters in them, then please set a system locale with the LANG\n" + "environment variable\n."); } #ifdef ENABLE_NLS diff -urNp emelfm2-0.0.8/src/emelfm2.h emelfm2-dsd/src/emelfm2.h --- emelfm2-0.0.8/src/emelfm2.h 2004-04-25 16:18:15.000000000 +0100 +++ emelfm2-dsd/src/emelfm2.h 2004-06-22 14:35:30.700325584 +0100 @@ -68,10 +68,61 @@ #define MAX_COLUMNS 8 #define STREQ(a,b) (g_str_equal ((a),(b))) -#define _STR2UTF(d) g_filename_to_utf8 (d, -1, NULL, NULL, NULL) -#define _UTF2STR(d) g_filename_from_utf8 (d, -1, NULL, NULL, NULL) -#define STR2UTF(d) g_locale_to_utf8 (d, -1, NULL, NULL, NULL) -#define UTF2STR(d) g_locale_from_utf8 (d, -1, NULL, NULL, NULL) + +static inline gchar *_STR2UTF(gchar *d) { + gchar *ret; + ret = g_filename_to_utf8(d, -1, NULL, NULL, NULL); + if(!ret) { + ret = g_convert(d, -1, "utf-8", "iso-8859-1", + NULL, NULL, NULL); + if(!ret) + ret = g_strdup("Unknown"); + } + return ret; +} + +static inline gchar *_UTF2STR(gchar *d) { + gchar *ret; + ret = g_filename_from_utf8(d, -1, NULL, NULL, NULL); + if(!ret) { + ret = g_convert(d, -1, "iso-8859-1", "utf-8", + NULL, NULL, NULL); + if(!ret) + ret = g_strdup("Unknown"); + } + return ret; +} + +static inline gchar *STR2UTF(gchar *d) { + gchar *ret; + if (g_utf8_validate(d, -1, NULL)) + return g_strdup(d); + + ret = g_locale_to_utf8(d, -1, NULL, NULL, NULL); + + if (!ret) + ret = g_convert(d, -1, "utf-8", "iso-8859-1", NULL, NULL, NULL); + + if (!ret) + ret = g_strdup("Unknown"); + + return ret; +} + + +static inline gchar *UTF2STR(gchar *d) { + gchar *ret; + ret = g_locale_from_utf8(d, -1, NULL, NULL, NULL); + + if (!ret) + ret = g_convert(d, -1, "iso-8859-1", "utf-8", NULL, NULL, NULL); + + if (!ret) + ret = g_strdup("Unknown"); + + return ret; +} + #define MESC(d) g_markup_escape_text (d, -1) #define WAIT_FOR_EVENTS while (gtk_events_pending ()) { gtk_main_iteration (); }