NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
commands.h File Reference

Setup NeoMutt Commands. More...

#include "core/lib.h"
+ Include dependency graph for commands.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

const struct Commandcommand_find_by_id (const struct CommandArray *ca, enum CommandId id)
 Find a NeoMutt Command by its CommandId.
 
const struct Commandcommand_find_by_name (const struct CommandArray *ca, const char *name)
 Find a NeoMutt Command by its name.
 

Detailed Description

Setup NeoMutt Commands.

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

Function Documentation

◆ command_find_by_id()

const struct Command * command_find_by_id ( const struct CommandArray * ca,
enum CommandId id )

Find a NeoMutt Command by its CommandId.

Parameters
caArray of Commands
idID to find
Return values
ptrMatching Command

Definition at line 120 of file commands.c.

121{
122 if (!ca || (id == CMD_NONE))
123 return NULL;
124
125 const struct Command **cp = NULL;
126 ARRAY_FOREACH(cp, ca)
127 {
128 const struct Command *cmd = *cp;
129
130 if (cmd->id == id)
131 return cmd;
132 }
133
134 return NULL;
135}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
@ CMD_NONE
No Command.
Definition command.h:62
enum CommandId id
ID of the Command.
Definition command.h:163
+ Here is the caller graph for this function:

◆ command_find_by_name()

const struct Command * command_find_by_name ( const struct CommandArray * ca,
const char * name )

Find a NeoMutt Command by its name.

Parameters
caArray of Commands
nameName to find
Return values
ptrMatching Command
Note
If the name matches a Command Synonym, the real Command is returned.

Definition at line 145 of file commands.c.

146{
147 if (!ca || !name)
148 return NULL;
149
150 const struct Command **cp = NULL;
151 ARRAY_FOREACH(cp, ca)
152 {
153 const struct Command *cmd = *cp;
154
155 if (mutt_str_equal(cmd->name, name))
156 {
157 // If this is a synonym, look up the real Command
158 if ((cmd->flags & CF_SYNONYM) && cmd->help)
159 {
160 const char *real_name = cmd->help;
161 // Search for the real command (non-recursive, single pass)
162 const struct Command **rp = NULL;
163 ARRAY_FOREACH(rp, ca)
164 {
165 const struct Command *real_cmd = *rp;
166 if (mutt_str_equal(real_cmd->name, real_name) && !(real_cmd->flags & CF_SYNONYM))
167 return real_cmd;
168 }
169 return NULL; // Real command not found
170 }
171 return cmd;
172 }
173 }
174
175 return NULL;
176}
@ CF_SYNONYM
Command is a synonym for another command.
Definition command.h:50
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
CommandFlags flags
Command flags, e.g. CF_SYNONYM.
Definition command.h:187
const char * help
One-line description of the Command.
Definition command.h:183
const char * name
Name of the Command.
Definition command.h:162
+ Here is the call graph for this function:
+ Here is the caller graph for this function: