NeoMutt
2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Toggle main menu visibility
Loading...
Searching...
No Matches
command.c
Go to the documentation of this file.
1
22
28
29
#include "config.h"
30
#include <stddef.h>
31
#include "
mutt/lib.h
"
32
#include "
command.h
"
33
37
static
int
commands_sort
(
const
void
*a,
const
void
*b,
void
*sdata)
38
{
39
const
struct
Command
*x = *(
const
struct
Command
**) a;
40
const
struct
Command
*y = *(
const
struct
Command
**) b;
41
42
return
mutt_str_cmp
(x->
name
, y->
name
);
43
}
44
51
bool
commands_register
(
struct
CommandArray *ca,
const
struct
Command
*cmds)
52
{
53
if
(!ca || !cmds)
54
return
false
;
55
56
for
(
int
i = 0; cmds[i].
name
; i++)
57
{
58
ARRAY_ADD
(ca, &cmds[i]);
59
}
60
ARRAY_SORT
(ca,
commands_sort
, NULL);
61
62
return
true
;
63
}
64
70
void
commands_clear
(
struct
CommandArray *ca)
71
{
72
ARRAY_FREE
(ca);
73
}
74
82
const
struct
Command
*
commands_get
(
struct
CommandArray *ca,
const
char
*
name
)
83
{
84
const
struct
Command
**cp = NULL;
85
ARRAY_FOREACH
(cp, ca)
86
{
87
const
struct
Command
*cmd = *cp;
88
89
if
(
mutt_str_equal
(
name
, cmd->
name
))
90
return
cmd;
91
}
92
return
NULL;
93
}
ARRAY_SORT
#define ARRAY_SORT(head, fn, sdata)
Sort an array.
Definition
array.h:373
ARRAY_ADD
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition
array.h:157
ARRAY_FOREACH
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition
array.h:223
ARRAY_FREE
#define ARRAY_FREE(head)
Release all memory.
Definition
array.h:209
command.h
NeoMutt commands API.
commands_register
bool commands_register(struct CommandArray *ca, const struct Command *cmds)
Add commands to Commands array.
Definition
command.c:51
commands_get
const struct Command * commands_get(struct CommandArray *ca, const char *name)
Get a Command by its name.
Definition
command.c:82
commands_clear
void commands_clear(struct CommandArray *ca)
Clear an Array of Commands.
Definition
command.c:70
commands_sort
static int commands_sort(const void *a, const void *b, void *sdata)
Compare two commands by name - Implements sort_t -.
Definition
command.c:37
lib.h
Convenience wrapper for the library headers.
mutt_str_cmp
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition
string.c:403
mutt_str_equal
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition
string.c:666
Command
Definition
command.h:161
Command::name
const char * name
Name of the Command.
Definition
command.h:162