From 1a1ddcd520801697eec2b5e2638f102eaf5fa056 Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Tue, 8 Oct 2024 08:46:19 +0100 Subject: [PATCH 1/3] feat: flush [-noprompt], option support --- commands/CmdFI.c | 15 ++++++++++++--- doc/html/flush.html | 6 +++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/commands/CmdFI.c b/commands/CmdFI.c index cfd4066b..314dd20e 100644 --- a/commands/CmdFI.c +++ b/commands/CmdFI.c @@ -943,6 +943,7 @@ CmdFlush(w, cmd) static char *actionNames[] = { "no", "yes", 0 }; char *prompt; bool dereference = FALSE; + bool noprompt = FALSE; /* no interactive confirm when changed */ if (!strncmp(cmd->tx_argv[cmd->tx_argc - 1], "-deref", 6)) { @@ -950,9 +951,15 @@ CmdFlush(w, cmd) cmd->tx_argc--; } + if (!strcmp(cmd->tx_argv[cmd->tx_argc - 1], "-noprompt")) + { + noprompt = TRUE; + cmd->tx_argc--; + } + if (cmd->tx_argc > 2) { - TxError("Usage: flush [cellname] [dereference]\n"); + TxError("Usage: flush [cellname] [-noprompt] [-dereference]\n"); return; } @@ -973,7 +980,9 @@ CmdFlush(w, cmd) } } - if (def->cd_flags & (CDMODIFIED|CDSTAMPSCHANGED|CDBOXESCHANGED)) + bool has_changes = (def->cd_flags & (CDMODIFIED|CDSTAMPSCHANGED|CDBOXESCHANGED)) != 0; + + if (!noprompt && has_changes) { prompt = TxPrintString("Really throw away all changes made" " to cell %s? ", def->cd_name); @@ -984,7 +993,7 @@ CmdFlush(w, cmd) cmdFlushCell(def, dereference); SelectClear(); - TxPrintf("[Flushed]\n"); + TxPrintf("[Flushed%s]\n", has_changes ? " Modifications were Discarded" : ""); } diff --git a/doc/html/flush.html b/doc/html/flush.html index 6ee7be30..8ae2b68f 100644 --- a/doc/html/flush.html +++ b/doc/html/flush.html @@ -26,7 +26,7 @@

flush

Usage:

- flush [cellname] [-dereference]

+ flush [cellname] [-noprompt] [-dereference]

where cellname is the name of a cell definition to be flushed. @@ -43,6 +43,10 @@

Summary:

The effects of the flush command are irrevocable; the command cannot be undone with an undo command.

+ With the -noprompt option, no interactive confirmation is + presented if there are unsaved changes. Those changes will be + flushed. + With the -dereference option, any file path that has been associated with the cell is discarded, and the cell is reloaded from the first location found in the search path. With search From 31c8c1a56cd3d0dde2a661a869af052f478c8576 Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Tue, 8 Oct 2024 08:51:28 +0100 Subject: [PATCH 2/3] docs: quit -noprompt Was looking to implement this feature and found it was already implemented but is a secret feature. Updated documentation and modified implementation so it is possible a user can discover the feature via usage such as "quit -help -invalid" like other commands. --- doc/html/quit.html | 5 ++++- windows/windCmdNR.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/doc/html/quit.html b/doc/html/quit.html index 2bff2e41..e263a1a8 100644 --- a/doc/html/quit.html +++ b/doc/html/quit.html @@ -31,7 +31,7 @@

Shortcuts:

Usage:

- quit

+ quit [-noprompt]

Summary:

@@ -45,6 +45,9 @@

Summary:

and the Tcl exit command is required to quit the program. The Tcl exit command will always exit magic immediately, without prompting or cleanup or any other niceties.

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

Implementation Notes:

diff --git a/windows/windCmdNR.c b/windows/windCmdNR.c index b550bd2e..48fb5fe7 100644 --- a/windows/windCmdNR.c +++ b/windows/windCmdNR.c @@ -265,15 +265,28 @@ windQuitCmd(w, cmd) bool checkfirst = TRUE; if (cmd->tx_argc == 2) + { if (!strcmp(cmd->tx_argv[1], "-noprompt")) + { checkfirst = FALSE; + cmd->tx_argc--; + } + } + + if (cmd->tx_argc > 1) + { + TxError("Usage: quit [-noprompt]\n"); + return; + } if (checkfirst) + { for (cr = windFirstClientRec; cr != (clientRec *) NULL; cr = cr->w_nextClient) if (cr->w_exit != NULL) if (!(*(cr->w_exit))()) return; + } MainExit(0); } From 71bc7438155ef7658be7850f049c9615a67eb60c Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Tue, 8 Oct 2024 08:58:20 +0100 Subject: [PATCH 3/3] 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 @@

Shortcuts:

Usage:

- quit [-noprompt]

+ quit [exit_status] [-noprompt]

Summary:

@@ -46,8 +46,12 @@

Summary:

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 48fb5fe7..9c50a565 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); }