From 2f5e3b9eada122b66d8d1317a7bcfdd01710a02b Mon Sep 17 00:00:00 2001 From: "Steffen (Daode) Nurpmeso" Date: Thu, 29 Jun 2017 16:51:43 +0200 Subject: [PATCH] `exit', `quit': support optional exit status argument --- cmd-tab.h | 12 ++++++------ go.c | 24 ++++++++++++++++++------ nail.1 | 10 ++++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/cmd-tab.h b/cmd-tab.h index 21cac768..5df5faec 100644 --- a/cmd-tab.h +++ b/cmd-tab.h @@ -486,8 +486,8 @@ n_CMD_ARG_DESC_SUBCLASS_DEF(vpospar, 2, a_ctab_cad_vpospar){ DS(N_("Either [] or the error message ring")) }, { "eval", &c_eval, (G | M | X | EM | TWYSH), 1, MAC, NULL DS(N_("Construct command from ::, reuse its $? and $!")) }, - { "exit", &c_exit, (M | X | TWYSH), 0, 0, NULL - DS(N_("Immediately return to the shell without saving")) }, + { "exit", &c_exit, (M | X | TWYSH), 0, 1, NULL + DS(N_("Immediately return [] to the shell without saving")) }, { "history", #ifdef HAVE_HISTORY @@ -512,8 +512,8 @@ n_CMD_ARG_DESC_SUBCLASS_DEF(vpospar, 2, a_ctab_cad_vpospar){ (M | TWYSH), 0, 1, NULL DS(N_("[], or the .netrc cache")) }, - { "quit", &c_quit, TWYSH, 0, 0, NULL - DS(N_("Terminate session, saving messages as necessary")) }, + { "quit", &c_quit, TWYSH, 0, 1, NULL + DS(N_("Exit session with [], saving messages as necessary")) }, { "read", &c_read, (G | M | X | EM | TWYSH), 1, MAC, NULL DS(N_("Read a line from standard input into (s)")) }, @@ -552,8 +552,8 @@ n_CMD_ARG_DESC_SUBCLASS_DEF(vpospar, 2, a_ctab_cad_vpospar){ { "version", &c_version, (H | M | X | TWYSH), 0, 0, NULL DS(N_("Show the version and feature set of the program")) }, - { "xit"/*POSIX, first!*/, &c_exit, (M | X | TWYSH), 0, 0, NULL - DS(N_("Immediately return to the shell without saving")) }, + { "xit"/*POSIX, first!*/, &c_exit, (M | X | TWYSH), 0, 1, NULL + DS(N_("Immediately return [] to the shell without saving")) }, { "xcall", &c_xcall, (M | X | EM | TARG), 0, 0, n_CMD_ARG_DESC_SUBCLASS_CAST(&a_ctab_cad_call) DS(N_("Replace currently executing macro with macro [::]")) }, diff --git a/go.c b/go.c index ca7bd3f3..b0d9ef5a 100644 --- a/go.c +++ b/go.c @@ -263,6 +263,8 @@ a_go_evaluate(struct a_go_eval_ctx *gecp){ } flags; NYD_ENTER; + n_exit_status = n_EXIT_OK; + flags = a_NONE; rv = 1; nerrn = n_ERR_NONE; @@ -1229,8 +1231,6 @@ n_go_main_loop(void){ /* FIXME */ n_pstate |= odid; } } - - n_exit_status = n_EXIT_OK; } /* Read a line of commands and handle end of file specially */ @@ -2035,11 +2035,17 @@ jerr: FL int c_exit(void *vp){ + char const **argv; NYD_ENTER; - n_UNUSED(vp); + + if(*(argv = vp) != NULL && (n_idec_si32_cp(&n_exit_status, *argv, 0, NULL) & + (n_IDEC_STATE_EMASK | n_IDEC_STATE_CONSUMED) + ) != n_IDEC_STATE_CONSUMED) + n_exit_status |= n_EXIT_ERR; + if(n_pstate & n_PS_COMPOSE_FORKHOOK){ /* TODO sic */ fflush(NULL); - _exit(0); + _exit(n_exit_status); }else if(n_pstate & n_PS_COMPOSE_MODE) /* XXX really.. */ n_err(_("`exit' delayed until compose mode is left\n")); /* XXX ..log? */ n_psonce |= n_PSO_XIT; @@ -2049,11 +2055,17 @@ c_exit(void *vp){ FL int c_quit(void *vp){ + char const **argv; NYD_ENTER; - n_UNUSED(vp); + + if(*(argv = vp) != NULL && (n_idec_si32_cp(&n_exit_status, *argv, 0, NULL) & + (n_IDEC_STATE_EMASK | n_IDEC_STATE_CONSUMED) + ) != n_IDEC_STATE_CONSUMED) + n_exit_status |= n_EXIT_ERR; + if(n_pstate & n_PS_COMPOSE_FORKHOOK){ /* TODO sic */ fflush(NULL); - _exit(0); + _exit(n_exit_status); }else if(n_pstate & n_PS_COMPOSE_MODE) /* XXX really.. */ n_err(_("`exit' delayed until compose mode is left\n")); /* XXX ..log? */ n_psonce |= n_PSO_QUIT; diff --git a/nail.1 b/nail.1 index a38143a2..2a322a19 100644 --- a/nail.1 +++ b/nail.1 @@ -4473,6 +4473,11 @@ any saving of messages in the .Sx "secondary mailbox" .Ev MBOX as well as a possibly tracked line editor history file. +The optional status number argument will be passed through to +.Xr exit 3 . +\*(ID For now it can happen that the given status will be overwritten, +later this will only occur if a later error needs to be reported onto an +otherwise success indicating status. . .Mx .It Ic File @@ -5427,6 +5432,11 @@ then the edit file is rewritten. A return to the shell is effected, unless the rewrite of edit file fails, in which case the user can escape with the exit command. +The optional status number argument will be passed through to +.Xr exit 3 . +\*(ID For now it can happen that the given status will be overwritten, +later this will only occur if a later error needs to be reported onto an +otherwise success indicating status. . .Mx .It Ic read -- 2.11.4.GIT