From 786ff643f5933939b8c5173155aa0ae5a3a00eba Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Thu, 25 Sep 2014 13:04:24 +0200 Subject: [PATCH] uprf: We don't have to implement it ourselves but can use strncasecmp() Also clarified what an ``unsigned prefix'' really is. I haven't changed all uses of uprf() in the code to strncasecmp(). This could be done. I'm not sure if it would enhance the clarity of the code. We don't need a prototype for strncasecmp(), because it's declared in strings.h. --- h/prototypes.h | 1 - sbr/uprf.c | 15 ++++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/h/prototypes.h b/h/prototypes.h index ed7f1ae..9b76d07 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -111,7 +111,6 @@ int vfgets(FILE *, char **); char *write_charset_8bit(void); int mh_strcasecmp(const char *s1, const char *s2); -int strncasecmp(const char *s1, const char *s2, size_t n); /* diff --git a/sbr/uprf.c b/sbr/uprf.c index f283a1b..f370b5c 100644 --- a/sbr/uprf.c +++ b/sbr/uprf.c @@ -1,5 +1,6 @@ /* ** uprf.c -- "unsigned" lexical prefix +** -- Check if `word' starts with `prefix', caseinsensitively. ** ** This code is Copyright (c) 2002, by the authors of nmh. See the ** COPYRIGHT file in the root directory of the nmh distribution for @@ -10,18 +11,10 @@ int -uprf(char *c1, char *c2) +uprf(char *word, char *prefix) { - int c; - - if (!(c1 && c2)) + if (!word || !prefix) { return 0; - - while ((c = *c2++)) { - if (tolower(c &= 0xff) != tolower(*c1 & 0xff)) - return 0; - else - c1++; } - return 1; + return (strncasecmp(word, prefix, strlen(prefix))==0) ? 1 : 0; } -- 1.7.10.4