Read an initialization file.
65{
66 if (!rcfile_path || !pc || !pe)
67 return -1;
68
71
72 int lineno = 0;
73 int rc = 0;
74 int warnings = 0;
76 struct Buffer *linebuf = NULL;
77 char *line = NULL;
78 char *currentline = NULL;
80 size_t linelen = 0;
81 pid_t pid = 0;
82
84
86 if (rcfilelen == 0)
87 return -1;
88
89 bool ispipe = rcfile[rcfilelen - 1] == '|';
90
91 if (!ispipe)
92 {
95 {
96 mutt_error(
_(
"Error: Can't build path of '%s'"), rcfile_path);
97 return -1;
98 }
99
101 {
103 {
104 break;
105 }
106 }
107 if (np)
108 {
109 mutt_error(
_(
"Error: Cyclic sourcing of configuration file '%s'"), rcfile);
110 return -1;
111 }
112
114 }
115
117
119 if (!fp)
120 {
121 buf_printf(err,
"%s: %s", rcfile, strerror(errno));
122 return -1;
123 }
124
126
130 {
131 const bool conv = c_config_charset && c_charset;
132 if (conv)
133 {
135 if (!currentline)
136 continue;
138 }
139 else
140 {
141 currentline = line;
142 }
143
145
149 {
152 {
153 if (conv)
155 break;
156 }
157 }
159 {
160
162 warnings++;
163 }
165 {
166 if (conv)
168 break;
169 }
170 else
171 {
172 if (rc < 0)
173 rc = -1;
174 }
175 if (conv)
177 }
178
181 if (ispipe && (pid != -1))
182 {
184 if (status != 0)
185 {
186 mutt_error(
_(
"Command '%s' exited with status %d"), rcfile, status);
187 if (rc == 0)
188 rc = -1;
189 }
190 }
191
192 if (rc)
193 {
194
196 buf_printf(err, (rc >= -
MAX_ERRS) ?
_(
"source: errors in %s") :
_(
"source: reading aborted due to too many errors in %s"),
197 rcfile);
198 rc = -1;
199 }
200 else
201 {
202
203 if (warnings > 0)
204 {
205 buf_printf(err, ngettext(
"source: %d warning in %s",
"source: %d warnings in %s", warnings),
206 warnings, rcfile);
207 rc = -2;
208 }
209 }
210
212 {
217 }
218
220 return rc;
221}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
CommandResult
Error codes for command_t parse functions.
@ MUTT_CMD_ERROR
Error: Can't help the user.
@ MUTT_CMD_WARNING
Warning: Help given to the user.
@ MUTT_CMD_FINISH
Finish: Stop processing this file.
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
const char * cc_charset(void)
Get the cached value of $charset.
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags)
Read a line from a file.
#define mutt_file_fclose(FP)
@ MUTT_RL_CONT
-continuation
#define mutt_warning(...)
#define mutt_debug(LEVEL,...)
struct ListNode * mutt_list_insert_head(struct ListHead *h, char *s)
Insert a string at the beginning of a List.
@ LL_DEBUG2
Log at debug level 2.
#define FREE(x)
Free memory and set the pointer to NULL.
@ MODULE_ID_COMMANDS
ModuleCommands, NeoMutt Commands
int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags)
Convert a string between encodings.
#define MUTT_ICONV_NONE
No flags are set.
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
bool mutt_path_to_absolute(char *path, const char *reference)
Convert a relative path to its absolute form.
char * mutt_str_dup(const char *str)
Copy a string, safely.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination).
FILE * mutt_open_read(const char *path, pid_t *thepid)
Run a command to read from.
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
#define STAILQ_REMOVE_HEAD(head, field)
#define STAILQ_FIRST(head)
#define STAILQ_FOREACH(var, head, field)
#define STAILQ_EMPTY(head)
enum CommandResult parse_rc_line(struct Buffer *line, struct ParseContext *pc, struct ParseError *pe)
Parse a line of user config.
String manipulation buffer.
Commands private Module data.
struct ListHead muttrc_stack
LIFO of sourced config files (avoid cycles).
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.
struct Buffer * message
Error message.