NeoMutt  2021-10-22-8-g9cb437
Teaching an old dog new tricks
DOXYGEN
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 "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.

Functions

 ARRAY_HEAD (struct Command)
 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...
 

Variables

static const struct Command mutt_commands []
 

Detailed Description

Definitions of NeoMutt commands.

Authors
  • 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 http://www.gnu.org/licenses/.

Definition in file mutt_commands.c.

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( struct Command  )

Initialize commands array and register default commands.

Definition at line 130 of file mutt_commands.c.

136 {
137  ARRAY_RESERVE(&commands, 100);
139 }
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:185
static const struct Command mutt_commands[]
Definition: mutt_commands.c:47
#define COMMANDS_REGISTER(cmds)
Definition: mutt_commands.h:47

◆ 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 157 of file mutt_commands.c.

158 {
159  for (int i = 0; i < num_cmds; i++)
160  {
161  ARRAY_ADD(&commands, cmds[i]);
162  }
163  ARRAY_SORT(&commands, commands_cmp);
164 }
#define ARRAY_SORT(head, fn)
Sort an array.
Definition: array.h:274
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:152
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 169 of file mutt_commands.c.

170 {
171  ARRAY_FREE(&commands);
172 }
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:200
+ 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 179 of file mutt_commands.c.

180 {
181  *first = ARRAY_FIRST(&commands);
182  return ARRAY_SIZE(&commands);
183 }
#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 191 of file mutt_commands.c.

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

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

Variable Documentation

◆ mutt_commands

const struct Command mutt_commands[]
static

Definition at line 1 of file mutt_commands.c.