commit bash-20041014 snapshot

This commit is contained in:
Chet Ramey
2011-12-03 13:38:04 -05:00
parent cac4cdbf5e
commit 453f278a2a
28 changed files with 7978 additions and 116 deletions
+40
View File
@@ -10318,3 +10318,43 @@ doc/{bash.1,bashref.texi}
- note that redirections using file descriptors > 9 should be used
carefully, because they might conflict with file descriptors the
shell uses internally
10/11
-----
parse.y
- fix pipeline_command production to handle case where `pipeline'
as `argument' of `!' or `time' is null (e.g., a syntax error not
handled by the grammar)
10/13
-----
lib/readline/readline.c
- new internal variable, _rl_bind_stty_chars; if non-zero, bind the
terminal special characters to readline equivalents at startup
- change readline_default_bindings() and reset_default_bindings() to
understand _rl_bind_stty_chars
lib/readline/rlprivate.h
- new extern declaration for _rl_bind_stty_chars
lib/readline/rltty.c
- change rl_prep_terminal to add support for _rl_bind_stty_chars
10/15
-----
lib/readline/bind.c
- new bindable variable, `bind-tty-special-chars', bound to value of
_rl_bind_stty_chars
doc/bash.1,lib/readline/doc/{readline.3,rluser.texi}
- documented new readline variable `bind-tty-special-chars'
builtins/pushd.def
- make the first check for option `--' skip the rest of option
checking
10/16
-----
lib/readline/shell.c
- change sh_set_lines_and_columns to prefer setenv, which has
predictable memory allocation behavior, to putenv, which does not
+39
View File
@@ -10313,3 +10313,42 @@ redir.c
- experimental change to add_undo_redirect to save manipulations to
file descriptors >= SHELL_FD_BASE (10) on the list of redirections
to be undone even if `exec' causes the list to be discarded
doc/{bash.1,bashref.texi}
- note that redirections using file descriptors > 9 should be used
carefully, because they might conflict with file descriptors the
shell uses internally
10/11
-----
parse.y
- fix pipeline_command production to handle case where `pipeline'
as `argument' of `!' or `time' is null (e.g., a syntax error not
handled by the grammar)
10/13
-----
lib/readline/readline.c
- new internal variable, _rl_bind_stty_chars; if non-zero, bind the
terminal special characters to readline equivalents at startup
- change readline_default_bindings() and reset_default_bindings() to
understand _rl_bind_stty_chars
lib/readline/rlprivate.h
- new extern declaration for _rl_bind_stty_chars
lib/readline/rltty.c
- change rl_prep_terminal to add support for _rl_bind_stty_chars
10/15
-----
lib/readline/bind.c
- new bindable variable, `bind-tty-special-chars', bound to value of
_rl_bind_stty_chars
doc/bash.1,lib/readline/doc/{readline.3,rluser.texi}
- documented new readline variable `bind-tty-special-chars'
builtins/pushd.def
- make the first check for option `--' skip the rest of option
checking
+82 -82
View File
@@ -15,96 +15,96 @@
'configure.in'
],
{
'AC_CONFIG_FILES' => 1,
'AC_HEADER_TIME' => 1,
'AC_PROG_CPP' => 1,
'AC_FUNC_REALLOC' => 1,
'AC_C_CONST' => 1,
'AC_C_VOLATILE' => 1,
'AM_INIT_AUTOMAKE' => 1,
'AC_DECL_SYS_SIGLIST' => 1,
'AC_STRUCT_TIMEZONE' => 1,
'AC_SUBST' => 1,
'AC_TYPE_SIGNAL' => 1,
'AC_CHECK_MEMBERS' => 1,
'AC_TYPE_SIZE_T' => 1,
'AC_FUNC_SETPGRP' => 1,
'AC_TYPE_OFF_T' => 1,
'AC_FUNC_GETMNTENT' => 1,
'AC_FUNC_LSTAT' => 1,
'AC_FUNC_GETGROUPS' => 1,
'AC_CONFIG_HEADERS' => 1,
'AC_FUNC_SELECT_ARGTYPES' => 1,
'AC_PROG_CC' => 1,
'AM_CONDITIONAL' => 1,
'AC_REPLACE_FNMATCH' => 1,
'AC_FUNC_MEMCMP' => 1,
'AC_FUNC_STRTOD' => 1,
'AC_FUNC_STRNLEN' => 1,
'AC_FUNC_STRFTIME' => 1,
'AC_FUNC_GETPGRP' => 1,
'AC_CANONICAL_SYSTEM' => 1,
'AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK' => 1,
'AC_CONFIG_FILES' => 1,
'AC_PROG_CPP' => 1,
'AC_CHECK_TYPES' => 1,
'AC_LIBSOURCE' => 1,
'AC_STRUCT_TM' => 1,
'AC_C_CONST' => 1,
'AC_FUNC_FORK' => 1,
'AC_HEADER_SYS_WAIT' => 1,
'AM_GNU_GETTEXT' => 1,
'AC_INIT' => 1,
'AC_FUNC_UTIME_NULL' => 1,
'AM_AUTOMAKE_VERSION' => 1,
'AC_TYPE_UID_T' => 1,
'AC_HEADER_STDC' => 1,
'AC_PROG_CXX' => 1,
'AC_FUNC_STRERROR_R' => 1,
'AC_PROG_YACC' => 1,
'AC_CONFIG_AUX_DIR' => 1,
'AC_FUNC_OBSTACK' => 1,
'AC_HEADER_STAT' => 1,
'AC_FUNC_CLOSEDIR_VOID' => 1,
'AC_PROG_CXX' => 1,
'AC_STRUCT_TM' => 1,
'AC_FUNC_STRFTIME' => 1,
'AC_FUNC_UTIME_NULL' => 1,
'AC_PROG_LIBTOOL' => 1,
'AC_FUNC_FSEEKO' => 1,
'AM_GNU_GETTEXT' => 1,
'AC_PROG_RANLIB' => 1,
'AC_FUNC_FORK' => 1,
'AC_FUNC_MALLOC' => 1,
'AC_FUNC_SETVBUF_REVERSED' => 1,
'AC_TYPE_PID_T' => 1,
'AC_PROG_GCC_TRADITIONAL' => 1,
'AC_PROG_LEX' => 1,
'AC_FUNC_STRCOLL' => 1,
'AC_PATH_X' => 1,
'AM_INIT_AUTOMAKE' => 1,
'AC_CHECK_TYPES' => 1,
'AC_FUNC_GETLOADAVG' => 1,
'include' => 1,
'AC_LIBSOURCE' => 1,
'AC_CHECK_FUNCS' => 1,
'm4_include' => 1,
'AC_FUNC_MKTIME' => 1,
'AC_FUNC_STAT' => 1,
'AC_FUNC_CHOWN' => 1,
'AC_HEADER_DIRENT' => 1,
'AC_FUNC_STRNLEN' => 1,
'AM_MAINTAINER_MODE' => 1,
'AC_FUNC_WAIT3' => 1,
'AC_PROG_LN_S' => 1,
'AC_PROG_INSTALL' => 1,
'm4_pattern_allow' => 1,
'AC_FUNC_GETPGRP' => 1,
'AC_PROG_AWK' => 1,
'AC_INIT' => 1,
'AC_DEFINE_TRACE_LITERAL' => 1,
'AC_CHECK_LIB' => 1,
'AC_HEADER_MAJOR' => 1,
'AC_FUNC_MBRTOWC' => 1,
'AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK' => 1,
'AC_FUNC_MMAP' => 1,
'AC_CANONICAL_HOST' => 1,
'AC_CONFIG_SUBDIRS' => 1,
'AC_DECL_SYS_SIGLIST' => 1,
'AC_HEADER_SYS_WAIT' => 1,
'AC_C_INLINE' => 1,
'AC_STRUCT_ST_BLOCKS' => 1,
'AC_FUNC_ALLOCA' => 1,
'AM_PROG_CC_C_O' => 1,
'AC_CANONICAL_SYSTEM' => 1,
'AC_FUNC_VPRINTF' => 1,
'AC_FUNC_ERROR_AT_LINE' => 1,
'AH_OUTPUT' => 1,
'AC_TYPE_MODE_T' => 1,
'AC_PROG_RANLIB' => 1,
'AC_PROG_LEX' => 1,
'AM_PROG_CC_C_O' => 1,
'AC_CHECK_FUNCS' => 1,
'AC_SUBST' => 1,
'AC_FUNC_MBRTOWC' => 1,
'AC_FUNC_GETGROUPS' => 1,
'AC_PROG_LN_S' => 1,
'AC_FUNC_CHOWN' => 1,
'AC_FUNC_GETMNTENT' => 1,
'AC_PROG_MAKE_SET' => 1,
'AC_TYPE_MODE_T' => 1,
'AH_OUTPUT' => 1,
'AC_C_VOLATILE' => 1,
'AC_FUNC_ALLOCA' => 1,
'AC_TYPE_UID_T' => 1,
'AM_MAINTAINER_MODE' => 1,
'AC_FUNC_SETVBUF_REVERSED' => 1,
'AC_STRUCT_ST_BLOCKS' => 1,
'm4_include' => 1,
'AC_CONFIG_AUX_DIR' => 1,
'AC_FUNC_FSEEKO' => 1,
'AC_FUNC_OBSTACK' => 1,
'AC_FUNC_MEMCMP' => 1,
'AC_FUNC_MKTIME' => 1,
'AC_FUNC_STRTOD' => 1,
'AC_FUNC_GETLOADAVG' => 1,
'AC_CHECK_HEADERS' => 1,
'AC_FUNC_SETPGRP' => 1,
'AC_CHECK_LIB' => 1,
'AC_FUNC_SELECT_ARGTYPES' => 1,
'AC_TYPE_OFF_T' => 1,
'AC_DEFINE_TRACE_LITERAL' => 1,
'AC_HEADER_STAT' => 1,
'AC_PROG_LIBTOOL' => 1,
'm4_pattern_forbid' => 1,
'AC_HEADER_STDC' => 1,
'AC_CHECK_HEADERS' => 1
'AC_TYPE_PID_T' => 1,
'AC_TYPE_SIZE_T' => 1,
'AC_FUNC_MALLOC' => 1,
'AC_HEADER_DIRENT' => 1,
'AC_PROG_INSTALL' => 1,
'AC_CONFIG_SUBDIRS' => 1,
'AC_FUNC_ERROR_AT_LINE' => 1,
'AC_FUNC_MMAP' => 1,
'AC_HEADER_TIME' => 1,
'AC_FUNC_REALLOC' => 1,
'include' => 1,
'm4_pattern_allow' => 1,
'AC_FUNC_WAIT3' => 1,
'AC_PROG_AWK' => 1,
'AC_HEADER_MAJOR' => 1,
'AM_CONDITIONAL' => 1,
'AC_PROG_CC' => 1,
'AC_CHECK_MEMBERS' => 1,
'AC_TYPE_SIGNAL' => 1,
'AC_C_INLINE' => 1,
'AC_FUNC_CLOSEDIR_VOID' => 1,
'AC_FUNC_LSTAT' => 1,
'AC_CONFIG_HEADERS' => 1,
'AC_REPLACE_FNMATCH' => 1,
'AC_PATH_X' => 1,
'AC_FUNC_STAT' => 1,
'AC_PROG_GCC_TRADITIONAL' => 1,
'AC_CANONICAL_HOST' => 1
}
], 'Request' )
);
+8 -3
View File
@@ -152,12 +152,17 @@ pushd_builtin (list)
WORD_LIST *list;
{
char *temp, *current_directory, *top;
int j, flags;
int j, flags, skipopt;
intmax_t num;
char direction;
if (list && list->word && ISOPTION (list->word->word, '-'))
list = list->next;
{
list = list->next;
skipopt = 1;
}
else
skipopt = 0;
/* If there is no argument list then switch current and
top of list. */
@@ -181,7 +186,7 @@ pushd_builtin (list)
return j;
}
for (flags = 0; list; list = list->next)
for (flags = 0; skipopt == 0 && list; list = list->next)
{
if (ISOPTION (list->word->word, 'n'))
{
+743
View File
@@ -0,0 +1,743 @@
This file is pushd.def, from which is created pushd.c. It implements the
builtins "pushd", "popd", and "dirs" in Bash.
Copyright (C) 1987-2003 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 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.
$PRODUCES pushd.c
$BUILTIN pushd
$FUNCTION pushd_builtin
$DEPENDS_ON PUSHD_AND_POPD
$SHORT_DOC pushd [dir | +N | -N] [-n]
Adds a directory to the top of the directory stack, or rotates
the stack, making the new top of the stack the current working
directory. With no arguments, exchanges the top two directories.
+N Rotates the stack so that the Nth directory (counting
from the left of the list shown by `dirs', starting with
zero) is at the top.
-N Rotates the stack so that the Nth directory (counting
from the right of the list shown by `dirs', starting with
zero) is at the top.
-n suppress the normal change of directory when adding directories
to the stack, so only the stack is manipulated.
dir adds DIR to the directory stack at the top, making it the
new current working directory.
You can see the directory stack with the `dirs' command.
$END
$BUILTIN popd
$FUNCTION popd_builtin
$DEPENDS_ON PUSHD_AND_POPD
$SHORT_DOC popd [+N | -N] [-n]
Removes entries from the directory stack. With no arguments,
removes the top directory from the stack, and cd's to the new
top directory.
+N removes the Nth entry counting from the left of the list
shown by `dirs', starting with zero. For example: `popd +0'
removes the first directory, `popd +1' the second.
-N removes the Nth entry counting from the right of the list
shown by `dirs', starting with zero. For example: `popd -0'
removes the last directory, `popd -1' the next to last.
-n suppress the normal change of directory when removing directories
from the stack, so only the stack is manipulated.
You can see the directory stack with the `dirs' command.
$END
$BUILTIN dirs
$FUNCTION dirs_builtin
$DEPENDS_ON PUSHD_AND_POPD
$SHORT_DOC dirs [-clpv] [+N] [-N]
Display the list of currently remembered directories. Directories
find their way onto the list with the `pushd' command; you can get
back up through the list with the `popd' command.
The -l flag specifies that `dirs' should not print shorthand versions
of directories which are relative to your home directory. This means
that `~/bin' might be displayed as `/homes/bfox/bin'. The -v flag
causes `dirs' to print the directory stack with one entry per line,
prepending the directory name with its position in the stack. The -p
flag does the same thing, but the stack position is not prepended.
The -c flag clears the directory stack by deleting all of the elements.
+N displays the Nth entry counting from the left of the list shown by
dirs when invoked without options, starting with zero.
-N displays the Nth entry counting from the right of the list shown by
dirs when invoked without options, starting with zero.
$END
#include <config.h>
#if defined (PUSHD_AND_POPD)
#include <stdio.h>
#ifndef _MINIX
# include <sys/param.h>
#endif
#if defined (HAVE_UNISTD_H)
# ifdef _MINIX
# include <sys/types.h>
# endif
# include <unistd.h>
#endif
#include "../bashansi.h"
#include "../bashintl.h"
#include <errno.h>
#include <tilde/tilde.h>
#include "../shell.h"
#include "maxpath.h"
#include "common.h"
#include "builtext.h"
#ifdef LOADABLE_BUILTIN
# include "builtins.h"
#endif
#if !defined (errno)
extern int errno;
#endif /* !errno */
/* The list of remembered directories. */
static char **pushd_directory_list = (char **)NULL;
/* Number of existing slots in this list. */
static int directory_list_size;
/* Offset to the end of the list. */
static int directory_list_offset;
static void pushd_error __P((int, char *));
static void clear_directory_stack __P((void));
static int cd_to_string __P((char *));
static int change_to_temp __P((char *));
static void add_dirstack_element __P((char *));
static int get_dirstack_index __P((intmax_t, int, int *));
#define NOCD 0x01
#define ROTATE 0x02
#define LONGFORM 0x04
#define CLEARSTAK 0x08
int
pushd_builtin (list)
WORD_LIST *list;
{
char *temp, *current_directory, *top;
int j, flags;
intmax_t num;
char direction;
if (list && list->word && ISOPTION (list->word->word, '-'))
list = list->next;
/* If there is no argument list then switch current and
top of list. */
if (list == 0)
{
if (directory_list_offset == 0)
{
builtin_error (_("no other directory"));
return (EXECUTION_FAILURE);
}
current_directory = get_working_directory ("pushd");
if (current_directory == 0)
return (EXECUTION_FAILURE);
j = directory_list_offset - 1;
temp = pushd_directory_list[j];
pushd_directory_list[j] = current_directory;
j = change_to_temp (temp);
free (temp);
return j;
}
for (flags = 0; list; list = list->next)
{
if (ISOPTION (list->word->word, 'n'))
{
flags |= NOCD;
}
else if (ISOPTION (list->word->word, '-'))
{
list = list->next;
break;
}
else if (list->word->word[0] == '-' && list->word->word[1] == '\0')
/* Let `pushd -' work like it used to. */
break;
else if (((direction = list->word->word[0]) == '+') || direction == '-')
{
if (legal_number (list->word->word + 1, &num) == 0)
{
sh_invalidnum (list->word->word);
builtin_usage ();
return (EXECUTION_FAILURE);
}
if (direction == '-')
num = directory_list_offset - num;
if (num > directory_list_offset || num < 0)
{
pushd_error (directory_list_offset, list->word->word);
return (EXECUTION_FAILURE);
}
flags |= ROTATE;
}
else if (*list->word->word == '-')
{
sh_invalidopt (list->word->word);
builtin_usage ();
return (EXECUTION_FAILURE);
}
else
break;
}
if (flags & ROTATE)
{
/* Rotate the stack num times. Remember, the current
directory acts like it is part of the stack. */
temp = get_working_directory ("pushd");
if (num == 0)
{
j = ((flags & NOCD) == 0) ? change_to_temp (temp) : EXECUTION_SUCCESS;
free (temp);
return j;
}
do
{
top = pushd_directory_list[directory_list_offset - 1];
for (j = directory_list_offset - 2; j > -1; j--)
pushd_directory_list[j + 1] = pushd_directory_list[j];
pushd_directory_list[j + 1] = temp;
temp = top;
num--;
}
while (num);
j = ((flags & NOCD) == 0) ? change_to_temp (temp) : EXECUTION_SUCCESS;
free (temp);
return j;
}
if (list == 0)
return (EXECUTION_SUCCESS);
/* Change to the directory in list->word->word. Save the current
directory on the top of the stack. */
current_directory = get_working_directory ("pushd");
if (current_directory == 0)
return (EXECUTION_FAILURE);
j = ((flags & NOCD) == 0) ? cd_builtin (list) : EXECUTION_SUCCESS;
if (j == EXECUTION_SUCCESS)
{
add_dirstack_element ((flags & NOCD) ? savestring (list->word->word) : current_directory);
dirs_builtin ((WORD_LIST *)NULL);
if (flags & NOCD)
free (current_directory);
return (EXECUTION_SUCCESS);
}
else
{
free (current_directory);
return (EXECUTION_FAILURE);
}
}
/* Pop the directory stack, and then change to the new top of the stack.
If LIST is non-null it should consist of a word +N or -N, which says
what element to delete from the stack. The default is the top one. */
int
popd_builtin (list)
WORD_LIST *list;
{
register int i;
intmax_t which;
int flags;
char direction;
char *which_word;
which_word = (char *)NULL;
for (flags = 0, which = 0, direction = '+'; list; list = list->next)
{
if (ISOPTION (list->word->word, 'n'))
{
flags |= NOCD;
}
else if (ISOPTION (list->word->word, '-'))
{
list = list->next;
break;
}
else if (((direction = list->word->word[0]) == '+') || direction == '-')
{
if (legal_number (list->word->word + 1, &which) == 0)
{
sh_invalidnum (list->word->word);
builtin_usage ();
return (EXECUTION_FAILURE);
}
which_word = list->word->word;
}
else if (*list->word->word == '-')
{
sh_invalidopt (list->word->word);
builtin_usage ();
return (EXECUTION_FAILURE);
}
else
break;
}
if (which > directory_list_offset || (directory_list_offset == 0 && which == 0))
{
pushd_error (directory_list_offset, which_word ? which_word : "");
return (EXECUTION_FAILURE);
}
/* Handle case of no specification, or top of stack specification. */
if ((direction == '+' && which == 0) ||
(direction == '-' && which == directory_list_offset))
{
i = ((flags & NOCD) == 0) ? cd_to_string (pushd_directory_list[directory_list_offset - 1])
: EXECUTION_SUCCESS;
if (i != EXECUTION_SUCCESS)
return (i);
free (pushd_directory_list[--directory_list_offset]);
}
else
{
/* Since an offset other than the top directory was specified,
remove that directory from the list and shift the remainder
of the list into place. */
i = (direction == '+') ? directory_list_offset - which : which;
free (pushd_directory_list[i]);
directory_list_offset--;
/* Shift the remainder of the list into place. */
for (; i < directory_list_offset; i++)
pushd_directory_list[i] = pushd_directory_list[i + 1];
}
dirs_builtin ((WORD_LIST *)NULL);
return (EXECUTION_SUCCESS);
}
/* Print the current list of directories on the directory stack. */
int
dirs_builtin (list)
WORD_LIST *list;
{
int flags, desired_index, index_flag, vflag;
intmax_t i;
char *temp, *w;
for (flags = vflag = index_flag = 0, desired_index = -1, w = ""; list; list = list->next)
{
if (ISOPTION (list->word->word, 'l'))
{
flags |= LONGFORM;
}
else if (ISOPTION (list->word->word, 'c'))
{
flags |= CLEARSTAK;
}
else if (ISOPTION (list->word->word, 'v'))
{
vflag |= 2;
}
else if (ISOPTION (list->word->word, 'p'))
{
vflag |= 1;
}
else if (ISOPTION (list->word->word, '-'))
{
list = list->next;
break;
}
else if (*list->word->word == '+' || *list->word->word == '-')
{
int sign;
if (legal_number (w = list->word->word + 1, &i) == 0)
{
sh_invalidnum (list->word->word);
builtin_usage ();
return (EXECUTION_FAILURE);
}
sign = (*list->word->word == '+') ? 1 : -1;
desired_index = get_dirstack_index (i, sign, &index_flag);
}
else
{
sh_invalidopt (list->word->word);
builtin_usage ();
return (EXECUTION_FAILURE);
}
}
if (flags & CLEARSTAK)
{
clear_directory_stack ();
return (EXECUTION_SUCCESS);
}
if (index_flag && (desired_index < 0 || desired_index > directory_list_offset))
{
pushd_error (directory_list_offset, w);
return (EXECUTION_FAILURE);
}
#define DIRSTACK_FORMAT(temp) \
(flags & LONGFORM) ? temp : polite_directory_format (temp)
/* The first directory printed is always the current working directory. */
if (index_flag == 0 || (index_flag == 1 && desired_index == 0))
{
temp = get_working_directory ("dirs");
if (temp == 0)
temp = savestring (_("<no current directory>"));
if (vflag & 2)
printf ("%2d %s", 0, DIRSTACK_FORMAT (temp));
else
printf ("%s", DIRSTACK_FORMAT (temp));
free (temp);
if (index_flag)
{
putchar ('\n');
return EXECUTION_SUCCESS;
}
}
#define DIRSTACK_ENTRY(i) \
(flags & LONGFORM) ? pushd_directory_list[i] \
: polite_directory_format (pushd_directory_list[i])
/* Now print the requested directory stack entries. */
if (index_flag)
{
if (vflag & 2)
printf ("%2d %s", directory_list_offset - desired_index,
DIRSTACK_ENTRY (desired_index));
else
printf ("%s", DIRSTACK_ENTRY (desired_index));
}
else
for (i = directory_list_offset - 1; i >= 0; i--)
if (vflag >= 2)
printf ("\n%2d %s", directory_list_offset - (int)i, DIRSTACK_ENTRY (i));
else
printf ("%s%s", (vflag & 1) ? "\n" : " ", DIRSTACK_ENTRY (i));
putchar ('\n');
fflush (stdout);
return (EXECUTION_SUCCESS);
}
static void
pushd_error (offset, arg)
int offset;
char *arg;
{
if (offset == 0)
builtin_error ("directory stack empty");
else
sh_erange (arg, "directory stack index");
}
static void
clear_directory_stack ()
{
register int i;
for (i = 0; i < directory_list_offset; i++)
free (pushd_directory_list[i]);
directory_list_offset = 0;
}
/* Switch to the directory in NAME. This uses the cd_builtin to do the work,
so if the result is EXECUTION_FAILURE then an error message has already
been printed. */
static int
cd_to_string (name)
char *name;
{
WORD_LIST *tlist;
int result;
tlist = make_word_list (make_word (name), NULL);
result = cd_builtin (tlist);
dispose_words (tlist);
return (result);
}
static int
change_to_temp (temp)
char *temp;
{
int tt;
tt = temp ? cd_to_string (temp) : EXECUTION_FAILURE;
if (tt == EXECUTION_SUCCESS)
dirs_builtin ((WORD_LIST *)NULL);
return (tt);
}
static void
add_dirstack_element (dir)
char *dir;
{
if (directory_list_offset == directory_list_size)
pushd_directory_list = strvec_resize (pushd_directory_list, directory_list_size += 10);
pushd_directory_list[directory_list_offset++] = dir;
}
static int
get_dirstack_index (ind, sign, indexp)
intmax_t ind;
int sign, *indexp;
{
if (indexp)
*indexp = sign > 0 ? 1 : 2;
/* dirs +0 prints the current working directory. */
/* dirs -0 prints last element in directory stack */
if (ind == 0 && sign > 0)
return 0;
else if (ind == directory_list_offset)
{
if (indexp)
*indexp = sign > 0 ? 2 : 1;
return 0;
}
else if (ind >= 0 && ind <= directory_list_offset)
return (sign > 0 ? directory_list_offset - ind : ind);
else
return -1;
}
/* Used by the tilde expansion code. */
char *
get_dirstack_from_string (string)
char *string;
{
int ind, sign, index_flag;
intmax_t i;
sign = 1;
if (*string == '-' || *string == '+')
{
sign = (*string == '-') ? -1 : 1;
string++;
}
if (legal_number (string, &i) == 0)
return ((char *)NULL);
index_flag = 0;
ind = get_dirstack_index (i, sign, &index_flag);
if (index_flag && (ind < 0 || ind > directory_list_offset))
return ((char *)NULL);
if (index_flag == 0 || (index_flag == 1 && ind == 0))
return (get_string_value ("PWD"));
else
return (pushd_directory_list[ind]);
}
#ifdef INCLUDE_UNUSED
char *
get_dirstack_element (ind, sign)
intmax_t ind;
int sign;
{
int i;
i = get_dirstack_index (ind, sign, (int *)NULL);
return (i < 0 || i > directory_list_offset) ? (char *)NULL
: pushd_directory_list[i];
}
#endif
void
set_dirstack_element (ind, sign, value)
intmax_t ind;
int sign;
char *value;
{
int i;
i = get_dirstack_index (ind, sign, (int *)NULL);
if (ind == 0 || i < 0 || i > directory_list_offset)
return;
free (pushd_directory_list[i]);
pushd_directory_list[i] = savestring (value);
}
WORD_LIST *
get_directory_stack ()
{
register int i;
WORD_LIST *ret;
char *d, *t;
for (ret = (WORD_LIST *)NULL, i = 0; i < directory_list_offset; i++)
{
d = polite_directory_format (pushd_directory_list[i]);
ret = make_word_list (make_word (d), ret);
}
/* Now the current directory. */
d = get_working_directory ("dirstack");
i = 0; /* sentinel to decide whether or not to free d */
if (d == 0)
d = ".";
else
{
t = polite_directory_format (d);
/* polite_directory_format sometimes returns its argument unchanged.
If it does not, we can free d right away. If it does, we need to
mark d to be deleted later. */
if (t != d)
{
free (d);
d = t;
}
else /* t == d, so d is what we want */
i = 1;
}
ret = make_word_list (make_word (d), ret);
if (i)
free (d);
return ret; /* was (REVERSE_LIST (ret, (WORD_LIST *)); */
}
#ifdef LOADABLE_BUILTIN
static char *dirs_doc[] = {
N_("Display the list of currently remembered directories. Directories"),
N_("find their way onto the list with the `pushd' command; you can get"),
N_("back up through the list with the `popd' command."),
N_(""),
N_("The -l flag specifies that `dirs' should not print shorthand versions"),
N_("of directories which are relative to your home directory. This means"),
N_("that `~/bin' might be displayed as `/homes/bfox/bin'. The -v flag"),
N_("causes `dirs' to print the directory stack with one entry per line,"),
N_("prepending the directory name with its position in the stack. The -p"),
N_("flag does the same thing, but the stack position is not prepended."),
N_("The -c flag clears the directory stack by deleting all of the elements."),
N_(""),
N_("+N displays the Nth entry counting from the left of the list shown by"),
N_(" dirs when invoked without options, starting with zero."),
N_(""),
N_("-N displays the Nth entry counting from the right of the list shown by"),
N_(" dirs when invoked without options, starting with zero."),
(char *)NULL
};
static char *pushd_doc[] = {
N_("Adds a directory to the top of the directory stack, or rotates"),
N_("the stack, making the new top of the stack the current working"),
N_("directory. With no arguments, exchanges the top two directories."),
N_(""),
N_("+N Rotates the stack so that the Nth directory (counting"),
N_(" from the left of the list shown by `dirs', starting with"),
N_(" zero) is at the top."),
N_(""),
N_("-N Rotates the stack so that the Nth directory (counting"),
N_(" from the right of the list shown by `dirs', starting with"),
N_(" zero) is at the top."),
N_(""),
N_("-n suppress the normal change of directory when adding directories"),
N_(" to the stack, so only the stack is manipulated."),
N_(""),
N_("dir adds DIR to the directory stack at the top, making it the"),
N_(" new current working directory."),
N_(""),
N_("You can see the directory stack with the `dirs' command."),
(char *)NULL
};
static char *popd_doc[] = {
N_("Removes entries from the directory stack. With no arguments,"),
N_("removes the top directory from the stack, and cd's to the new"),
N_("top directory."),
N_(""),
N_("+N removes the Nth entry counting from the left of the list"),
N_(" shown by `dirs', starting with zero. For example: `popd +0'"),
N_(" removes the first directory, `popd +1' the second."),
N_(""),
N_("-N removes the Nth entry counting from the right of the list"),
N_(" shown by `dirs', starting with zero. For example: `popd -0'"),
N_(" removes the last directory, `popd -1' the next to last."),
N_(""),
N_("-n suppress the normal change of directory when removing directories"),
N_(" from the stack, so only the stack is manipulated."),
N_(""),
N_("You can see the directory stack with the `dirs' command."),
(char *)NULL
};
struct builtin pushd_struct = {
"pushd",
pushd_builtin,
BUILTIN_ENABLED,
pushd_doc,
"pushd [+N | -N] [-n] [dir]",
0
};
struct builtin popd_struct = {
"popd",
popd_builtin,
BUILTIN_ENABLED,
popd_doc,
"popd [+N | -N] [-n]",
0
};
struct builtin dirs_struct = {
"dirs",
dirs_builtin,
BUILTIN_ENABLED,
dirs_doc,
"dirs [-clpv] [+N] [-N]",
0
};
#endif /* LOADABLE_BUILTIN */
#endif /* PUSHD_AND_POPD */
+5
View File
@@ -4516,6 +4516,11 @@ If set to \fBnone\fP, readline never rings the bell. If set to
\fBvisible\fP, readline uses a visible bell if one is available.
If set to \fBaudible\fP, readline attempts to ring the terminal's bell.
.TP
.B bind\-tty\-special\-chars (On)
If set to \fBOn\fP, readline attempts to bind the control characters
treated specially by the kernel's terminal driver to their readline
equivalents.
.TP
.B comment\-begin (``#'')
The string that is inserted when the readline
.B insert\-comment
+4
View File
@@ -2950,6 +2950,10 @@ a UDP connection to the corresponding socket.
.RE
.PP
A failure to open or create a file causes the redirection to fail.
.PP
Redirections using file descriptors greater than 9 should be used with
care, as they may conflict with file descriptors the shell uses
internally.
.SS Redirecting Input
.PP
Redirection of input causes the file whose name results from
+2 -2
View File
@@ -4,7 +4,7 @@ Copyright (C) 1988-2004 Free Software Foundation, Inc.
@set EDITION 3.1-devel
@set VERSION 3.1-devel
@set UPDATED 9 October 2004
@set UPDATED 15 October 2004
@set UPDATED-MONTH October 2004
@set LASTCHANGE Sat Oct 9 18:40:05 EDT 2004
@set LASTCHANGE Fri Oct 15 14:53:01 EDT 2004
+1 -1
View File
@@ -7,4 +7,4 @@ Copyright (C) 1988-2004 Free Software Foundation, Inc.
@set UPDATED 9 October 2004
@set UPDATED-MONTH October 2004
@set LASTCHANGE
@set LASTCHANGE Sat Oct 9 18:40:05 EDT 2004
+1
View File
@@ -1355,6 +1355,7 @@ static struct {
int *value;
int flags;
} boolean_varlist [] = {
{ "bind-tty-special-chars", &_rl_bind_stty_chars, 0 },
{ "blink-matching-paren", &rl_blink_matching_paren, V_SPECIAL },
{ "byte-oriented", &rl_byte_oriented, 0 },
{ "completion-ignore-case", &_rl_completion_case_fold, 0 },
+2223
View File
File diff suppressed because it is too large Load Diff
+6 -1
View File
@@ -8,7 +8,7 @@
.\"
.\" Last Change: Wed Jan 28 15:43:53 EST 2004
.\"
.TH READLINE 3 "2004 January 28" "GNU Readline 5.0"
.TH READLINE 3 "2004 October 15" "GNU Readline 5.0"
.\"
.\" File Name macro. This used to be `.PN', for Path Name,
.\" but Sun doesn't seem to like that very much.
@@ -338,6 +338,11 @@ If set to \fBnone\fP, readline never rings the bell. If set to
\fBvisible\fP, readline uses a visible bell if one is available.
If set to \fBaudible\fP, readline attempts to ring the terminal's bell.
.TP
.B bind\-tty\-special\-chars (On)
If set to \fBOn\fP, readline attempts to bind the control characters
treated specially by the kernel's terminal driver to their readline
equivalents.
.TP
.B comment\-begin (``#'')
The string that is inserted in \fBvi\fP mode when the
.B insert\-comment
File diff suppressed because it is too large Load Diff
+2
View File
@@ -284,6 +284,8 @@ negative argument.
A command function should return 0 if its action completes successfully,
and a non-zero value if some error occurs.
This is the convention obeyed by all of the builtin Readline bindable
command functions.
@node Readline Variables
@section Readline Variables
File diff suppressed because it is too large Load Diff
+6
View File
@@ -404,6 +404,12 @@ If set to @samp{none}, Readline never rings the bell. If set to
If set to @samp{audible} (the default), Readline attempts to ring
the terminal's bell.
@item bind-tty-special-chars
@vinded bind-tty-special-chars
If set to @samp{on}, Readline attempts to bind the control characters
treated specially by the kernel's terminal driver to their Readline
equivalents.
@item comment-begin
@vindex comment-begin
The string to insert at the beginning of the line when the
+6
View File
@@ -1693,6 +1693,12 @@ shell functions specified with @option{-F}.
@item nospace
Tell Readline not to append a space (the default) to words completed at
the end of the line.
@item plusdirs
After any matches defined by the compspec are generated,
directory name completion is attempted and any
matches are added to the results of the other actions.
@end table
@item -A @var{action}
+5 -5
View File
@@ -2,9 +2,9 @@
Copyright (C) 1988-2004 Free Software Foundation, Inc.
@end ignore
@set EDITION 5.0
@set VERSION 5.0
@set UPDATED 28 January 2004
@set UPDATED-MONTH January 2004
@set EDITION 5.1-devel
@set VERSION 5.1-devel
@set UPDATED 16 October 2004
@set UPDATED-MONTH October 2004
@set LASTCHANGE Wed Jan 28 15:46:54 EST 2004
@set LASTCHANGE Sat Oct 16 19:08:23 EDT 2004
+10
View File
@@ -0,0 +1,10 @@
@ignore
Copyright (C) 1988-2004 Free Software Foundation, Inc.
@end ignore
@set EDITION 5.1-devel
@set VERSION 5.1-devel
@set UPDATED 15 October 2004
@set UPDATED-MONTH October 2004
@set LASTCHANGE Fri Oct 15 14:52:31 EDT 2004
+11 -3
View File
@@ -251,6 +251,10 @@ int _rl_convert_meta_chars_to_ascii = 1;
rather than as a meta-prefixed escape sequence. */
int _rl_output_meta_chars = 0;
/* Non-zero means to look at the termios special characters and bind
them to equivalent readline functions at startup. */
int _rl_bind_stty_chars = 1;
/* **************************************************************** */
/* */
/* Top Level Functions */
@@ -863,7 +867,8 @@ readline_initialize_everything ()
static void
readline_default_bindings ()
{
rl_tty_set_default_bindings (_rl_keymap);
if (_rl_bind_stty_chars)
rl_tty_set_default_bindings (_rl_keymap);
}
/* Reset the default bindings for the terminal special characters we're
@@ -871,8 +876,11 @@ readline_default_bindings ()
static void
reset_default_bindings ()
{
rl_tty_unset_default_bindings (_rl_keymap);
rl_tty_set_default_bindings (_rl_keymap);
if (_rl_bind_stty_chars)
{
rl_tty_unset_default_bindings (_rl_keymap);
rl_tty_set_default_bindings (_rl_keymap);
}
}
/* Bind some common arrow key sequences in MAP. */
File diff suppressed because it is too large Load Diff
+1
View File
@@ -250,6 +250,7 @@ extern int _rl_bell_preference;
extern int _rl_meta_flag;
extern int _rl_convert_meta_chars_to_ascii;
extern int _rl_output_meta_chars;
extern int _rl_bind_stty_chars;
extern char *_rl_comment_begin;
extern unsigned char _rl_parsing_conditionalized_out;
extern Keymap _rl_keymap;
+4 -2
View File
@@ -657,10 +657,12 @@ rl_prep_terminal (meta_flag)
otio = tio;
rl_tty_unset_default_bindings (_rl_keymap);
if (_rl_bind_stty_chars)
rl_tty_unset_default_bindings (_rl_keymap);
save_tty_chars (&otio);
RL_SETSTATE(RL_STATE_TTYCSAVED);
_rl_bind_tty_special_chars (_rl_keymap, tio);
if (_rl_bind_stty_chars)
_rl_bind_tty_special_chars (_rl_keymap, tio);
prepare_terminal_settings (meta_flag, otio, &tio);
+12 -12
View File
@@ -122,16 +122,7 @@ sh_set_lines_and_columns (lines, cols)
{
char *b;
#if defined (HAVE_PUTENV)
b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("LINES=") + 1);
sprintf (b, "LINES=%d", lines);
putenv (b);
b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("COLUMNS=") + 1);
sprintf (b, "COLUMNS=%d", cols);
putenv (b);
#else /* !HAVE_PUTENV */
# if defined (HAVE_SETENV)
#if defined (HAVE_SETENV)
b = (char *)xmalloc (INT_STRLEN_BOUND (int) + 1);
sprintf (b, "%d", lines);
setenv ("LINES", b, 1);
@@ -141,8 +132,17 @@ sh_set_lines_and_columns (lines, cols)
sprintf (b, "%d", cols);
setenv ("COLUMNS", b, 1);
free (b);
# endif /* HAVE_SETENV */
#endif /* !HAVE_PUTENV */
#else /* !HAVE_SETENV */
# if defined (HAVE_PUTENV)
b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("LINES=") + 1);
sprintf (b, "LINES=%d", lines);
putenv (b);
b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("COLUMNS=") + 1);
sprintf (b, "COLUMNS=%d", cols);
putenv (b);
# endif /* HAVE_PUTENV */
#endif /* !HAVE_SETENV */
}
char *
+200
View File
@@ -0,0 +1,200 @@
/* shell.c -- readline utility functions that are normally provided by
bash when readline is linked as part of the shell. */
/* Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU Readline Library, a library for
reading lines of text with interactive input and history editing.
The GNU Readline Library 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.
The GNU Readline Library 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.
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#define READLINE_LIBRARY
#if defined (HAVE_CONFIG_H)
# include <config.h>
#endif
#include <sys/types.h>
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
#if defined (HAVE_STDLIB_H)
# include <stdlib.h>
#else
# include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */
#if defined (HAVE_STRING_H)
# include <string.h>
#else
# include <strings.h>
#endif /* !HAVE_STRING_H */
#if defined (HAVE_LIMITS_H)
# include <limits.h>
#endif
#include <fcntl.h>
#include <pwd.h>
#include <stdio.h>
#include "rlstdc.h"
#include "rlshell.h"
#include "xmalloc.h"
#if !defined (HAVE_GETPW_DECLS)
extern struct passwd *getpwuid PARAMS((uid_t));
#endif /* !HAVE_GETPW_DECLS */
#ifndef NULL
# define NULL 0
#endif
#ifndef CHAR_BIT
# define CHAR_BIT 8
#endif
/* Nonzero if the integer type T is signed. */
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
/* Bound on length of the string representing an integer value of type T.
Subtract one for the sign bit if T is signed;
302 / 1000 is log10 (2) rounded up;
add one for integer division truncation;
add one more for a minus sign if t is signed. */
#define INT_STRLEN_BOUND(t) \
((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 1000 \
+ 1 + TYPE_SIGNED (t))
/* All of these functions are resolved from bash if we are linking readline
as part of bash. */
/* Does shell-like quoting using single quotes. */
char *
sh_single_quote (string)
char *string;
{
register int c;
char *result, *r, *s;
result = (char *)xmalloc (3 + (4 * strlen (string)));
r = result;
*r++ = '\'';
for (s = string; s && (c = *s); s++)
{
*r++ = c;
if (c == '\'')
{
*r++ = '\\'; /* insert escaped single quote */
*r++ = '\'';
*r++ = '\''; /* start new quoted string */
}
}
*r++ = '\'';
*r = '\0';
return (result);
}
/* Set the environment variables LINES and COLUMNS to lines and cols,
respectively. */
void
sh_set_lines_and_columns (lines, cols)
int lines, cols;
{
char *b;
#if defined (HAVE_PUTENV)
b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("LINES=") + 1);
sprintf (b, "LINES=%d", lines);
putenv (b);
b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("COLUMNS=") + 1);
sprintf (b, "COLUMNS=%d", cols);
putenv (b);
#else /* !HAVE_PUTENV */
# if defined (HAVE_SETENV)
b = (char *)xmalloc (INT_STRLEN_BOUND (int) + 1);
sprintf (b, "%d", lines);
setenv ("LINES", b, 1);
free (b);
b = (char *)xmalloc (INT_STRLEN_BOUND (int) + 1);
sprintf (b, "%d", cols);
setenv ("COLUMNS", b, 1);
free (b);
# endif /* HAVE_SETENV */
#endif /* !HAVE_PUTENV */
}
char *
sh_get_env_value (varname)
const char *varname;
{
return ((char *)getenv (varname));
}
char *
sh_get_home_dir ()
{
char *home_dir;
struct passwd *entry;
home_dir = (char *)NULL;
entry = getpwuid (getuid ());
if (entry)
home_dir = entry->pw_dir;
return (home_dir);
}
#if !defined (O_NDELAY)
# if defined (FNDELAY)
# define O_NDELAY FNDELAY
# endif
#endif
int
sh_unset_nodelay_mode (fd)
int fd;
{
int flags, bflags;
if ((flags = fcntl (fd, F_GETFL, 0)) < 0)
return -1;
bflags = 0;
#ifdef O_NONBLOCK
bflags |= O_NONBLOCK;
#endif
#ifdef O_NDELAY
bflags |= O_NDELAY;
#endif
if (flags & bflags)
{
flags &= ~bflags;
return (fcntl (fd, F_SETFL, flags));
}
return 0;
}
+6
View File
@@ -20,6 +20,12 @@
#if !defined (HAVE_STRNLEN)
#include <sys/types.h>
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include <stdc.h>
/* Find the length of S, but scan at most MAXLEN characters. If no '\0'
+8 -4
View File
@@ -962,22 +962,26 @@ pipeline_command: pipeline
{ $$ = $1; }
| BANG pipeline
{
$2->flags |= CMD_INVERT_RETURN;
if ($2)
$2->flags |= CMD_INVERT_RETURN;
$$ = $2;
}
| timespec pipeline
{
$2->flags |= $1;
if ($2)
$2->flags |= $1;
$$ = $2;
}
| timespec BANG pipeline
{
$3->flags |= $1|CMD_INVERT_RETURN;
if ($3)
$3->flags |= $1|CMD_INVERT_RETURN;
$$ = $3;
}
| BANG timespec pipeline
{
$3->flags |= $2|CMD_INVERT_RETURN;
if ($3)
$3->flags |= $2|CMD_INVERT_RETURN;
$$ = $3;
}
| timespec list_terminator
+1 -1
View File
@@ -1,4 +1,4 @@
BUILD_DIR=/usr/local/build/chet/bash/bash-current
BUILD_DIR=/usr/local/build/bash/bash-current
THIS_SH=$BUILD_DIR/bash
PATH=$PATH:$BUILD_DIR