degesch: add & use strncasecmp_ascii()

This commit is contained in:
Přemysl Eric Janouch 2015-06-02 21:28:41 +02:00
parent a6782e5e60
commit 897bb00af1
2 changed files with 13 additions and 2 deletions

View File

@ -70,6 +70,17 @@ str_vector_find (const struct str_vector *v, const char *s)
return -1; 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 ----------------------------------------------------------------- // --- Logging -----------------------------------------------------------------
static void static void

View File

@ -6388,11 +6388,11 @@ complete_command (struct app_context *ctx, struct completion *data,
prefix = "/"; prefix = "/";
} }
size_t word_len = strlen (word);
for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++) for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++)
{ {
struct command_handler *handler = &g_command_handlers[i]; struct command_handler *handler = &g_command_handlers[i];
// FIXME: we want an ASCII version if (!strncasecmp_ascii (word, handler->name, word_len))
if (!strncasecmp (word, handler->name, strlen (word)))
str_vector_add_owned (output, str_vector_add_owned (output,
xstrdup_printf ("%s%s", prefix, handler->name)); xstrdup_printf ("%s%s", prefix, handler->name));
} }