]> granicus.if.org Git - neomutt/commitdiff
init.c: allow sourcing of multiple files 626/head
authortoogley <toogley@mailbox.org>
Thu, 8 Jun 2017 22:39:37 +0000 (00:39 +0200)
committerRichard Russon <rich@flatcap.org>
Mon, 12 Jun 2017 23:08:01 +0000 (00:08 +0100)
Credits: Cedric Duval,
http://cedricduval.free.fr/mutt/patches/download/patch-1.5.4.cd.source_multiple.2

Issue #616

doc/manual.xml.head
init.c
init.h

index 1b28fbd61d4def2911d78e784b8b2a74c43ad81a..2fc7ea3374211c845e175c28a0fb1112f5115f1b 100644 (file)
@@ -5485,8 +5485,7 @@ set spam_separator=", "
             readability</title>
             <screen>
 set my_cfgdir = $HOME/mutt/config
-source $my_cfgdir/hooks
-source $my_cfgdir/macros
+source $my_cfgdir/hooks $my_cfgdir/macros
 <emphasis role="comment"># more source commands...</emphasis>
 </screen>
           </example>
@@ -5593,8 +5592,8 @@ mailboxes $my_mx +mailbox3</screen>
       <para>Usage:</para>
       <cmdsynopsis>
         <command>source</command>
-        <arg choice="plain">
-          <replaceable class="parameter">filename</replaceable>
+        <arg choice="plain" rep="repeat">
+          <replaceable class="parameter">file</replaceable>
         </arg>
       </cmdsynopsis>
       <para>This command allows the inclusion of initialization commands from
diff --git a/init.c b/init.c
index f6879bb1c3c457d8ba0c2bb3f0c247667be77676..04dfb68d72f2a65f15f9f33e28bd1253ad837edd 100644 (file)
--- 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 867b65a18e6a77f208b340dbf66f7d5d44f3b762..c55d77f771d6e623b4486b314e06dc4297ec175e 100644 (file)
--- 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);