Hi Chet, I don't really know how readline development works, but I wondered if it would be at all helpful if I supplied a slightly more complete patch.
The patch below renames _rl_eof_found to rl_eof_found, and moves the declaration into the readline.h header file. I've updated doc/rltech.texi to mention this variable, though I've not regenerated any of the final doc formats, which I note are also part of the repo. Finally, I've added a line to callback.c to set rl_eof_found. Inline with your suggestions here: https://lists.gnu.org/archive/html/bug-readline/2022-02/msg00024.html I've just assigned to rl_eof_found from eof, rather than replacing the use of eof with rl_eof_found throughout rl_callback_read_char. You did mention here: https://lists.gnu.org/archive/html/bug-readline/2022-02/msg00026.html Both having rl_eof_found _and_ adding a new state flag. I've not done that here, I figure this is a minimal patch that would resolve the issues I was seeing. If having the state flag is a requirement then I'm happy to rewrite this patch to include that, or that state flag could be added later. If there's anything at all that I can do to facilitate landing this, or anything equivalent into readline, then please do let me know. Many thanks, Andrew --- commit 021341e37a3dc7c4e6c3849eaf32bfeb069907a4 Author: Andrew Burgess <[email protected]> Date: Thu Mar 3 10:50:19 2022 +0000 add rl_eof_found to the api, and set correctly for callback api Currently _rl_eof_found is only set for the traditional (non-callback) api. This commit ensures that _rl_eof_found is also set for the callback api. Additionally, this commit renamed _rl_eof_found to rl_eof_found, and makes this variable part of the advertised api. The documentation is updated to include mention of this variable. diff --git a/callback.c b/callback.c index a466cf9..5624781 100644 --- a/callback.c +++ b/callback.c @@ -127,7 +127,7 @@ void rl_callback_read_char (void) { char *line; - int eof, jcode; + int eof = 0, jcode; static procenv_t olevel; if (rl_linefunc == NULL) @@ -261,6 +261,8 @@ rl_callback_read_char (void) else eof = readline_internal_char (); + rl_eof_found = eof; + RL_CHECK_SIGNALS (); if (rl_done == 0 && _rl_want_redisplay) { diff --git a/doc/rltech.texi b/doc/rltech.texi index bbf57c2..4c98d21 100644 --- a/doc/rltech.texi +++ b/doc/rltech.texi @@ -325,6 +325,13 @@ line immediately. @end deftypevar +@deftypevar int rl_eof_found +Set to a non-zero value if readline encountered @code{EOF}, zero +otherwise. Application functions can test this to discover if the +user has sent @code{EOF}. + +@end deftypevar + @deftypevar int rl_num_chars_to_read Setting this to a positive value before calling @code{readline()} causes Readline to return after accepting that many characters, rather diff --git a/readline.c b/readline.c index e61d188..e315209 100644 --- a/readline.c +++ b/readline.c @@ -218,8 +218,8 @@ 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; +/* Non-zero when EOF is found at the end of the input line. */ +int rl_eof_found = 0; /* Pointer to a useful terminal name. */ const char *rl_terminal_name = (const char *)NULL; @@ -703,8 +703,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 diff --git a/readline.h b/readline.h index 78fa39d..b51e327 100644 --- a/readline.h +++ b/readline.h @@ -553,6 +553,10 @@ extern int rl_mark; line and should return it. */ extern int rl_done; +/* Flag to indicate that readline has encountered EOF at the end of the + current input line. */ +extern int rl_eof_found; + /* If set to a character value, that will be the next keystroke read. */ extern int rl_pending_input; diff --git a/rlprivate.h b/rlprivate.h index 23ab2d8..02838ae 100644 --- a/rlprivate.h +++ b/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/rltty.c b/rltty.c index d0cd572..b5e9199 100644 --- a/rltty.c +++ b/rltty.c @@ -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"); }
