aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--readline/readline/callback.c8
-rw-r--r--readline/readline/doc/rltech.texi11
-rw-r--r--readline/readline/readline.c19
-rw-r--r--readline/readline/readline.h8
-rw-r--r--readline/readline/rlprivate.h1
-rw-r--r--readline/readline/rltty.c4
6 files changed, 39 insertions, 12 deletions
diff --git a/readline/readline/callback.c b/readline/readline/callback.c
index a466cf9..58b84d2 100644
--- a/readline/readline/callback.c
+++ b/readline/readline/callback.c
@@ -1,6 +1,6 @@
/* callback.c -- functions to use readline as an X `callback' mechanism. */
-/* Copyright (C) 1987-2017 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
@@ -136,6 +136,8 @@ rl_callback_read_char (void)
abort ();
}
+ eof = 0;
+
memcpy ((void *)olevel, (void *)_rl_top_level, sizeof (procenv_t));
#if defined (HAVE_POSIX_SIGSETJMP)
jcode = sigsetjmp (_rl_top_level, 0);
@@ -268,6 +270,10 @@ rl_callback_read_char (void)
_rl_want_redisplay = 0;
}
+ /* Make sure application hooks can see whether we saw EOF. */
+ if (rl_eof_found = eof)
+ RL_SETSTATE(RL_STATE_EOF);
+
if (rl_done)
{
line = readline_internal_teardown (eof);
diff --git a/readline/readline/doc/rltech.texi b/readline/readline/doc/rltech.texi
index bbf57c2..797e34d 100644
--- a/readline/readline/doc/rltech.texi
+++ b/readline/readline/doc/rltech.texi
@@ -323,6 +323,14 @@ and point define a @emph{region}.
@deftypevar int rl_done
Setting this to a non-zero value causes Readline to return the current
line immediately.
+Readline will set this variable when it has read a key sequence bound
+to @code{accept-line} and is about to return the line to the caller.
+@end deftypevar
+
+@deftypevar int rl_eof_found
+Readline will set this variable when it has read an EOF character (e.g., the
+stty @samp{EOF} character) on an empty line or encountered a read error and
+is about to return a NULL line to the caller.
@end deftypevar
@deftypevar int rl_num_chars_to_read
@@ -588,6 +596,9 @@ the current call to @code{readline()}.
@item RL_STATE_DONE
Readline has read a key sequence bound to @code{accept-line}
and is about to return the line to the caller.
+@item RL_STATE_EOF
+Readline has read an EOF character (e.g., the stty @samp{EOF} character)
+or encountered a read error and is about to return a NULL line to the caller.
@end table
@end deftypevar
diff --git a/readline/readline/readline.c b/readline/readline/readline.c
index e61d188..0e33587 100644
--- a/readline/readline/readline.c
+++ b/readline/readline/readline.c
@@ -1,7 +1,7 @@
/* readline.c -- a general facility for reading lines of input
with emacs style editing and completion. */
-/* Copyright (C) 1987-2020 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
@@ -165,6 +165,9 @@ int rl_end;
/* Make this non-zero to return the current input_line. */
int rl_done;
+/* If non-zero when readline_internal returns, it means we found EOF */
+int rl_eof_found = 0;
+
/* The last function executed by readline. */
rl_command_func_t *rl_last_func = (rl_command_func_t *)NULL;
@@ -218,9 +221,6 @@ int _rl_eof_char = CTRL ('D');
/* Non-zero makes this the next keystroke to read. */
int rl_pending_input = 0;
-/* If non-zero when readline_internal returns, it means we found EOF */
-int _rl_eof_found = 0;
-
/* Pointer to a useful terminal name. */
const char *rl_terminal_name = (const char *)NULL;
@@ -474,6 +474,9 @@ readline_internal_teardown (int eof)
RL_CHECK_SIGNALS ();
+ if (eof)
+ RL_SETSTATE (RL_STATE_EOF); /* XXX */
+
/* Restore the original of this history line, iff the line that we
are editing was originally in the history, AND the line has changed. */
entry = current_history ();
@@ -596,6 +599,7 @@ readline_internal_charloop (void)
RL_SETSTATE(RL_STATE_DONE);
return (rl_done = 1);
#else
+ RL_SETSTATE(RL_STATE_EOF);
eof_found = 1;
break;
#endif
@@ -636,6 +640,7 @@ readline_internal_charloop (void)
RL_SETSTATE(RL_STATE_DONE);
return (rl_done = 1);
#else
+ RL_SETSTATE(RL_STATE_EOF);
eof_found = 1;
break;
#endif
@@ -703,8 +708,8 @@ static char *
readline_internal (void)
{
readline_internal_setup ();
- _rl_eof_found = readline_internal_charloop ();
- return (readline_internal_teardown (_rl_eof_found));
+ rl_eof_found = readline_internal_charloop ();
+ return (readline_internal_teardown (rl_eof_found));
}
void
@@ -1161,7 +1166,7 @@ rl_initialize (void)
/* We aren't done yet. We haven't even gotten started yet! */
rl_done = 0;
- RL_UNSETSTATE(RL_STATE_DONE);
+ RL_UNSETSTATE(RL_STATE_DONE|RL_STATE_EOF);
/* Tell the history routines what is going on. */
_rl_start_using_history ();
diff --git a/readline/readline/readline.h b/readline/readline/readline.h
index 78fa39d..9f79810 100644
--- a/readline/readline/readline.h
+++ b/readline/readline/readline.h
@@ -1,6 +1,6 @@
/* Readline.h -- the names of functions callable from within readline. */
-/* Copyright (C) 1987-2020 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
@@ -553,6 +553,10 @@ extern int rl_mark;
line and should return it. */
extern int rl_done;
+/* Flag to indicate that readline has read an EOF character or read has
+ returned 0 or error, and is returning a NULL line as a result. */
+extern int rl_eof_found;
+
/* If set to a character value, that will be the next keystroke read. */
extern int rl_pending_input;
@@ -906,6 +910,8 @@ extern int rl_persistent_signal_handlers;
#define RL_STATE_REDISPLAYING 0x1000000 /* updating terminal display */
#define RL_STATE_DONE 0x2000000 /* done; accepted line */
+#define RL_STATE_EOF 0x8000000 /* done; got eof on read */
+
#define RL_SETSTATE(x) (rl_readline_state |= (x))
#define RL_UNSETSTATE(x) (rl_readline_state &= ~(x))
diff --git a/readline/readline/rlprivate.h b/readline/readline/rlprivate.h
index 23ab2d8..02838ae 100644
--- a/readline/readline/rlprivate.h
+++ b/readline/readline/rlprivate.h
@@ -544,7 +544,6 @@ extern FILE *_rl_in_stream;
extern FILE *_rl_out_stream;
extern int _rl_last_command_was_kill;
extern int _rl_eof_char;
-extern int _rl_eof_found;
extern procenv_t _rl_top_level;
extern _rl_keyseq_cxt *_rl_kscxt;
extern int _rl_keyseq_timeout;
diff --git a/readline/readline/rltty.c b/readline/readline/rltty.c
index d0cd572..11997b7 100644
--- a/readline/readline/rltty.c
+++ b/readline/readline/rltty.c
@@ -1,7 +1,7 @@
/* rltty.c -- functions to prepare and restore the terminal for readline's
use. */
-/* Copyright (C) 1992-2017 Free Software Foundation, Inc.
+/* Copyright (C) 1992-2022 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
@@ -692,7 +692,7 @@ rl_deprep_terminal (void)
if (terminal_prepped & TPX_BRACKPASTE)
{
fprintf (rl_outstream, BRACK_PASTE_FINI);
- if (_rl_eof_found)
+ if (rl_eof_found)
fprintf (rl_outstream, "\n");
}