NeoMutt  2025-12-11-435-g4ac674
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 146 of file commands.c.

147{
148 if (!ca || (id == CMD_NONE))
149 return NULL;
150
151 const struct Command **cp = NULL;
152 ARRAY_FOREACH(cp, ca)
153 {
154 const struct Command *cmd = *cp;
155
156 if (cmd->id == id)
157 return cmd;
158 }
159
160 return NULL;
161}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
@ CMD_NONE
No Command.
Definition command.h:59
enum CommandId id
ID of the Command.
Definition command.h:160
+ 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 171 of file commands.c.

172{
173 if (!ca || !name)
174 return NULL;
175
176 const struct Command **cp = NULL;
177 ARRAY_FOREACH(cp, ca)
178 {
179 const struct Command *cmd = *cp;
180
181 if (mutt_str_equal(cmd->name, name))
182 {
183 // If this is a synonym, look up the real Command
184 if ((cmd->flags & CF_SYNONYM) && cmd->help)
185 {
186 const char *real_name = cmd->help;
187 // Search for the real command (non-recursive, single pass)
188 const struct Command **rp = NULL;
189 ARRAY_FOREACH(rp, ca)
190 {
191 const struct Command *real_cmd = *rp;
192 if (mutt_str_equal(real_cmd->name, real_name) && !(real_cmd->flags & CF_SYNONYM))
193 return real_cmd;
194 }
195 return NULL; // Real command not found
196 }
197 return cmd;
198 }
199 }
200
201 return NULL;
202}
#define CF_SYNONYM
Command is a synonym for another command.
Definition command.h:49
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:662
CommandFlags flags
Command flags, e.g. CF_SYNONYM.
Definition command.h:184
const char * help
One-line description of the Command.
Definition command.h:180
const char * name
Name of the Command.
Definition command.h:159
+ Here is the call graph for this function:
+ Here is the caller graph for this function: