From bbd1e57e0537cb550cef17bed60b3dbbb636b7a1 Mon Sep 17 00:00:00 2001 From: toogley Date: Fri, 9 Jun 2017 00:39:37 +0200 Subject: [PATCH] init.c: allow sourcing of multiple files Credits: Cedric Duval, http://cedricduval.free.fr/mutt/patches/download/patch-1.5.4.cd.source_multiple.2 Issue #616 --- doc/manual.xml.head | 7 +++---- init.c | 33 ++++++++++++++++++++------------- init.h | 2 +- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/doc/manual.xml.head b/doc/manual.xml.head index 1b28fbd61..2fc7ea337 100644 --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -5485,8 +5485,7 @@ set spam_separator=", " readability set my_cfgdir = $HOME/mutt/config -source $my_cfgdir/hooks -source $my_cfgdir/macros +source $my_cfgdir/hooks $my_cfgdir/macros # more source commands... @@ -5593,8 +5592,8 @@ mailboxes $my_mx +mailbox3 Usage: source - - filename + + file This command allows the inclusion of initialization commands from diff --git a/init.c b/init.c index f6879bb1c..04dfb68d7 100644 --- a/init.c +++ b/init.c @@ -3136,24 +3136,31 @@ static int source_rc(const char *rcfile_path, struct Buffer *err) #undef MAXERRS -static int parse_source(struct Buffer *tmp, struct Buffer *s, +static int parse_source(struct Buffer *tmp, struct Buffer *token, unsigned long data, struct Buffer *err) { char path[_POSIX_PATH_MAX]; - if (mutt_extract_token(tmp, s, 0) != 0) - { - snprintf(err->data, err->dsize, _("source: error at %s"), s->dptr); - return -1; - } - if (MoreArgs(s)) + do { - strfcpy(err->data, _("source: too many arguments"), err->dsize); - return -1; - } - strfcpy(path, tmp->data, sizeof(path)); - mutt_expand_path(path, sizeof(path)); - return source_rc(path, err); + if (mutt_extract_token(tmp, token, 0) != 0) + { + snprintf(err->data, err->dsize, _("source: error at %s"), token->dptr); + return -1; + } + strfcpy(path, tmp->data, sizeof(path)); + mutt_expand_path(path, sizeof(path)); + + if (source_rc(path, err) < 0) + { + snprintf(err->data, err->dsize, + _("source: file %s could not be sourced."), path); + return -1; + } + + } while (MoreArgs(token)); + + return 0; } /* line command to execute diff --git a/init.h b/init.h index 867b65a18..c55d77f77 100644 --- a/init.h +++ b/init.h @@ -4482,7 +4482,7 @@ static int parse_ignore(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err); static int parse_unignore(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err); -static int parse_source(struct Buffer *buf, struct Buffer *s, +static int parse_source(struct Buffer *buf, struct Buffer *token, unsigned long data, struct Buffer *err); static int parse_set(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err); -- 2.40.0