comparison mcabber/src/compl.c @ 1228:9a68fe4515dc

Improve MUC nickname completion
author Mikael Berthe <mikael@lilotux.net>
date Sun, 20 May 2007 22:01:20 +0200
parents 2de8f8ba1f34
children a54645448e00
comparison
equal deleted inserted replaced
1227:79c396678f1b 1228:9a68fe4515dc
55 // new_completion(prefix, compl_cat) 55 // new_completion(prefix, compl_cat)
56 // . prefix = beginning of the word, typed by the user 56 // . prefix = beginning of the word, typed by the user
57 // . compl_cat = pointer to a completion category list (list of *char) 57 // . compl_cat = pointer to a completion category list (list of *char)
58 // Set the InputCompl pointer to an allocated compl structure. 58 // Set the InputCompl pointer to an allocated compl structure.
59 // done_completion() must be called when finished. 59 // done_completion() must be called when finished.
60 void new_completion(char *prefix, GSList *compl_cat) 60 // Returns the number of possible completions.
61 guint new_completion(char *prefix, GSList *compl_cat)
61 { 62 {
62 compl *c; 63 compl *c;
63 GSList *sl_cat; 64 GSList *sl_cat;
64 size_t len = strlen(prefix); 65 size_t len = strlen(prefix);
65 66
67 cancel_completion(); 68 cancel_completion();
68 } 69 }
69 70
70 c = g_new0(compl, 1); 71 c = g_new0(compl, 1);
71 // Build the list of matches 72 // Build the list of matches
72 for (sl_cat=compl_cat; sl_cat; sl_cat = g_slist_next(sl_cat)) { 73 for (sl_cat = compl_cat; sl_cat; sl_cat = g_slist_next(sl_cat)) {
73 char *word = sl_cat->data; 74 char *word = sl_cat->data;
74 if (!strncasecmp(prefix, word, len)) { 75 if (!strncasecmp(prefix, word, len)) {
75 if (strlen(word) != len) 76 if (strlen(word) != len)
76 c->list = g_slist_append(c->list, g_strdup(word+len)); // TODO sort 77 c->list = g_slist_append(c->list, g_strdup(word+len)); // TODO sort
77 } 78 }
78 } 79 }
79 c->next = c->list; 80 c->next = c->list;
80 InputCompl = c; 81 InputCompl = c;
82 return g_slist_length(c->list);
81 } 83 }
82 84
83 // done_completion(); 85 // done_completion();
84 void done_completion(void) 86 void done_completion(void)
85 { 87 {