NeoMutt  2022-04-29-70-g0c028c
Teaching an old dog new tricks
mutt_commands.c File Reference

Definitions of NeoMutt commands. More...

#include "config.h"
#include <stddef.h>
#include <string.h>
#include "address/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "alias/lib.h"
#include "mutt.h"
#include "mutt_commands.h"
#include "attach/lib.h"
#include "color/lib.h"
#include "command_parse.h"
#include "hook.h"
#include "keymap.h"
#include "mutt_globals.h"
#include "score.h"
+ Include dependency graph for mutt_commands.c:

Go to the source code of this file.


 ARRAY_HEAD (CommandArray, struct Command)
void mutt_commands_init (void)
 Initialize commands array and register default commands. More...
int commands_cmp (const void *a, const void *b)
 Compare two commands by name - Implements sort_t -. More...
void commands_register (const struct Command *cmds, const size_t num_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...


static const struct Command mutt_commands []
struct CommandArray commands = ARRAY_HEAD_INITIALIZER

Detailed Description

Definitions of NeoMutt commands.

  • Michael R. Elkins
  • g10 Code GmbH

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

Definition in file mutt_commands.c.

Function Documentation


ARRAY_HEAD ( CommandArray  ,
struct Command   

◆ mutt_commands_init()

void mutt_commands_init ( void  )

Initialize commands array and register default commands.

Definition at line 137 of file mutt_commands.c.

138 {
139  ARRAY_RESERVE(&commands, 100);
141 }
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:188
struct CommandArray commands
static const struct Command mutt_commands[]
Definition: mutt_commands.c:48
Definition: mutt_commands.h:47
+ 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.

cmdsArray of Commands
num_cmdsNumber of Commands in the Array

Definition at line 159 of file mutt_commands.c.

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

◆ mutt_commands_free()

void mutt_commands_free ( void  )

Free Commands array.

Definition at line 171 of file mutt_commands.c.

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

◆ mutt_commands_array()

size_t mutt_commands_array ( struct Command **  first)

Get Commands array.

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

Definition at line 181 of file mutt_commands.c.

182 {
183  *first = ARRAY_FIRST(&commands);
184  return ARRAY_SIZE(&commands);
185 }
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition: array.h:134
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:86
+ 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.

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

Definition at line 193 of file mutt_commands.c.

194 {
195  struct Command *cmd = NULL;
196  ARRAY_FOREACH(cmd, &commands)
197  {
198  if (mutt_str_equal(s, cmd->name))
199  return cmd;
200  }
201  return NULL;
202 }
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:211
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:784
const char * name
Name of the command.
Definition: command.h:50
+ 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.

dataData to pass to the callback function
applicationCallback function

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

Definition at line 212 of file mutt_commands.c.

213 {
214  struct Command *cmd = NULL;
215  ARRAY_FOREACH(cmd, &commands)
216  {
217  application(data, cmd);
218  }
219 }
intptr_t data
Data or flags to pass to the command.
Definition: command.h:65
+ Here is the caller graph for this function:

Variable Documentation

◆ mutt_commands

const struct Command mutt_commands[]

Definition at line 1 of file mutt_commands.c.

◆ commands

struct CommandArray commands = ARRAY_HEAD_INITIALIZER

Definition at line 131 of file mutt_commands.c.