All from a report by Siteshwar Vashisht <svashisht@redhat.com>
+ 6/29
+ ----
+lib/readline/examples/histexamp.c,lib/readline/examples/manexamp.c,
+lib/readline/examples/rl-callbacktest.c,lib/readline/examples/rl-callbacktest2.c,
+lib/readline/examples/excallback.c,lib/readline/examples/rlptytest.c
+ - small changes to fix warnings
+ From a report by Hiroo Hayashi <hirooih@gmail.com>
+
+ 7/1
+ ---
+execute_cmd.c:
+ - ADJUST_LINE_NUMBER: encapsulate code that adjusts line_number in
+ shell functions executed in interactive shells into a macro
.\" Case Western Reserve University
.\" chet.ramey@case.edu
.\"
-.\" Last Change: Wed Jun 12 10:31:44 PDT 2024
+.\" Last Change: Mon Jul 1 09:46:16 EDT 2024
.\"
.\" bash_builtins, strip all but Built-Ins section
.\" avoid a warning about an undefined register
.\" .if !rzY .nr zY 0
.if \n(zZ=1 .ig zZ
.if \n(zY=1 .ig zY
-.TH BASH 1 "2024 June 12" "GNU Bash 5.3"
+.TH BASH 1 "2024 July 1" "GNU Bash 5.3"
.\"
.ie \n(.g \{\
.ds ' \(aq
This may be inhibited by using the
.B \-\-norc
option.
-The \fB\-\-rcfile\fP \fIfile\fP option will force
+The \fB\-\-rcfile\fP \fIfile\fP option will cause
.B bash
-to read and execute commands from \fIfile\fP instead of \fI\*~/.bashrc\fP.
+to replace \fI\*~/.bashrc\fP with \fIfile\fP.
.PP
When
.B bash
.B \-\-norc
option may be used to inhibit this behavior, and the
.B \-\-rcfile
-option may be used to force another file to be read, but neither
+option will make \fBbash\fP replace \fI\*~/.bashrc\fP with a different file,
+but neither
\fIrshd\fP nor \fIsshd\fP generally invoke the shell with those options
or allow them to be specified.
.PP
When an interactive shell that is not a login shell is started, Bash
reads and executes commands from @file{~/.bashrc}, if that file exists.
This may be inhibited by using the @option{--norc} option.
-The @option{--rcfile @var{file}} option will force Bash to read and
-execute commands from @var{file} instead of @file{~/.bashrc}.
+The @option{--rcfile @var{file}} option will
+cause Bash to
+replace @file{~/.bashrc} with @var{file}.
So, typically, your @file{~/.bash_profile} contains the line
@example
file exists and is readable.
It will not do this if invoked as @code{sh}.
The @option{--norc} option may be used to inhibit this behavior, and the
-@option{--rcfile} option may be used to force another file to be read, but
-neither @code{rshd} nor @code{sshd} generally invoke the shell with those
+@option{--rcfile} option
+will make Bash replace @file{~/.bashrc} with a different file,
+but neither
+@code{rshd} nor @code{sshd} generally invoke the shell with those
options or allow them to be specified.
@subsubheading Invoked with unequal effective and real @sc{uid/gid}s
Copyright (C) 1988-2024 Free Software Foundation, Inc.
@end ignore
-@set LASTCHANGE Wed Jun 12 10:34:52 PDT 2024
+@set LASTCHANGE Mon Jul 1 09:45:45 EDT 2024
@set EDITION 5.3
@set VERSION 5.3
-@set UPDATED 12 June 2024
-@set UPDATED-MONTH June 2024
+@set UPDATED 1 July 2024
+@set UPDATED-MONTH July 2024
? line_number_for_err_trap \
: executing_line_number ()
+/* We adjust the line number when executing shell functions in an interactive
+ shell. */
+#define ADJUST_LINE_NUMBER() \
+do { \
+ if (variable_context && interactive_shell && sourcelevel == 0) \
+ { \
+ /* line numbers in a function start at 1 */ \
+ line_number -= function_line_number - 1; \
+ if (line_number <= 0) \
+ line_number = 1; \
+ } \
+} while (0)
+
/* A sort of function nesting level counter */
int funcnest = 0;
int funcnest_max = 0;
line_number before executing each expression -- for $LINENO
and the DEBUG trap. */
line_number = arith_lineno = arith_for_command->line;
- if (variable_context && interactive_shell && sourcelevel == 0)
- {
- /* line numbers in a function start at 1 */
- line_number -= function_line_number - 1;
- if (line_number <= 0)
- line_number = 1;
- }
+ ADJUST_LINE_NUMBER ();
/* Evaluate the initialization expression. */
expresult = eval_arith_for_expr (arith_for_command->init, &expok);
this_command_name = "(("; /* )) */
SET_LINE_NUMBER (arith_command->line);
/* If we're in a function, update the line number information. */
- if (variable_context && interactive_shell && sourcelevel == 0)
- {
- /* line numbers in a function start at 1 */
- line_number -= function_line_number - 1;
- if (line_number <= 0)
- line_number = 1;
- }
+ ADJUST_LINE_NUMBER ();
command_string_index = 0;
print_arith_command (arith_command->exp);
SET_LINE_NUMBER (cond_command->line);
/* If we're in a function, update the line number information. */
- if (variable_context && interactive_shell && sourcelevel == 0)
- {
- /* line numbers in a function start at 1 */
- line_number -= function_line_number - 1;
- if (line_number <= 0)
- line_number = 1;
- }
+ ADJUST_LINE_NUMBER ();
+
command_string_index = 0;
print_cond_command (cond_command);
QUIT;
/* If we're in a function, update the line number information. */
- if (variable_context && interactive_shell && sourcelevel == 0)
- {
- /* line numbers in a function start at 1 */
- line_number -= function_line_number - 1;
- if (line_number <= 0)
- line_number = 1;
- }
+ ADJUST_LINE_NUMBER ();
/* Remember what this command line looks like at invocation. */
command_string_index = 0;
pipe_in, pipe_out, async, fds_to_close,
cmdflags);
-#if 0
-/* If we forked but still have to fork again to run the disk command, we
- did so because we created FIFOs. We can't just execve the command in case
- it dies of a signal without a chance to clean up the FIFOs, so we fork
- again, then make sure we wait for the child from execute_disk_command(),
- unlink the FIFOs we created, and exit ourselves. */
-if (dofork && already_forked && (cmdflags & CMD_NO_FORK) == 0)
- {
- result = wait_for (last_made_pid, 0);
-#if defined (PROCESS_SUBSTITUTION)
- if (fifos_pending ())
- unlink_fifo_list ();
-#endif
- sh_exit (result & 0xFF);
- }
-#endif
-
return_result:
bind_lastarg (lastarg);
FREE (command_line);
if (rl_point >= rl_end)
return (0);
- if (count < 0)
- @{
- direction = -1;
- count = -count;
- @}
- else
- direction = 1;
-
/* Find the end of the range to modify. */
- end = start + (count * direction);
+ end = start + count;
/* Force it to be within range. */
if (end > rl_end)
if (start == end)
return (0);
+ /* For positive arguments, put point after the last changed character. For
+ negative arguments, put point before the last changed character. */
+ rl_point = end;
+
+ /* Swap start and end if we are moving backwards */
if (start > end)
@{
int temp = start;
else if (_rl_lowercase_p (rl_line_buffer[i]))
rl_line_buffer[i] = _rl_to_upper (rl_line_buffer[i]);
@}
- /* Move point to on top of the last character changed. */
- rl_point = (direction == 1) ? end - 1 : start;
+
return (0);
@}
@end example
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <locale.h>
/* Used for select(2) */
#include <sys/types.h>
#include <signal.h>
+#include <errno.h>
#include <stdio.h>
+#include <locale.h>
+
/* Standard readline include files. */
#include <readline/readline.h>
#include <readline/history.h>
+#if !defined (errno)
+extern int errno;
+#endif
+
static void cb_linehandler (char *);
static void sighandler (int);
while (running)
@{
FD_ZERO (&fds);
- FD_SET (fileno (rl_instream), &fds);
+ FD_SET (fileno (rl_instream), &fds);
r = select (FD_SETSIZE, &fds, NULL, NULL, NULL);
if (r < 0 && errno != EINTR)
#ifdef READLINE_LIBRARY
# include "readline.h"
+# include "history.h"
#else
# include <readline/readline.h>
+# include <readline/history.h>
#endif
#ifndef STDIN_FILENO
*/
void process_line(char *line);
-int change_prompt(void);
+int change_prompt(int, int);
char *get_prompt(void);
int prompt = 1;
cc_t old_vtime;
struct termios term;
-int
+int
main(int c, char **v)
{
fd_set fds;
}
int
-change_prompt(void)
+change_prompt(int count, int key)
{
/* toggle the prompt variable */
prompt = !prompt;
- /* save away the current contents of the line */
- strcpy(line_buf, rl_line_buffer);
-
- /* install a new handler which will change the prompt and erase the current line */
- rl_callback_handler_install(get_prompt(), process_line);
-
- /* insert the old text on the new line */
- rl_insert_text(line_buf);
-
- /* redraw the current line - this is an undocumented function. It invokes the
- * redraw-current-line command.
- */
- rl_refresh_line(0, 0);
+ rl_set_prompt (get_prompt ());
+ return 0;
}
char *
get_prompt(void)
{
/* The prompts can even be different lengths! */
- sprintf(prompt_buf, "%s",
+ sprintf(prompt_buf, "%s",
prompt ? "Hit ctrl-t to toggle prompt> " : "Pretty cool huh?> ");
return prompt_buf;
}
# include <readline/history.h>
#endif
+#if !defined (errno)
extern int errno;
+#endif
static void cb_linehandler (char *);
static void signandler (int);
-int running, sigwinch_received;
+int running;
+int sigwinch_received;
const char *prompt = "rltest$ ";
/* Handle SIGWINCH and window size changes when readline is not active and
fd_set fds;
int r;
+ /* Set the default locale values according to environment variables. */
setlocale (LC_ALL, "");
- /* Handle SIGWINCH */
+ /* Handle window size changes when readline is not active and reading
+ characters. */
signal (SIGWINCH, sighandler);
/* Install the line handler. */
/* Used for select(2) */
#include <sys/types.h>
#include <sys/select.h>
-#include <errno.h>
#include <signal.h>
-#include <locale.h>
+#include <errno.h>
#include <stdio.h>
+#include <locale.h>
+
/* Standard readline include files. */
#if defined (READLINE_LIBRARY)
# include "readline.h"
# include <readline/history.h>
#endif
+#if !defined (errno)
+extern int errno;
+#endif
+
static void cb_linehandler (char *);
static void sigint_sighandler (int);
static int sigint_handler (int);
fd_set fds;
int r, err;
char *not_done = "";
-
+
/* Install the line handler. */
rl_callback_handler_install (prompt, cb_linehandler);
-if (RL_ISSTATE (RL_STATE_ISEARCH))
- fprintf(stderr, "cb_readline: after handler install, state (ISEARCH) = %d", rl_readline_state);
-else if (RL_ISSTATE (RL_STATE_NSEARCH))
- fprintf(stderr, "cb_readline: after handler install, state (NSEARCH) = %d", rl_readline_state);
-/* MULTIKEY VIMOTION NUMERICARG _rl_callback_func */
+ if (RL_ISSTATE (RL_STATE_ISEARCH))
+ fprintf(stderr, "cb_readline: after handler install, state (ISEARCH) = %lu", rl_readline_state);
+ else if (RL_ISSTATE (RL_STATE_NSEARCH))
+ fprintf(stderr, "cb_readline: after handler install, state (NSEARCH) = %lu", rl_readline_state);
+ /* MULTIKEY VIMOTION NUMERICARG _rl_callback_func */
FD_ZERO (&fds);
- FD_SET (fileno (rl_instream), &fds);
+ FD_SET (fileno (rl_instream), &fds);
input_string = not_done;
while (r == 0)
{
struct timeval timeout = {0, 100000};
- struct timeval *timeoutp = NULL;
+ struct timeval *timeoutp = NULL;
timeoutp = &timeout;
- FD_SET (fileno (rl_instream), &fds);
+ FD_SET (fileno (rl_instream), &fds);
r = select (FD_SETSIZE, &fds, NULL, NULL, timeoutp);
err = errno;
}
rl_cleanup_after_signal ();
rl_callback_handler_remove ();
saw_signal = 0;
-fprintf(stderr, "sigint_handler: readline state = %d\r\n", rl_readline_state);
return s;
}
#include <signal.h>
+/* Need a configure check here to turn this into a real application. */
#if 1 /* LINUX */
#include <pty.h>
#else
#ifdef READLINE_LIBRARY
# include "readline.h"
+# include "history.h"
#else
# include <readline/readline.h>
+# include <readline/history.h>
#endif
+int tty_reset(int fd);
+
/**
* Master/Slave PTY used to keep readline off of stdin/stdout.
*/
*
* Returns: 0 on success, -1 on error
*/
-int tty_reset(int fd)
+int
+tty_reset(int fd)
{
if(ttystate != TCBREAK)
return (0);