Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR#340 alternative ? flush -noconfirm .. exit exit_status -noconfirm #341

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions commands/CmdFI.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,16 +943,23 @@ 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))
{
dereference = TRUE;
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;
}

Expand All @@ -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);
Expand All @@ -984,7 +993,7 @@ CmdFlush(w, cmd)

cmdFlushCell(def, dereference);
SelectClear();
TxPrintf("[Flushed]\n");
TxPrintf("[Flushed%s]\n", has_changes ? " Modifications were Discarded" : "");
}


Expand Down
6 changes: 5 additions & 1 deletion doc/html/flush.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <H2>flush</H2>

<H3>Usage:</H3>
<BLOCKQUOTE>
<B>flush</B> [<I>cellname</I>] [<B>-dereference</B>]<BR><BR>
<B>flush</B> [<I>cellname</I>] [<B>-noprompt</B>] [<B>-dereference</B>]<BR><BR>
<BLOCKQUOTE>
where <I>cellname</I> is the name of a cell definition to be
flushed.
Expand All @@ -43,6 +43,10 @@ <H3>Summary:</H3>
The effects of the <B>flush</B> command are irrevocable; the
command cannot be undone with an <B>undo</B> command. <P>

With the <B>-noprompt</B> option, no interactive confirmation is
presented if there are unsaved changes. Those changes will be
flushed.

With the <B>-dereference</B> 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
Expand Down
9 changes: 8 additions & 1 deletion 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> <BR><BR>
<B>quit</B> [<B>exit_status</B>] [<B>-noprompt</B>]<BR><BR>
</BLOCKQUOTE>

<H3>Summary:</H3>
Expand All @@ -45,6 +45,13 @@ <H3>Summary:</H3>
and the Tcl <B>exit</B> command is required to quit the program.
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. <P>
</BLOCKQUOTE>

<H3>Implementation Notes:</H3>
Expand Down
34 changes: 31 additions & 3 deletions windows/windCmdNR.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,47 @@ windQuitCmd(w, cmd)
{
clientRec *cr;
bool checkfirst = TRUE;
int exit_status = 0;

if (cmd->tx_argc == 2)
if (!strcmp(cmd->tx_argv[1], "-noprompt"))
if (cmd->tx_argc > 1)
{
if (!strcmp(cmd->tx_argv[cmd->tx_argc - 1], "-noprompt"))
{
checkfirst = FALSE;
cmd->tx_argc--;
}
}

if (cmd->tx_argc > 1)
{
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;
}

if (checkfirst)
{
for (cr = windFirstClientRec; cr != (clientRec *) NULL;
cr = cr->w_nextClient)
if (cr->w_exit != NULL)
if (!(*(cr->w_exit))())
return;
}

MainExit(0);
MainExit(exit_status);
}


Expand Down