Imported from ../bash-4.0-rc1.tar.gz.
This commit is contained in:
parent
f1be666c7d
commit
3185942a52
666 changed files with 188710 additions and 54674 deletions
|
|
@ -1,20 +1,19 @@
|
|||
# This Makefile for building libbuiltins.a is in -*- text -*- for Emacs.
|
||||
#
|
||||
# Copyright (C) 1996-2005 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1996-2009 Free Software Foundation, Inc.
|
||||
|
||||
# This program 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.
|
||||
# This program 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.
|
||||
|
||||
# This program 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.
|
||||
# This program 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 this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
PACKAGE = @PACKAGE_NAME@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
|
|
@ -39,9 +38,12 @@ prefix = @prefix@
|
|||
srcdir = @srcdir@
|
||||
VPATH = .:@srcdir@
|
||||
topdir = @top_srcdir@
|
||||
|
||||
datarootdir = @datarootdir@
|
||||
|
||||
includedir = @includedir@
|
||||
datadir = @datadir@
|
||||
localedir = $(datadir)/locale
|
||||
localedir = @localedir@
|
||||
|
||||
# Support an alternate destination root directory for package building
|
||||
DESTDIR =
|
||||
|
|
@ -63,7 +65,7 @@ LOCAL_DEFS = @LOCAL_DEFS@
|
|||
|
||||
LIBS = @LIBS@
|
||||
LDFLAGS = @LDFLAGS@ $(LOCAL_LDFLAGS) $(CFLAGS)
|
||||
LDFLAGS_FOR_BUILD = $(LDFLAGS)
|
||||
LDFLAGS_FOR_BUILD = @LDFLAGS_FOR_BUILD@ $(LOCAL_LDFLAGS) $(CFLAGS_FOR_BUILD)
|
||||
LOCAL_LDFLAGS = @LOCAL_LDFLAGS@
|
||||
#LIBS_FOR_BUILD = @LIBS_FOR_BUILD@
|
||||
LIBS_FOR_BUILD = $(LIBS)
|
||||
|
|
@ -74,7 +76,10 @@ RL_INCLUDEDIR = @RL_INCLUDEDIR@
|
|||
|
||||
INTL_LIBSRC = ${topdir}/lib/intl
|
||||
INTL_BUILDDIR = ${LIBBUILD}/intl
|
||||
INTL_LIBDIR = ${INTL_BUILDDIR}
|
||||
INTL_LIBRARY = ${INTL_BUILDDIR}/libintl.a
|
||||
INTL_INC = @INTL_INC@
|
||||
INTL_DEP = @INTL_DEP@
|
||||
LIBINTL_H = @LIBINTL_H@
|
||||
|
||||
HELPDIR = @HELPDIR@
|
||||
|
|
@ -134,7 +139,7 @@ DEFSRC = $(srcdir)/alias.def $(srcdir)/bind.def $(srcdir)/break.def \
|
|||
$(srcdir)/times.def $(srcdir)/trap.def $(srcdir)/type.def \
|
||||
$(srcdir)/ulimit.def $(srcdir)/umask.def $(srcdir)/wait.def \
|
||||
$(srcdir)/reserved.def $(srcdir)/pushd.def $(srcdir)/shopt.def \
|
||||
$(srcdir)/printf.def $(srcdir)/complete.def
|
||||
$(srcdir)/printf.def $(srcdir)/complete.def $(srcdir)/mapfile.def
|
||||
|
||||
STATIC_SOURCE = common.c evalstring.c evalfile.c getopt.c bashgetopt.c \
|
||||
getopt.h
|
||||
|
|
@ -142,8 +147,8 @@ STATIC_SOURCE = common.c evalstring.c evalfile.c getopt.c bashgetopt.c \
|
|||
OFILES = builtins.o \
|
||||
alias.o bind.o break.o builtin.o caller.o cd.o colon.o command.o \
|
||||
common.o declare.o echo.o enable.o eval.o evalfile.o \
|
||||
evalstring.o exec.o \
|
||||
exit.o fc.o fg_bg.o hash.o help.o history.o jobs.o kill.o let.o \
|
||||
evalstring.o exec.o exit.o fc.o fg_bg.o hash.o help.o history.o \
|
||||
jobs.o kill.o let.o mapfile.o \
|
||||
pushd.o read.o return.o set.o setattr.o shift.o source.o \
|
||||
suspend.o test.o times.o trap.o type.o ulimit.o umask.o \
|
||||
wait.o getopts.o shopt.o printf.o getopt.o bashgetopt.o complete.o
|
||||
|
|
@ -236,6 +241,11 @@ $(OFILES): $(MKBUILTINS) ../config.h
|
|||
po: builtins.c
|
||||
xgettext -L C -o $(topdir)/po/builtins.pot --keyword='N_' builtins.c 2>/dev/null
|
||||
|
||||
${LIBINTL_H}:
|
||||
@echo making $@ in ${INTL_BUILDDIR}
|
||||
@(cd ${INTL_BUILDDIR} && \
|
||||
$(MAKE) $(MFLAGS) libintl.h) || exit 1
|
||||
|
||||
# dependencies
|
||||
|
||||
alias.o: alias.def
|
||||
|
|
@ -260,6 +270,7 @@ history.o: history.def
|
|||
jobs.o: jobs.def
|
||||
kill.o: kill.def
|
||||
let.o: let.def
|
||||
mapfile.o: mapfile.def
|
||||
printf.o: printf.def
|
||||
pushd.o: pushd.def
|
||||
read.o: read.def
|
||||
|
|
@ -584,6 +595,12 @@ complete.o: ${topdir}/bashtypes.h ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib
|
|||
complete.o: ${topdir}/builtins.h
|
||||
complete.o: ${topdir}/pcomplete.h
|
||||
complete.o: ${srcdir}/common.h ${srcdir}/bashgetopt.h
|
||||
mapfile.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
mapfile.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
mapfile.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
|
||||
mapfile.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
mapfile.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
mapfile.o: $(topdir)/arrayfunc.h
|
||||
|
||||
#bind.o: $(RL_LIBSRC)chardefs.h $(RL_LIBSRC)readline.h $(RL_LIBSRC)keymaps.h
|
||||
|
||||
|
|
@ -609,7 +626,8 @@ inlib.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
|||
jobs.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
kill.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
let.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
mkbuiltins.c: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
mapfile.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
mkbuiltins.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
printf.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
pushd.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
read.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
|
|
|
|||
|
|
@ -1,35 +1,43 @@
|
|||
This file is alias.def, from which is created alias.c
|
||||
It implements the builtins "alias" and "unalias" in Bash.
|
||||
|
||||
Copyright (C) 1987-2004 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/>.
|
||||
|
||||
$BUILTIN alias
|
||||
$FUNCTION alias_builtin
|
||||
$DEPENDS_ON ALIAS
|
||||
$PRODUCES alias.c
|
||||
$SHORT_DOC alias [-p] [name[=value] ... ]
|
||||
`alias' with no arguments or with the -p option prints the list
|
||||
of aliases in the form alias NAME=VALUE on standard output.
|
||||
Define or display aliases.
|
||||
|
||||
Without arguments, `alias' prints the list of aliases in the reusable
|
||||
form `alias NAME=VALUE' on standard output.
|
||||
|
||||
Otherwise, an alias is defined for each NAME whose VALUE is given.
|
||||
A trailing space in VALUE causes the next word to be checked for
|
||||
alias substitution when the alias is expanded. Alias returns
|
||||
true unless a NAME is given for which no alias has been defined.
|
||||
alias substitution when the alias is expanded.
|
||||
|
||||
Options:
|
||||
-p Print all defined aliases in a reusable format
|
||||
|
||||
Exit Status:
|
||||
alias returns true unless a NAME is supplied for which no alias has been
|
||||
defined.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -103,7 +111,7 @@ alias_builtin (list)
|
|||
free (alias_list); /* XXX - Do not free the strings. */
|
||||
|
||||
if (list == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
any_failed = 0;
|
||||
|
|
@ -149,8 +157,12 @@ $BUILTIN unalias
|
|||
$FUNCTION unalias_builtin
|
||||
$DEPENDS_ON ALIAS
|
||||
$SHORT_DOC unalias [-a] name [name ...]
|
||||
Remove NAMEs from the list of defined aliases. If the -a option is given,
|
||||
then remove all alias definitions.
|
||||
Remove each NAME from the list of defined aliases.
|
||||
|
||||
Options:
|
||||
-a remove all alias definitions.
|
||||
|
||||
Return success unless a NAME is not an existing alias.
|
||||
$END
|
||||
|
||||
#if defined (ALIAS)
|
||||
|
|
|
|||
|
|
@ -2,21 +2,21 @@
|
|||
|
||||
/* Copyright (C) 1992-2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,19 +4,19 @@
|
|||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/* See getopt.h for the explanation of these variables. */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
This file is bind.def, from which is created bind.c.
|
||||
It implements the builtin "bind" 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 bind.c
|
||||
|
||||
|
|
@ -27,12 +26,15 @@ $BUILTIN bind
|
|||
$DEPENDS_ON READLINE
|
||||
$FUNCTION bind_builtin
|
||||
$SHORT_DOC bind [-lpvsPVS] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
|
||||
Bind a key sequence to a Readline function or a macro, or set
|
||||
a Readline variable. The non-option argument syntax is equivalent
|
||||
to that found in ~/.inputrc, but must be passed as a single argument:
|
||||
bind '"\C-x\C-r": re-read-init-file'.
|
||||
bind accepts the following options:
|
||||
-m keymap Use `keymap' as the keymap for the duration of this
|
||||
Set Readline key bindings and variables.
|
||||
|
||||
Bind a key sequence to a Readline function or a macro, or set a
|
||||
Readline variable. The non-option argument syntax is equivalent to
|
||||
that found in ~/.inputrc, but must be passed as a single argument:
|
||||
e.g., bind '"\C-x\C-r": re-read-init-file'.
|
||||
|
||||
Options:
|
||||
-m keymap Use KEYMAP as the keymap for the duration of this
|
||||
command. Acceptable keymap names are emacs,
|
||||
emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move,
|
||||
vi-command, and vi-insert.
|
||||
|
|
@ -40,18 +42,21 @@ bind accepts the following options:
|
|||
-P List function names and bindings.
|
||||
-p List functions and bindings in a form that can be
|
||||
reused as input.
|
||||
-r keyseq Remove the binding for KEYSEQ.
|
||||
-x keyseq:shell-command Cause SHELL-COMMAND to be executed when
|
||||
KEYSEQ is entered.
|
||||
-f filename Read key bindings from FILENAME.
|
||||
-q function-name Query about which keys invoke the named function.
|
||||
-u function-name Unbind all keys which are bound to the named function.
|
||||
-V List variable names and values
|
||||
-v List variable names and values in a form that can
|
||||
be reused as input.
|
||||
-S List key sequences that invoke macros and their values
|
||||
-s List key sequences that invoke macros and their values
|
||||
in a form that can be reused as input.
|
||||
-V List variable names and values
|
||||
-v List variable names and values in a form that can
|
||||
be reused as input.
|
||||
-q function-name Query about which keys invoke the named function.
|
||||
-u function-name Unbind all keys which are bound to the named function.
|
||||
-r keyseq Remove the binding for KEYSEQ.
|
||||
-f filename Read key bindings from FILENAME.
|
||||
-x keyseq:shell-command Cause SHELL-COMMAND to be executed when
|
||||
KEYSEQ is entered.
|
||||
|
||||
Exit Status:
|
||||
bind returns 0 unless an unrecognized option is given or an error occurs.
|
||||
$END
|
||||
|
||||
#if defined (READLINE)
|
||||
|
|
@ -110,14 +115,21 @@ bind_builtin (list)
|
|||
char *initfile, *map_name, *fun_name, *unbind_name, *remove_seq, *cmd_seq;
|
||||
|
||||
if (no_line_editing)
|
||||
return (EXECUTION_FAILURE);
|
||||
{
|
||||
#if 0
|
||||
builtin_error (_("line editing not enabled"));
|
||||
return (EXECUTION_FAILURE);
|
||||
#else
|
||||
builtin_warning (_("line editing not enabled"));
|
||||
#endif
|
||||
}
|
||||
|
||||
kmap = saved_keymap = (Keymap) NULL;
|
||||
flags = 0;
|
||||
initfile = map_name = fun_name = unbind_name = remove_seq = (char *)NULL;
|
||||
return_code = EXECUTION_SUCCESS;
|
||||
|
||||
if (!bash_readline_initialized)
|
||||
if (bash_readline_initialized == 0)
|
||||
initialize_readline ();
|
||||
|
||||
begin_unwind_frame ("bind_builtin");
|
||||
|
|
@ -266,7 +278,7 @@ bind_builtin (list)
|
|||
|
||||
run_unwind_frame ("bind_builtin");
|
||||
|
||||
return (return_code);
|
||||
return (sh_chkwrite (return_code));
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -310,7 +322,7 @@ unbind_command (name)
|
|||
function = rl_named_function (name);
|
||||
if (function == 0)
|
||||
{
|
||||
builtin_error ("`%s': unknown function name", name);
|
||||
builtin_error (_("`%s': unknown function name"), name);
|
||||
return EXECUTION_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +1,35 @@
|
|||
This file is break.def, from which is created break.c.
|
||||
It implements the builtins "break" and "continue" 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 break.c
|
||||
|
||||
$BUILTIN break
|
||||
$FUNCTION break_builtin
|
||||
$SHORT_DOC break [n]
|
||||
Exit from within a FOR, WHILE or UNTIL loop. If N is specified,
|
||||
break N levels.
|
||||
Exit for, while, or until loops.
|
||||
|
||||
Exit a FOR, WHILE or UNTIL loop. If N is specified, break N enclosing
|
||||
loops.
|
||||
|
||||
Exit Status:
|
||||
The exit status is 0 unless N is not greater than or equal to 1.
|
||||
$END
|
||||
#include <config.h>
|
||||
|
||||
|
|
@ -66,11 +70,11 @@ break_builtin (list)
|
|||
if (check_loop_level () == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
newbreak = get_numeric_arg (list, 1);
|
||||
(void)get_numeric_arg (list, 1, &newbreak);
|
||||
|
||||
if (newbreak <= 0)
|
||||
{
|
||||
sh_erange (list->word->word, "loop count");
|
||||
sh_erange (list->word->word, _("loop count"));
|
||||
breaking = loop_level;
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
|
@ -86,8 +90,13 @@ break_builtin (list)
|
|||
$BUILTIN continue
|
||||
$FUNCTION continue_builtin
|
||||
$SHORT_DOC continue [n]
|
||||
Resume the next iteration of the enclosing FOR, WHILE or UNTIL loop.
|
||||
If N is specified, resume at the N-th enclosing loop.
|
||||
Resume for, while, or until loops.
|
||||
|
||||
Resumes the next iteration of the enclosing FOR, WHILE or UNTIL loop.
|
||||
If N is specified, resumes the Nth enclosing loop.
|
||||
|
||||
Exit Status:
|
||||
The exit status is 0 unless N is not greater than or equal to 1.
|
||||
$END
|
||||
|
||||
/* Set up to continue x levels, where x defaults to 1, but can be specified
|
||||
|
|
@ -101,11 +110,11 @@ continue_builtin (list)
|
|||
if (check_loop_level () == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
newcont = get_numeric_arg (list, 1);
|
||||
(void)get_numeric_arg (list, 1, &newcont);
|
||||
|
||||
if (newcont <= 0)
|
||||
{
|
||||
sh_erange (list->word->word, "loop count");
|
||||
sh_erange (list->word->word, _("loop count"));
|
||||
breaking = loop_level;
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,37 @@
|
|||
This file is builtin.def, from which is created builtin.c.
|
||||
It implements the builtin "builtin" in Bash.
|
||||
|
||||
Copyright (C) 1987-2002 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 builtin.c
|
||||
|
||||
$BUILTIN builtin
|
||||
$FUNCTION builtin_builtin
|
||||
$SHORT_DOC builtin [shell-builtin [arg ...]]
|
||||
Run a shell builtin. This is useful when you wish to rename a
|
||||
shell builtin to be a function, but need the functionality of the
|
||||
builtin within the function itself.
|
||||
Execute shell builtins.
|
||||
|
||||
Execute SHELL-BUILTIN with arguments ARGs without performing command
|
||||
lookup. This is useful when you wish to reimplement a shell builtin
|
||||
as a shell function, but need to execute the builtin within the function.
|
||||
|
||||
Exit Status:
|
||||
Returns the exit status of SHELL-BUILTIN, or false if SHELL-BUILTIN is
|
||||
not a shell builtin..
|
||||
$END
|
||||
#include <config.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,39 +1,41 @@
|
|||
This file is caller.def, from which is created caller.c. It implements the
|
||||
builtin "caller" in Bash.
|
||||
|
||||
Copyright (C) 2002-2003 Rocky Bernstein for Free Software Foundation, Inc.
|
||||
Copyright (C) 2002-2008 Rocky Bernstein for 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 caller.c
|
||||
|
||||
$BUILTIN caller
|
||||
$FUNCTION caller_builtin
|
||||
$DEPENDS_ON DEBUGGER
|
||||
$SHORT_DOC caller [EXPR]
|
||||
$SHORT_DOC caller [expr]
|
||||
Return the context of the current subroutine call.
|
||||
|
||||
Returns the context of the current subroutine call.
|
||||
|
||||
Without EXPR, returns "$line $filename". With EXPR,
|
||||
returns "$line $subroutine $filename"; this extra information
|
||||
can be used to provide a stack trace.
|
||||
Without EXPR, returns "$line $filename". With EXPR, returns
|
||||
"$line $subroutine $filename"; this extra information can be used to
|
||||
provide a stack trace.
|
||||
|
||||
The value of EXPR indicates how many call frames to go back before the
|
||||
current one; the top frame is frame 0.
|
||||
|
||||
Exit Status:
|
||||
Returns 0 unless the shell is not executing a shell function or EXPR
|
||||
is invalid.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -128,14 +130,14 @@ caller_builtin (list)
|
|||
|
||||
#ifdef LOADABLE_BUILTIN
|
||||
static char *caller_doc[] = {
|
||||
N_("Returns the context of the current subroutine call."),
|
||||
N_(" "),
|
||||
N_("Without EXPR, returns returns \"$line $filename\". With EXPR,"),
|
||||
N_("returns \"$line $subroutine $filename\"; this extra information"),
|
||||
N_("can be used used to provide a stack trace."),
|
||||
N_(" "),
|
||||
N_("The value of EXPR indicates how many call frames to go back before the"),
|
||||
N_("current one; the top frame is frame 0."),
|
||||
N_("Returns the context of the current subroutine call.\n\
|
||||
\n\
|
||||
Without EXPR, returns "$line $filename". With EXPR, returns\n\
|
||||
"$line $subroutine $filename"; this extra information can be used to\n\
|
||||
provide a stack trace.\n\
|
||||
\n\
|
||||
The value of EXPR indicates how many call frames to go back before the\n\
|
||||
current one; the top frame is frame 0."),
|
||||
(char *)NULL
|
||||
};
|
||||
|
||||
|
|
|
|||
121
builtins/cd.def
121
builtins/cd.def
|
|
@ -1,23 +1,22 @@
|
|||
This file is cd.def, from which is created cd.c. It implements the
|
||||
builtins "cd" and "pwd" in Bash.
|
||||
|
||||
Copyright (C) 1987-2005 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 cd.c
|
||||
#include <config.h>
|
||||
|
|
@ -56,15 +55,13 @@ extern int errno;
|
|||
|
||||
extern int posixly_correct;
|
||||
extern int array_needs_making;
|
||||
extern char *bash_getcwd_errstr;
|
||||
extern const char * const bash_getcwd_errstr;
|
||||
|
||||
static int bindpwd __P((int));
|
||||
static void setpwd __P((char *));
|
||||
static char *resetpwd __P((char *));
|
||||
static int change_to_directory __P((char *, int));
|
||||
|
||||
static char *cdspell __P((char *));
|
||||
|
||||
/* Change this to 1 to get cd spelling correction by default. */
|
||||
int cdspelling = 0;
|
||||
|
||||
|
|
@ -73,17 +70,29 @@ int cdable_vars;
|
|||
$BUILTIN cd
|
||||
$FUNCTION cd_builtin
|
||||
$SHORT_DOC cd [-L|-P] [dir]
|
||||
Change the current directory to DIR. The variable $HOME is the
|
||||
default DIR. The variable CDPATH defines the search path for
|
||||
the directory containing DIR. Alternative directory names in CDPATH
|
||||
are separated by a colon (:). A null directory name is the same as
|
||||
the current directory, i.e. `.'. If DIR begins with a slash (/),
|
||||
then CDPATH is not used. If the directory is not found, and the
|
||||
shell option `cdable_vars' is set, then try the word as a variable
|
||||
name. If that variable has a value, then cd to the value of that
|
||||
variable. The -P option says to use the physical directory structure
|
||||
instead of following symbolic links; the -L option forces symbolic links
|
||||
to be followed.
|
||||
Change the shell working directory.
|
||||
|
||||
Change the current directory to DIR. The default DIR is the value of the
|
||||
HOME shell variable.
|
||||
|
||||
The variable CDPATH defines the search path for the directory containing
|
||||
DIR. Alternative directory names in CDPATH are separated by a colon (:).
|
||||
A null directory name is the same as the current directory. If DIR begins
|
||||
with a slash (/), then CDPATH is not used.
|
||||
|
||||
If the directory is not found, and the shell option `cdable_vars' is set,
|
||||
the word is assumed to be a variable name. If that variable has a value,
|
||||
its value is used for DIR.
|
||||
|
||||
Options:
|
||||
-L force symbolic links to be followed
|
||||
-P use the physical directory structure without following symbolic
|
||||
links
|
||||
|
||||
The default is to follow symbolic links, as if `-L' were specified.
|
||||
|
||||
Exit Status:
|
||||
Returns 0 if the directory is changed; non-zero otherwise.
|
||||
$END
|
||||
|
||||
/* Just set $PWD, don't change OLDPWD. Used by `pwd -P' in posix mode. */
|
||||
|
|
@ -108,9 +117,11 @@ bindpwd (no_symlinks)
|
|||
int no_symlinks;
|
||||
{
|
||||
char *dirname, *pwdvar;
|
||||
int old_anm;
|
||||
int old_anm, r;
|
||||
SHELL_VAR *tvar;
|
||||
|
||||
r = sh_chkwrite (EXECUTION_SUCCESS);
|
||||
|
||||
#define tcwd the_current_working_directory
|
||||
dirname = tcwd ? (no_symlinks ? sh_physpath (tcwd, 0) : tcwd)
|
||||
: get_working_directory ("cd");
|
||||
|
|
@ -131,7 +142,7 @@ bindpwd (no_symlinks)
|
|||
if (dirname && dirname != the_current_working_directory)
|
||||
free (dirname);
|
||||
|
||||
return (EXECUTION_SUCCESS);
|
||||
return (r);
|
||||
}
|
||||
|
||||
/* Call get_working_directory to reset the value of
|
||||
|
|
@ -224,7 +235,7 @@ cd_builtin (list)
|
|||
}
|
||||
else if (absolute_pathname (list->word->word))
|
||||
dirname = list->word->word;
|
||||
else if (cdpath = get_string_value ("CDPATH"))
|
||||
else if (privileged_mode == 0 && (cdpath = get_string_value ("CDPATH")))
|
||||
{
|
||||
dirname = list->word->word;
|
||||
|
||||
|
|
@ -300,7 +311,7 @@ cd_builtin (list)
|
|||
typo. This is similar to the UNIX 8th and 9th Edition shells. */
|
||||
if (lflag & LCD_DOSPELL)
|
||||
{
|
||||
temp = cdspell (dirname);
|
||||
temp = dirspell (dirname);
|
||||
if (temp && change_to_directory (temp, no_symlinks))
|
||||
{
|
||||
printf ("%s\n", temp);
|
||||
|
|
@ -317,9 +328,18 @@ cd_builtin (list)
|
|||
$BUILTIN pwd
|
||||
$FUNCTION pwd_builtin
|
||||
$SHORT_DOC pwd [-LP]
|
||||
Print the current working directory. With the -P option, pwd prints
|
||||
the physical directory, without any symbolic links; the -L option
|
||||
makes pwd follow symbolic links.
|
||||
Print the name of the current working directory.
|
||||
|
||||
Options:
|
||||
-L print the value of $PWD if it names the current working
|
||||
directory
|
||||
-P print the physical directory, without any symbolic links
|
||||
|
||||
By default, `pwd' behaves as if `-L' were specified.
|
||||
|
||||
Exit Status:
|
||||
Returns 0 unless an invalid option is given or the current directory
|
||||
cannot be read.
|
||||
$END
|
||||
|
||||
/* Non-zero means that pwd always prints the physical directory, without
|
||||
|
|
@ -375,15 +395,7 @@ pwd_builtin (list)
|
|||
setpwd (directory);
|
||||
if (directory != the_current_working_directory)
|
||||
free (directory);
|
||||
fflush (stdout);
|
||||
if (ferror (stdout))
|
||||
{
|
||||
sh_wrerror ();
|
||||
clearerr (stdout);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
return (EXECUTION_SUCCESS);
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
else
|
||||
return (EXECUTION_FAILURE);
|
||||
|
|
@ -499,28 +511,3 @@ change_to_directory (newdir, nolinks)
|
|||
free (tdir);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Code for cd spelling correction. Original patch submitted by
|
||||
Neil Russel (caret@c-side.com). */
|
||||
|
||||
static char *
|
||||
cdspell (dirname)
|
||||
char *dirname;
|
||||
{
|
||||
int n;
|
||||
char *guess;
|
||||
|
||||
n = (strlen (dirname) * 3 + 1) / 2 + 1;
|
||||
guess = (char *)xmalloc (n);
|
||||
|
||||
switch (spname (dirname, guess))
|
||||
{
|
||||
case -1:
|
||||
default:
|
||||
free (guess);
|
||||
return (char *)NULL;
|
||||
case 0:
|
||||
case 1:
|
||||
return guess;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
This file is colon.def, from which is created colon.c.
|
||||
It implements the builtin ":" in Bash.
|
||||
|
||||
Copyright (C) 1987-2002 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 colon.c
|
||||
|
||||
|
|
@ -25,19 +24,30 @@ $BUILTIN :
|
|||
$DOCNAME colon
|
||||
$FUNCTION colon_builtin
|
||||
$SHORT_DOC :
|
||||
No effect; the command does nothing. A zero exit code is returned.
|
||||
Null command.
|
||||
|
||||
No effect; the command does nothing.
|
||||
|
||||
Exit Status:
|
||||
Always succeeds.
|
||||
$END
|
||||
|
||||
$BUILTIN true
|
||||
$FUNCTION colon_builtin
|
||||
$SHORT_DOC true
|
||||
Return a successful result.
|
||||
|
||||
Exit Status:
|
||||
Always succeeds.
|
||||
$END
|
||||
|
||||
$BUILTIN false
|
||||
$FUNCTION false_builtin
|
||||
$SHORT_DOC false
|
||||
Return an unsuccessful result.
|
||||
|
||||
Exit Status:
|
||||
Always fails.
|
||||
$END
|
||||
|
||||
/* Return a successful result. */
|
||||
|
|
|
|||
|
|
@ -1,35 +1,42 @@
|
|||
This file is command.def, from which is created command.c.
|
||||
It implements the builtin "command" in Bash.
|
||||
|
||||
Copyright (C) 1987-2004 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 command.c
|
||||
|
||||
$BUILTIN command
|
||||
$FUNCTION command_builtin
|
||||
$SHORT_DOC command [-pVv] command [arg ...]
|
||||
Runs COMMAND with ARGS ignoring shell functions. If you have a shell
|
||||
function called `ls', and you wish to call the command `ls', you can
|
||||
say "command ls". If the -p option is given, a default value is used
|
||||
for PATH that is guaranteed to find all of the standard utilities. If
|
||||
the -V or -v option is given, a string is printed describing COMMAND.
|
||||
The -V option produces a more verbose description.
|
||||
Execute a simple command or display information about commands.
|
||||
|
||||
Runs COMMAND with ARGS suppressing shell function lookup, or display
|
||||
information about the specified COMMANDs. Can be used to invoke commands
|
||||
on disk when a function with the same name exists.
|
||||
|
||||
Options:
|
||||
-p use a default value for PATH that is guaranteed to find all of
|
||||
the standard utilities
|
||||
-v print a description of COMMAND similar to the `type' builtin
|
||||
-V print a more verbose description of each COMMAND
|
||||
|
||||
Exit Status:
|
||||
Returns exit status of COMMAND, or failure if COMMAND is not found.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
/* Copyright (C) 1987-2007 Free Software Foundation, Inc.
|
||||
/* common.c - utility functions for all builtins */
|
||||
|
||||
/* 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.
|
||||
|
||||
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. */
|
||||
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. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
|
@ -42,6 +44,8 @@
|
|||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#define NEED_FPURGE_DECL
|
||||
|
||||
#include "../shell.h"
|
||||
#include "maxpath.h"
|
||||
#include "../flags.h"
|
||||
|
|
@ -69,7 +73,7 @@ extern int last_command_exit_value;
|
|||
extern int running_trap;
|
||||
extern int posixly_correct;
|
||||
extern char *this_command_name, *shell_name;
|
||||
extern char *bash_getcwd_errstr;
|
||||
extern const char * const bash_getcwd_errstr;
|
||||
|
||||
/* Used by some builtins and the mainline code. */
|
||||
sh_builtin_func_t *last_shell_builtin = (sh_builtin_func_t *)NULL;
|
||||
|
|
@ -84,6 +88,22 @@ sh_builtin_func_t *this_shell_builtin = (sh_builtin_func_t *)NULL;
|
|||
/* This is a lot like report_error (), but it is for shell builtins
|
||||
instead of shell control structures, and it won't ever exit the
|
||||
shell. */
|
||||
|
||||
static void
|
||||
builtin_error_prolog ()
|
||||
{
|
||||
char *name;
|
||||
|
||||
name = get_name_for_error ();
|
||||
fprintf (stderr, "%s: ", name);
|
||||
|
||||
if (interactive_shell == 0)
|
||||
fprintf (stderr, _("line %d: "), executing_line_number ());
|
||||
|
||||
if (this_command_name && *this_command_name)
|
||||
fprintf (stderr, "%s: ", this_command_name);
|
||||
}
|
||||
|
||||
void
|
||||
#if defined (PREFER_STDARG)
|
||||
builtin_error (const char *format, ...)
|
||||
|
|
@ -94,16 +114,29 @@ builtin_error (format, va_alist)
|
|||
#endif
|
||||
{
|
||||
va_list args;
|
||||
char *name;
|
||||
|
||||
name = get_name_for_error ();
|
||||
fprintf (stderr, "%s: ", name);
|
||||
builtin_error_prolog ();
|
||||
|
||||
if (interactive_shell == 0)
|
||||
fprintf (stderr, "line %d: ", executing_line_number ());
|
||||
SH_VA_START (args, format);
|
||||
|
||||
if (this_command_name && *this_command_name)
|
||||
fprintf (stderr, "%s: ", this_command_name);
|
||||
vfprintf (stderr, format, args);
|
||||
va_end (args);
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
|
||||
void
|
||||
#if defined (PREFER_STDARG)
|
||||
builtin_warning (const char *format, ...)
|
||||
#else
|
||||
builtin_warning (format, va_alist)
|
||||
const char *format;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
|
||||
builtin_error_prolog ();
|
||||
fprintf (stderr, _("warning: "));
|
||||
|
||||
SH_VA_START (args, format);
|
||||
|
||||
|
|
@ -117,7 +150,7 @@ void
|
|||
builtin_usage ()
|
||||
{
|
||||
if (this_command_name && *this_command_name)
|
||||
fprintf (stderr, "%s: usage: ", this_command_name);
|
||||
fprintf (stderr, _("%s: usage: "), this_command_name);
|
||||
fprintf (stderr, "%s\n", current_builtin->short_doc);
|
||||
fflush (stderr);
|
||||
}
|
||||
|
|
@ -199,7 +232,15 @@ void
|
|||
sh_invalidnum (s)
|
||||
char *s;
|
||||
{
|
||||
builtin_error (_("%s: invalid number"), s);
|
||||
char *msg;
|
||||
|
||||
if (*s == '0' && isdigit (s[1]))
|
||||
msg = _("invalid octal number");
|
||||
else if (*s == '0' && s[1] == 'x')
|
||||
msg = _("invalid hex number");
|
||||
else
|
||||
msg = _("invalid number");
|
||||
builtin_error ("%s: %s", s, msg);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -274,9 +315,27 @@ sh_notbuiltin (s)
|
|||
void
|
||||
sh_wrerror ()
|
||||
{
|
||||
#if defined (DONT_REPORT_BROKEN_PIPE_WRITE_ERRORS) && defined (EPIPE)
|
||||
if (errno != EPIPE)
|
||||
#endif /* DONT_REPORT_BROKEN_PIPE_WRITE_ERRORS && EPIPE */
|
||||
builtin_error (_("write error: %s"), strerror (errno));
|
||||
}
|
||||
|
||||
int
|
||||
sh_chkwrite (s)
|
||||
int s;
|
||||
{
|
||||
fflush (stdout);
|
||||
if (ferror (stdout))
|
||||
{
|
||||
sh_wrerror ();
|
||||
fpurge (stdout);
|
||||
clearerr (stdout);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
return (s);
|
||||
}
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* Shell positional parameter manipulation */
|
||||
|
|
@ -372,30 +431,35 @@ set_dollar_vars_changed ()
|
|||
/* Read a numeric arg for this_command_name, the name of the shell builtin
|
||||
that wants it. LIST is the word list that the arg is to come from.
|
||||
Accept only the numeric argument; report an error if other arguments
|
||||
follow. If FATAL is true, call throw_to_top_level, which exits the
|
||||
shell; if not, call jump_to_top_level (DISCARD), which aborts the
|
||||
current command. */
|
||||
intmax_t
|
||||
get_numeric_arg (list, fatal)
|
||||
follow. If FATAL is 1, call throw_to_top_level, which exits the
|
||||
shell; if it's 2, call jump_to_top_level (DISCARD), which aborts the
|
||||
current command; if FATAL is 0, return an indication of an invalid
|
||||
number by setting *NUMOK == 0 and return -1. */
|
||||
int
|
||||
get_numeric_arg (list, fatal, count)
|
||||
WORD_LIST *list;
|
||||
int fatal;
|
||||
intmax_t *count;
|
||||
{
|
||||
intmax_t count = 1;
|
||||
char *arg;
|
||||
|
||||
if (count)
|
||||
*count = 1;
|
||||
|
||||
if (list && list->word && ISOPTION (list->word->word, '-'))
|
||||
list = list->next;
|
||||
|
||||
if (list)
|
||||
{
|
||||
register char *arg;
|
||||
|
||||
arg = list->word->word;
|
||||
if (arg == 0 || (legal_number (arg, &count) == 0))
|
||||
if (arg == 0 || (legal_number (arg, count) == 0))
|
||||
{
|
||||
sh_neednumarg (list->word->word);
|
||||
if (fatal)
|
||||
sh_neednumarg (list->word->word ? list->word->word : "`'");
|
||||
if (fatal == 0)
|
||||
return 0;
|
||||
else if (fatal == 1) /* fatal == 1; abort */
|
||||
throw_to_top_level ();
|
||||
else
|
||||
else /* fatal == 2; discard current command */
|
||||
{
|
||||
top_level_cleanup ();
|
||||
jump_to_top_level (DISCARD);
|
||||
|
|
@ -404,7 +468,7 @@ get_numeric_arg (list, fatal)
|
|||
no_args (list->next);
|
||||
}
|
||||
|
||||
return (count);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Get an eight-bit status value from LIST */
|
||||
|
|
@ -647,7 +711,7 @@ display_signal_list (list, forcecols)
|
|||
{
|
||||
printf ("%2d) %s", i, name);
|
||||
|
||||
if (++column < 4)
|
||||
if (++column < 5)
|
||||
printf ("\t");
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,19 +4,19 @@
|
|||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#if !defined (__COMMON_H)
|
||||
# define __COMMON_H
|
||||
|
|
@ -31,6 +31,8 @@
|
|||
#define SEVAL_NOHIST 0x004
|
||||
#define SEVAL_NOFREE 0x008
|
||||
#define SEVAL_RESETLINE 0x010
|
||||
#define SEVAL_PARSEONLY 0x020
|
||||
#define SEVAL_NOLONGJMP 0x040
|
||||
|
||||
/* Flags for describe_command, shared between type.def and command.def */
|
||||
#define CDESC_ALL 0x001 /* type -a */
|
||||
|
|
@ -57,6 +59,7 @@
|
|||
|
||||
/* Functions from common.c */
|
||||
extern void builtin_error __P((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
|
||||
extern void builtin_warning __P((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
|
||||
extern void builtin_usage __P((void));
|
||||
extern void no_args __P((WORD_LIST *));
|
||||
extern int no_options __P((WORD_LIST *));
|
||||
|
|
@ -78,6 +81,7 @@ extern void sh_nojobs __P((char *));
|
|||
extern void sh_restricted __P((char *));
|
||||
extern void sh_notbuiltin __P((char *));
|
||||
extern void sh_wrerror __P((void));
|
||||
extern int sh_chkwrite __P((int));
|
||||
|
||||
extern char **make_builtin_argv __P((WORD_LIST *, int *));
|
||||
extern void remember_args __P((WORD_LIST *, int));
|
||||
|
|
@ -86,7 +90,7 @@ extern int dollar_vars_changed __P((void));
|
|||
extern void set_dollar_vars_unchanged __P((void));
|
||||
extern void set_dollar_vars_changed __P((void));
|
||||
|
||||
extern intmax_t get_numeric_arg __P((WORD_LIST *, int));
|
||||
extern int get_numeric_arg __P((WORD_LIST *, int, intmax_t *));
|
||||
extern int get_exitstat __P((WORD_LIST *));
|
||||
extern int read_octal __P((char *));
|
||||
|
||||
|
|
@ -141,6 +145,7 @@ extern int describe_command __P((char *, int));
|
|||
|
||||
/* Functions from setattr.def */
|
||||
extern int set_or_show_attributes __P((WORD_LIST *, int, int));
|
||||
extern int show_all_var_attributes __P((int, int));
|
||||
extern int show_var_attributes __P((SHELL_VAR *, int, int));
|
||||
extern int show_name_attributes __P((char *, int));
|
||||
extern void set_var_attribute __P((char *, int, int));
|
||||
|
|
@ -154,6 +159,7 @@ extern WORD_LIST *get_directory_stack __P((int));
|
|||
/* Functions from evalstring.c */
|
||||
extern int parse_and_execute __P((char *, const char *, int));
|
||||
extern void parse_and_execute_cleanup __P((void));
|
||||
extern int parse_string __P((char *, const char *, int, char **));
|
||||
|
||||
/* Functions from evalfile.c */
|
||||
extern int maybe_execute_file __P((const char *, int));
|
||||
|
|
|
|||
|
|
@ -1,35 +1,45 @@
|
|||
This file is complete.def, from which is created complete.c.
|
||||
It implements the builtins "complete" and "compgen" in Bash.
|
||||
It implements the builtins "complete", "compgen", and "compopt" in Bash.
|
||||
|
||||
Copyright (C) 1999-2003 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-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 complete.c
|
||||
|
||||
$BUILTIN complete
|
||||
$DEPENDS_ON PROGRAMMABLE_COMPLETION
|
||||
$FUNCTION complete_builtin
|
||||
$SHORT_DOC complete [-abcdefgjksuv] [-pr] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [name ...]
|
||||
For each NAME, specify how arguments are to be completed.
|
||||
If the -p option is supplied, or if no options are supplied, existing
|
||||
completion specifications are printed in a way that allows them to be
|
||||
reused as input. The -r option removes a completion specification for
|
||||
each NAME, or, if no NAMEs are supplied, all completion specifications.
|
||||
$SHORT_DOC complete [-abcdefgjksuv] [-pr] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
|
||||
Specify how arguments are to be completed by Readline.
|
||||
|
||||
For each NAME, specify how arguments are to be completed. If no options
|
||||
are supplied, existing completion specifications are printed in a way that
|
||||
allows them to be reused as input.
|
||||
|
||||
Options:
|
||||
-p print existing completion specifications in a reusable format
|
||||
-r remove a completion specification for each NAME, or, if no
|
||||
NAMEs are supplied, all completion specifications
|
||||
|
||||
When completion is attempted, the actions are applied in the order the
|
||||
uppercase-letter options are listed above.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is supplied or an error occurs.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -57,22 +67,31 @@ $END
|
|||
|
||||
#define STRDUP(x) ((x) ? savestring (x) : (char *)NULL)
|
||||
|
||||
/* Structure containing all the non-action (binary) options; filled in by
|
||||
build_actions(). */
|
||||
struct _optflags {
|
||||
int pflag;
|
||||
int rflag;
|
||||
int Eflag;
|
||||
};
|
||||
|
||||
static int find_compact __P((char *));
|
||||
static int find_compopt __P((char *));
|
||||
|
||||
static int build_actions __P((WORD_LIST *, int *, int *, unsigned long *, unsigned long *));
|
||||
static int build_actions __P((WORD_LIST *, struct _optflags *, unsigned long *, unsigned long *));
|
||||
|
||||
static int remove_cmd_completions __P((WORD_LIST *));
|
||||
|
||||
static int print_one_completion __P((char *, COMPSPEC *));
|
||||
static int print_compitem __P((BUCKET_CONTENTS *));
|
||||
static void print_compopts __P((const char *, COMPSPEC *, int));
|
||||
static void print_all_completions __P((void));
|
||||
static int print_cmd_completions __P((WORD_LIST *));
|
||||
|
||||
static char *Garg, *Warg, *Parg, *Sarg, *Xarg, *Farg, *Carg;
|
||||
|
||||
static struct _compacts {
|
||||
char *actname;
|
||||
static const struct _compacts {
|
||||
const char * const actname;
|
||||
int actflag;
|
||||
int actopt;
|
||||
} compacts[] = {
|
||||
|
|
@ -104,8 +123,8 @@ static struct _compacts {
|
|||
};
|
||||
|
||||
/* This should be a STRING_INT_ALIST */
|
||||
static struct _compopt {
|
||||
char *optname;
|
||||
const static struct _compopt {
|
||||
const char * const optname;
|
||||
int optflag;
|
||||
} compopts[] = {
|
||||
{ "bashdefault", COPT_BASHDEFAULT },
|
||||
|
|
@ -156,9 +175,9 @@ find_compopt (name)
|
|||
*/
|
||||
|
||||
static int
|
||||
build_actions (list, pp, rp, actp, optp)
|
||||
build_actions (list, flagp, actp, optp)
|
||||
WORD_LIST *list;
|
||||
int *pp, *rp;
|
||||
struct _optflags *flagp;
|
||||
unsigned long *actp, *optp;
|
||||
{
|
||||
int opt, ind, opt_given;
|
||||
|
|
@ -168,15 +187,15 @@ build_actions (list, pp, rp, actp, optp)
|
|||
opt_given = 0;
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "abcdefgjko:prsuvA:G:W:P:S:X:F:C:")) != -1)
|
||||
while ((opt = internal_getopt (list, "abcdefgjko:prsuvA:G:W:P:S:X:F:C:E")) != -1)
|
||||
{
|
||||
opt_given = 1;
|
||||
switch (opt)
|
||||
{
|
||||
case 'r':
|
||||
if (rp)
|
||||
if (flagp)
|
||||
{
|
||||
*rp = 1;
|
||||
flagp->rflag = 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
|
@ -187,9 +206,9 @@ build_actions (list, pp, rp, actp, optp)
|
|||
}
|
||||
|
||||
case 'p':
|
||||
if (pp)
|
||||
if (flagp)
|
||||
{
|
||||
*pp = 1;
|
||||
flagp->pflag = 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
|
@ -256,6 +275,18 @@ build_actions (list, pp, rp, actp, optp)
|
|||
case 'C':
|
||||
Carg = list_optarg;
|
||||
break;
|
||||
case 'E':
|
||||
if (flagp)
|
||||
{
|
||||
flagp->Eflag = 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
sh_invalidopt ("-E");
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
case 'F':
|
||||
Farg = list_optarg;
|
||||
break;
|
||||
|
|
@ -291,9 +322,11 @@ int
|
|||
complete_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int opt_given, pflag, rflag, rval;
|
||||
int opt_given, rval;
|
||||
unsigned long acts, copts;
|
||||
COMPSPEC *cs;
|
||||
struct _optflags oflags;
|
||||
WORD_LIST *l, *wl;
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
|
|
@ -301,24 +334,33 @@ complete_builtin (list)
|
|||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
opt_given = pflag = rflag = 0;
|
||||
opt_given = oflags.pflag = oflags.rflag = oflags.Eflag = 0;
|
||||
|
||||
acts = copts = (unsigned long)0L;
|
||||
Garg = Warg = Parg = Sarg = Xarg = Farg = Carg = (char *)NULL;
|
||||
cs = (COMPSPEC *)NULL;
|
||||
|
||||
/* Build the actions from the arguments. Also sets the [A-Z]arg variables
|
||||
as a side effect if they are supplied as options. */
|
||||
rval = build_actions (list, &pflag, &rflag, &acts, &copts);
|
||||
rval = build_actions (list, &oflags, &acts, &copts);
|
||||
if (rval == EX_USAGE)
|
||||
return (rval);
|
||||
opt_given = rval != EXECUTION_FAILURE;
|
||||
|
||||
list = loptend;
|
||||
|
||||
wl = oflags.Eflag ? make_word_list (make_bare_word ("_EmptycmD_"), (WORD_LIST *)NULL) : 0;
|
||||
|
||||
/* -p overrides everything else */
|
||||
if (pflag || (list == 0 && opt_given == 0))
|
||||
if (oflags.pflag || (list == 0 && opt_given == 0))
|
||||
{
|
||||
if (list == 0)
|
||||
if (wl)
|
||||
{
|
||||
rval = print_cmd_completions (wl);
|
||||
dispose_words (wl);
|
||||
return rval;
|
||||
}
|
||||
else if (list == 0)
|
||||
{
|
||||
print_all_completions ();
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
|
@ -327,9 +369,15 @@ complete_builtin (list)
|
|||
}
|
||||
|
||||
/* next, -r overrides everything else. */
|
||||
if (rflag)
|
||||
if (oflags.rflag)
|
||||
{
|
||||
if (list == 0)
|
||||
if (wl)
|
||||
{
|
||||
rval = remove_cmd_completions (wl);
|
||||
dispose_words (wl);
|
||||
return rval;
|
||||
}
|
||||
else if (list == 0)
|
||||
{
|
||||
progcomp_flush ();
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
|
@ -337,7 +385,7 @@ complete_builtin (list)
|
|||
return (remove_cmd_completions (list));
|
||||
}
|
||||
|
||||
if (list == 0 && opt_given)
|
||||
if (wl == 0 && list == 0 && opt_given)
|
||||
{
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
|
|
@ -357,13 +405,14 @@ complete_builtin (list)
|
|||
cs->command = STRDUP (Carg);
|
||||
cs->filterpat = STRDUP (Xarg);
|
||||
|
||||
for (rval = EXECUTION_SUCCESS ; list; list = list->next)
|
||||
for (rval = EXECUTION_SUCCESS, l = wl ? wl : list ; l; l = l->next)
|
||||
{
|
||||
/* Add CS as the compspec for the specified commands. */
|
||||
if (progcomp_insert (list->word->word, cs) == 0)
|
||||
if (progcomp_insert (l->word->word, cs) == 0)
|
||||
rval = EXECUTION_FAILURE;
|
||||
}
|
||||
|
||||
dispose_words (wl);
|
||||
return (rval);
|
||||
}
|
||||
|
||||
|
|
@ -419,6 +468,14 @@ remove_cmd_completions (list)
|
|||
printf ("-o %s ", f); \
|
||||
} while (0)
|
||||
|
||||
#define XPRINTCOMPOPT(a, f) \
|
||||
do { \
|
||||
if (copts & a) \
|
||||
printf ("-o %s ", f); \
|
||||
else \
|
||||
printf ("+o %s ", f); \
|
||||
} while (0)
|
||||
|
||||
static int
|
||||
print_one_completion (cmd, cs)
|
||||
char *cmd;
|
||||
|
|
@ -478,15 +535,49 @@ print_one_completion (cmd, cs)
|
|||
SQPRINTARG (cs->suffix, "-S");
|
||||
SQPRINTARG (cs->filterpat, "-X");
|
||||
|
||||
SQPRINTARG (cs->command, "-C");
|
||||
|
||||
/* simple arguments that don't require quoting */
|
||||
PRINTARG (cs->funcname, "-F");
|
||||
PRINTARG (cs->command, "-C");
|
||||
|
||||
printf ("%s\n", cmd);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
print_compopts (cmd, cs, full)
|
||||
const char *cmd;
|
||||
COMPSPEC *cs;
|
||||
int full;
|
||||
{
|
||||
int copts;
|
||||
|
||||
printf ("compopt ");
|
||||
copts = cs->options;
|
||||
|
||||
if (full)
|
||||
{
|
||||
XPRINTCOMPOPT (COPT_BASHDEFAULT, "bashdefault");
|
||||
XPRINTCOMPOPT (COPT_DEFAULT, "default");
|
||||
XPRINTCOMPOPT (COPT_DIRNAMES, "dirnames");
|
||||
XPRINTCOMPOPT (COPT_FILENAMES, "filenames");
|
||||
XPRINTCOMPOPT (COPT_NOSPACE, "nospace");
|
||||
XPRINTCOMPOPT (COPT_PLUSDIRS, "plusdirs");
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINTCOMPOPT (COPT_BASHDEFAULT, "bashdefault");
|
||||
PRINTCOMPOPT (COPT_DEFAULT, "default");
|
||||
PRINTCOMPOPT (COPT_DIRNAMES, "dirnames");
|
||||
PRINTCOMPOPT (COPT_FILENAMES, "filenames");
|
||||
PRINTCOMPOPT (COPT_NOSPACE, "nospace");
|
||||
PRINTCOMPOPT (COPT_PLUSDIRS, "plusdirs");
|
||||
}
|
||||
|
||||
printf ("%s\n", cmd);
|
||||
}
|
||||
|
||||
static int
|
||||
print_compitem (item)
|
||||
BUCKET_CONTENTS *item;
|
||||
|
|
@ -525,17 +616,22 @@ print_cmd_completions (list)
|
|||
ret = EXECUTION_FAILURE;
|
||||
}
|
||||
}
|
||||
return (ret);
|
||||
|
||||
return (sh_chkwrite (ret));
|
||||
}
|
||||
|
||||
$BUILTIN compgen
|
||||
$DEPENDS_ON PROGRAMMABLE_COMPLETION
|
||||
$FUNCTION compgen_builtin
|
||||
$SHORT_DOC compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [word]
|
||||
Display the possible completions depending on the options. Intended
|
||||
to be used from within a shell function generating possible completions.
|
||||
If the optional WORD argument is supplied, matches against WORD are
|
||||
generated.
|
||||
$SHORT_DOC compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word]
|
||||
Display possible completions depending on the options.
|
||||
|
||||
Intended to be used from within a shell function generating possible
|
||||
completions. If the optional WORD argument is supplied, matches against
|
||||
WORD are generated.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is supplied or an error occurs.
|
||||
$END
|
||||
|
||||
int
|
||||
|
|
@ -557,7 +653,7 @@ compgen_builtin (list)
|
|||
|
||||
/* Build the actions from the arguments. Also sets the [A-Z]arg variables
|
||||
as a side effect if they are supplied as options. */
|
||||
rval = build_actions (list, (int *)NULL, (int *)NULL, &acts, &copts);
|
||||
rval = build_actions (list, (struct _optflags *)NULL, &acts, &copts);
|
||||
if (rval == EX_USAGE)
|
||||
return (rval);
|
||||
if (rval == EXECUTION_FAILURE)
|
||||
|
|
@ -620,3 +716,114 @@ compgen_builtin (list)
|
|||
compspec_dispose (cs);
|
||||
return (rval);
|
||||
}
|
||||
|
||||
$BUILTIN compopt
|
||||
$DEPENDS_ON PROGRAMMABLE_COMPLETION
|
||||
$FUNCTION compopt_builtin
|
||||
$SHORT_DOC compopt [-o|+o option] [name ...]
|
||||
Modify or display completion options.
|
||||
|
||||
Modify the completion options for each NAME, or, if no NAMEs are supplied,
|
||||
the completion currently begin executed. If no OPTIONs are givenm, print
|
||||
the completion options for each NAME or the current completion specification.
|
||||
|
||||
Options:
|
||||
-o option Set completion option OPTION for each NAME
|
||||
|
||||
Using `+o' instead of `-o' turns off the specified option.
|
||||
|
||||
Arguments:
|
||||
|
||||
Each NAME refers to a command for which a completion specification must
|
||||
have previously been defined using the `complete' builtin. If no NAMEs
|
||||
are supplied, compopt must be called by a function currently generating
|
||||
completions, and the options for that currently-executing completion
|
||||
generator are modified.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is supplied or NAME does not
|
||||
have a completion specification defined.
|
||||
$END
|
||||
|
||||
int
|
||||
compopt_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int opts_on, opts_off, *opts, opt, oind, ret, Eflag;
|
||||
WORD_LIST *l;
|
||||
COMPSPEC *cs;
|
||||
|
||||
opts_on = opts_off = 0;
|
||||
ret = EXECUTION_SUCCESS;
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "+o:")) != EOF)
|
||||
{
|
||||
opts = (list_opttype == '-') ? &opts_on : &opts_off;
|
||||
|
||||
switch (opt)
|
||||
{
|
||||
case 'o':
|
||||
oind = find_compopt (list_optarg);
|
||||
if (oind < 0)
|
||||
{
|
||||
sh_invalidoptname (list_optarg);
|
||||
return (EX_USAGE);
|
||||
}
|
||||
*opts |= compopts[oind].optflag;
|
||||
break;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
if (RL_ISSTATE (RL_STATE_COMPLETING) == 0 || pcomp_curcs == 0)
|
||||
{
|
||||
builtin_error (_("not currently executing completion function"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
cs = pcomp_curcs;
|
||||
|
||||
if (opts_on == 0 && opts_off == 0)
|
||||
{
|
||||
print_compopts (pcomp_curcmd, cs, 1);
|
||||
return (sh_chkwrite (ret));
|
||||
}
|
||||
|
||||
/* Set the compspec options */
|
||||
pcomp_set_compspec_options (cs, opts_on, 1);
|
||||
pcomp_set_compspec_options (cs, opts_off, 0);
|
||||
|
||||
/* And change the readline variables the options control */
|
||||
pcomp_set_readline_variables (opts_on, 1);
|
||||
pcomp_set_readline_variables (opts_off, 0);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
for (l = list; l; l = l->next)
|
||||
{
|
||||
cs = progcomp_search (l->word->word);
|
||||
if (cs == 0)
|
||||
{
|
||||
builtin_error (_("%s: no completion specification"), l->word->word);
|
||||
ret = EXECUTION_FAILURE;
|
||||
continue;
|
||||
}
|
||||
if (opts_on == 0 && opts_off == 0)
|
||||
{
|
||||
print_compopts (l->word->word, cs, 1);
|
||||
continue; /* XXX -- fill in later */
|
||||
}
|
||||
|
||||
/* Set the compspec options */
|
||||
pcomp_set_compspec_options (cs, opts_on, 1);
|
||||
pcomp_set_compspec_options (cs, opts_off, 0);
|
||||
}
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,59 +1,67 @@
|
|||
This file is declare.def, from which is created declare.c.
|
||||
It implements the builtins "declare" and "local" in Bash.
|
||||
|
||||
Copyright (C) 1987-2004 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 declare.c
|
||||
|
||||
$BUILTIN declare
|
||||
$FUNCTION declare_builtin
|
||||
$SHORT_DOC declare [-afFirtx] [-p] [name[=value] ...]
|
||||
Declare variables and/or give them attributes. If no NAMEs are
|
||||
given, then display the values of variables instead. The -p option
|
||||
will display the attributes and values of each NAME.
|
||||
$SHORT_DOC declare [-aAfFilrtux] [-p] [name[=value] ...]
|
||||
Set variable values and attributes.
|
||||
|
||||
The flags are:
|
||||
Declare variables and give them attributes. If no NAMEs are given,
|
||||
display the attributes and values of all variables.
|
||||
|
||||
-a to make NAMEs arrays (if supported)
|
||||
-f to select from among function names only
|
||||
-F to display function names (and line number and source file name if
|
||||
debugging) without definitions
|
||||
Options:
|
||||
-f restrict action or display to function names and definitions
|
||||
-F restrict display to function names only (plus line number and
|
||||
source file when debugging)
|
||||
-p display the attributes and value of each NAME
|
||||
|
||||
Options which set attributes:
|
||||
-a to make NAMEs indexed arrays (if supported)
|
||||
-A to make NAMEs associative arrays (if supported)
|
||||
-i to make NAMEs have the `integer' attribute
|
||||
-l to convert NAMEs to lower case on assignment
|
||||
-r to make NAMEs readonly
|
||||
-t to make NAMEs have the `trace' attribute
|
||||
-u to convert NAMEs to upper case on assignment
|
||||
-x to make NAMEs export
|
||||
|
||||
Using `+' instead of `-' turns off the given attribute.
|
||||
|
||||
Variables with the integer attribute have arithmetic evaluation (see
|
||||
`let') done when the variable is assigned to.
|
||||
the `let' command) performed when the variable is assigned a value.
|
||||
|
||||
When displaying values of variables, -f displays a function's name
|
||||
and definition. The -F option restricts the display to function
|
||||
name only.
|
||||
When used in a function, `declare' makes NAMEs local, as with the `local'
|
||||
command.
|
||||
|
||||
Using `+' instead of `-' turns off the given attribute instead. When
|
||||
used in a function, makes NAMEs local, as with the `local' command.
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is supplied or an error occurs.
|
||||
$END
|
||||
|
||||
$BUILTIN typeset
|
||||
$FUNCTION declare_builtin
|
||||
$SHORT_DOC typeset [-afFirtx] [-p] name[=value] ...
|
||||
Obsolete. See `declare'.
|
||||
$SHORT_DOC typeset [-aAfFilrtux] [-p] name[=value] ...
|
||||
Set variable values and attributes.
|
||||
|
||||
Obsolete. See `help declare'.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -90,10 +98,18 @@ declare_builtin (list)
|
|||
|
||||
$BUILTIN local
|
||||
$FUNCTION local_builtin
|
||||
$SHORT_DOC local name[=value] ...
|
||||
Create a local variable called NAME, and give it VALUE. LOCAL
|
||||
can only be used within a function; it makes the variable NAME
|
||||
have a visible scope restricted to that function and its children.
|
||||
$SHORT_DOC local [option] name[=value] ...
|
||||
Define local variables.
|
||||
|
||||
Create a local variable called NAME, and give it VALUE. OPTION can
|
||||
be any option accepted by `declare'.
|
||||
|
||||
Local variables can only be used within a function; they are visible
|
||||
only to the function where they are defined and its children.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is supplied, an error occurs,
|
||||
or the shell is not executing a function.
|
||||
$END
|
||||
int
|
||||
local_builtin (list)
|
||||
|
|
@ -109,9 +125,9 @@ local_builtin (list)
|
|||
}
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
# define DECLARE_OPTS "+afiprtxF"
|
||||
# define DECLARE_OPTS "+acfilprtuxAF"
|
||||
#else
|
||||
# define DECLARE_OPTS "+fiprtxF"
|
||||
# define DECLARE_OPTS "+cfilprtuxF"
|
||||
#endif
|
||||
|
||||
/* The workhorse function. */
|
||||
|
|
@ -120,7 +136,8 @@ declare_internal (list, local_var)
|
|||
register WORD_LIST *list;
|
||||
int local_var;
|
||||
{
|
||||
int flags_on, flags_off, *flags, any_failed, assign_error, pflag, nodefs, opt;
|
||||
int flags_on, flags_off, *flags;
|
||||
int any_failed, assign_error, pflag, nodefs, opt;
|
||||
char *t, *subscript_start;
|
||||
SHELL_VAR *var;
|
||||
FUNCTION_DEF *shell_fn;
|
||||
|
|
@ -136,8 +153,19 @@ declare_internal (list, local_var)
|
|||
case 'a':
|
||||
#if defined (ARRAY_VARS)
|
||||
*flags |= att_array;
|
||||
#endif
|
||||
break;
|
||||
#else
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
#endif
|
||||
case 'A':
|
||||
#if defined (ARRAY_VARS)
|
||||
*flags |= att_assoc;
|
||||
break;
|
||||
#else
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
#endif
|
||||
case 'p':
|
||||
if (local_var == 0)
|
||||
pflag++;
|
||||
|
|
@ -162,6 +190,25 @@ declare_internal (list, local_var)
|
|||
*flags |= att_exported;
|
||||
array_needs_making = 1;
|
||||
break;
|
||||
#if defined (CASEMOD_ATTRS)
|
||||
# if defined (CASEMOD_CAPCASE)
|
||||
case 'c':
|
||||
*flags |= att_capcase;
|
||||
if (flags == &flags_on)
|
||||
flags_off |= att_uppercase|att_lowercase;
|
||||
break;
|
||||
# endif
|
||||
case 'l':
|
||||
*flags |= att_lowercase;
|
||||
if (flags == &flags_on)
|
||||
flags_off |= att_capcase|att_uppercase;
|
||||
break;
|
||||
case 'u':
|
||||
*flags |= att_uppercase;
|
||||
if (flags == &flags_on)
|
||||
flags_off |= att_capcase|att_lowercase;
|
||||
break;
|
||||
#endif /* CASEMOD_ATTRS */
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
|
|
@ -172,7 +219,7 @@ declare_internal (list, local_var)
|
|||
|
||||
/* If there are no more arguments left, then we just want to show
|
||||
some variables. */
|
||||
if (list == 0) /* declare -[afFirtx] */
|
||||
if (list == 0) /* declare -[aAfFirtx] */
|
||||
{
|
||||
/* Show local variables defined at this context level if this is
|
||||
the `local' builtin. */
|
||||
|
|
@ -191,19 +238,17 @@ declare_internal (list, local_var)
|
|||
free (vlist);
|
||||
}
|
||||
}
|
||||
else if (pflag && (flags_on == 0 || flags_on == att_function))
|
||||
show_all_var_attributes (flags_on == 0, nodefs);
|
||||
else if (flags_on == 0)
|
||||
return (set_builtin ((WORD_LIST *)NULL));
|
||||
else
|
||||
{
|
||||
if (flags_on == 0)
|
||||
set_builtin ((WORD_LIST *)NULL);
|
||||
else
|
||||
set_or_show_attributes ((WORD_LIST *)NULL, flags_on, nodefs);
|
||||
}
|
||||
set_or_show_attributes ((WORD_LIST *)NULL, flags_on, nodefs);
|
||||
|
||||
fflush (stdout);
|
||||
return (EXECUTION_SUCCESS);
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
if (pflag) /* declare -p [-afFirtx] name [name...] */
|
||||
if (pflag) /* declare -p [-aAfFirtx] name [name...] */
|
||||
{
|
||||
for (any_failed = 0; list; list = list->next)
|
||||
{
|
||||
|
|
@ -214,13 +259,13 @@ declare_internal (list, local_var)
|
|||
any_failed++;
|
||||
}
|
||||
}
|
||||
return (any_failed ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
|
||||
return (sh_chkwrite (any_failed ? EXECUTION_FAILURE : EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
#define NEXT_VARIABLE() free (name); list = list->next; continue
|
||||
|
||||
/* There are arguments left, so we are making variables. */
|
||||
while (list) /* declare [-afFirx] name [name ...] */
|
||||
while (list) /* declare [-aAfFirx] name [name ...] */
|
||||
{
|
||||
char *value, *name;
|
||||
int offset, aflags;
|
||||
|
|
@ -232,7 +277,7 @@ declare_internal (list, local_var)
|
|||
offset = assignment (name, 0);
|
||||
aflags = 0;
|
||||
|
||||
if (offset) /* declare [-afFirx] name=value */
|
||||
if (offset) /* declare [-aAfFirx] name=value */
|
||||
{
|
||||
name[offset] = '\0';
|
||||
value = name + offset + 1;
|
||||
|
|
@ -279,7 +324,9 @@ declare_internal (list, local_var)
|
|||
if (variable_context && ((flags_on & att_function) == 0))
|
||||
{
|
||||
#if defined (ARRAY_VARS)
|
||||
if ((flags_on & att_array) || making_array_special)
|
||||
if (flags_on & att_assoc)
|
||||
var = make_local_assoc_variable (name);
|
||||
else if ((flags_on & att_array) || making_array_special)
|
||||
var = make_local_array_variable (name);
|
||||
else
|
||||
#endif
|
||||
|
|
@ -336,8 +383,9 @@ declare_internal (list, local_var)
|
|||
#endif /* DEBUGGER */
|
||||
{
|
||||
t = nodefs ? var->name
|
||||
: named_function_string (name, function_cell (var), 1);
|
||||
: named_function_string (name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL);
|
||||
printf ("%s\n", t);
|
||||
any_failed = sh_chkwrite (any_failed);
|
||||
}
|
||||
}
|
||||
else /* declare -[fF] -[rx] name [name...] */
|
||||
|
|
@ -351,7 +399,7 @@ declare_internal (list, local_var)
|
|||
NEXT_VARIABLE ();
|
||||
}
|
||||
}
|
||||
else /* declare -[airx] name [name...] */
|
||||
else /* declare -[aAirx] name [name...] */
|
||||
{
|
||||
/* Non-null if we just created or fetched a local variable. */
|
||||
if (var == 0)
|
||||
|
|
@ -360,11 +408,20 @@ declare_internal (list, local_var)
|
|||
if (var == 0)
|
||||
{
|
||||
#if defined (ARRAY_VARS)
|
||||
if ((flags_on & att_array) || making_array_special)
|
||||
if (flags_on & att_assoc)
|
||||
var = make_new_assoc_variable (name);
|
||||
else if ((flags_on & att_array) || making_array_special)
|
||||
var = make_new_array_variable (name);
|
||||
else
|
||||
#endif
|
||||
var = bind_variable (name, "", 0);
|
||||
|
||||
if (offset)
|
||||
var = bind_variable (name, "", 0);
|
||||
else
|
||||
{
|
||||
var = bind_variable (name, (char *)NULL, 0);
|
||||
VSETATTR (var, att_invisible);
|
||||
}
|
||||
}
|
||||
|
||||
/* Cannot use declare +r to turn off readonly attribute. */
|
||||
|
|
@ -386,30 +443,48 @@ declare_internal (list, local_var)
|
|||
}
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
if ((making_array_special || (flags_on & att_array) || array_p (var)) && offset)
|
||||
if ((making_array_special || (flags_on & (att_array|att_assoc)) || array_p (var) || assoc_p (var)) && offset)
|
||||
{
|
||||
int vlen;
|
||||
vlen = STRLEN (value);
|
||||
#if 0
|
||||
if (value[0] == '(' && strchr (value, ')'))
|
||||
#else
|
||||
|
||||
if (value[0] == '(' && value[vlen-1] == ')')
|
||||
#endif
|
||||
compound_array_assign = 1;
|
||||
else
|
||||
simple_array_assign = 1;
|
||||
}
|
||||
|
||||
/* Cannot use declare +a name to remove an array variable. */
|
||||
if ((flags_off & att_array) && array_p (var))
|
||||
/* Cannot use declare +a name or declare +A name to remove an
|
||||
array variable. */
|
||||
if (((flags_off & att_array) && array_p (var)) || ((flags_off & att_assoc) && assoc_p (var)))
|
||||
{
|
||||
builtin_error (_("%s: cannot destroy array variables in this way"), name);
|
||||
any_failed++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
|
||||
/* declare -a name makes name an array variable. */
|
||||
if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0)
|
||||
if ((flags_on & att_array) && assoc_p (var))
|
||||
{
|
||||
builtin_error (_("%s: cannot convert associative to indexed array"), name);
|
||||
any_failed++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
if ((flags_on & att_assoc) && array_p (var))
|
||||
{
|
||||
builtin_error (_("%s: cannot convert indexed to associative array"), name);
|
||||
any_failed++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
|
||||
/* declare -A name[[n]] makes name an associative array variable. */
|
||||
if (flags_on & att_assoc)
|
||||
{
|
||||
if (assoc_p (var) == 0)
|
||||
var = convert_var_to_assoc (var);
|
||||
}
|
||||
/* declare -a name[[n]] or declare name[n] makes name an indexed
|
||||
array variable. */
|
||||
else if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0)
|
||||
var = convert_var_to_array (var);
|
||||
#endif /* ARRAY_VARS */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
This file is echo.def, from which is created echo.c.
|
||||
It implements the builtin "echo" in Bash.
|
||||
|
||||
Copyright (C) 1987-2002 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 echo.c
|
||||
#include <config.h>
|
||||
|
|
@ -37,31 +36,48 @@ $BUILTIN echo
|
|||
$FUNCTION echo_builtin
|
||||
$DEPENDS_ON V9_ECHO
|
||||
$SHORT_DOC echo [-neE] [arg ...]
|
||||
Output the ARGs. If -n is specified, the trailing newline is
|
||||
suppressed. If the -e option is given, interpretation of the
|
||||
following backslash-escaped characters is turned on:
|
||||
\a alert (bell)
|
||||
\b backspace
|
||||
\c suppress trailing newline
|
||||
\E escape character
|
||||
\f form feed
|
||||
\n new line
|
||||
\r carriage return
|
||||
\t horizontal tab
|
||||
\v vertical tab
|
||||
\\ backslash
|
||||
\0nnn the character whose ASCII code is NNN (octal). NNN can be
|
||||
0 to 3 octal digits
|
||||
Write arguments to the standard output.
|
||||
|
||||
You can explicitly turn off the interpretation of the above characters
|
||||
with the -E option.
|
||||
Display the ARGs on the standard output followed by a newline.
|
||||
|
||||
Options:
|
||||
-n do not append a newline
|
||||
-e enable interpretation of the following backslash escapes
|
||||
-E explicitly suppress interpretation of backslash escapes
|
||||
|
||||
`echo' interprets the following backslash-escaped characters:
|
||||
\a alert (bell)
|
||||
\b backspace
|
||||
\c suppress further output
|
||||
\e escape character
|
||||
\f form feed
|
||||
\n new line
|
||||
\r carriage return
|
||||
\t horizontal tab
|
||||
\v vertical tab
|
||||
\\ backslash
|
||||
\0nnn the character whose ASCII code is NNN (octal). NNN can be
|
||||
0 to 3 octal digits
|
||||
\xHH the eight-bit character whose value is HH (hexadecimal). HH
|
||||
can be one or two hex digits
|
||||
|
||||
Exit Status:
|
||||
Returns success unless a write error occurs.
|
||||
$END
|
||||
|
||||
$BUILTIN echo
|
||||
$FUNCTION echo_builtin
|
||||
$DEPENDS_ON !V9_ECHO
|
||||
$SHORT_DOC echo [-n] [arg ...]
|
||||
Output the ARGs. If -n is specified, the trailing newline is suppressed.
|
||||
Write arguments to the standard output.
|
||||
|
||||
Display the ARGs on the standard output followed by a newline.
|
||||
|
||||
Options:
|
||||
-n do not append a newline
|
||||
|
||||
Exit Status:
|
||||
Returns success unless a write error occurs.
|
||||
$END
|
||||
|
||||
#if defined (V9_ECHO)
|
||||
|
|
@ -143,6 +159,7 @@ just_echo:
|
|||
|
||||
clearerr (stdout); /* clear error before writing and testing success */
|
||||
|
||||
terminate_immediately++;
|
||||
while (list)
|
||||
{
|
||||
i = len = 0;
|
||||
|
|
@ -175,12 +192,7 @@ just_echo:
|
|||
|
||||
if (display_return)
|
||||
putchar ('\n');
|
||||
fflush (stdout);
|
||||
if (ferror (stdout))
|
||||
{
|
||||
sh_wrerror ();
|
||||
clearerr (stdout);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
terminate_immediately--;
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,42 +1,51 @@
|
|||
This file is enable.def, from which is created enable.c.
|
||||
It implements the builtin "enable" 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 enable.c
|
||||
|
||||
$BUILTIN enable
|
||||
$FUNCTION enable_builtin
|
||||
$SHORT_DOC enable [-pnds] [-a] [-f filename] [name ...]
|
||||
Enable and disable builtin shell commands. This allows
|
||||
you to use a disk command which has the same name as a shell
|
||||
builtin without specifying a full pathname. If -n is used, the
|
||||
NAMEs become disabled; otherwise NAMEs are enabled. For example,
|
||||
to use the `test' found in $PATH instead of the shell builtin
|
||||
version, type `enable -n test'. On systems supporting dynamic
|
||||
loading, the -f option may be used to load new builtins from the
|
||||
shared object FILENAME. The -d option will delete a builtin
|
||||
previously loaded with -f. If no non-option names are given, or
|
||||
the -p option is supplied, a list of builtins is printed. The
|
||||
-a option means to print every builtin with an indication of whether
|
||||
or not it is enabled. The -s option restricts the output to the POSIX.2
|
||||
`special' builtins. The -n option displays a list of all disabled builtins.
|
||||
$SHORT_DOC enable [-a] [-dnps] [-f filename] [name ...]
|
||||
Enable and disable shell builtins.
|
||||
|
||||
Enables and disables builtin shell commands. Disabling allows you to
|
||||
execute a disk command which has the same name as a shell builtin
|
||||
without using a full pathname.
|
||||
|
||||
Options:
|
||||
-a print a list of builtins showing whether or not each is enabled
|
||||
-n disable each NAME or display a list of disabled builtins
|
||||
-p print the list of builtins in a reusable format
|
||||
-s print only the names of Posix `special' builtins
|
||||
|
||||
Options controlling dynamic loading:
|
||||
-f Load builtin NAME from shared object FILENAME
|
||||
-d Remove a builtin loaded with -f
|
||||
|
||||
Without options, each NAME is enabled.
|
||||
|
||||
To use the `test' found in $PATH instead of the shell builtin
|
||||
version, type `enable -n test'.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless NAME is not a shell builtin or an error occurs.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
|
|||
|
|
@ -1,30 +1,35 @@
|
|||
This file is eval.def, from which is created eval.c.
|
||||
It implements the builtin "eval" in Bash.
|
||||
|
||||
Copyright (C) 1987-2002 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 eval.c
|
||||
|
||||
$BUILTIN eval
|
||||
$FUNCTION eval_builtin
|
||||
$SHORT_DOC eval [arg ...]
|
||||
Read ARGs as input to the shell and execute the resulting command(s).
|
||||
Execute arguments as a shell command.
|
||||
|
||||
Combine ARGs into a single string, use the result as input to the shell,
|
||||
and execute the resulting commands.
|
||||
|
||||
Exit Status:
|
||||
Returns exit status of command or success if command is null.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
/* Copyright (C) 1996-2003 Free Software Foundation, Inc.
|
||||
/* evalfile.c - read and evaluate commands from a file or file descriptor */
|
||||
|
||||
/* Copyright (C) 1996-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.
|
||||
|
||||
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. */
|
||||
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. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
|
@ -45,6 +47,8 @@
|
|||
# include "../bashhist.h"
|
||||
#endif
|
||||
|
||||
#include <typemax.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#if !defined (errno)
|
||||
|
|
@ -78,6 +82,7 @@ _evalfile (filename, flags)
|
|||
volatile int old_interactive;
|
||||
procenv_t old_return_catch;
|
||||
int return_val, fd, result, pflags;
|
||||
ssize_t nr; /* return value from read(2) */
|
||||
char *string;
|
||||
struct stat finfo;
|
||||
size_t file_size;
|
||||
|
|
@ -147,31 +152,37 @@ file_error_and_exit:
|
|||
setmode (fd, O_TEXT);
|
||||
#endif
|
||||
|
||||
string = (char *)xmalloc (1 + file_size);
|
||||
result = read (fd, string, file_size);
|
||||
string[result] = '\0';
|
||||
if (S_ISREG (finfo.st_mode) && file_size <= SSIZE_MAX)
|
||||
{
|
||||
string = (char *)xmalloc (1 + file_size);
|
||||
nr = read (fd, string, file_size);
|
||||
if (nr >= 0)
|
||||
string[nr] = '\0';
|
||||
}
|
||||
else
|
||||
nr = zmapfd (fd, &string, 0);
|
||||
|
||||
return_val = errno;
|
||||
close (fd);
|
||||
errno = return_val;
|
||||
|
||||
if (result < 0) /* XXX was != file_size, not < 0 */
|
||||
if (nr < 0) /* XXX was != file_size, not < 0 */
|
||||
{
|
||||
free (string);
|
||||
goto file_error_and_exit;
|
||||
}
|
||||
|
||||
if (result == 0)
|
||||
if (nr == 0)
|
||||
{
|
||||
free (string);
|
||||
return ((flags & FEVAL_BUILTIN) ? EXECUTION_SUCCESS : 1);
|
||||
}
|
||||
|
||||
if ((flags & FEVAL_CHECKBINARY) &&
|
||||
check_binary_file (string, (result > 80) ? 80 : result))
|
||||
check_binary_file (string, (nr > 80) ? 80 : nr))
|
||||
{
|
||||
free (string);
|
||||
(*errfunc) ("%s: cannot execute binary file", filename);
|
||||
(*errfunc) (_("%s: cannot execute binary file"), filename);
|
||||
return ((flags & FEVAL_BUILTIN) ? EX_BINARY_FILE : -1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
/* Evaluate a string as one or more shell commands.
|
||||
/* evalstring.c - evaluate a string as one or more shell commands.
|
||||
|
||||
Copyright (C) 1996-2005 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1996-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.
|
||||
|
||||
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. */
|
||||
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. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
|
@ -44,6 +44,8 @@
|
|||
#include "../redir.h"
|
||||
#include "../trap.h"
|
||||
|
||||
#include <y.tab.h>
|
||||
|
||||
#if defined (HISTORY)
|
||||
# include "../bashhist.h"
|
||||
#endif
|
||||
|
|
@ -58,15 +60,21 @@ extern int errno;
|
|||
|
||||
extern int indirection_level, subshell_environment;
|
||||
extern int line_number;
|
||||
extern int current_token, shell_eof_token;
|
||||
extern int last_command_exit_value;
|
||||
extern int running_trap;
|
||||
extern int loop_level;
|
||||
extern int executing_list;
|
||||
extern int comsub_ignore_return;
|
||||
extern int posixly_correct;
|
||||
|
||||
int parse_and_execute_level = 0;
|
||||
|
||||
static int cat_file __P((REDIRECT *));
|
||||
|
||||
#define PE_TAG "parse_and_execute top"
|
||||
#define PS_TAG "parse_string top"
|
||||
|
||||
#if defined (HISTORY)
|
||||
static void
|
||||
set_history_remembering ()
|
||||
|
|
@ -84,7 +92,64 @@ parse_and_execute_cleanup ()
|
|||
run_trap_cleanup (running_trap - 1);
|
||||
unfreeze_jobs_list ();
|
||||
}
|
||||
run_unwind_frame ("parse_and_execute_top");
|
||||
|
||||
if (have_unwind_protects ())
|
||||
run_unwind_frame (PE_TAG);
|
||||
else
|
||||
parse_and_execute_level = 0; /* XXX */
|
||||
}
|
||||
|
||||
static void
|
||||
parse_prologue (string, flags, tag)
|
||||
char *string;
|
||||
int flags;
|
||||
char *tag;
|
||||
{
|
||||
char *orig_string;
|
||||
int x;
|
||||
|
||||
orig_string = string;
|
||||
/* Unwind protect this invocation of parse_and_execute (). */
|
||||
begin_unwind_frame (tag);
|
||||
unwind_protect_int (parse_and_execute_level);
|
||||
unwind_protect_jmp_buf (top_level);
|
||||
unwind_protect_int (indirection_level);
|
||||
unwind_protect_int (line_number);
|
||||
unwind_protect_int (loop_level);
|
||||
unwind_protect_int (executing_list);
|
||||
unwind_protect_int (comsub_ignore_return);
|
||||
if (flags & (SEVAL_NONINT|SEVAL_INTERACT))
|
||||
unwind_protect_int (interactive);
|
||||
|
||||
#if defined (HISTORY)
|
||||
if (parse_and_execute_level == 0)
|
||||
add_unwind_protect (set_history_remembering, (char *)NULL);
|
||||
else
|
||||
unwind_protect_int (remember_on_history); /* can be used in scripts */
|
||||
# if defined (BANG_HISTORY)
|
||||
if (interactive_shell)
|
||||
unwind_protect_int (history_expansion_inhibited);
|
||||
# endif /* BANG_HISTORY */
|
||||
#endif /* HISTORY */
|
||||
|
||||
if (interactive_shell)
|
||||
{
|
||||
x = get_current_prompt_level ();
|
||||
add_unwind_protect (set_current_prompt_level, x);
|
||||
}
|
||||
|
||||
add_unwind_protect (pop_stream, (char *)NULL);
|
||||
if (orig_string && ((flags & SEVAL_NOFREE) == 0))
|
||||
add_unwind_protect (xfree, orig_string);
|
||||
end_unwind_frame ();
|
||||
|
||||
if (flags & (SEVAL_NONINT|SEVAL_INTERACT))
|
||||
interactive = (flags & SEVAL_NONINT) ? 0 : 1;
|
||||
|
||||
#if defined (HISTORY)
|
||||
if (flags & SEVAL_NOHIST)
|
||||
bash_history_disable ();
|
||||
#endif /* HISTORY */
|
||||
}
|
||||
|
||||
/* Parse and execute the commands in STRING. Returns whatever
|
||||
|
|
@ -104,50 +169,16 @@ parse_and_execute (string, from_file, flags)
|
|||
const char *from_file;
|
||||
int flags;
|
||||
{
|
||||
int code, x, lreset;
|
||||
int code, lreset;
|
||||
volatile int should_jump_to_top_level, last_result;
|
||||
char *orig_string;
|
||||
COMMAND *volatile command;
|
||||
|
||||
orig_string = string;
|
||||
/* Unwind protect this invocation of parse_and_execute (). */
|
||||
begin_unwind_frame ("parse_and_execute_top");
|
||||
unwind_protect_int (parse_and_execute_level);
|
||||
unwind_protect_jmp_buf (top_level);
|
||||
unwind_protect_int (indirection_level);
|
||||
unwind_protect_int (line_number);
|
||||
unwind_protect_int (loop_level);
|
||||
if (flags & (SEVAL_NONINT|SEVAL_INTERACT))
|
||||
unwind_protect_int (interactive);
|
||||
|
||||
lreset = flags & SEVAL_RESETLINE;
|
||||
|
||||
#if defined (HISTORY)
|
||||
if (parse_and_execute_level == 0)
|
||||
add_unwind_protect (set_history_remembering, (char *)NULL);
|
||||
else
|
||||
unwind_protect_int (remember_on_history); /* can be used in scripts */
|
||||
# if defined (BANG_HISTORY)
|
||||
if (interactive_shell)
|
||||
{
|
||||
unwind_protect_int (history_expansion_inhibited);
|
||||
}
|
||||
# endif /* BANG_HISTORY */
|
||||
#endif /* HISTORY */
|
||||
|
||||
if (interactive_shell)
|
||||
{
|
||||
x = get_current_prompt_level ();
|
||||
add_unwind_protect (set_current_prompt_level, x);
|
||||
}
|
||||
|
||||
add_unwind_protect (pop_stream, (char *)NULL);
|
||||
if (orig_string && ((flags & SEVAL_NOFREE) == 0))
|
||||
add_unwind_protect (xfree, orig_string);
|
||||
end_unwind_frame ();
|
||||
parse_prologue (string, flags, PE_TAG);
|
||||
|
||||
parse_and_execute_level++;
|
||||
|
||||
lreset = flags & SEVAL_RESETLINE;
|
||||
|
||||
/* Reset the line number if the caller wants us to. If we don't reset the
|
||||
line number, we have to subtract one, because we will add one just
|
||||
before executing the next command (resetting the line number sets it to
|
||||
|
|
@ -157,13 +188,6 @@ parse_and_execute (string, from_file, flags)
|
|||
line_number--;
|
||||
|
||||
indirection_level++;
|
||||
if (flags & (SEVAL_NONINT|SEVAL_INTERACT))
|
||||
interactive = (flags & SEVAL_NONINT) ? 0 : 1;
|
||||
|
||||
#if defined (HISTORY)
|
||||
if (flags & SEVAL_NOHIST)
|
||||
bash_history_disable ();
|
||||
#endif /* HISTORY */
|
||||
|
||||
code = should_jump_to_top_level = 0;
|
||||
last_result = EXECUTION_SUCCESS;
|
||||
|
|
@ -224,7 +248,7 @@ parse_and_execute (string, from_file, flags)
|
|||
|
||||
if (parse_command () == 0)
|
||||
{
|
||||
if (interactive_shell == 0 && read_but_dont_execute)
|
||||
if ((flags & SEVAL_PARSEONLY) || (interactive_shell == 0 && read_but_dont_execute))
|
||||
{
|
||||
last_result = EXECUTION_SUCCESS;
|
||||
dispose_command (global_command);
|
||||
|
|
@ -241,6 +265,12 @@ parse_and_execute (string, from_file, flags)
|
|||
|
||||
global_command = (COMMAND *)NULL;
|
||||
|
||||
if ((subshell_environment & SUBSHELL_COMSUB) && comsub_ignore_return)
|
||||
{
|
||||
command->flags |= CMD_IGNORE_RETURN;
|
||||
itrace("parse_and_execute: turned on CMD_IGNORE_RETURN from comsub_ignore_return");
|
||||
}
|
||||
|
||||
#if defined (ONESHOT)
|
||||
/*
|
||||
* IF
|
||||
|
|
@ -305,7 +335,7 @@ parse_and_execute (string, from_file, flags)
|
|||
|
||||
out:
|
||||
|
||||
run_unwind_frame ("parse_and_execute_top");
|
||||
run_unwind_frame (PE_TAG);
|
||||
|
||||
if (interrupt_state && parse_and_execute_level == 0)
|
||||
{
|
||||
|
|
@ -322,6 +352,110 @@ parse_and_execute (string, from_file, flags)
|
|||
return (last_result);
|
||||
}
|
||||
|
||||
/* Parse a command contained in STRING according to FLAGS and return the
|
||||
number of characters consumed from the string. If non-NULL, set *ENDP
|
||||
to the position in the string where the parse ended. Used to validate
|
||||
command substitutions during parsing to obey Posix rules about finding
|
||||
the end of the command and balancing parens. */
|
||||
int
|
||||
parse_string (string, from_file, flags, endp)
|
||||
char *string;
|
||||
const char *from_file;
|
||||
int flags;
|
||||
char **endp;
|
||||
{
|
||||
int code, nc;
|
||||
volatile int should_jump_to_top_level;
|
||||
COMMAND *volatile command, *oglobal;
|
||||
char *ostring;
|
||||
|
||||
parse_prologue (string, flags, PS_TAG);
|
||||
|
||||
/* Reset the line number if the caller wants us to. If we don't reset the
|
||||
line number, we have to subtract one, because we will add one just
|
||||
before executing the next command (resetting the line number sets it to
|
||||
0; the first line number is 1). */
|
||||
push_stream (0);
|
||||
|
||||
code = should_jump_to_top_level = 0;
|
||||
oglobal = global_command;
|
||||
ostring = string;
|
||||
|
||||
with_input_from_string (string, from_file);
|
||||
while (*(bash_input.location.string))
|
||||
{
|
||||
command = (COMMAND *)NULL;
|
||||
|
||||
#if 0
|
||||
if (interrupt_state)
|
||||
break;
|
||||
#endif
|
||||
|
||||
/* Provide a location for functions which `longjmp (top_level)' to
|
||||
jump to. */
|
||||
code = setjmp (top_level);
|
||||
|
||||
if (code)
|
||||
{
|
||||
#if defined (DEBUG)
|
||||
itrace("parse_string: longjmp executed: code = %d", code);
|
||||
#endif
|
||||
should_jump_to_top_level = 0;
|
||||
switch (code)
|
||||
{
|
||||
case FORCE_EOF:
|
||||
case ERREXIT:
|
||||
case EXITPROG:
|
||||
case DISCARD: /* XXX */
|
||||
if (command)
|
||||
dispose_command (command);
|
||||
/* Remember to call longjmp (top_level) after the old
|
||||
value for it is restored. */
|
||||
should_jump_to_top_level = 1;
|
||||
goto out;
|
||||
|
||||
default:
|
||||
command_error ("parse_string", CMDERR_BADJUMP, code, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (parse_command () == 0)
|
||||
{
|
||||
dispose_command (global_command);
|
||||
global_command = (COMMAND *)NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((flags & SEVAL_NOLONGJMP) == 0)
|
||||
{
|
||||
should_jump_to_top_level = 1;
|
||||
code = DISCARD;
|
||||
}
|
||||
else
|
||||
reset_parser (); /* XXX - sets token_to_read */
|
||||
break;
|
||||
}
|
||||
|
||||
if (current_token == yacc_EOF || current_token == shell_eof_token)
|
||||
break;
|
||||
}
|
||||
|
||||
out:
|
||||
|
||||
global_command = oglobal;
|
||||
nc = bash_input.location.string - ostring;
|
||||
if (endp)
|
||||
*endp = bash_input.location.string;
|
||||
|
||||
run_unwind_frame (PS_TAG);
|
||||
|
||||
if (should_jump_to_top_level)
|
||||
jump_to_top_level (code);
|
||||
|
||||
return (nc);
|
||||
}
|
||||
|
||||
/* Handle a $( < file ) command substitution. This expands the filename,
|
||||
returning errors as appropriate, then just cats the file to the standard
|
||||
output. */
|
||||
|
|
|
|||
|
|
@ -1,37 +1,44 @@
|
|||
This file is exec.def, from which is created exec.c.
|
||||
It implements the builtin "exec" 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 exec.c
|
||||
|
||||
$BUILTIN exec
|
||||
$FUNCTION exec_builtin
|
||||
$SHORT_DOC exec [-cl] [-a name] file [redirection ...]
|
||||
Exec FILE, replacing this shell with the specified program.
|
||||
If FILE is not specified, the redirections take effect in this
|
||||
shell. If the first argument is `-l', then place a dash in the
|
||||
zeroth arg passed to FILE, as login does. If the `-c' option
|
||||
is supplied, FILE is executed with a null environment. The `-a'
|
||||
option means to make set argv[0] of the executed process to NAME.
|
||||
If the file cannot be executed and the shell is not interactive,
|
||||
then the shell exits, unless the shell option `execfail' is set.
|
||||
$SHORT_DOC exec [-cl] [-a name] [command [arguments ...]] [redirection ...]
|
||||
Replace the shell with the given command.
|
||||
|
||||
Execute COMMAND, replacing this shell with the specified program.
|
||||
ARGUMENTS become the arguments to COMMAND. If COMMAND is not specified,
|
||||
any redirections take effect in the current shell.
|
||||
|
||||
Options:
|
||||
-a name pass NAME as the zeroth argument to COMMAND
|
||||
-c execute COMMAND with an empty environment
|
||||
-l place a dash in the zeroth argument to COMMAND
|
||||
|
||||
If the command cannot be executed, a non-interactive shell exits, unless
|
||||
the shell option `execfail' is set.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless COMMAND is not found or a redirection error occurs.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
|
|||
|
|
@ -1,30 +1,31 @@
|
|||
This file is exit.def, from which is created exit.c.
|
||||
It implements the builtins "exit", and "logout" in Bash.
|
||||
|
||||
Copyright (C) 1987-2005 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 exit.c
|
||||
|
||||
$BUILTIN exit
|
||||
$FUNCTION exit_builtin
|
||||
$SHORT_DOC exit [n]
|
||||
Exit the shell with a status of N. If N is omitted, the exit status
|
||||
Exit the shell.
|
||||
|
||||
Exits the shell with a status of N. If N is omitted, the exit status
|
||||
is that of the last command executed.
|
||||
$END
|
||||
|
||||
|
|
@ -45,6 +46,7 @@ $END
|
|||
#include "common.h"
|
||||
#include "builtext.h" /* for jobs_builtin */
|
||||
|
||||
extern int check_jobs_at_exit;
|
||||
extern int last_command_exit_value;
|
||||
extern int running_trap, trap_saved_exit_value;
|
||||
extern int subshell_environment;
|
||||
|
|
@ -60,7 +62,7 @@ exit_builtin (list)
|
|||
{
|
||||
if (interactive)
|
||||
{
|
||||
fprintf (stderr, login_shell ? "logout\n" : "exit\n");
|
||||
fprintf (stderr, login_shell ? _("logout\n") : "exit\n");
|
||||
fflush (stderr);
|
||||
}
|
||||
|
||||
|
|
@ -69,8 +71,11 @@ exit_builtin (list)
|
|||
|
||||
$BUILTIN logout
|
||||
$FUNCTION logout_builtin
|
||||
$SHORT_DOC logout
|
||||
Logout of a login shell.
|
||||
$SHORT_DOC logout [n]
|
||||
Exit a login shell.
|
||||
|
||||
Exits a login shell with exit status N. Returns an error if not executed
|
||||
in a login shell.
|
||||
$END
|
||||
|
||||
/* How to logout. */
|
||||
|
|
@ -94,7 +99,7 @@ exit_or_logout (list)
|
|||
int exit_value;
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
int exit_immediate_okay;
|
||||
int exit_immediate_okay, stopmsg;
|
||||
|
||||
exit_immediate_okay = (interactive == 0 ||
|
||||
last_shell_builtin == exit_builtin ||
|
||||
|
|
@ -102,21 +107,32 @@ exit_or_logout (list)
|
|||
last_shell_builtin == jobs_builtin);
|
||||
|
||||
/* Check for stopped jobs if the user wants to. */
|
||||
if (!exit_immediate_okay)
|
||||
if (exit_immediate_okay == 0)
|
||||
{
|
||||
register int i;
|
||||
for (i = 0; i < js.j_jobslots; i++)
|
||||
for (i = stopmsg = 0; i < js.j_jobslots; i++)
|
||||
if (jobs[i] && STOPPED (i))
|
||||
{
|
||||
fprintf (stderr, _("There are stopped jobs.\n"));
|
||||
stopmsg = JSTOPPED;
|
||||
else if (check_jobs_at_exit && stopmsg == 0 && RUNNING (i))
|
||||
stopmsg = JRUNNING;
|
||||
|
||||
/* This is NOT superfluous because EOF can get here without
|
||||
going through the command parser. Set both last and this
|
||||
so that either `exit', `logout', or ^D will work to exit
|
||||
immediately if nothing intervenes. */
|
||||
this_shell_builtin = last_shell_builtin = exit_builtin;
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
if (stopmsg == JSTOPPED)
|
||||
fprintf (stderr, _("There are stopped jobs.\n"));
|
||||
else if (stopmsg == JRUNNING)
|
||||
fprintf (stderr, _("There are running jobs.\n"));
|
||||
|
||||
if (stopmsg && check_jobs_at_exit)
|
||||
list_all_jobs (JLIST_STANDARD);
|
||||
|
||||
if (stopmsg)
|
||||
{
|
||||
/* This is NOT superfluous because EOF can get here without
|
||||
going through the command parser. Set both last and this
|
||||
so that either `exit', `logout', or ^D will work to exit
|
||||
immediately if nothing intervenes. */
|
||||
this_shell_builtin = last_shell_builtin = exit_builtin;
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
#endif /* JOB_CONTROL */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,48 +1,52 @@
|
|||
This file is fc.def, from which is created fc.c.
|
||||
It implements the builtin "fc" in Bash.
|
||||
|
||||
Copyright (C) 1987-2005 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 fc.c
|
||||
|
||||
$BUILTIN fc
|
||||
$FUNCTION fc_builtin
|
||||
$DEPENDS_ON HISTORY
|
||||
$SHORT_DOC fc [-e ename] [-nlr] [first] [last] or fc -s [pat=rep] [cmd]
|
||||
$SHORT_DOC fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command]
|
||||
Display or execute commands from the history list.
|
||||
|
||||
fc is used to list or edit and re-execute commands from the history list.
|
||||
FIRST and LAST can be numbers specifying the range, or FIRST can be a
|
||||
string, which means the most recent command beginning with that
|
||||
string.
|
||||
|
||||
-e ENAME selects which editor to use. Default is FCEDIT, then EDITOR,
|
||||
then vi.
|
||||
Options:
|
||||
-e ENAME select which editor to use. Default is FCEDIT, then EDITOR,
|
||||
then vi
|
||||
-l list lines instead of editing
|
||||
-n omit line numbers when listing
|
||||
-r reverse the order of the lines (newest listed first)
|
||||
|
||||
-l means list lines instead of editing.
|
||||
-n means no line numbers listed.
|
||||
-r means reverse the order of the lines (making it newest listed first).
|
||||
|
||||
With the `fc -s [pat=rep ...] [command]' format, the command is
|
||||
With the `fc -s [pat=rep ...] [command]' format, COMMAND is
|
||||
re-executed after the substitution OLD=NEW is performed.
|
||||
|
||||
A useful alias to use with this is r='fc -s', so that typing `r cc'
|
||||
runs the last command beginning with `cc' and typing `r' re-executes
|
||||
the last command.
|
||||
|
||||
Exit Status:
|
||||
Returns success or status of executed command; non-zero if an error occurs.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -88,7 +92,6 @@ extern int posixly_correct;
|
|||
extern int unlink __P((const char *));
|
||||
|
||||
extern FILE *sh_mktmpfp __P((char *, int, char **));
|
||||
extern int delete_last_history __P((void));
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
|
|
@ -290,12 +293,7 @@ fc_builtin (list)
|
|||
line was actually added (HISTIGNORE may have caused it to not be),
|
||||
so we check hist_last_line_added. */
|
||||
|
||||
/* "When not listing, he fc command that caused the editing shall not be
|
||||
entered into the history list." */
|
||||
if (listing == 0 && hist_last_line_added)
|
||||
delete_last_history ();
|
||||
|
||||
last_hist = i - 1 - hist_last_line_added;
|
||||
last_hist = i - remember_on_history - hist_last_line_added;
|
||||
|
||||
if (list)
|
||||
{
|
||||
|
|
@ -322,6 +320,21 @@ fc_builtin (list)
|
|||
histbeg = histend = last_hist;
|
||||
}
|
||||
|
||||
/* "When not listing, the fc command that caused the editing shall not be
|
||||
entered into the history list." */
|
||||
if (listing == 0 && hist_last_line_added)
|
||||
{
|
||||
bash_delete_last_history ();
|
||||
/* If we're editing a single command -- the last command in the
|
||||
history -- and we just removed the dummy command added by
|
||||
edit_and_execute_command (), we need to check whether or not we
|
||||
just removed the last command in the history and need to back
|
||||
the pointer up. remember_on_history is off because we're running
|
||||
in parse_and_execute(). */
|
||||
if (histbeg == histend && histend == last_hist && hlist[last_hist] == 0)
|
||||
last_hist = histbeg = --histend;
|
||||
}
|
||||
|
||||
/* We print error messages for line specifications out of range. */
|
||||
if ((histbeg < 0) || (histend < 0))
|
||||
{
|
||||
|
|
@ -368,8 +381,15 @@ fc_builtin (list)
|
|||
}
|
||||
|
||||
if (listing)
|
||||
return (EXECUTION_SUCCESS);
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
|
||||
fflush (stream);
|
||||
if (ferror (stream))
|
||||
{
|
||||
sh_wrerror ();
|
||||
fclose (stream);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
fclose (stream);
|
||||
|
||||
/* Now edit the file of commands. */
|
||||
|
|
@ -436,10 +456,11 @@ fc_gethnum (command, hlist)
|
|||
char *command;
|
||||
HIST_ENTRY **hlist;
|
||||
{
|
||||
int sign = 1, n, clen;
|
||||
int sign, n, clen;
|
||||
register int i, j;
|
||||
register char *s;
|
||||
|
||||
sign = 1;
|
||||
/* Count history elements. */
|
||||
for (i = 0; hlist[i]; i++);
|
||||
|
||||
|
|
@ -449,8 +470,9 @@ fc_gethnum (command, hlist)
|
|||
and makes the last command that this deals with be the last command
|
||||
the user entered before the fc. We need to check whether the
|
||||
line was actually added (HISTIGNORE may have caused it to not be),
|
||||
so we check hist_last_line_added. */
|
||||
i -= 1 + hist_last_line_added;
|
||||
so we check hist_last_line_added. This needs to agree with the
|
||||
calculation of last_hist in fc_builtin above. */
|
||||
i -= remember_on_history + hist_last_line_added;
|
||||
|
||||
/* No specification defaults to most recent command. */
|
||||
if (command == NULL)
|
||||
|
|
@ -601,7 +623,7 @@ fc_replhist (command)
|
|||
|
||||
if (command && *command)
|
||||
{
|
||||
delete_last_history ();
|
||||
bash_delete_last_history ();
|
||||
maybe_add_history (command); /* Obeys HISTCONTROL setting. */
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
This file is fg_bg.def, from which is created fg_bg.c.
|
||||
It implements the builtins "bg" and "fg" in Bash.
|
||||
|
||||
Copyright (C) 1987-2005 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 fg_bg.c
|
||||
|
||||
|
|
@ -25,9 +24,14 @@ $BUILTIN fg
|
|||
$FUNCTION fg_builtin
|
||||
$DEPENDS_ON JOB_CONTROL
|
||||
$SHORT_DOC fg [job_spec]
|
||||
Place JOB_SPEC in the foreground, and make it the current job. If
|
||||
JOB_SPEC is not present, the shell's notion of the current job is
|
||||
used.
|
||||
Move job to the foreground.
|
||||
|
||||
Place the job identified by JOB_SPEC in the foreground, making it the
|
||||
current job. If JOB_SPEC is not present, the shell's notion of the
|
||||
current job is used.
|
||||
|
||||
Exit Status:
|
||||
Status of command placed in foreground, or failure if an error occurs.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -83,9 +87,14 @@ $BUILTIN bg
|
|||
$FUNCTION bg_builtin
|
||||
$DEPENDS_ON JOB_CONTROL
|
||||
$SHORT_DOC bg [job_spec ...]
|
||||
Place each JOB_SPEC in the background, as if it had been started with
|
||||
`&'. If JOB_SPEC is not present, the shell's notion of the current
|
||||
job is used.
|
||||
Move jobs to the background.
|
||||
|
||||
Place the jobs identified by each JOB_SPEC in the background, as if they
|
||||
had been started with `&'. If JOB_SPEC is not present, the shell's notion
|
||||
of the current job is used.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless job control is not enabled or an error occurs.
|
||||
$END
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
|
|
@ -137,7 +146,7 @@ fg_bg (list, foreground)
|
|||
if (INVALID_JOB (job))
|
||||
{
|
||||
if (job != DUP_JOB)
|
||||
sh_badjob (list ? list->word->word : "current");
|
||||
sh_badjob (list ? list->word->word : _("current"));
|
||||
|
||||
goto failure;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,22 @@
|
|||
/* getopt for BASH.
|
||||
/* getopt.c - getopt for Bash. Used by the getopt builtin. */
|
||||
|
||||
Copyright (C) 1993, 1994
|
||||
Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1993-2009 Free Software Foundation, Inc.
|
||||
|
||||
This program 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.
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
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.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
||||
along with Bash. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,22 @@
|
|||
/* Declarations for getopt.
|
||||
Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
|
||||
/* getopt.h - declarations for getopt. */
|
||||
|
||||
This program 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.
|
||||
/* Copyright (C) 1989, 1990, 1991, 1992, 1993, 2008,2009 Free Software Foundation, Inc.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
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 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.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
||||
along with Bash. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* XXX THIS HAS BEEN MODIFIED FOR INCORPORATION INTO BASH XXX */
|
||||
|
||||
|
|
|
|||
|
|
@ -5,26 +5,28 @@ Copyright (C) 1987-2004 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 getopts.c
|
||||
|
||||
$BUILTIN getopts
|
||||
$FUNCTION getopts_builtin
|
||||
$SHORT_DOC getopts optstring name [arg]
|
||||
Getopts is used by shell procedures to parse positional parameters.
|
||||
Parse option arguments.
|
||||
|
||||
Getopts is used by shell procedures to parse positional parameters
|
||||
as options.
|
||||
|
||||
OPTSTRING contains the option letters to be recognized; if a letter
|
||||
is followed by a colon, the option is expected to have an argument,
|
||||
|
|
@ -54,6 +56,10 @@ OPTSTRING is not a colon. OPTERR has the value 1 by default.
|
|||
|
||||
Getopts normally parses the positional parameters ($0 - $9), but if
|
||||
more arguments are given, they are parsed instead.
|
||||
|
||||
Exit Status:
|
||||
Returns success if an option is found; fails if the end of options is
|
||||
encountered or an error occurs.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
|
|||
|
|
@ -1,39 +1,47 @@
|
|||
This file is hash.def, from which is created hash.c.
|
||||
It implements the builtin "hash" in Bash.
|
||||
|
||||
Copyright (C) 1987-2006 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 hash.c
|
||||
|
||||
$BUILTIN hash
|
||||
$FUNCTION hash_builtin
|
||||
$SHORT_DOC hash [-lr] [-p pathname] [-dt] [name ...]
|
||||
For each NAME, the full pathname of the command is determined and
|
||||
remembered. If the -p option is supplied, PATHNAME is used as the
|
||||
full pathname of NAME, and no path search is performed. The -r
|
||||
option causes the shell to forget all remembered locations. The -d
|
||||
option causes the shell to forget the remembered location of each NAME.
|
||||
If the -t option is supplied the full pathname to which each NAME
|
||||
corresponds is printed. If multiple NAME arguments are supplied with
|
||||
-t, the NAME is printed before the hashed full pathname. The -l option
|
||||
causes output to be displayed in a format that may be reused as input.
|
||||
If no arguments are given, information about remembered commands is displayed.
|
||||
Remember or display program locations.
|
||||
|
||||
Determine and remember the full pathname of each command NAME. If
|
||||
no arguments are given, information about remembered commands is displayed.
|
||||
|
||||
Options:
|
||||
-d forget the remembered location of each NAME
|
||||
-l display in a format that may be reused as input
|
||||
-p pathname use PATHNAME is the full pathname of NAME
|
||||
-r forget all remembered locations
|
||||
-t print the remembered location of each NAME, preceding
|
||||
each location with the corresponding NAME if multiple
|
||||
NAMEs are given
|
||||
Arguments:
|
||||
NAME Each NAME is searched for in $PATH and added to the list
|
||||
of remembered commands.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless NAME is not found or an invalid option is given.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -158,7 +166,7 @@ hash_builtin (list)
|
|||
#ifdef EISDIR
|
||||
builtin_error ("%s: %s", pathname, strerror (EISDIR));
|
||||
#else
|
||||
builtin_error ("%s: is a directory", pathname);
|
||||
builtin_error (_("%s: is a directory"), pathname);
|
||||
#endif
|
||||
opt = EXECUTION_FAILURE;
|
||||
}
|
||||
|
|
@ -233,7 +241,7 @@ print_hashed_commands (fmt)
|
|||
return (0);
|
||||
|
||||
if (fmt == 0)
|
||||
printf ("hits\tcommand\n");
|
||||
printf (_("hits\tcommand\n"));
|
||||
hash_walk (hashed_filenames, fmt ? print_portable_hash_info : print_hash_info);
|
||||
return (1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,35 +1,46 @@
|
|||
This file is help.def, from which is created help.c.
|
||||
It implements the builtin "help" 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 help.c
|
||||
|
||||
$BUILTIN help
|
||||
$FUNCTION help_builtin
|
||||
$DEPENDS_ON HELP_BUILTIN
|
||||
$SHORT_DOC help [-s] [pattern ...]
|
||||
Display helpful information about builtin commands. If PATTERN is
|
||||
$SHORT_DOC help [-ds] [pattern ...]
|
||||
Display information about builtin commands.
|
||||
|
||||
Displays brief summaries of builtin commands. If PATTERN is
|
||||
specified, gives detailed help on all commands matching PATTERN,
|
||||
otherwise a list of the builtins is printed. The -s option
|
||||
restricts the output for each builtin command matching PATTERN to
|
||||
a short usage synopsis.
|
||||
otherwise the list of help topics is printed.
|
||||
|
||||
Options:
|
||||
-d output short description for each topic
|
||||
-m display usage in pseudo-manpage format
|
||||
-s output only a short usage synopsis for each topic matching
|
||||
PATTERN
|
||||
|
||||
Arguments:
|
||||
PATTERN Pattern specifiying a help topic
|
||||
|
||||
Exit Status:
|
||||
Returns success unless PATTERN is not found or an invalid option is given.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -63,7 +74,13 @@ $END
|
|||
extern int errno;
|
||||
#endif
|
||||
|
||||
extern const char * const bash_copyright;
|
||||
extern const char * const bash_license;
|
||||
|
||||
static void show_builtin_command_help __P((void));
|
||||
static int open_helpfile __P((char *));
|
||||
static void show_desc __P((char *, int));
|
||||
static void show_manpage __P((char *, int));
|
||||
static void show_longdoc __P((int));
|
||||
|
||||
/* Print out a list of the known functions in the shell, and what they do.
|
||||
|
|
@ -75,14 +92,20 @@ help_builtin (list)
|
|||
{
|
||||
register int i;
|
||||
char *pattern, *name;
|
||||
int plen, match_found, sflag;
|
||||
int plen, match_found, sflag, dflag, mflag;
|
||||
|
||||
sflag = 0;
|
||||
dflag = sflag = mflag = 0;
|
||||
reset_internal_getopt ();
|
||||
while ((i = internal_getopt (list, "s")) != -1)
|
||||
while ((i = internal_getopt (list, "dms")) != -1)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 'd':
|
||||
dflag = 1;
|
||||
break;
|
||||
case 'm':
|
||||
mflag = 1;
|
||||
break;
|
||||
case 's':
|
||||
sflag = 1;
|
||||
break;
|
||||
|
|
@ -104,10 +127,7 @@ help_builtin (list)
|
|||
|
||||
if (glob_pattern_p (list->word->word))
|
||||
{
|
||||
if (list->next)
|
||||
printf (_("Shell commands matching keywords `"));
|
||||
else
|
||||
printf (_("Shell commands matching keyword `"));
|
||||
printf (ngettext ("Shell commands matching keyword `", "Shell commands matching keywords `", (list->next ? 2 : 1)));
|
||||
print_word_list (list, ", ");
|
||||
printf ("'\n\n");
|
||||
}
|
||||
|
|
@ -123,12 +143,22 @@ help_builtin (list)
|
|||
if ((strncmp (pattern, name, plen) == 0) ||
|
||||
(strmatch (pattern, name, FNMATCH_EXTFLAG) != FNM_NOMATCH))
|
||||
{
|
||||
match_found++;
|
||||
if (dflag)
|
||||
{
|
||||
show_desc (name, i);
|
||||
continue;
|
||||
}
|
||||
else if (mflag)
|
||||
{
|
||||
show_manpage (name, i);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf ("%s: %s\n", name, shell_builtins[i].short_doc);
|
||||
|
||||
if (sflag == 0)
|
||||
show_longdoc (i);
|
||||
|
||||
match_found++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -143,6 +173,21 @@ help_builtin (list)
|
|||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
static int
|
||||
open_helpfile (name)
|
||||
char *name;
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open (name, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
builtin_error (_("%s: cannot open: %s"), name, strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* By convention, enforced by mkbuiltins.c, if separate help files are being
|
||||
used, the long_doc array contains one string -- the full pathname of the
|
||||
help file for this builtin. */
|
||||
|
|
@ -158,12 +203,9 @@ show_longdoc (i)
|
|||
|
||||
if (doc && doc[0] && *doc[0] == '/' && doc[1] == (char *)NULL)
|
||||
{
|
||||
fd = open (doc[0], O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
builtin_error (_("%s: cannot open: %s"), doc[0], strerror (errno));
|
||||
return;
|
||||
}
|
||||
fd = open_helpfile (doc[0]);
|
||||
if (fd < 0)
|
||||
return;
|
||||
zcatfd (fd, 1, doc[0]);
|
||||
close (fd);
|
||||
}
|
||||
|
|
@ -172,11 +214,124 @@ show_longdoc (i)
|
|||
printf ("%*s%s\n", BASE_INDENT, " ", _(doc[j]));
|
||||
}
|
||||
|
||||
static void
|
||||
show_desc (name, i)
|
||||
char *name;
|
||||
int i;
|
||||
{
|
||||
register int j;
|
||||
char **doc, *line;
|
||||
int fd, usefile;
|
||||
|
||||
doc = (char **)shell_builtins[i].long_doc;
|
||||
|
||||
usefile = (doc && doc[0] && *doc[0] == '/' && doc[1] == (char *)NULL);
|
||||
if (usefile)
|
||||
{
|
||||
fd = open_helpfile (doc[0]);
|
||||
if (fd < 0)
|
||||
return;
|
||||
zmapfd (fd, &line, doc[0]);
|
||||
close (fd);
|
||||
}
|
||||
else
|
||||
line = doc ? doc[0] : (char *)NULL;
|
||||
|
||||
printf ("%s - ", name);
|
||||
for (j = 0; line && line[j]; j++)
|
||||
{
|
||||
putchar (line[j]);
|
||||
if (line[j] == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
fflush (stdout);
|
||||
|
||||
if (usefile)
|
||||
free (line);
|
||||
}
|
||||
|
||||
/* Print builtin help in pseudo-manpage format. */
|
||||
static void
|
||||
show_manpage (name, i)
|
||||
char *name;
|
||||
int i;
|
||||
{
|
||||
register int j;
|
||||
char **doc, *line;
|
||||
int fd, usefile;
|
||||
|
||||
doc = (char **)shell_builtins[i].long_doc;
|
||||
|
||||
usefile = (doc && doc[0] && *doc[0] == '/' && doc[1] == (char *)NULL);
|
||||
if (usefile)
|
||||
{
|
||||
fd = open_helpfile (doc[0]);
|
||||
if (fd < 0)
|
||||
return;
|
||||
zmapfd (fd, &line, doc[0]);
|
||||
close (fd);
|
||||
}
|
||||
else
|
||||
line = doc ? _(doc[0]) : (char *)NULL;
|
||||
|
||||
/* NAME */
|
||||
printf ("NAME\n");
|
||||
printf ("%*s%s - ", BASE_INDENT, " ", name);
|
||||
for (j = 0; line && line[j]; j++)
|
||||
{
|
||||
putchar (line[j]);
|
||||
if (line[j] == '\n')
|
||||
break;
|
||||
}
|
||||
printf ("\n");
|
||||
|
||||
/* SYNOPSIS */
|
||||
printf ("SYNOPSIS\n");
|
||||
printf ("%*s%s\n\n", BASE_INDENT, " ", shell_builtins[i].short_doc);
|
||||
|
||||
/* DESCRIPTION */
|
||||
printf ("DESCRIPTION\n");
|
||||
if (usefile == 0)
|
||||
{
|
||||
for (j = 0; doc[j]; j++)
|
||||
printf ("%*s%s\n", BASE_INDENT, " ", _(doc[j]));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j = 0; line && line[j]; j++)
|
||||
{
|
||||
putchar (line[j]);
|
||||
if (line[j] == '\n')
|
||||
printf ("%*s", BASE_INDENT, " ");
|
||||
}
|
||||
}
|
||||
putchar ('\n');
|
||||
|
||||
/* SEE ALSO */
|
||||
printf ("SEE ALSO\n");
|
||||
printf ("%*sbash(1)\n\n", BASE_INDENT, " ");
|
||||
|
||||
/* IMPLEMENTATION */
|
||||
printf ("IMPLEMENTATION\n");
|
||||
printf ("%*s", BASE_INDENT, " ");
|
||||
show_shell_version (0);
|
||||
printf ("%*s", BASE_INDENT, " ");
|
||||
printf ("%s\n", _(bash_copyright));
|
||||
printf ("%*s", BASE_INDENT, " ");
|
||||
printf ("%s\n", _(bash_license));
|
||||
|
||||
fflush (stdout);
|
||||
if (usefile)
|
||||
free (line);
|
||||
}
|
||||
|
||||
static void
|
||||
show_builtin_command_help ()
|
||||
{
|
||||
int i, j;
|
||||
char blurb[36];
|
||||
int height, width;
|
||||
char *t, blurb[128];
|
||||
|
||||
printf (
|
||||
_("These shell commands are defined internally. Type `help' to see this list.\n\
|
||||
|
|
@ -187,21 +342,42 @@ Use `man -k' or `info' to find out more about commands not in this list.\n\
|
|||
A star (*) next to a name means that the command is disabled.\n\
|
||||
\n"));
|
||||
|
||||
for (i = 0; i < num_shell_builtins; i++)
|
||||
t = get_string_value ("COLUMNS");
|
||||
width = (t && *t) ? atoi (t) : 80;
|
||||
if (width <= 0)
|
||||
width = 80;
|
||||
|
||||
width /= 2;
|
||||
if (width > sizeof (blurb))
|
||||
width = sizeof (blurb);
|
||||
height = (num_shell_builtins + 1) / 2; /* number of rows */
|
||||
|
||||
for (i = 0; i < height; i++)
|
||||
{
|
||||
QUIT;
|
||||
blurb[0] = (shell_builtins[i].flags & BUILTIN_ENABLED) ? ' ' : '*';
|
||||
strncpy (blurb + 1, shell_builtins[i].short_doc, 34);
|
||||
blurb[35] = '\0';
|
||||
printf ("%s", blurb);
|
||||
|
||||
if (i % 2)
|
||||
printf ("\n");
|
||||
else
|
||||
for (j = strlen (blurb); j < 35; j++)
|
||||
putc (' ', stdout);
|
||||
/* first column */
|
||||
blurb[0] = (shell_builtins[i].flags & BUILTIN_ENABLED) ? ' ' : '*';
|
||||
strncpy (blurb + 1, shell_builtins[i].short_doc, width - 2);
|
||||
blurb[width - 2] = '>'; /* indicate truncation */
|
||||
blurb[width - 1] = '\0';
|
||||
printf ("%s", blurb);
|
||||
if (((i << 1) >= num_shell_builtins) || (i+height >= num_shell_builtins))
|
||||
{
|
||||
printf ("\n");
|
||||
break;
|
||||
}
|
||||
|
||||
/* two spaces */
|
||||
for (j = strlen (blurb); j < width; j++)
|
||||
putc (' ', stdout);
|
||||
|
||||
/* second column */
|
||||
blurb[0] = (shell_builtins[i+height].flags & BUILTIN_ENABLED) ? ' ' : '*';
|
||||
strncpy (blurb + 1, shell_builtins[i+height].short_doc, width - 3);
|
||||
blurb[width - 3] = '>'; /* indicate truncation */
|
||||
blurb[width - 2] = '\0';
|
||||
printf ("%s\n", blurb);
|
||||
}
|
||||
if (i % 2)
|
||||
printf ("\n");
|
||||
}
|
||||
#endif /* HELP_BUILTIN */
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
$SHORT_DOC history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
|
||||
Display or manipulate the history list.
|
||||
|
||||
If FILENAME is given, then that is used as the history file else
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -5,19 +5,18 @@ Copyright (C) 1987-2002 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 inlib.c
|
||||
#include <config.h>
|
||||
|
|
@ -29,12 +28,17 @@ $BUILTIN inlib
|
|||
$FUNCTION inlib_builtin
|
||||
$DEPENDS_ON apollo
|
||||
$SHORT_DOC inlib pathname [pathname...]
|
||||
Install user-supplied library.
|
||||
|
||||
Install a user-supplied library specified by pathname in the current
|
||||
shell process. The library is used to resolve external references
|
||||
in programs and libraries loaded after its installation. Note
|
||||
that the library is not loaded into the address space unless it is
|
||||
needed to resolve an external reference. The list of inlibed
|
||||
libraries is passed to all children of the current shell.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless PATHNAME is not found or an error occurs.
|
||||
$END
|
||||
|
||||
#if defined (apollo)
|
||||
|
|
@ -64,7 +68,7 @@ inlib_builtin (list)
|
|||
|
||||
if (status.all != status_$ok)
|
||||
{
|
||||
builtin_error ("%s: inlib failed", list->word->word);
|
||||
builtin_error (_("%s: inlib failed"), list->word->word);
|
||||
return_value = EXECUTION_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
This file is jobs.def, from which is created jobs.c.
|
||||
It implements the builtins "jobs" and "disown" in Bash.
|
||||
|
||||
Copyright (C) 1987-2005 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 jobs.c
|
||||
|
||||
|
|
@ -25,15 +24,26 @@ $BUILTIN jobs
|
|||
$FUNCTION jobs_builtin
|
||||
$DEPENDS_ON JOB_CONTROL
|
||||
$SHORT_DOC jobs [-lnprs] [jobspec ...] or jobs -x command [args]
|
||||
Lists the active jobs. The -l option lists process id's in addition
|
||||
to the normal information; the -p option lists process id's only.
|
||||
If -n is given, only processes that have changed status since the last
|
||||
notification are printed. JOBSPEC restricts output to that job. The
|
||||
-r and -s options restrict output to running and stopped jobs only,
|
||||
respectively. Without options, the status of all active jobs is
|
||||
printed. If -x is given, COMMAND is run after all job specifications
|
||||
that appear in ARGS have been replaced with the process ID of that job's
|
||||
Display status of jobs.
|
||||
|
||||
Lists the active jobs. JOBSPEC restricts output to that job.
|
||||
Without options, the status of all active jobs is displayed.
|
||||
|
||||
Options:
|
||||
-l lists process IDs in addition to the normal information
|
||||
-n list only processes that have changed status since the last
|
||||
notification
|
||||
-p lists process IDs only
|
||||
-r restrict output to running jobs
|
||||
-s restrict output to stopped jobs
|
||||
|
||||
If -x is supplied, COMMAND is run after all job specifications that
|
||||
appear in ARGS have been replaced with the process ID of that job's
|
||||
process group leader.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is given or an error occurs.
|
||||
If -x is used, returns the exit status of COMMAND.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -203,11 +213,19 @@ $BUILTIN disown
|
|||
$FUNCTION disown_builtin
|
||||
$DEPENDS_ON JOB_CONTROL
|
||||
$SHORT_DOC disown [-h] [-ar] [jobspec ...]
|
||||
By default, removes each JOBSPEC argument from the table of active jobs.
|
||||
If the -h option is given, the job is not removed from the table, but is
|
||||
marked so that SIGHUP is not sent to the job if the shell receives a
|
||||
SIGHUP. The -a option, when JOBSPEC is not supplied, means to remove all
|
||||
jobs from the job table; the -r option means to remove only running jobs.
|
||||
Remove jobs from current shell.
|
||||
|
||||
Removes each JOBSPEC argument from the table of active jobs. Without
|
||||
any JOBSPECs, the shell uses its notion of the current job.
|
||||
|
||||
Options:
|
||||
-a remove all jobs if JOBSPEC is not supplied
|
||||
-h mark each JOBSPEC so that SIGHUP is not sent to the job if the
|
||||
shell receives a SIGHUP
|
||||
-r remove only running jobs
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option or JOBSPEC is given.
|
||||
$END
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
|
|
@ -261,7 +279,7 @@ disown_builtin (list)
|
|||
|
||||
if (job == NO_JOB || jobs == 0 || INVALID_JOB (job))
|
||||
{
|
||||
sh_badjob (list ? list->word->word : "current");
|
||||
sh_badjob (list ? list->word->word : _("current"));
|
||||
retval = EXECUTION_FAILURE;
|
||||
}
|
||||
else if (nohup_only)
|
||||
|
|
|
|||
|
|
@ -1,36 +1,46 @@
|
|||
This file is kill.def, from which is created kill.c.
|
||||
It implements the builtin "kill" in Bash.
|
||||
|
||||
Copyright (C) 1987-2005 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 kill.c
|
||||
|
||||
$BUILTIN kill
|
||||
$FUNCTION kill_builtin
|
||||
$SHORT_DOC kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
|
||||
Send the processes named by PID (or JOBSPEC) the signal SIGSPEC. If
|
||||
SIGSPEC is not present, then SIGTERM is assumed. An argument of `-l'
|
||||
lists the signal names; if arguments follow `-l' they are assumed to
|
||||
be signal numbers for which names should be listed. Kill is a shell
|
||||
builtin for two reasons: it allows job IDs to be used instead of
|
||||
process IDs, and, if you have reached the limit on processes that
|
||||
you can create, you don't have to start a process to kill another one.
|
||||
Send a signal to a job.
|
||||
|
||||
Send the processes identified by PID or JOBSPEC the signal named by
|
||||
SIGSPEC or SIGNUM. If neither SIGSPEC nor SIGNUM is present, then
|
||||
SIGTERM is assumed.
|
||||
|
||||
Options:
|
||||
-s sig SIG is a signal name
|
||||
-n sig SIG is a signal number
|
||||
-l list the signal names; if arguments follow `-l' they are
|
||||
assumed to be signal numbers for which names should be listed
|
||||
|
||||
Kill is a shell builtin for two reasons: it allows job IDs to be used
|
||||
instead of process IDs, and allows processes to be killed if the limit
|
||||
on processes that you can create is reached.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is given or an error occurs.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
|
|||
|
|
@ -1,33 +1,34 @@
|
|||
This file is let.def, from which is created let.c.
|
||||
It implements the builtin "let" in Bash.
|
||||
|
||||
Copyright (C) 1987-2002 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/>.
|
||||
|
||||
$BUILTIN let
|
||||
$FUNCTION let_builtin
|
||||
$PRODUCES let.c
|
||||
$SHORT_DOC let arg [arg ...]
|
||||
Each ARG is an arithmetic expression to be evaluated. Evaluation
|
||||
is done in fixed-width integers with no check for overflow, though
|
||||
division by 0 is trapped and flagged as an error. The following
|
||||
list of operators is grouped into levels of equal-precedence operators.
|
||||
The levels are listed in order of decreasing precedence.
|
||||
Evaluate arithmetic expressions.
|
||||
|
||||
Evaluate each ARG as an arithmetic expression. Evaluation is done in
|
||||
fixed-width integers with no check for overflow, though division by 0
|
||||
is trapped and flagged as an error. The following list of operators is
|
||||
grouped into levels of equal-precedence operators. The levels are listed
|
||||
in order of decreasing precedence.
|
||||
|
||||
id++, id-- variable post-increment, post-decrement
|
||||
++id, --id variable pre-increment, pre-decrement
|
||||
|
|
@ -59,8 +60,8 @@ Operators are evaluated in order of precedence. Sub-expressions in
|
|||
parentheses are evaluated first and may override the precedence
|
||||
rules above.
|
||||
|
||||
If the last ARG evaluates to 0, let returns 1; 0 is returned
|
||||
otherwise.
|
||||
Exit Status:
|
||||
If the last ARG evaluates to 0, let returns 1; let returns 0 otherwise..
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
|
|||
317
builtins/mapfile.def
Normal file
317
builtins/mapfile.def
Normal file
|
|
@ -0,0 +1,317 @@
|
|||
This file is mapfile.def, from which is created mapfile.c.
|
||||
It implements the builtin "mapfile" in Bash.
|
||||
|
||||
Copyright (C) 2005-2006 Rocky Bernstein for Free Software Foundation, Inc.
|
||||
Copyright (C) 2008,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 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.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Bash. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
$PRODUCES mapfile.c
|
||||
|
||||
$BUILTIN mapfile
|
||||
$FUNCTION mapfile_builtin
|
||||
$SHORT_DOC mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
|
||||
Read lines from a file into an array variable.
|
||||
|
||||
Read lines from the standard input into the array variable ARRAY, or from
|
||||
file descriptor FD if the -u option is supplied. The variable MAPFILE is
|
||||
the default ARRAY.
|
||||
|
||||
Options:
|
||||
-n count Copy at most COUNT lines. If COUNT is 0, all lines are copied.
|
||||
-O origin Begin assigning to ARRAY at index ORIGIN. The default index is 0.
|
||||
-s count Discard the first COUNT lines read.
|
||||
-t Remove a trailing newline from each line read.
|
||||
-u fd Read lines from file descriptor FD instead of the standard input.
|
||||
-C callback Evaluate CALLBACK each time QUANTUM lines are read.
|
||||
-c quantum Specify the number of lines read between each call to CALLBACK.
|
||||
|
||||
Arguments:
|
||||
ARRAY Array variable name to use for file data.
|
||||
|
||||
If -C is supplied without -c, the default quantum is 5000.
|
||||
|
||||
If not supplied with an explicit origin, mapfile will clear ARRAY before
|
||||
assigning to it.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is given or ARRAY is readonly.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "builtins.h"
|
||||
#include "posixstat.h"
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "bashansi.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../bashintl.h"
|
||||
#include "../shell.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
|
||||
#define DEFAULT_ARRAY_NAME "MAPFILE"
|
||||
|
||||
/* The value specifying how frequently `mapfile' calls the callback. */
|
||||
#define DEFAULT_QUANTUM 5000
|
||||
|
||||
/* Values for FLAGS */
|
||||
#define MAPF_CLEARARRAY 0x01
|
||||
#define MAPF_CHOP 0x02
|
||||
|
||||
static int
|
||||
run_callback(callback, current_index)
|
||||
const char *callback;
|
||||
unsigned int current_index;
|
||||
{
|
||||
unsigned int execlen;
|
||||
char *execstr;
|
||||
|
||||
execlen = strlen (callback) + 10;
|
||||
/* 1 for space between %s and %d,
|
||||
another 1 for the last nul char for C string. */
|
||||
execlen += 2;
|
||||
execstr = xmalloc (execlen);
|
||||
|
||||
snprintf (execstr, execlen, "%s %d", callback, current_index);
|
||||
return parse_and_execute(execstr, NULL, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
do_chop(line)
|
||||
char * line;
|
||||
{
|
||||
int length;
|
||||
|
||||
length = strlen (line);
|
||||
if (length && line[length-1] == '\n')
|
||||
line[length-1] = '\0';
|
||||
}
|
||||
|
||||
static int
|
||||
mapfile (fd, line_count_goal, origin, nskip, callback_quantum, callback, array_name, flags)
|
||||
int fd;
|
||||
long line_count_goal, origin, nskip, callback_quantum;
|
||||
char *callback, *array_name;
|
||||
int flags;
|
||||
{
|
||||
char *line;
|
||||
size_t line_length;
|
||||
unsigned int array_index, line_count;
|
||||
SHELL_VAR *entry;
|
||||
int unbuffered_read;
|
||||
|
||||
line = NULL;
|
||||
line_length = 0;
|
||||
unbuffered_read = 0;
|
||||
|
||||
/* The following check should be done before reading any lines. Doing it
|
||||
here allows us to call bind_array_element instead of bind_array_variable
|
||||
and skip the variable lookup on every call. */
|
||||
entry = find_or_make_array_variable (array_name, 1);
|
||||
if (entry == 0)
|
||||
return (EXECUTION_FAILURE);
|
||||
if (flags & MAPF_CLEARARRAY)
|
||||
array_flush (array_cell (entry));
|
||||
|
||||
#ifndef __CYGWIN__
|
||||
unbuffered_read = (lseek (fd, 0L, SEEK_CUR) < 0) && (errno == ESPIPE);
|
||||
#else
|
||||
unbuffered_read = 1;
|
||||
#endif
|
||||
|
||||
/* Skip any lines at beginning of file? */
|
||||
for (line_count = 0; line_count < nskip; line_count++)
|
||||
zgetline(fd, &line, &line_length, unbuffered_read);
|
||||
line = 0;
|
||||
line_length = 0;
|
||||
|
||||
/* Reset the buffer for bash own stream */
|
||||
for (array_index = origin, line_count = 0;
|
||||
zgetline(fd, &line, &line_length, unbuffered_read) != -1;
|
||||
array_index++, line_count++)
|
||||
{
|
||||
/* Have we exceeded # of lines to store? */
|
||||
if (line_count_goal != 0 && line_count >= line_count_goal)
|
||||
break;
|
||||
|
||||
/* Remove trailing newlines? */
|
||||
if (flags & MAPF_CHOP)
|
||||
do_chop (line);
|
||||
|
||||
/* Has a callback been registered and if so is it time to call it? */
|
||||
if (callback && line_count && (line_count % callback_quantum) == 0)
|
||||
{
|
||||
run_callback (callback, array_index);
|
||||
|
||||
/* Reset the buffer for bash own stream. */
|
||||
if (unbuffered_read == 0)
|
||||
zsyncfd (fd);
|
||||
}
|
||||
|
||||
bind_array_element (entry, array_index, line, 0);
|
||||
}
|
||||
|
||||
xfree (line);
|
||||
|
||||
if (unbuffered_read == 0)
|
||||
zsyncfd (fd);
|
||||
|
||||
return EXECUTION_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
mapfile_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int opt, code, fd, clear_array, flags;
|
||||
intmax_t intval;
|
||||
long lines, origin, nskip, callback_quantum;
|
||||
char *array_name, *callback;
|
||||
|
||||
clear_array = 1;
|
||||
fd = 0;
|
||||
lines = origin = nskip = 0;
|
||||
flags = MAPF_CLEARARRAY;
|
||||
callback_quantum = DEFAULT_QUANTUM;
|
||||
callback = 0;
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "u:n:O:tC:c:s:")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'u':
|
||||
code = legal_number (list_optarg, &intval);
|
||||
if (code == 0 || intval < 0 || intval != (int)intval)
|
||||
{
|
||||
builtin_error (_("%s: invalid file descriptor specification"), list_optarg);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else
|
||||
fd = intval;
|
||||
|
||||
if (sh_validfd (fd) == 0)
|
||||
{
|
||||
builtin_error (_("%d: invalid file descriptor: %s"), fd, strerror (errno));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
code = legal_number (list_optarg, &intval);
|
||||
if (code == 0 || intval < 0 || intval != (unsigned)intval)
|
||||
{
|
||||
builtin_error (_("%s: invalid line count"), list_optarg);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else
|
||||
lines = intval;
|
||||
break;
|
||||
|
||||
case 'O':
|
||||
code = legal_number (list_optarg, &intval);
|
||||
if (code == 0 || intval < 0 || intval != (unsigned)intval)
|
||||
{
|
||||
builtin_error (_("%s: invalid array origin"), list_optarg);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else
|
||||
origin = intval;
|
||||
flags &= ~MAPF_CLEARARRAY;
|
||||
break;
|
||||
case 't':
|
||||
flags |= MAPF_CHOP;
|
||||
break;
|
||||
case 'C':
|
||||
callback = list_optarg;
|
||||
break;
|
||||
case 'c':
|
||||
code = legal_number (list_optarg, &intval);
|
||||
if (code == 0 || intval < 0 || intval != (unsigned)intval)
|
||||
{
|
||||
builtin_error (_("%s: invalid callback quantum"), list_optarg);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else
|
||||
callback_quantum = intval;
|
||||
break;
|
||||
case 's':
|
||||
code = legal_number (list_optarg, &intval);
|
||||
if (code == 0 || intval < 0 || intval != (unsigned)intval)
|
||||
{
|
||||
builtin_error (_("%s: invalid line count"), list_optarg);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else
|
||||
nskip = intval;
|
||||
break;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
if (list == 0)
|
||||
array_name = DEFAULT_ARRAY_NAME;
|
||||
else if (list->word == 0 || list->word->word == 0)
|
||||
{
|
||||
builtin_error ("internal error: getting variable name");
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else if (list->word->word[0] == '\0')
|
||||
{
|
||||
builtin_error (_("empty array variable name"));
|
||||
return (EX_USAGE);
|
||||
}
|
||||
else
|
||||
array_name = list->word->word;
|
||||
|
||||
if (legal_identifier (array_name) == 0 && valid_array_reference (array_name) == 0)
|
||||
{
|
||||
sh_invalidid (array_name);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
return mapfile (fd, lines, origin, nskip, callback_quantum, callback, array_name, flags);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
mapfile_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
builtin_error (_("array variable support required"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
#endif /* ARRAY_VARS */
|
||||
|
|
@ -1,23 +1,23 @@
|
|||
/* mkbuiltins.c - Create builtins.c, builtext.h, and builtdoc.c from
|
||||
a single source file called builtins.def. */
|
||||
|
||||
/* Copyright (C) 1987-2006 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#if !defined (CROSS_COMPILING)
|
||||
# include <config.h>
|
||||
|
|
@ -71,6 +71,7 @@ extern char *strcpy ();
|
|||
/* Flag values that builtins can have. */
|
||||
#define BUILTIN_FLAG_SPECIAL 0x01
|
||||
#define BUILTIN_FLAG_ASSIGNMENT 0x02
|
||||
#define BUILTIN_FLAG_POSIX_BUILTIN 0x04
|
||||
|
||||
#define BASE_INDENT 4
|
||||
|
||||
|
|
@ -154,9 +155,18 @@ char *assignment_builtins[] =
|
|||
(char *)NULL
|
||||
};
|
||||
|
||||
/* The builtin commands that are special to the POSIX search order. */
|
||||
char *posix_builtins[] =
|
||||
{
|
||||
"alias", "bg", "cd", "command", "false", "fc", "fg", "getopts", "jobs",
|
||||
"kill", "newgrp", "pwd", "read", "true", "umask", "unalias", "wait",
|
||||
(char *)NULL
|
||||
};
|
||||
|
||||
/* Forward declarations. */
|
||||
static int is_special_builtin ();
|
||||
static int is_assignment_builtin ();
|
||||
static int is_posix_builtin ();
|
||||
|
||||
#if !defined (HAVE_RENAME)
|
||||
static int rename ();
|
||||
|
|
@ -800,6 +810,8 @@ builtin_handler (self, defs, arg)
|
|||
new->flags |= BUILTIN_FLAG_SPECIAL;
|
||||
if (is_assignment_builtin (name))
|
||||
new->flags |= BUILTIN_FLAG_ASSIGNMENT;
|
||||
if (is_posix_builtin (name))
|
||||
new->flags |= BUILTIN_FLAG_POSIX_BUILTIN;
|
||||
|
||||
array_add ((char *)new, defs->builtins);
|
||||
building_builtin = 1;
|
||||
|
|
@ -1080,23 +1092,23 @@ char *structfile_header[] = {
|
|||
"/* This file is manufactured by ./mkbuiltins, and should not be",
|
||||
" edited by hand. See the source to mkbuiltins for details. */",
|
||||
"",
|
||||
"/* Copyright (C) 1987-2002 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. */",
|
||||
" along with Bash. If not, see <http://www.gnu.org/licenses/>.",
|
||||
"*/",
|
||||
"",
|
||||
"/* The list of shell builtins. Each element is name, function, flags,",
|
||||
" long-doc, short-doc. The long-doc field contains a pointer to an array",
|
||||
|
|
@ -1217,14 +1229,15 @@ write_builtins (defs, structfile, externfile)
|
|||
else
|
||||
fprintf (structfile, "(sh_builtin_func_t *)0x0, ");
|
||||
|
||||
fprintf (structfile, "%s%s%s, %s_doc,\n",
|
||||
fprintf (structfile, "%s%s%s%s, %s_doc,\n",
|
||||
"BUILTIN_ENABLED | STATIC_BUILTIN",
|
||||
(builtin->flags & BUILTIN_FLAG_SPECIAL) ? " | SPECIAL_BUILTIN" : "",
|
||||
(builtin->flags & BUILTIN_FLAG_ASSIGNMENT) ? " | ASSIGNMENT_BUILTIN" : "",
|
||||
(builtin->flags & BUILTIN_FLAG_POSIX_BUILTIN) ? " | POSIX_BUILTIN" : "",
|
||||
document_name (builtin));
|
||||
|
||||
fprintf
|
||||
(structfile, " \"%s\", (char *)NULL },\n",
|
||||
(structfile, " N_(\"%s\"), (char *)NULL },\n",
|
||||
builtin->shortdoc ? builtin->shortdoc : builtin->name);
|
||||
|
||||
}
|
||||
|
|
@ -1561,6 +1574,13 @@ is_assignment_builtin (name)
|
|||
return (_find_in_table (name, assignment_builtins));
|
||||
}
|
||||
|
||||
static int
|
||||
is_posix_builtin (name)
|
||||
char *name;
|
||||
{
|
||||
return (_find_in_table (name, posix_builtins));
|
||||
}
|
||||
|
||||
#if !defined (HAVE_RENAME)
|
||||
static int
|
||||
rename (from, to)
|
||||
|
|
|
|||
|
|
@ -1,39 +1,49 @@
|
|||
This file is printf.def, from which is created printf.c.
|
||||
It implements the builtin "printf" in Bash.
|
||||
|
||||
Copyright (C) 1997-2007 Free Software Foundation, Inc.
|
||||
Copyright (C) 1997-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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 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 printf.c
|
||||
|
||||
$BUILTIN printf
|
||||
$FUNCTION printf_builtin
|
||||
$SHORT_DOC printf [-v var] format [arguments]
|
||||
printf formats and prints ARGUMENTS under control of the FORMAT. FORMAT
|
||||
is a character string which contains three types of objects: plain
|
||||
characters, which are simply copied to standard output, character escape
|
||||
sequences which are converted and copied to the standard output, and
|
||||
Formats and prints ARGUMENTS under control of the FORMAT.
|
||||
|
||||
Options:
|
||||
-v var assign the output to shell variable VAR rather than
|
||||
display it on the standard output
|
||||
|
||||
FORMAT is a character string which contains three types of objects: plain
|
||||
characters, which are simply copied to standard output; character escape
|
||||
sequences, which are converted and copied to the standard output; and
|
||||
format specifications, each of which causes printing of the next successive
|
||||
argument. In addition to the standard printf(1) formats, %b means to
|
||||
expand backslash escape sequences in the corresponding argument, and %q
|
||||
means to quote the argument in a way that can be reused as shell input.
|
||||
If the -v option is supplied, the output is placed into the value of the
|
||||
shell variable VAR rather than being sent to the standard output.
|
||||
argument.
|
||||
|
||||
In addition to the standard format specifications described in printf(1)
|
||||
and printf(3), printf interprets:
|
||||
|
||||
%b expand backslash escape sequences in the corresponding argument
|
||||
%q quote the argument in a way that can be reused as shell input
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is given or a write or assignment
|
||||
error occurs.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -66,6 +76,7 @@ $END
|
|||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "shmbutil.h"
|
||||
#include "stdc.h"
|
||||
#include "bashgetopt.h"
|
||||
#include "common.h"
|
||||
|
|
@ -99,31 +110,22 @@ extern int errno;
|
|||
|
||||
#define PF(f, func) \
|
||||
do { \
|
||||
char *b = 0; \
|
||||
int nw; \
|
||||
clearerr (stdout); \
|
||||
if (have_fieldwidth && have_precision) \
|
||||
nw = asprintf(&b, f, fieldwidth, precision, func); \
|
||||
nw = vflag ? vbprintf (f, fieldwidth, precision, func) : printf (f, fieldwidth, precision, func); \
|
||||
else if (have_fieldwidth) \
|
||||
nw = asprintf(&b, f, fieldwidth, func); \
|
||||
nw = vflag ? vbprintf (f, fieldwidth, func) : printf (f, fieldwidth, func); \
|
||||
else if (have_precision) \
|
||||
nw = asprintf(&b, f, precision, func); \
|
||||
nw = vflag ? vbprintf (f, precision, func) : printf (f, fieldwidth, func); \
|
||||
else \
|
||||
nw = asprintf(&b, f, func); \
|
||||
nw = vflag ? vbprintf (f, func) : printf (f, func); \
|
||||
tw += nw; \
|
||||
if (b) \
|
||||
if (ferror (stdout)) \
|
||||
{ \
|
||||
if (vflag) \
|
||||
(void)vbadd (b, nw); \
|
||||
else \
|
||||
(void)fputs (b, stdout); \
|
||||
if (ferror (stdout)) \
|
||||
{ \
|
||||
sh_wrerror (); \
|
||||
clearerr (stdout); \
|
||||
return (EXECUTION_FAILURE); \
|
||||
} \
|
||||
free (b); \
|
||||
sh_wrerror (); \
|
||||
clearerr (stdout); \
|
||||
return (EXECUTION_FAILURE); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
|
@ -148,6 +150,9 @@ extern int errno;
|
|||
vbsize = 0; \
|
||||
vbuf = 0; \
|
||||
} \
|
||||
else if (vbuf) \
|
||||
vbuf[0] = 0; \
|
||||
terminate_immediately--; \
|
||||
fflush (stdout); \
|
||||
if (ferror (stdout)) \
|
||||
{ \
|
||||
|
|
@ -165,11 +170,16 @@ extern int errno;
|
|||
extern int asprintf __P((char **, const char *, ...)) __attribute__((__format__ (printf, 2, 3)));
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VSNPRINTF
|
||||
extern int vsnprintf __P((char *, size_t, const char *, ...)) __attribute__((__format__ (printf, 3, 4)));
|
||||
#endif
|
||||
|
||||
static void printf_erange __P((char *));
|
||||
static int printstr __P((char *, char *, int, int, int));
|
||||
static int tescape __P((char *, char *, int *));
|
||||
static char *bexpand __P((char *, int, int *, int *));
|
||||
static char *vbadd __P((char *, int));
|
||||
static int vbprintf __P((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
|
||||
static char *mklong __P((char *, char *, size_t));
|
||||
static int getchr __P((void));
|
||||
static char *getstr __P((void));
|
||||
|
|
@ -188,7 +198,7 @@ typedef double floatmax_t;
|
|||
#endif
|
||||
static floatmax_t getfloatmax __P((void));
|
||||
|
||||
static int asciicode __P((void));
|
||||
static intmax_t asciicode __P((void));
|
||||
|
||||
static WORD_LIST *garglist;
|
||||
static int retval;
|
||||
|
|
@ -228,6 +238,8 @@ printf_builtin (list)
|
|||
{
|
||||
vflag = 1;
|
||||
vblen = 0;
|
||||
if (vbuf)
|
||||
vbuf[0] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -259,6 +271,8 @@ printf_builtin (list)
|
|||
/* If the format string is empty after preprocessing, return immediately. */
|
||||
if (format == 0 || *format == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
terminate_immediately++;
|
||||
|
||||
/* Basic algorithm is to scan the format string for conversion
|
||||
specifications -- once one is found, find out if the field
|
||||
|
|
@ -554,7 +568,7 @@ static void
|
|||
printf_erange (s)
|
||||
char *s;
|
||||
{
|
||||
builtin_error ("warning: %s: %s", s, strerror(ERANGE));
|
||||
builtin_error (_("warning: %s: %s"), s, strerror(ERANGE));
|
||||
}
|
||||
|
||||
/* We duplicate a lot of what printf(3) does here. */
|
||||
|
|
@ -577,7 +591,7 @@ printstr (fmt, string, len, fieldwidth, precision)
|
|||
#else
|
||||
if (string == 0 || len == 0)
|
||||
#endif
|
||||
return;
|
||||
return 0;
|
||||
|
||||
#if 0
|
||||
s = fmt;
|
||||
|
|
@ -835,7 +849,7 @@ vbadd (buf, blen)
|
|||
|
||||
if (blen == 1)
|
||||
vbuf[vblen++] = buf[0];
|
||||
else
|
||||
else if (blen > 1)
|
||||
{
|
||||
FASTCOPY (buf, vbuf + vblen, blen);
|
||||
vblen += blen;
|
||||
|
|
@ -850,6 +864,42 @@ vbadd (buf, blen)
|
|||
return vbuf;
|
||||
}
|
||||
|
||||
static int
|
||||
#if defined (PREFER_STDARG)
|
||||
vbprintf (const char *format, ...)
|
||||
#else
|
||||
vbprintf (format, va_alist)
|
||||
const char *format;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
size_t nlen;
|
||||
int blen;
|
||||
|
||||
SH_VA_START (args, format);
|
||||
blen = vsnprintf (vbuf + vblen, vbsize - vblen, format, args);
|
||||
|
||||
nlen = vblen + blen + 1;
|
||||
if (nlen >= vbsize)
|
||||
{
|
||||
vbsize = ((nlen + 63) >> 6) << 6;
|
||||
vbuf = (char *)xrealloc (vbuf, vbsize);
|
||||
blen = vsnprintf (vbuf + vblen, vbsize - vblen, format, args);
|
||||
}
|
||||
|
||||
va_end (args);
|
||||
vblen += blen;
|
||||
vbuf[vblen] = '\0';
|
||||
|
||||
#ifdef DEBUG
|
||||
if (strlen (vbuf) != vblen)
|
||||
internal_error ("printf:vbadd: vblen (%d) != strlen (vbuf) (%d)", vblen, (int)strlen (vbuf));
|
||||
#endif
|
||||
|
||||
return (blen);
|
||||
}
|
||||
|
||||
static char *
|
||||
mklong (str, modifiers, mlen)
|
||||
char *str;
|
||||
|
|
@ -1014,12 +1064,28 @@ getfloatmax ()
|
|||
}
|
||||
|
||||
/* NO check is needed for garglist here. */
|
||||
static int
|
||||
static intmax_t
|
||||
asciicode ()
|
||||
{
|
||||
register int ch;
|
||||
register intmax_t ch;
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
wchar_t wc;
|
||||
size_t mblength, slen;
|
||||
#endif
|
||||
DECLARE_MBSTATE;
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
slen = strlen (garglist->word->word+1);
|
||||
mblength = MBLEN (garglist->word->word+1, slen);
|
||||
if (mblength > 1)
|
||||
{
|
||||
mblength = mbtowc (&wc, garglist->word->word+1, slen);
|
||||
ch = wc; /* XXX */
|
||||
}
|
||||
else
|
||||
#endif
|
||||
ch = (unsigned char)garglist->word->word[1];
|
||||
|
||||
ch = garglist->word->word[1];
|
||||
garglist = garglist->next;
|
||||
return (ch);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,19 +4,19 @@
|
|||
|
||||
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. */
|
||||
along with Bash. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Write output in 128-byte chunks until we get a sigpipe or write gets an
|
||||
EPIPE. Then report how many bytes we wrote. We assume that this is the
|
||||
|
|
|
|||
|
|
@ -1,94 +1,114 @@
|
|||
This file is pushd.def, from which is created pushd.c. It implements the
|
||||
builtins "pushd", "popd", and "dirs" in Bash.
|
||||
|
||||
Copyright (C) 1987-2004 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 pushd.c
|
||||
|
||||
$BUILTIN pushd
|
||||
$FUNCTION pushd_builtin
|
||||
$DEPENDS_ON PUSHD_AND_POPD
|
||||
$SHORT_DOC pushd [dir | +N | -N] [-n]
|
||||
$SHORT_DOC pushd [-n] [+N | -N | dir]
|
||||
Add directories to stack.
|
||||
|
||||
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
|
||||
Options:
|
||||
-n Suppresses the normal change of directory when adding
|
||||
directories to the stack, so only the stack is manipulated.
|
||||
|
||||
Arguments:
|
||||
+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
|
||||
-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
|
||||
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.
|
||||
The `dirs' builtin displays the directory stack.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid argument is supplied or the directory
|
||||
change fails.
|
||||
$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.
|
||||
$SHORT_DOC popd [-n] [+N | -N]
|
||||
Remove directories from stack.
|
||||
|
||||
+N removes the Nth entry counting from the left of the list
|
||||
Removes entries from the directory stack. With no arguments, removes
|
||||
the top directory from the stack, and changes to the new top directory.
|
||||
|
||||
Options:
|
||||
-n Suppresses the normal change of directory when removing
|
||||
directories from the stack, so only the stack is manipulated.
|
||||
|
||||
Arguments:
|
||||
+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
|
||||
-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.
|
||||
The `dirs' builtin displays the directory stack.
|
||||
|
||||
You can see the directory stack with the `dirs' command.
|
||||
Exit Status:
|
||||
Returns success unless an invalid argument is supplied or the directory
|
||||
change fails.
|
||||
$END
|
||||
|
||||
$BUILTIN dirs
|
||||
$FUNCTION dirs_builtin
|
||||
$DEPENDS_ON PUSHD_AND_POPD
|
||||
$SHORT_DOC dirs [-clpv] [+N] [-N]
|
||||
Display directory stack.
|
||||
|
||||
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.
|
||||
Options:
|
||||
-c clear the directory stack by deleting all of the elements
|
||||
-l do not print tilde-prefixed versions of directories relative
|
||||
to your home directory
|
||||
-p print the directory stack with one entry per line
|
||||
-v print the directory stack with one entry per line prefixed
|
||||
with its position in the stack
|
||||
|
||||
+N displays the Nth entry counting from the left of the list shown by
|
||||
Arguments:
|
||||
+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
|
||||
-N Displays the Nth entry counting from the right of the list shown by
|
||||
dirs when invoked without options, starting with zero.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is supplied or an error occurs.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -448,7 +468,7 @@ dirs_builtin (list)
|
|||
if (index_flag)
|
||||
{
|
||||
putchar ('\n');
|
||||
return EXECUTION_SUCCESS;
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -473,8 +493,8 @@ dirs_builtin (list)
|
|||
printf ("%s%s", (vflag & 1) ? "\n" : " ", DIRSTACK_ENTRY (i));
|
||||
|
||||
putchar ('\n');
|
||||
fflush (stdout);
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -483,9 +503,9 @@ pushd_error (offset, arg)
|
|||
char *arg;
|
||||
{
|
||||
if (offset == 0)
|
||||
builtin_error ("directory stack empty");
|
||||
builtin_error (_("directory stack empty"));
|
||||
else
|
||||
sh_erange (arg, "directory stack index");
|
||||
sh_erange (arg, _("directory stack index"));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -660,66 +680,70 @@ get_directory_stack (flags)
|
|||
|
||||
#ifdef LOADABLE_BUILTIN
|
||||
char * const 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."),
|
||||
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\
|
||||
Options:\n\
|
||||
-c clear the directory stack by deleting all of the elements\n\
|
||||
-l do not print tilde-prefixed versions of directories relative\n\
|
||||
to your home directory\n\
|
||||
-p print the directory stack with one entry per line\n\
|
||||
-v print the directory stack with one entry per line prefixed\n\
|
||||
with its position in the stack\n\
|
||||
\n\
|
||||
Arguments:\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
|
||||
};
|
||||
|
||||
char * const 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."),
|
||||
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\
|
||||
Options:\n\
|
||||
-n Suppresses the normal change of directory when adding\n\
|
||||
directories to the stack, so only the stack is manipulated.\n\
|
||||
\n\
|
||||
Arguments:\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\
|
||||
dir Adds DIR to the directory stack at the top, making it the\n\
|
||||
new current working directory.\n\
|
||||
\n\
|
||||
The `dirs' builtin displays the directory stack."),
|
||||
(char *)NULL
|
||||
};
|
||||
|
||||
char * const 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."),
|
||||
N_("Removes entries from the directory stack. With no arguments, removes\n\
|
||||
the top directory from the stack, and changes to the new top directory.\n\
|
||||
\n\
|
||||
Options:\n\
|
||||
-n Suppresses the normal change of directory when removing\n\
|
||||
directories from the stack, so only the stack is manipulated.\n\
|
||||
\n\
|
||||
Arguments:\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\
|
||||
The `dirs' builtin displays the directory stack."),
|
||||
(char *)NULL
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,50 +1,63 @@
|
|||
This file is read.def, from which is created read.c.
|
||||
It implements the builtin "read" in Bash.
|
||||
|
||||
Copyright (C) 1987-2005 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 read.c
|
||||
|
||||
$BUILTIN read
|
||||
$FUNCTION read_builtin
|
||||
$SHORT_DOC read [-ers] [-u fd] [-t timeout] [-p prompt] [-a array] [-n nchars] [-d delim] [name ...]
|
||||
One line is read from the standard input, or from file descriptor FD if the
|
||||
-u option is supplied, and the first word is assigned to the first NAME,
|
||||
the second word to the second NAME, and so on, with leftover words assigned
|
||||
to the last NAME. Only the characters found in $IFS are recognized as word
|
||||
delimiters. If no NAMEs are supplied, the line read is stored in the REPLY
|
||||
variable. If the -r option is given, this signifies `raw' input, and
|
||||
backslash escaping is disabled. The -d option causes read to continue
|
||||
until the first character of DELIM is read, rather than newline. If the -p
|
||||
option is supplied, the string PROMPT is output without a trailing newline
|
||||
before attempting to read. If -a is supplied, the words read are assigned
|
||||
to sequential indices of ARRAY, starting at zero. If -e is supplied and
|
||||
the shell is interactive, readline is used to obtain the line. If -n is
|
||||
supplied with a non-zero NCHARS argument, read returns after NCHARS
|
||||
characters have been read. The -s option causes input coming from a
|
||||
terminal to not be echoed.
|
||||
$SHORT_DOC read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
|
||||
Read a line from the standard input and split it into fields.
|
||||
|
||||
The -t option causes read to time out and return failure if a complete line
|
||||
of input is not read within TIMEOUT seconds. If the TMOUT variable is set,
|
||||
its value is the default timeout. The return code is zero, unless end-of-file
|
||||
is encountered, read times out, or an invalid file descriptor is supplied as
|
||||
the argument to -u.
|
||||
Reads a single line from the standard input, or from file descriptor FD
|
||||
if the -u option is supplied. The line is split into fields as with word
|
||||
splitting, and the first word is assigned to the first NAME, the second
|
||||
word to the second NAME, and so on, with any leftover words assigned to
|
||||
the last NAME. Only the characters found in $IFS are recognized as word
|
||||
delimiters.
|
||||
|
||||
If no NAMEs are supplied, the line read is stored in the REPLY variable.
|
||||
|
||||
Options:
|
||||
-a array assign the words read to sequential indices of the array
|
||||
variable ARRAY, starting at zero
|
||||
-d delim continue until the first character of DELIM is read, rather
|
||||
than newline
|
||||
-e use Readline to obtain the line in an interactive shell
|
||||
-i text Use TEXT as the initial text for Readline
|
||||
-n nchars return after reading NCHARS characters rather than waiting
|
||||
for a newline
|
||||
-p prompt output the string PROMPT without a trailing newline before
|
||||
attempting to read
|
||||
-r do not allow backslashes to escape any characters
|
||||
-s do not echo input coming from a terminal
|
||||
-t timeout time out and return failure if a complete line of input is
|
||||
not read withint TIMEOUT seconds. The value of the TMOUT
|
||||
variable is the default timeout. TIMEOUT may be a
|
||||
fractional number. If TIMEOUT is 0, read returns success only
|
||||
if input is available on the specified file descriptor. The
|
||||
exit status is greater than 128 if the timeout is exceeded
|
||||
-u fd read from file descriptor FD instead of the standard input
|
||||
|
||||
Exit Status:
|
||||
The return code is zero, unless end-of-file is encountered, read times out,
|
||||
or an invalid file descriptor is supplied as the argument to -u.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -54,6 +67,8 @@ $END
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "bashansi.h"
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
|
@ -87,13 +102,24 @@ $END
|
|||
extern int errno;
|
||||
#endif
|
||||
|
||||
struct ttsave
|
||||
{
|
||||
int fd;
|
||||
TTYSTRUCT *attrs;
|
||||
};
|
||||
|
||||
#if defined (READLINE)
|
||||
static void reset_attempted_completion_function __P((char *));
|
||||
static char *edit_line __P((char *));
|
||||
static int set_itext __P((void));
|
||||
static char *edit_line __P((char *, char *));
|
||||
static void set_eol_delim __P((int));
|
||||
static void reset_eol_delim __P((char *));
|
||||
#endif
|
||||
static SHELL_VAR *bind_read_variable __P((char *, char *));
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
static int read_mbchar __P((int, char *, int, int, int));
|
||||
#endif
|
||||
static void ttyrestore __P((struct ttsave *));
|
||||
|
||||
static sighandler sigalrm __P((int));
|
||||
static void reset_alarm __P((void));
|
||||
|
|
@ -113,7 +139,7 @@ static void
|
|||
reset_alarm ()
|
||||
{
|
||||
set_signal_handler (SIGALRM, old_alrm);
|
||||
alarm (0);
|
||||
falarm (0, 0);
|
||||
}
|
||||
|
||||
/* Read the value of the shell variables whose names follow.
|
||||
|
|
@ -130,18 +156,21 @@ read_builtin (list)
|
|||
int size, i, nr, pass_next, saw_escape, eof, opt, retval, code, print_ps2;
|
||||
int input_is_tty, input_is_pipe, unbuffered_read, skip_ctlesc, skip_ctlnul;
|
||||
int raw, edit, nchars, silent, have_timeout, fd;
|
||||
unsigned int tmout;
|
||||
unsigned int tmsec, tmusec;
|
||||
long ival, uval;
|
||||
intmax_t intval;
|
||||
char c;
|
||||
char *input_string, *orig_input_string, *ifs_chars, *prompt, *arrayname;
|
||||
char *e, *t, *t1, *ps2, *tofree;
|
||||
struct stat tsb;
|
||||
SHELL_VAR *var;
|
||||
TTYSTRUCT ttattrs, ttset;
|
||||
struct ttsave termsave;
|
||||
#if defined (ARRAY_VARS)
|
||||
WORD_LIST *alist;
|
||||
#endif
|
||||
#if defined (READLINE)
|
||||
char *rlbuf;
|
||||
char *rlbuf, *itext;
|
||||
int rlind;
|
||||
#endif
|
||||
|
||||
|
|
@ -153,7 +182,8 @@ read_builtin (list)
|
|||
USE_VAR(input_is_pipe);
|
||||
/* USE_VAR(raw); */
|
||||
USE_VAR(edit);
|
||||
USE_VAR(tmout);
|
||||
USE_VAR(tmsec);
|
||||
USE_VAR(tmusec);
|
||||
USE_VAR(nchars);
|
||||
USE_VAR(silent);
|
||||
USE_VAR(ifs_chars);
|
||||
|
|
@ -162,6 +192,7 @@ read_builtin (list)
|
|||
#if defined (READLINE)
|
||||
USE_VAR(rlbuf);
|
||||
USE_VAR(rlind);
|
||||
USE_VAR(itext);
|
||||
#endif
|
||||
USE_VAR(list);
|
||||
USE_VAR(ps2);
|
||||
|
|
@ -173,16 +204,16 @@ read_builtin (list)
|
|||
fd = 0; /* file descriptor to read from */
|
||||
|
||||
#if defined (READLINE)
|
||||
rlbuf = (char *)0;
|
||||
rlbuf = itext = (char *)0;
|
||||
rlind = 0;
|
||||
#endif
|
||||
|
||||
tmout = 0; /* no timeout */
|
||||
tmsec = tmusec = 0; /* no timeout */
|
||||
nr = nchars = input_is_tty = input_is_pipe = unbuffered_read = have_timeout = 0;
|
||||
delim = '\n'; /* read until newline */
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "ersa:d:n:p:t:u:")) != -1)
|
||||
while ((opt = internal_getopt (list, "ersa:d:i:n:p:t:u:")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
|
|
@ -198,6 +229,11 @@ read_builtin (list)
|
|||
case 'e':
|
||||
#if defined (READLINE)
|
||||
edit = 1;
|
||||
#endif
|
||||
break;
|
||||
case 'i':
|
||||
#if defined (READLINE)
|
||||
itext = list_optarg;
|
||||
#endif
|
||||
break;
|
||||
#if defined (ARRAY_VARS)
|
||||
|
|
@ -206,8 +242,8 @@ read_builtin (list)
|
|||
break;
|
||||
#endif
|
||||
case 't':
|
||||
code = legal_number (list_optarg, &intval);
|
||||
if (code == 0 || intval < 0 || intval != (unsigned int)intval)
|
||||
code = uconvert (list_optarg, &ival, &uval);
|
||||
if (code == 0 || ival < 0 || uval < 0)
|
||||
{
|
||||
builtin_error (_("%s: invalid timeout specification"), list_optarg);
|
||||
return (EXECUTION_FAILURE);
|
||||
|
|
@ -215,7 +251,8 @@ read_builtin (list)
|
|||
else
|
||||
{
|
||||
have_timeout = 1;
|
||||
tmout = intval;
|
||||
tmsec = ival;
|
||||
tmusec = uval;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
|
|
@ -256,24 +293,34 @@ read_builtin (list)
|
|||
/* `read -t 0 var' returns failure immediately. XXX - should it test
|
||||
whether input is available with select/FIONREAD, and fail if those
|
||||
are unavailable? */
|
||||
if (have_timeout && tmout == 0)
|
||||
if (have_timeout && tmsec == 0 && tmusec == 0)
|
||||
#if 0
|
||||
return (EXECUTION_FAILURE);
|
||||
#else
|
||||
return (input_avail (fd) ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
|
||||
#endif
|
||||
|
||||
/* IF IFS is unset, we use the default of " \t\n". */
|
||||
ifs_chars = getifs ();
|
||||
if (ifs_chars == 0) /* XXX - shouldn't happen */
|
||||
ifs_chars = "";
|
||||
for (skip_ctlesc = skip_ctlnul = 0, e = ifs_chars; *e; e++)
|
||||
skip_ctlesc |= *e == CTLESC, skip_ctlnul |= *e == CTLNUL;
|
||||
|
||||
input_string = (char *)xmalloc (size = 112); /* XXX was 128 */
|
||||
input_string[0] = '\0';
|
||||
|
||||
/* $TMOUT, if set, is the default timeout for read. */
|
||||
if (have_timeout == 0 && (e = get_string_value ("TMOUT")))
|
||||
{
|
||||
code = legal_number (e, &intval);
|
||||
if (code == 0 || intval < 0 || intval != (unsigned int)intval)
|
||||
tmout = 0;
|
||||
code = uconvert (e, &ival, &uval);
|
||||
if (code == 0 || ival < 0 || uval < 0)
|
||||
tmsec = tmusec = 0;
|
||||
else
|
||||
tmout = intval;
|
||||
{
|
||||
tmsec = ival;
|
||||
tmusec = uval;
|
||||
}
|
||||
}
|
||||
|
||||
begin_unwind_frame ("read_builtin");
|
||||
|
|
@ -296,6 +343,9 @@ read_builtin (list)
|
|||
if ((prompt || edit || silent) && input_is_tty == 0)
|
||||
{
|
||||
prompt = (char *)NULL;
|
||||
#if defined (READLINE)
|
||||
itext = (char *)NULL;
|
||||
#endif
|
||||
edit = silent = 0;
|
||||
}
|
||||
|
||||
|
|
@ -304,30 +354,30 @@ read_builtin (list)
|
|||
add_unwind_protect (xfree, rlbuf);
|
||||
#endif
|
||||
|
||||
if (prompt && edit == 0)
|
||||
{
|
||||
fprintf (stderr, "%s", prompt);
|
||||
fflush (stderr);
|
||||
}
|
||||
|
||||
pass_next = 0; /* Non-zero signifies last char was backslash. */
|
||||
saw_escape = 0; /* Non-zero signifies that we saw an escape char */
|
||||
|
||||
if (tmout > 0)
|
||||
if (tmsec > 0 || tmusec > 0)
|
||||
{
|
||||
/* Turn off the timeout if stdin is a regular file (e.g. from
|
||||
input redirection). */
|
||||
if ((fstat (fd, &tsb) < 0) || S_ISREG (tsb.st_mode))
|
||||
tmout = 0;
|
||||
tmsec = tmusec = 0;
|
||||
}
|
||||
|
||||
if (tmout > 0)
|
||||
if (tmsec > 0 || tmusec > 0)
|
||||
{
|
||||
code = setjmp (alrmbuf);
|
||||
if (code)
|
||||
{
|
||||
#if 0
|
||||
run_unwind_frame ("read_builtin");
|
||||
return (EXECUTION_FAILURE);
|
||||
#else
|
||||
input_string[i] = '\0'; /* make sure it's terminated */
|
||||
retval = 128+SIGALRM;;
|
||||
goto assign_vars;
|
||||
#endif
|
||||
}
|
||||
old_alrm = set_signal_handler (SIGALRM, sigalrm);
|
||||
add_unwind_protect (reset_alarm, (char *)NULL);
|
||||
|
|
@ -335,7 +385,7 @@ read_builtin (list)
|
|||
if (edit)
|
||||
add_unwind_protect (reset_attempted_completion_function, (char *)NULL);
|
||||
#endif
|
||||
alarm (tmout);
|
||||
falarm (tmsec, tmusec);
|
||||
}
|
||||
|
||||
/* If we've been asked to read only NCHARS chars, or we're using some
|
||||
|
|
@ -361,29 +411,46 @@ read_builtin (list)
|
|||
#endif
|
||||
if (input_is_tty)
|
||||
{
|
||||
ttsave ();
|
||||
/* ttsave() */
|
||||
termsave.fd = fd;
|
||||
ttgetattr (fd, &ttattrs);
|
||||
termsave.attrs = &ttattrs;
|
||||
|
||||
ttset = ttattrs;
|
||||
if (silent)
|
||||
ttcbreak ();
|
||||
ttfd_cbreak (fd, &ttset); /* ttcbreak () */
|
||||
else
|
||||
ttonechar ();
|
||||
add_unwind_protect ((Function *)ttrestore, (char *)NULL);
|
||||
ttfd_onechar (fd, &ttset); /* ttonechar () */
|
||||
add_unwind_protect ((Function *)ttyrestore, (char *)&termsave);
|
||||
}
|
||||
}
|
||||
else if (silent) /* turn off echo but leave term in canonical mode */
|
||||
{
|
||||
ttsave ();
|
||||
ttnoecho ();
|
||||
add_unwind_protect ((Function *)ttrestore, (char *)NULL);
|
||||
/* ttsave (); */
|
||||
termsave.fd = fd;
|
||||
ttgetattr (fd, &ttattrs);
|
||||
termsave.attrs = &ttattrs;
|
||||
|
||||
ttset = ttattrs;
|
||||
ttfd_noecho (fd, &ttset); /* ttnoecho (); */
|
||||
|
||||
add_unwind_protect ((Function *)ttyrestore, (char *)&termsave);
|
||||
}
|
||||
|
||||
/* This *must* be the top unwind-protect on the stack, so the manipulation
|
||||
of the unwind-protect stack after the realloc() works right. */
|
||||
add_unwind_protect (xfree, input_string);
|
||||
interrupt_immediately++;
|
||||
terminate_immediately = 1;
|
||||
terminate_immediately++;
|
||||
|
||||
unbuffered_read = (nchars > 0) || (delim != '\n') || input_is_pipe;
|
||||
|
||||
if (prompt && edit == 0)
|
||||
{
|
||||
fprintf (stderr, "%s", prompt);
|
||||
fflush (stderr);
|
||||
}
|
||||
|
||||
#if defined (__CYGWIN__) && defined (O_TEXT)
|
||||
setmode (0, O_TEXT);
|
||||
#endif
|
||||
|
|
@ -401,7 +468,7 @@ read_builtin (list)
|
|||
}
|
||||
if (rlbuf == 0)
|
||||
{
|
||||
rlbuf = edit_line (prompt ? prompt : "");
|
||||
rlbuf = edit_line (prompt ? prompt : "", itext);
|
||||
rlind = 0;
|
||||
}
|
||||
if (rlbuf == 0)
|
||||
|
|
@ -439,7 +506,7 @@ read_builtin (list)
|
|||
}
|
||||
#endif
|
||||
|
||||
if (i + 2 >= size)
|
||||
if (i + 4 >= size) /* XXX was i + 2; use i + 4 for multibyte/read_mbchar */
|
||||
{
|
||||
input_string = (char *)xrealloc (input_string, size += 128);
|
||||
remove_unwind_protect ();
|
||||
|
|
@ -462,18 +529,22 @@ read_builtin (list)
|
|||
continue;
|
||||
}
|
||||
|
||||
/* This may cause problems if IFS contains CTLESC */
|
||||
if (c == '\\' && raw == 0)
|
||||
{
|
||||
pass_next++;
|
||||
saw_escape++;
|
||||
input_string[i++] = CTLESC;
|
||||
if (skip_ctlesc == 0)
|
||||
{
|
||||
saw_escape++;
|
||||
input_string[i++] = CTLESC;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((unsigned char)c == delim)
|
||||
break;
|
||||
|
||||
if (c == CTLESC || c == CTLNUL)
|
||||
if ((skip_ctlesc == 0 && c == CTLESC) || (skip_ctlnul == 0 && c == CTLNUL))
|
||||
{
|
||||
saw_escape++;
|
||||
input_string[i++] = CTLESC;
|
||||
|
|
@ -481,6 +552,15 @@ read_builtin (list)
|
|||
|
||||
add_char:
|
||||
input_string[i++] = c;
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (nchars > 0 && MB_CUR_MAX > 1)
|
||||
{
|
||||
input_string[i] = '\0'; /* for simplicity and debugging */
|
||||
i += read_mbchar (fd, input_string, i, c, unbuffered_read);
|
||||
}
|
||||
#endif
|
||||
|
||||
nr++;
|
||||
|
||||
if (nchars > 0 && nr >= nchars)
|
||||
|
|
@ -497,7 +577,7 @@ add_char:
|
|||
}
|
||||
#endif
|
||||
|
||||
if (tmout > 0)
|
||||
if (tmsec > 0 || tmusec > 0)
|
||||
reset_alarm ();
|
||||
|
||||
if (nchars > 0 || delim != '\n')
|
||||
|
|
@ -513,20 +593,22 @@ add_char:
|
|||
else
|
||||
#endif
|
||||
if (input_is_tty)
|
||||
ttrestore ();
|
||||
ttyrestore (&termsave);
|
||||
}
|
||||
else if (silent)
|
||||
ttrestore ();
|
||||
ttyrestore (&termsave);
|
||||
|
||||
if (unbuffered_read == 0)
|
||||
zsyncfd (fd);
|
||||
|
||||
interrupt_immediately--;
|
||||
terminate_immediately = 0;
|
||||
terminate_immediately--;
|
||||
discard_unwind_frame ("read_builtin");
|
||||
|
||||
retval = eof ? EXECUTION_FAILURE : EXECUTION_SUCCESS;
|
||||
|
||||
assign_vars:
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
/* If -a was given, take the string read, break it into a list of words,
|
||||
an assign them to `arrayname' in turn. */
|
||||
|
|
@ -603,7 +685,6 @@ add_char:
|
|||
for (t = input_string; ifs_chars && *ifs_chars && spctabnl(*t) && isifs(*t); t++)
|
||||
;
|
||||
input_string = t;
|
||||
|
||||
for (; list->next; list = list->next)
|
||||
{
|
||||
varname = list->word->word;
|
||||
|
|
@ -718,8 +799,66 @@ bind_read_variable (name, value)
|
|||
#endif /* !ARRAY_VARS */
|
||||
}
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
static int
|
||||
read_mbchar (fd, string, ind, ch, unbuffered)
|
||||
int fd;
|
||||
char *string;
|
||||
int ind, ch, unbuffered;
|
||||
{
|
||||
char mbchar[MB_LEN_MAX + 1];
|
||||
int i, n, r;
|
||||
char c;
|
||||
size_t ret;
|
||||
mbstate_t ps, ps_back;
|
||||
wchar_t wc;
|
||||
|
||||
memset (&ps, '\0', sizeof (mbstate_t));
|
||||
memset (&ps_back, '\0', sizeof (mbstate_t));
|
||||
|
||||
mbchar[0] = ch;
|
||||
i = 1;
|
||||
for (n = 0; n <= MB_LEN_MAX; n++)
|
||||
{
|
||||
ps_back = ps;
|
||||
ret = mbrtowc (&wc, mbchar, i, &ps);
|
||||
if (ret == (size_t)-2)
|
||||
{
|
||||
ps = ps_back;
|
||||
if (unbuffered)
|
||||
r = zread (fd, &c, 1);
|
||||
else
|
||||
r = zreadc (fd, &c);
|
||||
if (r < 0)
|
||||
goto mbchar_return;
|
||||
mbchar[i++] = c;
|
||||
continue;
|
||||
}
|
||||
else if (ret == (size_t)-1 || ret == (size_t)0 || ret > (size_t)0)
|
||||
break;
|
||||
}
|
||||
|
||||
mbchar_return:
|
||||
if (i > 1) /* read a multibyte char */
|
||||
/* mbchar[0] is already string[ind-1] */
|
||||
for (r = 1; r < i; r++)
|
||||
string[ind+r-1] = mbchar[r];
|
||||
return i - 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
ttyrestore (ttp)
|
||||
struct ttsave *ttp;
|
||||
{
|
||||
ttsetattr (ttp->fd, ttp->attrs);
|
||||
}
|
||||
|
||||
#if defined (READLINE)
|
||||
static rl_completion_func_t *old_attempted_completion_function = 0;
|
||||
static rl_hook_func_t *old_startup_hook;
|
||||
static char *deftext;
|
||||
|
||||
static void
|
||||
reset_attempted_completion_function (cp)
|
||||
|
|
@ -729,9 +868,28 @@ reset_attempted_completion_function (cp)
|
|||
rl_attempted_completion_function = old_attempted_completion_function;
|
||||
}
|
||||
|
||||
static int
|
||||
set_itext ()
|
||||
{
|
||||
int r1, r2;
|
||||
|
||||
r1 = r2 = 0;
|
||||
if (old_startup_hook)
|
||||
r1 = (*old_startup_hook) ();
|
||||
if (deftext)
|
||||
{
|
||||
r2 = rl_insert_text (deftext);
|
||||
deftext = (char *)NULL;
|
||||
rl_startup_hook = old_startup_hook;
|
||||
old_startup_hook = (rl_hook_func_t *)NULL;
|
||||
}
|
||||
return (r1 || r2);
|
||||
}
|
||||
|
||||
static char *
|
||||
edit_line (p)
|
||||
edit_line (p, itext)
|
||||
char *p;
|
||||
char *itext;
|
||||
{
|
||||
char *ret;
|
||||
int len;
|
||||
|
|
@ -741,6 +899,12 @@ edit_line (p)
|
|||
|
||||
old_attempted_completion_function = rl_attempted_completion_function;
|
||||
rl_attempted_completion_function = (rl_completion_func_t *)NULL;
|
||||
if (itext)
|
||||
{
|
||||
old_startup_hook = rl_startup_hook;
|
||||
rl_startup_hook = set_itext;
|
||||
deftext = itext;
|
||||
}
|
||||
ret = readline (p);
|
||||
rl_attempted_completion_function = old_attempted_completion_function;
|
||||
old_attempted_completion_function = (rl_completion_func_t *)NULL;
|
||||
|
|
|
|||
|
|
@ -2,35 +2,41 @@ This file is reserved.def, in which the shell reserved words are defined.
|
|||
It has no direct C file production, but defines builtins for the Bash
|
||||
builtin help command.
|
||||
|
||||
Copyright (C) 1987-2006 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/>.
|
||||
|
||||
$BUILTIN for
|
||||
$SHORT_DOC for NAME [in WORDS ... ;] do COMMANDS; done
|
||||
$SHORT_DOC for NAME [in WORDS ... ] ; do COMMANDS; done
|
||||
Execute commands for each member in a list.
|
||||
|
||||
The `for' loop executes a sequence of commands for each member in a
|
||||
list of items. If `in WORDS ...;' is not present, then `in "$@"' is
|
||||
assumed. For each element in WORDS, NAME is set to that element, and
|
||||
the COMMANDS are executed.
|
||||
|
||||
Exit Status:
|
||||
Returns the status of the last command executed.
|
||||
$END
|
||||
|
||||
$BUILTIN for ((
|
||||
$DOCNAME arith_for
|
||||
$SHORT_DOC for (( exp1; exp2; exp3 )); do COMMANDS; done
|
||||
Arithmetic for loop.
|
||||
|
||||
Equivalent to
|
||||
(( EXP1 ))
|
||||
while (( EXP2 )); do
|
||||
|
|
@ -39,10 +45,15 @@ Equivalent to
|
|||
done
|
||||
EXP1, EXP2, and EXP3 are arithmetic expressions. If any expression is
|
||||
omitted, it behaves as if it evaluates to 1.
|
||||
|
||||
Exit Status:
|
||||
Returns the status of the last command executed.
|
||||
$END
|
||||
|
||||
$BUILTIN select
|
||||
$SHORT_DOC select NAME [in WORDS ... ;] do COMMANDS; done
|
||||
Select words from a list and execute commands.
|
||||
|
||||
The WORDS are expanded, generating a list of words. The
|
||||
set of expanded words is printed on the standard error, each
|
||||
preceded by a number. If `in WORDS' is not present, `in "$@"'
|
||||
|
|
@ -54,25 +65,42 @@ redisplayed. If EOF is read, the command completes. Any other
|
|||
value read causes NAME to be set to null. The line read is saved
|
||||
in the variable REPLY. COMMANDS are executed after each selection
|
||||
until a break command is executed.
|
||||
|
||||
Exit Status:
|
||||
Returns the status of the last command executed.
|
||||
$END
|
||||
|
||||
$BUILTIN time
|
||||
$SHORT_DOC time [-p] PIPELINE
|
||||
$SHORT_DOC time [-p] pipeline
|
||||
Report time consumed by pipeline's execution.
|
||||
|
||||
Execute PIPELINE and print a summary of the real time, user CPU time,
|
||||
and system CPU time spent executing PIPELINE when it terminates.
|
||||
The return status is the return status of PIPELINE. The `-p' option
|
||||
prints the timing summary in a slightly different format. This uses
|
||||
the value of the TIMEFORMAT variable as the output format.
|
||||
|
||||
Options:
|
||||
-p print the timing summary in the portable Posix format
|
||||
|
||||
The value of the TIMEFORMAT variable is used as the output format.
|
||||
|
||||
Exit Status:
|
||||
The return status is the return status of PIPELINE.
|
||||
$END
|
||||
|
||||
$BUILTIN case
|
||||
$SHORT_DOC case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac
|
||||
Execute commands based on pattern matching.
|
||||
|
||||
Selectively execute COMMANDS based upon WORD matching PATTERN. The
|
||||
`|' is used to separate multiple patterns.
|
||||
|
||||
Exit Status:
|
||||
Returns the status of the last command executed.
|
||||
$END
|
||||
|
||||
$BUILTIN if
|
||||
$SHORT_DOC if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
|
||||
Execute commands based on conditional.
|
||||
|
||||
The `if COMMANDS' list is executed. If its exit status is zero, then the
|
||||
`then COMMANDS' list is executed. Otherwise, each `elif COMMANDS' list is
|
||||
executed in turn, and if its exit status is zero, the corresponding
|
||||
|
|
@ -80,75 +108,119 @@ executed in turn, and if its exit status is zero, the corresponding
|
|||
the `else COMMANDS' list is executed, if present. The exit status of the
|
||||
entire construct is the exit status of the last command executed, or zero
|
||||
if no condition tested true.
|
||||
|
||||
Exit Status:
|
||||
Returns the status of the last command executed.
|
||||
$END
|
||||
|
||||
$BUILTIN while
|
||||
$SHORT_DOC while COMMANDS; do COMMANDS; done
|
||||
Execute commands as long as a test succeeds.
|
||||
|
||||
Expand and execute COMMANDS as long as the final command in the
|
||||
`while' COMMANDS has an exit status of zero.
|
||||
|
||||
Exit Status:
|
||||
Returns the status of the last command executed.
|
||||
$END
|
||||
|
||||
$BUILTIN until
|
||||
$SHORT_DOC until COMMANDS; do COMMANDS; done
|
||||
Execute commands as long as a test does not succeed.
|
||||
|
||||
Expand and execute COMMANDS as long as the final command in the
|
||||
`until' COMMANDS has an exit status which is not zero.
|
||||
|
||||
Exit Status:
|
||||
Returns the status of the last command executed.
|
||||
$END
|
||||
|
||||
$BUILTIN function
|
||||
$SHORT_DOC function NAME { COMMANDS ; } or NAME () { COMMANDS ; }
|
||||
Create a simple command invoked by NAME which runs COMMANDS.
|
||||
Arguments on the command line along with NAME are passed to the
|
||||
function as $0 .. $n.
|
||||
$SHORT_DOC function name { COMMANDS ; } or name () { COMMANDS ; }
|
||||
Define shell function.
|
||||
|
||||
Create a shell function named NAME. When invoked as a simple command,
|
||||
NAME runs COMMANDs in the calling shell's context. When NAME is invoked,
|
||||
the arguments are passed to the function as $1...$n, and the function's
|
||||
name is in $FUNCNAME.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless NAME is readonly.
|
||||
$END
|
||||
|
||||
$BUILTIN { ... }
|
||||
$DOCNAME grouping_braces
|
||||
$SHORT_DOC { COMMANDS ; }
|
||||
Group commands as a unit.
|
||||
|
||||
Run a set of commands in a group. This is one way to redirect an
|
||||
entire set of commands.
|
||||
|
||||
Exit Status:
|
||||
Returns the status of the last command executed.
|
||||
$END
|
||||
|
||||
$BUILTIN %
|
||||
$DOCNAME fg_percent
|
||||
$SHORT_DOC JOB_SPEC [&]
|
||||
$SHORT_DOC job_spec [&]
|
||||
Resume job in foreground.
|
||||
|
||||
Equivalent to the JOB_SPEC argument to the `fg' command. Resume a
|
||||
stopped or background job. JOB_SPEC can specify either a job name
|
||||
or a job number. Following JOB_SPEC with a `&' places the job in
|
||||
the background, as if the job specification had been supplied as an
|
||||
argument to `bg'.
|
||||
|
||||
Exit Status:
|
||||
Returns the status of the resumed job.
|
||||
$END
|
||||
|
||||
$BUILTIN (( ... ))
|
||||
$DOCNAME arith
|
||||
$SHORT_DOC (( expression ))
|
||||
Evaluate arithmetic expression.
|
||||
|
||||
The EXPRESSION is evaluated according to the rules for arithmetic
|
||||
evaluation. Equivalent to "let EXPRESSION".
|
||||
|
||||
Exit Status:
|
||||
Returns 1 if EXPRESSION evaluates to 0; returns 0 otherwise.
|
||||
$END
|
||||
|
||||
$BUILTIN [[ ... ]]
|
||||
$DOCNAME conditional
|
||||
$SHORT_DOC [[ expression ]]
|
||||
Execute conditional command.
|
||||
|
||||
Returns a status of 0 or 1 depending on the evaluation of the conditional
|
||||
expression EXPRESSION. Expressions are composed of the same primaries used
|
||||
by the `test' builtin, and may be combined using the following operators
|
||||
by the `test' builtin, and may be combined using the following operators:
|
||||
|
||||
( EXPRESSION ) Returns the value of EXPRESSION
|
||||
! EXPRESSION True if EXPRESSION is false; else false
|
||||
EXPR1 && EXPR2 True if both EXPR1 and EXPR2 are true; else false
|
||||
EXPR1 || EXPR2 True if either EXPR1 or EXPR2 is true; else false
|
||||
( EXPRESSION ) Returns the value of EXPRESSION
|
||||
! EXPRESSION True if EXPRESSION is false; else false
|
||||
EXPR1 && EXPR2 True if both EXPR1 and EXPR2 are true; else false
|
||||
EXPR1 || EXPR2 True if either EXPR1 or EXPR2 is true; else false
|
||||
|
||||
When the `==' and `!=' operators are used, the string to the right of the
|
||||
operator is used as a pattern and pattern matching is performed. The
|
||||
&& and || operators do not evaluate EXPR2 if EXPR1 is sufficient to
|
||||
When the `==' and `!=' operators are used, the string to the right of
|
||||
the operator is used as a pattern and pattern matching is performed.
|
||||
When the `=~' operator is used, the string to the right of the operator
|
||||
is matched as a regular expression.
|
||||
|
||||
The && and || operators do not evaluate EXPR2 if EXPR1 is sufficient to
|
||||
determine the expression's value.
|
||||
|
||||
Exit Status:
|
||||
0 or 1 depending on value of EXPRESSION.
|
||||
$END
|
||||
|
||||
$BUILTIN variables
|
||||
$DOCNAME variable_help
|
||||
$SHORT_DOC variables - Some variable names and meanings
|
||||
$SHORT_DOC variables - Names and meanings of some shell variables
|
||||
Common shell variable names and usage.
|
||||
|
||||
BASH_VERSION Version information for this Bash.
|
||||
CDPATH A colon-separated list of directories to search
|
||||
for directries given as arguments to `cd'.
|
||||
for directories given as arguments to `cd'.
|
||||
GLOBIGNORE A colon-separated list of patterns describing filenames to
|
||||
be ignored by pathname expansion.
|
||||
#if defined (HISTORY)
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
This file is return.def, from which is created return.c.
|
||||
It implements the builtin "return" 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 return.c
|
||||
|
||||
|
|
@ -25,8 +24,14 @@ $BUILTIN return
|
|||
|
||||
$FUNCTION return_builtin
|
||||
$SHORT_DOC return [n]
|
||||
Causes a function to exit with the return value specified by N. If N
|
||||
is omitted, the return status is that of the last command.
|
||||
Return from a shell function.
|
||||
|
||||
Causes a function or sourced script to exit with the return value
|
||||
specified by N. If N is omitted, the return status is that of the
|
||||
last command executed within the function or script.
|
||||
|
||||
Exit Status:
|
||||
Returns N, or failure if the shell is not executing a function or script.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -42,6 +47,7 @@ $END
|
|||
|
||||
#include "../shell.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
extern int last_command_exit_value;
|
||||
extern int subshell_environment;
|
||||
|
|
@ -54,6 +60,10 @@ int
|
|||
return_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
if (no_options (list))
|
||||
return (EX_USAGE);
|
||||
list = loptend; /* skip over possible `--' */
|
||||
|
||||
return_catch_value = get_exitstat (list);
|
||||
|
||||
if (return_catch_flag)
|
||||
|
|
|
|||
202
builtins/set.def
202
builtins/set.def
|
|
@ -1,23 +1,22 @@
|
|||
This file is set.def, from which is created set.c.
|
||||
It implements the "set" and "unset" builtins in Bash.
|
||||
|
||||
Copyright (C) 1987-2004 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 set.c
|
||||
|
||||
|
|
@ -60,87 +59,96 @@ extern int no_line_editing;
|
|||
|
||||
$BUILTIN set
|
||||
$FUNCTION set_builtin
|
||||
$SHORT_DOC set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
|
||||
-a Mark variables which are modified or created for export.
|
||||
-b Notify of job termination immediately.
|
||||
-e Exit immediately if a command exits with a non-zero status.
|
||||
-f Disable file name generation (globbing).
|
||||
-h Remember the location of commands as they are looked up.
|
||||
-k All assignment arguments are placed in the environment for a
|
||||
command, not just those that precede the command name.
|
||||
-m Job control is enabled.
|
||||
-n Read commands but do not execute them.
|
||||
-o option-name
|
||||
Set the variable corresponding to option-name:
|
||||
allexport same as -a
|
||||
braceexpand same as -B
|
||||
$SHORT_DOC set [--abefhkmnptuvxBCHP] [-o option-name] [arg ...]
|
||||
Set or unset values of shell options and positional parameters.
|
||||
|
||||
Change the value of shell attributes and positional parameters, or
|
||||
display the names and values of shell variables.
|
||||
|
||||
Options:
|
||||
-a Mark variables which are modified or created for export.
|
||||
-b Notify of job termination immediately.
|
||||
-e Exit immediately if a command exits with a non-zero status.
|
||||
-f Disable file name generation (globbing).
|
||||
-h Remember the location of commands as they are looked up.
|
||||
-k All assignment arguments are placed in the environment for a
|
||||
command, not just those that precede the command name.
|
||||
-m Job control is enabled.
|
||||
-n Read commands but do not execute them.
|
||||
-o option-name
|
||||
Set the variable corresponding to option-name:
|
||||
allexport same as -a
|
||||
braceexpand same as -B
|
||||
#if defined (READLINE)
|
||||
emacs use an emacs-style line editing interface
|
||||
emacs use an emacs-style line editing interface
|
||||
#endif /* READLINE */
|
||||
errexit same as -e
|
||||
errtrace same as -E
|
||||
functrace same as -T
|
||||
hashall same as -h
|
||||
errexit same as -e
|
||||
errtrace same as -E
|
||||
functrace same as -T
|
||||
hashall same as -h
|
||||
#if defined (BANG_HISTORY)
|
||||
histexpand same as -H
|
||||
histexpand same as -H
|
||||
#endif /* BANG_HISTORY */
|
||||
#if defined (HISTORY)
|
||||
history enable command history
|
||||
history enable command history
|
||||
#endif
|
||||
ignoreeof the shell will not exit upon reading EOF
|
||||
interactive-comments
|
||||
allow comments to appear in interactive commands
|
||||
keyword same as -k
|
||||
monitor same as -m
|
||||
noclobber same as -C
|
||||
noexec same as -n
|
||||
noglob same as -f
|
||||
nolog currently accepted but ignored
|
||||
notify same as -b
|
||||
nounset same as -u
|
||||
onecmd same as -t
|
||||
physical same as -P
|
||||
pipefail the return value of a pipeline is the status of
|
||||
the last command to exit with a non-zero status,
|
||||
or zero if no command exited with a non-zero status
|
||||
posix change the behavior of bash where the default
|
||||
operation differs from the 1003.2 standard to
|
||||
match the standard
|
||||
privileged same as -p
|
||||
verbose same as -v
|
||||
ignoreeof the shell will not exit upon reading EOF
|
||||
interactive-comments
|
||||
allow comments to appear in interactive commands
|
||||
keyword same as -k
|
||||
monitor same as -m
|
||||
noclobber same as -C
|
||||
noexec same as -n
|
||||
noglob same as -f
|
||||
nolog currently accepted but ignored
|
||||
notify same as -b
|
||||
nounset same as -u
|
||||
onecmd same as -t
|
||||
physical same as -P
|
||||
pipefail the return value of a pipeline is the status of
|
||||
the last command to exit with a non-zero status,
|
||||
or zero if no command exited with a non-zero status
|
||||
posix change the behavior of bash where the default
|
||||
operation differs from the Posix standard to
|
||||
match the standard
|
||||
privileged same as -p
|
||||
verbose same as -v
|
||||
#if defined (READLINE)
|
||||
vi use a vi-style line editing interface
|
||||
vi use a vi-style line editing interface
|
||||
#endif /* READLINE */
|
||||
xtrace same as -x
|
||||
-p Turned on whenever the real and effective user ids do not match.
|
||||
Disables processing of the $ENV file and importing of shell
|
||||
functions. Turning this option off causes the effective uid and
|
||||
gid to be set to the real uid and gid.
|
||||
-t Exit after reading and executing one command.
|
||||
-u Treat unset variables as an error when substituting.
|
||||
-v Print shell input lines as they are read.
|
||||
-x Print commands and their arguments as they are executed.
|
||||
xtrace same as -x
|
||||
-p Turned on whenever the real and effective user ids do not match.
|
||||
Disables processing of the $ENV file and importing of shell
|
||||
functions. Turning this option off causes the effective uid and
|
||||
gid to be set to the real uid and gid.
|
||||
-t Exit after reading and executing one command.
|
||||
-u Treat unset variables as an error when substituting.
|
||||
-v Print shell input lines as they are read.
|
||||
-x Print commands and their arguments as they are executed.
|
||||
#if defined (BRACE_EXPANSION)
|
||||
-B the shell will perform brace expansion
|
||||
-B the shell will perform brace expansion
|
||||
#endif /* BRACE_EXPANSION */
|
||||
-C If set, disallow existing regular files to be overwritten
|
||||
by redirection of output.
|
||||
-E If set, the ERR trap is inherited by shell functions.
|
||||
-C If set, disallow existing regular files to be overwritten
|
||||
by redirection of output.
|
||||
-E If set, the ERR trap is inherited by shell functions.
|
||||
#if defined (BANG_HISTORY)
|
||||
-H Enable ! style history substitution. This flag is on
|
||||
by default when the shell is interactive.
|
||||
-H Enable ! style history substitution. This flag is on
|
||||
by default when the shell is interactive.
|
||||
#endif /* BANG_HISTORY */
|
||||
-P If set, do not follow symbolic links when executing commands
|
||||
such as cd which change the current directory.
|
||||
-T If set, the DEBUG trap is inherited by shell functions.
|
||||
- Assign any remaining arguments to the positional parameters.
|
||||
The -x and -v options are turned off.
|
||||
-P If set, do not follow symbolic links when executing commands
|
||||
such as cd which change the current directory.
|
||||
-T If set, the DEBUG trap is inherited by shell functions.
|
||||
- Assign any remaining arguments to the positional parameters.
|
||||
The -x and -v options are turned off.
|
||||
|
||||
Using + rather than - causes these flags to be turned off. The
|
||||
flags can also be used upon invocation of the shell. The current
|
||||
set of flags may be found in $-. The remaining n ARGs are positional
|
||||
parameters and are assigned, in order, to $1, $2, .. $n. If no
|
||||
ARGs are given, all shell variables are printed.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is given.
|
||||
$END
|
||||
|
||||
typedef int setopt_set_func_t __P((int, char *));
|
||||
|
|
@ -161,13 +169,13 @@ static int get_edit_mode __P((char *));
|
|||
static int bash_set_history __P((int, char *));
|
||||
#endif
|
||||
|
||||
static char *on = "on";
|
||||
static char *off = "off";
|
||||
static const char * const on = "on";
|
||||
static const char * const off = "off";
|
||||
|
||||
/* A struct used to match long options for set -o to the corresponding
|
||||
option letter or internal variable. The functions can be called to
|
||||
dynamically generate values. */
|
||||
struct {
|
||||
const struct {
|
||||
char *name;
|
||||
int letter;
|
||||
int *variable;
|
||||
|
|
@ -426,7 +434,7 @@ set_minus_o_option (on_or_off, option_name)
|
|||
}
|
||||
|
||||
sh_invalidoptname (option_name);
|
||||
return (EXECUTION_FAILURE);
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -549,7 +557,7 @@ initialize_shell_options (no_shellopts)
|
|||
/* set up any shell options we may have inherited. */
|
||||
if (var && imported_p (var))
|
||||
{
|
||||
temp = (array_p (var)) ? (char *)NULL : savestring (value_cell (var));
|
||||
temp = (array_p (var) || assoc_p (var)) ? (char *)NULL : savestring (value_cell (var));
|
||||
if (temp)
|
||||
{
|
||||
parse_shellopts (temp);
|
||||
|
|
@ -581,17 +589,18 @@ int
|
|||
set_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int on_or_off, flag_name, force_assignment, opts_changed;
|
||||
int on_or_off, flag_name, force_assignment, opts_changed, rv, r;
|
||||
register char *arg;
|
||||
char s[3];
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
print_all_shell_variables ();
|
||||
return (EXECUTION_SUCCESS);
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
/* Check validity of flag arguments. */
|
||||
rv = EXECUTION_SUCCESS;
|
||||
reset_internal_getopt ();
|
||||
while ((flag_name = internal_getopt (list, optflags)) != -1)
|
||||
{
|
||||
|
|
@ -654,6 +663,7 @@ set_builtin (list)
|
|||
if (opt == 0)
|
||||
{
|
||||
list_minus_o_opts (-1, (on_or_off == '+'));
|
||||
rv = sh_chkwrite (rv);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -668,10 +678,10 @@ set_builtin (list)
|
|||
list = list->next; /* Skip over option name. */
|
||||
|
||||
opts_changed = 1;
|
||||
if (set_minus_o_option (on_or_off, option_name) != EXECUTION_SUCCESS)
|
||||
if ((r = set_minus_o_option (on_or_off, option_name)) != EXECUTION_SUCCESS)
|
||||
{
|
||||
set_shellopts ();
|
||||
return (EXECUTION_FAILURE);
|
||||
return (r);
|
||||
}
|
||||
}
|
||||
else if (change_flag (flag_name, on_or_off) == FLAG_ERROR)
|
||||
|
|
@ -700,17 +710,27 @@ set_builtin (list)
|
|||
/* Set up new value of $SHELLOPTS */
|
||||
if (opts_changed)
|
||||
set_shellopts ();
|
||||
return (EXECUTION_SUCCESS);
|
||||
return (rv);
|
||||
}
|
||||
|
||||
$BUILTIN unset
|
||||
$FUNCTION unset_builtin
|
||||
$SHORT_DOC unset [-f] [-v] [name ...]
|
||||
For each NAME, remove the corresponding variable or function. Given
|
||||
the `-v', unset will only act on variables. Given the `-f' flag,
|
||||
unset will only act on functions. With neither flag, unset first
|
||||
tries to unset a variable, and if that fails, then tries to unset a
|
||||
function. Some variables cannot be unset; also see readonly.
|
||||
Unset values and attributes of shell variables and functions.
|
||||
|
||||
For each NAME, remove the corresponding variable or function.
|
||||
|
||||
Options:
|
||||
-f treat each NAME as a shell function
|
||||
-v treat each NAME as a shell variable
|
||||
|
||||
Without options, unset first tries to unset a variable, and if that fails,
|
||||
tries to unset a function.
|
||||
|
||||
Some variables cannot be unset; also see `readonly'.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is given or a NAME is read-only.
|
||||
$END
|
||||
|
||||
#define NEXT_VARIABLE() any_failed++; list = list->next; continue;
|
||||
|
|
@ -798,7 +818,7 @@ unset_builtin (list)
|
|||
#if defined (ARRAY_VARS)
|
||||
if (var && unset_array)
|
||||
{
|
||||
if (array_p (var) == 0)
|
||||
if (array_p (var) == 0 && assoc_p (var) == 0)
|
||||
{
|
||||
builtin_error (_("%s: not an array variable"), name);
|
||||
NEXT_VARIABLE ();
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
This file is setattr.def, from which is created setattr.c.
|
||||
It implements the builtins "export" and "readonly", in Bash.
|
||||
|
||||
Copyright (C) 1987-2004 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 setattr.c
|
||||
|
||||
|
|
@ -52,14 +51,21 @@ extern int declare_builtin __P((WORD_LIST *));
|
|||
|
||||
$BUILTIN export
|
||||
$FUNCTION export_builtin
|
||||
$SHORT_DOC export [-nf] [name[=value] ...] or export -p
|
||||
NAMEs are marked for automatic export to the environment of
|
||||
subsequently executed commands. If the -f option is given,
|
||||
the NAMEs refer to functions. If no NAMEs are given, or if `-p'
|
||||
is given, a list of all names that are exported in this shell is
|
||||
printed. An argument of `-n' says to remove the export property
|
||||
from subsequent NAMEs. An argument of `--' disables further option
|
||||
processing.
|
||||
$SHORT_DOC export [-fn] [name[=value] ...] or export -p
|
||||
Set export attribute for shell variables.
|
||||
|
||||
Marks each NAME for automatic export to the environment of subsequently
|
||||
executed commands. If VALUE is supplied, assign VALUE before exporting.
|
||||
|
||||
Options:
|
||||
-f refer to shell functions
|
||||
-n remove the export property from each NAME
|
||||
-p display a list of all exported variables and functions
|
||||
|
||||
An argument of `--' disables further option processing.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is given or NAME is invalid.
|
||||
$END
|
||||
|
||||
/* For each variable name in LIST, make that variable appear in the
|
||||
|
|
@ -77,13 +83,22 @@ export_builtin (list)
|
|||
$BUILTIN readonly
|
||||
$FUNCTION readonly_builtin
|
||||
$SHORT_DOC readonly [-af] [name[=value] ...] or readonly -p
|
||||
The given NAMEs are marked readonly and the values of these NAMEs may
|
||||
not be changed by subsequent assignment. If the -f option is given,
|
||||
then functions corresponding to the NAMEs are so marked. If no
|
||||
arguments are given, or if `-p' is given, a list of all readonly names
|
||||
is printed. The `-a' option means to treat each NAME as
|
||||
an array variable. An argument of `--' disables further option
|
||||
processing.
|
||||
Mark shell variables as unchangeable.
|
||||
|
||||
Mark each NAME as read-only; the values of these NAMEs may not be
|
||||
changed by subsequent assignment. If VALUE is supplied, assign VALUE
|
||||
before marking as read-only.
|
||||
|
||||
Options:
|
||||
-a refer to indexed array variables
|
||||
-A refer to associative array variables
|
||||
-f refer to shell functions
|
||||
-p display a list of all readonly variables and functions
|
||||
|
||||
An argument of `--' disables further option processing.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is given or NAME is invalid.
|
||||
$END
|
||||
|
||||
/* For each variable name in LIST, make that variable readonly. Given an
|
||||
|
|
@ -96,7 +111,7 @@ readonly_builtin (list)
|
|||
}
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
# define ATTROPTS "afnp"
|
||||
# define ATTROPTS "aAfnp"
|
||||
#else
|
||||
# define ATTROPTS "fnp"
|
||||
#endif
|
||||
|
|
@ -110,7 +125,8 @@ set_or_show_attributes (list, attribute, nodefs)
|
|||
int attribute, nodefs;
|
||||
{
|
||||
register SHELL_VAR *var;
|
||||
int assign, undo, functions_only, arrays_only, any_failed, assign_error, opt;
|
||||
int assign, undo, any_failed, assign_error, opt;
|
||||
int functions_only, arrays_only, assoc_only;
|
||||
int aflags;
|
||||
char *name;
|
||||
#if defined (ARRAY_VARS)
|
||||
|
|
@ -118,7 +134,8 @@ set_or_show_attributes (list, attribute, nodefs)
|
|||
WORD_DESC *w;
|
||||
#endif
|
||||
|
||||
undo = functions_only = arrays_only = any_failed = assign_error = 0;
|
||||
functions_only = arrays_only = assoc_only = 0;
|
||||
undo = any_failed = assign_error = 0;
|
||||
/* Read arguments from the front of the list. */
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, ATTROPTS)) != -1)
|
||||
|
|
@ -133,8 +150,11 @@ set_or_show_attributes (list, attribute, nodefs)
|
|||
break;
|
||||
#if defined (ARRAY_VARS)
|
||||
case 'a':
|
||||
arrays_only = 1;
|
||||
break;
|
||||
arrays_only = 1;
|
||||
break;
|
||||
case 'A':
|
||||
assoc_only = 1;
|
||||
break;
|
||||
#endif
|
||||
case 'p':
|
||||
break;
|
||||
|
|
@ -206,11 +226,11 @@ set_or_show_attributes (list, attribute, nodefs)
|
|||
#if defined (ARRAY_VARS)
|
||||
/* Let's try something here. Turn readonly -a xxx=yyy into
|
||||
declare -ra xxx=yyy and see what that gets us. */
|
||||
if (arrays_only)
|
||||
if (arrays_only || assoc_only)
|
||||
{
|
||||
tlist = list->next;
|
||||
list->next = (WORD_LIST *)NULL;
|
||||
w = make_word ("-ra");
|
||||
w = arrays_only ? make_word ("-ra") : make_word ("-rA");
|
||||
nlist = make_word_list (w, list);
|
||||
opt = declare_builtin (nlist);
|
||||
if (opt != EXECUTION_SUCCESS)
|
||||
|
|
@ -257,6 +277,12 @@ set_or_show_attributes (list, attribute, nodefs)
|
|||
if (attribute != att_array)
|
||||
attribute &= ~att_array;
|
||||
}
|
||||
else if (attribute & att_assoc)
|
||||
{
|
||||
assoc_only++;
|
||||
if (attribute != att_assoc)
|
||||
attribute &= ~att_assoc;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (variable_list)
|
||||
|
|
@ -266,9 +292,15 @@ set_or_show_attributes (list, attribute, nodefs)
|
|||
#if defined (ARRAY_VARS)
|
||||
if (arrays_only && array_p (var) == 0)
|
||||
continue;
|
||||
else if (assoc_only && assoc_p (var) == 0)
|
||||
continue;
|
||||
#endif
|
||||
if ((var->attributes & attribute))
|
||||
show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
|
||||
{
|
||||
show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
|
||||
if (any_failed = sh_chkwrite (any_failed))
|
||||
break;
|
||||
}
|
||||
}
|
||||
free (variable_list);
|
||||
}
|
||||
|
|
@ -279,6 +311,30 @@ set_or_show_attributes (list, attribute, nodefs)
|
|||
: EXECUTION_FAILURE));
|
||||
}
|
||||
|
||||
/* Show all variable variables (v == 1) or functions (v == 0) with
|
||||
attributes. */
|
||||
int
|
||||
show_all_var_attributes (v, nodefs)
|
||||
int v, nodefs;
|
||||
{
|
||||
SHELL_VAR **variable_list, *var;
|
||||
int any_failed;
|
||||
register int i;
|
||||
|
||||
variable_list = v ? all_shell_variables () : all_shell_functions ();
|
||||
if (variable_list == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
for (i = any_failed = 0; var = variable_list[i]; i++)
|
||||
{
|
||||
show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
|
||||
if (any_failed = sh_chkwrite (any_failed))
|
||||
break;
|
||||
}
|
||||
free (variable_list);
|
||||
return (any_failed == 0 ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
/* Show the attributes for shell variable VAR. If NODEFS is non-zero,
|
||||
don't show function definitions along with the name. If PATTR is
|
||||
non-zero, it indicates we're being called from `export' or `readonly'.
|
||||
|
|
@ -290,7 +346,7 @@ show_var_attributes (var, pattr, nodefs)
|
|||
SHELL_VAR *var;
|
||||
int pattr, nodefs;
|
||||
{
|
||||
char flags[8], *x;
|
||||
char flags[16], *x;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
|
|
@ -301,6 +357,9 @@ show_var_attributes (var, pattr, nodefs)
|
|||
#if defined (ARRAY_VARS)
|
||||
if (array_p (var))
|
||||
flags[i++] = 'a';
|
||||
|
||||
if (assoc_p (var))
|
||||
flags[i++] = 'A';
|
||||
#endif
|
||||
|
||||
if (function_p (var))
|
||||
|
|
@ -317,12 +376,24 @@ show_var_attributes (var, pattr, nodefs)
|
|||
|
||||
if (exported_p (var))
|
||||
flags[i++] = 'x';
|
||||
|
||||
if (capcase_p (var))
|
||||
flags[i++] = 'c';
|
||||
|
||||
if (lowercase_p (var))
|
||||
flags[i++] = 'l';
|
||||
|
||||
if (uppercase_p (var))
|
||||
flags[i++] = 'u';
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined (ARRAY_VARS)
|
||||
if (array_p (var))
|
||||
flags[i++] = 'a';
|
||||
|
||||
if (assoc_p (var))
|
||||
flags[i++] = 'A';
|
||||
#endif
|
||||
|
||||
if (function_p (var))
|
||||
|
|
@ -336,7 +407,7 @@ show_var_attributes (var, pattr, nodefs)
|
|||
reused as input to recreate the current state. */
|
||||
if (function_p (var) && nodefs == 0 && (pattr == 0 || posixly_correct == 0))
|
||||
{
|
||||
printf ("%s\n", named_function_string (var->name, function_cell (var), 1));
|
||||
printf ("%s\n", named_function_string (var->name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL));
|
||||
nodefs++;
|
||||
if (pattr == 0 && i == 1 && flags[0] == 'f')
|
||||
return 0; /* don't print `declare -f name' */
|
||||
|
|
@ -350,8 +421,10 @@ show_var_attributes (var, pattr, nodefs)
|
|||
printf ("%s ", this_command_name);
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
if (array_p (var))
|
||||
if (array_p (var))
|
||||
print_array_assignment (var, 1);
|
||||
else if (assoc_p (var))
|
||||
print_assoc_assignment (var, 1);
|
||||
else
|
||||
#endif
|
||||
/* force `readonly' and `export' to not print out function definitions
|
||||
|
|
@ -359,7 +432,7 @@ show_var_attributes (var, pattr, nodefs)
|
|||
if (nodefs || (function_p (var) && pattr != 0 && posixly_correct))
|
||||
printf ("%s\n", var->name);
|
||||
else if (function_p (var))
|
||||
printf ("%s\n", named_function_string (var->name, function_cell (var), 1));
|
||||
printf ("%s\n", named_function_string (var->name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL));
|
||||
else if (invisible_p (var))
|
||||
printf ("%s\n", var->name);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
This file is shift.def, from which is created shift.c.
|
||||
It implements the builtin "shift" 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 shift.c
|
||||
|
||||
|
|
@ -39,8 +38,13 @@ $PRODUCES shift.c
|
|||
$BUILTIN shift
|
||||
$FUNCTION shift_builtin
|
||||
$SHORT_DOC shift [n]
|
||||
The positional parameters from $N+1 ... are renamed to $1 ... If N is
|
||||
Shift positional parameters.
|
||||
|
||||
Rename the positional parameters $N+1,$N+2 ... to $1,$2 ... If N is
|
||||
not given, it is assumed to be 1.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless N is negative or greater than $#.
|
||||
$END
|
||||
|
||||
int print_shift_error;
|
||||
|
|
@ -57,7 +61,8 @@ shift_builtin (list)
|
|||
register int count;
|
||||
WORD_LIST *temp;
|
||||
|
||||
times = get_numeric_arg (list, 0);
|
||||
if (get_numeric_arg (list, 0, ×) == 0)
|
||||
return (EXECUTION_FAILURE);
|
||||
|
||||
if (times == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
|
|
|||
|
|
@ -1,37 +1,44 @@
|
|||
This file is shopt.def, from which is created shopt.c.
|
||||
It implements the Bash `shopt' builtin.
|
||||
|
||||
Copyright (C) 1994-2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 1994-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 shopt.c
|
||||
|
||||
$BUILTIN shopt
|
||||
$FUNCTION shopt_builtin
|
||||
$SHORT_DOC shopt [-pqsu] [-o long-option] optname [optname...]
|
||||
Toggle the values of variables controlling optional behavior.
|
||||
The -s flag means to enable (set) each OPTNAME; the -u flag
|
||||
unsets each OPTNAME. The -q flag suppresses output; the exit
|
||||
status indicates whether each OPTNAME is set or unset. The -o
|
||||
option restricts the OPTNAMEs to those defined for use with
|
||||
`set -o'. With no options, or with the -p option, a list of all
|
||||
settable options is displayed, with an indication of whether or
|
||||
not each is set.
|
||||
$SHORT_DOC shopt [-pqsu] [-o] [optname ...]
|
||||
Set and unset shell options.
|
||||
|
||||
Change the setting of each shell option OPTNAME. Without any option
|
||||
arguments, list all shell options with an indication of whether or not each
|
||||
is set.
|
||||
|
||||
Options:
|
||||
-o restrict OPTNAMEs to those defined for use with `set -o'
|
||||
-p print each shell option with an indication of its status
|
||||
-q suppress output
|
||||
-s enable (set) each OPTNAME
|
||||
-u disable (unset) each OPTNAME
|
||||
|
||||
Exit Status:
|
||||
Returns success if OPTNAME is enabled; fails if an invalid option is
|
||||
given or OPTNAME is disabled.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -45,6 +52,8 @@ $END
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
|
|
@ -52,6 +61,10 @@ $END
|
|||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
#if defined (HISTORY)
|
||||
# include "../bashhist.h"
|
||||
#endif
|
||||
|
||||
#define UNSETOPT 0
|
||||
#define SETOPT 1
|
||||
|
||||
|
|
@ -68,20 +81,20 @@ extern int glob_ignore_case, match_ignore_case;
|
|||
extern int hup_on_exit;
|
||||
extern int xpg_echo;
|
||||
extern int gnu_error_format;
|
||||
extern int check_jobs_at_exit;
|
||||
extern int autocd;
|
||||
extern int glob_star;
|
||||
|
||||
#if defined (EXTENDED_GLOB)
|
||||
extern int extended_glob;
|
||||
#endif
|
||||
|
||||
#if defined (HISTORY)
|
||||
extern int literal_history, command_oriented_history;
|
||||
extern int force_append_history;
|
||||
#endif
|
||||
|
||||
#if defined (READLINE)
|
||||
extern int hist_verify, history_reediting, perform_hostname_completion;
|
||||
extern int no_empty_command_completion;
|
||||
extern int force_fignore;
|
||||
extern int dircomplete_spelling;
|
||||
|
||||
extern int enable_hostname_completion __P((int));
|
||||
#endif
|
||||
|
||||
|
|
@ -109,6 +122,7 @@ static int set_restricted_shell __P((int));
|
|||
|
||||
static int shopt_login_shell;
|
||||
static int shopt_compat31;
|
||||
static int shopt_compat32;
|
||||
|
||||
typedef int shopt_set_func_t __P((int));
|
||||
|
||||
|
|
@ -117,14 +131,22 @@ static struct {
|
|||
int *value;
|
||||
shopt_set_func_t *set_func;
|
||||
} shopt_vars[] = {
|
||||
{ "autocd", &autocd, (shopt_set_func_t *)NULL },
|
||||
{ "cdable_vars", &cdable_vars, (shopt_set_func_t *)NULL },
|
||||
{ "cdspell", &cdspelling, (shopt_set_func_t *)NULL },
|
||||
{ "checkhash", &check_hashed_filenames, (shopt_set_func_t *)NULL },
|
||||
#if defined (JOB_CONTROL)
|
||||
{ "checkjobs", &check_jobs_at_exit, (shopt_set_func_t *)NULL },
|
||||
#endif
|
||||
{ "checkwinsize", &check_window_size, (shopt_set_func_t *)NULL },
|
||||
#if defined (HISTORY)
|
||||
{ "cmdhist", &command_oriented_history, (shopt_set_func_t *)NULL },
|
||||
#endif
|
||||
{ "compat31", &shopt_compat31, set_compatibility_level },
|
||||
{ "compat32", &shopt_compat32, set_compatibility_level },
|
||||
#if defined (READLINE)
|
||||
{ "dirspell", &dircomplete_spelling, (shopt_set_func_t *)NULL },
|
||||
#endif
|
||||
{ "dotglob", &glob_dot_filenames, (shopt_set_func_t *)NULL },
|
||||
{ "execfail", &no_exit_on_failed_exec, (shopt_set_func_t *)NULL },
|
||||
{ "expand_aliases", &expand_aliases, (shopt_set_func_t *)NULL },
|
||||
|
|
@ -139,6 +161,7 @@ static struct {
|
|||
#if defined (READLINE)
|
||||
{ "force_fignore", &force_fignore, (shopt_set_func_t *)NULL },
|
||||
#endif
|
||||
{ "globstar", &glob_star, (shopt_set_func_t *)NULL },
|
||||
{ "gnu_errfmt", &gnu_error_format, (shopt_set_func_t *)NULL },
|
||||
#if defined (HISTORY)
|
||||
{ "histappend", &force_append_history, (shopt_set_func_t *)NULL },
|
||||
|
|
@ -174,8 +197,8 @@ static struct {
|
|||
{ (char *)0, (int *)0, (shopt_set_func_t *)NULL }
|
||||
};
|
||||
|
||||
static char *on = "on";
|
||||
static char *off = "off";
|
||||
static const char * const on = "on";
|
||||
static const char * const off = "off";
|
||||
|
||||
static int find_shopt __P((char *));
|
||||
static int toggle_shopts __P((int, WORD_LIST *, int));
|
||||
|
|
@ -352,7 +375,7 @@ list_shopts (list, flags)
|
|||
if ((flags & QFLAG) == 0)
|
||||
print_shopt (shopt_vars[i].name, val, flags);
|
||||
}
|
||||
return (EXECUTION_SUCCESS);
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
for (l = list, rval = EXECUTION_SUCCESS; l; l = l->next)
|
||||
|
|
@ -371,7 +394,7 @@ list_shopts (list, flags)
|
|||
print_shopt (l->word->word, val, flags);
|
||||
}
|
||||
|
||||
return (rval);
|
||||
return (sh_chkwrite (rval));
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -386,7 +409,7 @@ list_some_shopts (mode, flags)
|
|||
if (((flags & QFLAG) == 0) && mode == val)
|
||||
print_shopt (shopt_vars[i].name, val, flags);
|
||||
}
|
||||
return (EXECUTION_SUCCESS);
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -401,7 +424,7 @@ list_shopt_o_options (list, flags)
|
|||
{
|
||||
if ((flags & QFLAG) == 0)
|
||||
list_minus_o_opts (-1, (flags & PFLAG));
|
||||
return (EXECUTION_SUCCESS);
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
for (l = list, rval = EXECUTION_SUCCESS; l; l = l->next)
|
||||
|
|
@ -423,7 +446,7 @@ list_shopt_o_options (list, flags)
|
|||
printf (OPTFMT, l->word->word, val ? on : off);
|
||||
}
|
||||
}
|
||||
return (rval);
|
||||
return (sh_chkwrite (rval));
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -432,7 +455,7 @@ list_some_o_options (mode, flags)
|
|||
{
|
||||
if ((flags & QFLAG) == 0)
|
||||
list_minus_o_opts (mode, (flags & PFLAG));
|
||||
return (EXECUTION_SUCCESS);
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -470,8 +493,10 @@ set_compatibility_level (mode)
|
|||
/* Need to change logic here as we add more compatibility levels */
|
||||
if (shopt_compat31)
|
||||
shell_compatibility_level = 31;
|
||||
else
|
||||
else if (shopt_compat32)
|
||||
shell_compatibility_level = 32;
|
||||
else
|
||||
shell_compatibility_level = DEFAULT_COMPAT_LEVEL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -552,5 +577,5 @@ shopt_listopt (name, reusable)
|
|||
}
|
||||
|
||||
print_shopt (name, *shopt_vars[i].value, reusable ? PFLAG : 0);
|
||||
return (EXECUTION_SUCCESS);
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,44 +1,55 @@
|
|||
This file is source.def, from which is created source.c.
|
||||
It implements the builtins "." and "source" 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 source.c
|
||||
|
||||
$BUILTIN source
|
||||
$FUNCTION source_builtin
|
||||
$SHORT_DOC source filename [arguments]
|
||||
Read and execute commands from FILENAME and return. The pathnames
|
||||
in $PATH are used to find the directory containing FILENAME. If any
|
||||
ARGUMENTS are supplied, they become the positional parameters when
|
||||
FILENAME is executed.
|
||||
Execute commands from a file in the current shell.
|
||||
|
||||
Read and execute commands from FILENAME in the current shell. The
|
||||
entries in $PATH are used to find the directory containing FILENAME.
|
||||
If any ARGUMENTS are supplied, they become the positional parameters
|
||||
when FILENAME is executed.
|
||||
|
||||
Exit Status:
|
||||
Returns the status of the last command executed in FILENAME; fails if
|
||||
FILENAME cannot be read.
|
||||
$END
|
||||
|
||||
$BUILTIN .
|
||||
$DOCNAME dot
|
||||
$FUNCTION source_builtin
|
||||
$SHORT_DOC . filename [arguments]
|
||||
Read and execute commands from FILENAME and return. The pathnames
|
||||
in $PATH are used to find the directory containing FILENAME. If any
|
||||
ARGUMENTS are supplied, they become the positional parameters when
|
||||
FILENAME is executed.
|
||||
Execute commands from a file in the current shell.
|
||||
|
||||
Read and execute commands from FILENAME in the current shell. The
|
||||
entries in $PATH are used to find the directory containing FILENAME.
|
||||
If any ARGUMENTS are supplied, they become the positional parameters
|
||||
when FILENAME is executed.
|
||||
|
||||
Exit Status:
|
||||
Returns the status of the last command executed in FILENAME; fails if
|
||||
FILENAME cannot be read.
|
||||
$END
|
||||
/* source.c - Implements the `.' and `source' builtins. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
|
@ -68,6 +79,8 @@ $END
|
|||
extern int errno;
|
||||
#endif /* !errno */
|
||||
|
||||
extern int posixly_correct;
|
||||
|
||||
static void maybe_pop_dollar_vars __P((void));
|
||||
|
||||
/* If non-zero, `.' uses $PATH to look up the script to be sourced. */
|
||||
|
|
@ -126,7 +139,12 @@ source_builtin (list)
|
|||
#endif
|
||||
|
||||
filename = (char *)NULL;
|
||||
if (source_uses_path)
|
||||
/* XXX -- should this be absolute_pathname? */
|
||||
if (posixly_correct && strchr (list->word->word, '/'))
|
||||
filename = savestring (list->word->word);
|
||||
else if (absolute_pathname (list->word->word))
|
||||
filename = savestring (list->word->word);
|
||||
else if (source_uses_path)
|
||||
filename = find_path_file (list->word->word);
|
||||
if (filename == 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
This file is suspend.def, from which is created suspend.c.
|
||||
It implements the builtin "suspend" 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 suspend.c
|
||||
|
||||
|
|
@ -25,9 +24,16 @@ $BUILTIN suspend
|
|||
$DEPENDS_ON JOB_CONTROL
|
||||
$FUNCTION suspend_builtin
|
||||
$SHORT_DOC suspend [-f]
|
||||
Suspend the execution of this shell until it receives a SIGCONT
|
||||
signal. The `-f' if specified says not to complain about this
|
||||
being a login shell if it is; just suspend anyway.
|
||||
Suspend shell execution.
|
||||
|
||||
Suspend the execution of this shell until it receives a SIGCONT signal.
|
||||
Unless forced, login shells cannot be suspended.
|
||||
|
||||
Options:
|
||||
-f force the suspend, even if the shell is a login shell
|
||||
|
||||
Exit Status:
|
||||
Returns success unless job control is not enabled or an error occurs.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
|
|||
|
|
@ -1,29 +1,30 @@
|
|||
This file is test.def, from which is created test.c.
|
||||
It implements the builtin "test" in Bash.
|
||||
|
||||
Copyright (C) 1987-2002 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 test.c
|
||||
|
||||
$BUILTIN test
|
||||
$FUNCTION test_builtin
|
||||
$SHORT_DOC test [expr]
|
||||
Evaluate conditional expression.
|
||||
|
||||
Exits with a status of 0 (true) or 1 (false) depending on
|
||||
the evaluation of EXPR. Expressions may be unary or binary. Unary
|
||||
expressions are often used to examine the status of a file. There
|
||||
|
|
@ -31,27 +32,27 @@ are string operators as well, and numeric comparison operators.
|
|||
|
||||
File operators:
|
||||
|
||||
-a FILE True if file exists.
|
||||
-b FILE True if file is block special.
|
||||
-c FILE True if file is character special.
|
||||
-d FILE True if file is a directory.
|
||||
-e FILE True if file exists.
|
||||
-f FILE True if file exists and is a regular file.
|
||||
-g FILE True if file is set-group-id.
|
||||
-h FILE True if file is a symbolic link.
|
||||
-L FILE True if file is a symbolic link.
|
||||
-k FILE True if file has its `sticky' bit set.
|
||||
-p FILE True if file is a named pipe.
|
||||
-r FILE True if file is readable by you.
|
||||
-s FILE True if file exists and is not empty.
|
||||
-S FILE True if file is a socket.
|
||||
-t FD True if FD is opened on a terminal.
|
||||
-u FILE True if the file is set-user-id.
|
||||
-w FILE True if the file is writable by you.
|
||||
-x FILE True if the file is executable by you.
|
||||
-O FILE True if the file is effectively owned by you.
|
||||
-G FILE True if the file is effectively owned by your group.
|
||||
-N FILE True if the file has been modified since it was last read.
|
||||
-a FILE True if file exists.
|
||||
-b FILE True if file is block special.
|
||||
-c FILE True if file is character special.
|
||||
-d FILE True if file is a directory.
|
||||
-e FILE True if file exists.
|
||||
-f FILE True if file exists and is a regular file.
|
||||
-g FILE True if file is set-group-id.
|
||||
-h FILE True if file is a symbolic link.
|
||||
-L FILE True if file is a symbolic link.
|
||||
-k FILE True if file has its `sticky' bit set.
|
||||
-p FILE True if file is a named pipe.
|
||||
-r FILE True if file is readable by you.
|
||||
-s FILE True if file exists and is not empty.
|
||||
-S FILE True if file is a socket.
|
||||
-t FD True if FD is opened on a terminal.
|
||||
-u FILE True if the file is set-user-id.
|
||||
-w FILE True if the file is writable by you.
|
||||
-x FILE True if the file is executable by you.
|
||||
-O FILE True if the file is effectively owned by you.
|
||||
-G FILE True if the file is effectively owned by your group.
|
||||
-N FILE True if the file has been modified since it was last read.
|
||||
|
||||
FILE1 -nt FILE2 True if file1 is newer than file2 (according to
|
||||
modification date).
|
||||
|
|
@ -62,41 +63,47 @@ File operators:
|
|||
|
||||
String operators:
|
||||
|
||||
-z STRING True if string is empty.
|
||||
-z STRING True if string is empty.
|
||||
|
||||
-n STRING
|
||||
STRING True if string is not empty.
|
||||
-n STRING
|
||||
STRING True if string is not empty.
|
||||
|
||||
STRING1 = STRING2
|
||||
True if the strings are equal.
|
||||
STRING1 != STRING2
|
||||
True if the strings are not equal.
|
||||
STRING1 < STRING2
|
||||
True if STRING1 sorts before STRING2 lexicographically.
|
||||
STRING1 > STRING2
|
||||
True if STRING1 sorts after STRING2 lexicographically.
|
||||
STRING1 = STRING2
|
||||
True if the strings are equal.
|
||||
STRING1 != STRING2
|
||||
True if the strings are not equal.
|
||||
STRING1 < STRING2
|
||||
True if STRING1 sorts before STRING2 lexicographically.
|
||||
STRING1 > STRING2
|
||||
True if STRING1 sorts after STRING2 lexicographically.
|
||||
|
||||
Other operators:
|
||||
|
||||
-o OPTION True if the shell option OPTION is enabled.
|
||||
! EXPR True if expr is false.
|
||||
EXPR1 -a EXPR2 True if both expr1 AND expr2 are true.
|
||||
EXPR1 -o EXPR2 True if either expr1 OR expr2 is true.
|
||||
-o OPTION True if the shell option OPTION is enabled.
|
||||
! EXPR True if expr is false.
|
||||
EXPR1 -a EXPR2 True if both expr1 AND expr2 are true.
|
||||
EXPR1 -o EXPR2 True if either expr1 OR expr2 is true.
|
||||
|
||||
arg1 OP arg2 Arithmetic tests. OP is one of -eq, -ne,
|
||||
-lt, -le, -gt, or -ge.
|
||||
arg1 OP arg2 Arithmetic tests. OP is one of -eq, -ne,
|
||||
-lt, -le, -gt, or -ge.
|
||||
|
||||
Arithmetic binary operators return true if ARG1 is equal, not-equal,
|
||||
less-than, less-than-or-equal, greater-than, or greater-than-or-equal
|
||||
than ARG2.
|
||||
|
||||
Exit Status:
|
||||
Returns success if EXPR evaluates to true; fails if EXPR evaluates to
|
||||
false or an invalid argument is given.
|
||||
$END
|
||||
|
||||
$BUILTIN [
|
||||
$DOCNAME test_bracket
|
||||
$FUNCTION test_builtin
|
||||
$SHORT_DOC [ arg... ]
|
||||
This is a synonym for the "test" builtin, but the last
|
||||
argument must be a literal `]', to match the opening `['.
|
||||
Evaluate conditional expression.
|
||||
|
||||
This is a synonym for the "test" builtin, but the last argument must
|
||||
be a literal `]', to match the opening `['.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -109,6 +116,7 @@ $END
|
|||
#endif
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../test.h"
|
||||
|
|
@ -131,7 +139,7 @@ test_builtin (list)
|
|||
{
|
||||
if (this_command_name[0] == '[' && !this_command_name[1])
|
||||
{
|
||||
builtin_error ("missing `]'");
|
||||
builtin_error (_("missing `]'"));
|
||||
return (EX_BADUSAGE);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +1,35 @@
|
|||
This file is times.def, from which is created times.c.
|
||||
It implements the builtin "times" in Bash.
|
||||
|
||||
Copyright (C) 1987-2002 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 times.c
|
||||
|
||||
$BUILTIN times
|
||||
$FUNCTION times_builtin
|
||||
$SHORT_DOC times
|
||||
Print the accumulated user and system times for processes run from
|
||||
the shell.
|
||||
Display process times.
|
||||
|
||||
Prints the accumulated user and system times for the shell and all of its
|
||||
child processes.
|
||||
|
||||
Exit Status:
|
||||
Always succeeds.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -111,5 +115,5 @@ times_builtin (list)
|
|||
# endif /* HAVE_TIMES */
|
||||
#endif /* !HAVE_TIMES */
|
||||
|
||||
return (EXECUTION_SUCCESS);
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,43 +1,55 @@
|
|||
This file is trap.def, from which is created trap.c.
|
||||
It implements the builtin "trap" in Bash.
|
||||
|
||||
Copyright (C) 1987-2006 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 trap.c
|
||||
|
||||
$BUILTIN trap
|
||||
$FUNCTION trap_builtin
|
||||
$SHORT_DOC trap [-lp] [arg signal_spec ...]
|
||||
The command ARG is to be read and executed when the shell receives
|
||||
$SHORT_DOC trap [-lp] [[arg] signal_spec ...]
|
||||
Trap signals and other events.
|
||||
|
||||
Defines and activates handlers to be run when the shell receives signals
|
||||
or other conditions.
|
||||
|
||||
ARG is a command to be read and executed when the shell receives the
|
||||
signal(s) SIGNAL_SPEC. If ARG is absent (and a single SIGNAL_SPEC
|
||||
is supplied) or `-', each specified signal is reset to its original
|
||||
value. If ARG is the null string each SIGNAL_SPEC is ignored by the
|
||||
shell and by the commands it invokes. If a SIGNAL_SPEC is EXIT (0)
|
||||
the command ARG is executed on exit from the shell. If a SIGNAL_SPEC
|
||||
is DEBUG, ARG is executed after every simple command. If the`-p' option
|
||||
is supplied then the trap commands associated with each SIGNAL_SPEC are
|
||||
displayed. If no arguments are supplied or if only `-p' is given, trap
|
||||
prints the list of commands associated with each signal. Each SIGNAL_SPEC
|
||||
is either a signal name in <signal.h> or a signal number. Signal names
|
||||
are case insensitive and the SIG prefix is optional. `trap -l' prints
|
||||
a list of signal names and their corresponding numbers. Note that a
|
||||
signal can be sent to the shell with "kill -signal $$".
|
||||
shell and by the commands it invokes.
|
||||
|
||||
If a SIGNAL_SPEC is EXIT (0) ARG is executed on exit from the shell. If
|
||||
a SIGNAL_SPEC is DEBUG, ARG is executed before every simple command.
|
||||
|
||||
If no arguments are supplied, trap prints the list of commands associated
|
||||
with each signal.
|
||||
|
||||
Options:
|
||||
-l print a list of signal names and their corresponding numbers
|
||||
-p display the trap commands associated with each SIGNAL_SPEC
|
||||
|
||||
Each SIGNAL_SPEC is either a signal name in <signal.h> or a signal number.
|
||||
Signal names are case insensitive and the SIG prefix is optional. A
|
||||
signal may be sent to the shell with "kill -signal $$".
|
||||
|
||||
Exit Status:
|
||||
Returns success unless a SIGSPEC is invalid or an invalid option is given.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -112,9 +124,9 @@ trap_builtin (list)
|
|||
opt = DSIG_NOCASE|DSIG_SIGPREFIX; /* flags for decode_signal */
|
||||
|
||||
if (list_signal_names)
|
||||
return (display_signal_list ((WORD_LIST *)NULL, 1));
|
||||
return (sh_chkwrite (display_signal_list ((WORD_LIST *)NULL, 1)));
|
||||
else if (display || list == 0)
|
||||
return (display_traps (list));
|
||||
return (sh_chkwrite (display_traps (list)));
|
||||
else
|
||||
{
|
||||
char *first_arg;
|
||||
|
|
|
|||
|
|
@ -1,50 +1,53 @@
|
|||
This file is type.def, from which is created type.c.
|
||||
It implements the builtin "type" in Bash.
|
||||
|
||||
Copyright (C) 1987-2002 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 type.c
|
||||
|
||||
$BUILTIN type
|
||||
$FUNCTION type_builtin
|
||||
$SHORT_DOC type [-afptP] name [name ...]
|
||||
Display information about command type.
|
||||
|
||||
For each NAME, indicate how it would be interpreted if used as a
|
||||
command name.
|
||||
|
||||
If the -t option is used, `type' outputs a single word which is one of
|
||||
`alias', `keyword', `function', `builtin', `file' or `', if NAME is an
|
||||
alias, shell reserved word, shell function, shell builtin, disk file,
|
||||
or unfound, respectively.
|
||||
Options:
|
||||
-a display all locations containing an executable named NAME;
|
||||
includes aliases, builtins, and functions, if and only if
|
||||
the `-p' option is not also used
|
||||
-f suppress shell function lookup
|
||||
-P force a PATH search for each NAME, even if it is an alias,
|
||||
builtin, or function, and returns the name of the disk file
|
||||
that would be executed
|
||||
-p returns either the name of the disk file that would be executed,
|
||||
or nothing if `type -t NAME' would not return `file'.
|
||||
-t output a single word which is one of `alias', `keyword',
|
||||
`function', `builtin', `file' or `', if NAME is an alias, shell
|
||||
reserved word, shell function, shell builtin, disk file, or not
|
||||
found, respectively
|
||||
|
||||
If the -p flag is used, `type' either returns the name of the disk
|
||||
file that would be executed, or nothing if `type -t NAME' would not
|
||||
return `file'.
|
||||
Arguments:
|
||||
NAME Command name to be interpreted.
|
||||
|
||||
If the -a flag is used, `type' displays all of the places that contain
|
||||
an executable named `file'. This includes aliases, builtins, and
|
||||
functions, if and only if the -p flag is not also used.
|
||||
|
||||
The -f flag suppresses shell function lookup.
|
||||
|
||||
The -P flag forces a PATH search for each NAME, even if it is an alias,
|
||||
builtin, or function, and returns the name of the disk file that would
|
||||
be executed.
|
||||
Exit Status:
|
||||
Returns success if all of the NAMEs are found; fails if any are not found.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -108,14 +111,14 @@ int
|
|||
type_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int dflags, successful_finds, opt;
|
||||
int dflags, any_failed, opt;
|
||||
WORD_LIST *this;
|
||||
|
||||
if (list == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
dflags = CDESC_SHORTDESC; /* default */
|
||||
successful_finds = 0;
|
||||
any_failed = 0;
|
||||
|
||||
/* Handle the obsolescent `-type', `-path', and `-all' by prescanning
|
||||
the arguments and converting those options to the form that
|
||||
|
|
@ -181,13 +184,12 @@ type_builtin (list)
|
|||
if (!found && (dflags & (CDESC_PATH_ONLY|CDESC_TYPE)) == 0)
|
||||
sh_notfound (list->word->word);
|
||||
|
||||
successful_finds += found;
|
||||
any_failed += found == 0;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
fflush (stdout);
|
||||
|
||||
return ((successful_finds != 0) ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
|
||||
opt = (any_failed == 0) ? EXECUTION_SUCCESS : EXECUTION_FAILURE;
|
||||
return (sh_chkwrite (opt));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -267,18 +269,14 @@ describe_command (command, dflags)
|
|||
puts ("function");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
{
|
||||
#define PRETTY_PRINT_FUNC 1
|
||||
char *result;
|
||||
|
||||
printf (_("%s is a function\n"), command);
|
||||
|
||||
/* We're blowing away THE_PRINTED_COMMAND here... */
|
||||
|
||||
result = named_function_string (command,
|
||||
(COMMAND *) function_cell (func),
|
||||
PRETTY_PRINT_FUNC);
|
||||
result = named_function_string (command, function_cell (func), FUNC_MULTILINE|FUNC_EXTERNAL);
|
||||
printf ("%s\n", result);
|
||||
#undef PRETTY_PRINT_FUNC
|
||||
}
|
||||
else if (dflags & CDESC_REUSABLE)
|
||||
printf ("%s\n", command);
|
||||
|
|
@ -390,7 +388,7 @@ describe_command (command, dflags)
|
|||
if (dflags & CDESC_TYPE)
|
||||
puts ("file");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
printf ("%s is %s\n", command, full_path);
|
||||
printf (_("%s is %s\n"), command, full_path);
|
||||
else if (dflags & (CDESC_REUSABLE|CDESC_PATH_ONLY))
|
||||
printf ("%s\n", full_path);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,62 +1,68 @@
|
|||
This file is ulimit.def, from which is created ulimit.c.
|
||||
It implements the builtin "ulimit" in Bash.
|
||||
|
||||
Copyright (C) 1987-2005 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 ulimit.c
|
||||
|
||||
$BUILTIN ulimit
|
||||
$FUNCTION ulimit_builtin
|
||||
$DEPENDS_ON !_MINIX
|
||||
$SHORT_DOC ulimit [-SHacdfilmnpqstuvx] [limit]
|
||||
Ulimit provides control over the resources available to processes
|
||||
started by the shell, on systems that allow such control. If an
|
||||
option is given, it is interpreted as follows:
|
||||
$SHORT_DOC ulimit [-SHacdefilmnpqrstuvx] [limit]
|
||||
Modify shell resource limits.
|
||||
|
||||
-S use the `soft' resource limit
|
||||
-H use the `hard' resource limit
|
||||
-a all current limits are reported
|
||||
-c the maximum size of core files created
|
||||
-d the maximum size of a process's data segment
|
||||
-e the maximum scheduling priority (`nice')
|
||||
-f the maximum size of files written by the shell and its children
|
||||
-i the maximum number of pending signals
|
||||
-l the maximum size a process may lock into memory
|
||||
-m the maximum resident set size
|
||||
-n the maximum number of open file descriptors
|
||||
-p the pipe buffer size
|
||||
-q the maximum number of bytes in POSIX message queues
|
||||
-r the maximum real-time scheduling priority
|
||||
-s the maximum stack size
|
||||
-t the maximum amount of cpu time in seconds
|
||||
-u the maximum number of user processes
|
||||
-v the size of virtual memory
|
||||
-x the maximum number of file locks
|
||||
Provides control over the resources available to the shell and processes
|
||||
it creates, on systems that allow such control.
|
||||
|
||||
If LIMIT is given, it is the new value of the specified resource;
|
||||
the special LIMIT values `soft', `hard', and `unlimited' stand for
|
||||
the current soft limit, the current hard limit, and no limit, respectively.
|
||||
Otherwise, the current value of the specified resource is printed.
|
||||
If no option is given, then -f is assumed. Values are in 1024-byte
|
||||
increments, except for -t, which is in seconds, -p, which is in
|
||||
increments of 512 bytes, and -u, which is an unscaled number of
|
||||
processes.
|
||||
Options:
|
||||
-S use the `soft' resource limit
|
||||
-H use the `hard' resource limit
|
||||
-a all current limits are reported
|
||||
-b the socket buffer size
|
||||
-c the maximum size of core files created
|
||||
-d the maximum size of a process's data segment
|
||||
-e the maximum scheduling priority (`nice')
|
||||
-f the maximum size of files written by the shell and its children
|
||||
-i the maximum number of pending signals
|
||||
-l the maximum size a process may lock into memory
|
||||
-m the maximum resident set size
|
||||
-n the maximum number of open file descriptors
|
||||
-p the pipe buffer size
|
||||
-q the maximum number of bytes in POSIX message queues
|
||||
-r the maximum real-time scheduling priority
|
||||
-s the maximum stack size
|
||||
-t the maximum amount of cpu time in seconds
|
||||
-u the maximum number of user processes
|
||||
-v the size of virtual memory
|
||||
-x the maximum number of file locks
|
||||
|
||||
If LIMIT is given, it is the new value of the specified resource; the
|
||||
special LIMIT values `soft', `hard', and `unlimited' stand for the
|
||||
current soft limit, the current hard limit, and no limit, respectively.
|
||||
Otherwise, the current value of the specified resource is printed. If
|
||||
no option is given, then -f is assumed.
|
||||
|
||||
Values are in 1024-byte increments, except for -t, which is in seconds,
|
||||
-p, which is in increments of 512 bytes, and -u, which is an unscaled
|
||||
number of processes.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is supplied or an error occurs.
|
||||
$END
|
||||
|
||||
#if !defined (_MINIX)
|
||||
|
|
@ -98,7 +104,7 @@ extern int errno;
|
|||
# if defined (HPUX) && defined (RLIMIT_NEEDS_KERNEL)
|
||||
# undef _KERNEL
|
||||
# endif
|
||||
#else
|
||||
#elif defined (HAVE_SYS_TIMES_H)
|
||||
# include <sys/times.h>
|
||||
#endif
|
||||
|
||||
|
|
@ -172,6 +178,14 @@ extern int errno;
|
|||
#define LIMIT_HARD 0x01
|
||||
#define LIMIT_SOFT 0x02
|
||||
|
||||
/* "Blocks" are defined as 512 bytes when in Posix mode and 1024 bytes
|
||||
otherwise. */
|
||||
#define POSIXBLK -2
|
||||
|
||||
#define BLOCKSIZE(x) (((x) == POSIXBLK) ? (posixly_correct ? 512 : 1024) : (x))
|
||||
|
||||
extern int posixly_correct;
|
||||
|
||||
static int _findlim __P((int));
|
||||
|
||||
static int ulimit_internal __P((int, char *, int, int));
|
||||
|
|
@ -193,13 +207,19 @@ typedef struct {
|
|||
int option; /* The ulimit option for this limit. */
|
||||
int parameter; /* Parameter to pass to get_limit (). */
|
||||
int block_factor; /* Blocking factor for specific limit. */
|
||||
char *description; /* Descriptive string to output. */
|
||||
char *units; /* scale */
|
||||
const char * const description; /* Descriptive string to output. */
|
||||
const char * const units; /* scale */
|
||||
} RESOURCE_LIMITS;
|
||||
|
||||
static RESOURCE_LIMITS limits[] = {
|
||||
#ifdef RLIMIT_PTHREAD
|
||||
{ 'T', RLIMIT_PTHREAD, 1, "number of threads", (char *)NULL },
|
||||
#endif
|
||||
#ifdef RLIMIT_SBSIZE
|
||||
{ 'b', RLIMIT_SBSIZE, 1, "socket buffer size", "bytes" },
|
||||
#endif
|
||||
#ifdef RLIMIT_CORE
|
||||
{ 'c', RLIMIT_CORE, 1024, "core file size", "blocks" },
|
||||
{ 'c', RLIMIT_CORE, POSIXBLK, "core file size", "blocks" },
|
||||
#endif
|
||||
#ifdef RLIMIT_DATA
|
||||
{ 'd', RLIMIT_DATA, 1024, "data seg size", "kbytes" },
|
||||
|
|
@ -207,7 +227,7 @@ static RESOURCE_LIMITS limits[] = {
|
|||
#ifdef RLIMIT_NICE
|
||||
{ 'e', RLIMIT_NICE, 1, "scheduling priority", (char *)NULL },
|
||||
#endif
|
||||
{ 'f', RLIMIT_FILESIZE, 1024, "file size", "blocks" },
|
||||
{ 'f', RLIMIT_FILESIZE, POSIXBLK, "file size", "blocks" },
|
||||
#ifdef RLIMIT_SIGPENDING
|
||||
{ 'i', RLIMIT_SIGPENDING, 1, "pending signals", (char *)NULL },
|
||||
#endif
|
||||
|
|
@ -356,7 +376,7 @@ ulimit_builtin (list)
|
|||
}
|
||||
#endif
|
||||
print_all_limits (mode == 0 ? LIMIT_SOFT : mode);
|
||||
return (EXECUTION_SUCCESS);
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
/* default is `ulimit -f' */
|
||||
|
|
@ -425,12 +445,12 @@ ulimit_internal (cmd, cmdarg, mode, multiple)
|
|||
else if (all_digits (cmdarg))
|
||||
{
|
||||
limit = string_to_rlimtype (cmdarg);
|
||||
block_factor = limits[limind].block_factor;
|
||||
block_factor = BLOCKSIZE(limits[limind].block_factor);
|
||||
real_limit = limit * block_factor;
|
||||
|
||||
if ((real_limit / block_factor) != limit)
|
||||
{
|
||||
sh_erange (cmdarg, "limit");
|
||||
sh_erange (cmdarg, _("limit"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
|
|
@ -687,7 +707,9 @@ printone (limind, curlim, pdesc)
|
|||
int pdesc;
|
||||
{
|
||||
char unitstr[64];
|
||||
int factor;
|
||||
|
||||
factor = BLOCKSIZE(limits[limind].block_factor);
|
||||
if (pdesc)
|
||||
{
|
||||
if (limits[limind].units)
|
||||
|
|
@ -704,7 +726,7 @@ printone (limind, curlim, pdesc)
|
|||
else if (curlim == RLIM_SAVED_CUR)
|
||||
puts ("soft");
|
||||
else
|
||||
print_rlimtype ((curlim / limits[limind].block_factor), 1);
|
||||
print_rlimtype ((curlim / factor), 1);
|
||||
}
|
||||
|
||||
/* Set all limits to NEWLIM. NEWLIM currently must be RLIM_INFINITY, which
|
||||
|
|
@ -740,7 +762,7 @@ set_all_limits (mode, newlim)
|
|||
for (retval = i = 0; limits[i].option > 0; i++)
|
||||
if (set_limit (i, newlim, mode) < 0)
|
||||
{
|
||||
builtin_error ("%s: cannot modify limit: %s", limits[i].description,
|
||||
builtin_error (_("%s: cannot modify limit: %s"), limits[i].description,
|
||||
strerror (errno));
|
||||
retval = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,36 +1,42 @@
|
|||
This file is umask.def, from which is created umask.c.
|
||||
It implements the builtin "umask" in Bash.
|
||||
|
||||
Copyright (C) 1987-2004 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 umask.c
|
||||
|
||||
$BUILTIN umask
|
||||
$FUNCTION umask_builtin
|
||||
$SHORT_DOC umask [-p] [-S] [mode]
|
||||
The user file-creation mask is set to MODE. If MODE is omitted, or if
|
||||
`-S' is supplied, the current value of the mask is printed. The `-S'
|
||||
option makes the output symbolic; otherwise an octal number is output.
|
||||
If `-p' is supplied, and MODE is omitted, the output is in a form
|
||||
that may be used as input. If MODE begins with a digit, it is
|
||||
interpreted as an octal number, otherwise it is a symbolic mode string
|
||||
like that accepted by chmod(1).
|
||||
Display or set file mode mask.
|
||||
|
||||
Sets the user file-creation mask to MODE. If MODE is omitted, prints
|
||||
the current value of the mask.
|
||||
|
||||
If MODE begins with a digit, it is interpreted as an octal number;
|
||||
otherwise it is a symbolic mode string like that accepted by chmod(1).
|
||||
|
||||
Options:
|
||||
-p if MODE is omitted, output in a form that may be reused as input
|
||||
-S makes the output symbolic; otherwise an octal number is output
|
||||
|
||||
Exit Status:
|
||||
Returns success unless MODE is invalid or an invalid option is given.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -137,8 +143,7 @@ umask_builtin (list)
|
|||
printf ("%04lo\n", (unsigned long)umask_arg);
|
||||
}
|
||||
|
||||
fflush (stdout);
|
||||
return (EXECUTION_SUCCESS);
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
/* Print the umask in a symbolic form. In the output, a letter is
|
||||
|
|
|
|||
|
|
@ -1,44 +1,54 @@
|
|||
This file is wait.def, from which is created wait.c.
|
||||
It implements the builtin "wait" in Bash.
|
||||
|
||||
Copyright (C) 1987-2005 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/>.
|
||||
|
||||
$BUILTIN wait
|
||||
$FUNCTION wait_builtin
|
||||
$DEPENDS_ON JOB_CONTROL
|
||||
$PRODUCES wait.c
|
||||
$SHORT_DOC wait [n]
|
||||
Wait for the specified process and report its termination status. If
|
||||
N is not given, all currently active child processes are waited for,
|
||||
and the return code is zero. N may be a process ID or a job
|
||||
specification; if a job spec is given, all processes in the job's
|
||||
pipeline are waited for.
|
||||
$SHORT_DOC wait [id]
|
||||
Wait for job completion and return exit status.
|
||||
|
||||
Waits for the process identified by ID, which may be a process ID or a
|
||||
job specification, and reports its termination status. If ID is not
|
||||
given, waits for all currently active child processes, and the return
|
||||
status is zero. If ID is a a job specification, waits for all processes
|
||||
in the job's pipeline.
|
||||
|
||||
Exit Status:
|
||||
Returns the status of ID; fails if ID is invalid or an invalid option is
|
||||
given.
|
||||
$END
|
||||
|
||||
$BUILTIN wait
|
||||
$FUNCTION wait_builtin
|
||||
$DEPENDS_ON !JOB_CONTROL
|
||||
$SHORT_DOC wait [n]
|
||||
Wait for the specified process and report its termination status. If
|
||||
N is not given, all currently active child processes are waited for,
|
||||
and the return code is zero. N is a process ID; if it is not given,
|
||||
all child processes of the shell are waited for.
|
||||
$SHORT_DOC wait [pid]
|
||||
Wait for process completion and return exit status.
|
||||
|
||||
Waits for the specified process and reports its termination status. If
|
||||
PID is not given, all currently active child processes are waited for,
|
||||
and the return code is zero. PID must be a process ID.
|
||||
|
||||
Exit Status:
|
||||
Returns the status of ID; fails if ID is invalid or an invalid option is
|
||||
given.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue