37
37
#include "toolbox.h"
39
/* gm_mkdir_with_parents taken more or less 1:1 from glib 2.8 */
41
gm_mkdir_with_parents (const gchar *pathname,
42
*gm_string_gslist_remove_dups (GSList *origlist)
49
fn = g_strdup (pathname);
51
if (g_path_is_absolute (fn))
52
p = (gchar *) g_path_skip_root (fn);
53
/* p is now a pointer INSIDE the memory of fn, not a new string, see GLib doc
54
* for g_path_skip_root()
59
/* the following loop means for fn="/dir1/dir2/dir3" per iteration:
62
* fn == "/dir1/dir2/dir3"
64
* This is done by setting the terminating \0 at the position of
65
* every found dir separator per iteration.
68
/* increase p, until we reach the first dir separator */
69
while (*p && !G_IS_DIR_SEPARATOR (*p))
73
/* did we reach the end? */
76
/* this has the effect to give fn a new \0 at
77
* the dir separator for termination */
80
if (!g_file_test (fn, G_FILE_TEST_EXISTS)) {
81
if (g_mkdir (fn, mode) == -1) {
87
else if (!g_file_test (fn, G_FILE_TEST_IS_DIR)) {
93
/* restore the dir separator and search the next one */
94
*p++ = G_DIR_SEPARATOR;
95
while (*p && G_IS_DIR_SEPARATOR (*p))
100
/* we only need to free fn here, as p doesn't point to extra
101
* allocated memory, it points "inside" fn
44
/* from a GSList* of gchar*, remove all dup strings
45
* (C) Jan Schampera <jan.schampera@web.de> */
46
GSList *origlist_iter = NULL;
47
GSList *seenlist = NULL;
48
GSList *seenlist_iter = NULL;
49
gboolean seen = FALSE;
51
/* iterate through the original list and compare every stored gchar* to
52
* our "seen list", if not there, append it */
53
if (!origlist) return NULL;
55
for (origlist_iter = origlist;
56
origlist_iter != NULL;
57
origlist_iter = g_slist_next (origlist_iter))
59
if (origlist_iter->data)
62
/* check if the string is already in the "seen list" */
63
for (seenlist_iter = seenlist;
64
seenlist_iter != NULL;
65
seenlist_iter = g_slist_next (seenlist_iter))
67
if (seenlist_iter->data &&
68
!strcmp ((const char*) origlist_iter->data,
69
(const char*) seenlist_iter->data))
76
/* not in list? append it... */
77
seenlist = g_slist_append (seenlist,
79
((const gchar*) origlist_iter->data));
84
/* free the memory of the original list */
85
g_slist_foreach (origlist, (GFunc) g_free, NULL);
86
g_slist_free (origlist);