mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-13 15:10:49 +02:00
Bash-4.4 distribution sources and documentation
This commit is contained in:
+69
-14
@@ -1,6 +1,6 @@
|
||||
/* bashhist.c -- bash interface to the GNU history library. */
|
||||
|
||||
/* Copyright (C) 1993-2012 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1993-2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
@@ -83,8 +83,8 @@ static struct ignorevar histignore =
|
||||
/* Non-zero means to remember lines typed to the shell on the history
|
||||
list. This is different than the user-controlled behaviour; this
|
||||
becomes zero when we read lines from a file, for example. */
|
||||
int remember_on_history = 1;
|
||||
int enable_history_list = 1; /* value for `set -o history' */
|
||||
int remember_on_history = 0;
|
||||
int enable_history_list = 0; /* value for `set -o history' */
|
||||
|
||||
/* The number of lines that Bash has added to this history session. The
|
||||
difference between the number of the top element in the history list
|
||||
@@ -99,6 +99,8 @@ int history_lines_in_file;
|
||||
/* Non-zero means do no history expansion on this line, regardless
|
||||
of what history_expansion says. */
|
||||
int history_expansion_inhibited;
|
||||
/* If non-zero, double quotes can quote the history expansion character. */
|
||||
int double_quotes_inhibit_history_expansion = 0;
|
||||
#endif
|
||||
|
||||
/* With the old default, every line was saved in the history individually.
|
||||
@@ -186,7 +188,9 @@ extern int current_command_line_count;
|
||||
extern struct dstack dstack;
|
||||
extern int parser_state;
|
||||
|
||||
#if defined (BANG_HISTORY)
|
||||
static int bash_history_inhibit_expansion __P((char *, int));
|
||||
#endif
|
||||
#if defined (READLINE)
|
||||
static void re_edit __P((char *));
|
||||
#endif
|
||||
@@ -197,6 +201,7 @@ static HIST_ENTRY *last_history_entry __P((void));
|
||||
static char *expand_histignore_pattern __P((char *));
|
||||
static int history_should_ignore __P((char *));
|
||||
|
||||
#if defined (BANG_HISTORY)
|
||||
/* Is the history expansion starting at string[i] one that should not
|
||||
be expanded? */
|
||||
static int
|
||||
@@ -204,6 +209,12 @@ bash_history_inhibit_expansion (string, i)
|
||||
char *string;
|
||||
int i;
|
||||
{
|
||||
int t;
|
||||
char hx[2];
|
||||
|
||||
hx[0] = history_expansion_char;
|
||||
hx[1] = '\0';
|
||||
|
||||
/* The shell uses ! as a pattern negation character in globbing [...]
|
||||
expressions, so let those pass without expansion. */
|
||||
if (i > 0 && (string[i - 1] == '[') && member (']', string + i + 1))
|
||||
@@ -220,17 +231,33 @@ bash_history_inhibit_expansion (string, i)
|
||||
else if (extended_glob && i > 1 && string[i+1] == '(' && member (')', string + i + 2))
|
||||
return (1);
|
||||
#endif
|
||||
|
||||
/* Make sure the history expansion should not be skipped by quoting or
|
||||
command/process substitution. */
|
||||
else if ((t = skip_to_histexp (string, 0, hx, SD_NOJMP|SD_HISTEXP)) > 0)
|
||||
{
|
||||
/* Skip instances of history expansion appearing on the line before
|
||||
this one. */
|
||||
while (t < i)
|
||||
{
|
||||
t = skip_to_histexp (string, t+1, hx, SD_NOJMP|SD_HISTEXP);
|
||||
if (t <= 0)
|
||||
return 0;
|
||||
}
|
||||
return (t > i);
|
||||
}
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
bash_initialize_history ()
|
||||
{
|
||||
history_quotes_inhibit_expansion = 1;
|
||||
history_search_delimiter_chars = ";&()|<>";
|
||||
history_inhibit_expansion_function = bash_history_inhibit_expansion;
|
||||
#if defined (BANG_HISTORY)
|
||||
history_inhibit_expansion_function = bash_history_inhibit_expansion;
|
||||
sv_histchars ("histchars");
|
||||
#endif
|
||||
}
|
||||
@@ -241,10 +268,10 @@ bash_history_reinit (interact)
|
||||
{
|
||||
#if defined (BANG_HISTORY)
|
||||
history_expansion = interact != 0;
|
||||
history_expansion_inhibited = 1;
|
||||
#endif
|
||||
remember_on_history = enable_history_list = interact != 0;
|
||||
history_expansion_inhibited = 1; /* XXX */
|
||||
history_inhibit_expansion_function = bash_history_inhibit_expansion;
|
||||
#endif
|
||||
remember_on_history = enable_history_list;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -259,11 +286,11 @@ bash_history_disable ()
|
||||
void
|
||||
bash_history_enable ()
|
||||
{
|
||||
remember_on_history = 1;
|
||||
remember_on_history = enable_history_list = 1;
|
||||
#if defined (BANG_HISTORY)
|
||||
history_expansion_inhibited = 0;
|
||||
#endif
|
||||
history_inhibit_expansion_function = bash_history_inhibit_expansion;
|
||||
#endif
|
||||
sv_history_control ("HISTCONTROL");
|
||||
sv_histignore ("HISTIGNORE");
|
||||
}
|
||||
@@ -290,8 +317,13 @@ load_history ()
|
||||
if (hf && *hf && file_exists (hf))
|
||||
{
|
||||
read_history (hf);
|
||||
/* 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
|
||||
again. */
|
||||
history_lines_in_file = history_lines_read_from_file;
|
||||
using_history ();
|
||||
history_lines_in_file = where_history ();
|
||||
/* history_lines_in_file = where_history () + history_base - 1; */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,6 +332,7 @@ bash_clear_history ()
|
||||
{
|
||||
clear_history ();
|
||||
history_lines_this_session = 0;
|
||||
/* XXX - reset history_lines_read_from_file? */
|
||||
}
|
||||
|
||||
/* Delete and free the history list entry at offset I. */
|
||||
@@ -377,7 +410,7 @@ maybe_append_history (filename)
|
||||
struct stat buf;
|
||||
|
||||
result = EXECUTION_SUCCESS;
|
||||
if (history_lines_this_session && (history_lines_this_session <= where_history ()))
|
||||
if (history_lines_this_session > 0 && (history_lines_this_session <= where_history ()))
|
||||
{
|
||||
/* If the filename was supplied, then create it if necessary. */
|
||||
if (stat (filename, &buf) == -1 && errno == ENOENT)
|
||||
@@ -391,9 +424,14 @@ maybe_append_history (filename)
|
||||
close (fd);
|
||||
}
|
||||
result = append_history (history_lines_this_session, filename);
|
||||
/* Pretend we already read these lines from the file because we just
|
||||
added them */
|
||||
history_lines_in_file += history_lines_this_session;
|
||||
history_lines_this_session = 0;
|
||||
}
|
||||
else
|
||||
history_lines_this_session = 0; /* reset if > where_history() */
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
@@ -406,7 +444,7 @@ maybe_save_shell_history ()
|
||||
char *hf;
|
||||
|
||||
result = 0;
|
||||
if (history_lines_this_session)
|
||||
if (history_lines_this_session > 0)
|
||||
{
|
||||
hf = get_string_value ("HISTFILE");
|
||||
|
||||
@@ -433,7 +471,8 @@ maybe_save_shell_history ()
|
||||
else
|
||||
{
|
||||
result = write_history (hf);
|
||||
history_lines_in_file = history_lines_this_session;
|
||||
history_lines_in_file = history_lines_written_to_file;
|
||||
/* history_lines_in_file = where_history () + history_base - 1; */
|
||||
}
|
||||
history_lines_this_session = 0;
|
||||
|
||||
@@ -532,6 +571,7 @@ pre_process_line (line, print_changes, addit)
|
||||
if (hist_verify && expanded == 1)
|
||||
{
|
||||
re_edit (history_value);
|
||||
free (history_value);
|
||||
return ((char *)NULL);
|
||||
}
|
||||
# endif
|
||||
@@ -634,7 +674,9 @@ hc_erasedups (line)
|
||||
if (STREQ (temp->line, line))
|
||||
{
|
||||
r = where_history ();
|
||||
remove_history (r);
|
||||
temp = remove_history (r);
|
||||
if (temp)
|
||||
free_history_entry (temp);
|
||||
}
|
||||
}
|
||||
using_history ();
|
||||
@@ -706,11 +748,24 @@ check_add_history (line, force)
|
||||
#if defined (SYSLOG_HISTORY)
|
||||
#define SYSLOG_MAXLEN 600
|
||||
|
||||
extern char *shell_name;
|
||||
|
||||
#ifndef OPENLOG_OPTS
|
||||
#define OPENLOG_OPTS 0
|
||||
#endif
|
||||
|
||||
void
|
||||
bash_syslog_history (line)
|
||||
const char *line;
|
||||
{
|
||||
char trunc[SYSLOG_MAXLEN];
|
||||
static int first = 1;
|
||||
|
||||
if (first)
|
||||
{
|
||||
openlog (shell_name, OPENLOG_OPTS, SYSLOG_FACILITY);
|
||||
first = 0;
|
||||
}
|
||||
|
||||
if (strlen(line) < SYSLOG_MAXLEN)
|
||||
syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY: PID=%d UID=%d %s", getpid(), current_user.uid, line);
|
||||
|
||||
Reference in New Issue
Block a user