comparison mcabber/mcabber/compl.c @ 1756:e2c084204583

Add (optional) suffix after nick completion in Multi-User Chats New option: 'completion_muc_suffix' Closes issue #20 in mcabber-crew BTS.
author Mikael Berthe <mikael@lilotux.net>
date Sat, 13 Mar 2010 13:18:07 +0100
parents e6e89b1d7831
children e6d355e50d7a
comparison
equal deleted inserted replaced
1755:84487d78d0ea 1756:e2c084204583
89 { 89 {
90 registered_cats &= ~id; 90 registered_cats &= ~id;
91 } 91 }
92 #endif 92 #endif
93 93
94 // new_completion(prefix, compl_cat) 94 // new_completion(prefix, compl_cat, suffix)
95 // . prefix = beginning of the word, typed by the user 95 // . prefix = beginning of the word, typed by the user
96 // . compl_cat = pointer to a completion category list (list of *char) 96 // . compl_cat = pointer to a completion category list (list of *char)
97 // . suffix = string to append to all completion possibilities (i.e. ":")
97 // Set the InputCompl pointer to an allocated compl structure. 98 // Set the InputCompl pointer to an allocated compl structure.
98 // done_completion() must be called when finished. 99 // done_completion() must be called when finished.
99 // Returns the number of possible completions. 100 // Returns the number of possible completions.
100 guint new_completion(char *prefix, GSList *compl_cat) 101 guint new_completion(const char *prefix, GSList *compl_cat, const gchar *suffix)
101 { 102 {
102 compl *c; 103 compl *c;
103 GSList *sl_cat; 104 GSList *sl_cat;
104 size_t len = strlen(prefix); 105 size_t len = strlen(prefix);
105 106
110 c = g_new0(compl, 1); 111 c = g_new0(compl, 1);
111 // Build the list of matches 112 // Build the list of matches
112 for (sl_cat = compl_cat; sl_cat; sl_cat = g_slist_next(sl_cat)) { 113 for (sl_cat = compl_cat; sl_cat; sl_cat = g_slist_next(sl_cat)) {
113 char *word = sl_cat->data; 114 char *word = sl_cat->data;
114 if (!strncasecmp(prefix, word, len)) { 115 if (!strncasecmp(prefix, word, len)) {
115 if (strlen(word) != len) 116 if (strlen(word) != len) {
116 c->list = g_slist_append(c->list, g_strdup(word+len)); // TODO sort 117 gchar *compval;
118 if (suffix)
119 compval = g_strdup_printf("%s%s", word+len, suffix);
120 else
121 compval = g_strdup(word+len);
122 c->list = g_slist_append(c->list, compval); // TODO sort
123 }
117 } 124 }
118 } 125 }
119 c->next = c->list; 126 c->next = c->list;
120 InputCompl = c; 127 InputCompl = c;
121 return g_slist_length(c->list); 128 return g_slist_length(c->list);
173 180
174 /* Categories functions */ 181 /* Categories functions */
175 182
176 // compl_add_category_word(categ, command) 183 // compl_add_category_word(categ, command)
177 // Adds a keyword as a possible completion in category categ. 184 // Adds a keyword as a possible completion in category categ.
178 void compl_add_category_word(guint categ, const char *word) 185 void compl_add_category_word(guint categ, const gchar *word)
179 { 186 {
180 GSList *sl_cat; 187 GSList *sl_cat;
181 category *cat; 188 category *cat;
182 char *nword; 189 char *nword;
183 // Look for category 190 // Look for category
206 cat->words = g_slist_append(cat->words, nword); // TODO sort 213 cat->words = g_slist_append(cat->words, nword); // TODO sort
207 } 214 }
208 215
209 // compl_del_category_word(categ, command) 216 // compl_del_category_word(categ, command)
210 // Removes a keyword from category categ in completion list. 217 // Removes a keyword from category categ in completion list.
211 void compl_del_category_word(guint categ, const char *word) 218 void compl_del_category_word(guint categ, const gchar *word)
212 { 219 {
213 GSList *sl_cat, *sl_elt; 220 GSList *sl_cat, *sl_elt;
214 category *cat; 221 category *cat;
215 char *nword; 222 char *nword;
216 // Look for category 223 // Look for category