Mercurial > hg
changeset 284:f879b17ecb8e
Add compl_del_category_word()
This will allow us to remove an alias completion when it is unset.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Thu, 07 Jul 2005 22:12:29 +0100 |
parents | 00b2377539ac |
children | edc263a5d350 |
files | mcabber/src/compl.c mcabber/src/compl.h |
diffstat | 2 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mcabber/src/compl.c Wed Jul 06 22:29:17 2005 +0100 +++ b/mcabber/src/compl.c Thu Jul 07 22:12:29 2005 +0100 @@ -156,6 +156,45 @@ cat->words = g_slist_append(cat->words, nword); // TODO sort } +// compl_del_category_word(categ, command) +// Removes a keyword from category categ in completion list. +void compl_del_category_word(guint categ, const char *word) +{ + GSList *sl_cat, *sl_elt; + category *cat; + char *nword; + // Look for category + for (sl_cat=Categories; sl_cat; sl_cat = g_slist_next(sl_cat)) { + if (categ == ((category*)sl_cat->data)->flag) + break; + } + if (!sl_cat) return; // Category not found, finished! + + cat = (category*)sl_cat->data; + + // If word is not space-terminated, we add one trailing space + for (nword = (char*)word; *nword; nword++) + ; + if (nword > word) nword--; + if (*nword != ' ') { // Add a space + nword = g_new(char, strlen(word)+2); + strcpy(nword, word); + strcat(nword, " "); + } else { // word is fine + nword = g_strdup(word); + } + + sl_elt = cat->words; + while (sl_elt) { + if (!strcasecmp((char*)sl_elt->data, nword)) { + g_free(sl_elt->data); + cat->words = g_slist_delete_link(cat->words, sl_elt); + break; // Only remove first occurence + } + sl_elt = g_slist_next(sl_elt); + } +} + // compl_get_category_list() // Returns a slist of all words in the categories specified by the given flags GSList *compl_get_category_list(guint cat_flags)
--- a/mcabber/src/compl.h Wed Jul 06 22:29:17 2005 +0100 +++ b/mcabber/src/compl.h Thu Jul 07 22:12:29 2005 +0100 @@ -16,6 +16,7 @@ #define COMPL_MULTILINE (1<<11) void compl_add_category_word(guint, const char *command); +void compl_del_category_word(guint categ, const char *word); GSList *compl_get_category_list(guint cat_flags); void new_completion(char *prefix, GSList *compl_cat);