From: Richard Russon Date: Tue, 26 Feb 2019 23:31:02 +0000 (+0000) Subject: add typedef for HookFlags X-Git-Tag: 2019-10-25~347^2~16 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2f4b0c92bd03725a2df2a14df6be5aad60300df9;p=neomutt add typedef for HookFlags --- diff --git a/compress.c b/compress.c index 58adffafc..2b95b59f1 100644 --- a/compress.c +++ b/compress.c @@ -172,7 +172,7 @@ static void store_size(const struct Mailbox *m) /** * find_hook - Find a hook to match a path - * @param type Type of hook, e.g. #MUTT_CLOSE_HOOK + * @param type Type of hook, see #HookFlags * @param path Filename to test * @retval ptr Matching hook command * @retval NULL No matches @@ -186,7 +186,7 @@ static void store_size(const struct Mailbox *m) * Call: * find_hook (#MUTT_OPEN_HOOK, "myfile.gz"); */ -static const char *find_hook(int type, const char *path) +static const char *find_hook(HookFlags type, const char *path) { if (!path) return NULL; diff --git a/hook.c b/hook.c index 493415920..231eed410 100644 --- a/hook.c +++ b/hook.c @@ -63,7 +63,7 @@ bool C_SaveName; ///< Config: Save outgoing message to mailbox of recipient's na */ struct Hook { - int type; ///< Hook type + HookFlags type; ///< Hook type struct Regex regex; ///< Regular expression char *command; ///< Filename, command or pattern to execute struct Pattern *pattern; ///< Used for fcc,save,send-hook @@ -71,7 +71,7 @@ struct Hook }; static TAILQ_HEAD(, Hook) Hooks = TAILQ_HEAD_INITIALIZER(Hooks); -static int current_hook_type = 0; +static HookFlags current_hook_type = MUTT_HOOK_NO_FLAGS; /** * mutt_parse_hook - Parse the 'hook' family of commands - Implements ::command_t @@ -303,11 +303,11 @@ static void delete_hook(struct Hook *h) /** * mutt_delete_hooks - Delete matching hooks - * @param type Hook type to delete, e.g. #MUTT_SEND_HOOK + * @param type Hook type to delete, see #HookFlags * * If 0 is passed, all the hooks will be deleted. */ -void mutt_delete_hooks(int type) +void mutt_delete_hooks(HookFlags type) { struct Hook *h = NULL; struct Hook *tmp = NULL; @@ -412,13 +412,13 @@ void mutt_folder_hook(const char *path, const char *desc) /** * mutt_find_hook - Find a matching hook - * @param type Type, e.g. #MUTT_FOLDER_HOOK + * @param type Hook type, see #HookFlags * @param pat Pattern to match * @retval ptr Command string * * @note The returned string must not be freed. */ -char *mutt_find_hook(int type, const char *pat) +char *mutt_find_hook(HookFlags type, const char *pat) { struct Hook *tmp = NULL; @@ -437,9 +437,9 @@ char *mutt_find_hook(int type, const char *pat) * mutt_message_hook - Perform a message hook * @param m Mailbox Context * @param e Email - * @param type Hook type, e.g. #MUTT_MESSAGE_HOOK + * @param type Hook type, see #HookFlags */ -void mutt_message_hook(struct Mailbox *m, struct Email *e, int type) +void mutt_message_hook(struct Mailbox *m, struct Email *e, HookFlags type) { struct Buffer err, token; struct Hook *hook = NULL; @@ -485,14 +485,14 @@ void mutt_message_hook(struct Mailbox *m, struct Email *e, int type) * addr_hook - Perform an address hook (get a path) * @param path Buffer for path * @param pathlen Length of buffer - * @param type Type e.g. #MUTT_FCC_HOOK + * @param type Hook type, see #HookFlags * @param ctx Mailbox Context * @param e Email * @retval 0 Success * @retval -1 Failure */ -static int addr_hook(char *path, size_t pathlen, int type, struct Context *ctx, - struct Email *e) +static int addr_hook(char *path, size_t pathlen, HookFlags type, + struct Context *ctx, struct Email *e) { struct Hook *hook = NULL; struct PatternCache cache = { 0 }; @@ -582,9 +582,9 @@ void mutt_select_fcc(char *path, size_t pathlen, struct Email *e) * list_hook - Find hook strings matching * @param[out] matches List of hook strings * @param[in] match String to match - * @param[in] hook Hook type, e.g. #MUTT_CRYPT_HOOK + * @param[in] hook Hook type, see #HookFlags */ -static void list_hook(struct ListHead *matches, const char *match, int hook) +static void list_hook(struct ListHead *matches, const char *match, HookFlags hook) { struct Hook *tmp = NULL; @@ -702,12 +702,12 @@ void mutt_timeout_hook(void) /** * mutt_startup_shutdown_hook - Execute any startup/shutdown hooks - * @param type Hook type: MUTT_STARTUP_HOOK or MUTT_SHUTDOWN_HOOK + * @param type Hook type: #MUTT_STARTUP_HOOK or #MUTT_SHUTDOWN_HOOK * * The user can configure hooks to be run on startup/shutdown. * This function finds all the matching hooks and executes them. */ -void mutt_startup_shutdown_hook(int type) +void mutt_startup_shutdown_hook(HookFlags type) { struct Hook *hook = NULL; struct Buffer token = { 0 }; diff --git a/hook.h b/hook.h index 9d5f88810..76050a2e3 100644 --- a/hook.h +++ b/hook.h @@ -38,7 +38,8 @@ extern char *C_DefaultHook; extern bool C_ForceName; extern bool C_SaveName; -/* types for mutt_parse_hook() */ +typedef uint32_t HookFlags; ///< Flags for mutt_parse_hook(), e.g. #MUTT_FOLDER_HOOK +#define MUTT_HOOK_NO_FLAGS 0 ///< No flags are set #define MUTT_FOLDER_HOOK (1 << 0) ///< folder-hook: when entering a mailbox #define MUTT_MBOX_HOOK (1 << 1) ///< mbox-hook: move messages after reading them #define MUTT_SEND_HOOK (1 << 2) ///< send-hook: when composing a new email @@ -64,14 +65,14 @@ extern bool C_SaveName; void mutt_account_hook(const char *url); void mutt_crypt_hook(struct ListHead *list, struct Address *addr); void mutt_default_save(char *path, size_t pathlen, struct Email *e); -void mutt_delete_hooks(int type); -char *mutt_find_hook(int type, const char *pat); +void mutt_delete_hooks(HookFlags type); +char *mutt_find_hook(HookFlags type, const char *pat); void mutt_folder_hook(const char *path, const char *desc); -void mutt_message_hook(struct Mailbox *m, struct Email *e, int type); +void mutt_message_hook(struct Mailbox *m, struct Email *e, HookFlags type); enum CommandResult mutt_parse_hook(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err); enum CommandResult mutt_parse_unhook(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err); void mutt_select_fcc(char *path, size_t pathlen, struct Email *e); -void mutt_startup_shutdown_hook(int type); +void mutt_startup_shutdown_hook(HookFlags type); void mutt_timeout_hook(void); #endif /* MUTT_HOOK_H */