summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2017-06-02 11:41:09 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2017-06-02 11:41:09 +0300
commitd30e5a07f35c756df64559fddcd69d8aaa23ab8d (patch)
tree5e01b008f8b931735ddded12b0da1215cd58e84d
parent46d7640ffc83a8b809845099839990c9a2cf70f6 (diff)
downloadmailutils-d30e5a07f35c756df64559fddcd69d8aaa23ab8d.tar.gz
mailutils-d30e5a07f35c756df64559fddcd69d8aaa23ab8d.tar.bz2
mh whatnow: allow for arguments in the editor profile value
* mh/mh_whatnow.c (edit): Make sure ed is always initialized. Accept command line arguments in the "editor" and "*-next" values.
-rw-r--r--mh/mh_whatnow.c66
1 files changed, 50 insertions, 16 deletions
diff --git a/mh/mh_whatnow.c b/mh/mh_whatnow.c
index f75df71f3..999116f2f 100644
--- a/mh/mh_whatnow.c
+++ b/mh/mh_whatnow.c
@@ -382,9 +382,8 @@ display (struct mh_whatnow_env *wh, int argc, char **argv, int *status)
static int
edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs)
{
- char const *ed;
+ char const *ed = wh->editor;
int i, rc, status;
- char **xargv;
if (wh->reedit)
{
@@ -403,19 +402,50 @@ edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs)
}
else if (argc > 1)
ed = argv[1];
- else
- ed = wh->editor;
-
- xargv = mu_calloc (argc+2, sizeof (*xargv));
- xargv[0] = (char *)ed;
- for (i = 1; i + 1 < argc; i++)
- xargv[i] = argv[i+1];
- xargv[i++] = wh->file;
- xargv[i] = NULL;
-
- rc = mu_spawnvp (xargv[0], xargv, &status);
- free (xargv);
+ if (argc > 1)
+ {
+ char **xargv;
+
+ xargv = mu_calloc (argc+2, sizeof (*xargv));
+ xargv[0] = (char *)ed;
+ for (i = 1; i + 1 < argc; i++)
+ xargv[i] = argv[i+1];
+ xargv[i++] = wh->file;
+ xargv[i] = NULL;
+ rc = mu_spawnvp (xargv[0], xargv, &status);
+ free (xargv);
+ }
+ else
+ {
+ struct mu_wordsplit ws;
+ extern char **environ;
+ if (mu_wordsplit (ed, &ws,
+ MU_WRDSF_QUOTE
+ | MU_WRDSF_SQUEEZE_DELIMS
+ | MU_WRDSF_ENV))
+ {
+ mu_error (_("cannot split line `%s': %s"), ed,
+ mu_wordsplit_strerror (&ws));
+ rc = MU_ERR_FAILURE;
+ }
+ else
+ {
+ char *xargv[2];
+ xargv[0] = wh->file;
+ xargv[1] = NULL;
+ if (mu_wordsplit_append (&ws, 1, xargv))
+ {
+ mu_error (_("cannot append arguments: %s"),
+ mu_wordsplit_strerror (&ws));
+ rc = ENOMEM;
+ }
+ else
+ rc = mu_spawnvp (ws.ws_wordv[0], ws.ws_wordv, &status);
+ mu_wordsplit_free (&ws);
+ }
+ }
+
if (rc || check_exit_status (ed, status))
{
if (wh->file)
@@ -613,8 +643,12 @@ mh_whatnow (struct mh_whatnow_env *wh, int initial_edit)
{
set_default_editor (wh);
- if (initial_edit)
- mh_spawnp (wh->editor, wh->file);
+ if (initial_edit && wh->file)
+ {
+ char *argv[2] = { "edit", NULL };
+ int status;
+ edit (wh, 1, argv, &status);
+ }
if (!wh->prompt)
wh->prompt = (char*) _("What now?");

Return to:

Send suggestions and report system problems to the System administrator.