NeoMutt  2025-01-09-117-gace867
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
command.c File Reference

NeoMutt Commands. More...

#include "config.h"
#include <stddef.h>
#include "mutt/lib.h"
#include "command.h"
+ Include dependency graph for command.c:

Go to the source code of this file.

Functions

static int commands_sort (const void *a, const void *b, void *sdata)
 Compare two commands by name - Implements sort_t -.
 
bool commands_register (struct CommandArray *ca, const struct Command *cmds)
 Add commands to Commands array.
 
void commands_clear (struct CommandArray *ca)
 Clear an Array of Commands.
 
const struct Commandcommands_get (struct CommandArray *ca, const char *name)
 Get a Command by its name.
 

Detailed Description

NeoMutt Commands.

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 command.c.

Function Documentation

◆ commands_register()

bool commands_register ( struct CommandArray *  ca,
const struct Command cmds 
)

Add commands to Commands array.

Parameters
caCommand Array
cmdsNew Commands to add
Return values
trueSuccess

Definition at line 51 of file command.c.

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}
#define ARRAY_SORT(head, fn, sdata)
Sort an array.
Definition: array.h:335
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:156
static int commands_sort(const void *a, const void *b, void *sdata)
Compare two commands by name - Implements sort_t -.
Definition: command.c:37
const char * name
Name of the command.
Definition: command.h:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ commands_clear()

void commands_clear ( struct CommandArray *  ca)

Clear an Array of Commands.

Note
The Array itself is not freed

Definition at line 70 of file command.c.

71{
72 ARRAY_FREE(ca);
73}
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:204
+ Here is the caller graph for this function:

◆ commands_get()

const struct Command * commands_get ( struct CommandArray *  ca,
const char *  name 
)

Get a Command by its name.

Parameters
caCommand Array
nameCommand name to lookup
Return values
ptrSuccess, Command
NULLError, no such command

Definition at line 82 of file command.c.

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}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:214
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:661
+ Here is the call graph for this function:
+ Here is the caller graph for this function: