NeoMutt  2024-11-14-138-ge5ca67
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
command.h File Reference

NeoMutt commands API. More...

#include "config.h"
#include <stddef.h>
#include <stdint.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

struct Commandcommand_get (const char *s)
 Get a Command by its name.
 
size_t commands_array (struct Command **first)
 Get Commands array.
 
void commands_cleanup (void)
 Free Commands array.
 
void commands_init (void)
 Initialize commands array and register default commands.
 
void commands_register (const struct Command *cmds, const size_t num_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 35 of file command.h.

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

Function Documentation

◆ command_get()

struct Command * command_get ( const char *  s)

Get a Command by its name.

Parameters
sCommand string to lookup
Return values
ptrSuccess, Command
NULLError, no such command

Definition at line 87 of file command.c.

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_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
static struct CommandArray Commands
All the registered commands, e.g. alias, sidebar_pin.
Definition: command.c:35
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ commands_array()

size_t commands_array ( struct Command **  first)

Get Commands array.

Parameters
firstSet to first element of Commands array
Return values
numSize of Commands array

Definition at line 75 of file command.c.

76{
77 *first = ARRAY_FIRST(&Commands);
78 return ARRAY_SIZE(&Commands);
79}
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition: array.h:135
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
+ Here is the caller graph for this function:

◆ commands_cleanup()

void commands_cleanup ( void  )

Free Commands array.

Definition at line 65 of file command.c.

66{
68}
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:204
+ Here is the caller graph for this function:

◆ commands_init()

void commands_init ( void  )

Initialize commands array and register default commands.

Definition at line 1730 of file commands.c.

1731{
1733}
static const struct Command MuttCommands[]
General NeoMutt Commands.
Definition: commands.c:1662
void commands_register(const struct Command *cmds, const size_t num_cmds)
Add commands to Commands array.
Definition: command.c:53
#define mutt_array_size(x)
Definition: memory.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ commands_register()

void commands_register ( const struct Command cmds,
const size_t  num_cmds 
)

Add commands to Commands array.

Parameters
cmdsArray of Commands
num_cmdsNumber of Commands in the Array

Definition at line 53 of file command.c.

54{
55 for (int i = 0; i < num_cmds; i++)
56 {
57 ARRAY_ADD(&Commands, cmds[i]);
58 }
60}
#define ARRAY_SORT(head, fn, sdata)
Sort an array.
Definition: array.h:279
#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:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function: