* 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.
This commit is contained in:
Pavel Roskin 2003-02-18 06:12:57 +00:00
parent 89e5cc319e
commit 738e33006b
5 changed files with 27 additions and 2 deletions

View File

@ -1,5 +1,10 @@
2003-02-18 Pavel Roskin <proski@gnu.org> 2003-02-18 Pavel Roskin <proski@gnu.org>
* 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. * panel.h: Convert directory history to GList.
* widget.h: Convert input history to GList. * widget.h: Convert input history to GList.
Adjust all dependencies. Adjust all dependencies.

View File

@ -697,7 +697,7 @@ directory_history_add (struct WPanel *panel, char *s)
text = g_strdup (s); text = g_strdup (s);
strip_password (s, 1); strip_password (s, 1);
panel->dir_history = g_list_append (panel->dir_history, text); panel->dir_history = list_append_unique (panel->dir_history, text);
} }
/* /*

View File

@ -1163,6 +1163,25 @@ concat_dir_and_file (const char *dir, const char *file)
return g_strconcat (dir, PATH_SEP_STR, file, NULL); 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 */ /* Following code heavily borrows from libiberty, mkstemps.c */
/* Number of attempts to create a temporary file */ /* Number of attempts to create a temporary file */

View File

@ -125,6 +125,7 @@ void execute_hooks (Hook *hook_list);
void delete_hook (Hook **hook_list, void (*hook_fn)(void *)); void delete_hook (Hook **hook_list, void (*hook_fn)(void *));
int hook_present (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 */ /* Position saving and restoring */

View File

@ -1079,7 +1079,7 @@ push_history (WInput *in, char *text)
strip_password (t, 1); strip_password (t, 1);
} }
in->history = g_list_append (in->history, t); in->history = list_append_unique (in->history, t);
in->need_push = 0; in->need_push = 0;
return 2; return 2;