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

NeoMutt commands API. More...

#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include "mutt/lib.h"
+ Include dependency graph for command.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Command
 

Enumerations

enum  CommandResult { MUTT_CMD_ERROR = -1 , MUTT_CMD_WARNING = -2 , MUTT_CMD_SUCCESS = 0 , MUTT_CMD_FINISH = 1 }
 Error codes for command_t parse functions. More...
 

Functions

 ARRAY_HEAD (CommandArray, const struct Command *)
 
const struct Commandcommands_get (struct CommandArray *ca, const char *name)
 Get a Command by its name.
 
void commands_clear (struct CommandArray *ca)
 Clear an Array of Commands.
 
bool commands_init (void)
 Initialize commands array and register default commands.
 
bool commands_register (struct CommandArray *ca, const struct Command *cmds)
 Add commands to Commands array.
 

Detailed Description

NeoMutt commands API.

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.h.

Enumeration Type Documentation

◆ CommandResult

Error codes for command_t parse functions.

Enumerator
MUTT_CMD_ERROR 

Error: Can't help the user.

MUTT_CMD_WARNING 

Warning: Help given to the user.

MUTT_CMD_SUCCESS 

Success: Command worked.

MUTT_CMD_FINISH 

Finish: Stop processing this file.

Definition at line 34 of file command.h.

35{
36 MUTT_CMD_ERROR = -1,
37 MUTT_CMD_WARNING = -2,
40};
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition: command.h:38
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition: command.h:36
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition: command.h:37
@ MUTT_CMD_FINISH
Finish: Stop processing this file.
Definition: command.h:39

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( CommandArray  ,
const struct Command  
)

◆ 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
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_init()

bool commands_init ( void  )

Initialize commands array and register default commands.

Definition at line 1748 of file commands.c.

1749{
1751}
static const struct Command MuttCommands[]
General NeoMutt Commands.
Definition: commands.c:1679
bool commands_register(struct CommandArray *ca, const struct Command *cmds)
Add commands to Commands array.
Definition: command.c:51
Container for Accounts, Notifications.
Definition: neomutt.h:43
struct CommandArray commands
NeoMutt commands.
Definition: neomutt.h:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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
+ Here is the call graph for this function:
+ Here is the caller graph for this function: