From 738e33006b8987d806fe0686dfe4be52a319b7dc Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Tue, 18 Feb 2003 06:12:57 +0000 Subject: [PATCH] * util.c (list_append_unique): New function - add text to GList and remove duplicates. * main.c (directory_history_add): Use list_append_unique(). * widget.c (push_history): Likewise. --- src/ChangeLog | 5 +++++ src/main.c | 2 +- src/util.c | 19 +++++++++++++++++++ src/util.h | 1 + src/widget.c | 2 +- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 1717fefa8..b95f7764f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,10 @@ 2003-02-18 Pavel Roskin + * util.c (list_append_unique): New function - add text to GList + and remove duplicates. + * main.c (directory_history_add): Use list_append_unique(). + * widget.c (push_history): Likewise. + * panel.h: Convert directory history to GList. * widget.h: Convert input history to GList. Adjust all dependencies. diff --git a/src/main.c b/src/main.c index fc18e9012..ad68ba628 100644 --- a/src/main.c +++ b/src/main.c @@ -697,7 +697,7 @@ directory_history_add (struct WPanel *panel, char *s) text = g_strdup (s); strip_password (s, 1); - panel->dir_history = g_list_append (panel->dir_history, text); + panel->dir_history = list_append_unique (panel->dir_history, text); } /* diff --git a/src/util.c b/src/util.c index 35b6f9014..ff9c5c3fb 100644 --- a/src/util.c +++ b/src/util.c @@ -1163,6 +1163,25 @@ concat_dir_and_file (const char *dir, const char *file) return g_strconcat (dir, PATH_SEP_STR, file, NULL); } + +/* Append text to GList, remove all entries with the same text */ +GList * +list_append_unique (GList *list, char *text) +{ + GList *link, *newlink; + + link = g_list_first (list); + while (link) { + newlink = g_list_next (link); + if (!strcmp ((char *) link->data, text)) + list = g_list_remove_link (list, link); + link = newlink; + } + + return g_list_append (list, text); +} + + /* Following code heavily borrows from libiberty, mkstemps.c */ /* Number of attempts to create a temporary file */ diff --git a/src/util.h b/src/util.h index 0b53e7b0c..f22947ab5 100644 --- a/src/util.h +++ b/src/util.h @@ -125,6 +125,7 @@ void execute_hooks (Hook *hook_list); void delete_hook (Hook **hook_list, void (*hook_fn)(void *)); int hook_present (Hook *hook_list, void (*hook_fn)(void *)); +GList *list_append_unique (GList *list, char *text); /* Position saving and restoring */ diff --git a/src/widget.c b/src/widget.c index 845e2d08c..6690aea9a 100644 --- a/src/widget.c +++ b/src/widget.c @@ -1079,7 +1079,7 @@ push_history (WInput *in, char *text) strip_password (t, 1); } - in->history = g_list_append (in->history, t); + in->history = list_append_unique (in->history, t); in->need_push = 0; return 2;