Imported from ../bash-2.04.tar.gz.
This commit is contained in:
parent
b72432fdcc
commit
bb70624e96
387 changed files with 28522 additions and 9334 deletions
|
|
@ -7,7 +7,7 @@ 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 1, or (at your option) any later
|
||||
Software Foundation; either version 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
|
|
@ -17,18 +17,19 @@ 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, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
|
||||
$PRODUCES history.c
|
||||
|
||||
$BUILTIN history
|
||||
$FUNCTION history_builtin
|
||||
$DEPENDS_ON HISTORY
|
||||
$SHORT_DOC history [-c] [n] or history -awrn [filename] or history -ps arg [arg...]
|
||||
$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 `-w' option writes out the
|
||||
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.
|
||||
|
|
@ -49,8 +50,8 @@ $END
|
|||
#ifndef _MINIX
|
||||
# include <sys/file.h>
|
||||
#endif
|
||||
#include "../posixstat.h"
|
||||
#include "../filecntl.h"
|
||||
#include "posixstat.h"
|
||||
#include "filecntl.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
|
|
@ -72,6 +73,7 @@ extern int errno;
|
|||
static void display_history ();
|
||||
static void push_history ();
|
||||
static int expand_and_print_history ();
|
||||
static int delete_histent ();
|
||||
|
||||
#define AFLAG 0x01
|
||||
#define RFLAG 0x02
|
||||
|
|
@ -80,17 +82,19 @@ static int expand_and_print_history ();
|
|||
#define SFLAG 0x10
|
||||
#define PFLAG 0x20
|
||||
#define CFLAG 0x40
|
||||
#define DFLAG 0x80
|
||||
|
||||
int
|
||||
history_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int flags, opt, result;
|
||||
char *filename;
|
||||
char *filename, *delete_arg;
|
||||
long delete_offset;
|
||||
|
||||
flags = 0;
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "acnpsrw")) != -1)
|
||||
while ((opt = internal_getopt (list, "acd:npsrw")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
|
|
@ -112,6 +116,10 @@ history_builtin (list)
|
|||
case 's':
|
||||
flags |= SFLAG;
|
||||
break;
|
||||
case 'd':
|
||||
flags |= DFLAG;
|
||||
delete_arg = list_optarg;
|
||||
break;
|
||||
case 'p':
|
||||
#if defined (BANG_HISTORY)
|
||||
flags |= PFLAG;
|
||||
|
|
@ -153,6 +161,26 @@ history_builtin (list)
|
|||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
else if (flags & DFLAG)
|
||||
{
|
||||
if (legal_number (delete_arg, &delete_offset) == 0)
|
||||
{
|
||||
builtin_error ("%s: not a valid history position", delete_arg);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
opt = delete_offset;
|
||||
if (opt < history_base || opt < 0 || opt > (history_base + history_length))
|
||||
{
|
||||
builtin_error ("%d: not a valid history position", opt);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
result = 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)
|
||||
history_set_pos (history_length);
|
||||
return (result ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
|
||||
}
|
||||
else if ((flags & (AFLAG|RFLAG|NFLAG|WFLAG|CFLAG)) == 0)
|
||||
{
|
||||
display_history (list);
|
||||
|
|
@ -224,11 +252,28 @@ display_history (list)
|
|||
}
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
if (discard->line)
|
||||
free (discard->line);
|
||||
free ((char *) discard);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
delete_last_history ()
|
||||
{
|
||||
register int i;
|
||||
HIST_ENTRY **hlist, *histent, *discard;
|
||||
HIST_ENTRY **hlist, *histent;
|
||||
|
||||
hlist = history_list ();
|
||||
if (hlist == NULL)
|
||||
|
|
@ -243,14 +288,7 @@ delete_last_history ()
|
|||
if (histent == NULL)
|
||||
return 0;
|
||||
|
||||
discard = remove_history (i);
|
||||
if (discard)
|
||||
{
|
||||
if (discard->line)
|
||||
free (discard->line);
|
||||
free ((char *) discard);
|
||||
}
|
||||
return (1);
|
||||
return (delete_histent (i));
|
||||
}
|
||||
|
||||
/* Remove the last entry in the history list and add each argument in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue