NeoMutt  2022-04-29-249-gaae397
Teaching an old dog new tricks
DOXYGEN
icommands.h File Reference

Information commands. More...

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

Go to the source code of this file.

Data Structures

struct  ICommand
 An Informational Command. More...
 

Functions

enum CommandResult mutt_parse_icommand (const char *line, struct Buffer *err)
 Parse an informational command. More...
 

Detailed Description

Information commands.

Authors
  • Christopher John Czettel
  • 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 icommands.h.

Function Documentation

◆ mutt_parse_icommand()

enum CommandResult mutt_parse_icommand ( const char *  line,
struct Buffer err 
)

Parse an informational command.

Parameters
lineCommand to execute
errBuffer for error messages
Return values
MUTT_CMD_SUCCESSSuccess
MUTT_CMD_WARNINGWarning with message: command failed
MUTT_CMD_ERROR
  • Error (no message): command not found
  • Error with message: command failed

Definition at line 91 of file icommands.c.

92{
93 if (!line || (*line == '\0') || !err)
94 return MUTT_CMD_ERROR;
95
97
98 struct Buffer *token = mutt_buffer_pool_get();
99 struct Buffer expn = mutt_buffer_make(0);
100 mutt_buffer_addstr(&expn, line);
101 mutt_buffer_seek(&expn, 0);
102
104
105 SKIPWS(expn.dptr);
107 for (size_t i = 0; ICommandList[i].name; i++)
108 {
109 if (!mutt_str_equal(token->data, ICommandList[i].name))
110 continue;
111
112 rc = ICommandList[i].parse(token, &expn, ICommandList[i].data, err);
113 if (rc != MUTT_CMD_SUCCESS)
114 goto finish;
115
116 break; /* Continue with next command */
117 }
118
119finish:
121 mutt_buffer_dealloc(&expn);
122 return rc;
123}
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:67
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:309
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:233
void mutt_buffer_seek(struct Buffer *buf, size_t offset)
Set current read/write position to offset from beginning.
Definition: buffer.c:483
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:85
CommandResult
Error codes for command_t parse functions.
Definition: command.h:34
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition: command.h:37
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition: command.h:35
static const struct ICommand ICommandList[]
All available informational commands.
Definition: icommands.c:68
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:273
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:807
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:67
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define SKIPWS(ch)
Definition: string2.h:46
String manipulation buffer.
Definition: buffer.h:34
char * dptr
Current read/write position.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:35
enum CommandResult(* parse)(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Function to parse information commands.
Definition: icommands.h:47
char * name
Name of the command.
Definition: icommands.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function: