]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
updates for several readline examples; update examples in readline documentation...
authorChet Ramey <chet.ramey@case.edu>
Tue, 2 Jul 2024 18:34:40 +0000 (14:34 -0400)
committerChet Ramey <chet.ramey@case.edu>
Tue, 2 Jul 2024 18:34:40 +0000 (14:34 -0400)
CWRU/CWRU.chlog
doc/bash.1
doc/bashref.texi
doc/version.texi
execute_cmd.c
lib/readline/doc/rltech.texi
lib/readline/examples/excallback.c
lib/readline/examples/rl-callbacktest.c
lib/readline/examples/rl-callbacktest2.c
lib/readline/examples/rlptytest.c

index b716927aadcf2b516005402fa63f982cc5168d77..c68cbbbaf47c029c1de978f8e2acbb153259e41f 100644 (file)
@@ -9721,3 +9721,16 @@ lib/readline/funmap.c
 
          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
index c1df375434b78459b24e01c3237f1f2019d49f90..07c0f4048bb34453ef0d9cce583d2012e89733cd 100644 (file)
@@ -5,14 +5,14 @@
 .\"    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
@@ -351,9 +351,9 @@ reads and executes commands from \fI\*~/.bashrc\fP, if that file exists.
 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
@@ -448,7 +448,8 @@ The
 .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
index 2e52db8f324ca2884c552442a30dbf4607c1b423..cd2e7b281e325c4cc85d7c072a73a46176195b57 100644 (file)
@@ -7368,8 +7368,9 @@ the file @file{~/.bash_logout}, if it exists.
 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
@@ -7441,8 +7442,10 @@ it reads and executes commands from @file{~/.bashrc}, if that
 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
index a4c26ca457ed8a37de993143a0d765244a0065ef..bef2da69ba65b9d3aa4e8cc7340fe3025b6296dd 100644 (file)
@@ -2,10 +2,10 @@
 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
index 1596eae1faf2913a0b30ab91ed40477854548e7b..0142d3d90dd5e341fe07afab3b3b17c96771318d 100644 (file)
@@ -307,6 +307,19 @@ do { \
     ? 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;
@@ -3196,13 +3209,7 @@ execute_arith_for_command (ARITH_FOR_COM *arith_for_command)
      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);
@@ -3871,13 +3878,7 @@ execute_arith_command (ARITH_COM *arith_command)
   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);
@@ -4111,13 +4112,8 @@ execute_cond_command (COND_COM *cond_command)
 
   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);
 
@@ -4458,13 +4454,7 @@ execute_simple_command (SIMPLE_COM *simple_command, int pipe_in, int pipe_out, i
   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;
@@ -4916,23 +4906,6 @@ execute_from_filesystem:
                        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);
index 497cd4d1fbcf7359580b18005b7e38805cb2850e..56519d532e0dc8cdb5a0cd75d4f3ba653039394b 100644 (file)
@@ -1526,16 +1526,8 @@ invert_case_line (count, key)
   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)
@@ -1546,6 +1538,11 @@ invert_case_line (count, key)
   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;
@@ -1564,8 +1561,7 @@ invert_case_line (count, key)
       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
@@ -1583,7 +1579,6 @@ It understands the EOF character or "exit" to exit the program.
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <locale.h>
 
 /* Used for select(2) */
 #include <sys/types.h>
@@ -1591,12 +1586,19 @@ It understands the EOF character or "exit" to exit the program.
 
 #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);
 
@@ -1664,7 +1666,7 @@ main (int c, char **v)
   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)
index e8839d2686bbf61c06e9f0b043b93541b90d21cc..3f2744ee65315238e0f9d08ffed7c35f9ccd3a3a 100644 (file)
@@ -54,8 +54,10 @@ Copyright (C) 1999 Jeff Solomon
 
 #ifdef READLINE_LIBRARY
 #  include "readline.h"
+#  include "history.h"
 #else
 #  include <readline/readline.h>
+#  include <readline/history.h>
 #endif
 
 #ifndef STDIN_FILENO
@@ -92,7 +94,7 @@ Copyright (C) 1999 Jeff Solomon
  */
 
 void process_line(char *line);
-int  change_prompt(void);
+int  change_prompt(int, int);
 char *get_prompt(void);
 
 int prompt = 1;
@@ -101,7 +103,7 @@ tcflag_t old_lflag;
 cc_t     old_vtime;
 struct termios term;
 
-int 
+int
 main(int c, char **v)
 {
     fd_set fds;
@@ -170,31 +172,20 @@ process_line(char *line)
 }
 
 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;
 }
index 7febacd14c47f69ddc9f71cfbc2d6e9b6791b8b8..b6b38e8e5817032667ae1f485789b7ac41ba28cb 100644 (file)
 #  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
@@ -73,9 +76,11 @@ main (int c, char **v)
   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. */
index 0bf0641c984ff88af3eda9b77e27344005db72fd..84904d53565b9dcc14a932554252588802b0658e 100644 (file)
@@ -6,13 +6,14 @@
 /* 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);
@@ -51,18 +56,18 @@ cb_readline (void)
   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;
 
@@ -76,10 +81,10 @@ else if (RL_ISSTATE (RL_STATE_NSEARCH))
       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;
        }
@@ -115,7 +120,6 @@ sigint_handler (int s)
   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;  
 }
 
index 021a868b042060081318f219d487f53f91f4d292..226444120b714ec47e46860402af74517607c72f 100644 (file)
@@ -19,6 +19,7 @@
 
 #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.
  */
@@ -301,7 +306,8 @@ tty_off_xon_xoff (int fd)
  * 
  * Returns: 0 on success, -1 on error
  */
-int tty_reset(int fd)
+int
+tty_reset(int fd)
 {
    if(ttystate != TCBREAK)
       return (0);