Skip to content

Commit

Permalink
feat: quit [exit_status], option support
Browse files Browse the repository at this point in the history
Affecting process exit status.
  • Loading branch information
dlmiles committed Oct 9, 2024
1 parent 31c8c1a commit 71bc743
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
8 changes: 6 additions & 2 deletions doc/html/quit.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <H3>Shortcuts:</H3>

<H3>Usage:</H3>
<BLOCKQUOTE>
<B>quit</B> [<B>-noprompt</B>]<BR><BR>
<B>quit</B> [<B>exit_status</B>] [<B>-noprompt</B>]<BR><BR>
</BLOCKQUOTE>

<H3>Summary:</H3>
Expand All @@ -46,8 +46,12 @@ <H3>Summary:</H3>
The Tcl <B>exit</B> command will <I>always</I> exit <B>magic</B>
immediately, without prompting or cleanup or any other niceties. <P>

The <B>exit_status</B> 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.<P>

With the <B>-noprompt</B> option, the interactive confirm prompt
does not occur so any changes will be discarded.
does not occur so any changes will be discarded. <P>
</BLOCKQUOTE>

<H3>Implementation Notes:</H3>
Expand Down
23 changes: 19 additions & 4 deletions windows/windCmdNR.c
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
Expand All @@ -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;
}

Expand All @@ -288,7 +303,7 @@ windQuitCmd(w, cmd)
return;
}

MainExit(0);
MainExit(exit_status);
}


Expand Down

0 comments on commit 71bc743

Please sign in to comment.