From 0dcbacec1fcd144c179fe4d4e4cc703b7056ede4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sun, 13 Aug 2006 09:07:10 +0000 Subject: [PATCH] Use utf8/locale encoding wrappers. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@711 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 2 ++ src/build.c | 24 ++++++++---------------- src/callbacks.c | 15 ++++----------- src/dialogs.c | 9 +++------ src/keyfile.c | 3 +-- src/search.c | 3 +-- src/utils.c | 4 ++-- 7 files changed, 21 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index 63debc81..d94e046e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ Use wrappers for converting between utf8 and locale encoding. Fixed small memory leak. * src/vte.c: Added the GTK IM menu items to the VTE popup menu. + * src/utils.c, src/dialogs.c, src/build.c, src/callbacks.c, + src/search.c, src/keyfile.c: Use utf8/locale encoding wrappers. 2006-08-12 Enrico Tröger diff --git a/src/build.c b/src/build.c index be03aa57..381789f5 100644 --- a/src/build.c +++ b/src/build.c @@ -81,8 +81,7 @@ GPid build_view_tex_file(gint idx, gint mode) view_file = g_strconcat(executable, (mode == 0) ? ".dvi" : ".pdf", NULL); // try convert in locale for stat() - locale_filename = g_locale_from_utf8(view_file, -1, NULL, NULL, NULL); - if (locale_filename == NULL) locale_filename = g_strdup(view_file); + locale_filename = utils_get_locale_from_utf8(view_file); // check wether view_file exists if (stat(locale_filename, &st) != 0) @@ -101,8 +100,7 @@ GPid build_view_tex_file(gint idx, gint mode) cmd_string = utils_str_replace(cmd_string, "%e", executable); // try convert in locale - locale_cmd_string = g_locale_from_utf8(cmd_string, -1, NULL, NULL, NULL); - if (locale_cmd_string == NULL) locale_cmd_string = g_strdup(view_file); + locale_cmd_string = utils_get_locale_from_utf8(cmd_string); argv = g_new0(gchar *, 4); argv[0] = g_strdup("/bin/sh"); @@ -183,8 +181,7 @@ GPid build_link_file(gint idx) if (idx < 0 || doc_list[idx].file_name == NULL) return (GPid) 1; - locale_filename = g_locale_from_utf8(doc_list[idx].file_name, -1, NULL, NULL, NULL); - if (locale_filename == NULL) locale_filename = g_strdup(doc_list[idx].file_name); + locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name); executable = utils_remove_ext_from_filename(locale_filename); object_file = g_strdup_printf("%s.o", executable); @@ -258,8 +255,7 @@ static GPid build_spawn_cmd(gint idx, gchar **cmd) cmd_string = g_strjoinv(" ", cmd); g_strfreev(cmd); - locale_filename = g_locale_from_utf8(doc_list[idx].file_name, -1, NULL, NULL, NULL); - if (locale_filename == NULL) locale_filename = g_strdup(doc_list[idx].file_name); + locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name); executable = utils_remove_ext_from_filename(locale_filename); @@ -272,8 +268,7 @@ static GPid build_spawn_cmd(gint idx, gchar **cmd) g_free(tmp); g_free(executable); - utf8_cmd_string = g_locale_to_utf8(cmd_string, -1, NULL, NULL, NULL); - if (utf8_cmd_string == NULL) utf8_cmd_string = g_strdup(cmd_string); + utf8_cmd_string = utils_get_utf8_from_locale(cmd_string); argv = g_new0(gchar *, 4); argv[0] = g_strdup("/bin/sh"); @@ -342,11 +337,9 @@ GPid build_run_cmd(gint idx) script_name = g_strdup("./geany_run_script.sh"); - locale_filename = g_locale_from_utf8(doc_list[idx].file_name, -1, NULL, NULL, NULL); - if (locale_filename == NULL) locale_filename = g_strdup(doc_list[idx].file_name); + locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name); - locale_term_cmd = g_locale_from_utf8(app->tools_term_cmd, -1, NULL, NULL, NULL); - if (locale_term_cmd == NULL) locale_term_cmd = g_strdup(app->tools_term_cmd); + locale_term_cmd = utils_get_locale_from_utf8(app->tools_term_cmd); // split the term_cmd, so arguments will work too term_argv = g_strsplit(locale_term_cmd, " ", -1); term_argv_len = g_strv_length(term_argv); @@ -393,8 +386,7 @@ GPid build_run_cmd(gint idx) if (chdir(working_dir) != 0) { gchar *utf8_working_dir = NULL; - utf8_working_dir = g_locale_to_utf8(working_dir, -1, NULL, NULL, NULL); - if (utf8_working_dir == NULL) utf8_working_dir = g_strdup(working_dir); + utf8_working_dir = utils_get_utf8_from_locale(working_dir); msgwin_status_add(_("Failed to change the working directory to %s"), working_dir); result_id = (GPid) 1; // return 1, to prevent error handling of the caller diff --git a/src/callbacks.c b/src/callbacks.c index 3a9c9c95..892b4c8a 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -847,8 +847,7 @@ void on_file_open_entry_activate (GtkEntry *entry, gpointer user_data) { - gchar *locale_filename = g_locale_from_utf8(gtk_entry_get_text(entry), -1, NULL, NULL, NULL); - if (locale_filename == NULL) locale_filename = g_strdup(gtk_entry_get_text(entry)); + gchar *locale_filename = utils_get_locale_from_utf8(gtk_entry_get_text(entry)); if (g_file_test(locale_filename, G_FILE_TEST_IS_DIR)) { @@ -874,8 +873,7 @@ on_file_open_selection_changed (GtkFileChooser *filechooser, if (filename) { // try to get the UTF-8 equivalent for the filename, fallback to filename if error - gchar *utf8_filename = g_locale_to_utf8(filename, -1, NULL, NULL, NULL); - if (utf8_filename == NULL) utf8_filename = g_strdup(filename); + gchar *utf8_filename = utils_get_utf8_from_locale(filename); gtk_entry_set_text(GTK_ENTRY(lookup_widget( GTK_WIDGET(filechooser), "file_entry")), utf8_filename); @@ -1672,10 +1670,7 @@ on_build_make_activate (GtkMenuItem *menuitem, case 2: //make object { gchar *locale_filename, *short_file, *noext, *object_file; //temp - locale_filename = g_locale_from_utf8(doc_list[idx].file_name, - -1, NULL, NULL, NULL); - if (locale_filename == NULL) - locale_filename = g_strdup(doc_list[idx].file_name); + locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name); short_file = g_path_get_basename(locale_filename); g_free(locale_filename); @@ -2265,9 +2260,7 @@ void on_recent_file_activate (GtkMenuItem *menuitem, gpointer user_data) { - gchar *locale_filename = g_locale_from_utf8((gchar*) user_data, -1, NULL, NULL, NULL); - - if (locale_filename == NULL) locale_filename = g_strdup((gchar*) user_data); + gchar *locale_filename = utils_get_locale_from_utf8((gchar*) user_data); document_open_file(-1, locale_filename, 0, FALSE, NULL, NULL); utils_recent_file_loaded((gchar*) user_data); diff --git a/src/dialogs.c b/src/dialogs.c index 95d69da6..2742ba09 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -125,8 +125,7 @@ void dialogs_show_open_file () { gchar *locale_filename; - locale_filename = g_locale_from_utf8(initdir, -1, NULL, NULL, NULL); - if (locale_filename == NULL) locale_filename = g_strdup(initdir); + locale_filename = utils_get_locale_from_utf8(initdir); if (g_path_is_absolute(locale_filename)) gtk_file_chooser_set_current_folder( @@ -178,8 +177,7 @@ void dialogs_show_save_as() // If the current document has a filename we use that as the default. if (doc_list[idx].file_name != NULL) { - gchar *locale_filename = g_locale_from_utf8(doc_list[idx].file_name, -1, NULL, NULL, NULL); - if (locale_filename == NULL) locale_filename = g_strdup(doc_list[idx].file_name); + gchar *locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name); if (g_path_is_absolute(locale_filename)) gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(app->save_filesel), locale_filename); @@ -1061,8 +1059,7 @@ void dialogs_show_file_properties(gint idx) #if defined(HAVE_SYS_STAT_H) && defined(TIME_WITH_SYS_TIME) && defined(HAVE_SYS_TYPES_H) - locale_filename = g_locale_from_utf8(doc_list[idx].file_name, -1, NULL, NULL, NULL); - if (locale_filename == NULL) locale_filename = g_strdup(doc_list[idx].file_name); + locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name); if (stat(locale_filename, &st) == 0) { // first copy the returned string and the trim it, to not modify the static glibc string diff --git a/src/keyfile.c b/src/keyfile.c index 6135b348..229dc234 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -424,8 +424,7 @@ gboolean configuration_open_files() else file = array[1]; // try to get the locale equivalent for the filename, fallback to filename if error - locale_filename = g_locale_from_utf8(file, -1, NULL, NULL, NULL); - if (locale_filename == NULL) locale_filename = g_strdup(file); + locale_filename = utils_get_locale_from_utf8(file); if (g_file_test(locale_filename, G_FILE_TEST_IS_REGULAR || G_FILE_TEST_IS_SYMLINK)) { diff --git a/src/search.c b/src/search.c index eb544e34..710659e6 100644 --- a/src/search.c +++ b/src/search.c @@ -730,8 +730,7 @@ on_find_in_files_dialog_response(GtkDialog *dialog, gint response, gpointer user (invert ? FIF_INVERT_MATCH : 0) | (case_sens ? FIF_CASE_SENSITIVE : 0); - locale_dir = g_locale_from_utf8(utf8_dir, -1, NULL, NULL, NULL); - if (locale_dir == NULL) locale_dir = g_strdup(utf8_dir); + locale_dir = utils_get_locale_from_utf8(utf8_dir); if (search_find_in_files(search_text, locale_dir, opts)) { diff --git a/src/utils.c b/src/utils.c index bc8f6f38..c988e257 100644 --- a/src/utils.c +++ b/src/utils.c @@ -967,7 +967,7 @@ gboolean utils_check_disk_status(gint idx) if (doc_list[idx].last_check > (t - GEANY_CHECK_FILE_DELAY)) return FALSE; - locale_filename = g_locale_from_utf8(doc_list[idx].file_name, -1, NULL, NULL, NULL); + locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name); if (stat(locale_filename, &st) != 0) return FALSE; if (doc_list[idx].mtime > t || st.st_mtime > t) @@ -1836,7 +1836,7 @@ static void utils_recreate_recent_menu() void utils_recent_file_loaded(const gchar *filename) { - GList *item = + GList *item = g_queue_find_custom(app->recent_queue, filename, (GCompareFunc) strcmp); gchar *data;