[gtk+] Stop using pango_split_file_list
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Stop using pango_split_file_list
- Date: Sat, 26 Mar 2016 22:19:53 +0000 (UTC)
commit 8d874cf0f8e404d22e936afd8713f1ec7b3dab15
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Mar 26 18:18:50 2016 -0400
Stop using pango_split_file_list
Add a copy of this deprecated utility in gtkutils.c and use
it instead of the pango API.
gtk/Makefile.am | 2 +-
gtk/gtkmodules.c | 11 +++-----
gtk/gtkutils.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkutilsprivate.h | 2 +
gtk/queryimmodules.c | 5 +--
5 files changed, 82 insertions(+), 11 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 25729d0..0e92feb 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1511,7 +1511,7 @@ bin_PROGRAMS = \
gtk-query-settings \
gtk-launch
-gtk_query_immodules_3_0_SOURCES = queryimmodules.c
+gtk_query_immodules_3_0_SOURCES = queryimmodules.c gtkutils.c
gtk_query_immodules_3_0_LDADD = \
libgtk-3.la \
$(top_builddir)/gdk/libgdk-3.la \
diff --git a/gtk/gtkmodules.c b/gtk/gtkmodules.c
index ace1d10..0aaedae 100644
--- a/gtk/gtkmodules.c
+++ b/gtk/gtkmodules.c
@@ -26,6 +26,7 @@
#include "gtkprivate.h"
#include "gtkmodulesprivate.h"
#include "gtkintl.h"
+#include "gtkutilsprivate.h"
#include <gmodule.h>
@@ -77,9 +78,7 @@ get_module_path (void)
g_free (default_dir);
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- result = pango_split_file_list (module_path);
-G_GNUC_END_IGNORE_DEPRECATIONS
+ result = gtk_split_file_list (module_path);
g_free (module_path);
return result;
@@ -419,10 +418,8 @@ load_modules (const char *module_str)
GTK_NOTE (MODULES, g_message ("Loading module list: %s", module_str));
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- module_names = pango_split_file_list (module_str);
-G_GNUC_END_IGNORE_DEPRECATIONS
- for (i = 0; module_names[i]; i++)
+ module_names = gtk_split_file_list (module_str);
+ for (i = 0; module_names[i]; i++)
module_list = load_module (module_list, module_names[i]);
module_list = g_slist_reverse (module_list);
diff --git a/gtk/gtkutils.c b/gtk/gtkutils.c
index a6818b2..69c4ccb 100644
--- a/gtk/gtkutils.c
+++ b/gtk/gtkutils.c
@@ -191,3 +191,76 @@ gtk_read_line (FILE *stream, GString *str)
return (n_read > 0) ? lines : 0;
}
+
+char *
+gtk_trim_string (const char *str)
+{
+ int len;
+
+ g_return_val_if_fail (str != NULL, NULL);
+
+ while (*str && g_ascii_isspace (*str))
+ str++;
+
+ len = strlen (str);
+ while (len > 0 && g_ascii_isspace (str[len - 1]))
+ len--;
+
+ return g_strndup (str, len);
+}
+
+char **
+gtk_split_file_list (const char *str)
+{
+ int i = 0;
+ int j;
+ char **files;
+
+ files = g_strsplit (str, G_SEARCHPATH_SEPARATOR_S, -1);
+
+ while (files[i])
+ {
+ char *file = gtk_trim_string (files[i]);
+
+ /* If the resulting file is empty, skip it */
+ if (file[0] == '\0')
+ {
+ g_free (file);
+ g_free (files[i]);
+
+ for (j = i + 1; files[j]; j++)
+ files[j - 1] = files[j];
+
+ files[j - 1] = NULL;
+
+ continue;
+ }
+
+#ifndef G_OS_WIN32
+ /* '~' is a quite normal and common character in file names on
+ * Windows, especially in the 8.3 versions of long file names, which
+ * still occur now and then. Also, few Windows user are aware of the
+ * Unix shell convention that '~' stands for the home directory,
+ * even if they happen to have a home directory.
+ */
+ if (file[0] == '~' && file[1] == G_DIR_SEPARATOR)
+ {
+ char *tmp = g_strconcat (g_get_home_dir(), file + 1, NULL);
+ g_free (file);
+ file = tmp;
+ }
+ else if (file[0] == '~' && file[1] == '\0')
+ {
+ g_free (file);
+ file = g_strdup (g_get_home_dir ());
+ }
+#endif
+
+ g_free (files[i]);
+ files[i] = file;
+
+ i++;
+ }
+
+ return files;
+}
diff --git a/gtk/gtkutilsprivate.h b/gtk/gtkutilsprivate.h
index e5d34bb..a498c74 100644
--- a/gtk/gtkutilsprivate.h
+++ b/gtk/gtkutilsprivate.h
@@ -10,6 +10,8 @@ gboolean gtk_scan_string (const char **pos,
gboolean gtk_skip_space (const char **pos);
gint gtk_read_line (FILE *stream,
GString *str);
+char * gtk_trim_string (const char *str);
+char ** gtk_split_file_list (const char *str);
G_END_DECLS
diff --git a/gtk/queryimmodules.c b/gtk/queryimmodules.c
index 83052e8..e9978fd 100644
--- a/gtk/queryimmodules.c
+++ b/gtk/queryimmodules.c
@@ -36,6 +36,7 @@
#include "gtk/gtkimcontextinfo.h"
#include "gtk/gtkversion.h"
+#include "gtk/gtkutilsprivate.h"
#include "gtk/deprecated/gtkrc.h"
@@ -189,9 +190,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
g_string_append_printf (contents, "# ModulesPath = %s\n#\n", path);
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- dirs = pango_split_file_list (path);
-G_GNUC_END_IGNORE_DEPRECATIONS
+ dirs = gtk_split_file_list (path);
dirs_done = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
for (i = 0; dirs[i]; i++)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]