commit 56ce5f2ba8e2e3e4d440dd9e03bc08cef883ad4b
parent 5ebdd3fe6e7e038ed0c8394bfee4f5ccb8510066
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Fri, 23 Jun 2017 09:27:29 +0200
tweaks: rename a function and a variable, to better match what they do
Also improve some comments.
Diffstat:
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/src/nano.c b/src/nano.c
@@ -59,6 +59,9 @@ static struct termios oldterm;
static struct sigaction act;
/* Used to set up all our fun signal handlers. */
+static bool input_was_aborted = FALSE;
+ /* Whether reading from standard input was aborted via ^C. */
+
/* Create a new linestruct node. Note that we do not set prevnode->next
* to the new line. */
filestruct *make_new_node(filestruct *prevnode)
@@ -1100,13 +1103,10 @@ void do_cancel(void)
;
}
-static bool pager_input_aborted = FALSE;
- /* Did someone invoke the pager and abort it via ^C? */
-
-/* Cancel reading from stdin like a pager. */
-RETSIGTYPE cancel_stdin_pager(int signal)
+/* Make a note that reading from stdin was concluded with ^C. */
+RETSIGTYPE make_a_note(int signal)
{
- pager_input_aborted = TRUE;
+ input_was_aborted = TRUE;
}
/* Read whatever comes from standard input into a new buffer. */
@@ -1136,7 +1136,7 @@ bool scoop_stdin(void)
setup_failed = TRUE;
nperror("sigaction");
} else {
- newaction.sa_handler = cancel_stdin_pager;
+ newaction.sa_handler = make_a_note;
if (sigaction(SIGINT, &newaction, &oldaction) == -1) {
setup_failed = TRUE;
nperror("sigaction");
@@ -1166,8 +1166,11 @@ bool scoop_stdin(void)
dup2(thetty, 0);
close(thetty);
- if (!pager_input_aborted)
+ /* If things went well, store the current state of the terminal. */
+ if (!input_was_aborted)
tcgetattr(0, &oldterm);
+
+ /* If it was changed, restore the handler for SIGINT. */
if (!setup_failed && sigaction(SIGINT, &oldaction, NULL) == -1)
nperror("sigaction");