comparison mcabber/mcabber/compl.c @ 1926:c1f9a4d47e05

Add option 'completion_ignore_case' By default completion is now case sensitive. (Partially fixes issue #48)
author Mikael Berthe <mikael@lilotux.net>
date Thu, 11 Nov 2010 14:13:16 +0100
parents 924f4552996c
children dac609275117
comparison
equal deleted inserted replaced
1925:3655f52687f0 1926:c1f9a4d47e05
34 34
35 #include "compl.h" 35 #include "compl.h"
36 #include "utf8.h" 36 #include "utf8.h"
37 #include "roster.h" 37 #include "roster.h"
38 #include "events.h" 38 #include "events.h"
39 #include "settings.h"
39 #include "logprint.h" 40 #include "logprint.h"
40 41
41 // Completion structure 42 // Completion structure
42 typedef struct { 43 typedef struct {
43 GSList *list; // list of matches 44 GSList *list; // list of matches
133 // Returns the number of possible completions. 134 // Returns the number of possible completions.
134 guint new_completion(const char *prefix, GSList *compl_cat, const gchar *suffix) 135 guint new_completion(const char *prefix, GSList *compl_cat, const gchar *suffix)
135 { 136 {
136 compl *c; 137 compl *c;
137 GSList *sl_cat; 138 GSList *sl_cat;
139 gint (*cmp)(const char *s1, const char *s2, size_t n);
138 size_t len = strlen(prefix); 140 size_t len = strlen(prefix);
139 141
140 if (InputCompl) { // This should not happen, but hey... 142 if (InputCompl) { // This should not happen, but hey...
141 cancel_completion(); 143 cancel_completion();
142 } 144 }
145
146 if (settings_opt_get_int("completion_ignore_case"))
147 cmp = &strncasecmp;
148 else
149 cmp = &strncmp;
143 150
144 c = g_new0(compl, 1); 151 c = g_new0(compl, 1);
145 // Build the list of matches 152 // Build the list of matches
146 for (sl_cat = compl_cat; sl_cat; sl_cat = g_slist_next(sl_cat)) { 153 for (sl_cat = compl_cat; sl_cat; sl_cat = g_slist_next(sl_cat)) {
147 char *word = sl_cat->data; 154 char *word = sl_cat->data;
148 if (!strncasecmp(prefix, word, len)) { 155 if (!cmp(prefix, word, len)) {
149 if (strlen(word) != len) { 156 if (strlen(word) != len) {
150 gchar *compval; 157 gchar *compval;
151 if (suffix) 158 if (suffix)
152 compval = g_strdup_printf("%s%s", word+len, suffix); 159 compval = g_strdup_printf("%s%s", word+len, suffix);
153 else 160 else