NeoMutt  2020-09-25
Teaching an old dog new tricks
DOXYGEN
mutt_commands.h File Reference

Definitions of NeoMutt commands. More...

#include <stddef.h>
#include <stdint.h>
+ Include dependency graph for mutt_commands.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Command
 A user-callable command. More...
 

Macros

#define MUTT_NAMED   (1 << 0)
 
#define COMMANDS_REGISTER(cmds)   commands_register(cmds, mutt_array_size(cmds))
 

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...
 
enum  MuttSetCommand { MUTT_SET_SET, MUTT_SET_INV, MUTT_SET_UNSET, MUTT_SET_RESET }
 Flags for parse_set() More...
 

Functions

void mutt_commands_init (void)
 
void commands_register (const struct Command *cmdv, const size_t cmds)
 Add commands to Commands array. More...
 
void mutt_commands_free (void)
 Free Commands array. More...
 
size_t mutt_commands_array (struct Command **first)
 Get Commands array. More...
 
struct Commandmutt_command_get (const char *s)
 Get a Command by its name. More...
 
void mutt_commands_apply (void *data, void(*application)(void *, const struct Command *))
 Run a callback function on every Command. More...
 

Detailed Description

Definitions of NeoMutt commands.

Authors
  • Bernard Pratz

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

Macro Definition Documentation

◆ MUTT_NAMED

#define MUTT_NAMED   (1 << 0)

Definition at line 74 of file mutt_commands.h.

◆ COMMANDS_REGISTER

#define COMMANDS_REGISTER (   cmds)    commands_register(cmds, mutt_array_size(cmds))

Definition at line 77 of file mutt_commands.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 mutt_commands.h.

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

◆ MuttSetCommand

Flags for parse_set()

Enumerator
MUTT_SET_SET 

default is to set all vars

MUTT_SET_INV 

default is to invert all vars

MUTT_SET_UNSET 

default is to unset all vars

MUTT_SET_RESET 

default is to reset all vars to default

Definition at line 65 of file mutt_commands.h.

66 {
67  MUTT_SET_SET,
68  MUTT_SET_INV,
71 };
default is to reset all vars to default
Definition: mutt_commands.h:70
default is to unset all vars
Definition: mutt_commands.h:69
default is to set all vars
Definition: mutt_commands.h:67
default is to invert all vars
Definition: mutt_commands.h:68

Function Documentation

◆ mutt_commands_init()

void mutt_commands_init ( void  )
+ 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 163 of file mutt_commands.c.

164 {
165  for (int i = 0; i < num_cmds; i++)
166  {
167  ARRAY_ADD(&commands, cmds[i]);
168  }
169  ARRAY_SORT(&commands, commands_cmp);
170 }
int commands_cmp(const void *a, const void *b)
Compare two commands by name - Implements sort_t.
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:152
#define ARRAY_SORT(head, fn)
Sort an array.
Definition: array.h:271
+ Here is the call graph for this function:

◆ mutt_commands_free()

void mutt_commands_free ( void  )

Free Commands array.

Definition at line 175 of file mutt_commands.c.

176 {
177  ARRAY_FREE(&commands);
178 }
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:198
+ Here is the caller graph for this function:

◆ mutt_commands_array()

size_t mutt_commands_array ( struct Command **  first)

Get Commands array.

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

Definition at line 185 of file mutt_commands.c.

186 {
187  *first = ARRAY_FIRST(&commands);
188  return ARRAY_SIZE(&commands);
189 }
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition: array.h:131
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:83
+ Here is the caller graph for this function:

◆ mutt_command_get()

struct Command* mutt_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 197 of file mutt_commands.c.

198 {
199  struct Command *cmd = NULL;
200  ARRAY_FOREACH(cmd, &commands)
201  {
202  if (mutt_str_equal(s, cmd->name))
203  return cmd;
204  }
205  return NULL;
206 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
A user-callable command.
Definition: mutt_commands.h:45
const char * name
Name of the command.
Definition: mutt_commands.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_commands_apply()

void mutt_commands_apply ( void *  data,
void(*)(void *, const struct Command *)  application 
)

Run a callback function on every Command.

Parameters
dataData to pass to the callback function
applicationCallback function

This is used by Lua to expose all of NeoMutt's Commands.

Definition at line 216 of file mutt_commands.c.

217 {
218  struct Command *cmd = NULL;
219  ARRAY_FOREACH(cmd, &commands)
220  {
221  application(data, cmd);
222  }
223 }
intptr_t data
Data or flags to pass to the command.
Definition: mutt_commands.h:59
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
A user-callable command.
Definition: mutt_commands.h:45
+ Here is the caller graph for this function: