degesch: clean up complete_nicknames()

Using new irc_server_strncmp() instead of fnmatch().
This commit is contained in:
Přemysl Eric Janouch 2015-06-02 21:03:10 +02:00
parent 00a8b6616f
commit a6782e5e60
1 changed files with 15 additions and 7 deletions

View File

@ -3656,6 +3656,16 @@ irc_server_strcmp (struct server *s, const char *a, const char *b)
return 0;
}
static int
irc_server_strncmp (struct server *s, const char *a, const char *b, size_t n)
{
int x;
while (n-- && (*a || *b))
if ((x = s->irc_tolower (*a++) - s->irc_tolower (*b++)))
return x;
return 0;
}
static char *
irc_cut_nickname (const char *prefix)
{
@ -6419,22 +6429,20 @@ static void
complete_nicknames (struct app_context *ctx, struct completion *data,
const char *word, struct str_vector *output)
{
if (ctx->current_buffer->type != BUFFER_CHANNEL)
struct buffer *buffer = ctx->current_buffer;
if (buffer->type != BUFFER_CHANNEL)
return;
struct channel *channel = ctx->current_buffer->channel;
// XXX: this is a bit hackish and doesn't respect server case mapping
char *mask = xstrdup_printf ("%s*", word);
LIST_FOR_EACH (struct channel_user, iter, channel->users)
size_t word_len = strlen (word);
LIST_FOR_EACH (struct channel_user, iter, buffer->channel->users)
{
const char *nickname = iter->user->nickname;
if (fnmatch (mask, nickname, 0))
if (irc_server_strncmp (buffer->server, word, nickname, word_len))
continue;
str_vector_add_owned (output, data->location == 0
? xstrdup_printf ("%s:", nickname)
: xstrdup (nickname));
}
free (mask);
}
static char **