From 897bb00af12ac069a8c1fc717ee40e9333329b48 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Tue, 2 Jun 2015 21:28:41 +0200 Subject: degesch: add & use strncasecmp_ascii() --- common.c | 11 +++++++++++ degesch.c | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/common.c b/common.c index ce9e80f..52e737a 100644 --- a/common.c +++ b/common.c @@ -70,6 +70,17 @@ str_vector_find (const struct str_vector *v, const char *s) return -1; } +static int +strncasecmp_ascii (const char *a, const char *b, size_t n) +{ + int x; + while (n-- && (*a || *b)) + if ((x = tolower_ascii (*(const unsigned char *) a++) + - tolower_ascii (*(const unsigned char *) b++))) + return x; + return 0; +} + // --- Logging ----------------------------------------------------------------- static void diff --git a/degesch.c b/degesch.c index bb54c03..6ebb350 100644 --- a/degesch.c +++ b/degesch.c @@ -6388,11 +6388,11 @@ complete_command (struct app_context *ctx, struct completion *data, prefix = "/"; } + size_t word_len = strlen (word); for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++) { struct command_handler *handler = &g_command_handlers[i]; - // FIXME: we want an ASCII version - if (!strncasecmp (word, handler->name, strlen (word))) + if (!strncasecmp_ascii (word, handler->name, word_len)) str_vector_add_owned (output, xstrdup_printf ("%s%s", prefix, handler->name)); } -- cgit v1.2.3-70-g09d2