NeoMutt  2025-12-11-58-g09398d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
rc.h File Reference

Parse lines from a runtime configuration (rc) file. More...

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

Go to the source code of this file.

Functions

enum CommandResult parse_rc_line (struct Buffer *line, struct Buffer *err)
 Parse a line of user config.
 

Detailed Description

Parse lines from a runtime configuration (rc) file.

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

Function Documentation

◆ parse_rc_line()

enum CommandResult parse_rc_line ( struct Buffer * line,
struct Buffer * err )

Parse a line of user config.

Parameters
lineconfig line to read
errwhere to write error messages
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 45 of file rc.c.

46{
47 if (buf_is_empty(line))
48 return MUTT_CMD_SUCCESS;
49 if (!err)
50 return MUTT_CMD_ERROR;
51
52 struct Buffer *token = buf_pool_get();
54 bool show_help = false;
55
56 buf_reset(err);
57
58 /* Read from the beginning of line->data */
59 buf_seek(line, 0);
60
61 SKIPWS(line->dptr);
62 while (*line->dptr)
63 {
64 if (*line->dptr == '#')
65 break; /* rest of line is a comment */
66 if (*line->dptr == ';')
67 {
68 line->dptr++;
69 continue;
70 }
72
73 const int token_len = buf_len(token);
74 if ((token_len > 0) && (buf_at(token, token_len - 1) == '?'))
75 {
76 token->data[token_len - 1] = '\0';
77 show_help = true;
78 }
79
80 bool match = false;
81 const struct Command **cp = NULL;
83 {
84 const struct Command *cmd = *cp;
85
86 if (mutt_str_equal(token->data, cmd->name))
87 {
88 if (show_help)
89 {
90 buf_add_printf(err, "%s\n", _(cmd->help));
91 buf_add_printf(err, ":%s\n", _(cmd->proto));
92 buf_add_printf(err, "file:///usr/share/doc/neomutt/%s", cmd->path);
93 goto finish;
94 }
95
96 mutt_debug(LL_DEBUG1, "NT_COMMAND: %s\n", cmd->name);
97 rc = cmd->parse(cmd, line, err);
98 if ((rc == MUTT_CMD_WARNING) || (rc == MUTT_CMD_ERROR) || (rc == MUTT_CMD_FINISH))
99 goto finish; /* Propagate return code */
100
101 notify_send(NeoMutt->notify, NT_COMMAND, 0, (void *) cmd);
102 match = true;
103 break; /* Continue with next command */
104 }
105 }
106
107 if (!match)
108 {
109 buf_printf(err, _("%s: unknown command"), buf_string(token));
110 rc = MUTT_CMD_ERROR;
111 break; /* Ignore the rest of the line */
112 }
113 }
114
115finish:
116 buf_pool_release(&token);
117 return rc;
118}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:214
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition buffer.c:204
void buf_seek(struct Buffer *buf, size_t offset)
Set current read/write position to offset from beginning.
Definition buffer.c:622
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition buffer.c:491
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
char buf_at(const struct Buffer *buf, size_t offset)
Return the character at the given offset.
Definition buffer.c:668
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
CommandResult
Error codes for command_t parse functions.
Definition command.h:35
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition command.h:38
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition command.h:36
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition command.h:37
@ MUTT_CMD_FINISH
Finish: Stop processing this file.
Definition command.h:39
int parse_extract_token(struct Buffer *dest, struct Buffer *line, TokenFlags flags)
Extract one token from a string.
Definition extract.c:48
#define TOKEN_NO_FLAGS
No flags are set.
Definition extract.h:44
#define mutt_debug(LEVEL,...)
Definition logging2.h:90
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:44
static bool show_help(struct CliHelp *help)
Show the Help.
Definition main.c:929
#define _(a)
Definition message.h:28
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition notify.c:173
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:660
@ NT_COMMAND
A Command has been executed, Command.
Definition notify_type.h:42
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:96
#define SKIPWS(ch)
Definition string2.h:51
String manipulation buffer.
Definition buffer.h:36
char * dptr
Current read/write position.
Definition buffer.h:38
char * data
Pointer to data.
Definition buffer.h:37
enum CommandResult(* parse)(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Definition command.h:75
const char * proto
Command prototype.
Definition command.h:80
const char * help
One-line description of the Command.
Definition command.h:79
const char * path
Help path, relative to the NeoMutt Docs.
Definition command.h:81
const char * name
Name of the command.
Definition command.h:59
Container for Accounts, Notifications.
Definition neomutt.h:43
struct CommandArray commands
NeoMutt commands.
Definition neomutt.h:51
struct Notify * notify
Notifications handler.
Definition neomutt.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function: