[gtk/wip/baedert/for-master: 21/29] Remove gtkutils{.c,private.h}



commit 64e613f9ba466a9528abdb0ae1f353f4835fcdda
Author: Timm Bäder <mail baedert org>
Date:   Sat Jan 25 15:40:53 2020 +0100

    Remove gtkutils{.c,private.h}
    
    All but one functions are unused. Move the remaining one into
    gtkmodules.c, its only caller.

 gtk/gtkimmodule.c     |   1 -
 gtk/gtkmodules.c      |  76 +++++++++++++-
 gtk/gtkutils.c        | 268 --------------------------------------------------
 gtk/gtkutilsprivate.h |  19 ----
 gtk/meson.build       |   1 -
 5 files changed, 74 insertions(+), 291 deletions(-)
---
diff --git a/gtk/gtkimmodule.c b/gtk/gtkimmodule.c
index 2f4127faa7..3181ee26b7 100644
--- a/gtk/gtkimmodule.c
+++ b/gtk/gtkimmodule.c
@@ -37,7 +37,6 @@
 #include "gtkmodulesprivate.h"
 #include "gtksettings.h"
 #include "gtkprivate.h"
-#include "gtkutilsprivate.h"
 #include "gtkintl.h"
 
 #ifdef GDK_WINDOWING_X11
diff --git a/gtk/gtkmodules.c b/gtk/gtkmodules.c
index 88e74245e0..e3f057c125 100644
--- a/gtk/gtkmodules.c
+++ b/gtk/gtkmodules.c
@@ -25,10 +25,82 @@
 #include "gtkprivate.h"
 #include "gtkmodulesprivate.h"
 #include "gtkintl.h"
-#include "gtkutilsprivate.h"
 
 #include <gmodule.h>
 
+static 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);
+}
+
+static char **
+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;
+}
+
 static gchar **
 get_module_path (void)
 {
@@ -58,7 +130,7 @@ get_module_path (void)
 
   g_free (default_dir);
 
-  result = gtk_split_file_list (module_path);
+  result = split_file_list (module_path);
   g_free (module_path);
 
   return result;
diff --git a/gtk/meson.build b/gtk/meson.build
index 000bbb0dcd..374d0128c7 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -391,7 +391,6 @@ gtk_public_sources = files([
   'gtktreestore.c',
   'gtktreeview.c',
   'gtktreeviewcolumn.c',
-  'gtkutils.c',
   'gtkvideo.c',
   'gtkviewport.c',
   'gtkvolumebutton.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]