summaryrefslogtreecommitdiff
path: root/builtins/history.def
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2010-10-11 14:49:26 -0700
committerStephen Hemminger <stephen.hemminger@vyatta.com>2010-10-11 15:19:40 -0700
commit011c1d1c0766c65517ebd495465c99e86edb63ec (patch)
tree30d8f6a13235af90897c3223554871ef52225462 /builtins/history.def
parent40cfaccf7b178b6239b5cd0013ef80b7ff8e503e (diff)
downloadvyatta-bash-011c1d1c0766c65517ebd495465c99e86edb63ec.tar.gz
vyatta-bash-011c1d1c0766c65517ebd495465c99e86edb63ec.zip
Update to bash-4.1
Diffstat (limited to 'builtins/history.def')
-rw-r--r--builtins/history.def135
1 files changed, 50 insertions, 85 deletions
diff --git a/builtins/history.def b/builtins/history.def
index efee005..e8249e9 100644
--- a/builtins/history.def
+++ b/builtins/history.def
@@ -1,51 +1,58 @@
This file is history.def, from which is created history.c.
It implements the builtin "history" in Bash.
-Copyright (C) 1987-2003 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
-Bash is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
-version.
+Bash is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
-Bash is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
+Bash is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
-You should have received a copy of the GNU General Public License along
-with Bash; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES history.c
$BUILTIN history
$FUNCTION history_builtin
$DEPENDS_ON HISTORY
-$SHORT_DOC history [-c] [-d offset] [n] or history -awrn [filename] or history -ps arg [arg...]
-Display the history list with line numbers. Lines listed with
-with a `*' have been modified. Argument of N says to list only
-the last N lines. The `-c' option causes the history list to be
-cleared by deleting all of the entries. The `-d' option deletes
-the history entry at offset OFFSET. The `-w' option writes out the
-current history to the history file; `-r' means to read the file and
-append the contents to the history list instead. `-a' means
-to append history lines from this session to the history file.
-Argument `-n' means to read all history lines not already read
-from the history file and append them to the history list.
-
-If FILENAME is given, then that is used as the history file else
+$SHORT_DOC history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
+Display or manipulate the history list.
+
+Display the history list with line numbers, prefixing each modified
+entry with a `*'. An argument of N lists only the last N entries.
+
+Options:
+ -c clear the history list by deleting all of the entries
+ -d offset delete the history entry at offset OFFSET.
+
+ -a append history lines from this session to the history file
+ -n read all history lines not already read from the history file
+ -r read the history file and append the contents to the history
+ list
+ -w write the current history to the history file
+ and append them to the history list
+
+ -p perform history expansion on each ARG and display the result
+ without storing it in the history list
+ -s append the ARGs to the history list as a single entry
+
+If FILENAME is given, it is used as the history file. Otherwise,
if $HISTFILE has a value, that is used, else ~/.bash_history.
-If the -s option is supplied, the non-option ARGs are appended to
-the history list as a single entry. The -p option means to perform
-history expansion on each ARG and display the result, without storing
-anything in the history list.
If the $HISTTIMEFORMAT variable is set and not null, its value is used
as a format string for strftime(3) to print the time stamp associated
with each displayed history entry. No time stamps are printed otherwise.
+
+Exit Status:
+Returns success unless an invalid option is given or an error occurs.
$END
#include <config.h>
@@ -79,11 +86,8 @@ extern int errno;
extern int current_command_line_count;
extern int force_append_history; /* shopt -s histappend */
-int delete_last_history __P((void));
-
static char *histtime __P((HIST_ENTRY *, const char *));
-static void display_history __P((WORD_LIST *));
-static int delete_histent __P((int));
+static int display_history __P((WORD_LIST *));
static void push_history __P((WORD_LIST *));
static int expand_and_print_history __P((WORD_LIST *));
@@ -154,7 +158,7 @@ history_builtin (list)
/* clear the history, but allow other arguments to add to it again. */
if (flags & CFLAG)
{
- clear_history ();
+ bash_clear_history ();
if (list == 0)
return (EXECUTION_SUCCESS);
}
@@ -170,7 +174,7 @@ history_builtin (list)
{
if (list)
return (expand_and_print_history (list));
- return (EXECUTION_SUCCESS);
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
#endif
else if (flags & DFLAG)
@@ -183,7 +187,7 @@ history_builtin (list)
return (EXECUTION_FAILURE);
}
opt = delete_offset;
- result = delete_histent (opt - history_base);
+ result = bash_delete_histent (opt - history_base);
/* Since remove_history changes history_length, this can happen if
we delete the last history entry. */
if (where_history () > history_length)
@@ -192,8 +196,8 @@ history_builtin (list)
}
else if ((flags & (AFLAG|RFLAG|NFLAG|WFLAG|CFLAG)) == 0)
{
- display_history (list);
- return (EXECUTION_SUCCESS);
+ result = display_history (list);
+ return (sh_chkwrite (result));
}
filename = list ? list->word->word : get_string_value ("HISTFILE");
@@ -255,7 +259,7 @@ histtime (hlist, histtimefmt)
return timestr;
}
-static void
+static int
display_history (list)
WORD_LIST *list;
{
@@ -266,7 +270,9 @@ display_history (list)
if (list)
{
- limit = get_numeric_arg (list, 0);
+ if (get_numeric_arg (list, 0, &limit) == 0)
+ return (EXECUTION_FAILURE);
+
if (limit < 0)
limit = -limit;
}
@@ -285,7 +291,6 @@ display_history (list)
else
i = 0;
-
histtimefmt = get_string_value ("HISTTIMEFORMAT");
while (hlist[i])
@@ -300,48 +305,8 @@ display_history (list)
i++;
}
}
-}
-
-/* Delete and free the history list entry at offset I. */
-static int
-delete_histent (i)
- int i;
-{
- HIST_ENTRY *discard;
-
- discard = remove_history (i);
- if (discard)
- free_history_entry (discard);
-
- return 1;
-}
-
-int
-delete_last_history ()
-{
- register int i;
- HIST_ENTRY **hlist, *histent;
- int r;
-
- hlist = history_list ();
- if (hlist == NULL)
- return 0;
-
- for (i = 0; hlist[i]; i++)
- ;
- i--;
-
- /* History_get () takes a parameter that must be offset by history_base. */
- histent = history_get (history_base + i); /* Don't free this */
- if (histent == NULL)
- return 0;
-
- r = delete_histent (i);
-
- if (where_history () > history_length)
- history_set_pos (history_length);
- return r;
+ return (EXECUTION_SUCCESS);
}
/* Remove the last entry in the history list and add each argument in
@@ -359,12 +324,12 @@ push_history (list)
If you don't want history -s to remove the compound command from the
history, change #if 0 to #if 1 below. */
#if 0
- if (hist_last_line_pushed == 0 && hist_last_line_added && delete_last_history () == 0)
+ if (hist_last_line_pushed == 0 && hist_last_line_added && bash_delete_last_history () == 0)
#else
if (hist_last_line_pushed == 0 &&
(hist_last_line_added ||
(current_command_line_count > 0 && current_command_first_line_saved && command_oriented_history))
- && delete_last_history () == 0)
+ && bash_delete_last_history () == 0)
#endif
return;
@@ -389,7 +354,7 @@ expand_and_print_history (list)
char *s;
int r, result;
- if (hist_last_line_pushed == 0 && hist_last_line_added && delete_last_history () == 0)
+ if (hist_last_line_pushed == 0 && hist_last_line_added && bash_delete_last_history () == 0)
return EXECUTION_FAILURE;
result = EXECUTION_SUCCESS;
while (list)