Bash-5.3-alpha release

This commit is contained in:
Chet Ramey
2024-04-22 10:33:38 -04:00
parent f3b6bd1945
commit 622d318652
700 changed files with 136534 additions and 96420 deletions
+68 -77
View File
@@ -1,6 +1,6 @@
/* bashhist.c -- bash interface to the GNU history library. */
/* Copyright (C) 1993-2021 Free Software Foundation, Inc.
/* Copyright (C) 1993-2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -68,10 +68,10 @@ extern int rl_done, rl_dispatching; /* should really include readline.h */
extern int errno;
#endif
static int histignore_item_func PARAMS((struct ign *));
static int check_history_control PARAMS((char *));
static void hc_erasedups PARAMS((char *));
static void really_add_history PARAMS((char *));
static int histignore_item_func (struct ign *);
static int check_history_control (char *);
static void hc_erasedups (char *);
static void really_add_history (char *);
static struct ignorevar histignore =
{
@@ -193,25 +193,27 @@ int hist_verify;
int dont_save_function_defs;
#if defined (BANG_HISTORY)
static int bash_history_inhibit_expansion PARAMS((char *, int));
/* The usual history no-expand characters plus the shell metacharacters that
would result in an empty history event. */
static char *bash_history_no_expand_chars = " \t\n\r=;&|()<>";
static int bash_history_inhibit_expansion (char *, int);
#endif
#if defined (READLINE)
static void re_edit PARAMS((char *));
static void re_edit (char *);
#endif
static int history_expansion_p PARAMS((char *));
static int shell_comment PARAMS((char *));
static int should_expand PARAMS((char *));
static HIST_ENTRY *last_history_entry PARAMS((void));
static char *expand_histignore_pattern PARAMS((char *));
static int history_should_ignore PARAMS((char *));
static int history_expansion_p (char *);
static int shell_comment (char *);
static int should_expand (char *);
static HIST_ENTRY *last_history_entry (void);
static char *expand_histignore_pattern (char *);
static int history_should_ignore (char *);
#if defined (BANG_HISTORY)
/* Is the history expansion starting at string[i] one that should not
be expanded? */
static int
bash_history_inhibit_expansion (string, i)
char *string;
int i;
bash_history_inhibit_expansion (char *string, int i)
{
int t, si;
char hx[2];
@@ -232,6 +234,7 @@ bash_history_inhibit_expansion (string, i)
else if (i > 1 && string[i - 1] == '$' && string[i] == '!')
return (1);
#if defined (EXTENDED_GLOB)
/* This is on all the time now; see bash_history_no_expand_characters above */
else if (extended_glob && i > 1 && string[i+1] == '(' && member (')', string + i + 2))
return (1);
#endif
@@ -267,30 +270,31 @@ bash_history_inhibit_expansion (string, i)
#endif
void
bash_initialize_history ()
bash_initialize_history (void)
{
history_quotes_inhibit_expansion = 1;
history_search_delimiter_chars = ";&()|<>";
#if defined (BANG_HISTORY)
history_inhibit_expansion_function = bash_history_inhibit_expansion;
history_no_expand_chars = bash_history_no_expand_chars;
sv_histchars ("histchars");
#endif
}
void
bash_history_reinit (interact)
int interact;
bash_history_reinit (int interact)
{
#if defined (BANG_HISTORY)
history_expansion = (interact == 0) ? histexp_flag : HISTEXPAND_DEFAULT;
history_expansion_inhibited = (interact == 0) ? 1 - histexp_flag : 0; /* changed in bash_history_enable() */
history_inhibit_expansion_function = bash_history_inhibit_expansion;
history_no_expand_chars = bash_history_no_expand_chars;
#endif
remember_on_history = enable_history_list;
}
void
bash_history_disable ()
bash_history_disable (void)
{
remember_on_history = 0;
#if defined (BANG_HISTORY)
@@ -299,12 +303,13 @@ bash_history_disable ()
}
void
bash_history_enable ()
bash_history_enable (void)
{
remember_on_history = enable_history_list = 1;
#if defined (BANG_HISTORY)
history_expansion_inhibited = 0;
history_inhibit_expansion_function = bash_history_inhibit_expansion;
history_no_expand_chars = bash_history_no_expand_chars;
#endif
sv_history_control ("HISTCONTROL");
sv_histignore ("HISTIGNORE");
@@ -312,7 +317,7 @@ bash_history_enable ()
/* Load the history list from the history file. */
void
load_history ()
load_history (void)
{
char *hf;
@@ -331,7 +336,8 @@ load_history ()
if (hf && *hf && file_exists (hf))
{
read_history (hf);
while (read_history (hf) == EINTR) /* 0 on success */
QUIT;
/* We have read all of the lines from the history file, even if we
read more lines than $HISTSIZE. Remember the total number of lines
we read so we don't count the last N lines as new over and over
@@ -343,7 +349,7 @@ load_history ()
}
void
bash_clear_history ()
bash_clear_history (void)
{
clear_history ();
history_lines_this_session = 0;
@@ -352,8 +358,7 @@ bash_clear_history ()
/* Delete and free the history list entry at offset I. */
int
bash_delete_histent (i)
int i;
bash_delete_histent (int i)
{
HIST_ENTRY *discard;
@@ -367,8 +372,7 @@ bash_delete_histent (i)
}
int
bash_delete_history_range (first, last)
int first, last;
bash_delete_history_range (int first, int last)
{
register int i;
HIST_ENTRY **discard_list;
@@ -385,7 +389,7 @@ bash_delete_history_range (first, last)
}
int
bash_delete_last_history ()
bash_delete_last_history (void)
{
register int i;
HIST_ENTRY **hlist, *histent;
@@ -412,10 +416,16 @@ bash_delete_last_history ()
return r;
}
char *
bash_default_histfile (void)
{
return (bash_tilde_expand (posixly_correct ? "~/.sh_history" : "~/.bash_history", 0));
}
#ifdef INCLUDE_UNUSED
/* Write the existing history out to the history file. */
void
save_history ()
save_history (void)
{
char *hf;
int r;
@@ -437,8 +447,7 @@ save_history ()
#endif
int
maybe_append_history (filename)
char *filename;
maybe_append_history (char *filename)
{
int fd, result, histlen;
struct stat buf;
@@ -476,7 +485,7 @@ maybe_append_history (filename)
/* If this is an interactive shell, then append the lines executed
this session to the history file. */
int
maybe_save_shell_history ()
maybe_save_shell_history (void)
{
int result;
char *hf;
@@ -523,8 +532,7 @@ maybe_save_shell_history ()
#if defined (READLINE)
/* Tell readline () that we have some text for it to edit. */
static void
re_edit (text)
char *text;
re_edit (char *text)
{
if (bash_input.type == st_stdin)
bash_re_edit (text);
@@ -533,8 +541,7 @@ re_edit (text)
/* Return 1 if this line needs history expansion. */
static int
history_expansion_p (line)
char *line;
history_expansion_p (char *line)
{
register char *s;
@@ -552,9 +559,7 @@ history_expansion_p (line)
REMEMBER_ON_HISTORY can veto, and does.
Right now this does history expansion. */
char *
pre_process_line (line, print_changes, addit)
char *line;
int print_changes, addit;
pre_process_line (char *line, int print_changes, int addit)
{
char *history_value;
char *return_value;
@@ -650,8 +655,7 @@ pre_process_line (line, print_changes, addit)
first non-whitespace character. Return 0 if the line does not contain a
comment. */
static int
shell_comment (line)
char *line;
shell_comment (char *line)
{
char *p;
int n;
@@ -672,8 +676,7 @@ shell_comment (line)
/* Remove shell comments from LINE. A `#' and anything after it is a comment.
This isn't really useful yet, since it doesn't handle quoting. */
static char *
filter_comments (line)
char *line;
filter_comments (char *line)
{
char *p;
@@ -688,8 +691,7 @@ filter_comments (line)
/* Check LINE against what HISTCONTROL says to do. Returns 1 if the line
should be saved; 0 if it should be discarded. */
static int
check_history_control (line)
char *line;
check_history_control (char *line)
{
HIST_ENTRY *temp;
int r;
@@ -721,8 +723,7 @@ check_history_control (line)
/* Remove all entries matching LINE from the history list. Triggered when
HISTCONTROL includes `erasedups'. */
static void
hc_erasedups (line)
char *line;
hc_erasedups (char *line)
{
HIST_ENTRY *temp;
int r;
@@ -756,8 +757,7 @@ hc_erasedups (line)
entered. We also make sure to save multiple-line quoted strings or other
constructs. */
void
maybe_add_history (line)
char *line;
maybe_add_history (char *line)
{
int is_comment;
@@ -786,9 +786,7 @@ maybe_add_history (line)
history if it's OK. Used by `history -s' as well as maybe_add_history().
Returns 1 if the line was saved in the history, 0 otherwise. */
int
check_add_history (line, force)
char *line;
int force;
check_add_history (char *line, int force)
{
if (check_history_control (line) && history_should_ignore (line) == 0)
{
@@ -825,8 +823,7 @@ int syslog_history = 1;
#endif
void
bash_syslog_history (line)
const char *line;
bash_syslog_history (const char *line)
{
char trunc[SYSLOG_MAXLEN], *msg;
char loghdr[SYSLOG_MAXHDR];
@@ -869,10 +866,10 @@ bash_syslog_history (line)
complete parser construct, append LINE to the last history line instead
of adding it as a new line. */
void
bash_add_history (line)
char *line;
bash_add_history (char *line)
{
int add_it, offset, curlen, is_comment;
int add_it, offset, is_comment;
size_t curlen;
HIST_ENTRY *current, *old;
char *chars_to_add, *new_line;
@@ -913,8 +910,8 @@ bash_add_history (line)
newline, since that is what happens when the line is parsed. */
curlen = strlen (current->line);
if (dstack.delimiter_depth == 0 && current->line[curlen - 1] == '\\' &&
current->line[curlen - 2] != '\\')
if (dstack.delimiter_depth == 0 && curlen > 0 && current->line[curlen - 1] == '\\' &&
(curlen < 2 || current->line[curlen - 2] != '\\'))
{
current->line[curlen - 1] = '\0';
curlen--;
@@ -925,7 +922,7 @@ bash_add_history (line)
entry ends with a newline, and we're going to add a semicolon,
don't. In some cases, it results in a syntax error (e.g., before
a close brace), and it should not be needed. */
if (dstack.delimiter_depth == 0 && current->line[curlen - 1] == '\n' && *chars_to_add == ';')
if (dstack.delimiter_depth == 0 && curlen > 0 && current->line[curlen - 1] == '\n' && *chars_to_add == ';')
chars_to_add++;
new_line = (char *)xmalloc (1
@@ -959,8 +956,7 @@ bash_add_history (line)
}
static void
really_add_history (line)
char *line;
really_add_history (char *line)
{
hist_last_line_added = 1;
hist_last_line_pushed = 0;
@@ -969,15 +965,14 @@ really_add_history (line)
}
int
history_number ()
history_number (void)
{
using_history ();
return ((remember_on_history || enable_history_list) ? history_base + where_history () : 1);
}
static int
should_expand (s)
char *s;
static inline int
should_expand (char *s)
{
char *p;
@@ -992,8 +987,7 @@ should_expand (s)
}
static int
histignore_item_func (ign)
struct ign *ign;
histignore_item_func (struct ign *ign)
{
if (should_expand (ign->val))
ign->flags |= HIGN_EXPAND;
@@ -1001,14 +995,13 @@ histignore_item_func (ign)
}
void
setup_history_ignore (varname)
char *varname;
setup_history_ignore (const char *varname)
{
setup_ignore_patterns (&histignore);
}
static HIST_ENTRY *
last_history_entry ()
last_history_entry (void)
{
HIST_ENTRY *he;
@@ -1019,7 +1012,7 @@ last_history_entry ()
}
char *
last_history_line ()
last_history_line (void)
{
HIST_ENTRY *he;
@@ -1030,8 +1023,7 @@ last_history_line ()
}
static char *
expand_histignore_pattern (pat)
char *pat;
expand_histignore_pattern (char *pat)
{
HIST_ENTRY *phe;
char *ret;
@@ -1049,8 +1041,7 @@ expand_histignore_pattern (pat)
/* Return 1 if we should not put LINE into the history according to the
patterns in HISTIGNORE. */
static int
history_should_ignore (line)
char *line;
history_should_ignore (char *line)
{
register int i, match;
char *npat;