Author: jannis Date: 2008-06-29 16:51:33 +0000 (Sun, 29 Jun 2008) New Revision: 27182
Modified: libxfce4util/trunk/ChangeLog libxfce4util/trunk/INSTALL libxfce4util/trunk/libxfce4util/xfce-resource.c Log: * libxfce4util/xfce-resource.c: Add _res_remove_trailing_slashes(). It is used to support _res_remove_duplicates() in finding paths which appear multiple times but in fact refer to the same directory (like e.g. /usr/share/// and /usr/share). Use g_build_path() in g_resource_lookup() and g_resource_lookup_all() instead of concatenating with "%s/%s". Modified: libxfce4util/trunk/ChangeLog =================================================================== --- libxfce4util/trunk/ChangeLog 2008-06-29 12:31:40 UTC (rev 27181) +++ libxfce4util/trunk/ChangeLog 2008-06-29 16:51:33 UTC (rev 27182) @@ -1,3 +1,12 @@ +2008-06-29 Jannis Pohlmann <[EMAIL PROTECTED]> + + * libxfce4util/xfce-resource.c: Add _res_remove_trailing_slashes(). + It is used to support _res_remove_duplicates() in finding paths + which appear multiple times but in fact refer to the same + directory (like e.g. /usr/share/// and /usr/share). Use + g_build_path() in g_resource_lookup() and g_resource_lookup_all() + instead of concatenating with "%s/%s". + 2007-12-17 Brian Tarricone <[EMAIL PROTECTED]> * Fix docs/ stuff to include new signal handling functionality. Modified: libxfce4util/trunk/INSTALL =================================================================== --- libxfce4util/trunk/INSTALL 2008-06-29 12:31:40 UTC (rev 27181) +++ libxfce4util/trunk/INSTALL 2008-06-29 16:51:33 UTC (rev 27182) @@ -2,7 +2,7 @@ ************************* Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, -2006 Free Software Foundation, Inc. +2006, 2007 Free Software Foundation, Inc. This file is free documentation; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. @@ -67,6 +67,9 @@ all sorts of other programs in order to regenerate files that came with the distribution. + 6. Often, you can also type `make uninstall' to remove the installed + files again. + Compilers and Options ===================== Modified: libxfce4util/trunk/libxfce4util/xfce-resource.c =================================================================== --- libxfce4util/trunk/libxfce4util/xfce-resource.c 2008-06-29 12:31:40 UTC (rev 27181) +++ libxfce4util/trunk/libxfce4util/xfce-resource.c 2008-06-29 16:51:33 UTC (rev 27182) @@ -124,6 +124,43 @@ +static GList* +_res_remove_trailing_slashes (GList *list) +{ + GList *ll = NULL; + GList *lp; + const gchar *path; + gint len; + + for (lp = list; lp != NULL; lp = lp->next) + { + path = (const gchar *) lp->data; + len = strlen (path); + + while (len > 0 && G_IS_DIR_SEPARATOR (path[len-1])) + --len; + + if (len <= 0) + { + /* A string with slashes only => root directory */ + ll = g_list_append (ll, g_strdup ("/")); + g_free (lp->data); + } + else if (len < strlen (path)) + { + ll = g_list_append (ll, g_strndup (path, len)); + g_free (lp->data); + } + else + ll = g_list_append (ll, lp->data); + } + + g_list_free (list); + return ll; +} + + + static void _res_init (void) { @@ -222,6 +259,15 @@ _list[XFCE_RESOURCE_THEMES] = g_list_append (_list[XFCE_RESOURCE_THEMES], path); } + /* Remove trailing slashes */ +#define REMOVE_TRAILING_SLASHES(type) { _list[(type)] = _res_remove_trailing_slashes (_list[(type)]); } + REMOVE_TRAILING_SLASHES (XFCE_RESOURCE_DATA); + REMOVE_TRAILING_SLASHES (XFCE_RESOURCE_CONFIG); + REMOVE_TRAILING_SLASHES (XFCE_RESOURCE_CACHE); + REMOVE_TRAILING_SLASHES (XFCE_RESOURCE_ICONS); + REMOVE_TRAILING_SLASHES (XFCE_RESOURCE_THEMES); +#undef REMOVE_TRAILING_SLASHES + /* remove duplicates from the lists */ #define REMOVE_DUPLICATES(type) { _list[(type)] = _res_remove_duplicates (_list[(type)]); } REMOVE_DUPLICATES (XFCE_RESOURCE_DATA); @@ -425,7 +471,7 @@ const gchar *filename) { GFileTest test; - gchar path[PATH_MAX]; + gchar *path; GList *l; g_return_val_if_fail (TYPE_VALID (type), NULL); @@ -440,10 +486,13 @@ for (l = _list[type]; l != NULL; l = l->next) { - g_snprintf (path, PATH_MAX, "%s/%s", (const gchar *) l->data, filename); + path = g_build_path (G_DIR_SEPARATOR_S, (const gchar *) l->data, filename, NULL); + if (g_file_test (path, test)) - return g_strdup (path); + return path; + else + g_free (path); } return NULL; @@ -473,7 +522,7 @@ const gchar *filename) { GFileTest test; - gchar path[PATH_MAX]; + gchar *path; gchar **paths; guint size; guint pos; @@ -495,7 +544,7 @@ for (l = _list[type]; l != NULL; l = l->next) { - g_snprintf (path, PATH_MAX, "%s/%s", (const gchar *) l->data, filename); + path = g_build_path (G_DIR_SEPARATOR_S, (const gchar *) l->data, filename, NULL); if (g_file_test (path, test)) { @@ -505,9 +554,11 @@ paths = g_realloc (paths, (size + 1) * sizeof (*paths)); } - paths[pos] = g_strdup (path); + paths[pos] = path; ++pos; } + else + g_free (path); } paths[pos] = NULL; _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits