NeoMutt  2024-10-02-34-g9dd811
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
command.c
Go to the documentation of this file.
1
29#include "config.h"
30#include "mutt/lib.h"
31#include "command.h"
32
33ARRAY_HEAD(CommandArray, struct Command);
35static struct CommandArray Commands = ARRAY_HEAD_INITIALIZER;
36
40static int commands_sort(const void *a, const void *b, void *sdata)
41{
42 struct Command x = *(const struct Command *) a;
43 struct Command y = *(const struct Command *) b;
44
45 return mutt_str_cmp(x.name, y.name);
46}
47
53void commands_register(const struct Command *cmds, const size_t num_cmds)
54{
55 for (int i = 0; i < num_cmds; i++)
56 {
57 ARRAY_ADD(&Commands, cmds[i]);
58 }
60}
61
66{
68}
69
75size_t commands_array(struct Command **first)
76{
77 *first = ARRAY_FIRST(&Commands);
78 return ARRAY_SIZE(&Commands);
79}
80
87struct Command *command_get(const char *s)
88{
89 struct Command *cmd = NULL;
91 {
92 if (mutt_str_equal(s, cmd->name))
93 return cmd;
94 }
95 return NULL;
96}
#define ARRAY_SORT(head, fn, sdata)
Sort an array.
Definition: array.h:279
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition: array.h:135
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:156
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
#define ARRAY_HEAD(name, type)
Define a named struct for arrays of elements of a certain type.
Definition: array.h:47
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:204
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:58
NeoMutt commands API.
void commands_register(const struct Command *cmds, const size_t num_cmds)
Add commands to Commands array.
Definition: command.c:53
size_t commands_array(struct Command **first)
Get Commands array.
Definition: command.c:75
void commands_cleanup(void)
Free Commands array.
Definition: command.c:65
static struct CommandArray Commands
All the registered commands, e.g. alias, sidebar_pin.
Definition: command.c:35
struct Command * command_get(const char *s)
Get a Command by its name.
Definition: command.c:87
static int commands_sort(const void *a, const void *b, void *sdata)
Compare two commands by name - Implements sort_t -.
Definition: command.c:40
Convenience wrapper for the library headers.
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:399
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
const char * name
Name of the command.
Definition: command.h:52