From b1a9e10be732bd3fccccf64e0fb0805d839cff51 Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Tue, 8 Oct 2024 08:58:20 +0100 Subject: [PATCH] feat: quit [exit_status], option support Affecting process exit status. --- doc/html/quit.html | 8 ++++++-- windows/windCmdNR.c | 23 +++++++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/doc/html/quit.html b/doc/html/quit.html index e263a1a8..e428ca30 100644 --- a/doc/html/quit.html +++ b/doc/html/quit.html @@ -31,7 +31,7 @@ Exit magic

Usage:

- quit [-noprompt]

+ quit [exit_status] [-noprompt]

Summary:

@@ -46,8 +46,12 @@ Exit magic The Tcl exit command will always exit magic immediately, without prompting or cleanup or any other niceties.

+ The exit_status option allows an exit status number in + the range 0 to 255 to be indicated to the parent process. The + default exit_status is 0 indicating success.

+ With the -noprompt option, the interactive confirm prompt - does not occur so any changes will be discarded. + does not occur so any changes will be discarded.

Implementation Notes:

diff --git a/windows/windCmdNR.c b/windows/windCmdNR.c index 7a780472..21da2afd 100644 --- a/windows/windCmdNR.c +++ b/windows/windCmdNR.c @@ -263,10 +263,11 @@ windQuitCmd(w, cmd) { clientRec *cr; bool checkfirst = TRUE; + int exit_status = 0; - if (cmd->tx_argc == 2) + if (cmd->tx_argc > 1) { - if (!strcmp(cmd->tx_argv[1], "-noprompt")) + if (!strcmp(cmd->tx_argv[cmd->tx_argc - 1], "-noprompt")) { checkfirst = FALSE; cmd->tx_argc--; @@ -275,7 +276,21 @@ windQuitCmd(w, cmd) if (cmd->tx_argc > 1) { - TxError("Usage: quit [-noprompt]\n"); + int tmp; + if (sscanf(cmd->tx_argv[cmd->tx_argc - 1], "%d", &tmp) == 1 && exit_status >= 0 && exit_status <= 255) + { + exit_status = tmp; + cmd->tx_argc--; + } + else + { + TxError("Invalid exit_status: %s\n", cmd->tx_argv[cmd->tx_argc - 1]); + } + } + + if (cmd->tx_argc > 1) + { + TxError("Usage: quit [exit_status] [-noprompt]\n"); return; } @@ -288,7 +303,7 @@ windQuitCmd(w, cmd) return; } - MainExit(0); + MainExit(exit_status); }