NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dump.c File Reference

Dump the Hooks to the Pager. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "mutt.h"
#include "commands/lib.h"
#include "expando/lib.h"
#include "pager/lib.h"
#include "parse/lib.h"
#include "hook.h"
#include "muttlib.h"
#include "parse.h"
+ Include dependency graph for dump.c:

Go to the source code of this file.

Functions

static void hooks_dump_one (struct Hook *hook, const struct Command *cmd, struct Buffer *buf)
 Dump a single hook to the buffer.
 
static void hooks_dump_simple (struct Buffer *buf)
 Dump the simple Hooks.
 
static void hooks_dump_index (struct Buffer *buf)
 Dump the Index Format Hooks.
 
static void hooks_dump_charset (struct Buffer *buf)
 Dump the Charset Hooks.
 
enum CommandResult parse_hooks (const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
 Parse the 'hooks' command - Implements Command::parse() -.
 

Detailed Description

Dump the Hooks to the Pager.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file dump.c.

Function Documentation

◆ hooks_dump_one()

static void hooks_dump_one ( struct Hook * hook,
const struct Command * cmd,
struct Buffer * buf )
static

Dump a single hook to the buffer.

Parameters
hookHook to dump
cmdCommand defining the Hook
bufBuffer for the results

Definition at line 50 of file dump.c.

51{
52 struct Buffer *pretty = buf_pool_get();
53
54 buf_add_printf(buf, "%s ", cmd->name);
55
56 if (hook->regex.pattern)
57 {
58 if (hook->regex.pat_not)
59 buf_addch(pretty, '!');
60
61 if ((hook->id == CMD_FOLDER_HOOK) || (hook->id == CMD_MBOX_HOOK))
62 {
63 buf_strcpy(pretty, hook->regex.pattern);
64 pretty_mailbox(pretty);
65 buf_add_printf(buf, "\"%s\" ", buf_string(pretty));
66 }
67 else
68 {
69 buf_addstr(pretty, hook->regex.pattern);
70 pretty_var(buf_string(pretty), buf);
71 buf_addch(buf, ' ');
72 }
73 }
74
75 if ((hook->id == CMD_FCC_HOOK) || (hook->id == CMD_MBOX_HOOK) || (hook->id == CMD_SAVE_HOOK))
76 {
77 buf_strcpy(pretty, hook->command);
78 pretty_mailbox(pretty);
79 buf_add_printf(buf, "\"%s\"\n", buf_string(pretty));
80 }
81 else
82 {
83 pretty_var(hook->command, buf);
84 buf_addch(buf, '\n');
85 }
86
87 buf_pool_release(&pretty);
88}
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition buffer.c:204
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition buffer.c:241
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:226
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
@ CMD_FCC_HOOK
:fcc-hook
Definition command.h:75
@ CMD_SAVE_HOOK
:save-hook
Definition command.h:104
@ CMD_MBOX_HOOK
:mbox-hook
Definition command.h:93
@ CMD_FOLDER_HOOK
:folder-hook
Definition command.h:78
size_t pretty_var(const char *str, struct Buffer *buf)
Escape and stringify a config item value.
Definition dump.c:87
void pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition muttlib.c:427
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
String manipulation buffer.
Definition buffer.h:36
const char * name
Name of the Command.
Definition command.h:159
struct Regex regex
Regular expression.
Definition hook.h:35
char * command
Filename, command or pattern to execute.
Definition hook.h:36
enum CommandId id
Hook CommandId, e.g. CMD_FOLDER_HOOK.
Definition hook.h:34
char * pattern
printable version
Definition regex3.h:86
bool pat_not
do not match
Definition regex3.h:88
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hooks_dump_simple()

static void hooks_dump_simple ( struct Buffer * buf)
static

Dump the simple Hooks.

Parameters
bufBuffer for the results

Definition at line 94 of file dump.c.

95{
96 // Dump all the Hooks, except: CMD_CHARSET_HOOK, CMD_ICONV_HOOK, CMD_INDEX_FORMAT_HOOK
97 static const enum CommandId hook_ids[] = {
102 };
103
104 for (size_t i = 0; i < countof(hook_ids); i++)
105 {
106 const struct Command *hook_cmd = command_find_by_id(&NeoMutt->commands, hook_ids[i]);
107 enum CommandId id = hook_ids[i];
108 bool found_header = false;
109 struct Hook *hook = NULL;
110
111 TAILQ_FOREACH(hook, &Hooks, entries)
112 {
113 if (hook->id != id)
114 continue;
115
116 if (!found_header)
117 {
118 buf_add_printf(buf, "# %s\n", hook_cmd->help);
119 found_header = true;
120 }
121
122 hooks_dump_one(hook, hook_cmd, buf);
123 }
124
125 if (found_header)
126 buf_addstr(buf, "\n");
127 }
128}
CommandId
ID of Command.
Definition command.h:58
@ CMD_CLOSE_HOOK
:close-hook
Definition command.h:70
@ CMD_SEND_HOOK
:send-hook
Definition command.h:107
@ CMD_SHUTDOWN_HOOK
:shutdown-hook
Definition command.h:110
@ CMD_MESSAGE_HOOK
:message-hook
Definition command.h:94
@ CMD_SEND2_HOOK
:send2-hook
Definition command.h:106
@ CMD_REPLY_HOOK
:reply-hook
Definition command.h:102
@ CMD_STARTUP_HOOK
:startup-hook
Definition command.h:115
@ CMD_TIMEOUT_HOOK
:timeout-hook
Definition command.h:121
@ CMD_ACCOUNT_HOOK
:account-hook
Definition command.h:60
@ CMD_CRYPT_HOOK
:crypt-hook
Definition command.h:72
@ CMD_OPEN_HOOK
:open-hook
Definition command.h:100
@ CMD_APPEND_HOOK
:append-hook
Definition command.h:64
const struct Command * command_find_by_id(const struct CommandArray *ca, enum CommandId id)
Find a NeoMutt Command by its CommandId.
Definition commands.c:146
static void hooks_dump_one(struct Hook *hook, const struct Command *cmd, struct Buffer *buf)
Dump a single hook to the buffer.
Definition dump.c:50
struct HookList Hooks
All simple hooks, e.g. CMD_FOLDER_HOOK.
Definition parse.c:49
#define countof(x)
Definition memory.h:49
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:782
const char * help
One-line description of the Command.
Definition command.h:180
A list of user hooks.
Definition hook.h:33
Container for Accounts, Notifications.
Definition neomutt.h:41
struct CommandArray commands
NeoMutt commands.
Definition neomutt.h:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hooks_dump_index()

static void hooks_dump_index ( struct Buffer * buf)
static

Dump the Index Format Hooks.

Parameters
bufBuffer for the results

Definition at line 134 of file dump.c.

135{
136 if (!IdxFmtHooks)
137 return;
138
139 struct HashWalkState hws = { 0 };
140 struct HashElem *he = NULL;
141 bool found_header = false;
142
143 while ((he = mutt_hash_walk(IdxFmtHooks, &hws)))
144 {
145 const char *name = he->key.strkey;
146 struct HookList *hl = he->data;
147 struct Hook *hook = NULL;
148
149 TAILQ_FOREACH(hook, hl, entries)
150 {
151 if (!found_header)
152 {
153 const struct Command *hook_cmd = command_find_by_id(&NeoMutt->commands,
155 buf_add_printf(buf, "# %s\n", hook_cmd->help);
156 found_header = true;
157 }
158
159 buf_add_printf(buf, "index-format-hook '%s' %s'%s' '%s'\n", name,
160 hook->regex.pat_not ? "! " : "",
161 NONULL(hook->regex.pattern), NONULL(hook->expando->string));
162 }
163 }
164
165 if (found_header)
166 buf_addstr(buf, "\n");
167}
@ CMD_INDEX_FORMAT_HOOK
:index-format-hook
Definition command.h:86
struct HashElem * mutt_hash_walk(const struct HashTable *table, struct HashWalkState *state)
Iterate through all the HashElem's in a Hash Table.
Definition hash.c:491
struct HashTable * IdxFmtHooks
All Index Format hooks.
Definition parse.c:52
#define NONULL(x)
Definition string2.h:44
const char * string
Pointer to the parsed string.
Definition expando.h:42
The item stored in a Hash Table.
Definition hash.h:44
union HashKey key
Key representing the data.
Definition hash.h:46
void * data
User-supplied data.
Definition hash.h:47
Cursor to iterate through a Hash Table.
Definition hash.h:134
struct Expando * expando
Used for format hooks.
Definition hook.h:39
const char * strkey
String key.
Definition hash.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hooks_dump_charset()

static void hooks_dump_charset ( struct Buffer * buf)
static

Dump the Charset Hooks.

Parameters
bufBuffer for the results

Definition at line 173 of file dump.c.

174{
175 struct Lookup *l = NULL;
176 struct Buffer *charset = buf_pool_get();
177 struct Buffer *iconv = buf_pool_get();
178
179 TAILQ_FOREACH(l, &Lookups, entries)
180 {
181 if (l->type == MUTT_LOOKUP_CHARSET)
182 {
183 buf_addstr(charset, "charset-hook ");
184 pretty_var(l->regex.pattern, charset);
185 buf_addch(charset, ' ');
186 pretty_var(l->replacement, charset);
187 buf_addch(charset, '\n');
188 }
189 else if (l->type == MUTT_LOOKUP_ICONV)
190 {
191 buf_addstr(iconv, "iconv-hook ");
192 pretty_var(l->regex.pattern, iconv);
193 buf_addch(iconv, ' ');
194 pretty_var(l->replacement, iconv);
195 buf_addch(iconv, '\n');
196 }
197 }
198
199 const struct Command *cmd = NULL;
200 if (!buf_is_empty(charset))
201 {
202 cmd = command_find_by_name(&NeoMutt->commands, "charset-hook");
203 buf_add_printf(buf, "# %s\n", cmd->help);
204 buf_add_printf(buf, "%s\n", buf_string(charset));
205 }
206
207 if (!buf_is_empty(iconv))
208 {
209 cmd = command_find_by_name(&NeoMutt->commands, "iconv-hook");
210 buf_add_printf(buf, "# %s\n", cmd->help);
211 buf_add_printf(buf, "%s\n", buf_string(iconv));
212 }
213
214 buf_pool_release(&iconv);
215 buf_pool_release(&charset);
216}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
const struct Command * command_find_by_name(const struct CommandArray *ca, const char *name)
Find a NeoMutt Command by its name.
Definition commands.c:171
struct LookupList Lookups
Lookup table of preferred character set names.
Definition charset.c:69
@ MUTT_LOOKUP_ICONV
Character set conversion.
Definition charset.h:63
@ MUTT_LOOKUP_CHARSET
Alias for another character set.
Definition charset.h:62
Regex to String lookup table.
Definition charset.h:75
char * replacement
Alternative charset to use.
Definition charset.h:78
enum LookupType type
Lookup type.
Definition charset.h:76
struct Regex regex
Regular expression.
Definition charset.h:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function: