NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
parse.c
Go to the documentation of this file.
1
30
36
37#include "config.h"
38#include <errno.h>
39#include <stdbool.h>
40#include <stdio.h>
41#include <string.h>
42#include <unistd.h>
43#include "mutt/lib.h"
44#include "config/lib.h"
45#include "core/lib.h"
46#include "parse.h"
47#include "pager/lib.h"
48#include "parse/lib.h"
49#include "globals.h"
50#include "muttlib.h"
51#include "version.h"
52
59enum CommandResult parse_cd(const struct Command *cmd, struct Buffer *line,
60 const struct ParseContext *pc, struct ParseError *pe)
61{
62 struct Buffer *err = pe->message;
63
64 struct Buffer *token = buf_pool_get();
66
68 if (buf_is_empty(token))
69 {
71 }
72 else
73 {
74 expand_path(token, false);
75 }
76
77 if (chdir(buf_string(token)) != 0)
78 {
79 buf_printf(err, "%s: %s", cmd->name, strerror(errno));
80 goto done;
81 }
82
84
85done:
86 buf_pool_release(&token);
87 return rc;
88}
89
96enum CommandResult parse_echo(const struct Command *cmd, struct Buffer *line,
97 const struct ParseContext *pc, struct ParseError *pe)
98{
99 struct Buffer *err = pe->message;
100
101 if (!MoreArgs(line))
102 {
103 buf_printf(err, _("%s: too few arguments"), cmd->name);
104 return MUTT_CMD_WARNING;
105 }
106
107 struct Buffer *token = buf_pool_get();
108
110 OptForceRefresh = true;
111 mutt_message("%s", buf_string(token));
112 OptForceRefresh = false;
113 mutt_sleep(0);
114
115 buf_pool_release(&token);
116 return MUTT_CMD_SUCCESS;
117}
118
125enum CommandResult parse_version(const struct Command *cmd, struct Buffer *line,
126 const struct ParseContext *pc, struct ParseError *pe)
127{
128 struct Buffer *err = pe->message;
129
130 // silently ignore 'version' if it's in a config file
131 if (!StartupComplete)
132 return MUTT_CMD_SUCCESS;
133
134 if (MoreArgs(line))
135 {
136 buf_printf(err, _("%s: too many arguments"), cmd->name);
137 return MUTT_CMD_WARNING;
138 }
139
140 struct Buffer *tempfile = buf_pool_get();
142
143 buf_mktemp(tempfile);
144
145 FILE *fp_out = mutt_file_fopen(buf_string(tempfile), "w");
146 if (!fp_out)
147 {
148 // L10N: '%s' is the file name of the temporary file
149 buf_printf(err, _("Could not create temporary file %s"), buf_string(tempfile));
150 goto done;
151 }
152
153 print_version(fp_out, false);
154 mutt_file_fclose(&fp_out);
155
156 struct PagerData pdata = { 0 };
157 struct PagerView pview = { &pdata };
158
159 pdata.fname = buf_string(tempfile);
160
161 pview.banner = cmd->name;
163 pview.mode = PAGER_MODE_OTHER;
164
165 mutt_do_pager(&pview, NULL);
166 rc = MUTT_CMD_SUCCESS;
167
168done:
169 buf_pool_release(&tempfile);
170 return rc;
171}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
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
Parse Simple Commands.
Convenience wrapper for the config headers.
bool StartupComplete
When the config has been read.
Definition address.c:11
Convenience wrapper for the core headers.
int mutt_do_pager(struct PagerView *pview, struct Email *e)
Display some page-able text to the user (help or attachment)
Definition do_pager.c:122
int parse_extract_token(struct Buffer *dest, struct Buffer *line, TokenFlags flags)
Extract one token from a string.
Definition extract.c:49
#define MoreArgs(buf)
Definition extract.h:31
#define TOKEN_NO_FLAGS
No flags are set.
Definition extract.h:45
#define mutt_file_fclose(FP)
Definition file.h:139
#define mutt_file_fopen(PATH, MODE)
Definition file.h:138
bool OptForceRefresh
(pseudo) refresh even during macros
Definition globals.c:47
Global variables.
enum CommandResult parse_echo(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'echo' command - Implements Command::parse() -.
Definition parse.c:96
enum CommandResult parse_cd(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'cd' command - Implements Command::parse() -.
Definition parse.c:59
enum CommandResult parse_version(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'version' command - Implements Command::parse() -.
Definition parse.c:125
#define mutt_message(...)
Definition logging2.h:93
Convenience wrapper for the library headers.
#define _(a)
Definition message.h:28
void mutt_sleep(short s)
Sleep for a while.
Definition muttlib.c:786
void expand_path(struct Buffer *buf, bool regex)
Create the canonical path.
Definition muttlib.c:121
Some miscellaneous functions.
GUI display a file/email/help in a viewport with paging.
#define MUTT_PAGER_NO_FLAGS
No flags are set.
Definition lib.h:62
@ PAGER_MODE_OTHER
Pager is invoked via 3rd path. Non-email content is likely to be shown.
Definition lib.h:142
Text parsing functions.
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
String manipulation buffer.
Definition buffer.h:36
const char * name
Name of the Command.
Definition command.h:159
Container for Accounts, Notifications.
Definition neomutt.h:41
char * home_dir
User's home directory.
Definition neomutt.h:56
Data to be displayed by PagerView.
Definition lib.h:161
const char * fname
Name of the file to read.
Definition lib.h:165
Paged view into some data.
Definition lib.h:172
struct PagerData * pdata
Data that pager displays. NOTNULL.
Definition lib.h:173
enum PagerMode mode
Pager mode.
Definition lib.h:174
PagerFlags flags
Additional settings to tweak pager's function.
Definition lib.h:175
const char * banner
Title to display in status bar.
Definition lib.h:176
Context for config parsing (history/backtrace)
Definition pcontext.h:34
Detailed error information from config parsing.
Definition perror.h:34
struct Buffer * message
Error message.
Definition perror.h:35
#define buf_mktemp(buf)
Definition tmp.h:33
bool print_version(FILE *fp, bool use_ansi)
Print system and compile info to a file.
Definition version.c:589
Display version and copyright about NeoMutt.