Commit d30e5a07 d30e5a07f35c756df64559fddcd69d8aaa23ab8d by Sergey Poznyakoff

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.
1 parent 46d7640f
...@@ -382,9 +382,8 @@ display (struct mh_whatnow_env *wh, int argc, char **argv, int *status) ...@@ -382,9 +382,8 @@ display (struct mh_whatnow_env *wh, int argc, char **argv, int *status)
382 static int 382 static int
383 edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs) 383 edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs)
384 { 384 {
385 char const *ed; 385 char const *ed = wh->editor;
386 int i, rc, status; 386 int i, rc, status;
387 char **xargv;
388 387
389 if (wh->reedit) 388 if (wh->reedit)
390 { 389 {
...@@ -403,19 +402,50 @@ edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs) ...@@ -403,19 +402,50 @@ edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs)
403 } 402 }
404 else if (argc > 1) 403 else if (argc > 1)
405 ed = argv[1]; 404 ed = argv[1];
406 else
407 ed = wh->editor;
408
409 xargv = mu_calloc (argc+2, sizeof (*xargv));
410 xargv[0] = (char *)ed;
411 for (i = 1; i + 1 < argc; i++)
412 xargv[i] = argv[i+1];
413 xargv[i++] = wh->file;
414 xargv[i] = NULL;
415
416 rc = mu_spawnvp (xargv[0], xargv, &status);
417 free (xargv);
418 405
406 if (argc > 1)
407 {
408 char **xargv;
409
410 xargv = mu_calloc (argc+2, sizeof (*xargv));
411 xargv[0] = (char *)ed;
412 for (i = 1; i + 1 < argc; i++)
413 xargv[i] = argv[i+1];
414 xargv[i++] = wh->file;
415 xargv[i] = NULL;
416 rc = mu_spawnvp (xargv[0], xargv, &status);
417 free (xargv);
418 }
419 else
420 {
421 struct mu_wordsplit ws;
422 extern char **environ;
423 if (mu_wordsplit (ed, &ws,
424 MU_WRDSF_QUOTE
425 | MU_WRDSF_SQUEEZE_DELIMS
426 | MU_WRDSF_ENV))
427 {
428 mu_error (_("cannot split line `%s': %s"), ed,
429 mu_wordsplit_strerror (&ws));
430 rc = MU_ERR_FAILURE;
431 }
432 else
433 {
434 char *xargv[2];
435 xargv[0] = wh->file;
436 xargv[1] = NULL;
437 if (mu_wordsplit_append (&ws, 1, xargv))
438 {
439 mu_error (_("cannot append arguments: %s"),
440 mu_wordsplit_strerror (&ws));
441 rc = ENOMEM;
442 }
443 else
444 rc = mu_spawnvp (ws.ws_wordv[0], ws.ws_wordv, &status);
445 mu_wordsplit_free (&ws);
446 }
447 }
448
419 if (rc || check_exit_status (ed, status)) 449 if (rc || check_exit_status (ed, status))
420 { 450 {
421 if (wh->file) 451 if (wh->file)
...@@ -613,8 +643,12 @@ mh_whatnow (struct mh_whatnow_env *wh, int initial_edit) ...@@ -613,8 +643,12 @@ mh_whatnow (struct mh_whatnow_env *wh, int initial_edit)
613 { 643 {
614 set_default_editor (wh); 644 set_default_editor (wh);
615 645
616 if (initial_edit) 646 if (initial_edit && wh->file)
617 mh_spawnp (wh->editor, wh->file); 647 {
648 char *argv[2] = { "edit", NULL };
649 int status;
650 edit (wh, 1, argv, &status);
651 }
618 652
619 if (!wh->prompt) 653 if (!wh->prompt)
620 wh->prompt = (char*) _("What now?"); 654 wh->prompt = (char*) _("What now?");
......