From a6782e5e60427d32ef8aecc5179c5b34fc5dcbb5 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Tue, 2 Jun 2015 21:03:10 +0200
Subject: degesch: clean up complete_nicknames()
Using new irc_server_strncmp() instead of fnmatch().
---
degesch.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/degesch.c b/degesch.c
index 23d5124..bb54c03 100644
--- a/degesch.c
+++ b/degesch.c
@@ -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 **
--
cgit v1.2.3-70-g09d2