From 0b133b6a79c872fa8ffe78dcff58e695acfdc1cb Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Fri, 9 Nov 2018 15:11:41 +0000 Subject: [PATCH] mutt_str_startswith - init.c --- init.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/init.c b/init.c index d33187e15..9f669b75a 100644 --- a/init.c +++ b/init.c @@ -1032,14 +1032,14 @@ static int parse_attachments(struct Buffer *buf, struct Buffer *s, op = '+'; category--; } - if (mutt_str_strncasecmp(category, "attachment", strlen(category)) == 0) + if (mutt_str_startswith("attachment", category, CASE_IGNORE)) { if (op == '+') head = &AttachAllow; else head = &AttachExclude; } - else if (mutt_str_strncasecmp(category, "inline", strlen(category)) == 0) + else if (mutt_str_startswith("inline", category, CASE_IGNORE)) { if (op == '+') head = &InlineAllow; @@ -1434,13 +1434,13 @@ static int parse_set(struct Buffer *buf, struct Buffer *s, unsigned long data, query = true; s->dptr++; } - else if (mutt_str_strncmp("no", s->dptr, 2) == 0) + else if (mutt_str_startswith(s->dptr, "no", CASE_MATCH)) { prefix = true; unset = !unset; s->dptr += 2; } - else if (mutt_str_strncmp("inv", s->dptr, 3) == 0) + else if (mutt_str_startswith(s->dptr, "inv", CASE_MATCH)) { prefix = true; inv = !inv; @@ -1467,7 +1467,7 @@ static int parse_set(struct Buffer *buf, struct Buffer *s, unsigned long data, bool equals = false; struct HashElem *he = NULL; - bool my = (mutt_str_strncmp("my_", buf->data, 3) == 0); + bool my = mutt_str_startswith(buf->data, "my_", CASE_MATCH); if (!my) { he = cs_get_elem(Config, buf->data); @@ -1764,7 +1764,6 @@ static int parse_setenv(struct Buffer *buf, struct Buffer *s, /* get variable name */ mutt_extract_token(buf, s, MUTT_TOKEN_EQUAL); - int len = strlen(buf->data); if (query) { @@ -1772,7 +1771,7 @@ static int parse_setenv(struct Buffer *buf, struct Buffer *s, while (envp && *envp) { /* This will display all matches for "^QUERY" */ - if (mutt_str_strncmp(buf->data, *envp, len) == 0) + if (mutt_str_startswith(*envp, buf->data, CASE_MATCH)) { if (!found) { @@ -2219,14 +2218,14 @@ static int parse_unattachments(struct Buffer *buf, struct Buffer *s, op = '+'; p--; } - if (mutt_str_strncasecmp(p, "attachment", strlen(p)) == 0) + if (mutt_str_startswith("attachment", p, CASE_IGNORE)) { if (op == '+') head = &AttachAllow; else head = &AttachExclude; } - else if (mutt_str_strncasecmp(p, "inline", strlen(p)) == 0) + else if (mutt_str_startswith("inline", p, CASE_IGNORE)) { if (op == '+') head = &InlineAllow; @@ -3295,20 +3294,20 @@ int mutt_command_complete(char *buf, size_t buflen, int pos, int numtabs) /* return the completed command */ strncpy(buf, Completed, buflen - spaces); } - else if ((mutt_str_strncmp(buf, "set", 3) == 0) || - (mutt_str_strncmp(buf, "unset", 5) == 0) || - (mutt_str_strncmp(buf, "reset", 5) == 0) || - (mutt_str_strncmp(buf, "toggle", 6) == 0)) + else if (mutt_str_startswith(buf, "set", CASE_MATCH) || + mutt_str_startswith(buf, "unset", CASE_MATCH) || + mutt_str_startswith(buf, "reset", CASE_MATCH) || + mutt_str_startswith(buf, "toggle", CASE_MATCH)) { /* complete variables */ static const char *const prefixes[] = { "no", "inv", "?", "&", 0 }; pt++; /* loop through all the possible prefixes (no, inv, ...) */ - if (mutt_str_strncmp(buf, "set", 3) == 0) + if (mutt_str_startswith(buf, "set", CASE_MATCH)) { for (num = 0; prefixes[num]; num++) { - if (mutt_str_strncmp(pt, prefixes[num], mutt_str_strlen(prefixes[num])) == 0) + if (mutt_str_startswith(pt, prefixes[num], CASE_MATCH)) { pt += mutt_str_strlen(prefixes[num]); break; @@ -3353,7 +3352,7 @@ int mutt_command_complete(char *buf, size_t buflen, int pos, int numtabs) strncpy(pt, Completed, buf + buflen - pt - spaces); } - else if (mutt_str_strncmp(buf, "exec", 4) == 0) + else if (mutt_str_startswith(buf, "exec", CASE_MATCH)) { const struct Binding *menu = km_get_table(CurrentMenu); @@ -3608,7 +3607,7 @@ int mutt_var_value_complete(char *buf, size_t buflen, int pos) if (*pt == '=') /* abort if no var before the '=' */ return 0; - if (mutt_str_strncmp(buf, "set", 3) == 0) + if (mutt_str_startswith(buf, "set", CASE_MATCH)) { const char *myvarval = NULL; char var[STRING]; -- 2.50.0