NeoMutt  2025-12-11-435-g4ac674
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 ParseContext *pc, struct ParseError *pe)
 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 ParseContext * pc,
struct ParseError * pe )

Parse a line of user config.

Parameters
lineConfig line to read
pcParse Context
peParse Errors
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 45 of file rc.c.

47{
48 if (buf_is_empty(line))
49 return MUTT_CMD_SUCCESS;
50 if (!pc || !pe)
51 return MUTT_CMD_ERROR;
52
53 struct Buffer *err = pe->message;
54 struct Buffer *token = buf_pool_get();
56 bool show_help = false;
57
58 buf_reset(err);
59
60 /* Read from the beginning of line->data */
61 buf_seek(line, 0);
62
63 SKIPWS(line->dptr);
64 while (*line->dptr)
65 {
66 if (*line->dptr == '#')
67 break; /* rest of line is a comment */
68 if (*line->dptr == ';')
69 {
70 line->dptr++;
71 continue;
72 }
74
75 const int token_len = buf_len(token);
76 if ((token_len > 0) && (buf_at(token, token_len - 1) == '?'))
77 {
78 token->data[token_len - 1] = '\0';
79 show_help = true;
80 }
81
82 const struct Command *cmd = command_find_by_name(&NeoMutt->commands, buf_string(token));
83 if (cmd)
84 {
85 if (show_help)
86 {
87 buf_add_printf(err, "%s\n", _(cmd->help));
88 buf_add_printf(err, ":%s\n", _(cmd->proto));
89 buf_add_printf(err, "file:///usr/share/doc/neomutt/%s", cmd->path);
90 goto finish;
91 }
92
93 mutt_debug(LL_DEBUG1, "NT_COMMAND: %s\n", cmd->name);
94 rc = cmd->parse(cmd, line, pc, pe);
95 if ((rc == MUTT_CMD_WARNING) || (rc == MUTT_CMD_ERROR) || (rc == MUTT_CMD_FINISH))
96 goto finish; /* Propagate return code */
97
98 notify_send(NeoMutt->notify, NT_COMMAND, 0, (void *) cmd);
99 }
100 else
101 {
102 buf_printf(err, _("%s: unknown command"), buf_string(token));
103 rc = MUTT_CMD_ERROR;
104 }
105 }
106
107finish:
108 buf_pool_release(&token);
109 return rc;
110}
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:37
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition command.h:40
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition command.h:38
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition command.h:39
@ MUTT_CMD_FINISH
Finish: Stop processing this file.
Definition command.h:41
const struct Command * command_find_by_name(const struct CommandArray *ca, const char *name)
Find a NeoMutt Command by its name.
Definition commands.c:171
int parse_extract_token(struct Buffer *dest, struct Buffer *line, TokenFlags flags)
Extract one token from a string.
Definition extract.c:49
#define TOKEN_NO_FLAGS
No flags are set.
Definition extract.h:45
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
static bool show_help(struct CliHelp *help)
Show the Help.
Definition main.c:896
#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
@ 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:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
#define SKIPWS(ch)
Definition string2.h:52
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
const char * proto
Command prototype.
Definition command.h:181
const char * help
One-line description of the Command.
Definition command.h:180
enum CommandResult(* parse)(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Definition command.h:178
const char * path
Help path, relative to the NeoMutt Docs.
Definition command.h:182
const char * name
Name of the Command.
Definition command.h:159
Container for Accounts, Notifications.
Definition neomutt.h:41
struct CommandArray commands
NeoMutt commands.
Definition neomutt.h:53
struct Notify * notify
Notifications handler.
Definition neomutt.h:45
struct Buffer * message
Error message.
Definition perror.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function: