From 4604c111d8e296ba9e06e89d51e4439d74d95b0c Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Tue, 16 Jul 2019 22:04:02 +0100 Subject: [PATCH] iwyu: tidy #includes --- config/address.c | 1 - config/dump.c | 1 - config/enum.c | 7 +-- config/regex.c | 121 +++++++++++++++++++++++------------------------ config/set.c | 1 - config/slist.c | 1 - config/subset.c | 5 +- config/subset.h | 6 ++- conn/conn_raw.c | 1 - conn/ssl.h | 2 + core/account.c | 1 - core/mailbox.c | 1 - core/mailbox.h | 1 - email/tags.c | 2 - 14 files changed, 69 insertions(+), 82 deletions(-) diff --git a/config/address.c b/config/address.c index 48416cbd4..99a117dfe 100644 --- a/config/address.c +++ b/config/address.c @@ -34,7 +34,6 @@ #include #include "mutt/mutt.h" #include "address/lib.h" -#include "email/lib.h" #include "address.h" #include "set.h" #include "types.h" diff --git a/config/dump.c b/config/dump.c index a128682e9..7484a7cd6 100644 --- a/config/dump.c +++ b/config/dump.c @@ -30,7 +30,6 @@ #include #include #include -#include #include "mutt/mutt.h" #include "dump.h" #include "set.h" diff --git a/config/enum.c b/config/enum.c index bd9a22d22..dc7489fcc 100644 --- a/config/enum.c +++ b/config/enum.c @@ -30,12 +30,7 @@ #include #include #include -#include "mutt/buffer.h" -#include "mutt/hash.h" -#include "mutt/logging.h" -#include "mutt/mapping.h" -#include "mutt/memory.h" -#include "mutt/string2.h" +#include "mutt/mutt.h" #include "enum.h" #include "set.h" #include "types.h" diff --git a/config/regex.c b/config/regex.c index 9b8ef045c..3751707c7 100644 --- a/config/regex.c +++ b/config/regex.c @@ -33,10 +33,25 @@ #include #include #include "mutt/mutt.h" -#include "regex2.h" #include "set.h" #include "types.h" +/** + * regex_free - Free a Regex object + * @param[out] r Regex to free + */ +void regex_free(struct Regex **r) +{ + if (!r || !*r) + return; + + FREE(&(*r)->pattern); + if ((*r)->regex) + regfree((*r)->regex); + FREE(&(*r)->regex); + FREE(r); +} + /** * regex_destroy - Destroy a Regex object - Implements ::cst_destroy() */ @@ -52,6 +67,50 @@ static void regex_destroy(const struct ConfigSet *cs, void *var, const struct Co regex_free(r); } +/** + * regex_new - Create an Regex from a string + * @param str Regular expression + * @param flags Type flags, e.g. #DT_REGEX_MATCH_CASE + * @param err Buffer for error messages + * @retval ptr New Regex object + * @retval NULL Error + */ +struct Regex *regex_new(const char *str, int flags, struct Buffer *err) +{ + if (!str) + return NULL; + + int rflags = 0; + struct Regex *reg = mutt_mem_calloc(1, sizeof(struct Regex)); + + reg->regex = mutt_mem_calloc(1, sizeof(regex_t)); + reg->pattern = mutt_str_strdup(str); + + /* Should we use smart case matching? */ + if (((flags & DT_REGEX_MATCH_CASE) == 0) && mutt_mb_is_lower(str)) + rflags |= REG_ICASE; + + if ((flags & DT_REGEX_NOSUB)) + rflags |= REG_NOSUB; + + /* Is a prefix of '!' allowed? */ + if (((flags & DT_REGEX_ALLOW_NOT) != 0) && (str[0] == '!')) + { + reg->pat_not = true; + str++; + } + + int rc = REG_COMP(reg->regex, str, rflags); + if ((rc != 0) && err) + { + regerror(rc, reg->regex, err->data, err->dsize); + regex_free(®); + return NULL; + } + + return reg; +} + /** * regex_string_set - Set a Regex by string - Implements ::cst_string_set() */ @@ -260,63 +319,3 @@ void regex_init(struct ConfigSet *cs) }; cs_register_type(cs, DT_REGEX, &cst_regex); } - -/** - * regex_new - Create an Regex from a string - * @param str Regular expression - * @param flags Type flags, e.g. #DT_REGEX_MATCH_CASE - * @param err Buffer for error messages - * @retval ptr New Regex object - * @retval NULL Error - */ -struct Regex *regex_new(const char *str, int flags, struct Buffer *err) -{ - if (!str) - return NULL; - - int rflags = 0; - struct Regex *reg = mutt_mem_calloc(1, sizeof(struct Regex)); - - reg->regex = mutt_mem_calloc(1, sizeof(regex_t)); - reg->pattern = mutt_str_strdup(str); - - /* Should we use smart case matching? */ - if (((flags & DT_REGEX_MATCH_CASE) == 0) && mutt_mb_is_lower(str)) - rflags |= REG_ICASE; - - if ((flags & DT_REGEX_NOSUB)) - rflags |= REG_NOSUB; - - /* Is a prefix of '!' allowed? */ - if (((flags & DT_REGEX_ALLOW_NOT) != 0) && (str[0] == '!')) - { - reg->pat_not = true; - str++; - } - - int rc = REG_COMP(reg->regex, str, rflags); - if ((rc != 0) && err) - { - regerror(rc, reg->regex, err->data, err->dsize); - regex_free(®); - return NULL; - } - - return reg; -} - -/** - * regex_free - Free a Regex object - * @param[out] r Regex to free - */ -void regex_free(struct Regex **r) -{ - if (!r || !*r) - return; - - FREE(&(*r)->pattern); - if ((*r)->regex) - regfree((*r)->regex); - FREE(&(*r)->regex); - FREE(r); -} diff --git a/config/set.c b/config/set.c index 24d236cce..bf02d7076 100644 --- a/config/set.c +++ b/config/set.c @@ -29,7 +29,6 @@ #include "config.h" #include #include -#include #include #include "mutt/mutt.h" #include "set.h" diff --git a/config/slist.c b/config/slist.c index 57ed006ea..bbaed753d 100644 --- a/config/slist.c +++ b/config/slist.c @@ -30,7 +30,6 @@ #include #include #include -#include #include "mutt/mutt.h" #include "set.h" #include "types.h" diff --git a/config/subset.c b/config/subset.c index 072e54c6c..716e51cd8 100644 --- a/config/subset.c +++ b/config/subset.c @@ -27,14 +27,13 @@ */ #include "config.h" -#include #include #include +#include #include "mutt/mutt.h" -#include "config/lib.h" #include "subset.h" +#include "dump.h" #include "set.h" -#include "types.h" /** * cs_subset_free - Free a Config Subset diff --git a/config/subset.h b/config/subset.h index 5a03adc4c..b7f728ee8 100644 --- a/config/subset.h +++ b/config/subset.h @@ -23,8 +23,10 @@ #ifndef MUTT_CONFIG_SUBSET_H #define MUTT_CONFIG_SUBSET_H -#include -#include "set.h" +#include + +struct Buffer; +struct HashElem; /** * struct ConfigSubset - A set of inherited config items diff --git a/conn/conn_raw.c b/conn/conn_raw.c index 9f3ebf228..05301e46f 100644 --- a/conn/conn_raw.c +++ b/conn/conn_raw.c @@ -45,7 +45,6 @@ #include #include "mutt/mutt.h" #include "address/lib.h" -#include "email/lib.h" #include "conn/connaccount.h" #include "conn_globals.h" #include "connection.h" diff --git a/conn/ssl.h b/conn/ssl.h index 43341cf8a..4a43c5369 100644 --- a/conn/ssl.h +++ b/conn/ssl.h @@ -23,6 +23,8 @@ #ifndef MUTT_CONN_SSL_H #define MUTT_CONN_SSL_H +#include "config.h" + struct Connection; #ifdef USE_SSL diff --git a/core/account.c b/core/account.c index e1dc7e7de..5e34556ec 100644 --- a/core/account.c +++ b/core/account.c @@ -32,7 +32,6 @@ #include "config/lib.h" #include "account.h" #include "mailbox.h" -#include "neomutt.h" /** * account_new - Create a new Account diff --git a/core/mailbox.c b/core/mailbox.c index 07edf6fd0..297b3880f 100644 --- a/core/mailbox.c +++ b/core/mailbox.c @@ -30,7 +30,6 @@ #include "config.h" #include -#include "config/lib.h" #include "email/lib.h" #include "mailbox.h" #include "neomutt.h" diff --git a/core/mailbox.h b/core/mailbox.h index 54675c768..bb1e75cf9 100644 --- a/core/mailbox.h +++ b/core/mailbox.h @@ -31,7 +31,6 @@ #include #include "mutt/mutt.h" -struct ConfigSubset; struct Email; #define MB_NORMAL 0 diff --git a/email/tags.c b/email/tags.c index a7ed1aad9..b6c5989ea 100644 --- a/email/tags.c +++ b/email/tags.c @@ -29,9 +29,7 @@ #include "config.h" #include #include -#include #include "mutt/mutt.h" -#include "config/lib.h" #include "tags.h" /* These Config Variables are only used in email/tags.c */ -- 2.40.0