Adding upstream version 5.2.37.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
This commit is contained in:
parent
cf91100bce
commit
fa1b3d3922
1435 changed files with 757174 additions and 0 deletions
466
AUTHORS
Normal file
466
AUTHORS
Normal file
|
@ -0,0 +1,466 @@
|
|||
#
|
||||
# Master author manifest for bash
|
||||
#
|
||||
# The files in lib/intl were taken from the GNU gettext distribution.
|
||||
#
|
||||
# Any files appearing in the bash distribution not listed in this file
|
||||
# were created by Chet Ramey.
|
||||
#
|
||||
# Filename authors (first is original author)
|
||||
#
|
||||
README Brian Fox, Chet Ramey
|
||||
INSTALL Brian Fox, Chet Ramey
|
||||
COPYING Brian Fox, Chet Ramey
|
||||
MANIFEST Brian Fox, Chet Ramey
|
||||
configure Chet Ramey
|
||||
Makefile.in Brian Fox, Chet Ramey
|
||||
configure.in Chet Ramey
|
||||
aclocal.m4 Chet Ramey
|
||||
config.h.top Chet Ramey
|
||||
config.h.bot Chet Ramey
|
||||
config.h.in Chet Ramey
|
||||
array.c Chet Ramey
|
||||
print_cmd.c Brian Fox, Chet Ramey
|
||||
general.c Brian Fox, Chet Ramey
|
||||
variables.c Brian Fox, Chet Ramey
|
||||
make_cmd.c Brian Fox, Chet Ramey
|
||||
copy_cmd.c Brian Fox, Chet Ramey
|
||||
unwind_prot.c Brian Fox, Chet Ramey
|
||||
dispose_cmd.c Brian Fox, Chet Ramey
|
||||
getcwd.c Roland McGrath, Brian Fox, Chet Ramey
|
||||
bashhist.c Chet Ramey
|
||||
hash.c Brian Fox, Chet Ramey
|
||||
parse.y Brian Fox, Chet Ramey
|
||||
subst.c Brian Fox, Chet Ramey
|
||||
shell.c Brian Fox, Chet Ramey
|
||||
sig.c Chet Ramey
|
||||
trap.c Brian Fox, Chet Ramey
|
||||
siglist.c Brian Fox, Chet Ramey
|
||||
version.c Brian Fox, Chet Ramey
|
||||
flags.c Brian Fox, Chet Ramey
|
||||
jobs.c Brian Fox, Chet Ramey
|
||||
input.c Chet Ramey
|
||||
mailcheck.c Brian Fox, Chet Ramey
|
||||
pathexp.c Chet Ramey
|
||||
test.c Brian Fox, Chet Ramey
|
||||
expr.c Chet Ramey, Brian Fox
|
||||
alias.c Brian Fox, Chet Ramey
|
||||
execute_cmd.c Brian Fox, Chet Ramey
|
||||
bashline.c Brian Fox, Chet Ramey
|
||||
braces.c Brian Fox, Chet Ramey
|
||||
bracecomp.c Brian Fox, Chet Ramey, Tom Tromey
|
||||
nojobs.c Brian Fox, Chet Ramey
|
||||
vprint.c Chet Ramey
|
||||
oslib.c Chet Ramey
|
||||
error.c Brian Fox, Chet Ramey
|
||||
xmalloc.c Brian Fox, Chet Ramey
|
||||
alias.h Brian Fox, Chet Ramey
|
||||
array.h Chet Ramey
|
||||
builtins.h Brian Fox, Chet Ramey
|
||||
parser.h Brian Fox, Chet Ramey
|
||||
variables.h Brian Fox, Chet Ramey
|
||||
machines.h Brian Fox, Chet Ramey
|
||||
jobs.h Brian Fox, Chet Ramey
|
||||
maxpath.h Brian Fox, Chet Ramey
|
||||
pathexp.h Chet Ramey
|
||||
mailcheck.h Chet Ramey
|
||||
filecntl.h Brian Fox, Chet Ramey
|
||||
hash.h Brian Fox, Chet Ramey
|
||||
quit.h Brian Fox, Chet Ramey
|
||||
flags.h Brian Fox, Chet Ramey
|
||||
shell.h Brian Fox, Chet Ramey
|
||||
bashjmp.h Chet Ramey
|
||||
sig.h Chet Ramey
|
||||
trap.h Brian Fox, Chet Ramey
|
||||
general.h Brian Fox, Chet Ramey
|
||||
unwind_prot.h Brian Fox, Chet Ramey
|
||||
input.h Brian Fox, Chet Ramey
|
||||
error.h Brian Fox, Chet Ramey
|
||||
command.h Brian Fox, Chet Ramey
|
||||
externs.h Chet Ramey
|
||||
siglist.h Chet Ramey
|
||||
subst.h Brian Fox, Chet Ramey
|
||||
dispose_cmd.h Brian Fox, Chet Ramey
|
||||
bashansi.h Brian Fox, Chet Ramey
|
||||
make_cmd.h Brian Fox, Chet Ramey
|
||||
bashhist.h Chet Ramey
|
||||
bashline.h Chet Ramey
|
||||
execute_cmd.h Chet Ramey
|
||||
bashtypes.h Chet Ramey
|
||||
bashtty.h Chet Ramey
|
||||
pathnames.h Chet Ramey
|
||||
y.tab.c Brian Fox, Chet Ramey
|
||||
y.tab.h Brian Fox, Chet Ramey
|
||||
parser-built Brian Fox, Chet Ramey
|
||||
posixstat.h Brian Fox, Chet Ramey
|
||||
stdc.h Chet Ramey
|
||||
ansi_stdlib.h Brian Fox, Chet Ramey
|
||||
memalloc.h Chet Ramey
|
||||
builtins/ChangeLog Brian Fox, Chet Ramey
|
||||
builtins/Makefile.in Brian Fox, Chet Ramey
|
||||
builtins/alias.def Brian Fox, Chet Ramey
|
||||
builtins/bind.def Brian Fox, Chet Ramey
|
||||
builtins/break.def Brian Fox, Chet Ramey
|
||||
builtins/builtin.def Brian Fox, Chet Ramey
|
||||
builtins/caller.def Rocky Bernstein, Chet Ramey
|
||||
builtins/cd.def Brian Fox, Chet Ramey
|
||||
builtins/colon.def Brian Fox, Chet Ramey
|
||||
builtins/command.def Brian Fox, Chet Ramey
|
||||
builtins/common.c Brian Fox, Chet Ramey
|
||||
builtins/declare.def Brian Fox, Chet Ramey
|
||||
builtins/echo.def Brian Fox, Chet Ramey
|
||||
builtins/enable.def Brian Fox, Chet Ramey
|
||||
builtins/eval.def Brian Fox, Chet Ramey
|
||||
builtins/exec.def Brian Fox, Chet Ramey
|
||||
builtins/exit.def Brian Fox, Chet Ramey
|
||||
builtins/fc.def Brian Fox, Chet Ramey
|
||||
builtins/fg_bg.def Brian Fox, Chet Ramey
|
||||
builtins/getopt.c Roland McGrath, Brian Fox, Chet Ramey
|
||||
builtins/getopt.h Roland McGrath, Brian Fox, Chet Ramey
|
||||
builtins/getopts.def Brian Fox, Chet Ramey
|
||||
builtins/hash.def Brian Fox, Chet Ramey
|
||||
builtins/hashcom.h Brian Fox, Chet Ramey
|
||||
builtins/help.def Brian Fox, Chet Ramey
|
||||
builtins/let.def Chet Ramey, Brian Fox
|
||||
builtins/history.def Brian Fox, Chet Ramey
|
||||
builtins/jobs.def Brian Fox, Chet Ramey
|
||||
builtins/kill.def Brian Fox, Chet Ramey
|
||||
builtins/mapfile.def Rocky Bernstein
|
||||
builtins/mkbuiltins.c Brian Fox, Chet Ramey
|
||||
builtins/pushd.def Brian Fox, Chet Ramey
|
||||
builtins/read.def Brian Fox, Chet Ramey
|
||||
builtins/reserved.def Brian Fox, Chet Ramey
|
||||
builtins/return.def Brian Fox, Chet Ramey
|
||||
builtins/set.def Brian Fox, Chet Ramey
|
||||
builtins/setattr.def Brian Fox, Chet Ramey
|
||||
builtins/shift.def Brian Fox, Chet Ramey
|
||||
builtins/shopt.def Chet Ramey
|
||||
builtins/source.def Brian Fox, Chet Ramey
|
||||
builtins/suspend.def Brian Fox, Chet Ramey
|
||||
builtins/test.def Brian Fox, Chet Ramey
|
||||
builtins/times.def Brian Fox, Chet Ramey
|
||||
builtins/trap.def Brian Fox, Chet Ramey
|
||||
builtins/type.def Brian Fox, Chet Ramey
|
||||
builtins/ulimit.def Chet Ramey, Brian Fox
|
||||
builtins/umask.def Brian Fox, Chet Ramey
|
||||
builtins/wait.def Brian Fox, Chet Ramey
|
||||
builtins/psize.c Chet Ramey, Brian Fox
|
||||
builtins/psize.sh Chet Ramey, Brian Fox
|
||||
builtins/inlib.def Chet Ramey
|
||||
builtins/bashgetopt.c Chet Ramey
|
||||
builtins/common.h Chet Ramey
|
||||
builtins/bashgetopt.h Chet Ramey
|
||||
lib/doc-support/texindex.c bug-texinfo@prep.ai.mit.edu, Chet Ramey
|
||||
lib/doc-support/Makefile.in Chet Ramey
|
||||
lib/doc-support/getopt.h Roland McGrath
|
||||
lib/doc-support/getopt.c Roland McGrath
|
||||
lib/doc-support/getopt1.c Roland McGrath
|
||||
lib/glob/ChangeLog Brian Fox, Chet Ramey
|
||||
lib/glob/Makefile.in Brian Fox, Chet Ramey
|
||||
lib/glob/strmatch.c Roland McGrath, Brian Fox, Chet Ramey
|
||||
lib/glob/strmatch.h Roland McGrath, Brian Fox, Chet Ramey
|
||||
lib/glob/glob.c Richard Stallman, Roland McGrath, Brian Fox, Chet Ramey
|
||||
lib/glob/glob.h Chet Ramey
|
||||
lib/glob/ndir.h Doug Gwyn, Richard Stallman
|
||||
lib/glob/doc/Makefile.in Brian Fox, Chet Ramey
|
||||
lib/glob/doc/glob.texi Brian Fox, Chet Ramey
|
||||
lib/malloc/Makefile.in Chet Ramey
|
||||
lib/malloc/alloca.c Doug Gwyn, Richard Stallman, Brian Fox, Chet Ramey
|
||||
lib/malloc/getpagesize.h Brian Fox, Chet Ramey
|
||||
lib/malloc/malloc.c Chris Kingsley, Mike Muuss, Richard Stallman, Brian Fox, Chet Ramey
|
||||
lib/malloc/gmalloc.c Mike Haertel, Roland McGrath
|
||||
lib/malloc/stub.c Chet Ramey
|
||||
lib/malloc/i386-alloca.s Richard Stallman
|
||||
lib/malloc/x386-alloca.s Chip Salzenberg, Richard Stallman
|
||||
lib/malloc/xmalloc.c Brian Fox, Chet Ramey
|
||||
lib/posixheaders/posixstat.h Brian Fox, Chet Ramey
|
||||
lib/posixheaders/ansi_stdlib.h Brian Fox, Chet Ramey
|
||||
lib/posixheaders/stdc.h Chet Ramey
|
||||
lib/posixheaders/memalloc.h Chet Ramey
|
||||
lib/posixheaders/filecntl.h Brian Fox, Chet Ramey
|
||||
lib/readline/Makefile.in Brian Fox, Chet Ramey
|
||||
lib/readline/COPYING Brian Fox, Chet Ramey
|
||||
lib/readline/ChangeLog Brian Fox, Chet Ramey
|
||||
lib/readline/readline.c Brian Fox, Chet Ramey
|
||||
lib/readline/vi_mode.c Brian Fox, Chet Ramey
|
||||
lib/readline/emacs_keymap.c Brian Fox, Chet Ramey
|
||||
lib/readline/vi_keymap.c Brian Fox, Chet Ramey
|
||||
lib/readline/funmap.c Brian Fox, Chet Ramey
|
||||
lib/readline/keymaps.c Brian Fox, Chet Ramey
|
||||
lib/readline/xmalloc.c Brian Fox, Chet Ramey
|
||||
lib/readline/search.c Brian Fox, Chet Ramey
|
||||
lib/readline/isearch.c Brian Fox, Chet Ramey
|
||||
lib/readline/parens.c Brian Fox, Chet Ramey
|
||||
lib/readline/rltty.c Brian Fox, Chet Ramey
|
||||
lib/readline/complete.c Brian Fox, Chet Ramey
|
||||
lib/readline/bind.c Brian Fox, Chet Ramey
|
||||
lib/readline/display.c Brian Fox, Chet Ramey
|
||||
lib/readline/signals.c Brian Fox, Chet Ramey
|
||||
lib/readline/kill.c Brian Fox, Chet Ramey
|
||||
lib/readline/undo.c Brian Fox, Chet Ramey
|
||||
lib/readline/input.c Brian Fox, Chet Ramey
|
||||
lib/readline/macro.c Brian Fox, Chet Ramey
|
||||
lib/readline/util.c Brian Fox, Chet Ramey
|
||||
lib/readline/callback.c Chet Ramey
|
||||
lib/readline/readline.h Brian Fox, Chet Ramey
|
||||
lib/readline/chardefs.h Brian Fox, Chet Ramey
|
||||
lib/readline/keymaps.h Brian Fox, Chet Ramey
|
||||
lib/readline/rldefs.h Brian Fox, Chet Ramey
|
||||
lib/readline/posixstat.h Brian Fox, Chet Ramey
|
||||
lib/readline/ansi_stdlib.h Brian Fox, Chet Ramey
|
||||
lib/readline/memalloc.h Chet Ramey
|
||||
lib/readline/rlconf.h Chet Ramey
|
||||
lib/readline/rltty.h Chet Ramey
|
||||
lib/readline/history.c Brian Fox, Chet Ramey
|
||||
lib/readline/histexpand.c Brian Fox, Chet Ramey
|
||||
lib/readline/histfile.c Brian Fox, Chet Ramey
|
||||
lib/readline/histsearch.c Brian Fox, Chet Ramey
|
||||
lib/readline/history.h Brian Fox, Chet Ramey
|
||||
lib/readline/histlib.h Brian Fox, Chet Ramey
|
||||
lib/readline/tilde.c Brian Fox, Chet Ramey
|
||||
lib/readline/tilde.h Brian Fox, Chet Ramey
|
||||
lib/readline/doc/texindex.c bug-texinfo@prep.ai.mit.edu, Chet Ramey
|
||||
lib/readline/doc/Makefile Brian Fox, Chet Ramey
|
||||
lib/readline/doc/rlman.texinfo Brian Fox, Chet Ramey
|
||||
lib/readline/doc/rltech.texinfo Brian Fox, Chet Ramey
|
||||
lib/readline/doc/rluser.texinfo Brian Fox, Chet Ramey
|
||||
lib/readline/doc/hist.texinfo Brian Fox, Chet Ramey
|
||||
lib/readline/doc/hstech.texinfo Brian Fox, Chet Ramey
|
||||
lib/readline/doc/hsuser.texinfo Brian Fox, Chet Ramey
|
||||
lib/readline/examples/Makefile Brian Fox
|
||||
lib/readline/examples/fileman.c Brian Fox
|
||||
lib/readline/examples/manexamp.c Brian Fox
|
||||
lib/readline/examples/histexamp.c Brian Fox, Chet Ramey
|
||||
lib/readline/examples/rltest.c Brian Fox, Chet Ramey
|
||||
lib/readline/examples/Inputrc Brian Fox, Chet Ramey
|
||||
lib/termcap/Makefile.in David MacKenzie, Chet Ramey
|
||||
lib/termcap/termcap.c David MacKenzie
|
||||
lib/termcap/termcap.h David MacKenzie
|
||||
lib/termcap/tparam.c David MacKenzie
|
||||
lib/termcap/version.c David MacKenzie
|
||||
lib/termcap/grot/termcap.info David MacKenzie
|
||||
lib/termcap/grot/termcap.info-1 David MacKenzie
|
||||
lib/termcap/grot/termcap.info-2 David MacKenzie
|
||||
lib/termcap/grot/termcap.info-3 David MacKenzie
|
||||
lib/termcap/grot/termcap.info-4 David MacKenzie
|
||||
lib/termcap/grot/NEWS David MacKenzie
|
||||
lib/termcap/grot/INSTALL David MacKenzie
|
||||
lib/termcap/grot/ChangeLog David MacKenzie
|
||||
lib/termcap/grot/texinfo.tex David MacKenzie
|
||||
lib/termcap/grot/termcap.texi David MacKenzie
|
||||
lib/termcap/grot/Makefile.in David MacKenzie
|
||||
lib/termcap/grot/configure David MacKenzie
|
||||
lib/termcap/grot/configure.in David MacKenzie
|
||||
lib/termcap/grot/COPYING David MacKenzie
|
||||
lib/termcap/grot/README David MacKenzie
|
||||
lib/tilde/ChangeLog Brian Fox, Chet Ramey
|
||||
lib/tilde/Makefile.in Brian Fox, Chet Ramey
|
||||
lib/tilde/doc/tilde.texi Brian Fox, Chet Ramey
|
||||
lib/tilde/doc/Makefile Brian Fox, Chet Ramey
|
||||
lib/tilde/tilde.c Brian Fox, Chet Ramey
|
||||
lib/tilde/tilde.h Brian Fox, Chet Ramey
|
||||
lib/tilde/memalloc.h Brian Fox, Chet Ramey
|
||||
CWRU/misc/open-files.c Chet Ramey
|
||||
CWRU/misc/sigs.c Chet Ramey
|
||||
CWRU/misc/pid.c Chet Ramey
|
||||
CWRU/misc/sigstat.c Chet Ramey
|
||||
CWRU/misc/bison Chet Ramey
|
||||
CWRU/misc/aux-machine-desc Chet Ramey
|
||||
CWRU/PLATFORMS Chet Ramey
|
||||
CWRU/README Chet Ramey
|
||||
CWRU/CWRU.CHANGES.051093 Chet Ramey
|
||||
CWRU/POSIX.NOTES Chet Ramey
|
||||
CWRU/CWRU.CHANGES.071193 Chet Ramey
|
||||
CWRU/CWRU.CHANGES.090393 Chet Ramey
|
||||
doc/Makefile.in Brian Fox, Chet Ramey
|
||||
doc/bash.1 Chet Ramey
|
||||
doc/builtins.1 Chet Ramey
|
||||
doc/bash.ps Chet Ramey
|
||||
doc/bash.txt Chet Ramey
|
||||
doc/readline.3 Chet Ramey
|
||||
doc/readline.ps Chet Ramey
|
||||
doc/readline.txt Chet Ramey
|
||||
doc/texinfo.tex Richard Stallman
|
||||
doc/features.texi Brian Fox, Chet Ramey
|
||||
doc/features.ps Brian Fox, Chet Ramey
|
||||
doc/features.info Brian Fox, Chet Ramey
|
||||
doc/features.dvi Brian Fox, Chet Ramey
|
||||
doc/bash_builtins.1 Chet Ramey
|
||||
doc/bash_builtins.ps Chet Ramey
|
||||
doc/bash_builtins.txt Chet Ramey
|
||||
doc/bash_builtins.readme Chet Ramey
|
||||
doc/article.ms Chet Ramey
|
||||
doc/FAQ Chet Ramey
|
||||
support/cat-s Brian Fox, Chet Ramey
|
||||
support/mksysdefs Brian Fox, Chet Ramey
|
||||
support/mkversion.c Brian Fox, Chet Ramey
|
||||
support/mksignames.c Brian Fox, Chet Ramey
|
||||
support/getcppsyms.c Brian Fox, Chet Ramey
|
||||
support/cppmagic Brian Fox, Chet Ramey
|
||||
support/pagesize.sh Chet Ramey, Brian Fox
|
||||
support/pagesize.c Chet Ramey, Brian Fox
|
||||
support/bash.xbm Brian Fox
|
||||
support/FAQ Brian Fox
|
||||
support/PORTING Brian Fox
|
||||
support/mklinks Brian Fox
|
||||
support/fixlinks Chet Ramey
|
||||
support/mkdirs Chet Ramey
|
||||
support/clone-bash Chet Ramey
|
||||
support/bashbug.sh Chet Ramey
|
||||
support/mkmachtype Chet Ramey
|
||||
support/recho.c Chet Ramey
|
||||
support/config.guess Per Bothner, Chet Ramey
|
||||
support/config.sub Richard Stallman, Chet Ramey
|
||||
support/install.sh MIT X Consortium (X11R5)
|
||||
support/endian.c Chet Ramey
|
||||
support/printenv Chet Ramey
|
||||
examples/precedence-tester Brian Fox, Chet Ramey
|
||||
examples/functions/substr Brian Fox, Chet Ramey
|
||||
examples/functions/kshenv Chet Ramey
|
||||
examples/functions/autoload Chet Ramey
|
||||
examples/functions/csh-compat Brian Fox, Chet Ramey
|
||||
examples/functions/shcat Chet Ramey
|
||||
examples/functions/substr2 Chet Ramey
|
||||
examples/functions/term Chet Ramey
|
||||
examples/functions/whatis Chet Ramey
|
||||
examples/functions/whence Chet Ramey
|
||||
examples/functions/func Chet Ramey
|
||||
examples/functions/dirname Brian Fox, Noah Friedman
|
||||
examples/functions/basename Brian Fox, Noah Friedman
|
||||
examples/functions/exitstat Noah Friedman, Roland McGrath
|
||||
examples/functions/external Noah Friedman
|
||||
examples/functions/fact Brian Fox
|
||||
examples/functions/manpage Tom Tromey
|
||||
examples/functions/fstty Chet Ramey
|
||||
examples/functions/jj.bash Chet Ramey
|
||||
examples/functions/notify.bash Chet Ramey
|
||||
examples/loadables/getconf.c J.T. Conklin
|
||||
examples/scripts/shprompt Chet Ramey
|
||||
examples/scripts/adventure.sh Chet Ramey, Doug Gwyn
|
||||
examples/scripts/bcsh.sh Chris Robertson, Chet Ramey
|
||||
examples/startup-files/Bashrc Brian Fox
|
||||
examples/startup-files/Bash_aliases Brian Fox
|
||||
examples/startup-files/Bash_profile Brian Fox
|
||||
examples/startup-files/bash-profile Brian Fox
|
||||
examples/startup-files/bashrc Chet Ramey
|
||||
examples/suncmd.termcap Brian Fox, Chet Ramey
|
||||
examples/alias-conv.sh Brian Fox, Chet Ramey
|
||||
tests/README Chet Ramey
|
||||
tests/arith.tests Chet Ramey
|
||||
tests/arith.right Chet Ramey
|
||||
tests/array.tests Chet Ramey
|
||||
tests/array.right Chet Ramey
|
||||
tests/dollar-at.sh Chet Ramey
|
||||
tests/dollar-star.sh Chet Ramey
|
||||
tests/dollar.right Chet Ramey
|
||||
tests/exp-tests Chet Ramey
|
||||
tests/exp.right Chet Ramey
|
||||
tests/glob-test Chet Ramey
|
||||
tests/glob.right Chet Ramey
|
||||
tests/ifs-test-1.sh Chet Ramey
|
||||
tests/ifs-test-2.sh Chet Ramey
|
||||
tests/ifs-test-3.sh Chet Ramey
|
||||
tests/ifs.1.right Chet Ramey
|
||||
tests/ifs.2.right Chet Ramey
|
||||
tests/ifs.3.right Chet Ramey
|
||||
tests/input-line.sh Chet Ramey
|
||||
tests/input-line.sub Chet Ramey
|
||||
tests/input.right Chet Ramey
|
||||
tests/minus-e Chet Ramey
|
||||
tests/minus-e.right Chet Ramey
|
||||
tests/new-exp.tests Chet Ramey
|
||||
tests/new-exp.right Chet Ramey
|
||||
tests/prec.right Chet Ramey
|
||||
tests/precedence Chet Ramey
|
||||
tests/run-all Chet Ramey
|
||||
tests/run-dollars Chet Ramey
|
||||
tests/run-exp-tests Chet Ramey
|
||||
tests/run-glob-test Chet Ramey
|
||||
tests/run-ifs-tests Chet Ramey
|
||||
tests/run-input-test Chet Ramey
|
||||
tests/run-minus-e Chet Ramey
|
||||
tests/run-new-exp Chet Ramey
|
||||
tests/run-precedence Chet Ramey
|
||||
tests/run-set-e-test Chet Ramey
|
||||
tests/run-strip Chet Ramey
|
||||
tests/run-varenv Chet Ramey
|
||||
tests/set-e-test Chet Ramey
|
||||
tests/set-e.right Chet Ramey
|
||||
tests/strip.tests Chet Ramey
|
||||
tests/strip.right Chet Ramey
|
||||
tests/tilde-tests Chet Ramey
|
||||
tests/tilde.right Chet Ramey
|
||||
tests/unicode1.sub Chet Ramey, John Kearney
|
||||
tests/varenv.right Chet Ramey
|
||||
tests/varenv.sh Chet Ramey
|
||||
tests/misc/chld-trap.sh Chet Ramey
|
||||
tests/misc/dot-test-1.sh Chet Ramey
|
||||
tests/misc/dot-test-1.sub Chet Ramey
|
||||
tests/misc/gotest Chet Ramey
|
||||
tests/misc/perf-script Chet Ramey
|
||||
tests/misc/redir.t1.sh Chet Ramey
|
||||
tests/misc/redir.t2.sh Chet Ramey
|
||||
tests/misc/redir.t3.sh Chet Ramey
|
||||
tests/misc/redir.t3.sub Chet Ramey
|
||||
tests/misc/redir.t4.sh Chet Ramey
|
||||
tests/misc/run.r1.sh Chet Ramey
|
||||
tests/misc/run.r2.sh Chet Ramey
|
||||
tests/misc/run.r3.sh Chet Ramey
|
||||
tests/misc/sigint.t1.sh Chet Ramey
|
||||
tests/misc/sigint.t2.sh Chet Ramey
|
||||
tests/misc/sigint.t3.sh Chet Ramey
|
||||
tests/misc/sigint.t4.sh Chet Ramey
|
||||
tests/misc/test-minus-e.1 Chet Ramey
|
||||
tests/misc/test-minus-e.2 Chet Ramey
|
||||
lib/sh/Makefile.in Chet Ramey
|
||||
lib/sh/clktck.c Chet Ramey
|
||||
lib/sh/clock.c Chet Ramey
|
||||
lib/sh/fmtullong.c Chet Ramey
|
||||
lib/sh/fmtulong.c Chet Ramey
|
||||
lib/sh/getcwd.c Chet Ramey, Roland McGrath
|
||||
lib/sh/getenv.c Chet Ramey, Brian Fox
|
||||
lib/sh/inet_aton.c Chet Ramey, Ulrich Drepper, Paul Vixie
|
||||
lib/sh/itos.c Chet Ramey
|
||||
lib/sh/mailstat.c Chet Ramey
|
||||
lib/sh/makepath.c Chet Ramey
|
||||
lib/sh/mktime.c Chet Ramey, Paul Eggert
|
||||
lib/sh/netconn.c Chet Ramey
|
||||
lib/sh/netopen.c Chet Ramey
|
||||
lib/sh/oslib.c Chet Ramey, Brian Fox
|
||||
lib/sh/pathcanon.c Chet Ramey
|
||||
lib/sh/pathphys.c Chet Ramey
|
||||
lib/sh/rename.c Chet Ramey
|
||||
lib/sh/setlinebuf.c Chet Ramey, Brian Fox
|
||||
lib/sh/shquote.c Chet Ramey
|
||||
lib/sh/shtty.c Chet Ramey
|
||||
lib/sh/snprintf.c Chet Ramey, Unknown
|
||||
lib/sh/spell.c Chet Ramey
|
||||
lib/sh/strcasecmp.c Chet Ramey, Brian Fox
|
||||
lib/sh/strerror.c Chet Ramey, Brian Fox
|
||||
lib/sh/strftime.c Arnold Robbins
|
||||
lib/sh/strindex.c Chet Ramey
|
||||
lib/sh/stringlist.c Chet Ramey
|
||||
lib/sh/stringvec.c Chet Ramey
|
||||
lib/sh/strpbrk.c Roland McGrath
|
||||
lib/sh/strtod.c Chet Ramey, Roland McGrath
|
||||
lib/sh/strtoimax.c Chet Ramey, Paul Eggert
|
||||
lib/sh/strtol.c Chet Ramey, Paul Eggert
|
||||
lib/sh/strtoll.c Chet Ramey, Paul Eggert
|
||||
lib/sh/strtoul.c Chet Ramey, Paul Eggert
|
||||
lib/sh/strtoull.c Chet Ramey, Paul Eggert
|
||||
lib/sh/strtoumax.c Chet Ramey, Paul Eggert
|
||||
lib/sh/strtrans.c Chet Ramey
|
||||
lib/sh/times.c Chet Ramey, Brian Fox
|
||||
lib/sh/timeval.c Chet Ramey
|
||||
lib/sh/tmpfile.c Chet Ramey
|
||||
lib/sh/vprint.c Chet Ramey, Brian Fox
|
||||
lib/sh/xstrchr.c Chet Ramey, Mitsuru Chinen
|
||||
lib/sh/zread.c Chet Ramey
|
||||
lib/sh/zwrite.c Chet Ramey
|
||||
|
||||
tests/posix-ifs.sh Glenn Fowler
|
||||
|
||||
support/checkbashisms Julian Gilbey, Debian Linux team
|
||||
|
||||
lib/readline/colors.c Richard Stallman, David MacKenzie
|
||||
lib/readline/parse-colors.c Richard Stallman, David MacKenzie
|
596
COMPAT
Normal file
596
COMPAT
Normal file
|
@ -0,0 +1,596 @@
|
|||
Compatibility with previous versions
|
||||
====================================
|
||||
|
||||
This document details the incompatibilities between this version of bash,
|
||||
bash-5.2, and the previous widely-available versions, bash-3.2 (which is
|
||||
still the `standard' version for Mac OS X), 4.2/4.3 (which are still
|
||||
standard on a few Linux distributions), and bash-4.4/bash-5.0/bash-5.1,
|
||||
the current widely-available versions. These were discovered by users of
|
||||
bash-2.x through 5.x, so this list is not comprehensive. Some of these
|
||||
incompatibilities occur between the current version and versions 2.0 and
|
||||
above.
|
||||
|
||||
1. Bash uses a new quoting syntax, $"...", to do locale-specific
|
||||
string translation. Users who have relied on the (undocumented)
|
||||
behavior of bash-1.14 will have to change their scripts. For
|
||||
instance, if you are doing something like this to get the value of
|
||||
a variable whose name is the value of a second variable:
|
||||
|
||||
eval var2=$"$var1"
|
||||
|
||||
you will have to change to a different syntax.
|
||||
|
||||
This capability is directly supported by bash-2.0:
|
||||
|
||||
var2=${!var1}
|
||||
|
||||
This alternate syntax will work portably between bash-1.14 and bash-2.0:
|
||||
|
||||
eval var2=\$${var1}
|
||||
|
||||
2. One of the bugs fixed in the YACC grammar tightens up the rules
|
||||
concerning group commands ( {...} ). The `list' that composes the
|
||||
body of the group command must be terminated by a newline or
|
||||
semicolon. That's because the braces are reserved words, and are
|
||||
recognized as such only when a reserved word is legal. This means
|
||||
that while bash-1.14 accepted shell function definitions like this:
|
||||
|
||||
foo() { : }
|
||||
|
||||
bash-2.0 requires this:
|
||||
|
||||
foo() { :; }
|
||||
|
||||
This is also an issue for commands like this:
|
||||
|
||||
mkdir dir || { echo 'could not mkdir' ; exit 1; }
|
||||
|
||||
The syntax required by bash-2.0 is also accepted by bash-1.14.
|
||||
|
||||
3. The options to `bind' have changed to make them more consistent with
|
||||
the rest of the bash builtins. If you are using `bind -d' to list
|
||||
the readline key bindings in a form that can be re-read, use `bind -p'
|
||||
instead. If you were using `bind -v' to list the key bindings, use
|
||||
`bind -P' instead.
|
||||
|
||||
4. The `long' invocation options must now be prefixed by `--' instead
|
||||
of `-'. (The old form is still accepted, for the time being.)
|
||||
|
||||
5. There was a bug in the version of readline distributed with bash-1.14
|
||||
that caused it to write badly-formatted key bindings when using
|
||||
`bind -d'. The only key sequences that were affected are C-\ (which
|
||||
should appear as \C-\\ in a key binding) and C-" (which should appear
|
||||
as \C-\"). If these key sequences appear in your inputrc, as, for
|
||||
example,
|
||||
|
||||
"\C-\": self-insert
|
||||
|
||||
they will need to be changed to something like the following:
|
||||
|
||||
"\C-\\": self-insert
|
||||
|
||||
6. A number of people complained about having to use ESC to terminate an
|
||||
incremental search, and asked for an alternate mechanism. Bash-2.03
|
||||
uses the value of the settable readline variable `isearch-terminators'
|
||||
to decide which characters should terminate an incremental search. If
|
||||
that variable has not been set, ESC and Control-J will terminate a
|
||||
search.
|
||||
|
||||
7. Some variables have been removed: MAIL_WARNING, notify, history_control,
|
||||
command_oriented_history, glob_dot_filenames, allow_null_glob_expansion,
|
||||
nolinks, hostname_completion_file, noclobber, no_exit_on_failed_exec, and
|
||||
cdable_vars. Most of them are now implemented with the new `shopt'
|
||||
builtin; others were already implemented by `set'. Here is a list of
|
||||
correspondences:
|
||||
|
||||
MAIL_WARNING shopt mailwarn
|
||||
notify set -o notify
|
||||
history_control HISTCONTROL
|
||||
command_oriented_history shopt cmdhist
|
||||
glob_dot_filenames shopt dotglob
|
||||
allow_null_glob_expansion shopt nullglob
|
||||
nolinks set -o physical
|
||||
hostname_completion_file HOSTFILE
|
||||
noclobber set -o noclobber
|
||||
no_exit_on_failed_exec shopt execfail
|
||||
cdable_vars shopt cdable_vars
|
||||
|
||||
8. `ulimit' now sets both hard and soft limits and reports the soft limit
|
||||
by default (when neither -H nor -S is specified). This is compatible
|
||||
with versions of sh and ksh that implement `ulimit'. The bash-1.14
|
||||
behavior of, for example,
|
||||
|
||||
ulimit -c 0
|
||||
|
||||
can be obtained with
|
||||
|
||||
ulimit -S -c 0
|
||||
|
||||
It may be useful to define an alias:
|
||||
|
||||
alias ulimit="ulimit -S"
|
||||
|
||||
9. Bash-2.01 uses a new quoting syntax, $'...' to do ANSI-C string
|
||||
translation. Backslash-escaped characters in ... are expanded and
|
||||
replaced as specified by the ANSI C standard.
|
||||
|
||||
10. The sourcing of startup files has changed somewhat. This is explained
|
||||
more completely in the INVOCATION section of the manual page.
|
||||
|
||||
A non-interactive shell not named `sh' and not in posix mode reads
|
||||
and executes commands from the file named by $BASH_ENV. A
|
||||
non-interactive shell started by `su' and not in posix mode will read
|
||||
startup files. No other non-interactive shells read any startup files.
|
||||
|
||||
An interactive shell started in posix mode reads and executes commands
|
||||
from the file named by $ENV.
|
||||
|
||||
11. The <> redirection operator was changed to conform to the POSIX.2 spec.
|
||||
In the absence of any file descriptor specification preceding the `<>',
|
||||
file descriptor 0 is used. In bash-1.14, this was the behavior only
|
||||
when in POSIX mode. The bash-1.14 behavior may be obtained with
|
||||
|
||||
<>filename 1>&0
|
||||
|
||||
12. The `alias' builtin now checks for invalid options and takes a `-p'
|
||||
option to display output in POSIX mode. If you have old aliases beginning
|
||||
with `-' or `+', you will have to add the `--' to the alias command
|
||||
that declares them:
|
||||
|
||||
alias -x='chmod a-x' --> alias -- -x='chmod a-x'
|
||||
|
||||
13. The behavior of range specificiers within bracket matching expressions
|
||||
in the pattern matcher (e.g., [A-Z]) depends on the current locale,
|
||||
specifically the value of the LC_COLLATE environment variable. Setting
|
||||
this variable to C or POSIX will result in the traditional ASCII behavior
|
||||
for range comparisons. If the locale is set to something else, e.g.,
|
||||
en_US (specified by the LANG or LC_ALL variables), collation order is
|
||||
locale-dependent. For example, the en_US locale sorts the upper and
|
||||
lower case letters like this:
|
||||
|
||||
AaBb...Zz
|
||||
|
||||
so a range specification like [A-Z] will match every letter except `z'.
|
||||
Other locales collate like
|
||||
|
||||
aAbBcC...zZ
|
||||
|
||||
which means that [A-Z] matches every letter except `a'.
|
||||
|
||||
The portable way to specify upper case letters is [:upper:] instead of
|
||||
A-Z; lower case may be specified as [:lower:] instead of a-z.
|
||||
|
||||
Look at the manual pages for setlocale(3), strcoll(3), and, if it is
|
||||
present, locale(1).
|
||||
|
||||
You can find your current locale information by running locale(1):
|
||||
|
||||
caleb.ins.cwru.edu(2)$ locale
|
||||
LANG=en_US
|
||||
LC_CTYPE="en_US"
|
||||
LC_NUMERIC="en_US"
|
||||
LC_TIME="en_US"
|
||||
LC_COLLATE="en_US"
|
||||
LC_MONETARY="en_US"
|
||||
LC_MESSAGES="en_US"
|
||||
LC_ALL=en_US
|
||||
|
||||
My advice is to put
|
||||
|
||||
export LC_COLLATE=C
|
||||
|
||||
into /etc/profile and inspect any shell scripts run from cron for
|
||||
constructs like [A-Z]. This will prevent things like
|
||||
|
||||
rm [A-Z]*
|
||||
|
||||
from removing every file in the current directory except those beginning
|
||||
with `z' and still allow individual users to change the collation order.
|
||||
Users may put the above command into their own profiles as well, of course.
|
||||
|
||||
14. Bash versions up to 1.14.7 included an undocumented `-l' operator to
|
||||
the `test/[' builtin. It was a unary operator that expanded to the
|
||||
length of its string argument. This let you do things like
|
||||
|
||||
test -l $variable -lt 20
|
||||
|
||||
for example.
|
||||
|
||||
This was included for backwards compatibility with old versions of the
|
||||
Bourne shell, which did not provide an easy way to obtain the length of
|
||||
the value of a shell variable.
|
||||
|
||||
This operator is not part of the POSIX standard, because one can (and
|
||||
should) use ${#variable} to get the length of a variable's value.
|
||||
Bash-2.x does not support it.
|
||||
|
||||
15. Bash no longer auto-exports the HOME, PATH, SHELL, TERM, HOSTNAME,
|
||||
HOSTTYPE, MACHTYPE, or OSTYPE variables. If they appear in the initial
|
||||
environment, the export attribute will be set, but if bash provides a
|
||||
default value, they will remain local to the current shell.
|
||||
|
||||
16. Bash no longer initializes the FUNCNAME, GROUPS, or DIRSTACK variables
|
||||
to have special behavior if they appear in the initial environment.
|
||||
|
||||
17. Bash no longer removes the export attribute from the SSH_CLIENT or
|
||||
SSH2_CLIENT variables, and no longer attempts to discover whether or
|
||||
not it has been invoked by sshd in order to run the startup files.
|
||||
|
||||
18. Bash no longer requires that the body of a function be a group command;
|
||||
any compound command is accepted.
|
||||
|
||||
19. As of bash-3.0, the pattern substitution operators no longer perform
|
||||
quote removal on the pattern before attempting the match. This is the
|
||||
way the pattern removal functions behave, and is more consistent.
|
||||
|
||||
20. After bash-3.0 was released, I reimplemented tilde expansion, incorporating
|
||||
it into the mainline word expansion code. This fixes the bug that caused
|
||||
the results of tilde expansion to be re-expanded. There is one
|
||||
incompatibility: a ${paramOPword} expansion within double quotes will not
|
||||
perform tilde expansion on WORD. This is consistent with the other
|
||||
expansions, and what POSIX specifies.
|
||||
|
||||
21. A number of variables have the integer attribute by default, so the +=
|
||||
assignment operator returns expected results: RANDOM, LINENO, MAILCHECK,
|
||||
HISTCMD, OPTIND.
|
||||
|
||||
22. Bash-3.x is much stricter about $LINENO correctly reflecting the line
|
||||
number in a script; assignments to LINENO have little effect.
|
||||
|
||||
23. By default, readline binds the terminal special characters to their
|
||||
readline equivalents. As of bash-3.1/readline-5.1, this is optional and
|
||||
controlled by the bind-tty-special-chars readline variable.
|
||||
|
||||
24. The \W prompt string expansion abbreviates $HOME as `~'. The previous
|
||||
behavior is available with ${PWD##/*/}.
|
||||
|
||||
25. The arithmetic exponentiation operator is right-associative as of bash-3.1.
|
||||
|
||||
26. The rules concerning valid alias names are stricter, as per POSIX.2.
|
||||
|
||||
27. The Readline key binding functions now obey the convert-meta setting active
|
||||
when the binding takes place, as the dispatch code does when characters
|
||||
are read and processed.
|
||||
|
||||
28. The historical behavior of `trap' reverting signal disposition to the
|
||||
original handling in the absence of a valid first argument is implemented
|
||||
only if the first argument is a valid signal number.
|
||||
|
||||
29. In versions of bash after 3.1, the ${parameter//pattern/replacement}
|
||||
expansion does not interpret `%' or `#' specially. Those anchors don't
|
||||
have any real meaning when replacing every match.
|
||||
|
||||
30. Beginning with bash-3.1, the combination of posix mode and enabling the
|
||||
`xpg_echo' option causes echo to ignore all options, not looking for `-n'
|
||||
|
||||
31. Beginning with bash-3.2, bash follows the Bourne-shell-style (and POSIX-
|
||||
style) rules for parsing the contents of old-style backquoted command
|
||||
substitutions. Previous versions of bash attempted to recursively parse
|
||||
embedded quoted strings and shell constructs; bash-3.2 uses strict POSIX
|
||||
rules to find the closing backquote and simply passes the contents of the
|
||||
command substitution to a subshell for parsing and execution.
|
||||
|
||||
32. Beginning with bash-3.2, bash uses access(2) when executing primaries for
|
||||
the test builtin and the [[ compound command, rather than looking at the
|
||||
file permission bits obtained with stat(2). This obeys restrictions of
|
||||
the file system (e.g., read-only or noexec mounts) not available via stat.
|
||||
|
||||
33. Bash-3.2 adopts the convention used by other string and pattern matching
|
||||
operators for the `[[' compound command, and matches any quoted portion
|
||||
of the right-hand-side argument to the =~ operator as a string rather
|
||||
than a regular expression.
|
||||
|
||||
34. Bash-4.0 allows the behavior in the previous item to be modified using
|
||||
the notion of a shell `compatibility level'. If the compat31 shopt
|
||||
option is set, quoting the pattern has no special effect.
|
||||
|
||||
35. Bash-3.2 (patched) and Bash-4.0 fix a bug that leaves the shell in an
|
||||
inconsistent internal state following an assignment error. One of the
|
||||
changes means that compound commands or { ... } grouping commands are
|
||||
aborted under some circumstances in which they previously were not.
|
||||
This is what Posix specifies.
|
||||
|
||||
36. Bash-4.0 now allows process substitution constructs to pass unchanged
|
||||
through brace expansion, so any expansion of the contents will have to be
|
||||
separately specified, and each process substitution will have to be
|
||||
separately entered.
|
||||
|
||||
37. Bash-4.0 now allows SIGCHLD to interrupt the wait builtin, as Posix
|
||||
specifies, so the SIGCHLD trap is no longer always invoked once per
|
||||
exiting child if you are using `wait' to wait for all children. As
|
||||
of bash-4.2, this is the status quo only when in posix mode.
|
||||
|
||||
38. Since bash-4.0 now follows Posix rules for finding the closing delimiter
|
||||
of a $() command substitution, it will not behave as previous versions
|
||||
did, but will catch more syntax and parsing errors before spawning a
|
||||
subshell to evaluate the command substitution.
|
||||
|
||||
39. The programmable completion code uses the same set of delimiting characters
|
||||
as readline when breaking the command line into words, rather than the
|
||||
set of shell metacharacters, so programmable completion and readline
|
||||
should be more consistent.
|
||||
|
||||
40. When the read builtin times out, it attempts to assign any input read to
|
||||
specified variables, which also causes variables to be set to the empty
|
||||
string if there is not enough input. Previous versions discarded the
|
||||
characters read.
|
||||
|
||||
41. Beginning with bash-4.0, when one of the commands in a pipeline is killed
|
||||
by a SIGINT while executing a command list, the shell acts as if it
|
||||
received the interrupt. This can be disabled by setting the compat31 or
|
||||
compat32 shell options.
|
||||
|
||||
42. Bash-4.0 changes the handling of the set -e option so that the shell exits
|
||||
if a pipeline fails (and not just if the last command in the failing
|
||||
pipeline is a simple command). This is not as Posix specifies. There is
|
||||
work underway to update this portion of the standard; the bash-4.0
|
||||
behavior attempts to capture the consensus at the time of release.
|
||||
|
||||
43. Bash-4.0 fixes a Posix mode bug that caused the . (source) builtin to
|
||||
search the current directory for its filename argument, even if "." is
|
||||
not in $PATH. Posix says that the shell shouldn't look in $PWD in this
|
||||
case.
|
||||
|
||||
44. Bash-4.1 uses the current locale when comparing strings using the < and
|
||||
> operators to the `[[' command. This can be reverted to the previous
|
||||
behavior (ASCII collating and strcmp(3)) by setting one of the
|
||||
`compatNN' shopt options, where NN is less than 41.
|
||||
|
||||
45. Bash-4.1 conforms to the current Posix specification for `set -u':
|
||||
expansions of $@ and $* when there are no positional parameters do not
|
||||
cause the shell to exit.
|
||||
|
||||
46. Bash-4.1 implements the current Posix specification for `set -e' and
|
||||
exits when any command fails, not just a simple command or pipeline.
|
||||
|
||||
47. Command substitutions now remove the caller's trap strings when trap is
|
||||
run to set a new trap in the subshell. Previous to bash-4.2, the old
|
||||
trap strings persisted even though the actual signal handlers were reset.
|
||||
|
||||
48. When in Posix mode, a single quote is not treated specially in a
|
||||
double-quoted ${...} expansion, unless the expansion operator is
|
||||
# or % or the new `//', `^', or `,' expansions. In particular, it
|
||||
does not define a new quoting context. This is from Posix interpretation
|
||||
221.
|
||||
|
||||
49. Posix mode shells no longer exit if a variable assignment error occurs
|
||||
with an assignment preceding a command that is not a special builtin.
|
||||
|
||||
50. Bash-4.2 attempts to preserve what the user typed when performing word
|
||||
completion, instead of, for instance, expanding shell variable
|
||||
references to their value.
|
||||
|
||||
51. When in Posix mode, bash-4.2 exits if the filename supplied as an argument
|
||||
to `.' is not found and the shell is not interactive.
|
||||
|
||||
52. When compiled for strict Posix compatibility, bash-4.3 does not enable
|
||||
history expansion by default in interactive shells, since it results in
|
||||
a non-conforming environment.
|
||||
|
||||
53. Bash-4.3 runs the replacement string in the pattern substitution word
|
||||
expansion through quote removal. The code already treats quote
|
||||
characters in the replacement string as special; if it treats them as
|
||||
special, then quote removal should remove them.
|
||||
|
||||
54. Bash-4.4 no longer considers a reference to ${a[@]} or ${a[*]}, where `a'
|
||||
is an array without any elements set, to be a reference to an unset
|
||||
variable. This means that such a reference will not cause the shell to
|
||||
exit when the `-u' option is enabled.
|
||||
|
||||
55. Bash-4.4 allows double quotes to quote the history expansion character (!)
|
||||
when in Posix mode, since Posix specifies the effects of double quotes.
|
||||
|
||||
56. Bash-4.4 does not inherit $PS4 from the environment if running as root.
|
||||
|
||||
57. Bash-4.4 doesn't allow a `break' or `continue' in a function to affect
|
||||
loop execution in the calling context.
|
||||
|
||||
58. Bash-4.4 no longer expands tildes in $PATH elements when in Posix mode.
|
||||
|
||||
59. Bash-4.4 does not attempt to perform a compound array assignment if an
|
||||
argument to `declare' or a similar builtin expands to a word that looks
|
||||
like a compound array assignment (e.g. declare w=$x where x='(foo)').
|
||||
|
||||
60. Bash-5.0 only sets up BASH_ARGV and BASH_ARGC at startup if extended
|
||||
debugging mode is active. The old behavior of unconditionally setting
|
||||
BASH_ARGC and BASH_ARGV is available at compatibility levels less than
|
||||
or equal to 44.
|
||||
|
||||
61. Bash-5.0 doesn't allow a `break' or `continue' in a subshell to attempt
|
||||
to break or continue loop execution inherited from the calling context.
|
||||
|
||||
62. Bash-5.0 doesn't allow variable assignments preceding builtins like
|
||||
export and readonly to modify variables with the same name in preceding
|
||||
contexts (including the global context) unless the shell is in posix
|
||||
mode, since export and readonly are special builtins.
|
||||
|
||||
63. Bash-5.1 changes the way posix-mode shells handle assignment statements
|
||||
preceding shell function calls. Previous versions of POSIX specified that
|
||||
such assignments would persist after the function returned; subsequent
|
||||
versions of the standard removed that requirement (interpretation #654).
|
||||
Bash-5.1 posix mode assignment statements preceding shell function calls
|
||||
do not persist after the function returns.
|
||||
|
||||
64. Bash-5.1 reverts to the bash-4.4 treatment of pathname expansion of words
|
||||
containing backslashes but no other special globbing characters. This comes
|
||||
after a protracted discussion and a POSIX interpretation (#1234).
|
||||
|
||||
65. In bash-5.1, disabling posix mode attempts to restore the state of several
|
||||
options that posix mode modifies to the state they had before enabling
|
||||
posix mode. Previous versions restored these options to default values.
|
||||
|
||||
66. Bash-5.2 attempts to prevent double-expansion of array subscripts under
|
||||
certain circumstances, especially arithmetic evaluation, by acting as if
|
||||
the `assoc_expand_once' shell option were set.
|
||||
|
||||
67. The `unset' builtin in bash-5.2 treats array subscripts `@' and `*'
|
||||
differently than previous versions, and differently depending on whether
|
||||
the array is indexed or associative.
|
||||
|
||||
|
||||
Shell Compatibility Level
|
||||
=========================
|
||||
|
||||
Bash-4.0 introduced the concept of a `shell compatibility level', specified
|
||||
as a set of options to the shopt builtin (compat31, compat32, compat40,
|
||||
compat41, and so on). There is only one current compatibility level --
|
||||
each option is mutually exclusive. The compatibility level is intended to
|
||||
allow users to select behavior from previous versions that is incompatible
|
||||
with newer versions while they migrate scripts to use current features and
|
||||
behavior. It's intended to be a temporary solution.
|
||||
|
||||
This section does not mention behavior that is standard for a particular
|
||||
version (e.g., setting compat32 means that quoting the rhs of the regexp
|
||||
matching operator quotes special regexp characters in the word, which is
|
||||
default behavior in bash-3.2 and above).
|
||||
|
||||
If a user enables, say, compat32, it may affect the behavior of other
|
||||
compatibility levels up to and including the current compatibility level.
|
||||
The idea is that each compatibility level controls behavior that changed in
|
||||
that version of bash, but that behavior may have been present in earlier
|
||||
versions. For instance, the change to use locale-based comparisons with
|
||||
the `[[' command came in bash-4.1, and earlier versions used ASCII-based
|
||||
comparisons, so enabling compat32 will enable ASCII-based comparisons as
|
||||
well. That granularity may not be sufficient for all uses, and as a result
|
||||
users should employ compatibility levels carefully. Read the documentation
|
||||
for a particular feature to find out the current behavior.
|
||||
|
||||
Bash-4.3 introduced a new shell variable: BASH_COMPAT. The value assigned
|
||||
to this variable (a decimal version number like 4.2, or an integer
|
||||
corresponding to the compatNN option, like 42) determines the compatibility
|
||||
level.
|
||||
|
||||
Starting with bash-4.4, bash has begun deprecating older compatibility
|
||||
levels. Eventually, the options will be removed in favor of the
|
||||
BASH_COMPAT variable.
|
||||
|
||||
Bash-5.0 is the final version for which there will be an individual shopt
|
||||
option for the previous version. Users should use the BASH_COMPAT variable
|
||||
on bash-5.0 and later versions.
|
||||
|
||||
The following table describes the behavior changes controlled by each
|
||||
compatibility level setting. The `compatNN' tag is used as shorthand for
|
||||
setting the compatibility level to NN using one of the following
|
||||
mechanisms. For versions prior to bash-5.0, the compatibility level may be
|
||||
set using the corresponding compatNN shopt option. For bash-4.3 and later
|
||||
versions, the BASH_COMPAT variable is preferred, and it is required for
|
||||
bash-5.1 and later versions.
|
||||
|
||||
compat31
|
||||
- the < and > operators to the [[ command do not consider the current
|
||||
locale when comparing strings; they use ASCII ordering
|
||||
- quoting the rhs of the [[ command's regexp matching operator (=~)
|
||||
has no special effect
|
||||
|
||||
compat32
|
||||
- the < and > operators to the [[ command do not consider the current
|
||||
locale when comparing strings; they use ASCII ordering
|
||||
- interrupting a command list such as "a ; b ; c" causes the execution
|
||||
of the next command in the list (in bash-4.0 and later versions,
|
||||
the shell acts as if it received the interrupt, so interrupting
|
||||
one command in a list aborts the execution of the entire list)
|
||||
|
||||
compat40
|
||||
- the < and > operators to the [[ command do not consider the current
|
||||
locale when comparing strings; they use ASCII ordering.
|
||||
Bash versions prior to bash-4.1 use ASCII collation and strcmp(3);
|
||||
bash-4.1 and later use the current locale's collation sequence and
|
||||
strcoll(3).
|
||||
|
||||
compat41
|
||||
- in posix mode, `time' may be followed by options and still be
|
||||
recognized as a reserved word (this is POSIX interpretation 267)
|
||||
- in posix mode, the parser requires that an even number of single
|
||||
quotes occur in the `word' portion of a double-quoted ${...}
|
||||
parameter expansion and treats them specially, so that characters
|
||||
within the single quotes are considered quoted (this is POSIX
|
||||
interpretation 221)
|
||||
|
||||
compat42
|
||||
- the replacement string in double-quoted pattern substitution is not
|
||||
run through quote removal, as it is in versions after bash-4.2
|
||||
- in posix mode, single quotes are considered special when expanding
|
||||
the `word' portion of a double-quoted ${...} parameter expansion
|
||||
and can be used to quote a closing brace or other special character
|
||||
(this is part of POSIX interpretation 221); in later versions,
|
||||
single quotes are not special within double-quoted word expansions
|
||||
|
||||
compat43
|
||||
- the shell does not print a warning message if an attempt is made to
|
||||
use a quoted compound assignment as an argument to declare
|
||||
(declare -a foo='(1 2)'). Later versions warn that this usage is
|
||||
deprecated.
|
||||
- word expansion errors are considered non-fatal errors that cause the
|
||||
current command to fail, even in posix mode (the default behavior is
|
||||
to make them fatal errors that cause the shell to exit)
|
||||
- when executing a shell function, the loop state (while/until/etc.)
|
||||
is not reset, so `break' or `continue' in that function will break
|
||||
or continue loops in the calling context. Bash-4.4 and later reset
|
||||
the loop state to prevent this
|
||||
|
||||
compat44
|
||||
- the shell sets up the values used by BASH_ARGV and BASH_ARGC so
|
||||
they can expand to the shell's positional parameters even if extended
|
||||
debug mode is not enabled
|
||||
- a subshell inherits loops from its parent context, so `break'
|
||||
or `continue' will cause the subshell to exit. Bash-5.0 and later
|
||||
reset the loop state to prevent the exit
|
||||
- variable assignments preceding builtins like export and readonly
|
||||
that set attributes continue to affect variables with the same
|
||||
name in the calling environment even if the shell is not in posix
|
||||
mode
|
||||
|
||||
compat50 (set using BASH_COMPAT)
|
||||
- Bash-5.1 changed the way $RANDOM is generated to introduce slightly
|
||||
more randomness. If the shell compatibility level is set to 50 or
|
||||
lower, it reverts to the method from bash-5.0 and previous versions,
|
||||
so seeding the random number generator by assigning a value to
|
||||
RANDOM will produce the same sequence as in bash-5.0
|
||||
- If the command hash table is empty, bash versions prior to bash-5.1
|
||||
printed an informational message to that effect even when writing
|
||||
output in a format that can be reused as input (-l). Bash-5.1
|
||||
suppresses that message if -l is supplied
|
||||
- Bash-5.1 and later use pipes for here-documents and here-strings if
|
||||
they are smaller than the pipe capacity. If the shell compatibility
|
||||
level is set to 50 or lower, it reverts to using temporary files.
|
||||
|
||||
compat51 (set using BASH_COMPAT)
|
||||
- The `unset' builtin will unset the array a given an argument like
|
||||
`a[@]'. Bash-5.2 will unset an element with key `@' (associative
|
||||
arrays) or remove all the elements without unsetting the array
|
||||
(indexed arrays)
|
||||
- arithmetic commands ( ((...)) ) and the expressions in an arithmetic
|
||||
for statement can be expanded more than once
|
||||
- expressions used as arguments to arithmetic operators in the [[
|
||||
conditional command can be expanded more than once
|
||||
- indexed and associative array subscripts used as arguments to the
|
||||
operators in the [[ conditional command (e.g., `[[ -v') can be
|
||||
expanded more than once. Bash-5.2 behaves as if the
|
||||
`assoc_expand_once' option were enabled.
|
||||
- the expressions in substring parameter brace expansion can be
|
||||
expanded more than once
|
||||
- the expressions in the $(( ... )) word expansion can be expanded
|
||||
more than once
|
||||
- arithmetic expressions used as indexed array subscripts can be
|
||||
expanded more than once;
|
||||
- `test -v', when given an argument of A[@], where A is an existing
|
||||
associative array, will return true if the array has any set
|
||||
elements. Bash-5.2 will look for a key named `@';
|
||||
- the ${param[:]=value} word expansion will return VALUE, before any
|
||||
variable-specific transformations have been performed (e.g.,
|
||||
converting to lowercase). Bash-5.2 will return the final value
|
||||
assigned to the variable, as POSIX specifies;
|
||||
- Parsing command substitutions will act as if extended glob is
|
||||
enabled, so that parsing a command substitution containing an extglob
|
||||
pattern (say, as part of a shell function) will not fail. This
|
||||
assumes the intent is to enable extglob before the command is
|
||||
executed and word expansions are performed. It will fail at word
|
||||
expansion time if extglob hasn't been enabled by the time the
|
||||
command is executed.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved. This file is offered as-is,
|
||||
without any warranty.
|
674
COPYING
Normal file
674
COPYING
Normal file
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
31
CWRU/PLATFORMS
Normal file
31
CWRU/PLATFORMS
Normal file
|
@ -0,0 +1,31 @@
|
|||
The version of bash in this directory has been compiled on the
|
||||
following systems:
|
||||
|
||||
By chet:
|
||||
|
||||
SunOS 4.1.4
|
||||
SunOS 5.5
|
||||
BSDI BSD/OS 2.1
|
||||
FreeBSD 2.2
|
||||
NetBSD 1.2
|
||||
AIX 4.2
|
||||
AIX 4.1.4
|
||||
HP/UX 9.05, 10.01, 10.10, 10.20
|
||||
Linux 2.0.29 (libc 5.3.12)
|
||||
Linux 2.0.4 (libc 5.3.12)
|
||||
|
||||
By other testers:
|
||||
|
||||
SCO ODT 2.0
|
||||
SCO 3.2v5.0, 3.2v4.2
|
||||
SunOS 5.3
|
||||
SunOS 5.5
|
||||
BSD/OS 2.1
|
||||
FreeBSD 2.2
|
||||
SunOS 4.1.3
|
||||
Irix 5.3
|
||||
Irix 6.2
|
||||
Linux 2.0 (unknown distribution)
|
||||
Digital OSF/1 3.2
|
||||
GNU Hurd 0.1
|
||||
SVR4.2
|
20
CWRU/README
Normal file
20
CWRU/README
Normal file
|
@ -0,0 +1,20 @@
|
|||
Contents of this directory:
|
||||
|
||||
changelog - my change log since the last release
|
||||
|
||||
POSIX.NOTES - list of what changes for `posix mode'
|
||||
|
||||
README - this file
|
||||
|
||||
misc - directory with some useful tools
|
||||
|
||||
The following are distributed `as-is'. They will not apply without some
|
||||
modification.
|
||||
|
||||
sh-redir-hack - diff to parse.y to get redirections before
|
||||
compound commands
|
||||
|
||||
empty-for-wordlist - diff to parse.y to allow an empty wordlist after
|
||||
the `in' keyword in a `for' statement
|
||||
|
||||
mh-folder-comp - diffs that reportedly add MH folder completion
|
3952
CWRU/changelog
Normal file
3952
CWRU/changelog
Normal file
File diff suppressed because it is too large
Load diff
26
CWRU/misc/bison
Normal file
26
CWRU/misc/bison
Normal file
|
@ -0,0 +1,26 @@
|
|||
#! /bin/sh
|
||||
#
|
||||
# bison -- just call yacc
|
||||
#
|
||||
|
||||
# Copyright (C) 1996-2002 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 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.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
if [ "$1" = '-y' ]; then
|
||||
shift
|
||||
fi
|
||||
|
||||
exec /usr/bin/yacc ${1+"$@"}
|
57
CWRU/misc/errlist.c
Normal file
57
CWRU/misc/errlist.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* If necessary, link with lib/sh/libsh.a
|
||||
*/
|
||||
|
||||
/* Copyright (C) 1998-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/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
extern char *strerror();
|
||||
|
||||
extern int sys_nerr;
|
||||
|
||||
int
|
||||
main(c, v)
|
||||
int c;
|
||||
char **v;
|
||||
{
|
||||
int i, n;
|
||||
|
||||
if (c == 1) {
|
||||
for (i = 1; i < sys_nerr; i++)
|
||||
printf("%d --> %s\n", i, strerror(i));
|
||||
} else {
|
||||
for (i = 1; i < c; i++) {
|
||||
n = atoi(v[i]);
|
||||
printf("%d --> %s\n", n, strerror(n));
|
||||
}
|
||||
}
|
||||
exit (0);
|
||||
}
|
||||
|
||||
programming_error(a, b)
|
||||
char *a;
|
||||
int b;
|
||||
{
|
||||
}
|
||||
|
||||
fatal_error()
|
||||
{
|
||||
}
|
63
CWRU/misc/hpux10-dlfcn.h
Normal file
63
CWRU/misc/hpux10-dlfcn.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* HPUX 10.x stubs to implement dl* in terms of shl*
|
||||
*
|
||||
* Not needed for later versions; HPUX 11.x has dlopen() and friends.
|
||||
*
|
||||
* configure also needs to be faked out. You can create a dummy libdl.a
|
||||
* with stub entries for dlopen, dlclose, dlsym, and dlerror:
|
||||
*
|
||||
* int dlopen() { return(0);}
|
||||
* int dlclose() { return(0);}
|
||||
* int dlsym() { return(0);}
|
||||
* int dlerror() { return(0);}
|
||||
*
|
||||
* This has not been tested; I just read the manual page and coded this up.
|
||||
*
|
||||
* According to the ld manual page, you need to link bash with -dld and add
|
||||
* the -E flag to LOCAL_LDFLAGS.
|
||||
*/
|
||||
|
||||
/* Copyright (C) 1998-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/>.
|
||||
*/
|
||||
|
||||
#if !defined (__HPUX10_DLFCN_H__)
|
||||
|
||||
#define __HPUX10_DLFCN_H__
|
||||
|
||||
#include <dl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#define RTLD_LAZY BIND_DEFERRED
|
||||
#define RTLD_NOW BIND_IMMEDIATE
|
||||
#define RTLD_GLOBAL DYNAMIC_PATH
|
||||
|
||||
char *bash_global_sym_addr;
|
||||
|
||||
#define dlopen(file,mode) (void *)shl_load((file), (mode), 0L)
|
||||
|
||||
#define dlclose(handle) shl_unload((shl_t)(handle))
|
||||
|
||||
#define dlsym(handle,name) (bash_global_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&bash_global_sym_addr), (void *)bash_global_sym_addr)
|
||||
|
||||
#define dlerror() strerror(errno)
|
||||
|
||||
#endif /* __HPUX10_DLFCN_H__ */
|
39
CWRU/misc/open-files.c
Normal file
39
CWRU/misc/open-files.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* open-files -- report files a process has open */
|
||||
|
||||
/* Copyright (C) 1989-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/>.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/file.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
main()
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (i = 0; i < getdtablesize(); i++) {
|
||||
if (fcntl(i, F_GETFD, 0) != -1)
|
||||
fprintf(stderr, "fd %d: open\n", i);
|
||||
}
|
||||
exit(0);
|
||||
}
|
47
CWRU/misc/sigs.c
Normal file
47
CWRU/misc/sigs.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* sigs - print signal dispositions for a process */
|
||||
|
||||
/* Copyright (C) 1990-2010 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/>.
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern const char * const sys_siglist[];
|
||||
|
||||
typedef void sighandler();
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
register int i;
|
||||
sighandler *h;
|
||||
|
||||
for (i = 1; i < NSIG; i++) {
|
||||
h = signal(i, SIG_DFL);
|
||||
if (h != SIG_DFL) {
|
||||
if (h == SIG_IGN)
|
||||
fprintf(stderr, "%d: ignored (%s)\n", i, sys_siglist[i]);
|
||||
else
|
||||
fprintf(stderr, "%d: caught (%s)\n", i, sys_siglist[i]);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
226
CWRU/misc/sigstat.c
Normal file
226
CWRU/misc/sigstat.c
Normal file
|
@ -0,0 +1,226 @@
|
|||
/*
|
||||
* sigstat - print out useful information about signal arguments
|
||||
*
|
||||
* Chet Ramey
|
||||
* chet@po.cwru.edu
|
||||
*/
|
||||
|
||||
/* Copyright (C) 1991-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/>.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern char *strrchr();
|
||||
static char *signames[NSIG];
|
||||
|
||||
char *progname;
|
||||
|
||||
void sigstat();
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
register int i;
|
||||
char *t;
|
||||
|
||||
if (t = strrchr(argv[0], '/'))
|
||||
progname = ++t;
|
||||
else
|
||||
progname = argv[0];
|
||||
init_signames();
|
||||
if (argc == 1) {
|
||||
for (i = 1; i < NSIG; i++)
|
||||
sigstat(i);
|
||||
exit(0);
|
||||
}
|
||||
for (i = 1; i < argc; i++)
|
||||
sigstat(atoi(argv[i]));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
sigstat(sig)
|
||||
int sig;
|
||||
{
|
||||
struct sigaction oact;
|
||||
char *signame;
|
||||
sigset_t set, oset;
|
||||
int blocked;
|
||||
|
||||
if (sig < 0 || sig >= NSIG) {
|
||||
fprintf(stderr, "%s: %d: signal out of range\n", progname, sig);
|
||||
return;
|
||||
}
|
||||
signame = signames[sig];
|
||||
sigemptyset(&oset);
|
||||
sigprocmask(SIG_BLOCK, (sigset_t *)NULL, &oset);
|
||||
if (sigismember(&oset, sig))
|
||||
printf("%s: signal is blocked\n", signame);
|
||||
sigaction(sig, (struct sigaction *)NULL, &oact);
|
||||
if (oact.sa_handler == SIG_IGN)
|
||||
printf("%s: signal is ignored\n", signame);
|
||||
else if (oact.sa_handler == SIG_DFL)
|
||||
printf("%s: signal is defaulted\n", signame);
|
||||
else
|
||||
printf("%s: signal is trapped (?)\n", signame);
|
||||
}
|
||||
|
||||
init_signames()
|
||||
{
|
||||
register int i;
|
||||
bzero(signames, sizeof(signames));
|
||||
|
||||
#if defined (SIGHUP) /* hangup */
|
||||
signames[SIGHUP] = "SIGHUP";
|
||||
#endif
|
||||
#if defined (SIGINT) /* interrupt */
|
||||
signames[SIGINT] = "SIGINT";
|
||||
#endif
|
||||
#if defined (SIGQUIT) /* quit */
|
||||
signames[SIGQUIT] = "SIGQUIT";
|
||||
#endif
|
||||
#if defined (SIGILL) /* illegal instruction (not reset when caught) */
|
||||
signames[SIGILL] = "SIGILL";
|
||||
#endif
|
||||
#if defined (SIGTRAP) /* trace trap (not reset when caught) */
|
||||
signames[SIGTRAP] = "SIGTRAP";
|
||||
#endif
|
||||
#if defined (SIGABRT) /* */
|
||||
signames[SIGABRT] = "SIGABRT";
|
||||
#endif
|
||||
#if defined (SIGIOT) /* IOT instruction */
|
||||
signames[SIGIOT] = "SIGIOT";
|
||||
#endif
|
||||
#if defined (SIGEMT) /* EMT instruction */
|
||||
signames[SIGEMT] = "SIGEMT";
|
||||
#endif
|
||||
#if defined (SIGFPE) /* floating point exception */
|
||||
signames[SIGFPE] = "SIGFPE";
|
||||
#endif
|
||||
#if defined (SIGKILL) /* kill (cannot be caught or ignored) */
|
||||
signames[SIGKILL] = "SIGKILL";
|
||||
#endif
|
||||
#if defined (SIGBUS) /* bus error */
|
||||
signames[SIGBUS] = "SIGBUS";
|
||||
#endif
|
||||
#if defined (SIGSEGV) /* segmentation violation */
|
||||
signames[SIGSEGV] = "SIGSEGV";
|
||||
#endif
|
||||
#if defined (SIGSYS) /* bad argument to system call */
|
||||
signames[SIGSYS] = "SIGSYS";
|
||||
#endif
|
||||
#if defined (SIGPIPE) /* write on a pipe with no one to read it */
|
||||
signames[SIGPIPE] = "SIGPIPE";
|
||||
#endif
|
||||
#if defined (SIGALRM) /* alarm clock */
|
||||
signames[SIGALRM] = "SIGALRM";
|
||||
#endif
|
||||
#if defined (SIGTERM) /* software termination signal from kill */
|
||||
signames[SIGTERM] = "SIGTERM";
|
||||
#endif
|
||||
#if defined (SIGCLD) /* Like SIGCHLD. */
|
||||
signames[SIGCLD] = "SIGCLD";
|
||||
#endif
|
||||
#if defined (SIGPWR) /* Magic thing for some machines. */
|
||||
signames[SIGPWR] = "SIGPWR";
|
||||
#endif
|
||||
#if defined (SIGPOLL) /* For keyboard input? */
|
||||
signames[SIGPOLL] = "SIGPOLL";
|
||||
#endif
|
||||
#if defined (SIGURG) /* urgent condition on IO channel */
|
||||
signames[SIGURG] = "SIGURG";
|
||||
#endif
|
||||
#if defined (SIGSTOP) /* sendable stop signal not from tty */
|
||||
signames[SIGSTOP] = "SIGSTOP";
|
||||
#endif
|
||||
#if defined (SIGTSTP) /* stop signal from tty */
|
||||
signames[SIGTSTP] = "SIGTSTP";
|
||||
#endif
|
||||
#if defined (SIGCONT) /* continue a stopped process */
|
||||
signames[SIGCONT] = "SIGCONT";
|
||||
#endif
|
||||
#if defined (SIGCHLD) /* to parent on child stop or exit */
|
||||
signames[SIGCHLD] = "SIGCHLD";
|
||||
#endif
|
||||
#if defined (SIGTTIN) /* to readers pgrp upon background tty read */
|
||||
signames[SIGTTIN] = "SIGTTIN";
|
||||
#endif
|
||||
#if defined (SIGTTOU) /* like TTIN for output if (tp->t_local<OSTOP) */
|
||||
signames[SIGTTOU] = "SIGTTOU";
|
||||
#endif
|
||||
#if defined (SIGIO) /* input/output possible signal */
|
||||
signames[SIGIO] = "SIGIO";
|
||||
#endif
|
||||
#if defined (SIGXCPU) /* exceeded CPU time limit */
|
||||
signames[SIGXCPU] = "SIGXCPU";
|
||||
#endif
|
||||
#if defined (SIGXFSZ) /* exceeded file size limit */
|
||||
signames[SIGXFSZ] = "SIGXFSZ";
|
||||
#endif
|
||||
#if defined (SIGVTALRM) /* virtual time alarm */
|
||||
signames[SIGVTALRM] = "SIGVTALRM";
|
||||
#endif
|
||||
#if defined (SIGPROF) /* profiling time alarm */
|
||||
signames[SIGPROF] = "SIGPROF";
|
||||
#endif
|
||||
#if defined (SIGWINCH) /* window changed */
|
||||
signames[SIGWINCH] = "SIGWINCH";
|
||||
#endif
|
||||
#if defined (SIGLOST) /* resource lost (eg, record-lock lost) */
|
||||
signames[SIGLOST] = "SIGLOST";
|
||||
#endif
|
||||
#if defined (SIGUSR1) /* user defined signal 1 */
|
||||
signames[SIGUSR1] = "SIGUSR1";
|
||||
#endif
|
||||
#if defined (SIGUSR2) /* user defined signal 2 */
|
||||
signames[SIGUSR2] = "SIGUSR2";
|
||||
#endif
|
||||
#if defined (SIGMSG) /* HFT input data pending */
|
||||
signames[SIGMSG] = "SIGMSG";
|
||||
#endif
|
||||
#if defined (SIGPWR) /* power failure imminent (save your data) */
|
||||
signames[SIGPWR] = "SIGPWR";
|
||||
#endif
|
||||
#if defined (SIGDANGER) /* system crash imminent */
|
||||
signames[SIGDANGER] = "SIGDANGER";
|
||||
#endif
|
||||
#if defined (SIGMIGRATE) /* migrate process to another CPU */
|
||||
signames[SIGMIGRATE] = "SIGMIGRATE";
|
||||
#endif
|
||||
#if defined (SIGPRE) /* programming error */
|
||||
signames[SIGPRE] = "SIGPRE";
|
||||
#endif
|
||||
#if defined (SIGGRANT) /* HFT monitor mode granted */
|
||||
signames[SIGGRANT] = "SIGGRANT";
|
||||
#endif
|
||||
#if defined (SIGRETRACT) /* HFT monitor mode retracted */
|
||||
signames[SIGRETRACT] = "SIGRETRACT";
|
||||
#endif
|
||||
#if defined (SIGSOUND) /* HFT sound sequence has completed */
|
||||
signames[SIGSOUND] = "SIGSOUND";
|
||||
#endif
|
||||
|
||||
for (i = 0; i < NSIG; i++)
|
||||
if (signames[i] == (char *)NULL) {
|
||||
signames[i] = (char *)malloc (16);;
|
||||
sprintf (signames[i], "signal %d", i);
|
||||
}
|
||||
}
|
15
CWRU/sh-redir-hack
Normal file
15
CWRU/sh-redir-hack
Normal file
|
@ -0,0 +1,15 @@
|
|||
Add to `subshell' production in parse.y and recompile -DREDIRECTION_HACK to
|
||||
get `< xx (command)' sh compatibility.
|
||||
|
||||
| redirections '(' list ')'
|
||||
{
|
||||
#if defined (REDIRECTION_HACK)
|
||||
/* XXX - C News sh compatibility hack - XXX */
|
||||
$3->redirects = $1;
|
||||
$3->flags |= CMD_WANT_SUBSHELL;
|
||||
$$ = $3;
|
||||
#else
|
||||
yyerror ();
|
||||
YYABORT;
|
||||
#endif
|
||||
}
|
495
INSTALL
Normal file
495
INSTALL
Normal file
|
@ -0,0 +1,495 @@
|
|||
Basic Installation
|
||||
==================
|
||||
|
||||
These are installation instructions for Bash.
|
||||
|
||||
The simplest way to compile Bash is:
|
||||
|
||||
1. 'cd' to the directory containing the source code and type
|
||||
'./configure' to configure Bash for your system. If you're using
|
||||
'csh' on an old version of System V, you might need to type 'sh
|
||||
./configure' instead to prevent 'csh' from trying to execute
|
||||
'configure' itself.
|
||||
|
||||
Running 'configure' takes some time. While running, it prints
|
||||
messages telling which features it is checking for.
|
||||
|
||||
2. Type 'make' to compile Bash and build the 'bashbug' bug reporting
|
||||
script.
|
||||
|
||||
3. Optionally, type 'make tests' to run the Bash test suite.
|
||||
|
||||
4. Type 'make install' to install 'bash' and 'bashbug'. This will
|
||||
also install the manual pages and Info file, message translation
|
||||
files, some supplemental documentation, a number of example
|
||||
loadable builtin commands, and a set of header files for developing
|
||||
loadable builtins. You may need additional privileges to install
|
||||
'bash' to your desired destination, so 'sudo make install' might be
|
||||
required. More information about controlling the locations where
|
||||
'bash' and other files are installed is below (*note Installation
|
||||
Names::).
|
||||
|
||||
The 'configure' shell script attempts to guess correct values for
|
||||
various system-dependent variables used during compilation. It uses
|
||||
those values to create a 'Makefile' in each directory of the package
|
||||
(the top directory, the 'builtins', 'doc', 'po', and 'support'
|
||||
directories, each directory under 'lib', and several others). It also
|
||||
creates a 'config.h' file containing system-dependent definitions.
|
||||
Finally, it creates a shell script named 'config.status' that you can
|
||||
run in the future to recreate the current configuration, a file
|
||||
'config.cache' that saves the results of its tests to speed up
|
||||
reconfiguring, and a file 'config.log' containing compiler output
|
||||
(useful mainly for debugging 'configure'). If at some point
|
||||
'config.cache' contains results you don't want to keep, you may remove
|
||||
or edit it.
|
||||
|
||||
To find out more about the options and arguments that the 'configure'
|
||||
script understands, type
|
||||
|
||||
bash-4.2$ ./configure --help
|
||||
|
||||
at the Bash prompt in your Bash source directory.
|
||||
|
||||
If you want to build Bash in a directory separate from the source
|
||||
directory - to build for multiple architectures, for example - just use
|
||||
the full path to the configure script. The following commands will
|
||||
build bash in a directory under '/usr/local/build' from the source code
|
||||
in '/usr/local/src/bash-4.4':
|
||||
|
||||
mkdir /usr/local/build/bash-4.4
|
||||
cd /usr/local/build/bash-4.4
|
||||
bash /usr/local/src/bash-4.4/configure
|
||||
make
|
||||
|
||||
See *note Compiling For Multiple Architectures:: for more information
|
||||
about building in a directory separate from the source.
|
||||
|
||||
If you need to do unusual things to compile Bash, please try to figure
|
||||
out how 'configure' could check whether or not to do them, and mail
|
||||
diffs or instructions to <bash-maintainers@gnu.org> so they can be
|
||||
considered for the next release.
|
||||
|
||||
The file 'configure.ac' is used to create 'configure' by a program
|
||||
called Autoconf. You only need 'configure.ac' if you want to change it
|
||||
or regenerate 'configure' using a newer version of Autoconf. If you do
|
||||
this, make sure you are using Autoconf version 2.69 or newer.
|
||||
|
||||
You can remove the program binaries and object files from the source
|
||||
code directory by typing 'make clean'. To also remove the files that
|
||||
'configure' created (so you can compile Bash for a different kind of
|
||||
computer), type 'make distclean'.
|
||||
|
||||
Compilers and Options
|
||||
=====================
|
||||
|
||||
Some systems require unusual options for compilation or linking that the
|
||||
'configure' script does not know about. You can give 'configure'
|
||||
initial values for variables by setting them in the environment. Using
|
||||
a Bourne-compatible shell, you can do that on the command line like
|
||||
this:
|
||||
|
||||
CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
|
||||
|
||||
On systems that have the 'env' program, you can do it like this:
|
||||
|
||||
env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
|
||||
|
||||
The configuration process uses GCC to build Bash if it is available.
|
||||
|
||||
Compiling For Multiple Architectures
|
||||
====================================
|
||||
|
||||
You can compile Bash for more than one kind of computer at the same
|
||||
time, by placing the object files for each architecture in their own
|
||||
directory. To do this, you must use a version of 'make' that supports
|
||||
the 'VPATH' variable, such as GNU 'make'. 'cd' to the directory where
|
||||
you want the object files and executables to go and run the 'configure'
|
||||
script from the source directory (*note Basic Installation::). You may
|
||||
need to supply the '--srcdir=PATH' argument to tell 'configure' where
|
||||
the source files are. 'configure' automatically checks for the source
|
||||
code in the directory that 'configure' is in and in '..'.
|
||||
|
||||
If you have to use a 'make' that does not support the 'VPATH' variable,
|
||||
you can compile Bash for one architecture at a time in the source code
|
||||
directory. After you have installed Bash for one architecture, use
|
||||
'make distclean' before reconfiguring for another architecture.
|
||||
|
||||
Alternatively, if your system supports symbolic links, you can use the
|
||||
'support/mkclone' script to create a build tree which has symbolic links
|
||||
back to each file in the source directory. Here's an example that
|
||||
creates a build directory in the current directory from a source
|
||||
directory '/usr/gnu/src/bash-2.0':
|
||||
|
||||
bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
|
||||
|
||||
The 'mkclone' script requires Bash, so you must have already built Bash
|
||||
for at least one architecture before you can create build directories
|
||||
for other architectures.
|
||||
|
||||
Installation Names
|
||||
==================
|
||||
|
||||
By default, 'make install' will install into '/usr/local/bin',
|
||||
'/usr/local/man', etc.; that is, the "installation prefix" defaults to
|
||||
'/usr/local'. You can specify an installation prefix other than
|
||||
'/usr/local' by giving 'configure' the option '--prefix=PATH', or by
|
||||
specifying a value for the 'prefix' 'make' variable when running 'make
|
||||
install' (e.g., 'make install prefix=PATH'). The 'prefix' variable
|
||||
provides a default for 'exec_prefix' and other variables used when
|
||||
installing bash.
|
||||
|
||||
You can specify separate installation prefixes for architecture-specific
|
||||
files and architecture-independent files. If you give 'configure' the
|
||||
option '--exec-prefix=PATH', 'make install' will use PATH as the prefix
|
||||
for installing programs and libraries. Documentation and other data
|
||||
files will still use the regular prefix.
|
||||
|
||||
If you would like to change the installation locations for a single run,
|
||||
you can specify these variables as arguments to 'make': 'make install
|
||||
exec_prefix=/' will install 'bash' and 'bashbug' into '/bin' instead of
|
||||
the default '/usr/local/bin'.
|
||||
|
||||
If you want to see the files bash will install and where it will install
|
||||
them without changing anything on your system, specify the variable
|
||||
'DESTDIR' as an argument to 'make'. Its value should be the absolute
|
||||
directory path you'd like to use as the root of your sample installation
|
||||
tree. For example,
|
||||
|
||||
mkdir /fs1/bash-install
|
||||
make install DESTDIR=/fs1/bash-install
|
||||
|
||||
will install 'bash' into '/fs1/bash-install/usr/local/bin/bash', the
|
||||
documentation into directories within
|
||||
'/fs1/bash-install/usr/local/share', the example loadable builtins into
|
||||
'/fs1/bash-install/usr/local/lib/bash', and so on. You can use the
|
||||
usual 'exec_prefix' and 'prefix' variables to alter the directory paths
|
||||
beneath the value of 'DESTDIR'.
|
||||
|
||||
The GNU Makefile standards provide a more complete description of these
|
||||
variables and their effects.
|
||||
|
||||
Specifying the System Type
|
||||
==========================
|
||||
|
||||
There may be some features 'configure' can not figure out automatically,
|
||||
but needs to determine by the type of host Bash will run on. Usually
|
||||
'configure' can figure that out, but if it prints a message saying it
|
||||
can not guess the host type, give it the '--host=TYPE' option. 'TYPE'
|
||||
can either be a short name for the system type, such as 'sun4', or a
|
||||
canonical name with three fields: 'CPU-COMPANY-SYSTEM' (e.g.,
|
||||
'i386-unknown-freebsd4.2').
|
||||
|
||||
See the file 'support/config.sub' for the possible values of each field.
|
||||
|
||||
Sharing Defaults
|
||||
================
|
||||
|
||||
If you want to set default values for 'configure' scripts to share, you
|
||||
can create a site shell script called 'config.site' that gives default
|
||||
values for variables like 'CC', 'cache_file', and 'prefix'. 'configure'
|
||||
looks for 'PREFIX/share/config.site' if it exists, then
|
||||
'PREFIX/etc/config.site' if it exists. Or, you can set the
|
||||
'CONFIG_SITE' environment variable to the location of the site script.
|
||||
A warning: the Bash 'configure' looks for a site script, but not all
|
||||
'configure' scripts do.
|
||||
|
||||
Operation Controls
|
||||
==================
|
||||
|
||||
'configure' recognizes the following options to control how it operates.
|
||||
|
||||
'--cache-file=FILE'
|
||||
Use and save the results of the tests in FILE instead of
|
||||
'./config.cache'. Set FILE to '/dev/null' to disable caching, for
|
||||
debugging 'configure'.
|
||||
|
||||
'--help'
|
||||
Print a summary of the options to 'configure', and exit.
|
||||
|
||||
'--quiet'
|
||||
'--silent'
|
||||
'-q'
|
||||
Do not print messages saying which checks are being made.
|
||||
|
||||
'--srcdir=DIR'
|
||||
Look for the Bash source code in directory DIR. Usually
|
||||
'configure' can determine that directory automatically.
|
||||
|
||||
'--version'
|
||||
Print the version of Autoconf used to generate the 'configure'
|
||||
script, and exit.
|
||||
|
||||
'configure' also accepts some other, not widely used, boilerplate
|
||||
options. 'configure --help' prints the complete list.
|
||||
|
||||
Optional Features
|
||||
=================
|
||||
|
||||
The Bash 'configure' has a number of '--enable-FEATURE' options, where
|
||||
FEATURE indicates an optional part of Bash. There are also several
|
||||
'--with-PACKAGE' options, where PACKAGE is something like 'bash-malloc'
|
||||
or 'purify'. To turn off the default use of a package, use
|
||||
'--without-PACKAGE'. To configure Bash without a feature that is
|
||||
enabled by default, use '--disable-FEATURE'.
|
||||
|
||||
Here is a complete list of the '--enable-' and '--with-' options that
|
||||
the Bash 'configure' recognizes.
|
||||
|
||||
'--with-afs'
|
||||
Define if you are using the Andrew File System from Transarc.
|
||||
|
||||
'--with-bash-malloc'
|
||||
Use the Bash version of 'malloc' in the directory 'lib/malloc'.
|
||||
This is not the same 'malloc' that appears in GNU libc, but an
|
||||
older version originally derived from the 4.2 BSD 'malloc'. This
|
||||
'malloc' is very fast, but wastes some space on each allocation.
|
||||
This option is enabled by default. The 'NOTES' file contains a
|
||||
list of systems for which this should be turned off, and
|
||||
'configure' disables this option automatically for a number of
|
||||
systems.
|
||||
|
||||
'--with-curses'
|
||||
Use the curses library instead of the termcap library. This should
|
||||
be supplied if your system has an inadequate or incomplete termcap
|
||||
database.
|
||||
|
||||
'--with-gnu-malloc'
|
||||
A synonym for '--with-bash-malloc'.
|
||||
|
||||
'--with-installed-readline[=PREFIX]'
|
||||
Define this to make Bash link with a locally-installed version of
|
||||
Readline rather than the version in 'lib/readline'. This works
|
||||
only with Readline 5.0 and later versions. If PREFIX is 'yes' or
|
||||
not supplied, 'configure' uses the values of the make variables
|
||||
'includedir' and 'libdir', which are subdirectories of 'prefix' by
|
||||
default, to find the installed version of Readline if it is not in
|
||||
the standard system include and library directories. If PREFIX is
|
||||
'no', Bash links with the version in 'lib/readline'. If PREFIX is
|
||||
set to any other value, 'configure' treats it as a directory
|
||||
pathname and looks for the installed version of Readline in
|
||||
subdirectories of that directory (include files in PREFIX/'include'
|
||||
and the library in PREFIX/'lib').
|
||||
|
||||
'--with-libintl-prefix[=PREFIX]'
|
||||
Define this to make Bash link with a locally-installed version of
|
||||
the libintl library instead of the version in 'lib/intl'.
|
||||
|
||||
'--with-libiconv-prefix[=PREFIX]'
|
||||
Define this to make Bash look for libiconv in PREFIX instead of the
|
||||
standard system locations. There is no version included with Bash.
|
||||
|
||||
'--enable-minimal-config'
|
||||
This produces a shell with minimal features, close to the
|
||||
historical Bourne shell.
|
||||
|
||||
There are several '--enable-' options that alter how Bash is compiled,
|
||||
linked, and installed, rather than changing run-time features.
|
||||
|
||||
'--enable-largefile'
|
||||
Enable support for large files
|
||||
(http://www.unix.org/version2/whatsnew/lfs20mar.html) if the
|
||||
operating system requires special compiler options to build
|
||||
programs which can access large files. This is enabled by default,
|
||||
if the operating system provides large file support.
|
||||
|
||||
'--enable-profiling'
|
||||
This builds a Bash binary that produces profiling information to be
|
||||
processed by 'gprof' each time it is executed.
|
||||
|
||||
'--enable-separate-helpfiles'
|
||||
Use external files for the documentation displayed by the 'help'
|
||||
builtin instead of storing the text internally.
|
||||
|
||||
'--enable-static-link'
|
||||
This causes Bash to be linked statically, if 'gcc' is being used.
|
||||
This could be used to build a version to use as root's shell.
|
||||
|
||||
The 'minimal-config' option can be used to disable all of the following
|
||||
options, but it is processed first, so individual options may be enabled
|
||||
using 'enable-FEATURE'.
|
||||
|
||||
All of the following options except for 'alt-array-implementation',
|
||||
'disabled-builtins', 'direxpand-default', 'strict-posix-default', and
|
||||
'xpg-echo-default' are enabled by default, unless the operating system
|
||||
does not provide the necessary support.
|
||||
|
||||
'--enable-alias'
|
||||
Allow alias expansion and include the 'alias' and 'unalias'
|
||||
builtins (*note Aliases::).
|
||||
|
||||
'--enable-alt-array-implementation'
|
||||
This builds bash using an alternate implementation of arrays (*note
|
||||
Arrays::) that provides faster access at the expense of using more
|
||||
memory (sometimes many times more, depending on how sparse an array
|
||||
is).
|
||||
|
||||
'--enable-arith-for-command'
|
||||
Include support for the alternate form of the 'for' command that
|
||||
behaves like the C language 'for' statement (*note Looping
|
||||
Constructs::).
|
||||
|
||||
'--enable-array-variables'
|
||||
Include support for one-dimensional array shell variables (*note
|
||||
Arrays::).
|
||||
|
||||
'--enable-bang-history'
|
||||
Include support for 'csh'-like history substitution (*note History
|
||||
Interaction::).
|
||||
|
||||
'--enable-brace-expansion'
|
||||
Include 'csh'-like brace expansion ( 'b{a,b}c' ==> 'bac bbc' ).
|
||||
See *note Brace Expansion::, for a complete description.
|
||||
|
||||
'--enable-casemod-attributes'
|
||||
Include support for case-modifying attributes in the 'declare'
|
||||
builtin and assignment statements. Variables with the 'uppercase'
|
||||
attribute, for example, will have their values converted to
|
||||
uppercase upon assignment.
|
||||
|
||||
'--enable-casemod-expansion'
|
||||
Include support for case-modifying word expansions.
|
||||
|
||||
'--enable-command-timing'
|
||||
Include support for recognizing 'time' as a reserved word and for
|
||||
displaying timing statistics for the pipeline following 'time'
|
||||
(*note Pipelines::). This allows pipelines as well as shell
|
||||
builtins and functions to be timed.
|
||||
|
||||
'--enable-cond-command'
|
||||
Include support for the '[[' conditional command. (*note
|
||||
Conditional Constructs::).
|
||||
|
||||
'--enable-cond-regexp'
|
||||
Include support for matching POSIX regular expressions using the
|
||||
'=~' binary operator in the '[[' conditional command. (*note
|
||||
Conditional Constructs::).
|
||||
|
||||
'--enable-coprocesses'
|
||||
Include support for coprocesses and the 'coproc' reserved word
|
||||
(*note Pipelines::).
|
||||
|
||||
'--enable-debugger'
|
||||
Include support for the bash debugger (distributed separately).
|
||||
|
||||
'--enable-dev-fd-stat-broken'
|
||||
If calling 'stat' on /dev/fd/N returns different results than
|
||||
calling 'fstat' on file descriptor N, supply this option to enable
|
||||
a workaround. This has implications for conditional commands that
|
||||
test file attributes.
|
||||
|
||||
'--enable-direxpand-default'
|
||||
Cause the 'direxpand' shell option (*note The Shopt Builtin::) to
|
||||
be enabled by default when the shell starts. It is normally
|
||||
disabled by default.
|
||||
|
||||
'--enable-directory-stack'
|
||||
Include support for a 'csh'-like directory stack and the 'pushd',
|
||||
'popd', and 'dirs' builtins (*note The Directory Stack::).
|
||||
|
||||
'--enable-disabled-builtins'
|
||||
Allow builtin commands to be invoked via 'builtin xxx' even after
|
||||
'xxx' has been disabled using 'enable -n xxx'. See *note Bash
|
||||
Builtins::, for details of the 'builtin' and 'enable' builtin
|
||||
commands.
|
||||
|
||||
'--enable-dparen-arithmetic'
|
||||
Include support for the '((...))' command (*note Conditional
|
||||
Constructs::).
|
||||
|
||||
'--enable-extended-glob'
|
||||
Include support for the extended pattern matching features
|
||||
described above under *note Pattern Matching::.
|
||||
|
||||
'--enable-extended-glob-default'
|
||||
Set the default value of the 'extglob' shell option described above
|
||||
under *note The Shopt Builtin:: to be enabled.
|
||||
|
||||
'--enable-function-import'
|
||||
Include support for importing function definitions exported by
|
||||
another instance of the shell from the environment. This option is
|
||||
enabled by default.
|
||||
|
||||
'--enable-glob-asciirange-default'
|
||||
Set the default value of the 'globasciiranges' shell option
|
||||
described above under *note The Shopt Builtin:: to be enabled.
|
||||
This controls the behavior of character ranges when used in pattern
|
||||
matching bracket expressions.
|
||||
|
||||
'--enable-help-builtin'
|
||||
Include the 'help' builtin, which displays help on shell builtins
|
||||
and variables (*note Bash Builtins::).
|
||||
|
||||
'--enable-history'
|
||||
Include command history and the 'fc' and 'history' builtin commands
|
||||
(*note Bash History Facilities::).
|
||||
|
||||
'--enable-job-control'
|
||||
This enables the job control features (*note Job Control::), if the
|
||||
operating system supports them.
|
||||
|
||||
'--enable-multibyte'
|
||||
This enables support for multibyte characters if the operating
|
||||
system provides the necessary support.
|
||||
|
||||
'--enable-net-redirections'
|
||||
This enables the special handling of filenames of the form
|
||||
'/dev/tcp/HOST/PORT' and '/dev/udp/HOST/PORT' when used in
|
||||
redirections (*note Redirections::).
|
||||
|
||||
'--enable-process-substitution'
|
||||
This enables process substitution (*note Process Substitution::) if
|
||||
the operating system provides the necessary support.
|
||||
|
||||
'--enable-progcomp'
|
||||
Enable the programmable completion facilities (*note Programmable
|
||||
Completion::). If Readline is not enabled, this option has no
|
||||
effect.
|
||||
|
||||
'--enable-prompt-string-decoding'
|
||||
Turn on the interpretation of a number of backslash-escaped
|
||||
characters in the '$PS0', '$PS1', '$PS2', and '$PS4' prompt
|
||||
strings. See *note Controlling the Prompt::, for a complete list
|
||||
of prompt string escape sequences.
|
||||
|
||||
'--enable-readline'
|
||||
Include support for command-line editing and history with the Bash
|
||||
version of the Readline library (*note Command Line Editing::).
|
||||
|
||||
'--enable-restricted'
|
||||
Include support for a "restricted shell". If this is enabled,
|
||||
Bash, when called as 'rbash', enters a restricted mode. See *note
|
||||
The Restricted Shell::, for a description of restricted mode.
|
||||
|
||||
'--enable-select'
|
||||
Include the 'select' compound command, which allows the generation
|
||||
of simple menus (*note Conditional Constructs::).
|
||||
|
||||
'--enable-single-help-strings'
|
||||
Store the text displayed by the 'help' builtin as a single string
|
||||
for each help topic. This aids in translating the text to
|
||||
different languages. You may need to disable this if your compiler
|
||||
cannot handle very long string literals.
|
||||
|
||||
'--enable-strict-posix-default'
|
||||
Make Bash POSIX-conformant by default (*note Bash POSIX Mode::).
|
||||
|
||||
'--enable-translatable-strings'
|
||||
Enable support for '$"STRING"' translatable strings (*note Locale
|
||||
Translation::).
|
||||
|
||||
'--enable-usg-echo-default'
|
||||
A synonym for '--enable-xpg-echo-default'.
|
||||
|
||||
'--enable-xpg-echo-default'
|
||||
Make the 'echo' builtin expand backslash-escaped characters by
|
||||
default, without requiring the '-e' option. This sets the default
|
||||
value of the 'xpg_echo' shell option to 'on', which makes the Bash
|
||||
'echo' behave more like the version specified in the Single Unix
|
||||
Specification, version 3. *Note Bash Builtins::, for a description
|
||||
of the escape sequences that 'echo' recognizes.
|
||||
|
||||
The file 'config-top.h' contains C Preprocessor '#define' statements for
|
||||
options which are not settable from 'configure'. Some of these are not
|
||||
meant to be changed; beware of the consequences if you do. Read the
|
||||
comments associated with each definition for more information about its
|
||||
effect.
|
1781
Makefile.in
Normal file
1781
Makefile.in
Normal file
File diff suppressed because it is too large
Load diff
352
NOTES
Normal file
352
NOTES
Normal file
|
@ -0,0 +1,352 @@
|
|||
Platform-Specific Configuration and Operation Notes [very dated]
|
||||
====================================================================
|
||||
|
||||
1. configure --without-gnu-malloc on:
|
||||
|
||||
alpha running OSF/1, Linux, or NetBSD (malloc needs 8-byte alignment;
|
||||
bash malloc has 8-byte alignment now, but I have no alphas to test on)
|
||||
|
||||
next running NeXT/OS; machines running Openstep
|
||||
|
||||
all machines running SunOS YP code: SunOS4, SunOS5, HP/UX, if you
|
||||
have problems with username completion or tilde expansion for
|
||||
usernames found via YP/NIS
|
||||
|
||||
linux (optional, but don't do it if you're using Doug Lea's malloc)
|
||||
|
||||
QNX 4.2
|
||||
other OSF/1 machines (KSR/1, HP, IBM AIX/ESA)
|
||||
AIX
|
||||
sparc SVR4, SVR4.2 (ICL reference port)
|
||||
DG/UX
|
||||
Cray
|
||||
Haiku OS
|
||||
|
||||
NetBSD/sparc (malloc needs 8-byte alignment; bash malloc has 8-byte
|
||||
alignment now, but I have no NetBSD machines to test on)
|
||||
|
||||
BSD/OS 2.1, 3.x if you want to use loadable builtins
|
||||
|
||||
Motorola m68k machines running System V.3. There is a file descriptor
|
||||
leak caused by using the bash malloc because closedir(3) needs to read
|
||||
freed memory to find the file descriptor to close
|
||||
|
||||
2. Configure using shlicc2 on BSD/OS 2.1 and BSD/OS 3.x to use loadable
|
||||
builtins
|
||||
|
||||
3. Bash cannot be built in a directory separate from the source directory
|
||||
using configure --srcdir=... unless the version of `make' you're using
|
||||
does $VPATH handling right. The script support/mkclone can be used to
|
||||
create a `build tree' using symlinks to get around this.
|
||||
|
||||
4. I've had reports that username completion (as well as tilde expansion
|
||||
and \u prompt expansion) does not work on IRIX 5.3 when linking with
|
||||
-lnsl. This is only a problem when you're running NIS, since
|
||||
apparently -lnsl supports only /etc/passwd and not the NIS functions
|
||||
for retrieving usernames and passwords. Editing the Makefile after
|
||||
configure runs and removing the `-lnsl' from the assignment to `LIBS'
|
||||
fixes the problem.
|
||||
|
||||
5. There is a problem with the `makewhatis' script in older (pre-7.0)
|
||||
versions of Red Hat Linux. Running `makewhatis' with bash-2.0 or
|
||||
later versions results in error messages like this:
|
||||
|
||||
/usr/sbin/makewhatis: cd: manpath: No such file or directory
|
||||
/usr/sbin/makewhatis: manpath/whatis: No such file or directory
|
||||
chmod: manpath/whatis: No such file or directory
|
||||
/usr/sbin/makewhatis: cd: catpath: No such file or directory
|
||||
/usr/sbin/makewhatis: catpath/whatis: No such file or directory
|
||||
chmod: catpath/whatis: No such file or directory
|
||||
|
||||
The problem is with `makewhatis'. Red Hat (and possibly other
|
||||
Linux distributors) uses a construct like this in the code:
|
||||
|
||||
eval path=$"$pages"path
|
||||
|
||||
to do indirect variable expansion. This `happened to work' in
|
||||
bash-1.14 and previous versions, but that was more an accident
|
||||
of implementation than anything else -- it was never supported
|
||||
and certainly is not portable.
|
||||
|
||||
Bash-2.0 has a new feature that gives a new meaning to $"...".
|
||||
This is explained more completely in item 1 in the COMPAT file.
|
||||
|
||||
The three lines in the `makewhatis' script that need to be changed
|
||||
look like this:
|
||||
|
||||
eval $topath=$"$topath":$name
|
||||
[...]
|
||||
eval path=$"$pages"path
|
||||
[...]
|
||||
eval path=$"$pages"path
|
||||
|
||||
The portable way to write this code is
|
||||
|
||||
eval $topath="\$$topath":$name
|
||||
eval path="\$$pages"path
|
||||
eval path="\$$pages"path
|
||||
|
||||
You could also experiment with another new bash feature: ${!var}.
|
||||
This does indirect variable expansion, making the use of eval
|
||||
unnecessary.
|
||||
|
||||
6. There is a problem with syslogd on many Linux distributions (Red Hat
|
||||
and Slackware are two that I have received reports about). syslogd
|
||||
sends a SIGINT to its parent process, which is waiting for the daemon
|
||||
to finish its initialization. The parent process then dies due to
|
||||
the SIGINT, and bash reports it, causing unexpected console output
|
||||
while the system is booting that looks something like
|
||||
|
||||
starting daemons: syslogd/etc/rc.d/rc.M: line 29: 38 Interrupt ${NET}/syslogd
|
||||
|
||||
Bash-2.0 reports events such as processes dying in scripts due to
|
||||
signals when the standard output is a tty. Bash-1.14.x and previous
|
||||
versions did not report such events.
|
||||
|
||||
This should probably be reported as a bug to whatever Linux distributor
|
||||
people see the problem on. In my opinion, syslogd should be changed to
|
||||
use some other method of communication, or the wrapper function (which
|
||||
appeared to be `daemon' when I looked at it some time ago) or script
|
||||
(which appeared to be `syslog') should catch SIGINT, since it's an
|
||||
expected event, and exit cleanly.
|
||||
|
||||
7. Several people have reported that `dip' (a program for SLIP/PPP
|
||||
on Linux) does not work with bash-2.0 installed as /bin/sh.
|
||||
|
||||
I don't run any Linux boxes myself, and do not have the dip
|
||||
code handy to look at, but the `problem' with bash-2.0, as
|
||||
it has been related to me, is that bash requires the `-p'
|
||||
option to be supplied at invocation if it is to run setuid
|
||||
or setgid.
|
||||
|
||||
This means, among other things, that setuid or setgid programs
|
||||
which call system(3) (a horrendously bad practice in any case)
|
||||
relinquish their setuid/setgid status in the child that's forked
|
||||
to execute /bin/sh.
|
||||
|
||||
The following is an *unofficial* patch to bash-2.0 that causes it
|
||||
to not require `-p' to run setuid or setgid if invoked as `sh'.
|
||||
It has been reported to work on Linux. It will make your system
|
||||
vulnerable to bogus system(3) calls in setuid executables.
|
||||
|
||||
--- ../bash-2.0.orig/shell.c Wed Dec 18 14:16:30 1996
|
||||
+++ shell.c Fri Mar 7 13:12:03 1997
|
||||
@@ -347,7 +347,7 @@
|
||||
if (posixly_correct)
|
||||
posix_initialize (posixly_correct);
|
||||
|
||||
- if (running_setuid && privileged_mode == 0)
|
||||
+ if (running_setuid && privileged_mode == 0 && act_like_sh == 0)
|
||||
disable_priv_mode ();
|
||||
|
||||
/* Need to get the argument to a -c option processed in the
|
||||
|
||||
8. Some people have asked about binding all of the keys in a PC-keyboard-
|
||||
style numeric keypad to readline functions. Here's something I
|
||||
received from the gnu-win32 list that may help. Insert the following
|
||||
lines into ~/.inputrc:
|
||||
|
||||
# home key
|
||||
"\e[1~":beginning-of-line
|
||||
# insert key
|
||||
"\e[2~":kill-whole-line
|
||||
# del key
|
||||
"\e[3~":delete-char
|
||||
# end key
|
||||
"\e[4~":end-of-line
|
||||
# pgup key
|
||||
"\e[5~":history-search-forward
|
||||
# pgdn key
|
||||
"\e[6~":history-search-backward
|
||||
|
||||
9. Hints for building under Minix 2.0 (Contributed by Terry R. McConnell,
|
||||
<tmc@barnyard.syr.edu>)
|
||||
|
||||
The version of /bin/sh distributed with Minix is not up to the job of
|
||||
running the configure script. The easiest solution is to swap /bin/sh
|
||||
with /usr/bin/ash. Then use chmem(1) to increase the memory allocated
|
||||
to /bin/sh. The following settings are known to work:
|
||||
|
||||
text data bss stack memory
|
||||
63552 9440 3304 65536 141832 /bin/sh
|
||||
|
||||
If you have problems with make or yacc it may be worthwhile first to
|
||||
install the GNU versions of these utilities before attempting to build
|
||||
bash. (As of this writing, all of these utilities are available for the
|
||||
i386 as pre-built binaries via anonymous ftp at math.syr.edu in the
|
||||
pub/mcconnell/minix directory. Note that the GNU version of yacc is called
|
||||
bison.)
|
||||
|
||||
Unless you want to see lots of warnings about old-style declarations,
|
||||
do LOCAL_CFLAGS=-wo; export LOCAL_CFLAGS before running configure.
|
||||
(These warnings are harmless, but annoying.)
|
||||
|
||||
configure will insist that you supply a host type. For example, do
|
||||
./configure --host=i386-pc-minix.
|
||||
|
||||
Minix does not support the system calls required for a proper
|
||||
implementation of ulimit(). The `ulimit' builtin will not be available.
|
||||
|
||||
Configure will fail to notice that many things like uid_t are indeed
|
||||
typedef'd in <sys/types.h>, because it uses egrep for this purpose
|
||||
and minix has no egrep. You could try making a link /usr/bin/egrep -->
|
||||
/usr/bin/grep. Better is to install the GNU version of grep in
|
||||
/usr/local/bin and make the link /usr/local/bin/egrep -->/usr/local/bin/grep.
|
||||
(These must be hard links, of course, since Minix does not support
|
||||
symbolic links.)
|
||||
|
||||
You will see many warnings of the form:
|
||||
warning: unknown s_type: 98
|
||||
I have no idea what this means, but it doesn't seem to matter.
|
||||
|
||||
10. If you do not have /usr/ccs/bin in your PATH when building on SunOS 5.x
|
||||
(Solaris 2), the configure script will be unable to find `ar' and
|
||||
`ranlib' (of course, ranlib is unnecessary). Make sure your $PATH
|
||||
includes /usr/ccs/bin on SunOS 5.x. This generally manifests itself
|
||||
with libraries not being built and make reporting errors like
|
||||
`cr: not found' when library construction is attempted.
|
||||
|
||||
11. Building a statically-linked bash on Solaris 2.5.x, 2.6, 7, or 8 is
|
||||
complicated.
|
||||
|
||||
It's not possible to build a completely statically-linked binary, since
|
||||
part of the C library depends on dynamic linking. The following recipe
|
||||
assumes that you're using gcc and the Solaris ld (/usr/ccs/bin/ld) on
|
||||
Solaris 2.5.x or 2.6:
|
||||
|
||||
configure --enable-static-link
|
||||
make STATIC_LD= LOCAL_LIBS='-Wl,-B,dynamic -ldl -Wl,-B,static'
|
||||
|
||||
This should result in a bash binary that depends only on libdl.so:
|
||||
|
||||
thor(2)$ ldd bash
|
||||
libdl.so.1 => /usr/lib/libdl.so.1
|
||||
|
||||
If you're using the Sun C Compiler (Sun WorkShop C Compiler version
|
||||
4.2 was what I used), you should be able to get away with using
|
||||
|
||||
configure --enable-static-link
|
||||
make STATIC_LD= LOCAL_LIBS='-B dynamic -ldl -B static'
|
||||
|
||||
If you want to completely remove any dependence on /usr, perhaps
|
||||
to put a copy of bash in /sbin and have it available when /usr is
|
||||
not mounted, force the build process to use the shared dl.so library
|
||||
in /etc/lib.
|
||||
|
||||
For gcc, this would be something like
|
||||
|
||||
configure --enable-static-link
|
||||
make STATIC_LD= LOCAL_LIBS='-Wl,-B,dynamic -Wl,-R/etc/lib -ldl -Wl,-B,static'
|
||||
|
||||
For Sun's WS4.2 cc
|
||||
|
||||
configure --enable-static-link
|
||||
make STATIC_LD= LOCAL_LIBS='-B dynamic -R/etc/lib -ldl -B static'
|
||||
|
||||
seems to work, at least on Solaris 2.5.1:
|
||||
|
||||
thor(2)$ ldd bash
|
||||
libdl.so.1 => /etc/lib/libdl.so.1
|
||||
|
||||
On Solaris 7 (Solaris 8, using the version of gcc on the free software
|
||||
CD-ROM), the following recipe appears to work for gcc:
|
||||
|
||||
configure --enable-static-link
|
||||
make STATIC_LD='-Wl,-Bstatic' LOCAL_LIBS='-Wl,-Bdynamic -Wl,-R/etc/lib -ldl -Wl,-Bstatic'
|
||||
|
||||
thor.ins.cwru.edu(2)$ ldd bash
|
||||
libdl.so.1 => /etc/lib/libdl.so.1
|
||||
|
||||
Make the analogous changes if you are running Sun's C Compiler.
|
||||
|
||||
I have received word that adding -L/etc/lib (or the equivalent
|
||||
-Wl,-L/etc/lib) might also be necessary, in addition to the -R/etc/lib.
|
||||
|
||||
On later versions of Solaris, it may be necessary to add -lnsl before
|
||||
-ldl; statically-linked versions of bash using libnsl are not guaranteed
|
||||
to work correctly on future versions of Solaris.
|
||||
|
||||
12. Configuring bash to build it in a cross environment. Currently only
|
||||
two native versions can be compiled this way, cygwin32 and x86 BeOS.
|
||||
For BeOS, you would configure it like this:
|
||||
|
||||
export RANLIB=i586-beos-ranlib
|
||||
export AR=i586-beos-ar
|
||||
export CC=i586-beos-gcc
|
||||
configure i586-beos
|
||||
|
||||
Similarly for cygwin32.
|
||||
|
||||
13. Bash-2.05 has reverted to the bash-2.03 behavior of honoring the current
|
||||
locale setting when processing ranges within pattern matching bracket
|
||||
expressions ([A-Z]). This is what POSIX.2 and SUSv2 specify.
|
||||
|
||||
The behavior of the matcher in bash-2.05 depends on the current LC_COLLATE
|
||||
setting. Setting this variable to `C' or `POSIX' will result in the
|
||||
traditional behavior ([A-Z] matches all uppercase ASCII characters).
|
||||
Many other locales, including the en_US locale (the default on many US
|
||||
versions of Linux) collate the upper and lower case letters like this:
|
||||
|
||||
AaBb...Zz
|
||||
|
||||
which means that [A-Z] matches every letter except `z'.
|
||||
|
||||
The portable way to specify upper case letters is [:upper:] instead of
|
||||
A-Z; lower case may be specified as [:lower:] instead of a-z.
|
||||
|
||||
Look at the manual pages for setlocale(3), strcoll(3), and, if it is
|
||||
present, locale(1). If you have locale(1), you can use it to find
|
||||
your current locale information even if you do not have any of the
|
||||
LC_ variables set.
|
||||
|
||||
My advice is to put
|
||||
|
||||
export LC_COLLATE=C
|
||||
|
||||
into /etc/profile and inspect any shell scripts run from cron for
|
||||
constructs like [A-Z]. This will prevent things like
|
||||
|
||||
rm [A-Z]*
|
||||
|
||||
from removing every file in the current directory except those beginning
|
||||
with `z' and still allow individual users to change the collation order.
|
||||
Users may put the above command into their own profiles as well, of course.
|
||||
|
||||
14. Building on Interix (nee OpenNT), which Microsoft bought from Softway
|
||||
Systems and has seemingly abandoned (thanks to Kevin Moore for this item).
|
||||
|
||||
1. cp cross-build/opennt.cache config.cache
|
||||
|
||||
2. If desired, edit pathnames.h to set the values of SYS_PROFILE and
|
||||
DEFAULT_HOSTS_FILE appropriately.
|
||||
|
||||
3. export CONFIG_SHELL=$INTERIX_ROOT/bin/sh
|
||||
|
||||
4. ./configure --prefix=$INTERIX_ROOT/usr/local (or wherever you
|
||||
want it).
|
||||
|
||||
5. make; make install; enjoy
|
||||
|
||||
15. Configure with `CC=xlc' if you don't have gcc on AIX 4.2 and later
|
||||
versions. `xlc' running in `cc' mode has trouble compiling error.c.
|
||||
|
||||
16. Configure --disable-multibyte on NetBSD versions (1.4 through at least
|
||||
1.6.1) that include wctype.h but do not define wctype_t.
|
||||
|
||||
17. Do NOT use bison-1.75. It builds a non-working parser. The most
|
||||
obvious effect is that constructs like "for i; do echo $i; done" don't
|
||||
loop over the positional parameters.
|
||||
|
||||
18. I have received reports that using -O2 with the MIPSpro results in a
|
||||
binary that fails in strange ways. Using -O1 seems to work.
|
||||
|
||||
19. There is special handling to ensure the shell links against static
|
||||
versions of the included readline and history libraries on Mac OS X;
|
||||
Apple ships inadequate dynamic libreadline and libhistory "replacements"
|
||||
as standard libraries.
|
||||
|
||||
20. If you're on a system like SGI Irix, and you get an error about not
|
||||
being able to refer to a dynamic symbol
|
||||
(ld: non-dynamic relocations refer to dynamic symbol PC), add
|
||||
-DNEED_EXTERN_PC to the LOCAL_CFLAGS variable in lib/readline/Makefile.in
|
||||
and rebuild.
|
264
POSIX
Normal file
264
POSIX
Normal file
|
@ -0,0 +1,264 @@
|
|||
6.11 Bash POSIX Mode
|
||||
====================
|
||||
|
||||
Starting Bash with the '--posix' command-line option or executing 'set
|
||||
-o posix' while Bash is running will cause Bash to conform more closely
|
||||
to the POSIX standard by changing the behavior to match that specified
|
||||
by POSIX in areas where the Bash default differs.
|
||||
|
||||
When invoked as 'sh', Bash enters POSIX mode after reading the startup
|
||||
files.
|
||||
|
||||
The following list is what's changed when 'POSIX mode' is in effect:
|
||||
|
||||
1. Bash ensures that the 'POSIXLY_CORRECT' variable is set.
|
||||
|
||||
2. When a command in the hash table no longer exists, Bash will
|
||||
re-search '$PATH' to find the new location. This is also available
|
||||
with 'shopt -s checkhash'.
|
||||
|
||||
3. Bash will not insert a command without the execute bit set into the
|
||||
command hash table, even if it returns it as a (last-ditch) result
|
||||
from a '$PATH' search.
|
||||
|
||||
4. The message printed by the job control code and builtins when a job
|
||||
exits with a non-zero status is 'Done(status)'.
|
||||
|
||||
5. The message printed by the job control code and builtins when a job
|
||||
is stopped is 'Stopped(SIGNAME)', where SIGNAME is, for example,
|
||||
'SIGTSTP'.
|
||||
|
||||
6. Alias expansion is always enabled, even in non-interactive shells.
|
||||
|
||||
7. Reserved words appearing in a context where reserved words are
|
||||
recognized do not undergo alias expansion.
|
||||
|
||||
8. Alias expansion is performed when initially parsing a command
|
||||
substitution. The default mode generally defers it, when enabled,
|
||||
until the command substitution is executed. This means that
|
||||
command substitution will not expand aliases that are defined after
|
||||
the command substitution is initially parsed (e.g., as part of a
|
||||
function definition).
|
||||
|
||||
9. The POSIX 'PS1' and 'PS2' expansions of '!' to the history number
|
||||
and '!!' to '!' are enabled, and parameter expansion is performed
|
||||
on the values of 'PS1' and 'PS2' regardless of the setting of the
|
||||
'promptvars' option.
|
||||
|
||||
10. The POSIX startup files are executed ('$ENV') rather than the
|
||||
normal Bash files.
|
||||
|
||||
11. Tilde expansion is only performed on assignments preceding a
|
||||
command name, rather than on all assignment statements on the line.
|
||||
|
||||
12. The default history file is '~/.sh_history' (this is the default
|
||||
value of '$HISTFILE').
|
||||
|
||||
13. Redirection operators do not perform filename expansion on the
|
||||
word in the redirection unless the shell is interactive.
|
||||
|
||||
14. Redirection operators do not perform word splitting on the word in
|
||||
the redirection.
|
||||
|
||||
15. Function names must be valid shell 'name's. That is, they may not
|
||||
contain characters other than letters, digits, and underscores, and
|
||||
may not start with a digit. Declaring a function with an invalid
|
||||
name causes a fatal syntax error in non-interactive shells.
|
||||
|
||||
16. Function names may not be the same as one of the POSIX special
|
||||
builtins.
|
||||
|
||||
17. POSIX special builtins are found before shell functions during
|
||||
command lookup.
|
||||
|
||||
18. When printing shell function definitions (e.g., by 'type'), Bash
|
||||
does not print the 'function' keyword.
|
||||
|
||||
19. Literal tildes that appear as the first character in elements of
|
||||
the 'PATH' variable are not expanded as described above under *note
|
||||
Tilde Expansion::.
|
||||
|
||||
20. The 'time' reserved word may be used by itself as a command. When
|
||||
used in this way, it displays timing statistics for the shell and
|
||||
its completed children. The 'TIMEFORMAT' variable controls the
|
||||
format of the timing information.
|
||||
|
||||
21. When parsing and expanding a ${...} expansion that appears within
|
||||
double quotes, single quotes are no longer special and cannot be
|
||||
used to quote a closing brace or other special character, unless
|
||||
the operator is one of those defined to perform pattern removal.
|
||||
In this case, they do not have to appear as matched pairs.
|
||||
|
||||
22. The parser does not recognize 'time' as a reserved word if the
|
||||
next token begins with a '-'.
|
||||
|
||||
23. The '!' character does not introduce history expansion within a
|
||||
double-quoted string, even if the 'histexpand' option is enabled.
|
||||
|
||||
24. If a POSIX special builtin returns an error status, a
|
||||
non-interactive shell exits. The fatal errors are those listed in
|
||||
the POSIX standard, and include things like passing incorrect
|
||||
options, redirection errors, variable assignment errors for
|
||||
assignments preceding the command name, and so on.
|
||||
|
||||
25. A non-interactive shell exits with an error status if a variable
|
||||
assignment error occurs when no command name follows the assignment
|
||||
statements. A variable assignment error occurs, for example, when
|
||||
trying to assign a value to a readonly variable.
|
||||
|
||||
26. A non-interactive shell exits with an error status if a variable
|
||||
assignment error occurs in an assignment statement preceding a
|
||||
special builtin, but not with any other simple command. For any
|
||||
other simple command, the shell aborts execution of that command,
|
||||
and execution continues at the top level ("the shell shall not
|
||||
perform any further processing of the command in which the error
|
||||
occurred").
|
||||
|
||||
27. A non-interactive shell exits with an error status if the
|
||||
iteration variable in a 'for' statement or the selection variable
|
||||
in a 'select' statement is a readonly variable.
|
||||
|
||||
28. Non-interactive shells exit if FILENAME in '.' FILENAME is not
|
||||
found.
|
||||
|
||||
29. Non-interactive shells exit if a syntax error in an arithmetic
|
||||
expansion results in an invalid expression.
|
||||
|
||||
30. Non-interactive shells exit if a parameter expansion error occurs.
|
||||
|
||||
31. Non-interactive shells exit if there is a syntax error in a script
|
||||
read with the '.' or 'source' builtins, or in a string processed by
|
||||
the 'eval' builtin.
|
||||
|
||||
32. While variable indirection is available, it may not be applied to
|
||||
the '#' and '?' special parameters.
|
||||
|
||||
33. Expanding the '*' special parameter in a pattern context where the
|
||||
expansion is double-quoted does not treat the '$*' as if it were
|
||||
double-quoted.
|
||||
|
||||
34. Assignment statements preceding POSIX special builtins persist in
|
||||
the shell environment after the builtin completes.
|
||||
|
||||
35. The 'command' builtin does not prevent builtins that take
|
||||
assignment statements as arguments from expanding them as
|
||||
assignment statements; when not in POSIX mode, assignment builtins
|
||||
lose their assignment statement expansion properties when preceded
|
||||
by 'command'.
|
||||
|
||||
36. The 'bg' builtin uses the required format to describe each job
|
||||
placed in the background, which does not include an indication of
|
||||
whether the job is the current or previous job.
|
||||
|
||||
37. The output of 'kill -l' prints all the signal names on a single
|
||||
line, separated by spaces, without the 'SIG' prefix.
|
||||
|
||||
38. The 'kill' builtin does not accept signal names with a 'SIG'
|
||||
prefix.
|
||||
|
||||
39. The 'export' and 'readonly' builtin commands display their output
|
||||
in the format required by POSIX.
|
||||
|
||||
40. The 'trap' builtin displays signal names without the leading
|
||||
'SIG'.
|
||||
|
||||
41. The 'trap' builtin doesn't check the first argument for a possible
|
||||
signal specification and revert the signal handling to the original
|
||||
disposition if it is, unless that argument consists solely of
|
||||
digits and is a valid signal number. If users want to reset the
|
||||
handler for a given signal to the original disposition, they should
|
||||
use '-' as the first argument.
|
||||
|
||||
42. 'trap -p' displays signals whose dispositions are set to SIG_DFL
|
||||
and those that were ignored when the shell started.
|
||||
|
||||
43. The '.' and 'source' builtins do not search the current directory
|
||||
for the filename argument if it is not found by searching 'PATH'.
|
||||
|
||||
44. Enabling POSIX mode has the effect of setting the
|
||||
'inherit_errexit' option, so subshells spawned to execute command
|
||||
substitutions inherit the value of the '-e' option from the parent
|
||||
shell. When the 'inherit_errexit' option is not enabled, Bash
|
||||
clears the '-e' option in such subshells.
|
||||
|
||||
45. Enabling POSIX mode has the effect of setting the 'shift_verbose'
|
||||
option, so numeric arguments to 'shift' that exceed the number of
|
||||
positional parameters will result in an error message.
|
||||
|
||||
46. When the 'alias' builtin displays alias definitions, it does not
|
||||
display them with a leading 'alias ' unless the '-p' option is
|
||||
supplied.
|
||||
|
||||
47. When the 'set' builtin is invoked without options, it does not
|
||||
display shell function names and definitions.
|
||||
|
||||
48. When the 'set' builtin is invoked without options, it displays
|
||||
variable values without quotes, unless they contain shell
|
||||
metacharacters, even if the result contains nonprinting characters.
|
||||
|
||||
49. When the 'cd' builtin is invoked in logical mode, and the pathname
|
||||
constructed from '$PWD' and the directory name supplied as an
|
||||
argument does not refer to an existing directory, 'cd' will fail
|
||||
instead of falling back to physical mode.
|
||||
|
||||
50. When the 'cd' builtin cannot change a directory because the length
|
||||
of the pathname constructed from '$PWD' and the directory name
|
||||
supplied as an argument exceeds 'PATH_MAX' when all symbolic links
|
||||
are expanded, 'cd' will fail instead of attempting to use only the
|
||||
supplied directory name.
|
||||
|
||||
51. The 'pwd' builtin verifies that the value it prints is the same as
|
||||
the current directory, even if it is not asked to check the file
|
||||
system with the '-P' option.
|
||||
|
||||
52. When listing the history, the 'fc' builtin does not include an
|
||||
indication of whether or not a history entry has been modified.
|
||||
|
||||
53. The default editor used by 'fc' is 'ed'.
|
||||
|
||||
54. The 'type' and 'command' builtins will not report a non-executable
|
||||
file as having been found, though the shell will attempt to execute
|
||||
such a file if it is the only so-named file found in '$PATH'.
|
||||
|
||||
55. The 'vi' editing mode will invoke the 'vi' editor directly when
|
||||
the 'v' command is run, instead of checking '$VISUAL' and
|
||||
'$EDITOR'.
|
||||
|
||||
56. When the 'xpg_echo' option is enabled, Bash does not attempt to
|
||||
interpret any arguments to 'echo' as options. Each argument is
|
||||
displayed, after escape characters are converted.
|
||||
|
||||
57. The 'ulimit' builtin uses a block size of 512 bytes for the '-c'
|
||||
and '-f' options.
|
||||
|
||||
58. The arrival of 'SIGCHLD' when a trap is set on 'SIGCHLD' does not
|
||||
interrupt the 'wait' builtin and cause it to return immediately.
|
||||
The trap command is run once for each child that exits.
|
||||
|
||||
59. The 'read' builtin may be interrupted by a signal for which a trap
|
||||
has been set. If Bash receives a trapped signal while executing
|
||||
'read', the trap handler executes and 'read' returns an exit status
|
||||
greater than 128.
|
||||
|
||||
60. The 'printf' builtin uses 'double' (via 'strtod') to convert
|
||||
arguments corresponding to floating point conversion specifiers,
|
||||
instead of 'long double' if it's available. The 'L' length
|
||||
modifier forces 'printf' to use 'long double' if it's available.
|
||||
|
||||
61. Bash removes an exited background process's status from the list
|
||||
of such statuses after the 'wait' builtin is used to obtain it.
|
||||
|
||||
There is other POSIX behavior that Bash does not implement by default
|
||||
even when in POSIX mode. Specifically:
|
||||
|
||||
1. The 'fc' builtin checks '$EDITOR' as a program to edit history
|
||||
entries if 'FCEDIT' is unset, rather than defaulting directly to
|
||||
'ed'. 'fc' uses 'ed' if 'EDITOR' is unset.
|
||||
|
||||
2. As noted above, Bash requires the 'xpg_echo' option to be enabled
|
||||
for the 'echo' builtin to be fully conformant.
|
||||
|
||||
Bash can be configured to be POSIX-conformant by default, by specifying
|
||||
the '--enable-strict-posix-default' to 'configure' when building (*note
|
||||
Optional Features::).
|
||||
|
52
RBASH
Normal file
52
RBASH
Normal file
|
@ -0,0 +1,52 @@
|
|||
6.10 The Restricted Shell
|
||||
=========================
|
||||
|
||||
If Bash is started with the name 'rbash', or the '--restricted' or '-r'
|
||||
option is supplied at invocation, the shell becomes restricted. A
|
||||
restricted shell is used to set up an environment more controlled than
|
||||
the standard shell. A restricted shell behaves identically to 'bash'
|
||||
with the exception that the following are disallowed or not performed:
|
||||
|
||||
* Changing directories with the 'cd' builtin.
|
||||
* Setting or unsetting the values of the 'SHELL', 'PATH', 'HISTFILE',
|
||||
'ENV', or 'BASH_ENV' variables.
|
||||
* Specifying command names containing slashes.
|
||||
* Specifying a filename containing a slash as an argument to the '.'
|
||||
builtin command.
|
||||
* Specifying a filename containing a slash as an argument to the
|
||||
'history' builtin command.
|
||||
* Specifying a filename containing a slash as an argument to the '-p'
|
||||
option to the 'hash' builtin command.
|
||||
* Importing function definitions from the shell environment at
|
||||
startup.
|
||||
* Parsing the value of 'SHELLOPTS' from the shell environment at
|
||||
startup.
|
||||
* Redirecting output using the '>', '>|', '<>', '>&', '&>', and '>>'
|
||||
redirection operators.
|
||||
* Using the 'exec' builtin to replace the shell with another command.
|
||||
* Adding or deleting builtin commands with the '-f' and '-d' options
|
||||
to the 'enable' builtin.
|
||||
* Using the 'enable' builtin command to enable disabled shell
|
||||
builtins.
|
||||
* Specifying the '-p' option to the 'command' builtin.
|
||||
* Turning off restricted mode with 'set +r' or 'shopt -u
|
||||
restricted_shell'.
|
||||
|
||||
These restrictions are enforced after any startup files are read.
|
||||
|
||||
When a command that is found to be a shell script is executed (*note
|
||||
Shell Scripts::), 'rbash' turns off any restrictions in the shell
|
||||
spawned to execute the script.
|
||||
|
||||
The restricted shell mode is only one component of a useful restricted
|
||||
environment. It should be accompanied by setting 'PATH' to a value that
|
||||
allows execution of only a few verified commands (commands that allow
|
||||
shell escapes are particularly vulnerable), changing the current
|
||||
directory to a non-writable directory other than '$HOME' after login,
|
||||
not allowing the restricted shell to execute shell scripts, and cleaning
|
||||
the environment of variables that cause some commands to modify their
|
||||
behavior (e.g., 'VISUAL' or 'PAGER').
|
||||
|
||||
Modern systems provide more secure ways to implement a restricted
|
||||
environment, such as 'jails', 'zones', or 'containers'.
|
||||
|
112
README
Normal file
112
README
Normal file
|
@ -0,0 +1,112 @@
|
|||
Introduction
|
||||
============
|
||||
|
||||
This is GNU Bash, version 5.2. Bash is the GNU Project's Bourne
|
||||
Again SHell, a complete implementation of the POSIX shell spec,
|
||||
but also with interactive command line editing, job control on
|
||||
architectures that support it, csh-like features such as history
|
||||
substitution and brace expansion, and a slew of other features.
|
||||
For more information on the features of Bash that are new to this
|
||||
type of shell, see the file `doc/bashref.texi'. There is also a
|
||||
large Unix-style man page. The man page is the definitive description
|
||||
of the shell's features.
|
||||
|
||||
See the file POSIX for a discussion of how the Bash defaults differ
|
||||
from the POSIX spec and a description of the Bash `posix mode'.
|
||||
|
||||
There are some user-visible incompatibilities between this version
|
||||
of Bash and previous widely-distributed versions, bash-4.4, bash-5.0,
|
||||
and bash-5.1. For details, see the file COMPAT. The NEWS file tersely
|
||||
lists features that are new in this release.
|
||||
|
||||
Bash is free software, distributed under the terms of the [GNU] General
|
||||
Public License as published by the Free Software Foundation,
|
||||
version 3 of the License (or any later version). For more information,
|
||||
see the file COPYING.
|
||||
|
||||
A number of frequently-asked questions are answered in the file
|
||||
`doc/FAQ'. (That file is no longer updated.)
|
||||
|
||||
To compile Bash, type `./configure', then `make'. Bash auto-configures
|
||||
the build process, so no further intervention should be necessary. Bash
|
||||
builds with `gcc' by default if it is available. If you want to use `cc'
|
||||
instead, type
|
||||
|
||||
CC=cc ./configure
|
||||
|
||||
if you are using a Bourne-style shell. If you are not, the following
|
||||
may work:
|
||||
|
||||
env CC=cc ./configure
|
||||
|
||||
Read the file INSTALL in this directory for more information about how
|
||||
to customize and control the build process. The file NOTES contains
|
||||
platform-specific installation and configuration information.
|
||||
|
||||
If you are a csh user and wish to convert your csh aliases to Bash
|
||||
aliases, you may wish to use the script `examples/misc/alias-conv.sh'
|
||||
as a starting point. The script `examples/misc/cshtobash' is a
|
||||
more ambitious script that attempts to do a more complete job.
|
||||
|
||||
Reporting Bugs
|
||||
==============
|
||||
|
||||
Bug reports for bash should be sent to:
|
||||
|
||||
bug-bash@gnu.org
|
||||
|
||||
using the `bashbug' program that is built and installed at the same
|
||||
time as bash.
|
||||
|
||||
The discussion list `bug-bash@gnu.org' often contains information
|
||||
about new ports of Bash, or discussions of new features or behavior
|
||||
changes that people would like. This mailing list is also available
|
||||
as a usenet newsgroup: gnu.bash.bug.
|
||||
|
||||
When you send a bug report, please use the `bashbug' program that is
|
||||
built at the same time as bash. If bash fails to build, try building
|
||||
bashbug directly with `make bashbug'. If you cannot build `bashbug',
|
||||
please send mail to bug-bash@gnu.org with the following information:
|
||||
|
||||
* the version number and release status of Bash (e.g., 2.05a-release)
|
||||
* the machine and OS that it is running on (you may run
|
||||
`bashversion -l' from the bash build directory for this information)
|
||||
* a list of the compilation flags or the contents of `config.h', if
|
||||
appropriate
|
||||
* a description of the bug
|
||||
* a recipe for recreating the bug reliably
|
||||
* a fix for the bug if you have one!
|
||||
|
||||
The `bashbug' program includes much of this automatically.
|
||||
|
||||
Questions and requests for help with bash and bash programming may be
|
||||
sent to the help-bash@gnu.org mailing list.
|
||||
|
||||
If you would like to contact the Bash maintainers directly, send mail
|
||||
to bash-maintainers@gnu.org.
|
||||
|
||||
While the Bash maintainers do not promise to fix all bugs, we would
|
||||
like this shell to be the best that we can make it.
|
||||
|
||||
Other Packages
|
||||
==============
|
||||
|
||||
This distribution includes, in examples/bash-completion, a recent version
|
||||
of the `bash-completion' package, which provides programmable completions
|
||||
for a number of commands. It's available as a package in many distributions,
|
||||
and that is the first place from which to obtain it.
|
||||
|
||||
The latest version of bash-completion is always available from
|
||||
https://github.com/scop/bash-completion.
|
||||
|
||||
If it's not a package from your vendor, you may install the included version.
|
||||
|
||||
Enjoy!
|
||||
|
||||
Chet Ramey
|
||||
chet.ramey@case.edu
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved. This file is offered as-is,
|
||||
without any warranty.
|
4
Y2K
Normal file
4
Y2K
Normal file
|
@ -0,0 +1,4 @@
|
|||
Since Bash does not manipulate date strings, it is Y2K-safe.
|
||||
|
||||
The only thing that Bash does with date strings is manipulate the string
|
||||
returned by ctime(3) or strftime(3) in the prompt customization code.
|
2267
aclocal.m4
vendored
Normal file
2267
aclocal.m4
vendored
Normal file
File diff suppressed because it is too large
Load diff
594
alias.c
Normal file
594
alias.c
Normal file
|
@ -0,0 +1,594 @@
|
|||
/* alias.c -- Not a full alias, but just the kind that we use in the
|
||||
shell. Csh style alias is somewhere else (`over there, in a box'). */
|
||||
|
||||
/* Copyright (C) 1987-2021 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/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if defined (ALIAS)
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "chartypes.h"
|
||||
#include "bashansi.h"
|
||||
#include "command.h"
|
||||
#include "general.h"
|
||||
#include "externs.h"
|
||||
#include "alias.h"
|
||||
|
||||
#if defined (PROGRAMMABLE_COMPLETION)
|
||||
# include "pcomplete.h"
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_MBSTR_H) && defined (HAVE_MBSCHR)
|
||||
# include <mbstr.h> /* mbschr */
|
||||
#endif
|
||||
|
||||
#define ALIAS_HASH_BUCKETS 64 /* must be power of two */
|
||||
|
||||
typedef int sh_alias_map_func_t PARAMS((alias_t *));
|
||||
|
||||
static void free_alias_data PARAMS((PTR_T));
|
||||
static alias_t **map_over_aliases PARAMS((sh_alias_map_func_t *));
|
||||
static void sort_aliases PARAMS((alias_t **));
|
||||
static int qsort_alias_compare PARAMS((alias_t **, alias_t **));
|
||||
|
||||
#if defined (READLINE)
|
||||
static int skipquotes PARAMS((char *, int));
|
||||
static int skipws PARAMS((char *, int));
|
||||
static int rd_token PARAMS((char *, int));
|
||||
#endif
|
||||
|
||||
/* Non-zero means expand all words on the line. Otherwise, expand
|
||||
after first expansion if the expansion ends in a space. */
|
||||
int alias_expand_all = 0;
|
||||
|
||||
/* The list of aliases that we have. */
|
||||
HASH_TABLE *aliases = (HASH_TABLE *)NULL;
|
||||
|
||||
void
|
||||
initialize_aliases ()
|
||||
{
|
||||
if (aliases == 0)
|
||||
aliases = hash_create (ALIAS_HASH_BUCKETS);
|
||||
}
|
||||
|
||||
/* Scan the list of aliases looking for one with NAME. Return NULL
|
||||
if the alias doesn't exist, else a pointer to the alias_t. */
|
||||
alias_t *
|
||||
find_alias (name)
|
||||
char *name;
|
||||
{
|
||||
BUCKET_CONTENTS *al;
|
||||
|
||||
if (aliases == 0)
|
||||
return ((alias_t *)NULL);
|
||||
|
||||
al = hash_search (name, aliases, 0);
|
||||
return (al ? (alias_t *)al->data : (alias_t *)NULL);
|
||||
}
|
||||
|
||||
/* Return the value of the alias for NAME, or NULL if there is none. */
|
||||
char *
|
||||
get_alias_value (name)
|
||||
char *name;
|
||||
{
|
||||
alias_t *alias;
|
||||
|
||||
if (aliases == 0)
|
||||
return ((char *)NULL);
|
||||
|
||||
alias = find_alias (name);
|
||||
return (alias ? alias->value : (char *)NULL);
|
||||
}
|
||||
|
||||
/* Make a new alias from NAME and VALUE. If NAME can be found,
|
||||
then replace its value. */
|
||||
void
|
||||
add_alias (name, value)
|
||||
char *name, *value;
|
||||
{
|
||||
BUCKET_CONTENTS *elt;
|
||||
alias_t *temp;
|
||||
int n;
|
||||
|
||||
if (aliases == 0)
|
||||
{
|
||||
initialize_aliases ();
|
||||
temp = (alias_t *)NULL;
|
||||
}
|
||||
else
|
||||
temp = find_alias (name);
|
||||
|
||||
if (temp)
|
||||
{
|
||||
free (temp->value);
|
||||
temp->value = savestring (value);
|
||||
temp->flags &= ~AL_EXPANDNEXT;
|
||||
if (value[0])
|
||||
{
|
||||
n = value[strlen (value) - 1];
|
||||
if (n == ' ' || n == '\t')
|
||||
temp->flags |= AL_EXPANDNEXT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = (alias_t *)xmalloc (sizeof (alias_t));
|
||||
temp->name = savestring (name);
|
||||
temp->value = savestring (value);
|
||||
temp->flags = 0;
|
||||
|
||||
if (value[0])
|
||||
{
|
||||
n = value[strlen (value) - 1];
|
||||
if (n == ' ' || n == '\t')
|
||||
temp->flags |= AL_EXPANDNEXT;
|
||||
}
|
||||
|
||||
elt = hash_insert (savestring (name), aliases, HASH_NOSRCH);
|
||||
elt->data = temp;
|
||||
#if defined (PROGRAMMABLE_COMPLETION)
|
||||
set_itemlist_dirty (&it_aliases);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete a single alias structure. */
|
||||
static void
|
||||
free_alias_data (data)
|
||||
PTR_T data;
|
||||
{
|
||||
register alias_t *a;
|
||||
|
||||
a = (alias_t *)data;
|
||||
|
||||
if (a->flags & AL_BEINGEXPANDED)
|
||||
clear_string_list_expander (a); /* call back to the parser */
|
||||
|
||||
free (a->value);
|
||||
free (a->name);
|
||||
free (data);
|
||||
}
|
||||
|
||||
/* Remove the alias with name NAME from the alias table. Returns
|
||||
the number of aliases left in the table, or -1 if the alias didn't
|
||||
exist. */
|
||||
int
|
||||
remove_alias (name)
|
||||
char *name;
|
||||
{
|
||||
BUCKET_CONTENTS *elt;
|
||||
|
||||
if (aliases == 0)
|
||||
return (-1);
|
||||
|
||||
elt = hash_remove (name, aliases, 0);
|
||||
if (elt)
|
||||
{
|
||||
free_alias_data (elt->data);
|
||||
free (elt->key); /* alias name */
|
||||
free (elt); /* XXX */
|
||||
#if defined (PROGRAMMABLE_COMPLETION)
|
||||
set_itemlist_dirty (&it_aliases);
|
||||
#endif
|
||||
return (aliases->nentries);
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Delete all aliases. */
|
||||
void
|
||||
delete_all_aliases ()
|
||||
{
|
||||
if (aliases == 0)
|
||||
return;
|
||||
|
||||
hash_flush (aliases, free_alias_data);
|
||||
hash_dispose (aliases);
|
||||
aliases = (HASH_TABLE *)NULL;
|
||||
#if defined (PROGRAMMABLE_COMPLETION)
|
||||
set_itemlist_dirty (&it_aliases);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Return an array of aliases that satisfy the conditions tested by FUNCTION.
|
||||
If FUNCTION is NULL, return all aliases. */
|
||||
static alias_t **
|
||||
map_over_aliases (function)
|
||||
sh_alias_map_func_t *function;
|
||||
{
|
||||
register int i;
|
||||
register BUCKET_CONTENTS *tlist;
|
||||
alias_t *alias, **list;
|
||||
int list_index;
|
||||
|
||||
i = HASH_ENTRIES (aliases);
|
||||
if (i == 0)
|
||||
return ((alias_t **)NULL);
|
||||
|
||||
list = (alias_t **)xmalloc ((i + 1) * sizeof (alias_t *));
|
||||
for (i = list_index = 0; i < aliases->nbuckets; i++)
|
||||
{
|
||||
for (tlist = hash_items (i, aliases); tlist; tlist = tlist->next)
|
||||
{
|
||||
alias = (alias_t *)tlist->data;
|
||||
|
||||
if (!function || (*function) (alias))
|
||||
{
|
||||
list[list_index++] = alias;
|
||||
list[list_index] = (alias_t *)NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (list);
|
||||
}
|
||||
|
||||
static void
|
||||
sort_aliases (array)
|
||||
alias_t **array;
|
||||
{
|
||||
qsort (array, strvec_len ((char **)array), sizeof (alias_t *), (QSFUNC *)qsort_alias_compare);
|
||||
}
|
||||
|
||||
static int
|
||||
qsort_alias_compare (as1, as2)
|
||||
alias_t **as1, **as2;
|
||||
{
|
||||
int result;
|
||||
|
||||
if ((result = (*as1)->name[0] - (*as2)->name[0]) == 0)
|
||||
result = strcmp ((*as1)->name, (*as2)->name);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
/* Return a sorted list of all defined aliases */
|
||||
alias_t **
|
||||
all_aliases ()
|
||||
{
|
||||
alias_t **list;
|
||||
|
||||
if (aliases == 0 || HASH_ENTRIES (aliases) == 0)
|
||||
return ((alias_t **)NULL);
|
||||
|
||||
list = map_over_aliases ((sh_alias_map_func_t *)NULL);
|
||||
if (list)
|
||||
sort_aliases (list);
|
||||
return (list);
|
||||
}
|
||||
|
||||
char *
|
||||
alias_expand_word (s)
|
||||
char *s;
|
||||
{
|
||||
alias_t *r;
|
||||
|
||||
r = find_alias (s);
|
||||
return (r ? savestring (r->value) : (char *)NULL);
|
||||
}
|
||||
|
||||
/* Readline support functions -- expand all aliases in a line. */
|
||||
|
||||
#if defined (READLINE)
|
||||
|
||||
/* Return non-zero if CHARACTER is a member of the class of characters
|
||||
that are self-delimiting in the shell (this really means that these
|
||||
characters delimit tokens). */
|
||||
#define self_delimiting(character) (member ((character), " \t\n\r;|&()"))
|
||||
|
||||
/* Return non-zero if CHARACTER is a member of the class of characters
|
||||
that delimit commands in the shell. */
|
||||
#define command_separator(character) (member ((character), "\r\n;|&("))
|
||||
|
||||
/* If this is 1, we are checking the next token read for alias expansion
|
||||
because it is the first word in a command. */
|
||||
static int command_word;
|
||||
|
||||
/* This is for skipping quoted strings in alias expansions. */
|
||||
#define quote_char(c) (((c) == '\'') || ((c) == '"'))
|
||||
|
||||
/* Consume a quoted string from STRING, starting at string[START] (so
|
||||
string[START] is the opening quote character), and return the index
|
||||
of the closing quote character matching the opening quote character.
|
||||
This handles single matching pairs of unquoted quotes; it could afford
|
||||
to be a little smarter... This skips words between balanced pairs of
|
||||
quotes, words where the first character is quoted with a `\', and other
|
||||
backslash-escaped characters. */
|
||||
|
||||
static int
|
||||
skipquotes (string, start)
|
||||
char *string;
|
||||
int start;
|
||||
{
|
||||
register int i;
|
||||
int delimiter = string[start];
|
||||
|
||||
/* i starts at START + 1 because string[START] is the opening quote
|
||||
character. */
|
||||
for (i = start + 1 ; string[i] ; i++)
|
||||
{
|
||||
if (string[i] == '\\')
|
||||
{
|
||||
i++; /* skip backslash-quoted quote characters, too */
|
||||
if (string[i] == 0)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string[i] == delimiter)
|
||||
return i;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
/* Skip the white space and any quoted characters in STRING, starting at
|
||||
START. Return the new index into STRING, after zero or more characters
|
||||
have been skipped. */
|
||||
static int
|
||||
skipws (string, start)
|
||||
char *string;
|
||||
int start;
|
||||
{
|
||||
register int i;
|
||||
int pass_next, backslash_quoted_word;
|
||||
unsigned char peekc;
|
||||
|
||||
/* skip quoted strings, in ' or ", and words in which a character is quoted
|
||||
with a `\'. */
|
||||
i = backslash_quoted_word = pass_next = 0;
|
||||
|
||||
/* Skip leading whitespace (or separator characters), and quoted words.
|
||||
But save it in the output. */
|
||||
|
||||
for (i = start; string[i]; i++)
|
||||
{
|
||||
if (pass_next)
|
||||
{
|
||||
pass_next = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (whitespace (string[i]))
|
||||
{
|
||||
backslash_quoted_word = 0; /* we are no longer in a backslash-quoted word */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string[i] == '\\')
|
||||
{
|
||||
peekc = string[i+1];
|
||||
if (peekc == 0)
|
||||
break;
|
||||
if (ISLETTER (peekc))
|
||||
backslash_quoted_word++; /* this is a backslash-quoted word */
|
||||
else
|
||||
pass_next++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* This only handles single pairs of non-escaped quotes. This
|
||||
overloads backslash_quoted_word to also mean that a word like
|
||||
""f is being scanned, so that the quotes will inhibit any expansion
|
||||
of the word. */
|
||||
if (quote_char(string[i]))
|
||||
{
|
||||
i = skipquotes (string, i);
|
||||
/* This could be a line that contains a single quote character,
|
||||
in which case skipquotes () terminates with string[i] == '\0'
|
||||
(the end of the string). Check for that here. */
|
||||
if (string[i] == '\0')
|
||||
break;
|
||||
|
||||
peekc = string[i + 1];
|
||||
if (ISLETTER (peekc))
|
||||
backslash_quoted_word++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If we're in the middle of some kind of quoted word, let it
|
||||
pass through. */
|
||||
if (backslash_quoted_word)
|
||||
continue;
|
||||
|
||||
/* If this character is a shell command separator, then set a hint for
|
||||
alias_expand that the next token is the first word in a command. */
|
||||
|
||||
if (command_separator (string[i]))
|
||||
{
|
||||
command_word++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
/* Characters that may appear in a token. Basically, anything except white
|
||||
space and a token separator. */
|
||||
#define token_char(c) (!((whitespace (string[i]) || self_delimiting (string[i]))))
|
||||
|
||||
/* Read from START in STRING until the next separator character, and return
|
||||
the index of that separator. Skip backslash-quoted characters. Call
|
||||
skipquotes () for quoted strings in the middle or at the end of tokens,
|
||||
so all characters show up (e.g. foo'' and foo""bar) */
|
||||
static int
|
||||
rd_token (string, start)
|
||||
char *string;
|
||||
int start;
|
||||
{
|
||||
register int i;
|
||||
|
||||
/* From here to next separator character is a token. */
|
||||
for (i = start; string[i] && token_char (string[i]); i++)
|
||||
{
|
||||
if (string[i] == '\\')
|
||||
{
|
||||
i++; /* skip backslash-escaped character */
|
||||
if (string[i] == 0)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If this character is a quote character, we want to call skipquotes
|
||||
to get the whole quoted portion as part of this word. That word
|
||||
will not generally match an alias, even if te unquoted word would
|
||||
have. The presence of the quotes in the token serves then to
|
||||
inhibit expansion. */
|
||||
if (quote_char (string[i]))
|
||||
{
|
||||
i = skipquotes (string, i);
|
||||
/* This could be a line that contains a single quote character,
|
||||
in which case skipquotes () terminates with string[i] == '\0'
|
||||
(the end of the string). Check for that here. */
|
||||
if (string[i] == '\0')
|
||||
break;
|
||||
|
||||
/* Now string[i] is the matching quote character, and the
|
||||
quoted portion of the token has been scanned. */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
/* Return a new line, with any aliases substituted. */
|
||||
char *
|
||||
alias_expand (string)
|
||||
char *string;
|
||||
{
|
||||
register int i, j, start;
|
||||
char *line, *token;
|
||||
int line_len, tl, real_start, expand_next, expand_this_token;
|
||||
alias_t *alias;
|
||||
|
||||
line_len = strlen (string) + 1;
|
||||
line = (char *)xmalloc (line_len);
|
||||
token = (char *)xmalloc (line_len);
|
||||
|
||||
line[0] = i = 0;
|
||||
expand_next = 0;
|
||||
command_word = 1; /* initialized to expand the first word on the line */
|
||||
|
||||
/* Each time through the loop we find the next word in line. If it
|
||||
has an alias, substitute the alias value. If the value ends in ` ',
|
||||
then try again with the next word. Else, if there is no value, or if
|
||||
the value does not end in space, we are done. */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
|
||||
token[0] = 0;
|
||||
start = i;
|
||||
|
||||
/* Skip white space and quoted characters */
|
||||
i = skipws (string, start);
|
||||
|
||||
if (start == i && string[i] == '\0')
|
||||
{
|
||||
free (token);
|
||||
return (line);
|
||||
}
|
||||
|
||||
/* copy the just-skipped characters into the output string,
|
||||
expanding it if there is not enough room. */
|
||||
j = strlen (line);
|
||||
tl = i - start; /* number of characters just skipped */
|
||||
RESIZE_MALLOCED_BUFFER (line, j, (tl + 1), line_len, (tl + 50));
|
||||
strncpy (line + j, string + start, tl);
|
||||
line[j + tl] = '\0';
|
||||
|
||||
real_start = i;
|
||||
|
||||
command_word = command_word || (command_separator (string[i]));
|
||||
expand_this_token = (command_word || expand_next);
|
||||
expand_next = 0;
|
||||
|
||||
/* Read the next token, and copy it into TOKEN. */
|
||||
start = i;
|
||||
i = rd_token (string, start);
|
||||
|
||||
tl = i - start; /* token length */
|
||||
|
||||
/* If tl == 0, but we're not at the end of the string, then we have a
|
||||
single-character token, probably a delimiter */
|
||||
if (tl == 0 && string[i] != '\0')
|
||||
{
|
||||
tl = 1;
|
||||
i++; /* move past it */
|
||||
}
|
||||
|
||||
strncpy (token, string + start, tl);
|
||||
token [tl] = '\0';
|
||||
|
||||
/* If there is a backslash-escaped character quoted in TOKEN,
|
||||
then we don't do alias expansion. This should check for all
|
||||
other quoting characters, too. */
|
||||
if (mbschr (token, '\\'))
|
||||
expand_this_token = 0;
|
||||
|
||||
/* If we should be expanding here, if we are expanding all words, or if
|
||||
we are in a location in the string where an expansion is supposed to
|
||||
take place, see if this word has a substitution. If it does, then do
|
||||
the expansion. Note that we defer the alias value lookup until we
|
||||
are sure we are expanding this token. */
|
||||
|
||||
if ((token[0]) &&
|
||||
(expand_this_token || alias_expand_all) &&
|
||||
(alias = find_alias (token)))
|
||||
{
|
||||
char *v;
|
||||
int vlen, llen;
|
||||
|
||||
v = alias->value;
|
||||
vlen = strlen (v);
|
||||
llen = strlen (line);
|
||||
|
||||
/* +3 because we possibly add one more character below. */
|
||||
RESIZE_MALLOCED_BUFFER (line, llen, (vlen + 3), line_len, (vlen + 50));
|
||||
|
||||
strcpy (line + llen, v);
|
||||
|
||||
if ((expand_this_token && vlen && whitespace (v[vlen - 1])) ||
|
||||
alias_expand_all)
|
||||
expand_next = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int llen, tlen;
|
||||
|
||||
llen = strlen (line);
|
||||
tlen = i - real_start; /* tlen == strlen(token) */
|
||||
|
||||
RESIZE_MALLOCED_BUFFER (line, llen, (tlen + 1), line_len, (llen + tlen + 50));
|
||||
|
||||
strncpy (line + llen, string + real_start, tlen);
|
||||
line[llen + tlen] = '\0';
|
||||
}
|
||||
command_word = 0;
|
||||
}
|
||||
}
|
||||
#endif /* READLINE */
|
||||
#endif /* ALIAS */
|
73
alias.h
Normal file
73
alias.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
/* alias.h -- structure definitions. */
|
||||
|
||||
/* Copyright (C) 1987-2020 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/>.
|
||||
*/
|
||||
|
||||
#if !defined (_ALIAS_H_)
|
||||
#define _ALIAS_H_
|
||||
|
||||
#include "stdc.h"
|
||||
|
||||
#include "hashlib.h"
|
||||
|
||||
typedef struct alias {
|
||||
char *name;
|
||||
char *value;
|
||||
char flags;
|
||||
} alias_t;
|
||||
|
||||
/* Values for `flags' member of struct alias. */
|
||||
#define AL_EXPANDNEXT 0x1
|
||||
#define AL_BEINGEXPANDED 0x2
|
||||
|
||||
/* The list of known aliases. */
|
||||
extern HASH_TABLE *aliases;
|
||||
|
||||
extern void initialize_aliases PARAMS((void));
|
||||
|
||||
/* Scan the list of aliases looking for one with NAME. Return NULL
|
||||
if the alias doesn't exist, else a pointer to the alias. */
|
||||
extern alias_t *find_alias PARAMS((char *));
|
||||
|
||||
/* Return the value of the alias for NAME, or NULL if there is none. */
|
||||
extern char *get_alias_value PARAMS((char *));
|
||||
|
||||
/* Make a new alias from NAME and VALUE. If NAME can be found,
|
||||
then replace its value. */
|
||||
extern void add_alias PARAMS((char *, char *));
|
||||
|
||||
/* Remove the alias with name NAME from the alias list. Returns
|
||||
the index of the removed alias, or -1 if the alias didn't exist. */
|
||||
extern int remove_alias PARAMS((char *));
|
||||
|
||||
/* Remove all aliases. */
|
||||
extern void delete_all_aliases PARAMS((void));
|
||||
|
||||
/* Return an array of all defined aliases. */
|
||||
extern alias_t **all_aliases PARAMS((void));
|
||||
|
||||
/* Expand a single word for aliases. */
|
||||
extern char *alias_expand_word PARAMS((char *));
|
||||
|
||||
/* Return a new line, with any aliases expanded. */
|
||||
extern char *alias_expand PARAMS((char *));
|
||||
|
||||
/* Helper definition for the parser */
|
||||
extern void clear_string_list_expander PARAMS((alias_t *));
|
||||
|
||||
#endif /* _ALIAS_H_ */
|
182
array.h
Normal file
182
array.h
Normal file
|
@ -0,0 +1,182 @@
|
|||
/* array.h -- definitions for the interface exported by array.c that allows
|
||||
the rest of the shell to manipulate array variables. */
|
||||
|
||||
/* Copyright (C) 1997-2021 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/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _ARRAY_H_
|
||||
#define _ARRAY_H_
|
||||
|
||||
#include "stdc.h"
|
||||
|
||||
typedef intmax_t arrayind_t;
|
||||
|
||||
typedef struct array {
|
||||
arrayind_t max_index;
|
||||
arrayind_t num_elements;
|
||||
#ifdef ALT_ARRAY_IMPLEMENTATION
|
||||
arrayind_t first_index;
|
||||
arrayind_t alloc_size;
|
||||
struct array_element **elements;
|
||||
#else
|
||||
struct array_element *head;
|
||||
struct array_element *lastref;
|
||||
#endif
|
||||
} ARRAY;
|
||||
|
||||
typedef struct array_element {
|
||||
arrayind_t ind;
|
||||
char *value;
|
||||
#ifndef ALT_ARRAY_IMPLEMENTATION
|
||||
struct array_element *next, *prev;
|
||||
#endif
|
||||
} ARRAY_ELEMENT;
|
||||
|
||||
#define ARRAY_DEFAULT_SIZE 1024
|
||||
|
||||
typedef int sh_ae_map_func_t PARAMS((ARRAY_ELEMENT *, void *));
|
||||
|
||||
/* Basic operations on entire arrays */
|
||||
#ifdef ALT_ARRAY_IMPLEMENTATION
|
||||
extern void array_alloc PARAMS((ARRAY *, arrayind_t));
|
||||
extern void array_resize PARAMS((ARRAY *, arrayind_t));
|
||||
extern void array_expand PARAMS((ARRAY *, arrayind_t));
|
||||
extern void array_dispose_elements PARAMS((ARRAY_ELEMENT **));
|
||||
#endif
|
||||
extern ARRAY *array_create PARAMS((void));
|
||||
extern void array_flush PARAMS((ARRAY *));
|
||||
extern void array_dispose PARAMS((ARRAY *));
|
||||
extern ARRAY *array_copy PARAMS((ARRAY *));
|
||||
#ifndef ALT_ARRAY_IMPLEMENTATION
|
||||
extern ARRAY *array_slice PARAMS((ARRAY *, ARRAY_ELEMENT *, ARRAY_ELEMENT *));
|
||||
#else
|
||||
extern ARRAY *array_slice PARAMS((ARRAY *, arrayind_t, arrayind_t));
|
||||
#endif
|
||||
|
||||
extern void array_walk PARAMS((ARRAY *, sh_ae_map_func_t *, void *));
|
||||
|
||||
#ifndef ALT_ARRAY_IMPLEMENTATION
|
||||
extern ARRAY_ELEMENT *array_shift PARAMS((ARRAY *, int, int));
|
||||
#else
|
||||
extern ARRAY_ELEMENT **array_shift PARAMS((ARRAY *, int, int));
|
||||
#endif
|
||||
extern int array_rshift PARAMS((ARRAY *, int, char *));
|
||||
extern ARRAY_ELEMENT *array_unshift_element PARAMS((ARRAY *));
|
||||
extern int array_shift_element PARAMS((ARRAY *, char *));
|
||||
|
||||
extern ARRAY *array_quote PARAMS((ARRAY *));
|
||||
extern ARRAY *array_quote_escapes PARAMS((ARRAY *));
|
||||
extern ARRAY *array_dequote PARAMS((ARRAY *));
|
||||
extern ARRAY *array_dequote_escapes PARAMS((ARRAY *));
|
||||
extern ARRAY *array_remove_quoted_nulls PARAMS((ARRAY *));
|
||||
|
||||
extern char *array_subrange PARAMS((ARRAY *, arrayind_t, arrayind_t, int, int, int));
|
||||
extern char *array_patsub PARAMS((ARRAY *, char *, char *, int));
|
||||
extern char *array_modcase PARAMS((ARRAY *, char *, int, int));
|
||||
|
||||
/* Basic operations on array elements. */
|
||||
extern ARRAY_ELEMENT *array_create_element PARAMS((arrayind_t, char *));
|
||||
extern ARRAY_ELEMENT *array_copy_element PARAMS((ARRAY_ELEMENT *));
|
||||
extern void array_dispose_element PARAMS((ARRAY_ELEMENT *));
|
||||
|
||||
extern int array_insert PARAMS((ARRAY *, arrayind_t, char *));
|
||||
extern ARRAY_ELEMENT *array_remove PARAMS((ARRAY *, arrayind_t));
|
||||
extern char *array_reference PARAMS((ARRAY *, arrayind_t));
|
||||
|
||||
/* Converting to and from arrays */
|
||||
extern WORD_LIST *array_to_word_list PARAMS((ARRAY *));
|
||||
extern ARRAY *array_from_word_list PARAMS((WORD_LIST *));
|
||||
extern WORD_LIST *array_keys_to_word_list PARAMS((ARRAY *));
|
||||
extern WORD_LIST *array_to_kvpair_list PARAMS((ARRAY *));
|
||||
|
||||
extern ARRAY *array_assign_list PARAMS((ARRAY *, WORD_LIST *));
|
||||
|
||||
extern char **array_to_argv PARAMS((ARRAY *, int *));
|
||||
extern ARRAY *array_from_argv PARAMS((ARRAY *, char **, int));
|
||||
|
||||
extern char *array_to_kvpair PARAMS((ARRAY *, int));
|
||||
extern char *array_to_assign PARAMS((ARRAY *, int));
|
||||
extern char *array_to_string PARAMS((ARRAY *, char *, int));
|
||||
extern ARRAY *array_from_string PARAMS((char *, char *));
|
||||
|
||||
/* Flags for array_shift */
|
||||
#define AS_DISPOSE 0x01
|
||||
|
||||
#define array_num_elements(a) ((a)->num_elements)
|
||||
#define array_max_index(a) ((a)->max_index)
|
||||
#ifndef ALT_ARRAY_IMPLEMENTATION
|
||||
#define array_first_index(a) ((a)->head->next->ind)
|
||||
#define array_head(a) ((a)->head)
|
||||
#define array_alloc_size(a) ((a)->alloc_size)
|
||||
#else
|
||||
#define array_first_index(a) ((a)->first_index)
|
||||
#define array_head(a) ((a)->elements)
|
||||
#endif
|
||||
#define array_empty(a) ((a)->num_elements == 0)
|
||||
|
||||
#define element_value(ae) ((ae)->value)
|
||||
#define element_index(ae) ((ae)->ind)
|
||||
|
||||
#ifndef ALT_ARRAY_IMPLEMENTATION
|
||||
#define element_forw(ae) ((ae)->next)
|
||||
#define element_back(ae) ((ae)->prev)
|
||||
#else
|
||||
extern arrayind_t element_forw PARAMS((ARRAY *, arrayind_t));
|
||||
extern arrayind_t element_back PARAMS((ARRAY *, arrayind_t));
|
||||
#endif
|
||||
|
||||
|
||||
#define set_element_value(ae, val) ((ae)->value = (val))
|
||||
|
||||
#ifdef ALT_ARRAY_IMPLEMENTATION
|
||||
#define set_first_index(a, i) ((a)->first_index = (i))
|
||||
#endif
|
||||
|
||||
#define set_max_index(a, i) ((a)->max_index = (i))
|
||||
#define set_num_elements(a, n) ((a)->num_elements = (n))
|
||||
|
||||
/* Convenience */
|
||||
#define array_push(a,v) \
|
||||
do { array_rshift ((a), 1, (v)); } while (0)
|
||||
#define array_pop(a) \
|
||||
do { array_shift ((a), 1, AS_DISPOSE); } while (0)
|
||||
|
||||
#define GET_ARRAY_FROM_VAR(n, v, a) \
|
||||
do { \
|
||||
(v) = find_variable (n); \
|
||||
(a) = ((v) && array_p ((v))) ? array_cell (v) : (ARRAY *)0; \
|
||||
} while (0)
|
||||
|
||||
#define ARRAY_ELEMENT_REPLACE(ae, v) \
|
||||
do { \
|
||||
free ((ae)->value); \
|
||||
(ae)->value = (v); \
|
||||
} while (0)
|
||||
|
||||
#ifdef ALT_ARRAY_IMPLEMENTATION
|
||||
#define ARRAY_VALUE_REPLACE(a, i, v) \
|
||||
ARRAY_ELEMENT_REPLACE((a)->elements[(i)], (v))
|
||||
#endif
|
||||
|
||||
#define ALL_ELEMENT_SUB(c) ((c) == '@' || (c) == '*')
|
||||
|
||||
/* In eval.c, but uses ARRAY * */
|
||||
extern int execute_array_command PARAMS((ARRAY *, void *));
|
||||
|
||||
#endif /* _ARRAY_H_ */
|
1699
arrayfunc.c
Normal file
1699
arrayfunc.c
Normal file
File diff suppressed because it is too large
Load diff
140
arrayfunc.h
Normal file
140
arrayfunc.h
Normal file
|
@ -0,0 +1,140 @@
|
|||
/* arrayfunc.h -- declarations for miscellaneous array functions in arrayfunc.c */
|
||||
|
||||
/* Copyright (C) 2001-2021 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/>.
|
||||
*/
|
||||
|
||||
#if !defined (_ARRAYFUNC_H_)
|
||||
#define _ARRAYFUNC_H_
|
||||
|
||||
/* Must include variables.h before including this file. */
|
||||
|
||||
/* An object to encapsulate the state of an array element. It can describe
|
||||
an array assignment A[KEY]=VALUE or a[IND]=VALUE depending on TYPE, or
|
||||
for passing array subscript references around, where VALUE would be
|
||||
${a[IND]} or ${A[KEY]}. This is not dependent on ARRAY_VARS so we can
|
||||
use it in function parameters. */
|
||||
|
||||
/* values for `type' field */
|
||||
#define ARRAY_INVALID -1
|
||||
#define ARRAY_SCALAR 0
|
||||
#define ARRAY_INDEXED 1
|
||||
#define ARRAY_ASSOC 2
|
||||
|
||||
/* KEY will contain allocated memory if called through the assign_array_element
|
||||
code path because of how assoc_insert works. */
|
||||
typedef struct element_state
|
||||
{
|
||||
short type; /* assoc or indexed, says which fields are valid */
|
||||
short subtype; /* `*', `@', or something else */
|
||||
arrayind_t ind;
|
||||
char *key; /* can be allocated memory */
|
||||
char *value;
|
||||
} array_eltstate_t;
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
|
||||
/* This variable means to not expand associative array subscripts more than
|
||||
once, when performing variable expansion. */
|
||||
extern int assoc_expand_once;
|
||||
|
||||
/* The analog for indexed array subscripts */
|
||||
extern int array_expand_once;
|
||||
|
||||
/* Flags for array_value_internal and callers array_value/get_array_value; also
|
||||
used by array_variable_name and array_variable_part. */
|
||||
#define AV_ALLOWALL 0x001 /* treat a[@] like $@ and a[*] like $* */
|
||||
#define AV_QUOTED 0x002
|
||||
#define AV_USEIND 0x004
|
||||
#define AV_USEVAL 0x008 /* XXX - should move this */
|
||||
#define AV_ASSIGNRHS 0x010 /* no splitting, special case ${a[@]} */
|
||||
#define AV_NOEXPAND 0x020 /* don't run assoc subscripts through word expansion */
|
||||
#define AV_ONEWORD 0x040 /* not used yet */
|
||||
#define AV_ATSTARKEYS 0x080 /* accept a[@] and a[*] but use them as keys, not special values */
|
||||
|
||||
/* Flags for valid_array_reference. Value 1 is reserved for skipsubscript().
|
||||
Also used by unbind_array_element, which is currently the only function
|
||||
that uses VA_ALLOWALL. */
|
||||
#define VA_NOEXPAND 0x001
|
||||
#define VA_ONEWORD 0x002
|
||||
#define VA_ALLOWALL 0x004 /* allow @ to mean all elements of the array */
|
||||
|
||||
extern SHELL_VAR *convert_var_to_array PARAMS((SHELL_VAR *));
|
||||
extern SHELL_VAR *convert_var_to_assoc PARAMS((SHELL_VAR *));
|
||||
|
||||
extern char *make_array_variable_value PARAMS((SHELL_VAR *, arrayind_t, char *, char *, int));
|
||||
|
||||
extern SHELL_VAR *bind_array_variable PARAMS((char *, arrayind_t, char *, int));
|
||||
extern SHELL_VAR *bind_array_element PARAMS((SHELL_VAR *, arrayind_t, char *, int));
|
||||
extern SHELL_VAR *assign_array_element PARAMS((char *, char *, int, array_eltstate_t *));
|
||||
|
||||
extern SHELL_VAR *bind_assoc_variable PARAMS((SHELL_VAR *, char *, char *, char *, int));
|
||||
|
||||
extern SHELL_VAR *find_or_make_array_variable PARAMS((char *, int));
|
||||
|
||||
extern SHELL_VAR *assign_array_from_string PARAMS((char *, char *, int));
|
||||
extern SHELL_VAR *assign_array_var_from_word_list PARAMS((SHELL_VAR *, WORD_LIST *, int));
|
||||
|
||||
extern WORD_LIST *expand_compound_array_assignment PARAMS((SHELL_VAR *, char *, int));
|
||||
extern void assign_compound_array_list PARAMS((SHELL_VAR *, WORD_LIST *, int));
|
||||
extern SHELL_VAR *assign_array_var_from_string PARAMS((SHELL_VAR *, char *, int));
|
||||
|
||||
extern char *expand_and_quote_assoc_word PARAMS((char *, int));
|
||||
extern void quote_compound_array_list PARAMS((WORD_LIST *, int));
|
||||
|
||||
extern int kvpair_assignment_p PARAMS((WORD_LIST *));
|
||||
extern char *expand_and_quote_kvpair_word PARAMS((char *));
|
||||
|
||||
extern int unbind_array_element PARAMS((SHELL_VAR *, char *, int));
|
||||
extern int skipsubscript PARAMS((const char *, int, int));
|
||||
|
||||
extern void print_array_assignment PARAMS((SHELL_VAR *, int));
|
||||
extern void print_assoc_assignment PARAMS((SHELL_VAR *, int));
|
||||
|
||||
extern arrayind_t array_expand_index PARAMS((SHELL_VAR *, char *, int, int));
|
||||
extern int valid_array_reference PARAMS((const char *, int));
|
||||
extern int tokenize_array_reference PARAMS((char *, int, char **));
|
||||
|
||||
extern char *array_value PARAMS((const char *, int, int, array_eltstate_t *));
|
||||
extern char *get_array_value PARAMS((const char *, int, array_eltstate_t *));
|
||||
|
||||
extern char *array_keys PARAMS((char *, int, int));
|
||||
|
||||
extern char *array_variable_name PARAMS((const char *, int, char **, int *));
|
||||
extern SHELL_VAR *array_variable_part PARAMS((const char *, int, char **, int *));
|
||||
|
||||
extern void init_eltstate (array_eltstate_t *);
|
||||
extern void flush_eltstate (array_eltstate_t *);
|
||||
|
||||
#else
|
||||
|
||||
#define AV_ALLOWALL 0
|
||||
#define AV_QUOTED 0
|
||||
#define AV_USEIND 0
|
||||
#define AV_USEVAL 0
|
||||
#define AV_ASSIGNRHS 0
|
||||
#define AV_NOEXPAND 0
|
||||
#define AV_ONEWORD 0
|
||||
#define AV_ATSTARKEYS 0
|
||||
|
||||
#define VA_NOEXPAND 0
|
||||
#define VA_ONEWORD 0
|
||||
#define VA_ALLOWALL 0
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* !_ARRAYFUNC_H_ */
|
611
assoc.c
Normal file
611
assoc.c
Normal file
|
@ -0,0 +1,611 @@
|
|||
/*
|
||||
* assoc.c - functions to manipulate associative arrays
|
||||
*
|
||||
* Associative arrays are standard shell hash tables.
|
||||
*
|
||||
* Chet Ramey
|
||||
* chet@ins.cwru.edu
|
||||
*/
|
||||
|
||||
/* Copyright (C) 2008,2009,2011-2021 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/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bashansi.h"
|
||||
|
||||
#include "shell.h"
|
||||
#include "array.h"
|
||||
#include "assoc.h"
|
||||
#include "builtins/common.h"
|
||||
|
||||
static WORD_LIST *assoc_to_word_list_internal PARAMS((HASH_TABLE *, int));
|
||||
|
||||
/* assoc_create == hash_create */
|
||||
|
||||
void
|
||||
assoc_dispose (hash)
|
||||
HASH_TABLE *hash;
|
||||
{
|
||||
if (hash)
|
||||
{
|
||||
hash_flush (hash, 0);
|
||||
hash_dispose (hash);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
assoc_flush (hash)
|
||||
HASH_TABLE *hash;
|
||||
{
|
||||
hash_flush (hash, 0);
|
||||
}
|
||||
|
||||
int
|
||||
assoc_insert (hash, key, value)
|
||||
HASH_TABLE *hash;
|
||||
char *key;
|
||||
char *value;
|
||||
{
|
||||
BUCKET_CONTENTS *b;
|
||||
|
||||
b = hash_search (key, hash, HASH_CREATE);
|
||||
if (b == 0)
|
||||
return -1;
|
||||
/* If we are overwriting an existing element's value, we're not going to
|
||||
use the key. Nothing in the array assignment code path frees the key
|
||||
string, so we can free it here to avoid a memory leak. */
|
||||
if (b->key != key)
|
||||
free (key);
|
||||
FREE (b->data);
|
||||
b->data = value ? savestring (value) : (char *)0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Like assoc_insert, but returns b->data instead of freeing it */
|
||||
PTR_T
|
||||
assoc_replace (hash, key, value)
|
||||
HASH_TABLE *hash;
|
||||
char *key;
|
||||
char *value;
|
||||
{
|
||||
BUCKET_CONTENTS *b;
|
||||
PTR_T t;
|
||||
|
||||
b = hash_search (key, hash, HASH_CREATE);
|
||||
if (b == 0)
|
||||
return (PTR_T)0;
|
||||
/* If we are overwriting an existing element's value, we're not going to
|
||||
use the key. Nothing in the array assignment code path frees the key
|
||||
string, so we can free it here to avoid a memory leak. */
|
||||
if (b->key != key)
|
||||
free (key);
|
||||
t = b->data;
|
||||
b->data = value ? savestring (value) : (char *)0;
|
||||
return t;
|
||||
}
|
||||
|
||||
void
|
||||
assoc_remove (hash, string)
|
||||
HASH_TABLE *hash;
|
||||
char *string;
|
||||
{
|
||||
BUCKET_CONTENTS *b;
|
||||
|
||||
b = hash_remove (string, hash, 0);
|
||||
if (b)
|
||||
{
|
||||
free ((char *)b->data);
|
||||
free (b->key);
|
||||
free (b);
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
assoc_reference (hash, string)
|
||||
HASH_TABLE *hash;
|
||||
char *string;
|
||||
{
|
||||
BUCKET_CONTENTS *b;
|
||||
|
||||
if (hash == 0)
|
||||
return (char *)0;
|
||||
|
||||
b = hash_search (string, hash, 0);
|
||||
return (b ? (char *)b->data : 0);
|
||||
}
|
||||
|
||||
/* Quote the data associated with each element of the hash table ASSOC,
|
||||
using quote_string */
|
||||
HASH_TABLE *
|
||||
assoc_quote (h)
|
||||
HASH_TABLE *h;
|
||||
{
|
||||
int i;
|
||||
BUCKET_CONTENTS *tlist;
|
||||
char *t;
|
||||
|
||||
if (h == 0 || assoc_empty (h))
|
||||
return ((HASH_TABLE *)NULL);
|
||||
|
||||
for (i = 0; i < h->nbuckets; i++)
|
||||
for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
|
||||
{
|
||||
t = quote_string ((char *)tlist->data);
|
||||
FREE (tlist->data);
|
||||
tlist->data = t;
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
/* Quote escape characters in the data associated with each element
|
||||
of the hash table ASSOC, using quote_escapes */
|
||||
HASH_TABLE *
|
||||
assoc_quote_escapes (h)
|
||||
HASH_TABLE *h;
|
||||
{
|
||||
int i;
|
||||
BUCKET_CONTENTS *tlist;
|
||||
char *t;
|
||||
|
||||
if (h == 0 || assoc_empty (h))
|
||||
return ((HASH_TABLE *)NULL);
|
||||
|
||||
for (i = 0; i < h->nbuckets; i++)
|
||||
for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
|
||||
{
|
||||
t = quote_escapes ((char *)tlist->data);
|
||||
FREE (tlist->data);
|
||||
tlist->data = t;
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
HASH_TABLE *
|
||||
assoc_dequote (h)
|
||||
HASH_TABLE *h;
|
||||
{
|
||||
int i;
|
||||
BUCKET_CONTENTS *tlist;
|
||||
char *t;
|
||||
|
||||
if (h == 0 || assoc_empty (h))
|
||||
return ((HASH_TABLE *)NULL);
|
||||
|
||||
for (i = 0; i < h->nbuckets; i++)
|
||||
for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
|
||||
{
|
||||
t = dequote_string ((char *)tlist->data);
|
||||
FREE (tlist->data);
|
||||
tlist->data = t;
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
HASH_TABLE *
|
||||
assoc_dequote_escapes (h)
|
||||
HASH_TABLE *h;
|
||||
{
|
||||
int i;
|
||||
BUCKET_CONTENTS *tlist;
|
||||
char *t;
|
||||
|
||||
if (h == 0 || assoc_empty (h))
|
||||
return ((HASH_TABLE *)NULL);
|
||||
|
||||
for (i = 0; i < h->nbuckets; i++)
|
||||
for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
|
||||
{
|
||||
t = dequote_escapes ((char *)tlist->data);
|
||||
FREE (tlist->data);
|
||||
tlist->data = t;
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
HASH_TABLE *
|
||||
assoc_remove_quoted_nulls (h)
|
||||
HASH_TABLE *h;
|
||||
{
|
||||
int i;
|
||||
BUCKET_CONTENTS *tlist;
|
||||
char *t;
|
||||
|
||||
if (h == 0 || assoc_empty (h))
|
||||
return ((HASH_TABLE *)NULL);
|
||||
|
||||
for (i = 0; i < h->nbuckets; i++)
|
||||
for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
|
||||
{
|
||||
t = remove_quoted_nulls ((char *)tlist->data);
|
||||
tlist->data = t;
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a string whose elements are the members of array H beginning at
|
||||
* the STARTth element and spanning NELEM members. Null elements are counted.
|
||||
*/
|
||||
char *
|
||||
assoc_subrange (hash, start, nelem, starsub, quoted, pflags)
|
||||
HASH_TABLE *hash;
|
||||
arrayind_t start, nelem;
|
||||
int starsub, quoted, pflags;
|
||||
{
|
||||
WORD_LIST *l, *save, *h, *t;
|
||||
int i, j;
|
||||
char *ret;
|
||||
|
||||
if (assoc_empty (hash))
|
||||
return ((char *)NULL);
|
||||
|
||||
save = l = assoc_to_word_list (hash);
|
||||
if (save == 0)
|
||||
return ((char *)NULL);
|
||||
|
||||
for (i = 1; l && i < start; i++)
|
||||
l = l->next;
|
||||
if (l == 0)
|
||||
{
|
||||
dispose_words (save);
|
||||
return ((char *)NULL);
|
||||
}
|
||||
for (j = 0,h = t = l; l && j < nelem; j++)
|
||||
{
|
||||
t = l;
|
||||
l = l->next;
|
||||
}
|
||||
|
||||
t->next = (WORD_LIST *)NULL;
|
||||
|
||||
ret = string_list_pos_params (starsub ? '*' : '@', h, quoted, pflags);
|
||||
|
||||
if (t != l)
|
||||
t->next = l;
|
||||
|
||||
dispose_words (save);
|
||||
return (ret);
|
||||
|
||||
}
|
||||
|
||||
char *
|
||||
assoc_patsub (h, pat, rep, mflags)
|
||||
HASH_TABLE *h;
|
||||
char *pat, *rep;
|
||||
int mflags;
|
||||
{
|
||||
char *t;
|
||||
int pchar, qflags, pflags;
|
||||
WORD_LIST *wl, *save;
|
||||
|
||||
if (h == 0 || assoc_empty (h))
|
||||
return ((char *)NULL);
|
||||
|
||||
wl = assoc_to_word_list (h);
|
||||
if (wl == 0)
|
||||
return (char *)NULL;
|
||||
|
||||
for (save = wl; wl; wl = wl->next)
|
||||
{
|
||||
t = pat_subst (wl->word->word, pat, rep, mflags);
|
||||
FREE (wl->word->word);
|
||||
wl->word->word = t;
|
||||
}
|
||||
|
||||
pchar = (mflags & MATCH_STARSUB) == MATCH_STARSUB ? '*' : '@';
|
||||
qflags = (mflags & MATCH_QUOTED) == MATCH_QUOTED ? Q_DOUBLE_QUOTES : 0;
|
||||
pflags = (mflags & MATCH_ASSIGNRHS) == MATCH_ASSIGNRHS ? PF_ASSIGNRHS : 0;
|
||||
|
||||
t = string_list_pos_params (pchar, save, qflags, pflags);
|
||||
dispose_words (save);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
char *
|
||||
assoc_modcase (h, pat, modop, mflags)
|
||||
HASH_TABLE *h;
|
||||
char *pat;
|
||||
int modop;
|
||||
int mflags;
|
||||
{
|
||||
char *t;
|
||||
int pchar, qflags, pflags;
|
||||
WORD_LIST *wl, *save;
|
||||
|
||||
if (h == 0 || assoc_empty (h))
|
||||
return ((char *)NULL);
|
||||
|
||||
wl = assoc_to_word_list (h);
|
||||
if (wl == 0)
|
||||
return ((char *)NULL);
|
||||
|
||||
for (save = wl; wl; wl = wl->next)
|
||||
{
|
||||
t = sh_modcase (wl->word->word, pat, modop);
|
||||
FREE (wl->word->word);
|
||||
wl->word->word = t;
|
||||
}
|
||||
|
||||
pchar = (mflags & MATCH_STARSUB) == MATCH_STARSUB ? '*' : '@';
|
||||
qflags = (mflags & MATCH_QUOTED) == MATCH_QUOTED ? Q_DOUBLE_QUOTES : 0;
|
||||
pflags = (mflags & MATCH_ASSIGNRHS) == MATCH_ASSIGNRHS ? PF_ASSIGNRHS : 0;
|
||||
|
||||
t = string_list_pos_params (pchar, save, qflags, pflags);
|
||||
dispose_words (save);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
char *
|
||||
assoc_to_kvpair (hash, quoted)
|
||||
HASH_TABLE *hash;
|
||||
int quoted;
|
||||
{
|
||||
char *ret;
|
||||
char *istr, *vstr;
|
||||
int i, rsize, rlen, elen;
|
||||
BUCKET_CONTENTS *tlist;
|
||||
|
||||
if (hash == 0 || assoc_empty (hash))
|
||||
return (char *)0;
|
||||
|
||||
ret = xmalloc (rsize = 128);
|
||||
ret[rlen = 0] = '\0';
|
||||
|
||||
for (i = 0; i < hash->nbuckets; i++)
|
||||
for (tlist = hash_items (i, hash); tlist; tlist = tlist->next)
|
||||
{
|
||||
if (ansic_shouldquote (tlist->key))
|
||||
istr = ansic_quote (tlist->key, 0, (int *)0);
|
||||
else if (sh_contains_shell_metas (tlist->key))
|
||||
istr = sh_double_quote (tlist->key);
|
||||
else if (ALL_ELEMENT_SUB (tlist->key[0]) && tlist->key[1] == '\0')
|
||||
istr = sh_double_quote (tlist->key);
|
||||
else
|
||||
istr = tlist->key;
|
||||
|
||||
vstr = tlist->data ? (ansic_shouldquote ((char *)tlist->data) ?
|
||||
ansic_quote ((char *)tlist->data, 0, (int *)0) :
|
||||
sh_double_quote ((char *)tlist->data))
|
||||
: (char *)0;
|
||||
|
||||
elen = STRLEN (istr) + 4 + STRLEN (vstr);
|
||||
RESIZE_MALLOCED_BUFFER (ret, rlen, (elen+1), rsize, rsize);
|
||||
|
||||
strcpy (ret+rlen, istr);
|
||||
rlen += STRLEN (istr);
|
||||
ret[rlen++] = ' ';
|
||||
if (vstr)
|
||||
{
|
||||
strcpy (ret + rlen, vstr);
|
||||
rlen += STRLEN (vstr);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy (ret + rlen, "\"\"");
|
||||
rlen += 2;
|
||||
}
|
||||
ret[rlen++] = ' ';
|
||||
|
||||
if (istr != tlist->key)
|
||||
FREE (istr);
|
||||
|
||||
FREE (vstr);
|
||||
}
|
||||
|
||||
RESIZE_MALLOCED_BUFFER (ret, rlen, 1, rsize, 8);
|
||||
ret[rlen] = '\0';
|
||||
|
||||
if (quoted)
|
||||
{
|
||||
vstr = sh_single_quote (ret);
|
||||
free (ret);
|
||||
ret = vstr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *
|
||||
assoc_to_assign (hash, quoted)
|
||||
HASH_TABLE *hash;
|
||||
int quoted;
|
||||
{
|
||||
char *ret;
|
||||
char *istr, *vstr;
|
||||
int i, rsize, rlen, elen;
|
||||
BUCKET_CONTENTS *tlist;
|
||||
|
||||
if (hash == 0 || assoc_empty (hash))
|
||||
return (char *)0;
|
||||
|
||||
ret = xmalloc (rsize = 128);
|
||||
ret[0] = '(';
|
||||
rlen = 1;
|
||||
|
||||
for (i = 0; i < hash->nbuckets; i++)
|
||||
for (tlist = hash_items (i, hash); tlist; tlist = tlist->next)
|
||||
{
|
||||
if (ansic_shouldquote (tlist->key))
|
||||
istr = ansic_quote (tlist->key, 0, (int *)0);
|
||||
else if (sh_contains_shell_metas (tlist->key))
|
||||
istr = sh_double_quote (tlist->key);
|
||||
else if (ALL_ELEMENT_SUB (tlist->key[0]) && tlist->key[1] == '\0')
|
||||
istr = sh_double_quote (tlist->key);
|
||||
else
|
||||
istr = tlist->key;
|
||||
|
||||
vstr = tlist->data ? (ansic_shouldquote ((char *)tlist->data) ?
|
||||
ansic_quote ((char *)tlist->data, 0, (int *)0) :
|
||||
sh_double_quote ((char *)tlist->data))
|
||||
: (char *)0;
|
||||
|
||||
elen = STRLEN (istr) + 8 + STRLEN (vstr);
|
||||
RESIZE_MALLOCED_BUFFER (ret, rlen, (elen+1), rsize, rsize);
|
||||
|
||||
ret[rlen++] = '[';
|
||||
strcpy (ret+rlen, istr);
|
||||
rlen += STRLEN (istr);
|
||||
ret[rlen++] = ']';
|
||||
ret[rlen++] = '=';
|
||||
if (vstr)
|
||||
{
|
||||
strcpy (ret + rlen, vstr);
|
||||
rlen += STRLEN (vstr);
|
||||
}
|
||||
ret[rlen++] = ' ';
|
||||
|
||||
if (istr != tlist->key)
|
||||
FREE (istr);
|
||||
|
||||
FREE (vstr);
|
||||
}
|
||||
|
||||
RESIZE_MALLOCED_BUFFER (ret, rlen, 1, rsize, 8);
|
||||
ret[rlen++] = ')';
|
||||
ret[rlen] = '\0';
|
||||
|
||||
if (quoted)
|
||||
{
|
||||
vstr = sh_single_quote (ret);
|
||||
free (ret);
|
||||
ret = vstr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static WORD_LIST *
|
||||
assoc_to_word_list_internal (h, t)
|
||||
HASH_TABLE *h;
|
||||
int t;
|
||||
{
|
||||
WORD_LIST *list;
|
||||
int i;
|
||||
BUCKET_CONTENTS *tlist;
|
||||
char *w;
|
||||
|
||||
if (h == 0 || assoc_empty (h))
|
||||
return((WORD_LIST *)NULL);
|
||||
list = (WORD_LIST *)NULL;
|
||||
|
||||
for (i = 0; i < h->nbuckets; i++)
|
||||
for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
|
||||
{
|
||||
w = (t == 0) ? (char *)tlist->data : (char *)tlist->key;
|
||||
list = make_word_list (make_bare_word(w), list);
|
||||
}
|
||||
return (REVERSE_LIST(list, WORD_LIST *));
|
||||
}
|
||||
|
||||
WORD_LIST *
|
||||
assoc_to_word_list (h)
|
||||
HASH_TABLE *h;
|
||||
{
|
||||
return (assoc_to_word_list_internal (h, 0));
|
||||
}
|
||||
|
||||
WORD_LIST *
|
||||
assoc_keys_to_word_list (h)
|
||||
HASH_TABLE *h;
|
||||
{
|
||||
return (assoc_to_word_list_internal (h, 1));
|
||||
}
|
||||
|
||||
WORD_LIST *
|
||||
assoc_to_kvpair_list (h)
|
||||
HASH_TABLE *h;
|
||||
{
|
||||
WORD_LIST *list;
|
||||
int i;
|
||||
BUCKET_CONTENTS *tlist;
|
||||
char *k, *v;
|
||||
|
||||
if (h == 0 || assoc_empty (h))
|
||||
return((WORD_LIST *)NULL);
|
||||
list = (WORD_LIST *)NULL;
|
||||
|
||||
for (i = 0; i < h->nbuckets; i++)
|
||||
for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
|
||||
{
|
||||
k = (char *)tlist->key;
|
||||
v = (char *)tlist->data;
|
||||
list = make_word_list (make_bare_word (k), list);
|
||||
list = make_word_list (make_bare_word (v), list);
|
||||
}
|
||||
return (REVERSE_LIST(list, WORD_LIST *));
|
||||
}
|
||||
|
||||
char *
|
||||
assoc_to_string (h, sep, quoted)
|
||||
HASH_TABLE *h;
|
||||
char *sep;
|
||||
int quoted;
|
||||
{
|
||||
BUCKET_CONTENTS *tlist;
|
||||
int i;
|
||||
char *result, *t, *w;
|
||||
WORD_LIST *list, *l;
|
||||
|
||||
if (h == 0)
|
||||
return ((char *)NULL);
|
||||
if (assoc_empty (h))
|
||||
return (savestring (""));
|
||||
|
||||
result = NULL;
|
||||
l = list = NULL;
|
||||
/* This might be better implemented directly, but it's simple to implement
|
||||
by converting to a word list first, possibly quoting the data, then
|
||||
using list_string */
|
||||
for (i = 0; i < h->nbuckets; i++)
|
||||
for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
|
||||
{
|
||||
w = (char *)tlist->data;
|
||||
if (w == 0)
|
||||
continue;
|
||||
t = quoted ? quote_string (w) : savestring (w);
|
||||
list = make_word_list (make_bare_word(t), list);
|
||||
FREE (t);
|
||||
}
|
||||
|
||||
l = REVERSE_LIST(list, WORD_LIST *);
|
||||
|
||||
result = l ? string_list_internal (l, sep) : savestring ("");
|
||||
dispose_words (l);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif /* ARRAY_VARS */
|
66
assoc.h
Normal file
66
assoc.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
/* assoc.h -- definitions for the interface exported by assoc.c that allows
|
||||
the rest of the shell to manipulate associative array variables. */
|
||||
|
||||
/* Copyright (C) 2008,2009-2021 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _ASSOC_H_
|
||||
#define _ASSOC_H_
|
||||
|
||||
#include "stdc.h"
|
||||
#include "hashlib.h"
|
||||
|
||||
#define ASSOC_HASH_BUCKETS 1024
|
||||
|
||||
#define assoc_empty(h) ((h)->nentries == 0)
|
||||
#define assoc_num_elements(h) ((h)->nentries)
|
||||
|
||||
#define assoc_create(n) (hash_create((n)))
|
||||
|
||||
#define assoc_copy(h) (hash_copy((h), 0))
|
||||
|
||||
#define assoc_walk(h, f) (hash_walk((h), (f))
|
||||
|
||||
extern void assoc_dispose PARAMS((HASH_TABLE *));
|
||||
extern void assoc_flush PARAMS((HASH_TABLE *));
|
||||
|
||||
extern int assoc_insert PARAMS((HASH_TABLE *, char *, char *));
|
||||
extern PTR_T assoc_replace PARAMS((HASH_TABLE *, char *, char *));
|
||||
extern void assoc_remove PARAMS((HASH_TABLE *, char *));
|
||||
|
||||
extern char *assoc_reference PARAMS((HASH_TABLE *, char *));
|
||||
|
||||
extern char *assoc_subrange PARAMS((HASH_TABLE *, arrayind_t, arrayind_t, int, int, int));
|
||||
extern char *assoc_patsub PARAMS((HASH_TABLE *, char *, char *, int));
|
||||
extern char *assoc_modcase PARAMS((HASH_TABLE *, char *, int, int));
|
||||
|
||||
extern HASH_TABLE *assoc_quote PARAMS((HASH_TABLE *));
|
||||
extern HASH_TABLE *assoc_quote_escapes PARAMS((HASH_TABLE *));
|
||||
extern HASH_TABLE *assoc_dequote PARAMS((HASH_TABLE *));
|
||||
extern HASH_TABLE *assoc_dequote_escapes PARAMS((HASH_TABLE *));
|
||||
extern HASH_TABLE *assoc_remove_quoted_nulls PARAMS((HASH_TABLE *));
|
||||
|
||||
extern char *assoc_to_kvpair PARAMS((HASH_TABLE *, int));
|
||||
extern char *assoc_to_assign PARAMS((HASH_TABLE *, int));
|
||||
|
||||
extern WORD_LIST *assoc_to_word_list PARAMS((HASH_TABLE *));
|
||||
extern WORD_LIST *assoc_keys_to_word_list PARAMS((HASH_TABLE *));
|
||||
extern WORD_LIST *assoc_to_kvpair_list PARAMS((HASH_TABLE *));
|
||||
|
||||
extern char *assoc_to_string PARAMS((HASH_TABLE *, char *, int));
|
||||
#endif /* _ASSOC_H_ */
|
38
bashansi.h
Normal file
38
bashansi.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* bashansi.h -- Typically included information required by picky compilers. */
|
||||
|
||||
/* Copyright (C) 1993-2021 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/>.
|
||||
*/
|
||||
|
||||
#if !defined (_BASHANSI_H_)
|
||||
#define _BASHANSI_H_
|
||||
|
||||
#if defined (HAVE_STRING_H)
|
||||
# include <string.h>
|
||||
#endif /* !HAVE_STRING_H */
|
||||
|
||||
#if defined (HAVE_STRINGS_H)
|
||||
# include <strings.h>
|
||||
#endif /* !HAVE_STRINGS_H */
|
||||
|
||||
#if defined (HAVE_STDLIB_H)
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
# include "ansi_stdlib.h"
|
||||
#endif /* !HAVE_STDLIB_H */
|
||||
|
||||
#endif /* !_BASHANSI_H_ */
|
1079
bashhist.c
Normal file
1079
bashhist.c
Normal file
File diff suppressed because it is too large
Load diff
89
bashhist.h
Normal file
89
bashhist.h
Normal file
|
@ -0,0 +1,89 @@
|
|||
/* bashhist.h -- interface to the bash history functions in bashhist.c. */
|
||||
|
||||
/* Copyright (C) 1993-2020 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/>.
|
||||
*/
|
||||
|
||||
#if !defined (_BASHHIST_H_)
|
||||
#define _BASHHIST_H_
|
||||
|
||||
#include "stdc.h"
|
||||
|
||||
/* Flag values for history_control */
|
||||
#define HC_IGNSPACE 0x01
|
||||
#define HC_IGNDUPS 0x02
|
||||
#define HC_ERASEDUPS 0x04
|
||||
|
||||
#define HC_IGNBOTH (HC_IGNSPACE|HC_IGNDUPS)
|
||||
|
||||
#if defined (STRICT_POSIX)
|
||||
# undef HISTEXPAND_DEFAULT
|
||||
# define HISTEXPAND_DEFAULT 0
|
||||
#else
|
||||
# if !defined (HISTEXPAND_DEFAULT)
|
||||
# define HISTEXPAND_DEFAULT 1
|
||||
# endif /* !HISTEXPAND_DEFAULT */
|
||||
#endif
|
||||
|
||||
extern int remember_on_history;
|
||||
extern int enable_history_list; /* value for `set -o history' */
|
||||
extern int literal_history; /* controlled by `shopt lithist' */
|
||||
extern int force_append_history;
|
||||
extern int history_lines_this_session;
|
||||
extern int history_lines_in_file;
|
||||
extern int history_expansion;
|
||||
extern int history_control;
|
||||
extern int command_oriented_history;
|
||||
extern int current_command_first_line_saved;
|
||||
extern int current_command_first_line_comment;
|
||||
extern int hist_last_line_added;
|
||||
extern int hist_last_line_pushed;
|
||||
|
||||
extern int dont_save_function_defs;
|
||||
|
||||
# if defined (READLINE)
|
||||
extern int hist_verify;
|
||||
# endif
|
||||
|
||||
# if defined (BANG_HISTORY)
|
||||
extern int history_expansion_inhibited;
|
||||
extern int double_quotes_inhibit_history_expansion;
|
||||
# endif /* BANG_HISTORY */
|
||||
|
||||
extern void bash_initialize_history PARAMS((void));
|
||||
extern void bash_history_reinit PARAMS((int));
|
||||
extern void bash_history_disable PARAMS((void));
|
||||
extern void bash_history_enable PARAMS((void));
|
||||
extern void bash_clear_history PARAMS((void));
|
||||
extern int bash_delete_histent PARAMS((int));
|
||||
extern int bash_delete_history_range PARAMS((int, int));
|
||||
extern int bash_delete_last_history PARAMS((void));
|
||||
extern void load_history PARAMS((void));
|
||||
extern void save_history PARAMS((void));
|
||||
extern int maybe_append_history PARAMS((char *));
|
||||
extern int maybe_save_shell_history PARAMS((void));
|
||||
extern char *pre_process_line PARAMS((char *, int, int));
|
||||
extern void maybe_add_history PARAMS((char *));
|
||||
extern void bash_add_history PARAMS((char *));
|
||||
extern int check_add_history PARAMS((char *, int));
|
||||
extern int history_number PARAMS((void));
|
||||
|
||||
extern void setup_history_ignore PARAMS((char *));
|
||||
|
||||
extern char *last_history_line PARAMS((void));
|
||||
|
||||
#endif /* _BASHHIST_H_ */
|
54
bashintl.h
Normal file
54
bashintl.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
/* bashintl.h -- Internationalization functions and defines. */
|
||||
|
||||
/* 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 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/>.
|
||||
*/
|
||||
|
||||
#if !defined (_BASHINTL_H_)
|
||||
#define _BASHINTL_H_
|
||||
|
||||
#if defined (BUILDTOOL)
|
||||
# undef ENABLE_NLS
|
||||
# define ENABLE_NLS 0
|
||||
#endif
|
||||
|
||||
/* Include this *after* config.h */
|
||||
#include "gettext.h"
|
||||
|
||||
#if defined (HAVE_LOCALE_H)
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
#define _(msgid) gettext(msgid)
|
||||
#define N_(msgid) msgid
|
||||
#define D_(d, msgid) dgettext(d, msgid)
|
||||
|
||||
#define P_(m1, m2, n) ngettext(m1, m2, n)
|
||||
|
||||
#if defined (HAVE_SETLOCALE) && !defined (LC_ALL)
|
||||
# undef HAVE_SETLOCALE
|
||||
#endif
|
||||
|
||||
#if !defined (HAVE_SETLOCALE)
|
||||
# define setlocale(cat, loc)
|
||||
#endif
|
||||
|
||||
#if !defined (HAVE_LOCALE_H) || !defined (HAVE_LOCALECONV)
|
||||
# define locale_decpoint() '.'
|
||||
#endif
|
||||
|
||||
#endif /* !_BASHINTL_H_ */
|
47
bashjmp.h
Normal file
47
bashjmp.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* bashjmp.h -- wrapper for setjmp.h with necessary bash definitions. */
|
||||
|
||||
/* Copyright (C) 1987-2021 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _BASHJMP_H_
|
||||
#define _BASHJMP_H_
|
||||
|
||||
#include "posixjmp.h"
|
||||
|
||||
extern procenv_t top_level;
|
||||
extern procenv_t subshell_top_level;
|
||||
extern procenv_t return_catch; /* used by `return' builtin */
|
||||
extern procenv_t wait_intr_buf;
|
||||
|
||||
extern int no_longjmp_on_fatal_error;
|
||||
|
||||
#define SHFUNC_RETURN() sh_longjmp (return_catch, 1)
|
||||
|
||||
#define COPY_PROCENV(old, save) \
|
||||
xbcopy ((char *)old, (char *)save, sizeof (procenv_t));
|
||||
|
||||
/* Values for the second argument to longjmp/siglongjmp. */
|
||||
#define NOT_JUMPED 0 /* Not returning from a longjmp. */
|
||||
#define FORCE_EOF 1 /* We want to stop parsing. */
|
||||
#define DISCARD 2 /* Discard current command. */
|
||||
#define EXITPROG 3 /* Unconditionally exit the program now. */
|
||||
#define ERREXIT 4 /* Exit due to error condition */
|
||||
#define SIGEXIT 5 /* Exit due to fatal terminating signal */
|
||||
#define EXITBLTIN 6 /* Exit due to the exit builtin. */
|
||||
|
||||
#endif /* _BASHJMP_H_ */
|
4839
bashline.c
Normal file
4839
bashline.c
Normal file
File diff suppressed because it is too large
Load diff
69
bashline.h
Normal file
69
bashline.h
Normal file
|
@ -0,0 +1,69 @@
|
|||
/* bashline.h -- interface to the bash readline functions in bashline.c. */
|
||||
|
||||
/* Copyright (C) 1993-2019 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/>.
|
||||
*/
|
||||
|
||||
#if !defined (_BASHLINE_H_)
|
||||
#define _BASHLINE_H_
|
||||
|
||||
#include "stdc.h"
|
||||
|
||||
extern int bash_readline_initialized;
|
||||
extern int hostname_list_initialized;
|
||||
|
||||
/* these are controlled via shopt */
|
||||
extern int perform_hostname_completion;
|
||||
extern int no_empty_command_completion;
|
||||
extern int force_fignore;
|
||||
extern int dircomplete_spelling;
|
||||
extern int dircomplete_expand;
|
||||
extern int dircomplete_expand_relpath;
|
||||
extern int complete_fullquote;
|
||||
|
||||
extern void posix_readline_initialize PARAMS((int));
|
||||
extern void reset_completer_word_break_chars PARAMS((void));
|
||||
extern int enable_hostname_completion PARAMS((int));
|
||||
extern void initialize_readline PARAMS((void));
|
||||
extern void bashline_reset PARAMS((void));
|
||||
extern void bashline_reinitialize PARAMS((void));
|
||||
extern int bash_re_edit PARAMS((char *));
|
||||
|
||||
extern void bashline_set_event_hook PARAMS((void));
|
||||
extern void bashline_reset_event_hook PARAMS((void));
|
||||
|
||||
extern int bind_keyseq_to_unix_command PARAMS((char *));
|
||||
extern int bash_execute_unix_command PARAMS((int, int));
|
||||
extern int print_unix_command_map PARAMS((void));
|
||||
extern int unbind_unix_command PARAMS((char *));
|
||||
|
||||
extern char **bash_default_completion PARAMS((const char *, int, int, int, int));
|
||||
|
||||
extern void set_directory_hook PARAMS((void));
|
||||
|
||||
/* Used by programmable completion code. */
|
||||
extern char *command_word_completion_function PARAMS((const char *, int));
|
||||
extern char *bash_groupname_completion_function PARAMS((const char *, int));
|
||||
extern char *bash_servicename_completion_function PARAMS((const char *, int));
|
||||
|
||||
extern char **get_hostname_list PARAMS((void));
|
||||
extern void clear_hostname_list PARAMS((void));
|
||||
|
||||
extern char **bash_directory_completion_matches PARAMS((const char *));
|
||||
extern char *bash_dequote_text PARAMS((const char *));
|
||||
|
||||
#endif /* _BASHLINE_H_ */
|
42
bashtypes.h
Normal file
42
bashtypes.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* bashtypes.h -- Bash system types. */
|
||||
|
||||
/* Copyright (C) 1993-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/>.
|
||||
*/
|
||||
|
||||
#if !defined (_BASHTYPES_H_)
|
||||
# define _BASHTYPES_H_
|
||||
|
||||
#if defined (CRAY)
|
||||
# define word __word
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined (CRAY)
|
||||
# undef word
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_INTTYPES_H)
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
#endif /* _BASHTYPES_H_ */
|
221
bracecomp.c
Normal file
221
bracecomp.c
Normal file
|
@ -0,0 +1,221 @@
|
|||
/* bracecomp.c -- Complete a filename with the possible completions enclosed
|
||||
in csh-style braces such that the list of completions is available to the
|
||||
shell. */
|
||||
|
||||
/* Original version by tromey@cns.caltech.edu, Fri Feb 7 1992. */
|
||||
|
||||
/* Copyright (C) 1993-2020 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/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if defined (BRACE_EXPANSION) && defined (READLINE)
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "bashansi.h"
|
||||
#include "shmbutil.h"
|
||||
|
||||
#include "shell.h"
|
||||
#include <readline/readline.h>
|
||||
|
||||
static int _strcompare PARAMS((char **, char **));
|
||||
|
||||
/* Find greatest common prefix of two strings. */
|
||||
static int
|
||||
string_gcd (s1, s2)
|
||||
char *s1, *s2;
|
||||
{
|
||||
register int i;
|
||||
|
||||
if (s1 == NULL || s2 == NULL)
|
||||
return (0);
|
||||
|
||||
for (i = 0; *s1 && *s2; ++s1, ++s2, ++i)
|
||||
{
|
||||
if (*s1 != *s2)
|
||||
break;
|
||||
}
|
||||
|
||||
return (i);
|
||||
}
|
||||
|
||||
static char *
|
||||
really_munge_braces (array, real_start, real_end, gcd_zero)
|
||||
char **array;
|
||||
int real_start, real_end, gcd_zero;
|
||||
{
|
||||
int start, end, gcd;
|
||||
char *result, *subterm, *x;
|
||||
int result_size, flag, tlen;
|
||||
|
||||
flag = 0;
|
||||
|
||||
if (real_start == real_end)
|
||||
{
|
||||
x = array[real_start] ? sh_backslash_quote (array[real_start] + gcd_zero, 0, 0)
|
||||
: sh_backslash_quote (array[0], 0, 0);
|
||||
return x;
|
||||
}
|
||||
|
||||
result = (char *)xmalloc (result_size = 16);
|
||||
*result = '\0';
|
||||
|
||||
for (start = real_start; start < real_end; start = end + 1)
|
||||
{
|
||||
gcd = strlen (array[start]);
|
||||
for (end = start + 1; end < real_end; end++)
|
||||
{
|
||||
int temp;
|
||||
|
||||
temp = string_gcd (array[start], array[end]);
|
||||
|
||||
if (temp <= gcd_zero)
|
||||
break;
|
||||
|
||||
gcd = temp;
|
||||
}
|
||||
end--;
|
||||
|
||||
if (gcd_zero == 0 && start == real_start && end != (real_end - 1))
|
||||
{
|
||||
/* In this case, add in a leading '{', because we are at
|
||||
top level, and there isn't a consistent prefix. */
|
||||
result_size += 1;
|
||||
result = (char *)xrealloc (result, result_size);
|
||||
result[0] = '{'; result[1] = '\0';
|
||||
flag++;
|
||||
}
|
||||
|
||||
/* Make sure we backslash quote every substring we insert into the
|
||||
resultant brace expression. This is so the default filename
|
||||
quoting function won't inappropriately quote the braces. */
|
||||
if (start == end)
|
||||
{
|
||||
x = savestring (array[start] + gcd_zero);
|
||||
subterm = sh_backslash_quote (x, 0, 0);
|
||||
free (x);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If there is more than one element in the subarray,
|
||||
insert the (quoted) prefix and an opening brace. */
|
||||
tlen = gcd - gcd_zero;
|
||||
x = (char *)xmalloc (tlen + 1);
|
||||
strncpy (x, array[start] + gcd_zero, tlen);
|
||||
x[tlen] = '\0';
|
||||
subterm = sh_backslash_quote (x, 0, 0);
|
||||
free (x);
|
||||
result_size += strlen (subterm) + 1;
|
||||
result = (char *)xrealloc (result, result_size);
|
||||
strcat (result, subterm);
|
||||
free (subterm);
|
||||
strcat (result, "{");
|
||||
subterm = really_munge_braces (array, start, end + 1, gcd);
|
||||
subterm[strlen (subterm) - 1] = '}';
|
||||
}
|
||||
|
||||
result_size += strlen (subterm) + 1;
|
||||
result = (char *)xrealloc (result, result_size);
|
||||
strcat (result, subterm);
|
||||
strcat (result, ",");
|
||||
free (subterm);
|
||||
}
|
||||
|
||||
if (gcd_zero == 0)
|
||||
result[strlen (result) - 1] = flag ? '}' : '\0';
|
||||
return (result);
|
||||
}
|
||||
|
||||
static int
|
||||
_strcompare (s1, s2)
|
||||
char **s1, **s2;
|
||||
{
|
||||
int result;
|
||||
|
||||
result = **s1 - **s2;
|
||||
if (result == 0)
|
||||
result = strcmp (*s1, *s2);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
hack_braces_completion (names)
|
||||
char **names;
|
||||
{
|
||||
register int i;
|
||||
char *temp;
|
||||
|
||||
i = strvec_len (names);
|
||||
if (MB_CUR_MAX > 1 && i > 2)
|
||||
qsort (names+1, i-1, sizeof (char *), (QSFUNC *)_strcompare);
|
||||
|
||||
temp = really_munge_braces (names, 1, i, 0);
|
||||
|
||||
for (i = 0; names[i]; ++i)
|
||||
{
|
||||
free (names[i]);
|
||||
names[i] = NULL;
|
||||
}
|
||||
names[0] = temp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* We handle quoting ourselves within hack_braces_completion, so we turn off
|
||||
rl_filename_quoting_desired and rl_filename_quoting_function. */
|
||||
int
|
||||
bash_brace_completion (count, ignore)
|
||||
int count, ignore;
|
||||
{
|
||||
rl_compignore_func_t *orig_ignore_func;
|
||||
rl_compentry_func_t *orig_entry_func;
|
||||
rl_quote_func_t *orig_quoting_func;
|
||||
rl_completion_func_t *orig_attempt_func;
|
||||
int orig_quoting_desired, r;
|
||||
|
||||
orig_ignore_func = rl_ignore_some_completions_function;
|
||||
orig_attempt_func = rl_attempted_completion_function;
|
||||
orig_entry_func = rl_completion_entry_function;
|
||||
orig_quoting_func = rl_filename_quoting_function;
|
||||
orig_quoting_desired = rl_filename_quoting_desired;
|
||||
|
||||
rl_completion_entry_function = rl_filename_completion_function;
|
||||
rl_attempted_completion_function = (rl_completion_func_t *)NULL;
|
||||
rl_ignore_some_completions_function = hack_braces_completion;
|
||||
rl_filename_quoting_function = (rl_quote_func_t *)NULL;
|
||||
rl_filename_quoting_desired = 0;
|
||||
|
||||
r = rl_complete_internal (TAB);
|
||||
|
||||
rl_ignore_some_completions_function = orig_ignore_func;
|
||||
rl_attempted_completion_function = orig_attempt_func;
|
||||
rl_completion_entry_function = orig_entry_func;
|
||||
rl_filename_quoting_function = orig_quoting_func;
|
||||
rl_filename_quoting_desired = orig_quoting_desired;
|
||||
|
||||
return r;
|
||||
}
|
||||
#endif /* BRACE_EXPANSION && READLINE */
|
843
braces.c
Normal file
843
braces.c
Normal file
|
@ -0,0 +1,843 @@
|
|||
/* braces.c -- code for doing word expansion in curly braces. */
|
||||
|
||||
/* Copyright (C) 1987-2020 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/>.
|
||||
*/
|
||||
|
||||
/* Stuff in curly braces gets expanded before all other shell expansions. */
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if defined (BRACE_EXPANSION)
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "bashansi.h"
|
||||
#include "bashintl.h"
|
||||
|
||||
#if defined (SHELL)
|
||||
# include "shell.h"
|
||||
#else
|
||||
# if defined (TEST)
|
||||
typedef char *WORD_DESC;
|
||||
typedef char **WORD_LIST;
|
||||
#define _(X) X
|
||||
# endif /* TEST */
|
||||
#endif /* SHELL */
|
||||
|
||||
#include "typemax.h" /* INTMAX_MIN, INTMAX_MAX */
|
||||
#include "general.h"
|
||||
#include "shmbutil.h"
|
||||
#include "chartypes.h"
|
||||
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#define brace_whitespace(c) (!(c) || (c) == ' ' || (c) == '\t' || (c) == '\n')
|
||||
|
||||
#define BRACE_SEQ_SPECIFIER ".."
|
||||
|
||||
extern int asprintf PARAMS((char **, const char *, ...)) __attribute__((__format__ (printf, 2, 3)));
|
||||
|
||||
/* Basic idea:
|
||||
|
||||
Segregate the text into 3 sections: preamble (stuff before an open brace),
|
||||
postamble (stuff after the matching close brace) and amble (stuff after
|
||||
preamble, and before postamble). Expand amble, and then tack on the
|
||||
expansions to preamble. Expand postamble, and tack on the expansions to
|
||||
the result so far.
|
||||
*/
|
||||
|
||||
/* The character which is used to separate arguments. */
|
||||
static const int brace_arg_separator = ',';
|
||||
|
||||
#if defined (PARAMS)
|
||||
static int brace_gobbler PARAMS((char *, size_t, int *, int));
|
||||
static char **expand_amble PARAMS((char *, size_t, int));
|
||||
static char **expand_seqterm PARAMS((char *, size_t));
|
||||
static char **mkseq PARAMS((intmax_t, intmax_t, intmax_t, int, int));
|
||||
static char **array_concat PARAMS((char **, char **));
|
||||
#else
|
||||
static int brace_gobbler ();
|
||||
static char **expand_amble ();
|
||||
static char **expand_seqterm ();
|
||||
static char **mkseq();
|
||||
static char **array_concat ();
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
static void
|
||||
dump_result (a)
|
||||
char **a;
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; a[i]; i++)
|
||||
printf ("dump_result: a[%d] = -%s-\n", i, a[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Return an array of strings; the brace expansion of TEXT. */
|
||||
char **
|
||||
brace_expand (text)
|
||||
char *text;
|
||||
{
|
||||
register int start;
|
||||
size_t tlen;
|
||||
char *preamble, *postamble, *amble;
|
||||
size_t alen;
|
||||
char **tack, **result;
|
||||
int i, j, c, c1;
|
||||
|
||||
DECLARE_MBSTATE;
|
||||
|
||||
/* Find the text of the preamble. */
|
||||
tlen = strlen (text);
|
||||
i = 0;
|
||||
#if defined (CSH_BRACE_COMPAT)
|
||||
c = brace_gobbler (text, tlen, &i, '{'); /* } */
|
||||
#else
|
||||
/* Make sure that when we exit this loop, c == 0 or text[i] begins a
|
||||
valid brace expansion sequence. */
|
||||
do
|
||||
{
|
||||
c = brace_gobbler (text, tlen, &i, '{'); /* } */
|
||||
c1 = c;
|
||||
/* Verify that c begins a valid brace expansion word. If it doesn't, we
|
||||
go on. Loop stops when there are no more open braces in the word. */
|
||||
if (c)
|
||||
{
|
||||
start = j = i + 1; /* { */
|
||||
c = brace_gobbler (text, tlen, &j, '}');
|
||||
if (c == 0) /* it's not */
|
||||
{
|
||||
i++;
|
||||
c = c1;
|
||||
continue;
|
||||
}
|
||||
else /* it is */
|
||||
{
|
||||
c = c1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
while (c);
|
||||
#endif /* !CSH_BRACE_COMPAT */
|
||||
|
||||
preamble = (char *)xmalloc (i + 1);
|
||||
if (i > 0)
|
||||
strncpy (preamble, text, i);
|
||||
preamble[i] = '\0';
|
||||
|
||||
result = (char **)xmalloc (2 * sizeof (char *));
|
||||
result[0] = preamble;
|
||||
result[1] = (char *)NULL;
|
||||
|
||||
/* Special case. If we never found an exciting character, then
|
||||
the preamble is all of the text, so just return that. */
|
||||
if (c != '{')
|
||||
return (result);
|
||||
|
||||
/* Find the amble. This is the stuff inside this set of braces. */
|
||||
start = ++i;
|
||||
c = brace_gobbler (text, tlen, &i, '}');
|
||||
|
||||
/* What if there isn't a matching close brace? */
|
||||
if (c == 0)
|
||||
{
|
||||
#if defined (NOTDEF)
|
||||
/* Well, if we found an unquoted BRACE_ARG_SEPARATOR between START
|
||||
and I, then this should be an error. Otherwise, it isn't. */
|
||||
j = start;
|
||||
while (j < i)
|
||||
{
|
||||
if (text[j] == '\\')
|
||||
{
|
||||
j++;
|
||||
ADVANCE_CHAR (text, tlen, j);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (text[j] == brace_arg_separator)
|
||||
{ /* { */
|
||||
strvec_dispose (result);
|
||||
set_exit_status (EXECUTION_FAILURE);
|
||||
report_error ("no closing `%c' in %s", '}', text);
|
||||
throw_to_top_level ();
|
||||
}
|
||||
ADVANCE_CHAR (text, tlen, j);
|
||||
}
|
||||
#endif
|
||||
free (preamble); /* Same as result[0]; see initialization. */
|
||||
result[0] = savestring (text);
|
||||
return (result);
|
||||
}
|
||||
|
||||
#if defined (SHELL)
|
||||
amble = substring (text, start, i);
|
||||
alen = i - start;
|
||||
#else
|
||||
amble = (char *)xmalloc (1 + (i - start));
|
||||
strncpy (amble, &text[start], (i - start));
|
||||
alen = i - start;
|
||||
amble[alen] = '\0';
|
||||
#endif
|
||||
|
||||
#if defined (SHELL)
|
||||
INITIALIZE_MBSTATE;
|
||||
|
||||
/* If the amble does not contain an unquoted BRACE_ARG_SEPARATOR, then
|
||||
just return without doing any expansion. */
|
||||
j = 0;
|
||||
while (amble[j])
|
||||
{
|
||||
if (amble[j] == '\\')
|
||||
{
|
||||
j++;
|
||||
ADVANCE_CHAR (amble, alen, j);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (amble[j] == brace_arg_separator)
|
||||
break;
|
||||
|
||||
ADVANCE_CHAR (amble, alen, j);
|
||||
}
|
||||
|
||||
if (amble[j] == 0)
|
||||
{
|
||||
tack = expand_seqterm (amble, alen);
|
||||
if (tack)
|
||||
goto add_tack;
|
||||
else if (text[i + 1])
|
||||
{
|
||||
/* If the sequence expansion fails (e.g., because the integers
|
||||
overflow), but there is more in the string, try and process
|
||||
the rest of the string, which may contain additional brace
|
||||
expansions. Treat the unexpanded sequence term as a simple
|
||||
string (including the braces). */
|
||||
tack = strvec_create (2);
|
||||
tack[0] = savestring (text+start-1);
|
||||
tack[0][i-start+2] = '\0';
|
||||
tack[1] = (char *)0;
|
||||
goto add_tack;
|
||||
}
|
||||
else
|
||||
{
|
||||
free (amble);
|
||||
free (preamble);
|
||||
result[0] = savestring (text);
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
#endif /* SHELL */
|
||||
|
||||
tack = expand_amble (amble, alen, 0);
|
||||
add_tack:
|
||||
result = array_concat (result, tack);
|
||||
free (amble);
|
||||
if (tack != result)
|
||||
strvec_dispose (tack);
|
||||
|
||||
postamble = text + i + 1;
|
||||
|
||||
if (postamble && *postamble)
|
||||
{
|
||||
tack = brace_expand (postamble);
|
||||
result = array_concat (result, tack);
|
||||
if (tack != result)
|
||||
strvec_dispose (tack);
|
||||
}
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
/* Expand the text found inside of braces. We simply try to split the
|
||||
text at BRACE_ARG_SEPARATORs into separate strings. We then brace
|
||||
expand each slot which needs it, until there are no more slots which
|
||||
need it. */
|
||||
static char **
|
||||
expand_amble (text, tlen, flags)
|
||||
char *text;
|
||||
size_t tlen;
|
||||
int flags;
|
||||
{
|
||||
char **result, **partial, **tresult;
|
||||
char *tem;
|
||||
int start, i, c;
|
||||
|
||||
#if defined (SHELL)
|
||||
DECLARE_MBSTATE;
|
||||
#endif
|
||||
|
||||
result = (char **)NULL;
|
||||
|
||||
start = i = 0;
|
||||
c = 1;
|
||||
while (c)
|
||||
{
|
||||
c = brace_gobbler (text, tlen, &i, brace_arg_separator);
|
||||
#if defined (SHELL)
|
||||
tem = substring (text, start, i);
|
||||
#else
|
||||
tem = (char *)xmalloc (1 + (i - start));
|
||||
strncpy (tem, &text[start], (i - start));
|
||||
tem[i - start] = '\0';
|
||||
#endif
|
||||
|
||||
partial = brace_expand (tem);
|
||||
|
||||
if (!result)
|
||||
result = partial;
|
||||
else
|
||||
{
|
||||
register int lr, lp, j;
|
||||
|
||||
lr = strvec_len (result);
|
||||
lp = strvec_len (partial);
|
||||
|
||||
tresult = strvec_mresize (result, lp + lr + 1);
|
||||
if (tresult == 0)
|
||||
{
|
||||
internal_error (_("brace expansion: cannot allocate memory for %s"), tem);
|
||||
free (tem);
|
||||
strvec_dispose (partial);
|
||||
strvec_dispose (result);
|
||||
result = (char **)NULL;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
result = tresult;
|
||||
|
||||
for (j = 0; j < lp; j++)
|
||||
result[lr + j] = partial[j];
|
||||
|
||||
result[lr + j] = (char *)NULL;
|
||||
free (partial);
|
||||
}
|
||||
free (tem);
|
||||
#if defined (SHELL)
|
||||
ADVANCE_CHAR (text, tlen, i);
|
||||
#else
|
||||
i++;
|
||||
#endif
|
||||
start = i;
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
#define ST_BAD 0
|
||||
#define ST_INT 1
|
||||
#define ST_CHAR 2
|
||||
#define ST_ZINT 3
|
||||
|
||||
static char **
|
||||
mkseq (start, end, incr, type, width)
|
||||
intmax_t start, end, incr;
|
||||
int type, width;
|
||||
{
|
||||
intmax_t n, prevn;
|
||||
int i, nelem;
|
||||
char **result, *t;
|
||||
|
||||
if (incr == 0)
|
||||
incr = 1;
|
||||
|
||||
if (start > end && incr > 0)
|
||||
incr = -incr;
|
||||
else if (start < end && incr < 0)
|
||||
{
|
||||
if (incr == INTMAX_MIN) /* Don't use -INTMAX_MIN */
|
||||
return ((char **)NULL);
|
||||
incr = -incr;
|
||||
}
|
||||
|
||||
/* Check that end-start will not overflow INTMAX_MIN, INTMAX_MAX. The +3
|
||||
and -2, not strictly necessary, are there because of the way the number
|
||||
of elements and value passed to strvec_create() are calculated below. */
|
||||
if (SUBOVERFLOW (end, start, INTMAX_MIN+3, INTMAX_MAX-2))
|
||||
return ((char **)NULL);
|
||||
|
||||
prevn = sh_imaxabs (end - start);
|
||||
/* Need to check this way in case INT_MAX == INTMAX_MAX */
|
||||
if (INT_MAX == INTMAX_MAX && (ADDOVERFLOW (prevn, 2, INT_MIN, INT_MAX)))
|
||||
return ((char **)NULL);
|
||||
/* Make sure the assignment to nelem below doesn't end up <= 0 due to
|
||||
intmax_t overflow */
|
||||
else if (ADDOVERFLOW ((prevn/sh_imaxabs(incr)), 1, INTMAX_MIN, INTMAX_MAX))
|
||||
return ((char **)NULL);
|
||||
|
||||
/* XXX - TOFIX: potentially allocating a lot of extra memory if
|
||||
imaxabs(incr) != 1 */
|
||||
/* Instead of a simple nelem = prevn + 1, something like:
|
||||
nelem = (prevn / imaxabs(incr)) + 1;
|
||||
would work */
|
||||
if ((prevn / sh_imaxabs (incr)) > INT_MAX - 3) /* check int overflow */
|
||||
return ((char **)NULL);
|
||||
nelem = (prevn / sh_imaxabs(incr)) + 1;
|
||||
result = strvec_mcreate (nelem + 1);
|
||||
if (result == 0)
|
||||
{
|
||||
internal_error (_("brace expansion: failed to allocate memory for %u elements"), (unsigned int)nelem);
|
||||
return ((char **)NULL);
|
||||
}
|
||||
|
||||
/* Make sure we go through the loop at least once, so {3..3} prints `3' */
|
||||
i = 0;
|
||||
n = start;
|
||||
do
|
||||
{
|
||||
#if defined (SHELL)
|
||||
if (ISINTERRUPT)
|
||||
{
|
||||
result[i] = (char *)NULL;
|
||||
strvec_dispose (result);
|
||||
result = (char **)NULL;
|
||||
}
|
||||
QUIT;
|
||||
#endif
|
||||
if (type == ST_INT)
|
||||
result[i++] = t = itos (n);
|
||||
else if (type == ST_ZINT)
|
||||
{
|
||||
int len, arg;
|
||||
arg = n;
|
||||
len = asprintf (&t, "%0*d", width, arg);
|
||||
result[i++] = t;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (t = (char *)malloc (2))
|
||||
{
|
||||
t[0] = n;
|
||||
t[1] = '\0';
|
||||
}
|
||||
result[i++] = t;
|
||||
}
|
||||
|
||||
/* We failed to allocate memory for this number, so we bail. */
|
||||
if (t == 0)
|
||||
{
|
||||
char *p, lbuf[INT_STRLEN_BOUND(intmax_t) + 1];
|
||||
|
||||
/* Easier to do this than mess around with various intmax_t printf
|
||||
formats (%ld? %lld? %jd?) and PRIdMAX. */
|
||||
p = inttostr (n, lbuf, sizeof (lbuf));
|
||||
internal_error (_("brace expansion: failed to allocate memory for `%s'"), p);
|
||||
strvec_dispose (result);
|
||||
return ((char **)NULL);
|
||||
}
|
||||
|
||||
/* Handle overflow and underflow of n+incr */
|
||||
if (ADDOVERFLOW (n, incr, INTMAX_MIN, INTMAX_MAX))
|
||||
break;
|
||||
|
||||
n += incr;
|
||||
|
||||
if ((incr < 0 && n < end) || (incr > 0 && n > end))
|
||||
break;
|
||||
}
|
||||
while (1);
|
||||
|
||||
result[i] = (char *)0;
|
||||
return (result);
|
||||
}
|
||||
|
||||
static char **
|
||||
expand_seqterm (text, tlen)
|
||||
char *text;
|
||||
size_t tlen;
|
||||
{
|
||||
char *t, *lhs, *rhs;
|
||||
int lhs_t, rhs_t, lhs_l, rhs_l, width;
|
||||
intmax_t lhs_v, rhs_v, incr;
|
||||
intmax_t tl, tr;
|
||||
char **result, *ep, *oep;
|
||||
|
||||
t = strstr (text, BRACE_SEQ_SPECIFIER);
|
||||
if (t == 0)
|
||||
return ((char **)NULL);
|
||||
|
||||
lhs_l = t - text; /* index of start of BRACE_SEQ_SPECIFIER */
|
||||
lhs = substring (text, 0, lhs_l);
|
||||
rhs = substring (text, lhs_l + sizeof(BRACE_SEQ_SPECIFIER) - 1, tlen);
|
||||
|
||||
if (lhs[0] == 0 || rhs[0] == 0)
|
||||
{
|
||||
free (lhs);
|
||||
free (rhs);
|
||||
return ((char **)NULL);
|
||||
}
|
||||
|
||||
/* Now figure out whether LHS and RHS are integers or letters. Both
|
||||
sides have to match. */
|
||||
lhs_t = (legal_number (lhs, &tl)) ? ST_INT :
|
||||
((ISALPHA (lhs[0]) && lhs[1] == 0) ? ST_CHAR : ST_BAD);
|
||||
|
||||
/* Decide on rhs and whether or not it looks like the user specified
|
||||
an increment */
|
||||
ep = 0;
|
||||
if (ISDIGIT (rhs[0]) || ((rhs[0] == '+' || rhs[0] == '-') && ISDIGIT (rhs[1])))
|
||||
{
|
||||
rhs_t = ST_INT;
|
||||
errno = 0;
|
||||
tr = strtoimax (rhs, &ep, 10);
|
||||
if (errno == ERANGE || (ep && *ep != 0 && *ep != '.'))
|
||||
rhs_t = ST_BAD; /* invalid */
|
||||
}
|
||||
else if (ISALPHA (rhs[0]) && (rhs[1] == 0 || rhs[1] == '.'))
|
||||
{
|
||||
rhs_t = ST_CHAR;
|
||||
ep = rhs + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
rhs_t = ST_BAD;
|
||||
ep = 0;
|
||||
}
|
||||
|
||||
incr = 1;
|
||||
if (rhs_t != ST_BAD)
|
||||
{
|
||||
oep = ep;
|
||||
errno = 0;
|
||||
if (ep && *ep == '.' && ep[1] == '.' && ep[2])
|
||||
incr = strtoimax (ep + 2, &ep, 10);
|
||||
if (*ep != 0 || errno == ERANGE)
|
||||
rhs_t = ST_BAD; /* invalid incr or overflow */
|
||||
tlen -= ep - oep;
|
||||
}
|
||||
|
||||
if (lhs_t != rhs_t || lhs_t == ST_BAD || rhs_t == ST_BAD)
|
||||
{
|
||||
free (lhs);
|
||||
free (rhs);
|
||||
return ((char **)NULL);
|
||||
}
|
||||
|
||||
/* OK, we have something. It's either a sequence of integers, ascending
|
||||
or descending, or a sequence or letters, ditto. Generate the sequence,
|
||||
put it into a string vector, and return it. */
|
||||
|
||||
if (lhs_t == ST_CHAR)
|
||||
{
|
||||
lhs_v = (unsigned char)lhs[0];
|
||||
rhs_v = (unsigned char)rhs[0];
|
||||
width = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
lhs_v = tl; /* integer truncation */
|
||||
rhs_v = tr;
|
||||
|
||||
/* Decide whether or not the terms need zero-padding */
|
||||
rhs_l = tlen - lhs_l - sizeof (BRACE_SEQ_SPECIFIER) + 1;
|
||||
width = 0;
|
||||
if (lhs_l > 1 && lhs[0] == '0')
|
||||
width = lhs_l, lhs_t = ST_ZINT;
|
||||
if (lhs_l > 2 && lhs[0] == '-' && lhs[1] == '0')
|
||||
width = lhs_l, lhs_t = ST_ZINT;
|
||||
if (rhs_l > 1 && rhs[0] == '0' && width < rhs_l)
|
||||
width = rhs_l, lhs_t = ST_ZINT;
|
||||
if (rhs_l > 2 && rhs[0] == '-' && rhs[1] == '0' && width < rhs_l)
|
||||
width = rhs_l, lhs_t = ST_ZINT;
|
||||
|
||||
if (width < lhs_l && lhs_t == ST_ZINT)
|
||||
width = lhs_l;
|
||||
if (width < rhs_l && lhs_t == ST_ZINT)
|
||||
width = rhs_l;
|
||||
}
|
||||
|
||||
result = mkseq (lhs_v, rhs_v, incr, lhs_t, width);
|
||||
|
||||
free (lhs);
|
||||
free (rhs);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
/* Start at INDEX, and skip characters in TEXT. Set INDEX to the
|
||||
index of the character matching SATISFY. This understands about
|
||||
quoting. Return the character that caused us to stop searching;
|
||||
this is either the same as SATISFY, or 0. */
|
||||
/* If SATISFY is `}', we are looking for a brace expression, so we
|
||||
should enforce the rules that govern valid brace expansions:
|
||||
1) to count as an arg separator, a comma or `..' has to be outside
|
||||
an inner set of braces.
|
||||
*/
|
||||
static int
|
||||
brace_gobbler (text, tlen, indx, satisfy)
|
||||
char *text;
|
||||
size_t tlen;
|
||||
int *indx;
|
||||
int satisfy;
|
||||
{
|
||||
register int i, c, quoted, level, commas, pass_next;
|
||||
#if defined (SHELL)
|
||||
int si;
|
||||
char *t;
|
||||
#endif
|
||||
DECLARE_MBSTATE;
|
||||
|
||||
level = quoted = pass_next = 0;
|
||||
#if defined (CSH_BRACE_COMPAT)
|
||||
commas = 1;
|
||||
#else
|
||||
commas = (satisfy == '}') ? 0 : 1;
|
||||
#endif
|
||||
|
||||
i = *indx;
|
||||
while (c = text[i])
|
||||
{
|
||||
if (pass_next)
|
||||
{
|
||||
pass_next = 0;
|
||||
#if defined (SHELL)
|
||||
ADVANCE_CHAR (text, tlen, i);
|
||||
#else
|
||||
i++;
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
/* A backslash escapes the next character. This allows backslash to
|
||||
escape the quote character in a double-quoted string. */
|
||||
if (c == '\\' && (quoted == 0 || quoted == '"' || quoted == '`'))
|
||||
{
|
||||
pass_next = 1;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
#if defined (SHELL)
|
||||
/* If compiling for the shell, treat ${...} like \{...} */
|
||||
if (c == '$' && text[i+1] == '{' && quoted != '\'') /* } */
|
||||
{
|
||||
pass_next = 1;
|
||||
i++;
|
||||
if (quoted == 0)
|
||||
level++;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (quoted)
|
||||
{
|
||||
if (c == quoted)
|
||||
quoted = 0;
|
||||
#if defined (SHELL)
|
||||
/* The shell allows quoted command substitutions */
|
||||
if (quoted == '"' && c == '$' && text[i+1] == '(') /*)*/
|
||||
goto comsub;
|
||||
#endif
|
||||
#if defined (SHELL)
|
||||
ADVANCE_CHAR (text, tlen, i);
|
||||
#else
|
||||
i++;
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '"' || c == '\'' || c == '`')
|
||||
{
|
||||
quoted = c;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
#if defined (SHELL)
|
||||
/* Pass new-style command and process substitutions through unchanged. */
|
||||
if ((c == '$' || c == '<' || c == '>') && text[i+1] == '(') /* ) */
|
||||
{
|
||||
comsub:
|
||||
si = i + 2;
|
||||
t = extract_command_subst (text, &si, 0);
|
||||
i = si;
|
||||
free (t);
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (c == satisfy && level == 0 && quoted == 0 && commas > 0)
|
||||
{
|
||||
/* We ignore an open brace surrounded by whitespace, and also
|
||||
an open brace followed immediately by a close brace preceded
|
||||
by whitespace. */
|
||||
if (c == '{' &&
|
||||
((!i || brace_whitespace (text[i - 1])) &&
|
||||
(brace_whitespace (text[i + 1]) || text[i + 1] == '}')))
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (c == '{')
|
||||
level++;
|
||||
else if (c == '}' && level)
|
||||
level--;
|
||||
#if !defined (CSH_BRACE_COMPAT)
|
||||
else if (satisfy == '}' && c == brace_arg_separator && level == 0)
|
||||
commas++;
|
||||
else if (satisfy == '}' && STREQN (text+i, BRACE_SEQ_SPECIFIER, 2) &&
|
||||
text[i+2] != satisfy && level == 0)
|
||||
commas++;
|
||||
#endif
|
||||
|
||||
#if defined (SHELL)
|
||||
ADVANCE_CHAR (text, tlen, i);
|
||||
#else
|
||||
i++;
|
||||
#endif
|
||||
}
|
||||
|
||||
*indx = i;
|
||||
return (c);
|
||||
}
|
||||
|
||||
/* Return a new array of strings which is the result of appending each
|
||||
string in ARR2 to each string in ARR1. The resultant array is
|
||||
len (arr1) * len (arr2) long. For convenience, ARR1 (and its contents)
|
||||
are free ()'ed. ARR1 can be NULL, in that case, a new version of ARR2
|
||||
is returned. */
|
||||
static char **
|
||||
array_concat (arr1, arr2)
|
||||
char **arr1, **arr2;
|
||||
{
|
||||
register int i, j, len, len1, len2;
|
||||
register char **result;
|
||||
|
||||
if (arr1 == 0)
|
||||
return (arr2); /* XXX - see if we can get away without copying? */
|
||||
|
||||
if (arr2 == 0)
|
||||
return (arr1); /* XXX - caller expects us to free arr1 */
|
||||
|
||||
/* We can only short-circuit if the array consists of a single null element;
|
||||
otherwise we need to replicate the contents of the other array and
|
||||
prefix (or append, below) an empty element to each one. */
|
||||
if (arr1[0] && arr1[0][0] == 0 && arr1[1] == 0)
|
||||
{
|
||||
strvec_dispose (arr1);
|
||||
return (arr2); /* XXX - use flags to see if we can avoid copying here */
|
||||
}
|
||||
|
||||
if (arr2[0] && arr2[0][0] == 0 && arr2[1] == 0)
|
||||
return (arr1); /* XXX - rather than copying and freeing it */
|
||||
|
||||
len1 = strvec_len (arr1);
|
||||
len2 = strvec_len (arr2);
|
||||
|
||||
result = (char **)malloc ((1 + (len1 * len2)) * sizeof (char *));
|
||||
if (result == 0)
|
||||
return (result);
|
||||
|
||||
len = 0;
|
||||
for (i = 0; i < len1; i++)
|
||||
{
|
||||
int strlen_1 = strlen (arr1[i]);
|
||||
|
||||
for (j = 0; j < len2; j++)
|
||||
{
|
||||
result[len] = (char *)xmalloc (1 + strlen_1 + strlen (arr2[j]));
|
||||
strcpy (result[len], arr1[i]);
|
||||
strcpy (result[len] + strlen_1, arr2[j]);
|
||||
len++;
|
||||
}
|
||||
free (arr1[i]);
|
||||
}
|
||||
free (arr1);
|
||||
|
||||
result[len] = (char *)NULL;
|
||||
return (result);
|
||||
}
|
||||
|
||||
#if defined (TEST)
|
||||
#include <stdio.h>
|
||||
|
||||
void *
|
||||
xmalloc(n)
|
||||
size_t n;
|
||||
{
|
||||
return (malloc (n));
|
||||
}
|
||||
|
||||
void *
|
||||
xrealloc(p, n)
|
||||
void *p;
|
||||
size_t n;
|
||||
{
|
||||
return (realloc (p, n));
|
||||
}
|
||||
|
||||
int
|
||||
internal_error (format, arg1, arg2)
|
||||
char *format, *arg1, *arg2;
|
||||
{
|
||||
fprintf (stderr, format, arg1, arg2);
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
|
||||
main ()
|
||||
{
|
||||
char example[256];
|
||||
|
||||
for (;;)
|
||||
{
|
||||
char **result;
|
||||
int i;
|
||||
|
||||
fprintf (stderr, "brace_expand> ");
|
||||
|
||||
if ((!fgets (example, 256, stdin)) ||
|
||||
(strncmp (example, "quit", 4) == 0))
|
||||
break;
|
||||
|
||||
if (strlen (example))
|
||||
example[strlen (example) - 1] = '\0';
|
||||
|
||||
result = brace_expand (example);
|
||||
|
||||
for (i = 0; result[i]; i++)
|
||||
printf ("%s\n", result[i]);
|
||||
|
||||
strvec_dispose (result);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* compile-command: "gcc -g -Bstatic -DTEST -o brace_expand braces.c general.o"
|
||||
* end:
|
||||
*/
|
||||
|
||||
#endif /* TEST */
|
||||
#endif /* BRACE_EXPANSION */
|
68
builtins.h
Normal file
68
builtins.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
/* builtins.h -- What a builtin looks like, and where to find them. */
|
||||
|
||||
/* Copyright (C) 1987-2021 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/>.
|
||||
*/
|
||||
|
||||
#ifndef BUILTINS_H
|
||||
#define BUILTINS_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "command.h"
|
||||
#include "general.h"
|
||||
|
||||
#if defined (ALIAS)
|
||||
#include "alias.h"
|
||||
#endif
|
||||
|
||||
/* Flags describing various things about a builtin. */
|
||||
#define BUILTIN_ENABLED 0x01 /* This builtin is enabled. */
|
||||
#define BUILTIN_DELETED 0x02 /* This has been deleted with enable -d. */
|
||||
#define STATIC_BUILTIN 0x04 /* This builtin is not dynamically loaded. */
|
||||
#define SPECIAL_BUILTIN 0x08 /* This is a Posix `special' builtin. */
|
||||
#define ASSIGNMENT_BUILTIN 0x10 /* This builtin takes assignment statements. */
|
||||
#define POSIX_BUILTIN 0x20 /* This builtins is special in the Posix command search order. */
|
||||
#define LOCALVAR_BUILTIN 0x40 /* This builtin creates local variables */
|
||||
#define ARRAYREF_BUILTIN 0x80 /* This builtin takes array references as arguments */
|
||||
|
||||
#define BASE_INDENT 4
|
||||
|
||||
/* The thing that we build the array of builtins out of. */
|
||||
struct builtin {
|
||||
char *name; /* The name that the user types. */
|
||||
sh_builtin_func_t *function; /* The address of the invoked function. */
|
||||
int flags; /* One of the #defines above. */
|
||||
char * const *long_doc; /* NULL terminated array of strings. */
|
||||
const char *short_doc; /* Short version of documentation. */
|
||||
char *handle; /* for future use */
|
||||
};
|
||||
|
||||
/* Found in builtins.c, created by builtins/mkbuiltins. */
|
||||
extern int num_shell_builtins; /* Number of shell builtins. */
|
||||
extern struct builtin static_shell_builtins[];
|
||||
extern struct builtin *shell_builtins;
|
||||
extern struct builtin *current_builtin;
|
||||
|
||||
#endif /* BUILTINS_H */
|
723
builtins/Makefile.in
Normal file
723
builtins/Makefile.in
Normal file
|
@ -0,0 +1,723 @@
|
|||
# This Makefile for building libbuiltins.a is in -*- text -*- for Emacs.
|
||||
#
|
||||
# Copyright (C) 1996-2022 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 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.
|
||||
|
||||
# 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@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
|
||||
#
|
||||
SHELL = @MAKE_SHELL@
|
||||
RANLIB = @RANLIB@
|
||||
CC = @CC@
|
||||
CC_FOR_BUILD = @CC_FOR_BUILD@
|
||||
AR = @AR@
|
||||
ARFLAGS = @ARFLAGS@
|
||||
RM = rm -f
|
||||
CP = cp
|
||||
|
||||
EXEEXT = @EXEEXT@
|
||||
|
||||
prefix = @prefix@
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
topdir = @top_srcdir@
|
||||
|
||||
datarootdir = @datarootdir@
|
||||
|
||||
includedir = @includedir@
|
||||
datadir = @datadir@
|
||||
localedir = @localedir@
|
||||
|
||||
loadablesdir = @loadablesdir@
|
||||
|
||||
# Support an alternate destination root directory for package building
|
||||
DESTDIR =
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
BUILD_DIR = @BUILD_DIR@
|
||||
|
||||
LIBBUILD = ${BUILD_DIR}/lib
|
||||
|
||||
PROFILE_FLAGS = @PROFILE_FLAGS@
|
||||
CFLAGS = @CFLAGS@
|
||||
CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@ @CROSS_COMPILE@
|
||||
STYLE_CFLAGS = @STYLE_CFLAGS@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CPPFLAGS_FOR_BUILD = @CPPFLAGS_FOR_BUILD@
|
||||
LOCAL_CFLAGS = @LOCAL_CFLAGS@ ${DEBUG}
|
||||
DEFS = @DEFS@
|
||||
LOCAL_DEFS = @LOCAL_DEFS@
|
||||
|
||||
LIBS = @LIBS@
|
||||
LDFLAGS = @LDFLAGS@ $(LOCAL_LDFLAGS) $(CFLAGS)
|
||||
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)
|
||||
|
||||
BASHINCDIR = ${topdir}/include
|
||||
|
||||
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@
|
||||
MKDIRS = ${topdir}/support/mkdirs
|
||||
|
||||
HELPFILES_TARGET = @HELPFILES_TARGET@
|
||||
|
||||
INCLUDES = -I. -I.. @RL_INCLUDE@ -I$(topdir) -I$(BASHINCDIR) -I$(topdir)/lib -I$(srcdir) ${INTL_INC}
|
||||
|
||||
BASE_CCFLAGS = ${PROFILE_FLAGS} $(DEFS) $(LOCAL_DEFS) $(SYSTEM_FLAGS) \
|
||||
${INCLUDES} $(STYLE_CFLAGS) $(LOCAL_CFLAGS)
|
||||
|
||||
CCFLAGS = ${ADDON_CFLAGS} $(BASE_CCFLAGS) $(CPPFLAGS) $(CFLAGS)
|
||||
|
||||
CCFLAGS_FOR_BUILD = $(BASE_CCFLAGS) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD)
|
||||
|
||||
GCC_LINT_FLAGS = -Wall -Wshadow -Wpointer-arith -Wcast-qual \
|
||||
-Wcast-align -Wstrict-prototypes -Wconversion \
|
||||
-Wmissing-prototypes -Wtraditional -Wredundant-decls -pedantic
|
||||
|
||||
MKBUILTINS = mkbuiltins$(EXEEXT)
|
||||
DIRECTDEFINE = -D $(srcdir)
|
||||
HELPDIRDEFINE = @HELPDIRDEFINE@
|
||||
HELPSTRINGS = @HELPSTRINGS@
|
||||
|
||||
# xxx this is bad style
|
||||
RL_LIBSRC = $(topdir)/lib/readline
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .def .c .o
|
||||
# How to make a .o file from a .def file.
|
||||
.def.o:
|
||||
$(RM) $@
|
||||
./$(MKBUILTINS) $(DIRECTDEFINE) $<
|
||||
$(CC) -c $(CCFLAGS) $*.c || ( $(RM) $*.c ; exit 1 )
|
||||
$(RM) $*.c
|
||||
|
||||
# How to make a .c file from a .def file.
|
||||
.def.c:
|
||||
$(RM) $@
|
||||
./$(MKBUILTINS) $(DIRECTDEFINE) $<
|
||||
|
||||
# default rule for making a .o file from a .c file
|
||||
.c.o:
|
||||
$(RM) $@
|
||||
$(CC) -c $(CCFLAGS) $<
|
||||
|
||||
DEFSRC = $(srcdir)/alias.def $(srcdir)/bind.def $(srcdir)/break.def \
|
||||
$(srcdir)/builtin.def $(srcdir)/caller.def \
|
||||
$(srcdir)/cd.def $(srcdir)/colon.def \
|
||||
$(srcdir)/command.def $(srcdir)/declare.def $(srcdir)/echo.def \
|
||||
$(srcdir)/enable.def $(srcdir)/eval.def $(srcdir)/getopts.def \
|
||||
$(srcdir)/exec.def $(srcdir)/exit.def $(srcdir)/fc.def \
|
||||
$(srcdir)/fg_bg.def $(srcdir)/hash.def $(srcdir)/help.def \
|
||||
$(srcdir)/history.def $(srcdir)/jobs.def $(srcdir)/kill.def \
|
||||
$(srcdir)/let.def $(srcdir)/read.def $(srcdir)/return.def \
|
||||
$(srcdir)/set.def $(srcdir)/setattr.def $(srcdir)/shift.def \
|
||||
$(srcdir)/source.def $(srcdir)/suspend.def $(srcdir)/test.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)/mapfile.def
|
||||
|
||||
STATIC_SOURCE = common.c evalstring.c evalfile.c getopt.c bashgetopt.c \
|
||||
getopt.h
|
||||
|
||||
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 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
|
||||
|
||||
CREATED_FILES = builtext.h builtins.c psize.aux pipesize.h tmpbuiltins.c \
|
||||
tmpbuiltins.h
|
||||
CREATED_OBJECTS = tmpbuiltins.o gen-helpfiles.o mkbuiltins.o
|
||||
|
||||
all: $(MKBUILTINS) libbuiltins.a $(HELPFILES_TARGET)
|
||||
targets: libbuiltins.a $(HELPFILES_TARGET)
|
||||
|
||||
libbuiltins.a: $(MKBUILTINS) $(OFILES) builtins.o
|
||||
$(RM) $@
|
||||
$(AR) $(ARFLAGS) $@ $(OFILES)
|
||||
-$(RANLIB) $@
|
||||
|
||||
tmpbuiltins.c: $(MKBUILTINS) $(DEFSRC)
|
||||
./$(MKBUILTINS) -externfile tmpbuiltins.h -structfile $@ \
|
||||
-noproduction -nofunctions \
|
||||
$(DIRECTDEFINE) $(HELPSTRINGS) $(DEFSRC)
|
||||
|
||||
tmpbuiltins.h: tmpbuiltins.c
|
||||
|
||||
gen-helpfiles.o: ../config.h
|
||||
gen-helpfiles.o: gen-helpfiles.c
|
||||
$(RM) $@
|
||||
$(CC_FOR_BUILD) -c $(CCFLAGS_FOR_BUILD) $<
|
||||
|
||||
gen-helpfiles: tmpbuiltins.o gen-helpfiles.o
|
||||
$(CC_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ gen-helpfiles.o tmpbuiltins.o $(LIBS_FOR_BUILD)
|
||||
|
||||
builtext.h builtins.c: $(MKBUILTINS) $(DEFSRC)
|
||||
@RECPID=$$$$ ; \
|
||||
NEW_BUILTEXT=builtext-$$RECPID.h NEW_BUILTINS=builtins-$$RECPID.c ; \
|
||||
./$(MKBUILTINS) -externfile $$NEW_BUILTEXT \
|
||||
-includefile builtext.h \
|
||||
-structfile $$NEW_BUILTINS \
|
||||
-noproduction $(DIRECTDEFINE) $(HELPDIRDEFINE) $(HELPSTRINGS) $(DEFSRC) ; \
|
||||
if cmp -s $$NEW_BUILTEXT builtext.h 2>/dev/null; then \
|
||||
$(RM) $$NEW_BUILTEXT; \
|
||||
else \
|
||||
mv $$NEW_BUILTEXT builtext.h; \
|
||||
fi ; \
|
||||
if cmp -s $$NEW_BUILTINS builtins.c 2>/dev/null; then \
|
||||
$(RM) $$NEW_BUILTINS ; \
|
||||
else \
|
||||
mv $$NEW_BUILTINS builtins.c; \
|
||||
fi
|
||||
|
||||
helpdoc: gen-helpfiles
|
||||
./gen-helpfiles ${HELPDIRDEFINE}
|
||||
|
||||
install-help: $(HELPFILES_TARGET)
|
||||
@-if test -n "${HELPDIR}" && test -d helpfiles ; then \
|
||||
test -d $(DESTDIR)${HELPDIR} || ${SHELL} ${MKDIRS} $(DESTDIR)$(HELPDIR) ;\
|
||||
( for f in helpfiles/*; do \
|
||||
echo installing $$f; \
|
||||
${INSTALL_DATA} $$f $(DESTDIR)$(HELPDIR); \
|
||||
done; ) ; \
|
||||
fi
|
||||
|
||||
install: @HELPINSTALL@
|
||||
|
||||
mkbuiltins.o: ../config.h
|
||||
mkbuiltins.o: mkbuiltins.c
|
||||
$(RM) $@
|
||||
$(CC_FOR_BUILD) -c $(CCFLAGS_FOR_BUILD) $<
|
||||
|
||||
mkbuiltins$(EXEEXT): mkbuiltins.o
|
||||
$(CC_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $(MKBUILTINS) mkbuiltins.o $(LIBS_FOR_BUILD)
|
||||
|
||||
# rules for deficient makes, like SunOS
|
||||
mkbuiltins.o: mkbuiltins.c
|
||||
builtins.o: builtins.c
|
||||
common.o: common.c
|
||||
bashgetopt.o: bashgetopt.c
|
||||
getopt.o: getopt.c
|
||||
evalstring.o: evalstring.c
|
||||
evalfile.o: evalfile.c
|
||||
|
||||
tmpbuiltins.o: tmpbuiltins.c
|
||||
gen-helpfiles.o: gen-helpfiles.c
|
||||
|
||||
ulimit.o: pipesize.h
|
||||
|
||||
pipesize.h: psize.aux
|
||||
$(SHELL) $(srcdir)/psize.sh > $@
|
||||
|
||||
# Technically this is wrong; the pipe size should be for the target system,
|
||||
# not the build host.
|
||||
psize.aux: psize.c
|
||||
$(CC_FOR_BUILD) $(CCFLAGS_FOR_BUILD) ${LDFLAGS_FOR_BUILD} -o $@ $(srcdir)/psize.c
|
||||
|
||||
documentation: builtins.texi
|
||||
|
||||
builtins.texi: $(MKBUILTINS)
|
||||
./$(MKBUILTINS) -documentonly $(DEFSRC)
|
||||
|
||||
clean:
|
||||
$(RM) $(OFILES) $(CREATED_FILES) libbuiltins.a
|
||||
$(RM) $(MKBUILTINS) gen-helpfiles $(CREATED_OBJECTS)
|
||||
-test -d helpfiles && $(RM) -r helpfiles
|
||||
|
||||
mostlyclean:
|
||||
$(RM) $(OFILES) libbuiltins.a
|
||||
|
||||
distclean maintainer-clean: clean
|
||||
$(RM) Makefile
|
||||
|
||||
$(OFILES): $(MKBUILTINS) ../config.h
|
||||
|
||||
../version.h: ../config.h ../Makefile Makefile
|
||||
-( cd ${BUILD_DIR} && ${MAKE} ${MFLAGS} version.h )
|
||||
|
||||
# maintainer special - for now
|
||||
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
|
||||
bind.o: bind.def
|
||||
break.o: break.def
|
||||
builtin.o: builtin.def
|
||||
caller.o: caller.def
|
||||
cd.o: cd.def
|
||||
colon.o: colon.def
|
||||
command.o: command.def
|
||||
declare.o: declare.def
|
||||
echo.o: echo.def
|
||||
enable.o: enable.def
|
||||
eval.o: eval.def
|
||||
exec.o: exec.def
|
||||
exit.o: exit.def
|
||||
fc.o: fc.def
|
||||
fg_bg.o: fg_bg.def
|
||||
hash.o: hash.def
|
||||
help.o: help.def
|
||||
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
|
||||
return.o: return.def
|
||||
set.o: set.def
|
||||
setattr.o: setattr.def
|
||||
shift.o: shift.def
|
||||
shopt.o: shopt.def
|
||||
source.o: source.def
|
||||
suspend.o: suspend.def
|
||||
test.o: test.def
|
||||
times.o: times.def
|
||||
trap.o: trap.def
|
||||
type.o: type.def
|
||||
ulimit.o: ulimit.def
|
||||
umask.o: umask.def
|
||||
wait.o: wait.def
|
||||
getopts.o: getopts.def
|
||||
reserved.o: reserved.def
|
||||
complete.o: complete.def
|
||||
|
||||
# C files
|
||||
bashgetopt.o: ../config.h $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h
|
||||
bashgetopt.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/bashjmp.h
|
||||
bashgetopt.o: $(topdir)/command.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/error.h
|
||||
bashgetopt.o: $(topdir)/variables.h $(topdir)/conftypes.h $(topdir)/quit.h $(BASHINCDIR)/maxpath.h
|
||||
bashgetopt.o: $(topdir)/unwind_prot.h $(topdir)/dispose_cmd.h
|
||||
bashgetopt.o: $(topdir)/make_cmd.h $(topdir)/subst.h $(topdir)/sig.h
|
||||
bashgetopt.o: ../pathnames.h $(topdir)/externs.h $(srcdir)/common.h
|
||||
bashgetopt.o: $(BASHINCDIR)/chartypes.h
|
||||
common.o: $(topdir)/bashtypes.h $(BASHINCDIR)/posixstat.h $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h
|
||||
common.o: $(topdir)/shell.h $(topdir)/syntax.h ../config.h $(topdir)/bashjmp.h $(BASHINCDIR)/posixjmp.h
|
||||
common.o: $(topdir)/sig.h $(topdir)/command.h $(topdir)/parser.h
|
||||
common.o: $(topdir)/general.h $(topdir)/xmalloc.h $(BASHINCDIR)/stdc.h $(BASHINCDIR)/memalloc.h
|
||||
common.o: $(topdir)/variables.h $(topdir)/conftypes.h $(topdir)/input.h
|
||||
common.o: $(topdir)/siglist.h $(topdir)/bashhist.h $(topdir)/quit.h
|
||||
common.o: $(topdir)/unwind_prot.h $(BASHINCDIR)/maxpath.h $(topdir)/jobs.h
|
||||
common.o: $(topdir)/builtins.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
|
||||
common.o: $(topdir)/subst.h $(topdir)/execute_cmd.h $(topdir)/error.h
|
||||
common.o: $(topdir)/externs.h ../pathnames.h ./builtext.h
|
||||
common.o: $(BASHINCDIR)/chartypes.h
|
||||
evalfile.o: $(topdir)/bashtypes.h $(BASHINCDIR)/posixstat.h ${BASHINCDIR}/filecntl.h
|
||||
evalfile.o: $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h
|
||||
evalfile.o: $(topdir)/shell.h $(topdir)/syntax.h ../config.h $(topdir)/bashjmp.h
|
||||
evalfile.o: $(topdir)/command.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/error.h
|
||||
evalfile.o: $(topdir)/variables.h $(topdir)/conftypes.h $(topdir)/quit.h $(BASHINCDIR)/maxpath.h
|
||||
evalfile.o: $(topdir)/unwind_prot.h $(topdir)/dispose_cmd.h
|
||||
evalfile.o: $(topdir)/make_cmd.h $(topdir)/subst.h $(topdir)/sig.h
|
||||
evalfile.o: ../pathnames.h $(topdir)/externs.h $(topdir)/parser.h
|
||||
evalfile.o: $(topdir)/jobs.h $(topdir)/builtins.h $(topdir)/flags.h
|
||||
evalfile.o: $(topdir)/input.h $(topdir)/execute_cmd.h
|
||||
evalfile.o: $(topdir)/bashhist.h $(srcdir)/common.h
|
||||
evalstring.o: ../config.h $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h
|
||||
evalstring.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/bashjmp.h $(BASHINCDIR)/posixjmp.h
|
||||
evalstring.o: $(topdir)/sig.h $(topdir)/command.h $(topdir)/siglist.h
|
||||
evalstring.o: $(BASHINCDIR)/memalloc.h $(topdir)/variables.h $(topdir)/conftypes.h $(topdir)/input.h
|
||||
evalstring.o: $(topdir)/quit.h $(topdir)/unwind_prot.h
|
||||
evalstring.o: $(BASHINCDIR)/maxpath.h $(topdir)/jobs.h $(topdir)/builtins.h
|
||||
evalstring.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
|
||||
evalstring.o: $(topdir)/externs.h $(topdir)/jobs.h $(topdir)/builtins.h
|
||||
evalstring.o: $(topdir)/flags.h $(topdir)/input.h $(topdir)/execute_cmd.h
|
||||
evalstring.o: $(topdir)/bashhist.h $(srcdir)/common.h
|
||||
evalstring.o: $(topdir)/trap.h $(topdir)/redir.h ../pathnames.h ./builtext.h
|
||||
#evalstring.o: $(topdir)/y.tab.h
|
||||
getopt.o: ../config.h $(BASHINCDIR)/memalloc.h
|
||||
getopt.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/bashjmp.h $(topdir)/command.h
|
||||
getopt.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/error.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
getopt.o: $(topdir)/quit.h $(BASHINCDIR)/maxpath.h $(topdir)/unwind_prot.h
|
||||
getopt.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
|
||||
getopt.o: $(topdir)/sig.h ../pathnames.h $(topdir)/externs.h
|
||||
getopt.o: $(srcdir)/getopt.h
|
||||
mkbuiltins.o: ../config.h $(topdir)/bashtypes.h $(BASHINCDIR)/posixstat.h
|
||||
mkbuiltins.o: ${BASHINCDIR}/filecntl.h
|
||||
mkbuiltins.o: $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h
|
||||
|
||||
# def files
|
||||
alias.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
alias.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(BASHINCDIR)/maxpath.h
|
||||
alias.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
alias.o: $(topdir)/subst.h $(topdir)/externs.h $(srcdir)/common.h
|
||||
alias.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
alias.o: ../pathnames.h
|
||||
bind.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
|
||||
bind.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
bind.o: $(topdir)/subst.h $(topdir)/externs.h $(srcdir)/bashgetopt.h
|
||||
bind.o: $(topdir)/general.h $(topdir)/xmalloc.h $(BASHINCDIR)/maxpath.h $(topdir)/bashline.h
|
||||
bind.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
break.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
break.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
break.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
break.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
break.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
break.o: ../pathnames.h $(topdir)/execute_cmd.h
|
||||
builtin.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
builtin.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/externs.h
|
||||
builtin.o: $(topdir)/quit.h $(srcdir)/common.h $(BASHINCDIR)/maxpath.h $(topdir)/sig.h
|
||||
builtin.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
|
||||
builtin.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
builtin.o: $(srcdir)/bashgetopt.h ../pathnames.h $(topdir)/execute_cmd.h
|
||||
caller.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
|
||||
caller.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/quit.h $(topdir)/dispose_cmd.h
|
||||
caller.o: $(topdir)/make_cmd.h $(topdir)/subst.h $(topdir)/externs.h $(topdir)/sig.h
|
||||
caller.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
caller.o: $(srcdir)/common.h $(BASHINCDIR)/maxpath.h ./builtext.h
|
||||
caller.o: ${BASHINCDIR}/chartypes.h $(topdir)/bashtypes.h ../pathnames.h
|
||||
cd.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
|
||||
cd.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/quit.h $(topdir)/dispose_cmd.h
|
||||
cd.o: $(topdir)/make_cmd.h $(topdir)/subst.h $(topdir)/externs.h
|
||||
cd.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
cd.o: $(srcdir)/common.h $(BASHINCDIR)/maxpath.h ../pathnames.h
|
||||
cd.o: $(topdir)/sig.h
|
||||
colon.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
|
||||
colon.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/subst.h $(topdir)/externs.h
|
||||
colon.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
colon.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
colon.o: $(BASHINCDIR)/maxpath.h ../pathnames.h
|
||||
colon.o: $(srcdir)/common.h
|
||||
command.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
command.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/externs.h
|
||||
command.o: $(topdir)/quit.h $(srcdir)/bashgetopt.h $(BASHINCDIR)/maxpath.h
|
||||
command.o: $(topdir)/sig.h
|
||||
command.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
|
||||
command.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
command.o: ../pathnames.h
|
||||
declare.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
declare.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
declare.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
declare.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
declare.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
declare.o: $(topdir)/arrayfunc.h $(srcdir)/bashgetopt.h $(topdir)/flags.h
|
||||
declare.o: ./builtext.h ../pathnames.h
|
||||
echo.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
|
||||
echo.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/subst.h $(topdir)/externs.h
|
||||
echo.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
echo.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
echo.o: $(BASHINCDIR)/maxpath.h ../pathnames.h
|
||||
echo.o: $(srcdir)/common.h
|
||||
enable.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
enable.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
enable.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
|
||||
enable.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/sig.h
|
||||
enable.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
enable.o: $(BASHINCDIR)/maxpath.h ../pathnames.h
|
||||
enable.o: $(topdir)/pcomplete.h
|
||||
eval.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
eval.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
eval.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
|
||||
eval.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/sig.h
|
||||
eval.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
eval.o: $(BASHINCDIR)/maxpath.h ../pathnames.h
|
||||
exec.o: $(topdir)/bashtypes.h
|
||||
exec.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
exec.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
exec.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
exec.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/flags.h
|
||||
exec.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
exec.o: $(srcdir)/common.h $(topdir)/execute_cmd.h $(BASHINCDIR)/maxpath.h
|
||||
exec.o: $(topdir)/findcmd.h $(topdir)/jobs.h ../pathnames.h
|
||||
exit.o: $(topdir)/bashtypes.h
|
||||
exit.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
exit.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
exit.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
exit.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/jobs.h
|
||||
exit.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
exit.o: $(topdir)/execute_cmd.h
|
||||
exit.o: $(BASHINCDIR)/maxpath.h ./builtext.h ../pathnames.h
|
||||
fc.o: $(topdir)/bashtypes.h $(BASHINCDIR)/posixstat.h
|
||||
fc.o: $(topdir)/builtins.h $(topdir)/command.h $(srcdir)/bashgetopt.h
|
||||
fc.o: $(topdir)/bashhist.h $(topdir)/parser.h
|
||||
fc.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
|
||||
fc.o: $(topdir)/general.h $(topdir)/xmalloc.h $(BASHINCDIR)/maxpath.h
|
||||
fc.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
fc.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/shell.h $(topdir)/syntax.h
|
||||
fc.o: $(topdir)/flags.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
fc.o: $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h $(BASHINCDIR)/chartypes.h
|
||||
fc.o: ../pathnames.h
|
||||
fg_bg.o: $(topdir)/bashtypes.h $(srcdir)/bashgetopt.h
|
||||
fg_bg.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
fg_bg.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
fg_bg.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
fg_bg.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
fg_bg.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
fg_bg.o: $(topdir)/execute_cmd.h
|
||||
fg_bg.o: $(topdir)/jobs.h ../pathnames.h
|
||||
getopts.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
getopts.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
getopts.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
getopts.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
getopts.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
getopts.o: $(topdir)/execute_cmd.h
|
||||
getopts.o: ../pathnames.h
|
||||
hash.o: $(topdir)/builtins.h $(topdir)/command.h $(topdir)/quit.h
|
||||
hash.o: $(topdir)/findcmd.h $(topdir)/hashlib.h $(topdir)/sig.h
|
||||
hash.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
hash.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
hash.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h
|
||||
hash.o: $(topdir)/conftypes.h $(topdir)/execute_cmd.h
|
||||
hash.o: $(srcdir)/common.h $(BASHINCDIR)/maxpath.h ../pathnames.h
|
||||
help.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
help.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
help.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
|
||||
help.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
help.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h
|
||||
help.o: $(topdir)/conftypes.h $(topdir)/execute_cmd.h
|
||||
help.o: ${srcdir}/common.h $(topdir)/sig.h ../pathnames.h
|
||||
history.o: $(topdir)/bashtypes.h
|
||||
history.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
history.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
history.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
|
||||
history.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/sig.h $(topdir)/parser.h
|
||||
history.o: ${BASHINCDIR}/filecntl.h $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h
|
||||
history.o: $(topdir)/variables.h $(topdir)/conftypes.h $(topdir)/bashhist.h $(BASHINCDIR)/maxpath.h
|
||||
history.o: ../pathnames.h
|
||||
inlib.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
inlib.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
inlib.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
inlib.o: $(BASHINCDIR)/maxpath.h $(topdir)/subst.h $(topdir)/externs.h
|
||||
inlib.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h ../pathnames.h
|
||||
jobs.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
|
||||
jobs.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/quit.h $(srcdir)/bashgetopt.h
|
||||
jobs.o: $(BASHINCDIR)/maxpath.h $(topdir)/externs.h $(topdir)/jobs.h
|
||||
jobs.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
|
||||
jobs.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
jobs.o: $(topdir)/sig.h ../pathnames.h
|
||||
kill.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
|
||||
kill.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/subst.h $(topdir)/externs.h
|
||||
kill.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
kill.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/trap.h $(topdir)/unwind_prot.h
|
||||
kill.o: $(topdir)/variables.h $(topdir)/conftypes.h $(BASHINCDIR)/maxpath.h
|
||||
kill.o: $(topdir)/jobs.h ../pathnames.h
|
||||
let.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
let.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
let.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
let.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
let.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
let.o: ../pathnames.h
|
||||
printf.o: ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/bashjmp.h
|
||||
printf.o: $(topdir)/command.h $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
printf.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
|
||||
printf.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/sig.h
|
||||
printf.o: ../pathnames.h $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h
|
||||
printf.o: $(topdir)/variables.h $(topdir)/conftypes.h $(BASHINCDIR)/stdc.h $(srcdir)/bashgetopt.h
|
||||
printf.o: $(topdir)/bashtypes.h ${srcdir}/common.h $(BASHINCDIR)/chartypes.h
|
||||
printf.o: ${BASHINCDIR}/shmbutil.h ${BASHINCDIR}/shmbchar.h
|
||||
printf.o: ../pathnames.h
|
||||
pushd.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
pushd.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
pushd.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
|
||||
pushd.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/sig.h
|
||||
pushd.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
pushd.o: $(BASHINCDIR)/maxpath.h $(srcdir)/common.h ./builtext.h
|
||||
pushd.o: ../pathnames.h
|
||||
read.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
read.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
read.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
|
||||
read.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
read.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
read.o: $(BASHINCDIR)/shtty.h $(topdir)/sig.h
|
||||
read.o: ${BASHINCDIR}/shmbutil.h ${BASHINCDIR}/shmbchar.h
|
||||
read.o: $(topdir)/arrayfunc.h ../pathnames.h
|
||||
return.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
return.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
return.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
return.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
return.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h
|
||||
return.o: $(topdir)/conftypes.h $(topdir)/execute_cmd.h
|
||||
return.o: ../pathnames.h
|
||||
set.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
set.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/subst.h $(topdir)/externs.h
|
||||
set.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
|
||||
set.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
set.o: $(BASHINCDIR)/maxpath.h $(topdir)/error.h $(topdir)/sig.h
|
||||
set.o: $(topdir)/arrayfunc.h ../pathnames.h $(topdir)/parser.h
|
||||
setattr.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
setattr.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(BASHINCDIR)/maxpath.h
|
||||
setattr.o: $(topdir)/quit.h $(srcdir)/common.h $(srcdir)/bashgetopt.h
|
||||
setattr.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
|
||||
setattr.o: $(topdir)/externs.h $(topdir)/flags.h $(topdir)/sig.h
|
||||
setattr.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h
|
||||
setattr.o: $(topdir)/conftypes.h $(topdir)/execute_cmd.h
|
||||
setattr.o: $(topdir)/arrayfunc.h ../pathnames.h
|
||||
shift.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
shift.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
shift.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
shift.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
shift.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
shift.o: ../pathnames.h
|
||||
shopt.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
shopt.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
shopt.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
|
||||
shopt.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
shopt.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
shopt.o: $(srcdir)/common.h $(srcdir)/bashgetopt.h ../pathnames.h
|
||||
shopt.o: $(topdir)/bashhist.h $(topdir)/bashline.h $(topdir)/sig.h
|
||||
source.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
source.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/findcmd.h
|
||||
source.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
source.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
source.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
source.o: $(srcdir)/bashgetopt.h $(topdir)/flags.h $(topdir)/trap.h
|
||||
source.o: $(topdir)/execute_cmd.h
|
||||
source.o: ../pathnames.h
|
||||
suspend.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
suspend.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
suspend.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
suspend.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
suspend.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
suspend.o: $(topdir)/jobs.h ../pathnames.h
|
||||
test.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
test.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
test.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
test.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
test.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
test.o: $(topdir)/execute_cmd.h $(topdir)/test.h ../pathnames.h
|
||||
times.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
times.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
times.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
times.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
times.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
times.o: $(BASHINCDIR)/posixtime.h ../pathnames.h
|
||||
trap.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
trap.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/externs.h
|
||||
trap.o: $(topdir)/quit.h $(srcdir)/common.h $(BASHINCDIR)/maxpath.h $(topdir)/sig.h
|
||||
trap.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
|
||||
trap.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
trap.o: $(topdir)/findcmd.h ../pathnames.h
|
||||
type.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
type.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
type.o: $(topdir)/quit.h $(srcdir)/common.h $(BASHINCDIR)/maxpath.h $(topdir)/sig.h
|
||||
type.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
|
||||
type.o: $(topdir)/execute_cmd.h $(topdir)/parser.h
|
||||
type.o: $(topdir)/externs.h $(topdir)/hashcmd.h ../pathnames.h
|
||||
type.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
ulimit.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
ulimit.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
ulimit.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
ulimit.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
ulimit.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
ulimit.o: ../pathnames.h
|
||||
umask.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
umask.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
umask.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
umask.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
umask.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
umask.o: $(BASHINCDIR)/chartypes.h ../pathnames.h
|
||||
wait.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
|
||||
wait.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
|
||||
wait.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
|
||||
wait.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
|
||||
wait.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
|
||||
wait.o: $(topdir)/jobs.h $(topdir)/sig.h $(topdir)/execute_cmd.h
|
||||
wait.o: $(BASHINCDIR)/chartypes.h ../pathnames.h
|
||||
|
||||
complete.o: ../config.h ../pathnames.h
|
||||
complete.o: ${topdir}/shell.h $(topdir)/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h ${topdir}/sig.h
|
||||
complete.o: ${topdir}/unwind_prot.h ${topdir}/variables.h
|
||||
complete.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/sig.h
|
||||
complete.o: ${topdir}/bashtypes.h ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
|
||||
complete.o: ${topdir}/builtins.h ${topdir}/general.h
|
||||
complete.o: ${topdir}/bashtypes.h ${BASHINCDIR}/chartypes.h ${topdir}/xmalloc.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 $(topdir)/sig.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 ../pathnames.h
|
||||
|
||||
#bind.o: $(RL_LIBSRC)chardefs.h $(RL_LIBSRC)readline.h $(RL_LIBSRC)keymaps.h
|
||||
|
||||
# libintl dependencies
|
||||
bind.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
break.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
caller.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
cd.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
common.c: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
complete.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
declare.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
enable.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
evalfile.c: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
exec.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
exit.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
fc.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
fg_bg.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
getopt.c: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
hash.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
help.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
history.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
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
|
||||
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
|
||||
return.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
set.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
setattr.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
shift.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
shopt.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
source.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
suspend.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
type.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
ulimit.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
umask.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
|
||||
cd.o: $(topdir)/config-top.h
|
||||
command.o: $(topdir)/config-top.h
|
||||
common.o: $(topdir)/config-top.h
|
||||
declare.o: $(topdir)/config-top.h
|
||||
break.o: $(topdir)/config-top.h
|
||||
echo.o: $(topdir)/config-top.h
|
||||
evalstring.o: $(topdir)/config-top.h
|
||||
exit.o: $(topdir)/config-top.h
|
||||
kill.o: $(topdir)/config-top.h
|
||||
shopt.o: $(topdir)/config-top.h
|
241
builtins/alias.def
Normal file
241
builtins/alias.def
Normal file
|
@ -0,0 +1,241 @@
|
|||
This file is alias.def, from which is created alias.c
|
||||
It implements the builtins "alias" and "unalias" in Bash.
|
||||
|
||||
Copyright (C) 1987-2020 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/>.
|
||||
|
||||
$BUILTIN alias
|
||||
$FUNCTION alias_builtin
|
||||
$DEPENDS_ON ALIAS
|
||||
$PRODUCES alias.c
|
||||
$SHORT_DOC alias [-p] [name[=value] ... ]
|
||||
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.
|
||||
|
||||
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>
|
||||
|
||||
#if defined (ALIAS)
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
# include "../bashansi.h"
|
||||
# include "../bashintl.h"
|
||||
|
||||
# include <stdio.h>
|
||||
# include "../shell.h"
|
||||
# include "../alias.h"
|
||||
# include "common.h"
|
||||
# include "bashgetopt.h"
|
||||
|
||||
/* Flags for print_alias */
|
||||
#define AL_REUSABLE 0x01
|
||||
|
||||
static void print_alias PARAMS((alias_t *, int));
|
||||
|
||||
/* Hack the alias command in a Korn shell way. */
|
||||
int
|
||||
alias_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int any_failed, offset, pflag, dflags;
|
||||
alias_t **alias_list, *t;
|
||||
char *name, *value;
|
||||
|
||||
dflags = posixly_correct ? 0 : AL_REUSABLE;
|
||||
pflag = 0;
|
||||
reset_internal_getopt ();
|
||||
while ((offset = internal_getopt (list, "p")) != -1)
|
||||
{
|
||||
switch (offset)
|
||||
{
|
||||
case 'p':
|
||||
pflag = 1;
|
||||
dflags |= AL_REUSABLE;
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
|
||||
list = loptend;
|
||||
|
||||
if (list == 0 || pflag)
|
||||
{
|
||||
if (aliases == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
alias_list = all_aliases ();
|
||||
|
||||
if (alias_list == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
for (offset = 0; alias_list[offset]; offset++)
|
||||
print_alias (alias_list[offset], dflags);
|
||||
|
||||
free (alias_list); /* XXX - Do not free the strings. */
|
||||
|
||||
if (list == 0)
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
any_failed = 0;
|
||||
while (list)
|
||||
{
|
||||
name = list->word->word;
|
||||
|
||||
for (offset = 0; name[offset] && name[offset] != '='; offset++)
|
||||
;
|
||||
|
||||
if (offset && name[offset] == '=')
|
||||
{
|
||||
name[offset] = '\0';
|
||||
value = name + offset + 1;
|
||||
|
||||
if (legal_alias_name (name, 0) == 0)
|
||||
{
|
||||
builtin_error (_("`%s': invalid alias name"), name);
|
||||
any_failed++;
|
||||
}
|
||||
else
|
||||
add_alias (name, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
t = find_alias (name);
|
||||
if (t)
|
||||
print_alias (t, dflags);
|
||||
else
|
||||
{
|
||||
sh_notfound (name);
|
||||
any_failed++;
|
||||
}
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return (any_failed ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
|
||||
}
|
||||
#endif /* ALIAS */
|
||||
|
||||
$BUILTIN unalias
|
||||
$FUNCTION unalias_builtin
|
||||
$DEPENDS_ON ALIAS
|
||||
$SHORT_DOC unalias [-a] name [name ...]
|
||||
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)
|
||||
/* Remove aliases named in LIST from the aliases database. */
|
||||
int
|
||||
unalias_builtin (list)
|
||||
register WORD_LIST *list;
|
||||
{
|
||||
register alias_t *alias;
|
||||
int opt, aflag;
|
||||
|
||||
aflag = 0;
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "a")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'a':
|
||||
aflag = 1;
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
|
||||
list = loptend;
|
||||
|
||||
if (aflag)
|
||||
{
|
||||
delete_all_aliases ();
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
aflag = 0;
|
||||
while (list)
|
||||
{
|
||||
alias = find_alias (list->word->word);
|
||||
|
||||
if (alias)
|
||||
remove_alias (alias->name);
|
||||
else
|
||||
{
|
||||
sh_notfound (list->word->word);
|
||||
aflag++;
|
||||
}
|
||||
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return (aflag ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
/* Output ALIAS in such a way as to allow it to be read back in. */
|
||||
static void
|
||||
print_alias (alias, flags)
|
||||
alias_t *alias;
|
||||
int flags;
|
||||
{
|
||||
char *value;
|
||||
|
||||
value = sh_single_quote (alias->value);
|
||||
if (flags & AL_REUSABLE)
|
||||
printf ("alias %s", (alias->name && alias->name[0] == '-') ? "-- " : "");
|
||||
printf ("%s=%s\n", alias->name, value);
|
||||
free (value);
|
||||
|
||||
fflush (stdout);
|
||||
}
|
||||
#endif /* ALIAS */
|
194
builtins/bashgetopt.c
Normal file
194
builtins/bashgetopt.c
Normal file
|
@ -0,0 +1,194 @@
|
|||
/* bashgetopt.c -- `getopt' for use by the builtins. */
|
||||
|
||||
/* Copyright (C) 1992-2021 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/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include <chartypes.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../shell.h"
|
||||
#include "common.h"
|
||||
|
||||
#include "bashgetopt.h"
|
||||
|
||||
#define ISOPT(s) (((*(s) == '-') || (plus && *(s) == '+')) && (s)[1])
|
||||
#define NOTOPT(s) (((*(s) != '-') && (!plus || *(s) != '+')) || (s)[1] == '\0')
|
||||
|
||||
static int sp;
|
||||
|
||||
char *list_optarg;
|
||||
int list_optflags;
|
||||
int list_optopt;
|
||||
int list_opttype;
|
||||
|
||||
static WORD_LIST *lhead = (WORD_LIST *)NULL;
|
||||
WORD_LIST *lcurrent = (WORD_LIST *)NULL;
|
||||
WORD_LIST *loptend; /* Points to the first non-option argument in the list */
|
||||
|
||||
int
|
||||
internal_getopt(list, opts)
|
||||
WORD_LIST *list;
|
||||
char *opts;
|
||||
{
|
||||
register int c;
|
||||
register char *cp;
|
||||
int plus; /* nonzero means to handle +option */
|
||||
static char errstr[3] = { '-', '\0', '\0' };
|
||||
|
||||
plus = *opts == '+';
|
||||
if (plus)
|
||||
opts++;
|
||||
|
||||
if (list == 0) {
|
||||
list_optarg = (char *)NULL;
|
||||
list_optflags = 0;
|
||||
loptend = (WORD_LIST *)NULL; /* No non-option arguments */
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (list != lhead || lhead == 0) {
|
||||
/* Hmmm.... called with a different word list. Reset. */
|
||||
sp = 1;
|
||||
lcurrent = lhead = list;
|
||||
loptend = (WORD_LIST *)NULL;
|
||||
}
|
||||
|
||||
if (sp == 1) {
|
||||
if (lcurrent == 0 || NOTOPT(lcurrent->word->word)) {
|
||||
lhead = (WORD_LIST *)NULL;
|
||||
loptend = lcurrent;
|
||||
return(-1);
|
||||
} else if (ISHELP (lcurrent->word->word)) {
|
||||
lhead = (WORD_LIST *)NULL;
|
||||
loptend = lcurrent;
|
||||
return (GETOPT_HELP);
|
||||
} else if (lcurrent->word->word[0] == '-' &&
|
||||
lcurrent->word->word[1] == '-' &&
|
||||
lcurrent->word->word[2] == 0) {
|
||||
lhead = (WORD_LIST *)NULL;
|
||||
loptend = lcurrent->next;
|
||||
return(-1);
|
||||
}
|
||||
errstr[0] = list_opttype = lcurrent->word->word[0];
|
||||
}
|
||||
|
||||
list_optopt = c = lcurrent->word->word[sp];
|
||||
|
||||
if (c == ':' || (cp = strchr(opts, c)) == NULL) {
|
||||
errstr[1] = c;
|
||||
sh_invalidopt (errstr);
|
||||
if (lcurrent->word->word[++sp] == '\0') {
|
||||
lcurrent = lcurrent->next;
|
||||
sp = 1;
|
||||
}
|
||||
list_optarg = NULL;
|
||||
list_optflags = 0;
|
||||
if (lcurrent)
|
||||
loptend = lcurrent->next;
|
||||
return('?');
|
||||
}
|
||||
|
||||
if (*++cp == ':' || *cp == ';') {
|
||||
/* `:': Option requires an argument. */
|
||||
/* `;': option argument may be missing */
|
||||
/* We allow -l2 as equivalent to -l 2 */
|
||||
if (lcurrent->word->word[sp+1]) {
|
||||
list_optarg = lcurrent->word->word + sp + 1;
|
||||
list_optflags = 0;
|
||||
lcurrent = lcurrent->next;
|
||||
/* If the specifier is `;', don't set optarg if the next
|
||||
argument looks like another option. */
|
||||
#if 0
|
||||
} else if (lcurrent->next && (*cp == ':' || lcurrent->next->word->word[0] != '-')) {
|
||||
#else
|
||||
} else if (lcurrent->next && (*cp == ':' || NOTOPT(lcurrent->next->word->word))) {
|
||||
#endif
|
||||
lcurrent = lcurrent->next;
|
||||
list_optarg = lcurrent->word->word;
|
||||
list_optflags = lcurrent->word->flags;
|
||||
lcurrent = lcurrent->next;
|
||||
} else if (*cp == ';') {
|
||||
list_optarg = (char *)NULL;
|
||||
list_optflags = 0;
|
||||
lcurrent = lcurrent->next;
|
||||
} else { /* lcurrent->next == NULL */
|
||||
errstr[1] = c;
|
||||
sh_needarg (errstr);
|
||||
sp = 1;
|
||||
list_optarg = (char *)NULL;
|
||||
list_optflags = 0;
|
||||
return('?');
|
||||
}
|
||||
sp = 1;
|
||||
} else if (*cp == '#') {
|
||||
/* option requires a numeric argument */
|
||||
if (lcurrent->word->word[sp+1]) {
|
||||
if (DIGIT(lcurrent->word->word[sp+1])) {
|
||||
list_optarg = lcurrent->word->word + sp + 1;
|
||||
list_optflags = 0;
|
||||
lcurrent = lcurrent->next;
|
||||
} else {
|
||||
list_optarg = (char *)NULL;
|
||||
list_optflags = 0;
|
||||
}
|
||||
} else {
|
||||
if (lcurrent->next && legal_number(lcurrent->next->word->word, (intmax_t *)0)) {
|
||||
lcurrent = lcurrent->next;
|
||||
list_optarg = lcurrent->word->word;
|
||||
list_optflags = lcurrent->word->flags;
|
||||
lcurrent = lcurrent->next;
|
||||
} else {
|
||||
errstr[1] = c;
|
||||
sh_neednumarg (errstr);
|
||||
sp = 1;
|
||||
list_optarg = (char *)NULL;
|
||||
list_optflags = 0;
|
||||
return ('?');
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
/* No argument, just return the option. */
|
||||
if (lcurrent->word->word[++sp] == '\0') {
|
||||
sp = 1;
|
||||
lcurrent = lcurrent->next;
|
||||
}
|
||||
list_optarg = (char *)NULL;
|
||||
list_optflags = 0;
|
||||
}
|
||||
|
||||
return(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* reset_internal_getopt -- force the in[ft]ernal getopt to reset
|
||||
*/
|
||||
|
||||
void
|
||||
reset_internal_getopt ()
|
||||
{
|
||||
lhead = lcurrent = loptend = (WORD_LIST *)NULL;
|
||||
sp = 1;
|
||||
}
|
43
builtins/bashgetopt.h
Normal file
43
builtins/bashgetopt.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/* bashgetopt.h -- extern declarations for stuff defined in bashgetopt.c. */
|
||||
|
||||
/* Copyright (C) 1993-2021 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/>.
|
||||
*/
|
||||
|
||||
/* See getopt.h for the explanation of these variables. */
|
||||
|
||||
#if !defined (__BASH_GETOPT_H)
|
||||
# define __BASH_GETOPT_H
|
||||
|
||||
#include <stdc.h>
|
||||
|
||||
#define GETOPT_EOF -1
|
||||
#define GETOPT_HELP -99
|
||||
|
||||
extern char *list_optarg;
|
||||
extern int list_optflags;
|
||||
|
||||
extern int list_optopt;
|
||||
extern int list_opttype;
|
||||
|
||||
extern WORD_LIST *lcurrent;
|
||||
extern WORD_LIST *loptend;
|
||||
|
||||
extern int internal_getopt PARAMS((WORD_LIST *, char *));
|
||||
extern void reset_internal_getopt PARAMS((void));
|
||||
|
||||
#endif /* !__BASH_GETOPT_H */
|
405
builtins/bind.def
Normal file
405
builtins/bind.def
Normal file
|
@ -0,0 +1,405 @@
|
|||
This file is bind.def, from which is created bind.c.
|
||||
It implements the builtin "bind" in Bash.
|
||||
|
||||
Copyright (C) 1987-2021 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 bind.c
|
||||
|
||||
#include <config.h>
|
||||
|
||||
$BUILTIN bind
|
||||
$DEPENDS_ON READLINE
|
||||
$FUNCTION bind_builtin
|
||||
$SHORT_DOC bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
|
||||
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.
|
||||
-l List names of functions.
|
||||
-P List function names and bindings.
|
||||
-p List functions and bindings 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.
|
||||
-X List key sequences bound with -x and associated commands
|
||||
in a form that can be reused as input.
|
||||
|
||||
Exit Status:
|
||||
bind returns 0 unless an unrecognized option is given or an error occurs.
|
||||
$END
|
||||
|
||||
#if defined (READLINE)
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif /* !errno */
|
||||
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../bashline.h"
|
||||
#include "bashgetopt.h"
|
||||
#include "common.h"
|
||||
|
||||
static int query_bindings PARAMS((char *));
|
||||
static int unbind_command PARAMS((char *));
|
||||
static int unbind_keyseq PARAMS((char *));
|
||||
|
||||
#define BIND_RETURN(x) do { return_code = x; goto bind_exit; } while (0)
|
||||
|
||||
#define LFLAG 0x0001
|
||||
#define PFLAG 0x0002
|
||||
#define FFLAG 0x0004
|
||||
#define VFLAG 0x0008
|
||||
#define QFLAG 0x0010
|
||||
#define MFLAG 0x0020
|
||||
#define RFLAG 0x0040
|
||||
#define PPFLAG 0x0080
|
||||
#define VVFLAG 0x0100
|
||||
#define SFLAG 0x0200
|
||||
#define SSFLAG 0x0400
|
||||
#define UFLAG 0x0800
|
||||
#define XFLAG 0x1000
|
||||
#define XXFLAG 0x2000
|
||||
|
||||
int
|
||||
bind_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int return_code;
|
||||
Keymap kmap, saved_keymap;
|
||||
int flags, opt;
|
||||
char *initfile, *map_name, *fun_name, *unbind_name, *remove_seq, *cmd_seq, *t;
|
||||
|
||||
if (no_line_editing)
|
||||
{
|
||||
#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 = cmd_seq = (char *)NULL;
|
||||
return_code = EXECUTION_SUCCESS;
|
||||
|
||||
if (bash_readline_initialized == 0)
|
||||
initialize_readline ();
|
||||
|
||||
begin_unwind_frame ("bind_builtin");
|
||||
unwind_protect_var (rl_outstream);
|
||||
|
||||
rl_outstream = stdout;
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "lvpVPsSXf:q:u:m:r:x:")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'l':
|
||||
flags |= LFLAG;
|
||||
break;
|
||||
case 'v':
|
||||
flags |= VFLAG;
|
||||
break;
|
||||
case 'p':
|
||||
flags |= PFLAG;
|
||||
break;
|
||||
case 'f':
|
||||
flags |= FFLAG;
|
||||
initfile = list_optarg;
|
||||
break;
|
||||
case 'm':
|
||||
flags |= MFLAG;
|
||||
map_name = list_optarg;
|
||||
break;
|
||||
case 'q':
|
||||
flags |= QFLAG;
|
||||
fun_name = list_optarg;
|
||||
break;
|
||||
case 'u':
|
||||
flags |= UFLAG;
|
||||
unbind_name = list_optarg;
|
||||
break;
|
||||
case 'r':
|
||||
flags |= RFLAG;
|
||||
remove_seq = list_optarg;
|
||||
break;
|
||||
case 'V':
|
||||
flags |= VVFLAG;
|
||||
break;
|
||||
case 'P':
|
||||
flags |= PPFLAG;
|
||||
break;
|
||||
case 's':
|
||||
flags |= SFLAG;
|
||||
break;
|
||||
case 'S':
|
||||
flags |= SSFLAG;
|
||||
break;
|
||||
case 'x':
|
||||
flags |= XFLAG;
|
||||
cmd_seq = list_optarg;
|
||||
break;
|
||||
case 'X':
|
||||
flags |= XXFLAG;
|
||||
break;
|
||||
case GETOPT_HELP:
|
||||
default:
|
||||
builtin_usage ();
|
||||
BIND_RETURN (EX_USAGE);
|
||||
}
|
||||
}
|
||||
|
||||
list = loptend;
|
||||
|
||||
/* First, see if we need to install a special keymap for this
|
||||
command. Then start on the arguments. */
|
||||
|
||||
if ((flags & MFLAG) && map_name)
|
||||
{
|
||||
kmap = rl_get_keymap_by_name (map_name);
|
||||
if (kmap == 0)
|
||||
{
|
||||
builtin_error (_("`%s': invalid keymap name"), map_name);
|
||||
BIND_RETURN (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (kmap)
|
||||
{
|
||||
saved_keymap = rl_get_keymap ();
|
||||
rl_set_keymap (kmap);
|
||||
}
|
||||
|
||||
/* XXX - we need to add exclusive use tests here. It doesn't make sense
|
||||
to use some of these options together. */
|
||||
/* Now hack the option arguments */
|
||||
if (flags & LFLAG)
|
||||
rl_list_funmap_names ();
|
||||
|
||||
if (flags & PFLAG)
|
||||
rl_function_dumper (1);
|
||||
|
||||
if (flags & PPFLAG)
|
||||
rl_function_dumper (0);
|
||||
|
||||
if (flags & SFLAG)
|
||||
rl_macro_dumper (1);
|
||||
|
||||
if (flags & SSFLAG)
|
||||
rl_macro_dumper (0);
|
||||
|
||||
if (flags & VFLAG)
|
||||
rl_variable_dumper (1);
|
||||
|
||||
if (flags & VVFLAG)
|
||||
rl_variable_dumper (0);
|
||||
|
||||
if ((flags & FFLAG) && initfile)
|
||||
{
|
||||
if (rl_read_init_file (initfile) != 0)
|
||||
{
|
||||
t = printable_filename (initfile, 0);
|
||||
builtin_error (_("%s: cannot read: %s"), t, strerror (errno));
|
||||
if (t != initfile)
|
||||
free (t);
|
||||
BIND_RETURN (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if ((flags & QFLAG) && fun_name)
|
||||
return_code = query_bindings (fun_name);
|
||||
|
||||
if ((flags & UFLAG) && unbind_name)
|
||||
return_code = unbind_command (unbind_name);
|
||||
|
||||
if ((flags & RFLAG) && remove_seq)
|
||||
{
|
||||
opt = unbind_keyseq (remove_seq);
|
||||
BIND_RETURN (opt);
|
||||
}
|
||||
|
||||
if (flags & XFLAG)
|
||||
return_code = bind_keyseq_to_unix_command (cmd_seq);
|
||||
|
||||
if (flags & XXFLAG)
|
||||
return_code = print_unix_command_map ();
|
||||
|
||||
/* Process the rest of the arguments as binding specifications. */
|
||||
while (list)
|
||||
{
|
||||
int olen, nlen, d, i;
|
||||
char **obindings, **nbindings;
|
||||
|
||||
obindings = rl_invoking_keyseqs (bash_execute_unix_command);
|
||||
olen = obindings ? strvec_len (obindings) : 0;
|
||||
|
||||
rl_parse_and_bind (list->word->word);
|
||||
|
||||
nbindings = rl_invoking_keyseqs (bash_execute_unix_command);
|
||||
nlen = nbindings ? strvec_len (nbindings) : 0;
|
||||
|
||||
if (nlen < olen) /* fewer bind -x bindings */
|
||||
for (d = olen - nlen, i = 0; i < olen && d > 0; i++)
|
||||
if (nlen == 0 || strvec_search (nbindings, obindings[i]) < 0)
|
||||
{
|
||||
unbind_unix_command (obindings[i]);
|
||||
d--;
|
||||
}
|
||||
|
||||
strvec_dispose (obindings);
|
||||
strvec_dispose (nbindings);
|
||||
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
bind_exit:
|
||||
if (saved_keymap)
|
||||
rl_set_keymap (saved_keymap);
|
||||
|
||||
run_unwind_frame ("bind_builtin");
|
||||
|
||||
if (return_code < 0)
|
||||
return_code = EXECUTION_FAILURE;
|
||||
|
||||
return (sh_chkwrite (return_code));
|
||||
}
|
||||
|
||||
static int
|
||||
query_bindings (name)
|
||||
char *name;
|
||||
{
|
||||
rl_command_func_t *function;
|
||||
char **keyseqs;
|
||||
int j;
|
||||
|
||||
function = rl_named_function (name);
|
||||
if (function == 0)
|
||||
{
|
||||
builtin_error (_("`%s': unknown function name"), name);
|
||||
return EXECUTION_FAILURE;
|
||||
}
|
||||
|
||||
keyseqs = rl_invoking_keyseqs (function);
|
||||
|
||||
if (!keyseqs)
|
||||
{
|
||||
printf (_("%s is not bound to any keys.\n"), name);
|
||||
return EXECUTION_FAILURE;
|
||||
}
|
||||
|
||||
printf (_("%s can be invoked via "), name);
|
||||
for (j = 0; j < 5 && keyseqs[j]; j++)
|
||||
printf ("\"%s\"%s", keyseqs[j], keyseqs[j + 1] ? ", " : ".\n");
|
||||
if (keyseqs[j])
|
||||
printf ("...\n");
|
||||
strvec_dispose (keyseqs);
|
||||
return EXECUTION_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
unbind_command (name)
|
||||
char *name;
|
||||
{
|
||||
rl_command_func_t *function;
|
||||
|
||||
function = rl_named_function (name);
|
||||
if (function == 0)
|
||||
{
|
||||
builtin_error (_("`%s': unknown function name"), name);
|
||||
return EXECUTION_FAILURE;
|
||||
}
|
||||
|
||||
rl_unbind_function_in_map (function, rl_get_keymap ());
|
||||
return EXECUTION_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
unbind_keyseq (seq)
|
||||
char *seq;
|
||||
{
|
||||
char *kseq;
|
||||
int kslen, type;
|
||||
rl_command_func_t *f;
|
||||
|
||||
kseq = (char *)xmalloc ((2 * strlen (seq)) + 1);
|
||||
if (rl_translate_keyseq (seq, kseq, &kslen))
|
||||
{
|
||||
free (kseq);
|
||||
builtin_error (_("`%s': cannot unbind"), seq);
|
||||
return EXECUTION_FAILURE;
|
||||
}
|
||||
if ((f = rl_function_of_keyseq_len (kseq, kslen, (Keymap)0, &type)) == 0)
|
||||
{
|
||||
free (kseq);
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
if (type == ISKMAP)
|
||||
f = ((Keymap) f)[ANYOTHERKEY].function;
|
||||
|
||||
/* I wish this didn't have to translate the key sequence again, but readline
|
||||
doesn't have a binding function that takes a translated key sequence as
|
||||
an argument. */
|
||||
if (rl_bind_keyseq (seq, (rl_command_func_t *)NULL) != 0)
|
||||
{
|
||||
free (kseq);
|
||||
builtin_error (_("`%s': cannot unbind"), seq);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (f == bash_execute_unix_command)
|
||||
unbind_unix_command (seq);
|
||||
|
||||
free (kseq);
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
#endif /* READLINE */
|
143
builtins/break.def
Normal file
143
builtins/break.def
Normal file
|
@ -0,0 +1,143 @@
|
|||
This file is break.def, from which is created break.c.
|
||||
It implements the builtins "break" and "continue" in Bash.
|
||||
|
||||
Copyright (C) 1987-2020 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 break.c
|
||||
|
||||
$BUILTIN break
|
||||
$FUNCTION break_builtin
|
||||
$SHORT_DOC break [n]
|
||||
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>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "common.h"
|
||||
|
||||
static int check_loop_level PARAMS((void));
|
||||
|
||||
/* The depth of while's and until's. */
|
||||
int loop_level = 0;
|
||||
|
||||
/* Non-zero when a "break" instruction is encountered. */
|
||||
int breaking = 0;
|
||||
|
||||
/* Non-zero when we have encountered a continue instruction. */
|
||||
int continuing = 0;
|
||||
|
||||
/* Set up to break x levels, where x defaults to 1, but can be specified
|
||||
as the first argument. */
|
||||
int
|
||||
break_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
intmax_t newbreak;
|
||||
|
||||
CHECK_HELPOPT (list);
|
||||
|
||||
if (check_loop_level () == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
(void)get_numeric_arg (list, 1, &newbreak);
|
||||
|
||||
if (newbreak <= 0)
|
||||
{
|
||||
sh_erange (list->word->word, _("loop count"));
|
||||
breaking = loop_level;
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (newbreak > loop_level)
|
||||
newbreak = loop_level;
|
||||
|
||||
breaking = newbreak;
|
||||
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
$BUILTIN continue
|
||||
$FUNCTION continue_builtin
|
||||
$SHORT_DOC continue [n]
|
||||
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
|
||||
as the first argument. */
|
||||
int
|
||||
continue_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
intmax_t newcont;
|
||||
|
||||
CHECK_HELPOPT (list);
|
||||
|
||||
if (check_loop_level () == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
(void)get_numeric_arg (list, 1, &newcont);
|
||||
|
||||
if (newcont <= 0)
|
||||
{
|
||||
sh_erange (list->word->word, _("loop count"));
|
||||
breaking = loop_level;
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (newcont > loop_level)
|
||||
newcont = loop_level;
|
||||
|
||||
continuing = newcont;
|
||||
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
/* Return non-zero if a break or continue command would be okay.
|
||||
Print an error message if break or continue is meaningless here. */
|
||||
static int
|
||||
check_loop_level ()
|
||||
{
|
||||
#if defined (BREAK_COMPLAINS)
|
||||
if (loop_level == 0 && posixly_correct == 0)
|
||||
builtin_error (_("only meaningful in a `for', `while', or `until' loop"));
|
||||
#endif /* BREAK_COMPLAINS */
|
||||
|
||||
return (loop_level);
|
||||
}
|
85
builtins/builtin.def
Normal file
85
builtins/builtin.def
Normal file
|
@ -0,0 +1,85 @@
|
|||
This file is builtin.def, from which is created builtin.c.
|
||||
It implements the builtin "builtin" in Bash.
|
||||
|
||||
Copyright (C) 1987-2017 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 builtin.c
|
||||
|
||||
$BUILTIN builtin
|
||||
$FUNCTION builtin_builtin
|
||||
$SHORT_DOC builtin [shell-builtin [arg ...]]
|
||||
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>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
/* Run the command mentioned in list directly, without going through the
|
||||
normal alias/function/builtin/filename lookup process. */
|
||||
int
|
||||
builtin_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
sh_builtin_func_t *function;
|
||||
register char *command;
|
||||
|
||||
if (no_options (list))
|
||||
return (EX_USAGE);
|
||||
list = loptend; /* skip over possible `--' */
|
||||
|
||||
if (list == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
command = list->word->word;
|
||||
#if defined (DISABLED_BUILTINS)
|
||||
function = builtin_address (command);
|
||||
#else /* !DISABLED_BUILTINS */
|
||||
function = find_shell_builtin (command);
|
||||
#endif /* !DISABLED_BUILTINS */
|
||||
|
||||
if (function == 0)
|
||||
{
|
||||
sh_notbuiltin (command);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else
|
||||
{
|
||||
this_command_name = command;
|
||||
this_shell_builtin = function; /* overwrite "builtin" as this builtin */
|
||||
list = list->next;
|
||||
return ((*function) (list));
|
||||
}
|
||||
}
|
156
builtins/caller.def
Normal file
156
builtins/caller.def
Normal file
|
@ -0,0 +1,156 @@
|
|||
This file is caller.def, from which is created caller.c. It implements the
|
||||
builtin "caller" in Bash.
|
||||
|
||||
Copyright (C) 2002-2008 Rocky Bernstein for Free Software Foundation, Inc.
|
||||
Copyright (C) 2008-2019 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 caller.c
|
||||
|
||||
$BUILTIN caller
|
||||
$FUNCTION caller_builtin
|
||||
$DEPENDS_ON DEBUGGER
|
||||
$SHORT_DOC caller [expr]
|
||||
Return 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.
|
||||
|
||||
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>
|
||||
#include <stdio.h>
|
||||
#include "chartypes.h"
|
||||
#include "bashtypes.h"
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "common.h"
|
||||
#include "builtext.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
#ifdef LOADABLE_BUILTIN
|
||||
# include "builtins.h"
|
||||
#endif
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif /* !errno */
|
||||
|
||||
int
|
||||
caller_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
#if !defined (ARRAY_VARS)
|
||||
printf ("1 NULL\n");
|
||||
return (EXECUTION_FAILURE);
|
||||
#else
|
||||
SHELL_VAR *funcname_v, *bash_source_v, *bash_lineno_v;
|
||||
ARRAY *funcname_a, *bash_source_a, *bash_lineno_a;
|
||||
char *funcname_s, *source_s, *lineno_s;
|
||||
intmax_t num;
|
||||
|
||||
CHECK_HELPOPT (list);
|
||||
|
||||
GET_ARRAY_FROM_VAR ("FUNCNAME", funcname_v, funcname_a);
|
||||
GET_ARRAY_FROM_VAR ("BASH_SOURCE", bash_source_v, bash_source_a);
|
||||
GET_ARRAY_FROM_VAR ("BASH_LINENO", bash_lineno_v, bash_lineno_a);
|
||||
|
||||
if (bash_lineno_a == 0 || array_empty (bash_lineno_a))
|
||||
return (EXECUTION_FAILURE);
|
||||
|
||||
if (bash_source_a == 0 || array_empty (bash_source_a))
|
||||
return (EXECUTION_FAILURE);
|
||||
|
||||
if (no_options (list))
|
||||
return (EX_USAGE);
|
||||
list = loptend; /* skip over possible `--' */
|
||||
|
||||
/* If there is no argument list, then give short form: line filename. */
|
||||
if (list == 0)
|
||||
{
|
||||
lineno_s = array_reference (bash_lineno_a, 0);
|
||||
source_s = array_reference (bash_source_a, 1);
|
||||
printf("%s %s\n", lineno_s ? lineno_s : "NULL", source_s ? source_s : "NULL");
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
if (funcname_a == 0 || array_empty (funcname_a))
|
||||
return (EXECUTION_FAILURE);
|
||||
|
||||
if (legal_number (list->word->word, &num))
|
||||
{
|
||||
lineno_s = array_reference (bash_lineno_a, num);
|
||||
source_s = array_reference (bash_source_a, num+1);
|
||||
funcname_s = array_reference (funcname_a, num+1);
|
||||
|
||||
if (lineno_s == NULL|| source_s == NULL || funcname_s == NULL)
|
||||
return (EXECUTION_FAILURE);
|
||||
|
||||
printf("%s %s %s\n", lineno_s, funcname_s, source_s);
|
||||
}
|
||||
else
|
||||
{
|
||||
sh_invalidnum (list->word->word);
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
return (EXECUTION_SUCCESS);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef LOADABLE_BUILTIN
|
||||
static char *caller_doc[] = {
|
||||
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
|
||||
};
|
||||
|
||||
struct builtin caller_struct = {
|
||||
"caller",
|
||||
caller_builtin,
|
||||
BUILTIN_ENABLED,
|
||||
caller_doc,
|
||||
"caller [EXPR]",
|
||||
0
|
||||
};
|
||||
|
||||
#endif /* LOADABLE_BUILTIN */
|
685
builtins/cd.def
Normal file
685
builtins/cd.def
Normal file
|
@ -0,0 +1,685 @@
|
|||
This file is cd.def, from which is created cd.c. It implements the
|
||||
builtins "cd" and "pwd" in Bash.
|
||||
|
||||
Copyright (C) 1987-2022 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 cd.c
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashtypes.h"
|
||||
#include "posixdir.h"
|
||||
#include "posixstat.h"
|
||||
#if defined (HAVE_SYS_PARAM_H)
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <tilde/tilde.h>
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../flags.h"
|
||||
#include "maxpath.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif /* !errno */
|
||||
|
||||
extern const char * const bash_getcwd_errstr;
|
||||
|
||||
static int bindpwd PARAMS((int));
|
||||
static int setpwd PARAMS((char *));
|
||||
static char *resetpwd PARAMS((char *));
|
||||
static int change_to_directory PARAMS((char *, int, int));
|
||||
|
||||
static int cdxattr PARAMS((char *, char **));
|
||||
static void resetxattr PARAMS((void));
|
||||
|
||||
/* Change this to 1 to get cd spelling correction by default. */
|
||||
int cdspelling = 0;
|
||||
|
||||
int cdable_vars;
|
||||
|
||||
static int eflag; /* file scope so bindpwd() can see it */
|
||||
static int xattrflag; /* O_XATTR support for openat */
|
||||
static int xattrfd = -1;
|
||||
|
||||
$BUILTIN cd
|
||||
$FUNCTION cd_builtin
|
||||
$SHORT_DOC cd [-L|[-P [-e]] [-@]] [dir]
|
||||
Change the shell working directory.
|
||||
|
||||
Change the current directory to DIR. The default DIR is the value of the
|
||||
HOME shell variable. If DIR is "-", it is converted to $OLDPWD.
|
||||
|
||||
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: resolve symbolic
|
||||
links in DIR after processing instances of `..'
|
||||
-P use the physical directory structure without following
|
||||
symbolic links: resolve symbolic links in DIR before
|
||||
processing instances of `..'
|
||||
-e if the -P option is supplied, and the current working
|
||||
directory cannot be determined successfully, exit with
|
||||
a non-zero status
|
||||
#if defined (O_XATTR)
|
||||
-@ on systems that support it, present a file with extended
|
||||
attributes as a directory containing the file attributes
|
||||
#endif
|
||||
|
||||
The default is to follow symbolic links, as if `-L' were specified.
|
||||
`..' is processed by removing the immediately previous pathname component
|
||||
back to a slash or the beginning of DIR.
|
||||
|
||||
Exit Status:
|
||||
Returns 0 if the directory is changed, and if $PWD is set successfully when
|
||||
-P is used; non-zero otherwise.
|
||||
$END
|
||||
|
||||
/* Just set $PWD, don't change OLDPWD. Used by `pwd -P' in posix mode. */
|
||||
static int
|
||||
setpwd (dirname)
|
||||
char *dirname;
|
||||
{
|
||||
int old_anm;
|
||||
SHELL_VAR *tvar;
|
||||
|
||||
old_anm = array_needs_making;
|
||||
tvar = bind_variable ("PWD", dirname ? dirname : "", 0);
|
||||
if (tvar && readonly_p (tvar))
|
||||
return EXECUTION_FAILURE;
|
||||
if (tvar && old_anm == 0 && array_needs_making && exported_p (tvar))
|
||||
{
|
||||
update_export_env_inplace ("PWD=", 4, dirname ? dirname : "");
|
||||
array_needs_making = 0;
|
||||
}
|
||||
return EXECUTION_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
bindpwd (no_symlinks)
|
||||
int no_symlinks;
|
||||
{
|
||||
char *dirname, *pwdvar;
|
||||
int old_anm, r, canon_failed;
|
||||
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");
|
||||
#undef tcwd
|
||||
|
||||
/* If canonicalization fails, reset dirname to the_current_working_directory */
|
||||
canon_failed = 0;
|
||||
if (dirname == 0)
|
||||
{
|
||||
canon_failed = 1;
|
||||
dirname = the_current_working_directory;
|
||||
}
|
||||
|
||||
old_anm = array_needs_making;
|
||||
pwdvar = get_string_value ("PWD");
|
||||
|
||||
tvar = bind_variable ("OLDPWD", pwdvar, 0);
|
||||
if (tvar && readonly_p (tvar))
|
||||
r = EXECUTION_FAILURE;
|
||||
|
||||
if (old_anm == 0 && array_needs_making && exported_p (tvar))
|
||||
{
|
||||
update_export_env_inplace ("OLDPWD=", 7, pwdvar);
|
||||
array_needs_making = 0;
|
||||
}
|
||||
|
||||
if (setpwd (dirname) == EXECUTION_FAILURE)
|
||||
r = EXECUTION_FAILURE;
|
||||
if (canon_failed && eflag)
|
||||
r = EXECUTION_FAILURE;
|
||||
|
||||
if (dirname && dirname != the_current_working_directory)
|
||||
free (dirname);
|
||||
|
||||
return (r);
|
||||
}
|
||||
|
||||
/* Call get_working_directory to reset the value of
|
||||
the_current_working_directory () */
|
||||
static char *
|
||||
resetpwd (caller)
|
||||
char *caller;
|
||||
{
|
||||
char *tdir;
|
||||
|
||||
FREE (the_current_working_directory);
|
||||
the_current_working_directory = (char *)NULL;
|
||||
tdir = get_working_directory (caller);
|
||||
return (tdir);
|
||||
}
|
||||
|
||||
static int
|
||||
cdxattr (dir, ndirp)
|
||||
char *dir; /* don't assume we can always free DIR */
|
||||
char **ndirp; /* return new constructed directory name */
|
||||
{
|
||||
#if defined (O_XATTR)
|
||||
int apfd, fd, r, e;
|
||||
char buf[11+40+40]; /* construct new `fake' path for pwd */
|
||||
|
||||
apfd = openat (AT_FDCWD, dir, O_RDONLY|O_NONBLOCK);
|
||||
if (apfd < 0)
|
||||
return -1;
|
||||
fd = openat (apfd, ".", O_XATTR);
|
||||
e = errno;
|
||||
close (apfd); /* ignore close error for now */
|
||||
errno = e;
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
r = fchdir (fd); /* assume fchdir exists everywhere with O_XATTR */
|
||||
if (r < 0)
|
||||
{
|
||||
close (fd);
|
||||
return -1;
|
||||
}
|
||||
/* NFSv4 and ZFS extended attribute directories do not have names which are
|
||||
visible in the standard Unix directory tree structure. To ensure we have
|
||||
a valid name for $PWD, we synthesize one under /proc, but to keep that
|
||||
path valid, we need to keep the file descriptor open as long as we are in
|
||||
this directory. This imposes a certain structure on /proc. */
|
||||
if (ndirp)
|
||||
{
|
||||
sprintf (buf, "/proc/%d/fd/%d", getpid(), fd);
|
||||
*ndirp = savestring (buf);
|
||||
}
|
||||
|
||||
if (xattrfd >= 0)
|
||||
close (xattrfd);
|
||||
xattrfd = fd;
|
||||
|
||||
return r;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Clean up the O_XATTR baggage. Currently only closes xattrfd */
|
||||
static void
|
||||
resetxattr ()
|
||||
{
|
||||
#if defined (O_XATTR)
|
||||
if (xattrfd >= 0)
|
||||
{
|
||||
close (xattrfd);
|
||||
xattrfd = -1;
|
||||
}
|
||||
#else
|
||||
xattrfd = -1; /* not strictly necessary */
|
||||
#endif
|
||||
}
|
||||
|
||||
#define LCD_DOVARS 0x001
|
||||
#define LCD_DOSPELL 0x002
|
||||
#define LCD_PRINTPATH 0x004
|
||||
#define LCD_FREEDIRNAME 0x008
|
||||
|
||||
/* This builtin is ultimately the way that all user-visible commands should
|
||||
change the current working directory. It is called by cd_to_string (),
|
||||
so the programming interface is simple, and it handles errors and
|
||||
restrictions properly. */
|
||||
int
|
||||
cd_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
char *dirname, *cdpath, *path, *temp;
|
||||
int path_index, no_symlinks, opt, lflag, e;
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
if (restricted)
|
||||
{
|
||||
sh_restricted ((char *)NULL);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
#endif /* RESTRICTED_SHELL */
|
||||
|
||||
eflag = 0;
|
||||
no_symlinks = no_symbolic_links;
|
||||
xattrflag = 0;
|
||||
reset_internal_getopt ();
|
||||
#if defined (O_XATTR)
|
||||
while ((opt = internal_getopt (list, "eLP@")) != -1)
|
||||
#else
|
||||
while ((opt = internal_getopt (list, "eLP")) != -1)
|
||||
#endif
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'P':
|
||||
no_symlinks = 1;
|
||||
break;
|
||||
case 'L':
|
||||
no_symlinks = 0;
|
||||
break;
|
||||
case 'e':
|
||||
eflag = 1;
|
||||
break;
|
||||
#if defined (O_XATTR)
|
||||
case '@':
|
||||
xattrflag = 1;
|
||||
break;
|
||||
#endif
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
lflag = (cdable_vars ? LCD_DOVARS : 0) |
|
||||
((interactive && cdspelling) ? LCD_DOSPELL : 0);
|
||||
if (eflag && no_symlinks == 0)
|
||||
eflag = 0;
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
/* `cd' without arguments is equivalent to `cd $HOME' */
|
||||
dirname = get_string_value ("HOME");
|
||||
|
||||
if (dirname == 0)
|
||||
{
|
||||
builtin_error (_("HOME not set"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
lflag = 0;
|
||||
}
|
||||
#if defined (CD_COMPLAINS)
|
||||
else if (list->next)
|
||||
{
|
||||
builtin_error (_("too many arguments"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
#endif
|
||||
#if 0
|
||||
else if (list->word->word[0] == '\0')
|
||||
{
|
||||
builtin_error (_("null directory"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
#endif
|
||||
else if (list->word->word[0] == '-' && list->word->word[1] == '\0')
|
||||
{
|
||||
/* This is `cd -', equivalent to `cd $OLDPWD' */
|
||||
dirname = get_string_value ("OLDPWD");
|
||||
|
||||
if (dirname == 0)
|
||||
{
|
||||
builtin_error (_("OLDPWD not set"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
#if 0
|
||||
lflag = interactive ? LCD_PRINTPATH : 0;
|
||||
#else
|
||||
lflag = LCD_PRINTPATH; /* According to SUSv3 */
|
||||
#endif
|
||||
}
|
||||
else if (absolute_pathname (list->word->word))
|
||||
dirname = list->word->word;
|
||||
else if (privileged_mode == 0 && (cdpath = get_string_value ("CDPATH")))
|
||||
{
|
||||
dirname = list->word->word;
|
||||
|
||||
/* Find directory in $CDPATH. */
|
||||
path_index = 0;
|
||||
while (path = extract_colon_unit (cdpath, &path_index))
|
||||
{
|
||||
/* OPT is 1 if the path element is non-empty */
|
||||
opt = path[0] != '\0';
|
||||
temp = sh_makepath (path, dirname, MP_DOTILDE);
|
||||
free (path);
|
||||
|
||||
if (change_to_directory (temp, no_symlinks, xattrflag))
|
||||
{
|
||||
/* POSIX.2 says that if a nonempty directory from CDPATH
|
||||
is used to find the directory to change to, the new
|
||||
directory name is echoed to stdout, whether or not
|
||||
the shell is interactive. */
|
||||
if (opt && (path = no_symlinks ? temp : the_current_working_directory))
|
||||
printf ("%s\n", path);
|
||||
|
||||
free (temp);
|
||||
#if 0
|
||||
/* Posix.2 says that after using CDPATH, the resultant
|
||||
value of $PWD will not contain `.' or `..'. */
|
||||
return (bindpwd (posixly_correct || no_symlinks));
|
||||
#else
|
||||
return (bindpwd (no_symlinks));
|
||||
#endif
|
||||
}
|
||||
else
|
||||
free (temp);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* changed for bash-4.2 Posix cd description steps 5-6 */
|
||||
/* POSIX.2 says that if `.' does not appear in $CDPATH, we don't
|
||||
try the current directory, so we just punt now with an error
|
||||
message if POSIXLY_CORRECT is non-zero. The check for cdpath[0]
|
||||
is so we don't mistakenly treat a CDPATH value of "" as not
|
||||
specifying the current directory. */
|
||||
if (posixly_correct && cdpath[0])
|
||||
{
|
||||
builtin_error ("%s: %s", dirname, strerror (ENOENT));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
dirname = list->word->word;
|
||||
|
||||
/* When we get here, DIRNAME is the directory to change to. If we
|
||||
chdir successfully, just return. */
|
||||
if (change_to_directory (dirname, no_symlinks, xattrflag))
|
||||
{
|
||||
if (lflag & LCD_PRINTPATH)
|
||||
printf ("%s\n", dirname);
|
||||
return (bindpwd (no_symlinks));
|
||||
}
|
||||
|
||||
/* If the user requests it, then perhaps this is the name of
|
||||
a shell variable, whose value contains the directory to
|
||||
change to. */
|
||||
if (lflag & LCD_DOVARS)
|
||||
{
|
||||
temp = get_string_value (dirname);
|
||||
if (temp && change_to_directory (temp, no_symlinks, xattrflag))
|
||||
{
|
||||
printf ("%s\n", temp);
|
||||
return (bindpwd (no_symlinks));
|
||||
}
|
||||
}
|
||||
|
||||
/* If the user requests it, try to find a directory name similar in
|
||||
spelling to the one requested, in case the user made a simple
|
||||
typo. This is similar to the UNIX 8th and 9th Edition shells. */
|
||||
if (lflag & LCD_DOSPELL)
|
||||
{
|
||||
temp = dirspell (dirname);
|
||||
if (temp && change_to_directory (temp, no_symlinks, xattrflag))
|
||||
{
|
||||
printf ("%s\n", temp);
|
||||
free (temp);
|
||||
return (bindpwd (no_symlinks));
|
||||
}
|
||||
else
|
||||
FREE (temp);
|
||||
}
|
||||
|
||||
e = errno;
|
||||
temp = printable_filename (dirname, 0);
|
||||
builtin_error ("%s: %s", temp, strerror (e));
|
||||
if (temp != dirname)
|
||||
free (temp);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
$BUILTIN pwd
|
||||
$FUNCTION pwd_builtin
|
||||
$SHORT_DOC pwd [-LP]
|
||||
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
|
||||
symbolic links. */
|
||||
static int verbatim_pwd;
|
||||
|
||||
/* Print the name of the current working directory. */
|
||||
int
|
||||
pwd_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
char *directory;
|
||||
int opt, pflag;
|
||||
|
||||
verbatim_pwd = no_symbolic_links;
|
||||
pflag = 0;
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "LP")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'P':
|
||||
verbatim_pwd = pflag = 1;
|
||||
break;
|
||||
case 'L':
|
||||
verbatim_pwd = 0;
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
#define tcwd the_current_working_directory
|
||||
|
||||
directory = tcwd ? (verbatim_pwd ? sh_physpath (tcwd, 0) : tcwd)
|
||||
: get_working_directory ("pwd");
|
||||
|
||||
/* Try again using getcwd() if canonicalization fails (for instance, if
|
||||
the file system has changed state underneath bash). */
|
||||
if ((tcwd && directory == 0) ||
|
||||
(posixly_correct && same_file (".", tcwd, (struct stat *)0, (struct stat *)0) == 0))
|
||||
{
|
||||
if (directory && directory != tcwd)
|
||||
free (directory);
|
||||
directory = resetpwd ("pwd");
|
||||
}
|
||||
|
||||
#undef tcwd
|
||||
|
||||
if (directory)
|
||||
{
|
||||
opt = EXECUTION_SUCCESS;
|
||||
printf ("%s\n", directory);
|
||||
/* This is dumb but posix-mandated. */
|
||||
if (posixly_correct && pflag)
|
||||
opt = setpwd (directory);
|
||||
if (directory != the_current_working_directory)
|
||||
free (directory);
|
||||
return (sh_chkwrite (opt));
|
||||
}
|
||||
else
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
/* Do the work of changing to the directory NEWDIR. Handle symbolic
|
||||
link following, etc. This function *must* return with
|
||||
the_current_working_directory either set to NULL (in which case
|
||||
getcwd() will eventually be called), or set to a string corresponding
|
||||
to the working directory. Return 1 on success, 0 on failure. */
|
||||
|
||||
static int
|
||||
change_to_directory (newdir, nolinks, xattr)
|
||||
char *newdir;
|
||||
int nolinks, xattr;
|
||||
{
|
||||
char *t, *tdir, *ndir;
|
||||
int err, canon_failed, r, ndlen;
|
||||
|
||||
tdir = (char *)NULL;
|
||||
|
||||
if (the_current_working_directory == 0)
|
||||
{
|
||||
t = get_working_directory ("chdir");
|
||||
FREE (t);
|
||||
}
|
||||
|
||||
t = make_absolute (newdir, the_current_working_directory);
|
||||
|
||||
/* TDIR is either the canonicalized absolute pathname of NEWDIR
|
||||
(nolinks == 0) or the absolute physical pathname of NEWDIR
|
||||
(nolinks != 0). */
|
||||
tdir = nolinks ? sh_physpath (t, 0)
|
||||
: sh_canonpath (t, PATH_CHECKDOTDOT|PATH_CHECKEXISTS);
|
||||
|
||||
ndlen = strlen (newdir);
|
||||
|
||||
/* Use the canonicalized version of NEWDIR, or, if canonicalization
|
||||
failed, use the non-canonical form. */
|
||||
canon_failed = 0;
|
||||
if (tdir && *tdir)
|
||||
free (t);
|
||||
else
|
||||
{
|
||||
FREE (tdir);
|
||||
tdir = t;
|
||||
canon_failed = 1;
|
||||
}
|
||||
|
||||
/* In POSIX mode, if we're resolving symlinks logically and sh_canonpath
|
||||
returns NULL (because it checks the path, it will return NULL if the
|
||||
resolved path doesn't exist), fail immediately. */
|
||||
#if defined (ENAMETOOLONG)
|
||||
if (posixly_correct && nolinks == 0 && canon_failed && (errno != ENAMETOOLONG || ndlen > PATH_MAX))
|
||||
#else
|
||||
if (posixly_correct && nolinks == 0 && canon_failed && ndlen > PATH_MAX)
|
||||
#endif
|
||||
{
|
||||
#if defined ENAMETOOLONG
|
||||
if (errno != ENOENT && errno != ENAMETOOLONG)
|
||||
#else
|
||||
if (errno != ENOENT)
|
||||
#endif
|
||||
errno = ENOTDIR;
|
||||
free (tdir);
|
||||
return (0);
|
||||
}
|
||||
|
||||
#if defined (O_XATTR)
|
||||
if (xattrflag)
|
||||
{
|
||||
r = cdxattr (nolinks ? newdir : tdir, &ndir);
|
||||
if (r >= 0)
|
||||
{
|
||||
canon_failed = 0;
|
||||
free (tdir);
|
||||
tdir = ndir;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = errno;
|
||||
free (tdir);
|
||||
errno = err;
|
||||
return (0); /* no xattr */
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
r = chdir (nolinks ? newdir : tdir);
|
||||
if (r >= 0)
|
||||
resetxattr ();
|
||||
}
|
||||
|
||||
/* If the chdir succeeds, update the_current_working_directory. */
|
||||
if (r == 0)
|
||||
{
|
||||
/* If canonicalization failed, but the chdir succeeded, reset the
|
||||
shell's idea of the_current_working_directory. */
|
||||
if (canon_failed)
|
||||
{
|
||||
t = resetpwd ("cd");
|
||||
if (t == 0)
|
||||
set_working_directory (tdir);
|
||||
else
|
||||
free (t);
|
||||
}
|
||||
else
|
||||
set_working_directory (tdir);
|
||||
|
||||
free (tdir);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* We failed to change to the appropriate directory name. If we tried
|
||||
what the user passed (nolinks != 0), punt now. */
|
||||
if (nolinks)
|
||||
{
|
||||
free (tdir);
|
||||
return (0);
|
||||
}
|
||||
|
||||
err = errno;
|
||||
|
||||
/* We're not in physical mode (nolinks == 0), but we failed to change to
|
||||
the canonicalized directory name (TDIR). Try what the user passed
|
||||
verbatim. If we succeed, reinitialize the_current_working_directory.
|
||||
POSIX requires that we just fail here, so we do in posix mode. */
|
||||
if (posixly_correct == 0 && chdir (newdir) == 0)
|
||||
{
|
||||
t = resetpwd ("cd");
|
||||
if (t == 0)
|
||||
set_working_directory (tdir);
|
||||
else
|
||||
free (t);
|
||||
|
||||
r = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = err;
|
||||
r = 0;
|
||||
}
|
||||
|
||||
free (tdir);
|
||||
return r;
|
||||
}
|
76
builtins/colon.def
Normal file
76
builtins/colon.def
Normal file
|
@ -0,0 +1,76 @@
|
|||
This file is colon.def, from which is created colon.c.
|
||||
It implements the builtin ":" in Bash.
|
||||
|
||||
Copyright (C) 1987-2019 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 colon.c
|
||||
|
||||
$BUILTIN :
|
||||
$DOCNAME colon
|
||||
$FUNCTION colon_builtin
|
||||
$SHORT_DOC :
|
||||
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
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../shell.h"
|
||||
|
||||
/* Return a successful result. */
|
||||
int
|
||||
colon_builtin (ignore)
|
||||
WORD_LIST *ignore;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Return an unsuccessful result. */
|
||||
int
|
||||
false_builtin (ignore)
|
||||
WORD_LIST *ignore;
|
||||
{
|
||||
return (1);
|
||||
}
|
143
builtins/command.def
Normal file
143
builtins/command.def
Normal file
|
@ -0,0 +1,143 @@
|
|||
This file is command.def, from which is created command.c.
|
||||
It implements the builtin "command" in Bash.
|
||||
|
||||
Copyright (C) 1987-2020 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 command.c
|
||||
|
||||
$BUILTIN command
|
||||
$FUNCTION command_builtin
|
||||
$SHORT_DOC command [-pVv] command [arg ...]
|
||||
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>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashansi.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "../flags.h"
|
||||
#include "bashgetopt.h"
|
||||
#include "common.h"
|
||||
|
||||
#if defined (_CS_PATH) && defined (HAVE_CONFSTR) && !HAVE_DECL_CONFSTR
|
||||
extern size_t confstr PARAMS((int, char *, size_t));
|
||||
#endif
|
||||
|
||||
/* Run the commands mentioned in LIST without paying attention to shell
|
||||
functions. */
|
||||
int
|
||||
command_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int result, verbose, use_standard_path, opt;
|
||||
COMMAND *command;
|
||||
|
||||
verbose = use_standard_path = 0;
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "pvV")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'p':
|
||||
use_standard_path = CDESC_STDPATH;
|
||||
break;
|
||||
case 'V':
|
||||
verbose = CDESC_SHORTDESC|CDESC_ABSPATH; /* look in common.h for constants */
|
||||
break;
|
||||
case 'v':
|
||||
verbose = CDESC_REUSABLE; /* ditto */
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
if (list == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
if (use_standard_path && restricted)
|
||||
{
|
||||
sh_restricted ("-p");
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
int found, any_found;
|
||||
|
||||
for (any_found = 0; list; list = list->next)
|
||||
{
|
||||
found = describe_command (list->word->word, verbose|use_standard_path);
|
||||
|
||||
if (found == 0 && verbose != CDESC_REUSABLE)
|
||||
sh_notfound (list->word->word);
|
||||
|
||||
any_found += found;
|
||||
}
|
||||
|
||||
return (any_found ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
begin_unwind_frame ("command_builtin");
|
||||
|
||||
#define COMMAND_BUILTIN_FLAGS (CMD_NO_FUNCTIONS | CMD_INHIBIT_EXPANSION | CMD_COMMAND_BUILTIN | (use_standard_path ? CMD_STDPATH : 0))
|
||||
|
||||
INTERNAL_DEBUG (("command_builtin: running execute_command for `%s'", list->word->word));
|
||||
|
||||
/* We don't want this to be reparsed (consider command echo 'foo &'), so
|
||||
just make a simple_command structure and call execute_command with it. */
|
||||
command = make_bare_simple_command ();
|
||||
command->value.Simple->words = (WORD_LIST *)copy_word_list (list);
|
||||
command->value.Simple->redirects = (REDIRECT *)NULL;
|
||||
command->flags |= COMMAND_BUILTIN_FLAGS;
|
||||
command->value.Simple->flags |= COMMAND_BUILTIN_FLAGS;
|
||||
|
||||
add_unwind_protect ((char *)dispose_command, command);
|
||||
result = execute_command (command);
|
||||
|
||||
run_unwind_frame ("command_builtin");
|
||||
|
||||
return (result);
|
||||
}
|
1131
builtins/common.c
Normal file
1131
builtins/common.c
Normal file
File diff suppressed because it is too large
Load diff
289
builtins/common.h
Normal file
289
builtins/common.h
Normal file
|
@ -0,0 +1,289 @@
|
|||
/* common.h -- extern declarations for functions defined in common.c. */
|
||||
|
||||
/* Copyright (C) 1993-2022 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/>.
|
||||
*/
|
||||
|
||||
#if !defined (__COMMON_H)
|
||||
# define __COMMON_H
|
||||
|
||||
#include "stdc.h"
|
||||
|
||||
#define ISOPTION(s, c) (s[0] == '-' && s[1] == c && !s[2])
|
||||
#define ISHELP(s) (STREQ ((s), "--help"))
|
||||
|
||||
#define CHECK_HELPOPT(l) \
|
||||
do { \
|
||||
if ((l) && (l)->word && ISHELP((l)->word->word)) \
|
||||
{ \
|
||||
builtin_help (); \
|
||||
return (EX_USAGE); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CASE_HELPOPT \
|
||||
case GETOPT_HELP: \
|
||||
builtin_help (); \
|
||||
return (EX_USAGE)
|
||||
|
||||
/* Flag values for parse_and_execute () and parse_string () */
|
||||
#define SEVAL_NONINT 0x001
|
||||
#define SEVAL_INTERACT 0x002
|
||||
#define SEVAL_NOHIST 0x004
|
||||
#define SEVAL_NOFREE 0x008
|
||||
#define SEVAL_RESETLINE 0x010
|
||||
#define SEVAL_PARSEONLY 0x020
|
||||
#define SEVAL_NOLONGJMP 0x040
|
||||
#define SEVAL_FUNCDEF 0x080 /* only allow function definitions */
|
||||
#define SEVAL_ONECMD 0x100 /* only allow a single command */
|
||||
#define SEVAL_NOHISTEXP 0x200 /* inhibit history expansion */
|
||||
#define SEVAL_NOOPTIMIZE 0x400 /* don't try to set optimization flags */
|
||||
|
||||
/* Flags for describe_command, shared between type.def and command.def */
|
||||
#define CDESC_ALL 0x001 /* type -a */
|
||||
#define CDESC_SHORTDESC 0x002 /* command -V */
|
||||
#define CDESC_REUSABLE 0x004 /* command -v */
|
||||
#define CDESC_TYPE 0x008 /* type -t */
|
||||
#define CDESC_PATH_ONLY 0x010 /* type -p */
|
||||
#define CDESC_FORCE_PATH 0x020 /* type -ap or type -P */
|
||||
#define CDESC_NOFUNCS 0x040 /* type -f */
|
||||
#define CDESC_ABSPATH 0x080 /* convert to absolute path, no ./ */
|
||||
#define CDESC_STDPATH 0x100 /* command -p */
|
||||
|
||||
/* Flags for get_job_by_name */
|
||||
#define JM_PREFIX 0x01 /* prefix of job name */
|
||||
#define JM_SUBSTRING 0x02 /* substring of job name */
|
||||
#define JM_EXACT 0x04 /* match job name exactly */
|
||||
#define JM_STOPPED 0x08 /* match stopped jobs only */
|
||||
#define JM_FIRSTMATCH 0x10 /* return first matching job */
|
||||
|
||||
/* Flags for remember_args and value of changed_dollar_vars */
|
||||
#define ARGS_NONE 0x0
|
||||
#define ARGS_INVOC 0x01
|
||||
#define ARGS_FUNC 0x02
|
||||
#define ARGS_SETBLTIN 0x04
|
||||
|
||||
/* Maximum number of attribute letters */
|
||||
#define MAX_ATTRIBUTES 16
|
||||
|
||||
/* Functions from common.c */
|
||||
extern void builtin_error PARAMS((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
|
||||
extern void builtin_warning PARAMS((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
|
||||
extern void builtin_usage PARAMS((void));
|
||||
extern void no_args PARAMS((WORD_LIST *));
|
||||
extern int no_options PARAMS((WORD_LIST *));
|
||||
|
||||
/* common error message functions */
|
||||
extern void sh_needarg PARAMS((char *));
|
||||
extern void sh_neednumarg PARAMS((char *));
|
||||
extern void sh_notfound PARAMS((char *));
|
||||
extern void sh_invalidopt PARAMS((char *));
|
||||
extern void sh_invalidoptname PARAMS((char *));
|
||||
extern void sh_invalidid PARAMS((char *));
|
||||
extern void sh_invalidnum PARAMS((char *));
|
||||
extern void sh_invalidsig PARAMS((char *));
|
||||
extern void sh_readonly PARAMS((const char *));
|
||||
extern void sh_noassign PARAMS((const char *));
|
||||
extern void sh_erange PARAMS((char *, char *));
|
||||
extern void sh_badpid PARAMS((char *));
|
||||
extern void sh_badjob PARAMS((char *));
|
||||
extern void sh_nojobs PARAMS((char *));
|
||||
extern void sh_restricted PARAMS((char *));
|
||||
extern void sh_notbuiltin PARAMS((char *));
|
||||
extern void sh_wrerror PARAMS((void));
|
||||
extern void sh_ttyerror PARAMS((int));
|
||||
extern int sh_chkwrite PARAMS((int));
|
||||
|
||||
extern char **make_builtin_argv PARAMS((WORD_LIST *, int *));
|
||||
extern void remember_args PARAMS((WORD_LIST *, int));
|
||||
extern void shift_args PARAMS((int));
|
||||
extern int number_of_args PARAMS((void));
|
||||
|
||||
extern int dollar_vars_changed PARAMS((void));
|
||||
extern void set_dollar_vars_unchanged PARAMS((void));
|
||||
extern void set_dollar_vars_changed PARAMS((void));
|
||||
|
||||
extern int get_numeric_arg PARAMS((WORD_LIST *, int, intmax_t *));
|
||||
extern int get_exitstat PARAMS((WORD_LIST *));
|
||||
extern int read_octal PARAMS((char *));
|
||||
|
||||
/* Keeps track of the current working directory. */
|
||||
extern char *the_current_working_directory;
|
||||
extern char *get_working_directory PARAMS((char *));
|
||||
extern void set_working_directory PARAMS((char *));
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
extern int get_job_by_name PARAMS((const char *, int));
|
||||
extern int get_job_spec PARAMS((WORD_LIST *));
|
||||
#endif
|
||||
extern int display_signal_list PARAMS((WORD_LIST *, int));
|
||||
|
||||
/* It's OK to declare a function as returning a Function * without
|
||||
providing a definition of what a `Function' is. */
|
||||
extern struct builtin *builtin_address_internal PARAMS((char *, int));
|
||||
extern sh_builtin_func_t *find_shell_builtin PARAMS((char *));
|
||||
extern sh_builtin_func_t *builtin_address PARAMS((char *));
|
||||
extern sh_builtin_func_t *find_special_builtin PARAMS((char *));
|
||||
extern void initialize_shell_builtins PARAMS((void));
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
extern int set_expand_once PARAMS((int, int));
|
||||
#endif
|
||||
|
||||
/* Functions from exit.def */
|
||||
extern void bash_logout PARAMS((void));
|
||||
|
||||
/* Functions from getopts.def */
|
||||
extern void getopts_reset PARAMS((int));
|
||||
|
||||
/* Functions from help.def */
|
||||
extern void builtin_help PARAMS((void));
|
||||
|
||||
/* Functions from read.def */
|
||||
extern void read_tty_cleanup PARAMS((void));
|
||||
extern int read_tty_modified PARAMS((void));
|
||||
|
||||
extern int read_builtin_timeout PARAMS((int));
|
||||
extern void check_read_timeout PARAMS((void));
|
||||
|
||||
/* Functions from set.def */
|
||||
extern int minus_o_option_value PARAMS((char *));
|
||||
extern void list_minus_o_opts PARAMS((int, int));
|
||||
extern char **get_minus_o_opts PARAMS((void));
|
||||
extern int set_minus_o_option PARAMS((int, char *));
|
||||
|
||||
extern void set_shellopts PARAMS((void));
|
||||
extern void parse_shellopts PARAMS((char *));
|
||||
extern void initialize_shell_options PARAMS((int));
|
||||
|
||||
extern void reset_shell_options PARAMS((void));
|
||||
|
||||
extern char *get_current_options PARAMS((void));
|
||||
extern void set_current_options PARAMS((const char *));
|
||||
|
||||
/* Functions from shopt.def */
|
||||
extern void reset_shopt_options PARAMS((void));
|
||||
extern char **get_shopt_options PARAMS((void));
|
||||
|
||||
extern int shopt_setopt PARAMS((char *, int));
|
||||
extern int shopt_listopt PARAMS((char *, int));
|
||||
|
||||
extern int set_login_shell PARAMS((char *, int));
|
||||
|
||||
extern void set_bashopts PARAMS((void));
|
||||
extern void parse_bashopts PARAMS((char *));
|
||||
extern void initialize_bashopts PARAMS((int));
|
||||
|
||||
extern void set_compatibility_opts PARAMS((void));
|
||||
|
||||
/* Functions from type.def */
|
||||
extern int describe_command PARAMS((char *, int));
|
||||
|
||||
/* Functions from setattr.def */
|
||||
extern int set_or_show_attributes PARAMS((WORD_LIST *, int, int));
|
||||
extern int show_all_var_attributes PARAMS((int, int));
|
||||
extern int show_local_var_attributes PARAMS((int, int));
|
||||
extern int show_var_attributes PARAMS((SHELL_VAR *, int, int));
|
||||
extern int show_name_attributes PARAMS((char *, int));
|
||||
extern int show_localname_attributes PARAMS((char *, int));
|
||||
extern int show_func_attributes PARAMS((char *, int));
|
||||
extern void set_var_attribute PARAMS((char *, int, int));
|
||||
extern int var_attribute_string PARAMS((SHELL_VAR *, int, char *));
|
||||
|
||||
/* Functions from pushd.def */
|
||||
extern char *get_dirstack_from_string PARAMS((char *));
|
||||
extern char *get_dirstack_element PARAMS((intmax_t, int));
|
||||
extern void set_dirstack_element PARAMS((intmax_t, int, char *));
|
||||
extern WORD_LIST *get_directory_stack PARAMS((int));
|
||||
|
||||
/* Functions from evalstring.c */
|
||||
extern int parse_and_execute PARAMS((char *, const char *, int));
|
||||
extern int evalstring PARAMS((char *, const char *, int));
|
||||
extern void parse_and_execute_cleanup PARAMS((int));
|
||||
extern int parse_string PARAMS((char *, const char *, int, COMMAND **, char **));
|
||||
extern int should_suppress_fork PARAMS((COMMAND *));
|
||||
extern int can_optimize_connection PARAMS((COMMAND *));
|
||||
extern int can_optimize_cat_file PARAMS((COMMAND *));
|
||||
extern void optimize_connection_fork PARAMS((COMMAND *));
|
||||
extern void optimize_subshell_command PARAMS((COMMAND *));
|
||||
extern void optimize_shell_function PARAMS((COMMAND *));
|
||||
|
||||
/* Functions from evalfile.c */
|
||||
extern int maybe_execute_file PARAMS((const char *, int));
|
||||
extern int force_execute_file PARAMS((const char *, int));
|
||||
extern int source_file PARAMS((const char *, int));
|
||||
extern int fc_execute_file PARAMS((const char *));
|
||||
|
||||
/* variables from common.c */
|
||||
extern sh_builtin_func_t *this_shell_builtin;
|
||||
extern sh_builtin_func_t *last_shell_builtin;
|
||||
|
||||
extern SHELL_VAR *builtin_bind_variable PARAMS((char *, char *, int));
|
||||
extern SHELL_VAR *builtin_bind_var_to_int PARAMS((char *, intmax_t, int));
|
||||
extern int builtin_unbind_variable PARAMS((const char *));
|
||||
|
||||
extern SHELL_VAR *builtin_find_indexed_array PARAMS((char *, int));
|
||||
extern int builtin_arrayref_flags PARAMS((WORD_DESC *, int));
|
||||
|
||||
/* variables from evalfile.c */
|
||||
extern int sourcelevel;
|
||||
|
||||
/* variables from evalstring.c */
|
||||
extern int parse_and_execute_level;
|
||||
|
||||
/* variables from break.def/continue.def */
|
||||
extern int breaking;
|
||||
extern int continuing;
|
||||
extern int loop_level;
|
||||
|
||||
/* variables from shift.def */
|
||||
extern int print_shift_error;
|
||||
|
||||
/* variables from shopt.def */
|
||||
#if defined (ARRAY_VARS)
|
||||
extern int expand_once_flag;
|
||||
#endif
|
||||
|
||||
#if defined (EXTENDED_GLOB)
|
||||
extern int extglob_flag;
|
||||
#endif
|
||||
|
||||
extern int expaliases_flag;
|
||||
|
||||
/* variables from source.def */
|
||||
extern int source_searches_cwd;
|
||||
extern int source_uses_path;
|
||||
|
||||
/* variables from wait.def */
|
||||
extern int wait_intr_flag;
|
||||
|
||||
/* common code to set flags for valid_array_reference and builtin_bind_variable */
|
||||
#if defined (ARRAY_VARS)
|
||||
#define SET_VFLAGS(wordflags, vflags, bindflags) \
|
||||
do { \
|
||||
vflags = assoc_expand_once ? VA_NOEXPAND : 0; \
|
||||
bindflags = assoc_expand_once ? ASS_NOEXPAND : 0; \
|
||||
if (assoc_expand_once && (wordflags & W_ARRAYREF)) \
|
||||
vflags |= VA_ONEWORD|VA_NOEXPAND; \
|
||||
if (vflags & VA_NOEXPAND) \
|
||||
bindflags |= ASS_NOEXPAND; \
|
||||
if (vflags & VA_ONEWORD) \
|
||||
bindflags |= ASS_ONEWORD; \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#endif /* !__COMMON_H */
|
892
builtins/complete.def
Normal file
892
builtins/complete.def
Normal file
|
@ -0,0 +1,892 @@
|
|||
This file is complete.def, from which is created complete.c.
|
||||
It implements the builtins "complete", "compgen", and "compopt" in Bash.
|
||||
|
||||
Copyright (C) 1999-2021 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 complete.c
|
||||
|
||||
$BUILTIN complete
|
||||
$DEPENDS_ON PROGRAMMABLE_COMPLETION
|
||||
$FUNCTION complete_builtin
|
||||
$SHORT_DOC complete [-abcdefgjksuv] [-pr] [-DEI] [-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
|
||||
-D apply the completions and actions as the default for commands
|
||||
without any specific completion defined
|
||||
-E apply the completions and actions to "empty" commands --
|
||||
completion attempted on a blank line
|
||||
-I apply the completions and actions to the initial (usually the
|
||||
command) word
|
||||
|
||||
When completion is attempted, the actions are applied in the order the
|
||||
uppercase-letter options are listed above. If multiple options are supplied,
|
||||
the -D option takes precedence over -E, and both take precedence over -I.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is supplied or an error occurs.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../bashtypes.h"
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../builtins.h"
|
||||
#include "../pcomplete.h"
|
||||
#include "../bashline.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
#include <readline/readline.h>
|
||||
|
||||
#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 Dflag;
|
||||
int Eflag;
|
||||
int Iflag;
|
||||
};
|
||||
|
||||
static int find_compact PARAMS((char *));
|
||||
static int find_compopt PARAMS((char *));
|
||||
|
||||
static int build_actions PARAMS((WORD_LIST *, struct _optflags *, unsigned long *, unsigned long *));
|
||||
|
||||
static int remove_cmd_completions PARAMS((WORD_LIST *));
|
||||
|
||||
static int print_one_completion PARAMS((char *, COMPSPEC *));
|
||||
static int print_compitem PARAMS((BUCKET_CONTENTS *));
|
||||
static void print_compopts PARAMS((const char *, COMPSPEC *, int));
|
||||
static void print_all_completions PARAMS((void));
|
||||
static int print_cmd_completions PARAMS((WORD_LIST *));
|
||||
|
||||
static void print_compoptions PARAMS((unsigned long, int));
|
||||
static void print_compactions PARAMS((unsigned long));
|
||||
static void print_arg PARAMS((const char *, const char *, int));
|
||||
static void print_cmd_name PARAMS((const char *));
|
||||
|
||||
static char *Garg, *Warg, *Parg, *Sarg, *Xarg, *Farg, *Carg;
|
||||
|
||||
static const struct _compacts {
|
||||
const char * const actname;
|
||||
unsigned long actflag;
|
||||
int actopt;
|
||||
} compacts[] = {
|
||||
{ "alias", CA_ALIAS, 'a' },
|
||||
{ "arrayvar", CA_ARRAYVAR, 0 },
|
||||
{ "binding", CA_BINDING, 0 },
|
||||
{ "builtin", CA_BUILTIN, 'b' },
|
||||
{ "command", CA_COMMAND, 'c' },
|
||||
{ "directory", CA_DIRECTORY, 'd' },
|
||||
{ "disabled", CA_DISABLED, 0 },
|
||||
{ "enabled", CA_ENABLED, 0 },
|
||||
{ "export", CA_EXPORT, 'e' },
|
||||
{ "file", CA_FILE, 'f' },
|
||||
{ "function", CA_FUNCTION, 0 },
|
||||
{ "helptopic", CA_HELPTOPIC, 0 },
|
||||
{ "hostname", CA_HOSTNAME, 0 },
|
||||
{ "group", CA_GROUP, 'g' },
|
||||
{ "job", CA_JOB, 'j' },
|
||||
{ "keyword", CA_KEYWORD, 'k' },
|
||||
{ "running", CA_RUNNING, 0 },
|
||||
{ "service", CA_SERVICE, 's' },
|
||||
{ "setopt", CA_SETOPT, 0 },
|
||||
{ "shopt", CA_SHOPT, 0 },
|
||||
{ "signal", CA_SIGNAL, 0 },
|
||||
{ "stopped", CA_STOPPED, 0 },
|
||||
{ "user", CA_USER, 'u' },
|
||||
{ "variable", CA_VARIABLE, 'v' },
|
||||
{ (char *)NULL, 0, 0 },
|
||||
};
|
||||
|
||||
/* This should be a STRING_INT_ALIST */
|
||||
static const struct _compopt {
|
||||
const char * const optname;
|
||||
unsigned long optflag;
|
||||
} compopts[] = {
|
||||
{ "bashdefault", COPT_BASHDEFAULT },
|
||||
{ "default", COPT_DEFAULT },
|
||||
{ "dirnames", COPT_DIRNAMES },
|
||||
{ "filenames",COPT_FILENAMES},
|
||||
{ "noquote", COPT_NOQUOTE },
|
||||
{ "nosort", COPT_NOSORT },
|
||||
{ "nospace", COPT_NOSPACE },
|
||||
{ "plusdirs", COPT_PLUSDIRS },
|
||||
{ (char *)NULL, 0 },
|
||||
};
|
||||
|
||||
static int
|
||||
find_compact (name)
|
||||
char *name;
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (i = 0; compacts[i].actname; i++)
|
||||
if (STREQ (name, compacts[i].actname))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
find_compopt (name)
|
||||
char *name;
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (i = 0; compopts[i].optname; i++)
|
||||
if (STREQ (name, compopts[i].optname))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Build the actions and compspec options from the options specified in LIST.
|
||||
ACTP is a pointer to an unsigned long in which to place the bitmap of
|
||||
actions. OPTP is a pointer to an unsigned long in which to place the
|
||||
bitmap of compspec options (arguments to `-o'). PP, if non-null, gets 1
|
||||
if -p is supplied; RP, if non-null, gets 1 if -r is supplied.
|
||||
If either is null, the corresponding option generates an error.
|
||||
This also sets variables corresponding to options that take arguments as
|
||||
a side effect; the caller should ensure that those variables are set to
|
||||
NULL before calling build_actions. Return value:
|
||||
EX_USAGE = bad option
|
||||
EXECUTION_SUCCESS = some options supplied
|
||||
EXECUTION_FAILURE = no options supplied
|
||||
*/
|
||||
|
||||
static int
|
||||
build_actions (list, flagp, actp, optp)
|
||||
WORD_LIST *list;
|
||||
struct _optflags *flagp;
|
||||
unsigned long *actp, *optp;
|
||||
{
|
||||
int opt, ind, opt_given;
|
||||
unsigned long acts, copts;
|
||||
WORD_DESC w;
|
||||
|
||||
acts = copts = (unsigned long)0L;
|
||||
opt_given = 0;
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "abcdefgjko:prsuvA:G:W:P:S:X:F:C:DEI")) != -1)
|
||||
{
|
||||
opt_given = 1;
|
||||
switch (opt)
|
||||
{
|
||||
case 'r':
|
||||
if (flagp)
|
||||
{
|
||||
flagp->rflag = 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
sh_invalidopt ("-r");
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
case 'p':
|
||||
if (flagp)
|
||||
{
|
||||
flagp->pflag = 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
sh_invalidopt ("-p");
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
case 'a':
|
||||
acts |= CA_ALIAS;
|
||||
break;
|
||||
case 'b':
|
||||
acts |= CA_BUILTIN;
|
||||
break;
|
||||
case 'c':
|
||||
acts |= CA_COMMAND;
|
||||
break;
|
||||
case 'd':
|
||||
acts |= CA_DIRECTORY;
|
||||
break;
|
||||
case 'e':
|
||||
acts |= CA_EXPORT;
|
||||
break;
|
||||
case 'f':
|
||||
acts |= CA_FILE;
|
||||
break;
|
||||
case 'g':
|
||||
acts |= CA_GROUP;
|
||||
break;
|
||||
case 'j':
|
||||
acts |= CA_JOB;
|
||||
break;
|
||||
case 'k':
|
||||
acts |= CA_KEYWORD;
|
||||
break;
|
||||
case 's':
|
||||
acts |= CA_SERVICE;
|
||||
break;
|
||||
case 'u':
|
||||
acts |= CA_USER;
|
||||
break;
|
||||
case 'v':
|
||||
acts |= CA_VARIABLE;
|
||||
break;
|
||||
case 'o':
|
||||
ind = find_compopt (list_optarg);
|
||||
if (ind < 0)
|
||||
{
|
||||
sh_invalidoptname (list_optarg);
|
||||
return (EX_USAGE);
|
||||
}
|
||||
copts |= compopts[ind].optflag;
|
||||
break;
|
||||
case 'A':
|
||||
ind = find_compact (list_optarg);
|
||||
if (ind < 0)
|
||||
{
|
||||
builtin_error (_("%s: invalid action name"), list_optarg);
|
||||
return (EX_USAGE);
|
||||
}
|
||||
acts |= compacts[ind].actflag;
|
||||
break;
|
||||
case 'C':
|
||||
Carg = list_optarg;
|
||||
break;
|
||||
case 'D':
|
||||
if (flagp)
|
||||
{
|
||||
flagp->Dflag = 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
sh_invalidopt ("-D");
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
case 'E':
|
||||
if (flagp)
|
||||
{
|
||||
flagp->Eflag = 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
sh_invalidopt ("-E");
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
case 'I':
|
||||
if (flagp)
|
||||
{
|
||||
flagp->Iflag = 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
sh_invalidopt ("-I");
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
case 'F':
|
||||
w.word = Farg = list_optarg;
|
||||
w.flags = 0;
|
||||
if (check_identifier (&w, posixly_correct) == 0 || strpbrk (Farg, shell_break_chars) != 0)
|
||||
{
|
||||
sh_invalidid (Farg);
|
||||
return (EX_USAGE);
|
||||
}
|
||||
break;
|
||||
case 'G':
|
||||
Garg = list_optarg;
|
||||
break;
|
||||
case 'P':
|
||||
Parg = list_optarg;
|
||||
break;
|
||||
case 'S':
|
||||
Sarg = list_optarg;
|
||||
break;
|
||||
case 'W':
|
||||
Warg = list_optarg;
|
||||
break;
|
||||
case 'X':
|
||||
Xarg = list_optarg;
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
|
||||
*actp = acts;
|
||||
*optp = copts;
|
||||
|
||||
return (opt_given ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
/* Add, remove, and display completion specifiers. */
|
||||
int
|
||||
complete_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int opt_given, rval;
|
||||
unsigned long acts, copts;
|
||||
COMPSPEC *cs;
|
||||
struct _optflags oflags;
|
||||
WORD_LIST *l, *wl;
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
print_all_completions ();
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
opt_given = oflags.pflag = oflags.rflag = 0;
|
||||
oflags.Dflag = oflags.Eflag = oflags.Iflag = 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, &oflags, &acts, &copts);
|
||||
if (rval == EX_USAGE)
|
||||
return (rval);
|
||||
opt_given = rval != EXECUTION_FAILURE;
|
||||
|
||||
list = loptend;
|
||||
|
||||
if (oflags.Dflag)
|
||||
wl = make_word_list (make_bare_word (DEFAULTCMD), (WORD_LIST *)NULL);
|
||||
else if (oflags.Eflag)
|
||||
wl = make_word_list (make_bare_word (EMPTYCMD), (WORD_LIST *)NULL);
|
||||
else if (oflags.Iflag)
|
||||
wl = make_word_list (make_bare_word (INITIALWORD), (WORD_LIST *)NULL);
|
||||
else
|
||||
wl = (WORD_LIST *)NULL;
|
||||
|
||||
/* -p overrides everything else */
|
||||
if (oflags.pflag || (list == 0 && opt_given == 0))
|
||||
{
|
||||
if (wl)
|
||||
{
|
||||
rval = print_cmd_completions (wl);
|
||||
dispose_words (wl);
|
||||
return rval;
|
||||
}
|
||||
else if (list == 0)
|
||||
{
|
||||
print_all_completions ();
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
return (print_cmd_completions (list));
|
||||
}
|
||||
|
||||
/* next, -r overrides everything else. */
|
||||
if (oflags.rflag)
|
||||
{
|
||||
if (wl)
|
||||
{
|
||||
rval = remove_cmd_completions (wl);
|
||||
dispose_words (wl);
|
||||
return rval;
|
||||
}
|
||||
else if (list == 0)
|
||||
{
|
||||
progcomp_flush ();
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
return (remove_cmd_completions (list));
|
||||
}
|
||||
|
||||
if (wl == 0 && list == 0 && opt_given)
|
||||
{
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
/* If we get here, we need to build a compspec and add it for each
|
||||
remaining argument. */
|
||||
cs = compspec_create ();
|
||||
cs->actions = acts;
|
||||
cs->options = copts;
|
||||
|
||||
cs->globpat = STRDUP (Garg);
|
||||
cs->words = STRDUP (Warg);
|
||||
cs->prefix = STRDUP (Parg);
|
||||
cs->suffix = STRDUP (Sarg);
|
||||
cs->funcname = STRDUP (Farg);
|
||||
cs->command = STRDUP (Carg);
|
||||
cs->filterpat = STRDUP (Xarg);
|
||||
|
||||
for (rval = EXECUTION_SUCCESS, l = wl ? wl : list ; l; l = l->next)
|
||||
{
|
||||
/* Add CS as the compspec for the specified commands. */
|
||||
if (progcomp_insert (l->word->word, cs) == 0)
|
||||
rval = EXECUTION_FAILURE;
|
||||
}
|
||||
|
||||
dispose_words (wl);
|
||||
return (rval);
|
||||
}
|
||||
|
||||
static int
|
||||
remove_cmd_completions (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
WORD_LIST *l;
|
||||
int ret;
|
||||
|
||||
for (ret = EXECUTION_SUCCESS, l = list; l; l = l->next)
|
||||
{
|
||||
if (progcomp_remove (l->word->word) == 0)
|
||||
{
|
||||
builtin_error (_("%s: no completion specification"), l->word->word);
|
||||
ret = EXECUTION_FAILURE;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
print_compoptions (copts, full)
|
||||
unsigned long copts;
|
||||
int full;
|
||||
{
|
||||
const struct _compopt *co;
|
||||
|
||||
for (co = compopts; co->optname; co++)
|
||||
if (copts & co->optflag)
|
||||
printf ("-o %s ", co->optname);
|
||||
else if (full)
|
||||
printf ("+o %s ", co->optname);
|
||||
}
|
||||
|
||||
static void
|
||||
print_compactions (acts)
|
||||
unsigned long acts;
|
||||
{
|
||||
const struct _compacts *ca;
|
||||
|
||||
/* simple flags first */
|
||||
for (ca = compacts; ca->actname; ca++)
|
||||
if (ca->actopt && (acts & ca->actflag))
|
||||
printf ("-%c ", ca->actopt);
|
||||
|
||||
/* then the rest of the actions */
|
||||
for (ca = compacts; ca->actname; ca++)
|
||||
if (ca->actopt == 0 && (acts & ca->actflag))
|
||||
printf ("-A %s ", ca->actname);
|
||||
}
|
||||
|
||||
static void
|
||||
print_arg (arg, flag, quote)
|
||||
const char *arg, *flag;
|
||||
int quote;
|
||||
{
|
||||
char *x;
|
||||
|
||||
if (arg)
|
||||
{
|
||||
x = quote ? sh_single_quote (arg) : (char *)arg;
|
||||
printf ("%s %s ", flag, x);
|
||||
if (x != arg)
|
||||
free (x);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_cmd_name (cmd)
|
||||
const char *cmd;
|
||||
{
|
||||
char *x;
|
||||
|
||||
if (STREQ (cmd, DEFAULTCMD))
|
||||
printf ("-D");
|
||||
else if (STREQ (cmd, EMPTYCMD))
|
||||
printf ("-E");
|
||||
else if (STREQ (cmd, INITIALWORD))
|
||||
printf ("-I");
|
||||
else if (*cmd == 0) /* XXX - can this happen? */
|
||||
printf ("''");
|
||||
else if (sh_contains_shell_metas (cmd))
|
||||
{
|
||||
x = sh_single_quote (cmd);
|
||||
printf ("%s", x);
|
||||
free (x);
|
||||
}
|
||||
else
|
||||
printf ("%s", cmd);
|
||||
}
|
||||
|
||||
static int
|
||||
print_one_completion (cmd, cs)
|
||||
char *cmd;
|
||||
COMPSPEC *cs;
|
||||
{
|
||||
printf ("complete ");
|
||||
|
||||
print_compoptions (cs->options, 0);
|
||||
print_compactions (cs->actions);
|
||||
|
||||
/* now the rest of the arguments */
|
||||
|
||||
/* arguments that require quoting */
|
||||
print_arg (cs->globpat, "-G", 1);
|
||||
print_arg (cs->words, "-W", 1);
|
||||
print_arg (cs->prefix, "-P", 1);
|
||||
print_arg (cs->suffix, "-S", 1);
|
||||
print_arg (cs->filterpat, "-X", 1);
|
||||
|
||||
print_arg (cs->command, "-C", 1);
|
||||
|
||||
/* simple arguments that don't require quoting */
|
||||
print_arg (cs->funcname, "-F", sh_contains_shell_metas (cs->funcname) != 0);
|
||||
|
||||
print_cmd_name (cmd);
|
||||
printf ("\n");
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
print_compopts (cmd, cs, full)
|
||||
const char *cmd;
|
||||
COMPSPEC *cs;
|
||||
int full;
|
||||
{
|
||||
printf ("compopt ");
|
||||
|
||||
print_compoptions (cs->options, full);
|
||||
print_cmd_name (cmd);
|
||||
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
static int
|
||||
print_compitem (item)
|
||||
BUCKET_CONTENTS *item;
|
||||
{
|
||||
COMPSPEC *cs;
|
||||
char *cmd;
|
||||
|
||||
cmd = item->key;
|
||||
cs = (COMPSPEC *)item->data;
|
||||
|
||||
return (print_one_completion (cmd, cs));
|
||||
}
|
||||
|
||||
static void
|
||||
print_all_completions ()
|
||||
{
|
||||
progcomp_walk (print_compitem);
|
||||
}
|
||||
|
||||
static int
|
||||
print_cmd_completions (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
WORD_LIST *l;
|
||||
COMPSPEC *cs;
|
||||
int ret;
|
||||
|
||||
for (ret = EXECUTION_SUCCESS, l = list; l; l = l->next)
|
||||
{
|
||||
cs = progcomp_search (l->word->word);
|
||||
if (cs)
|
||||
print_one_completion (l->word->word, cs);
|
||||
else
|
||||
{
|
||||
builtin_error (_("%s: no completion specification"), l->word->word);
|
||||
ret = EXECUTION_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
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] [-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
|
||||
compgen_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int rval;
|
||||
unsigned long acts, copts;
|
||||
COMPSPEC *cs;
|
||||
STRINGLIST *sl;
|
||||
char *word, **matches;
|
||||
char *old_line;
|
||||
int old_ind;
|
||||
|
||||
if (list == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
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, (struct _optflags *)NULL, &acts, &copts);
|
||||
if (rval == EX_USAGE)
|
||||
return (rval);
|
||||
if (rval == EXECUTION_FAILURE)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
list = loptend;
|
||||
|
||||
word = (list && list->word) ? list->word->word : "";
|
||||
|
||||
if (Farg)
|
||||
builtin_error (_("warning: -F option may not work as you expect"));
|
||||
if (Carg)
|
||||
builtin_error (_("warning: -C option may not work as you expect"));
|
||||
|
||||
/* If we get here, we need to build a compspec and evaluate it. */
|
||||
cs = compspec_create ();
|
||||
cs->actions = acts;
|
||||
cs->options = copts;
|
||||
cs->refcount = 1;
|
||||
|
||||
cs->globpat = STRDUP (Garg);
|
||||
cs->words = STRDUP (Warg);
|
||||
cs->prefix = STRDUP (Parg);
|
||||
cs->suffix = STRDUP (Sarg);
|
||||
cs->funcname = STRDUP (Farg);
|
||||
cs->command = STRDUP (Carg);
|
||||
cs->filterpat = STRDUP (Xarg);
|
||||
|
||||
rval = EXECUTION_FAILURE;
|
||||
|
||||
/* probably don't have to save these, just being safe */
|
||||
old_line = pcomp_line;
|
||||
old_ind = pcomp_ind;
|
||||
pcomp_line = (char *)NULL;
|
||||
pcomp_ind = 0;
|
||||
sl = gen_compspec_completions (cs, "compgen", word, 0, 0, 0);
|
||||
pcomp_line = old_line;
|
||||
pcomp_ind = old_ind;
|
||||
|
||||
/* If the compspec wants the bash default completions, temporarily
|
||||
turn off programmable completion and call the bash completion code. */
|
||||
if ((sl == 0 || sl->list_len == 0) && (copts & COPT_BASHDEFAULT))
|
||||
{
|
||||
matches = bash_default_completion (word, 0, 0, 0, 0);
|
||||
sl = completions_to_stringlist (matches);
|
||||
strvec_dispose (matches);
|
||||
}
|
||||
|
||||
/* This isn't perfect, but it's the best we can do, given what readline
|
||||
exports from its set of completion utility functions. */
|
||||
if ((sl == 0 || sl->list_len == 0) && (copts & COPT_DEFAULT))
|
||||
{
|
||||
matches = rl_completion_matches (word, rl_filename_completion_function);
|
||||
strlist_dispose (sl);
|
||||
sl = completions_to_stringlist (matches);
|
||||
strvec_dispose (matches);
|
||||
}
|
||||
|
||||
if (sl)
|
||||
{
|
||||
if (sl->list && sl->list_len)
|
||||
{
|
||||
rval = EXECUTION_SUCCESS;
|
||||
strlist_print (sl, (char *)NULL);
|
||||
}
|
||||
strlist_dispose (sl);
|
||||
}
|
||||
|
||||
compspec_dispose (cs);
|
||||
return (rval);
|
||||
}
|
||||
|
||||
$BUILTIN compopt
|
||||
$DEPENDS_ON PROGRAMMABLE_COMPLETION
|
||||
$FUNCTION compopt_builtin
|
||||
$SHORT_DOC compopt [-o|+o option] [-DEI] [name ...]
|
||||
Modify or display completion options.
|
||||
|
||||
Modify the completion options for each NAME, or, if no NAMEs are supplied,
|
||||
the completion currently being executed. If no OPTIONs are given, print
|
||||
the completion options for each NAME or the current completion specification.
|
||||
|
||||
Options:
|
||||
-o option Set completion option OPTION for each NAME
|
||||
-D Change options for the "default" command completion
|
||||
-E Change options for the "empty" command completion
|
||||
-I Change options for completion on the initial word
|
||||
|
||||
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, Dflag, Eflag, Iflag;
|
||||
WORD_LIST *l, *wl;
|
||||
COMPSPEC *cs;
|
||||
|
||||
opts_on = opts_off = Eflag = Dflag = Iflag = 0;
|
||||
ret = EXECUTION_SUCCESS;
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "+o:DEI")) != -1)
|
||||
{
|
||||
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;
|
||||
case 'D':
|
||||
Dflag = 1;
|
||||
break;
|
||||
case 'E':
|
||||
Eflag = 1;
|
||||
break;
|
||||
case 'I':
|
||||
Iflag = 1;
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
if (Dflag)
|
||||
wl = make_word_list (make_bare_word (DEFAULTCMD), (WORD_LIST *)NULL);
|
||||
else if (Eflag)
|
||||
wl = make_word_list (make_bare_word (EMPTYCMD), (WORD_LIST *)NULL);
|
||||
else if (Iflag)
|
||||
wl = make_word_list (make_bare_word (INITIALWORD), (WORD_LIST *)NULL);
|
||||
else
|
||||
wl = (WORD_LIST *)NULL;
|
||||
|
||||
if (list == 0 && wl == 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 = wl ? wl : 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);
|
||||
}
|
||||
|
||||
if (wl)
|
||||
dispose_words (wl);
|
||||
|
||||
return (ret);
|
||||
}
|
1056
builtins/declare.def
Normal file
1056
builtins/declare.def
Normal file
File diff suppressed because it is too large
Load diff
202
builtins/echo.def
Normal file
202
builtins/echo.def
Normal file
|
@ -0,0 +1,202 @@
|
|||
This file is echo.def, from which is created echo.c.
|
||||
It implements the builtin "echo" in Bash.
|
||||
|
||||
Copyright (C) 1987-2018 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 echo.c
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashansi.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../shell.h"
|
||||
|
||||
#include "common.h"
|
||||
|
||||
$BUILTIN echo
|
||||
$FUNCTION echo_builtin
|
||||
$DEPENDS_ON V9_ECHO
|
||||
$SHORT_DOC echo [-neE] [arg ...]
|
||||
Write arguments to the standard output.
|
||||
|
||||
Display the ARGs, separated by a single space character and followed by a
|
||||
newline, on the standard output.
|
||||
|
||||
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
|
||||
\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
|
||||
\uHHHH the Unicode character whose value is the hexadecimal value HHHH.
|
||||
HHHH can be one to four hex digits.
|
||||
\UHHHHHHHH the Unicode character whose value is the hexadecimal value
|
||||
HHHHHHHH. HHHHHHHH can be one to eight 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 ...]
|
||||
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)
|
||||
# define VALID_ECHO_OPTIONS "neE"
|
||||
#else /* !V9_ECHO */
|
||||
# define VALID_ECHO_OPTIONS "n"
|
||||
#endif /* !V9_ECHO */
|
||||
|
||||
/* System V machines already have a /bin/sh with a v9 behaviour. We
|
||||
give Bash the identical behaviour for these machines so that the
|
||||
existing system shells won't barf. Regrettably, the SUS v2 has
|
||||
standardized the Sys V echo behavior. This variable is external
|
||||
so that we can have a `shopt' variable to control it at runtime. */
|
||||
#if defined (DEFAULT_ECHO_TO_XPG) || defined (STRICT_POSIX)
|
||||
int xpg_echo = 1;
|
||||
#else
|
||||
int xpg_echo = 0;
|
||||
#endif /* DEFAULT_ECHO_TO_XPG */
|
||||
|
||||
/* Print the words in LIST to standard output. If the first word is
|
||||
`-n', then don't print a trailing newline. We also support the
|
||||
echo syntax from Version 9 Unix systems. */
|
||||
int
|
||||
echo_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int display_return, do_v9, i, len;
|
||||
char *temp, *s;
|
||||
|
||||
do_v9 = xpg_echo;
|
||||
display_return = 1;
|
||||
|
||||
if (posixly_correct && xpg_echo)
|
||||
goto just_echo;
|
||||
|
||||
for (; list && (temp = list->word->word) && *temp == '-'; list = list->next)
|
||||
{
|
||||
/* If it appears that we are handling options, then make sure that
|
||||
all of the options specified are actually valid. Otherwise, the
|
||||
string should just be echoed. */
|
||||
temp++;
|
||||
|
||||
for (i = 0; temp[i]; i++)
|
||||
{
|
||||
if (strchr (VALID_ECHO_OPTIONS, temp[i]) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* echo - and echo -<nonopt> both mean to just echo the arguments. */
|
||||
if (*temp == 0 || temp[i])
|
||||
break;
|
||||
|
||||
/* All of the options in TEMP are valid options to ECHO.
|
||||
Handle them. */
|
||||
while (i = *temp++)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 'n':
|
||||
display_return = 0;
|
||||
break;
|
||||
#if defined (V9_ECHO)
|
||||
case 'e':
|
||||
do_v9 = 1;
|
||||
break;
|
||||
case 'E':
|
||||
do_v9 = 0;
|
||||
break;
|
||||
#endif /* V9_ECHO */
|
||||
default:
|
||||
goto just_echo; /* XXX */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
just_echo:
|
||||
|
||||
clearerr (stdout); /* clear error before writing and testing success */
|
||||
|
||||
while (list)
|
||||
{
|
||||
i = len = 0;
|
||||
temp = do_v9 ? ansicstr (list->word->word, STRLEN (list->word->word), 1, &i, &len)
|
||||
: list->word->word;
|
||||
if (temp)
|
||||
{
|
||||
if (do_v9)
|
||||
{
|
||||
for (s = temp; len > 0; len--)
|
||||
putchar (*s++);
|
||||
}
|
||||
else
|
||||
printf ("%s", temp);
|
||||
#if defined (SunOS5)
|
||||
fflush (stdout); /* Fix for bug in SunOS 5.5 printf(3) */
|
||||
#endif
|
||||
}
|
||||
QUIT;
|
||||
if (do_v9 && temp)
|
||||
free (temp);
|
||||
list = list->next;
|
||||
if (i)
|
||||
{
|
||||
display_return = 0;
|
||||
break;
|
||||
}
|
||||
if (list)
|
||||
putchar(' ');
|
||||
QUIT;
|
||||
}
|
||||
|
||||
if (display_return)
|
||||
putchar ('\n');
|
||||
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
586
builtins/enable.def
Normal file
586
builtins/enable.def
Normal file
|
@ -0,0 +1,586 @@
|
|||
This file is enable.def, from which is created enable.c.
|
||||
It implements the builtin "enable" in Bash.
|
||||
|
||||
Copyright (C) 1987-2021 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 enable.c
|
||||
|
||||
$BUILTIN enable
|
||||
$FUNCTION enable_builtin
|
||||
$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>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../builtins.h"
|
||||
#include "../flags.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
#include "findcmd.h"
|
||||
|
||||
#if defined (PROGRAMMABLE_COMPLETION)
|
||||
# include "../pcomplete.h"
|
||||
#endif
|
||||
|
||||
#define ENABLED 1
|
||||
#define DISABLED 2
|
||||
#define SPECIAL 4
|
||||
#define SILENT 8 /* affects dyn_load_builtin behavior */
|
||||
|
||||
#define AFLAG 0x01
|
||||
#define DFLAG 0x02
|
||||
#define FFLAG 0x04
|
||||
#define NFLAG 0x08
|
||||
#define PFLAG 0x10
|
||||
#define SFLAG 0x20
|
||||
|
||||
#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
|
||||
static int dyn_load_builtin PARAMS((WORD_LIST *, int, char *));
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_DLCLOSE)
|
||||
static int dyn_unload_builtin PARAMS((char *));
|
||||
static void delete_builtin PARAMS((struct builtin *));
|
||||
static int local_dlclose PARAMS((void *));
|
||||
#endif
|
||||
|
||||
#define STRUCT_SUFFIX "_struct"
|
||||
/* for now */
|
||||
#define LOAD_SUFFIX "_builtin_load"
|
||||
#define UNLOAD_SUFFIX "_builtin_unload"
|
||||
|
||||
static void list_some_builtins PARAMS((int));
|
||||
static int enable_shell_command PARAMS((char *, int));
|
||||
|
||||
/* Enable/disable shell commands present in LIST. If list is not specified,
|
||||
then print out a list of shell commands showing which are enabled and
|
||||
which are disabled. */
|
||||
int
|
||||
enable_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int result, flags;
|
||||
int opt, filter;
|
||||
WORD_LIST *next;
|
||||
#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
|
||||
char *filename;
|
||||
#endif
|
||||
|
||||
result = EXECUTION_SUCCESS;
|
||||
flags = 0;
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "adnpsf:")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'a':
|
||||
flags |= AFLAG;
|
||||
break;
|
||||
case 'n':
|
||||
flags |= NFLAG;
|
||||
break;
|
||||
case 'p':
|
||||
flags |= PFLAG;
|
||||
break;
|
||||
case 's':
|
||||
flags |= SFLAG;
|
||||
break;
|
||||
case 'f':
|
||||
#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
|
||||
flags |= FFLAG;
|
||||
filename = list_optarg;
|
||||
break;
|
||||
#else
|
||||
builtin_error (_("dynamic loading not available"));
|
||||
return (EX_USAGE);
|
||||
#endif
|
||||
#if defined (HAVE_DLCLOSE)
|
||||
case 'd':
|
||||
flags |= DFLAG;
|
||||
break;
|
||||
#else
|
||||
builtin_error (_("dynamic loading not available"));
|
||||
return (EX_USAGE);
|
||||
#endif /* HAVE_DLCLOSE */
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
|
||||
list = loptend;
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
/* Restricted shells cannot load new builtins. */
|
||||
if (restricted && (flags & (FFLAG|DFLAG)))
|
||||
{
|
||||
sh_restricted ((char *)NULL);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (list == 0 || (flags & PFLAG))
|
||||
{
|
||||
filter = (flags & AFLAG) ? (ENABLED | DISABLED)
|
||||
: (flags & NFLAG) ? DISABLED : ENABLED;
|
||||
|
||||
if (flags & SFLAG)
|
||||
filter |= SPECIAL;
|
||||
|
||||
list_some_builtins (filter);
|
||||
result = sh_chkwrite (EXECUTION_SUCCESS);
|
||||
}
|
||||
#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
|
||||
else if (flags & FFLAG)
|
||||
{
|
||||
filter = (flags & NFLAG) ? DISABLED : ENABLED;
|
||||
if (flags & SFLAG)
|
||||
filter |= SPECIAL;
|
||||
|
||||
result = dyn_load_builtin (list, filter, filename);
|
||||
if (result != EXECUTION_SUCCESS)
|
||||
result = EXECUTION_FAILURE; /* normalize return value */
|
||||
#if defined (PROGRAMMABLE_COMPLETION)
|
||||
set_itemlist_dirty (&it_builtins);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if defined (HAVE_DLCLOSE)
|
||||
else if (flags & DFLAG)
|
||||
{
|
||||
while (list)
|
||||
{
|
||||
opt = dyn_unload_builtin (list->word->word);
|
||||
if (opt == EXECUTION_FAILURE)
|
||||
result = EXECUTION_FAILURE;
|
||||
list = list->next;
|
||||
}
|
||||
#if defined (PROGRAMMABLE_COMPLETION)
|
||||
set_itemlist_dirty (&it_builtins);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
while (list)
|
||||
{
|
||||
opt = enable_shell_command (list->word->word, flags & NFLAG);
|
||||
next = list->next;
|
||||
|
||||
#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
|
||||
/* If we try to enable a non-existent builtin, and we have dynamic
|
||||
loading, try the equivalent of `enable -f name name'. */
|
||||
if (opt == EX_NOTFOUND)
|
||||
{
|
||||
int dflags, r;
|
||||
|
||||
dflags = ENABLED|SILENT|((flags & SFLAG) ? SPECIAL : 0);
|
||||
|
||||
list->next = 0;
|
||||
r = dyn_load_builtin (list, dflags, list->word->word);
|
||||
list->next = next;
|
||||
if (r == EXECUTION_SUCCESS)
|
||||
opt = r;
|
||||
#if defined (PROGRAMMABLE_COMPLETION)
|
||||
set_itemlist_dirty (&it_builtins);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if (opt == EX_NOTFOUND)
|
||||
{
|
||||
sh_notbuiltin (list->word->word);
|
||||
result = EXECUTION_FAILURE;
|
||||
}
|
||||
else if (opt != EXECUTION_SUCCESS)
|
||||
result = EXECUTION_FAILURE;
|
||||
|
||||
list = next;
|
||||
}
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
/* List some builtins.
|
||||
FILTER is a mask with two slots: ENABLED and DISABLED. */
|
||||
static void
|
||||
list_some_builtins (filter)
|
||||
int filter;
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (i = 0; i < num_shell_builtins; i++)
|
||||
{
|
||||
if (shell_builtins[i].function == 0 || (shell_builtins[i].flags & BUILTIN_DELETED))
|
||||
continue;
|
||||
|
||||
if ((filter & SPECIAL) &&
|
||||
(shell_builtins[i].flags & SPECIAL_BUILTIN) == 0)
|
||||
continue;
|
||||
|
||||
if ((filter & ENABLED) && (shell_builtins[i].flags & BUILTIN_ENABLED))
|
||||
printf ("enable %s\n", shell_builtins[i].name);
|
||||
else if ((filter & DISABLED) &&
|
||||
((shell_builtins[i].flags & BUILTIN_ENABLED) == 0))
|
||||
printf ("enable -n %s\n", shell_builtins[i].name);
|
||||
}
|
||||
}
|
||||
|
||||
/* Enable the shell command NAME. If DISABLE_P is non-zero, then
|
||||
disable NAME instead. */
|
||||
static int
|
||||
enable_shell_command (name, disable_p)
|
||||
char *name;
|
||||
int disable_p;
|
||||
{
|
||||
struct builtin *b;
|
||||
|
||||
b = builtin_address_internal (name, 1);
|
||||
if (b == 0)
|
||||
return (EX_NOTFOUND);
|
||||
|
||||
if (disable_p)
|
||||
b->flags &= ~BUILTIN_ENABLED;
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
else if (restricted && ((b->flags & BUILTIN_ENABLED) == 0))
|
||||
{
|
||||
sh_restricted ((char *)NULL);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
b->flags |= BUILTIN_ENABLED;
|
||||
|
||||
#if defined (PROGRAMMABLE_COMPLETION)
|
||||
set_itemlist_dirty (&it_enabled);
|
||||
set_itemlist_dirty (&it_disabled);
|
||||
#endif
|
||||
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
|
||||
|
||||
#if defined (HAVE_DLFCN_H)
|
||||
# include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
static int
|
||||
dyn_load_builtin (list, flags, filename)
|
||||
WORD_LIST *list;
|
||||
int flags;
|
||||
char *filename;
|
||||
{
|
||||
WORD_LIST *l;
|
||||
void *handle;
|
||||
|
||||
int total, size, new, replaced, r;
|
||||
char *struct_name, *name, *funcname;
|
||||
sh_load_func_t *loadfunc;
|
||||
struct builtin **new_builtins, *b, *new_shell_builtins, *old_builtin;
|
||||
char *loadables_path, *load_path;
|
||||
|
||||
if (list == 0)
|
||||
return (EXECUTION_FAILURE);
|
||||
|
||||
#ifndef RTLD_LAZY
|
||||
#define RTLD_LAZY 1
|
||||
#endif
|
||||
|
||||
handle = 0;
|
||||
if (absolute_program (filename) == 0)
|
||||
{
|
||||
loadables_path = get_string_value ("BASH_LOADABLES_PATH");
|
||||
if (loadables_path)
|
||||
{
|
||||
load_path = find_in_path (filename, loadables_path, FS_NODIRS|FS_EXEC_PREFERRED);
|
||||
if (load_path)
|
||||
{
|
||||
#if defined (_AIX)
|
||||
handle = dlopen (load_path, RTLD_NOW|RTLD_GLOBAL);
|
||||
#else
|
||||
handle = dlopen (load_path, RTLD_LAZY);
|
||||
#endif /* !_AIX */
|
||||
free (load_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Fall back to current directory for now */
|
||||
if (handle == 0)
|
||||
#if defined (_AIX)
|
||||
handle = dlopen (filename, RTLD_NOW|RTLD_GLOBAL);
|
||||
#else
|
||||
handle = dlopen (filename, RTLD_LAZY);
|
||||
#endif /* !_AIX */
|
||||
|
||||
if (handle == 0)
|
||||
{
|
||||
/* If we've been told to be quiet, don't complain about not finding the
|
||||
specified shared object. */
|
||||
if ((flags & SILENT) == 0)
|
||||
{
|
||||
name = printable_filename (filename, 0);
|
||||
builtin_error (_("cannot open shared object %s: %s"), name, dlerror ());
|
||||
if (name != filename)
|
||||
free (name);
|
||||
}
|
||||
return (EX_NOTFOUND);
|
||||
}
|
||||
|
||||
for (new = 0, l = list; l; l = l->next, new++)
|
||||
;
|
||||
new_builtins = (struct builtin **)xmalloc (new * sizeof (struct builtin *));
|
||||
|
||||
/* For each new builtin in the shared object, find it and its describing
|
||||
structure. If this is overwriting an existing builtin, do so, otherwise
|
||||
save the loaded struct for creating the new list of builtins. */
|
||||
for (replaced = new = 0; list; list = list->next)
|
||||
{
|
||||
name = list->word->word;
|
||||
|
||||
size = strlen (name);
|
||||
struct_name = (char *)xmalloc (size + 8);
|
||||
strcpy (struct_name, name);
|
||||
strcpy (struct_name + size, STRUCT_SUFFIX);
|
||||
|
||||
old_builtin = builtin_address_internal (name, 1);
|
||||
|
||||
b = (struct builtin *)dlsym (handle, struct_name);
|
||||
if (b == 0)
|
||||
{
|
||||
name = printable_filename (filename, 0);
|
||||
builtin_error (_("cannot find %s in shared object %s: %s"),
|
||||
struct_name, name, dlerror ());
|
||||
if (name != filename)
|
||||
free (name);
|
||||
free (struct_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
funcname = xrealloc (struct_name, size + sizeof (LOAD_SUFFIX) + 1);
|
||||
strcpy (funcname, name);
|
||||
strcpy (funcname + size, LOAD_SUFFIX);
|
||||
|
||||
loadfunc = (sh_load_func_t *)dlsym (handle, funcname);
|
||||
if (loadfunc)
|
||||
{
|
||||
/* Add warning if running an init function more than once */
|
||||
if (old_builtin && (old_builtin->flags & STATIC_BUILTIN) == 0)
|
||||
builtin_warning (_("%s: dynamic builtin already loaded"), name);
|
||||
r = (*loadfunc) (name);
|
||||
if (r == 0)
|
||||
{
|
||||
builtin_error (_("load function for %s returns failure (%d): not loaded"), name, r);
|
||||
free (funcname);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
free (funcname);
|
||||
|
||||
b->flags &= ~STATIC_BUILTIN;
|
||||
if (flags & SPECIAL)
|
||||
b->flags |= SPECIAL_BUILTIN;
|
||||
b->handle = handle;
|
||||
|
||||
if (old_builtin)
|
||||
{
|
||||
replaced++;
|
||||
FASTCOPY ((char *)b, (char *)old_builtin, sizeof (struct builtin));
|
||||
}
|
||||
else
|
||||
new_builtins[new++] = b;
|
||||
}
|
||||
|
||||
if (replaced == 0 && new == 0)
|
||||
{
|
||||
free (new_builtins);
|
||||
dlclose (handle);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (new)
|
||||
{
|
||||
total = num_shell_builtins + new;
|
||||
size = (total + 1) * sizeof (struct builtin);
|
||||
|
||||
new_shell_builtins = (struct builtin *)xmalloc (size);
|
||||
FASTCOPY ((char *)shell_builtins, (char *)new_shell_builtins,
|
||||
num_shell_builtins * sizeof (struct builtin));
|
||||
for (replaced = 0; replaced < new; replaced++)
|
||||
FASTCOPY ((char *)new_builtins[replaced],
|
||||
(char *)&new_shell_builtins[num_shell_builtins + replaced],
|
||||
sizeof (struct builtin));
|
||||
|
||||
new_shell_builtins[total].name = (char *)0;
|
||||
new_shell_builtins[total].function = (sh_builtin_func_t *)0;
|
||||
new_shell_builtins[total].flags = 0;
|
||||
|
||||
if (shell_builtins != static_shell_builtins)
|
||||
free (shell_builtins);
|
||||
|
||||
shell_builtins = new_shell_builtins;
|
||||
num_shell_builtins = total;
|
||||
initialize_shell_builtins ();
|
||||
}
|
||||
|
||||
free (new_builtins);
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_DLCLOSE)
|
||||
static void
|
||||
delete_builtin (b)
|
||||
struct builtin *b;
|
||||
{
|
||||
int ind, size;
|
||||
struct builtin *new_shell_builtins;
|
||||
|
||||
/* XXX - funky pointer arithmetic - XXX */
|
||||
#ifdef __STDC__
|
||||
ind = b - shell_builtins;
|
||||
#else
|
||||
ind = ((int)b - (int)shell_builtins) / sizeof (struct builtin);
|
||||
#endif
|
||||
size = num_shell_builtins * sizeof (struct builtin);
|
||||
new_shell_builtins = (struct builtin *)xmalloc (size);
|
||||
|
||||
/* Copy shell_builtins[0]...shell_builtins[ind - 1] to new_shell_builtins */
|
||||
if (ind)
|
||||
FASTCOPY ((char *)shell_builtins, (char *)new_shell_builtins,
|
||||
ind * sizeof (struct builtin));
|
||||
/* Copy shell_builtins[ind+1]...shell_builtins[num_shell_builtins to
|
||||
new_shell_builtins, starting at ind. */
|
||||
FASTCOPY ((char *)(&shell_builtins[ind+1]),
|
||||
(char *)(&new_shell_builtins[ind]),
|
||||
(num_shell_builtins - ind) * sizeof (struct builtin));
|
||||
|
||||
if (shell_builtins != static_shell_builtins)
|
||||
free (shell_builtins);
|
||||
|
||||
/* The result is still sorted. */
|
||||
num_shell_builtins--;
|
||||
shell_builtins = new_shell_builtins;
|
||||
}
|
||||
|
||||
/* Tenon's MachTen has a dlclose that doesn't return a value, so we
|
||||
finesse it with a local wrapper. */
|
||||
static int
|
||||
local_dlclose (handle)
|
||||
void *handle;
|
||||
{
|
||||
#if !defined (__MACHTEN__)
|
||||
return (dlclose (handle));
|
||||
#else /* __MACHTEN__ */
|
||||
dlclose (handle);
|
||||
return ((dlerror () != NULL) ? -1 : 0);
|
||||
#endif /* __MACHTEN__ */
|
||||
}
|
||||
|
||||
static int
|
||||
dyn_unload_builtin (name)
|
||||
char *name;
|
||||
{
|
||||
struct builtin *b;
|
||||
void *handle;
|
||||
char *funcname;
|
||||
sh_unload_func_t *unloadfunc;
|
||||
int ref, i, size;
|
||||
|
||||
b = builtin_address_internal (name, 1);
|
||||
if (b == 0)
|
||||
{
|
||||
sh_notbuiltin (name);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
if (b->flags & STATIC_BUILTIN)
|
||||
{
|
||||
builtin_error (_("%s: not dynamically loaded"), name);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
handle = (void *)b->handle;
|
||||
for (ref = i = 0; i < num_shell_builtins; i++)
|
||||
{
|
||||
if (shell_builtins[i].handle == b->handle)
|
||||
ref++;
|
||||
}
|
||||
|
||||
/* Call any unload function */
|
||||
size = strlen (name);
|
||||
funcname = xmalloc (size + sizeof (UNLOAD_SUFFIX) + 1);
|
||||
strcpy (funcname, name);
|
||||
strcpy (funcname + size, UNLOAD_SUFFIX);
|
||||
|
||||
unloadfunc = (sh_unload_func_t *)dlsym (handle, funcname);
|
||||
if (unloadfunc)
|
||||
(*unloadfunc) (name); /* void function */
|
||||
free (funcname);
|
||||
|
||||
/* Don't remove the shared object unless the reference count of builtins
|
||||
using it drops to zero. */
|
||||
if (ref == 1 && local_dlclose (handle) != 0)
|
||||
{
|
||||
builtin_error (_("%s: cannot delete: %s"), name, dlerror ());
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
/* Now remove this entry from the builtin table and reinitialize. */
|
||||
delete_builtin (b);
|
||||
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
#endif
|
57
builtins/eval.def
Normal file
57
builtins/eval.def
Normal file
|
@ -0,0 +1,57 @@
|
|||
This file is eval.def, from which is created eval.c.
|
||||
It implements the builtin "eval" in Bash.
|
||||
|
||||
Copyright (C) 1987-2016 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 eval.c
|
||||
|
||||
$BUILTIN eval
|
||||
$FUNCTION eval_builtin
|
||||
$SHORT_DOC eval [arg ...]
|
||||
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>
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../shell.h"
|
||||
#include "bashgetopt.h"
|
||||
#include "common.h"
|
||||
|
||||
/* Parse the string that these words make, and execute the command found. */
|
||||
int
|
||||
eval_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
if (no_options (list))
|
||||
return (EX_USAGE);
|
||||
list = loptend; /* skip over possible `--' */
|
||||
|
||||
return (list ? evalstring (string_list (list), "eval", SEVAL_NOHIST|SEVAL_NOOPTIMIZE) : EXECUTION_SUCCESS);
|
||||
}
|
384
builtins/evalfile.c
Normal file
384
builtins/evalfile.c
Normal file
|
@ -0,0 +1,384 @@
|
|||
/* evalfile.c - read and evaluate commands from a file or file descriptor */
|
||||
|
||||
/* Copyright (C) 1996-2017 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/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashtypes.h"
|
||||
#include "posixstat.h"
|
||||
#include "filecntl.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../parser.h"
|
||||
#include "../jobs.h"
|
||||
#include "../builtins.h"
|
||||
#include "../flags.h"
|
||||
#include "../input.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "../trap.h"
|
||||
|
||||
#include <y.tab.h>
|
||||
|
||||
#if defined (HISTORY)
|
||||
# include "../bashhist.h"
|
||||
#endif
|
||||
|
||||
#include <typemax.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
/* Flags for _evalfile() */
|
||||
#define FEVAL_ENOENTOK 0x001
|
||||
#define FEVAL_BUILTIN 0x002
|
||||
#define FEVAL_UNWINDPROT 0x004
|
||||
#define FEVAL_NONINT 0x008
|
||||
#define FEVAL_LONGJMP 0x010
|
||||
#define FEVAL_HISTORY 0x020
|
||||
#define FEVAL_CHECKBINARY 0x040
|
||||
#define FEVAL_REGFILE 0x080
|
||||
#define FEVAL_NOPUSHARGS 0x100
|
||||
|
||||
/* How many `levels' of sourced files we have. */
|
||||
int sourcelevel = 0;
|
||||
|
||||
static int
|
||||
_evalfile (filename, flags)
|
||||
const char *filename;
|
||||
int flags;
|
||||
{
|
||||
volatile int old_interactive;
|
||||
procenv_t old_return_catch;
|
||||
int return_val, fd, result, pflags, i, nnull;
|
||||
ssize_t nr; /* return value from read(2) */
|
||||
char *string;
|
||||
struct stat finfo;
|
||||
size_t file_size;
|
||||
sh_vmsg_func_t *errfunc;
|
||||
#if defined (ARRAY_VARS)
|
||||
SHELL_VAR *funcname_v, *bash_source_v, *bash_lineno_v;
|
||||
ARRAY *funcname_a, *bash_source_a, *bash_lineno_a;
|
||||
struct func_array_state *fa;
|
||||
# if defined (DEBUGGER)
|
||||
SHELL_VAR *bash_argv_v, *bash_argc_v;
|
||||
ARRAY *bash_argv_a, *bash_argc_a;
|
||||
# endif
|
||||
char *t, tt[2];
|
||||
#endif
|
||||
|
||||
USE_VAR(pflags);
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
GET_ARRAY_FROM_VAR ("FUNCNAME", funcname_v, funcname_a);
|
||||
GET_ARRAY_FROM_VAR ("BASH_SOURCE", bash_source_v, bash_source_a);
|
||||
GET_ARRAY_FROM_VAR ("BASH_LINENO", bash_lineno_v, bash_lineno_a);
|
||||
# if defined (DEBUGGER)
|
||||
GET_ARRAY_FROM_VAR ("BASH_ARGV", bash_argv_v, bash_argv_a);
|
||||
GET_ARRAY_FROM_VAR ("BASH_ARGC", bash_argc_v, bash_argc_a);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
fd = open (filename, O_RDONLY);
|
||||
|
||||
if (fd < 0 || (fstat (fd, &finfo) == -1))
|
||||
{
|
||||
i = errno;
|
||||
if (fd >= 0)
|
||||
close (fd);
|
||||
errno = i;
|
||||
|
||||
file_error_and_exit:
|
||||
if (((flags & FEVAL_ENOENTOK) == 0) || errno != ENOENT)
|
||||
file_error (filename);
|
||||
|
||||
if (flags & FEVAL_LONGJMP)
|
||||
{
|
||||
last_command_exit_value = EXECUTION_FAILURE;
|
||||
jump_to_top_level (EXITPROG);
|
||||
}
|
||||
|
||||
return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE
|
||||
: ((errno == ENOENT && (flags & FEVAL_ENOENTOK) != 0) ? 0 : -1));
|
||||
}
|
||||
|
||||
errfunc = ((flags & FEVAL_BUILTIN) ? builtin_error : internal_error);
|
||||
|
||||
if (S_ISDIR (finfo.st_mode))
|
||||
{
|
||||
(*errfunc) (_("%s: is a directory"), filename);
|
||||
close (fd);
|
||||
return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE : -1);
|
||||
}
|
||||
else if ((flags & FEVAL_REGFILE) && S_ISREG (finfo.st_mode) == 0)
|
||||
{
|
||||
(*errfunc) (_("%s: not a regular file"), filename);
|
||||
close (fd);
|
||||
return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE : -1);
|
||||
}
|
||||
|
||||
file_size = (size_t)finfo.st_size;
|
||||
/* Check for overflow with large files. */
|
||||
if (file_size != finfo.st_size || file_size + 1 < file_size)
|
||||
{
|
||||
(*errfunc) (_("%s: file is too large"), filename);
|
||||
close (fd);
|
||||
return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE : -1);
|
||||
}
|
||||
|
||||
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 (nr < 0) /* XXX was != file_size, not < 0 */
|
||||
{
|
||||
free (string);
|
||||
goto file_error_and_exit;
|
||||
}
|
||||
|
||||
if (nr == 0)
|
||||
{
|
||||
free (string);
|
||||
return ((flags & FEVAL_BUILTIN) ? EXECUTION_SUCCESS : 1);
|
||||
}
|
||||
|
||||
if ((flags & FEVAL_CHECKBINARY) &&
|
||||
check_binary_file (string, (nr > 80) ? 80 : nr))
|
||||
{
|
||||
free (string);
|
||||
(*errfunc) (_("%s: cannot execute binary file"), filename);
|
||||
return ((flags & FEVAL_BUILTIN) ? EX_BINARY_FILE : -1);
|
||||
}
|
||||
|
||||
i = strlen (string);
|
||||
if (i < nr)
|
||||
{
|
||||
for (nnull = i = 0; i < nr; i++)
|
||||
if (string[i] == '\0')
|
||||
{
|
||||
memmove (string+i, string+i+1, nr - i);
|
||||
nr--;
|
||||
/* Even if the `check binary' flag is not set, we want to avoid
|
||||
sourcing files with more than 256 null characters -- that
|
||||
probably indicates a binary file. */
|
||||
if ((flags & FEVAL_BUILTIN) && ++nnull > 256)
|
||||
{
|
||||
free (string);
|
||||
(*errfunc) (_("%s: cannot execute binary file"), filename);
|
||||
return ((flags & FEVAL_BUILTIN) ? EX_BINARY_FILE : -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & FEVAL_UNWINDPROT)
|
||||
{
|
||||
begin_unwind_frame ("_evalfile");
|
||||
|
||||
unwind_protect_int (return_catch_flag);
|
||||
unwind_protect_jmp_buf (return_catch);
|
||||
if (flags & FEVAL_NONINT)
|
||||
unwind_protect_int (interactive);
|
||||
unwind_protect_int (sourcelevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
COPY_PROCENV (return_catch, old_return_catch);
|
||||
if (flags & FEVAL_NONINT)
|
||||
old_interactive = interactive;
|
||||
}
|
||||
|
||||
if (flags & FEVAL_NONINT)
|
||||
interactive = 0;
|
||||
|
||||
return_catch_flag++;
|
||||
sourcelevel++;
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
array_push (bash_source_a, (char *)filename);
|
||||
t = itos (executing_line_number ());
|
||||
array_push (bash_lineno_a, t);
|
||||
free (t);
|
||||
array_push (funcname_a, "source"); /* not exactly right */
|
||||
|
||||
fa = (struct func_array_state *)xmalloc (sizeof (struct func_array_state));
|
||||
fa->source_a = bash_source_a;
|
||||
fa->source_v = bash_source_v;
|
||||
fa->lineno_a = bash_lineno_a;
|
||||
fa->lineno_v = bash_lineno_v;
|
||||
fa->funcname_a = funcname_a;
|
||||
fa->funcname_v = funcname_v;
|
||||
if (flags & FEVAL_UNWINDPROT)
|
||||
add_unwind_protect (restore_funcarray_state, fa);
|
||||
|
||||
# if defined (DEBUGGER)
|
||||
/* Have to figure out a better way to do this when `source' is supplied
|
||||
arguments */
|
||||
if ((flags & FEVAL_NOPUSHARGS) == 0)
|
||||
{
|
||||
if (shell_compatibility_level <= 44)
|
||||
init_bash_argv ();
|
||||
array_push (bash_argv_a, (char *)filename); /* XXX - unconditionally? */
|
||||
tt[0] = '1'; tt[1] = '\0';
|
||||
array_push (bash_argc_a, tt);
|
||||
if (flags & FEVAL_UNWINDPROT)
|
||||
add_unwind_protect (pop_args, 0);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* set the flags to be passed to parse_and_execute */
|
||||
pflags = SEVAL_RESETLINE|SEVAL_NOOPTIMIZE;
|
||||
pflags |= (flags & FEVAL_HISTORY) ? 0 : SEVAL_NOHIST;
|
||||
|
||||
if (flags & FEVAL_BUILTIN)
|
||||
result = EXECUTION_SUCCESS;
|
||||
|
||||
return_val = setjmp_nosigs (return_catch);
|
||||
|
||||
/* If `return' was seen outside of a function, but in the script, then
|
||||
force parse_and_execute () to clean up. */
|
||||
if (return_val)
|
||||
{
|
||||
parse_and_execute_cleanup (-1);
|
||||
result = return_catch_value;
|
||||
}
|
||||
else
|
||||
result = parse_and_execute (string, filename, pflags);
|
||||
|
||||
if (flags & FEVAL_UNWINDPROT)
|
||||
run_unwind_frame ("_evalfile");
|
||||
else
|
||||
{
|
||||
if (flags & FEVAL_NONINT)
|
||||
interactive = old_interactive;
|
||||
#if defined (ARRAY_VARS)
|
||||
restore_funcarray_state (fa);
|
||||
# if defined (DEBUGGER)
|
||||
if ((flags & FEVAL_NOPUSHARGS) == 0)
|
||||
{
|
||||
/* Don't need to call pop_args here until we do something better
|
||||
when source is passed arguments (see above). */
|
||||
array_pop (bash_argc_a);
|
||||
array_pop (bash_argv_a);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
return_catch_flag--;
|
||||
sourcelevel--;
|
||||
COPY_PROCENV (old_return_catch, return_catch);
|
||||
}
|
||||
|
||||
/* If we end up with EOF after sourcing a file, which can happen when the file
|
||||
doesn't end with a newline, pretend that it did. */
|
||||
if (current_token == yacc_EOF)
|
||||
push_token ('\n'); /* XXX */
|
||||
|
||||
return ((flags & FEVAL_BUILTIN) ? result : 1);
|
||||
}
|
||||
|
||||
int
|
||||
maybe_execute_file (fname, force_noninteractive)
|
||||
const char *fname;
|
||||
int force_noninteractive;
|
||||
{
|
||||
char *filename;
|
||||
int result, flags;
|
||||
|
||||
filename = bash_tilde_expand (fname, 0);
|
||||
flags = FEVAL_ENOENTOK;
|
||||
if (force_noninteractive)
|
||||
flags |= FEVAL_NONINT;
|
||||
result = _evalfile (filename, flags);
|
||||
free (filename);
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
force_execute_file (fname, force_noninteractive)
|
||||
const char *fname;
|
||||
int force_noninteractive;
|
||||
{
|
||||
char *filename;
|
||||
int result, flags;
|
||||
|
||||
filename = bash_tilde_expand (fname, 0);
|
||||
flags = 0;
|
||||
if (force_noninteractive)
|
||||
flags |= FEVAL_NONINT;
|
||||
result = _evalfile (filename, flags);
|
||||
free (filename);
|
||||
return result;
|
||||
}
|
||||
|
||||
#if defined (HISTORY)
|
||||
int
|
||||
fc_execute_file (filename)
|
||||
const char *filename;
|
||||
{
|
||||
int flags;
|
||||
|
||||
/* We want these commands to show up in the history list if
|
||||
remember_on_history is set. We use FEVAL_BUILTIN to return
|
||||
the result of parse_and_execute. */
|
||||
flags = FEVAL_ENOENTOK|FEVAL_HISTORY|FEVAL_REGFILE|FEVAL_BUILTIN;
|
||||
return (_evalfile (filename, flags));
|
||||
}
|
||||
#endif /* HISTORY */
|
||||
|
||||
int
|
||||
source_file (filename, sflags)
|
||||
const char *filename;
|
||||
int sflags;
|
||||
{
|
||||
int flags, rval;
|
||||
|
||||
flags = FEVAL_BUILTIN|FEVAL_UNWINDPROT|FEVAL_NONINT;
|
||||
if (sflags)
|
||||
flags |= FEVAL_NOPUSHARGS;
|
||||
/* POSIX shells exit if non-interactive and file error. */
|
||||
if (posixly_correct && interactive_shell == 0 && executing_command_builtin == 0)
|
||||
flags |= FEVAL_LONGJMP;
|
||||
rval = _evalfile (filename, flags);
|
||||
|
||||
run_return_trap ();
|
||||
return rval;
|
||||
}
|
843
builtins/evalstring.c
Normal file
843
builtins/evalstring.c
Normal file
|
@ -0,0 +1,843 @@
|
|||
/* evalstring.c - evaluate a string as one or more shell commands. */
|
||||
|
||||
/* Copyright (C) 1996-2022 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/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "filecntl.h"
|
||||
#include "../bashansi.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../jobs.h"
|
||||
#include "../builtins.h"
|
||||
#include "../flags.h"
|
||||
#include "../parser.h"
|
||||
#include "../input.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "../redir.h"
|
||||
#include "../trap.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include <y.tab.h>
|
||||
|
||||
#if defined (HISTORY)
|
||||
# include "../bashhist.h"
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
#include "builtext.h"
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#define IS_BUILTIN(s) (builtin_address_internal(s, 0) != (struct builtin *)NULL)
|
||||
|
||||
int parse_and_execute_level = 0;
|
||||
|
||||
static int cat_file PARAMS((REDIRECT *));
|
||||
|
||||
#define PE_TAG "parse_and_execute top"
|
||||
#define PS_TAG "parse_string top"
|
||||
|
||||
#if defined (HISTORY)
|
||||
static void
|
||||
set_history_remembering ()
|
||||
{
|
||||
remember_on_history = enable_history_list;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
restore_lastcom (x)
|
||||
char *x;
|
||||
{
|
||||
FREE (the_printed_command_except_trap);
|
||||
the_printed_command_except_trap = x;
|
||||
}
|
||||
|
||||
int
|
||||
should_optimize_fork (command, subshell)
|
||||
COMMAND *command;
|
||||
int subshell;
|
||||
{
|
||||
return (running_trap == 0 &&
|
||||
command->type == cm_simple &&
|
||||
signal_is_trapped (EXIT_TRAP) == 0 &&
|
||||
signal_is_trapped (ERROR_TRAP) == 0 &&
|
||||
any_signals_trapped () < 0 &&
|
||||
(subshell || (command->redirects == 0 && command->value.Simple->redirects == 0)) &&
|
||||
((command->flags & CMD_TIME_PIPELINE) == 0) &&
|
||||
((command->flags & CMD_INVERT_RETURN) == 0));
|
||||
}
|
||||
|
||||
/* This has extra tests to account for STARTUP_STATE == 2, which is for
|
||||
-c command but has been extended to command and process substitution
|
||||
(basically any time you call parse_and_execute in a subshell). */
|
||||
int
|
||||
should_suppress_fork (command)
|
||||
COMMAND *command;
|
||||
{
|
||||
int subshell;
|
||||
|
||||
subshell = subshell_environment & SUBSHELL_PROCSUB; /* salt to taste */
|
||||
return (startup_state == 2 && parse_and_execute_level == 1 &&
|
||||
*bash_input.location.string == '\0' &&
|
||||
parser_expanding_alias () == 0 &&
|
||||
should_optimize_fork (command, subshell));
|
||||
}
|
||||
|
||||
int
|
||||
can_optimize_connection (command)
|
||||
COMMAND *command;
|
||||
{
|
||||
return (*bash_input.location.string == '\0' &&
|
||||
parser_expanding_alias () == 0 &&
|
||||
(command->value.Connection->connector == AND_AND || command->value.Connection->connector == OR_OR || command->value.Connection->connector == ';') &&
|
||||
command->value.Connection->second->type == cm_simple);
|
||||
}
|
||||
|
||||
void
|
||||
optimize_connection_fork (command)
|
||||
COMMAND *command;
|
||||
{
|
||||
if (command->type == cm_connection &&
|
||||
(command->value.Connection->connector == AND_AND || command->value.Connection->connector == OR_OR || command->value.Connection->connector == ';') &&
|
||||
(command->value.Connection->second->flags & CMD_TRY_OPTIMIZING) &&
|
||||
(should_suppress_fork (command->value.Connection->second) ||
|
||||
((subshell_environment & SUBSHELL_PAREN) && should_optimize_fork (command->value.Connection->second, 0))))
|
||||
{
|
||||
command->value.Connection->second->flags |= CMD_NO_FORK;
|
||||
command->value.Connection->second->value.Simple->flags |= CMD_NO_FORK;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
optimize_subshell_command (command)
|
||||
COMMAND *command;
|
||||
{
|
||||
if (should_optimize_fork (command, 0))
|
||||
{
|
||||
command->flags |= CMD_NO_FORK;
|
||||
command->value.Simple->flags |= CMD_NO_FORK;
|
||||
}
|
||||
else if (command->type == cm_connection &&
|
||||
(command->value.Connection->connector == AND_AND || command->value.Connection->connector == OR_OR || command->value.Connection->connector == ';') &&
|
||||
command->value.Connection->second->type == cm_simple &&
|
||||
parser_expanding_alias () == 0)
|
||||
{
|
||||
command->value.Connection->second->flags |= CMD_TRY_OPTIMIZING;
|
||||
command->value.Connection->second->value.Simple->flags |= CMD_TRY_OPTIMIZING;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
optimize_shell_function (command)
|
||||
COMMAND *command;
|
||||
{
|
||||
COMMAND *fc;
|
||||
|
||||
fc = (command->type == cm_group) ? command->value.Group->command : command;
|
||||
|
||||
if (fc->type == cm_simple && should_suppress_fork (fc))
|
||||
{
|
||||
fc->flags |= CMD_NO_FORK;
|
||||
fc->value.Simple->flags |= CMD_NO_FORK;
|
||||
}
|
||||
else if (fc->type == cm_connection && can_optimize_connection (fc) && should_suppress_fork (fc->value.Connection->second))
|
||||
{
|
||||
fc->value.Connection->second->flags |= CMD_NO_FORK;
|
||||
fc->value.Connection->second->value.Simple->flags |= CMD_NO_FORK;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
can_optimize_cat_file (command)
|
||||
COMMAND *command;
|
||||
{
|
||||
return (command->type == cm_simple && !command->redirects &&
|
||||
(command->flags & CMD_TIME_PIPELINE) == 0 &&
|
||||
command->value.Simple->words == 0 &&
|
||||
command->value.Simple->redirects &&
|
||||
command->value.Simple->redirects->next == 0 &&
|
||||
command->value.Simple->redirects->instruction == r_input_direction &&
|
||||
command->value.Simple->redirects->redirector.dest == 0);
|
||||
}
|
||||
|
||||
/* How to force parse_and_execute () to clean up after itself. */
|
||||
void
|
||||
parse_and_execute_cleanup (old_running_trap)
|
||||
int old_running_trap;
|
||||
{
|
||||
if (running_trap > 0)
|
||||
{
|
||||
/* We assume if we have a different value for running_trap than when
|
||||
we started (the only caller that cares is evalstring()), the
|
||||
original caller will perform the cleanup, and we should not step
|
||||
on them. */
|
||||
if (running_trap != old_running_trap)
|
||||
run_trap_cleanup (running_trap - 1);
|
||||
unfreeze_jobs_list ();
|
||||
}
|
||||
|
||||
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, *lastcom;
|
||||
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 (line_number_for_err_trap);
|
||||
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)
|
||||
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);
|
||||
}
|
||||
|
||||
if (the_printed_command_except_trap)
|
||||
{
|
||||
lastcom = savestring (the_printed_command_except_trap);
|
||||
add_unwind_protect (restore_lastcom, lastcom);
|
||||
}
|
||||
|
||||
add_unwind_protect (pop_stream, (char *)NULL);
|
||||
if (parser_expanding_alias ())
|
||||
add_unwind_protect (parser_restore_alias, (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 ();
|
||||
# if defined (BANG_HISTORY)
|
||||
if (flags & SEVAL_NOHISTEXP)
|
||||
history_expansion_inhibited = 1;
|
||||
# endif /* BANG_HISTORY */
|
||||
#endif /* HISTORY */
|
||||
}
|
||||
|
||||
/* Parse and execute the commands in STRING. Returns whatever
|
||||
execute_command () returns. This frees STRING. FLAGS is a
|
||||
flags word; look in common.h for the possible values. Actions
|
||||
are:
|
||||
(flags & SEVAL_NONINT) -> interactive = 0;
|
||||
(flags & SEVAL_INTERACT) -> interactive = 1;
|
||||
(flags & SEVAL_NOHIST) -> call bash_history_disable ()
|
||||
(flags & SEVAL_NOFREE) -> don't free STRING when finished
|
||||
(flags & SEVAL_RESETLINE) -> reset line_number to 1
|
||||
(flags & SEVAL_NOHISTEXP) -> history_expansion_inhibited -> 1
|
||||
(flags & SEVAL_NOOPTIMIZE) -> don't try to turn on optimizing flags
|
||||
*/
|
||||
|
||||
int
|
||||
parse_and_execute (string, from_file, flags)
|
||||
char *string;
|
||||
const char *from_file;
|
||||
int flags;
|
||||
{
|
||||
int code, lreset;
|
||||
volatile int should_jump_to_top_level, last_result;
|
||||
COMMAND *volatile command;
|
||||
volatile sigset_t pe_sigmask;
|
||||
|
||||
parse_prologue (string, flags, PE_TAG);
|
||||
|
||||
parse_and_execute_level++;
|
||||
|
||||
lreset = flags & SEVAL_RESETLINE;
|
||||
|
||||
#if defined (HAVE_POSIX_SIGNALS)
|
||||
/* If we longjmp and are going to go on, use this to restore signal mask */
|
||||
sigemptyset ((sigset_t *)&pe_sigmask);
|
||||
sigprocmask (SIG_BLOCK, (sigset_t *)NULL, (sigset_t *)&pe_sigmask);
|
||||
#endif
|
||||
|
||||
/* 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 (lreset);
|
||||
if (parser_expanding_alias ())
|
||||
/* push current shell_input_line */
|
||||
parser_save_alias ();
|
||||
|
||||
if (lreset == 0)
|
||||
line_number--;
|
||||
|
||||
indirection_level++;
|
||||
|
||||
code = should_jump_to_top_level = 0;
|
||||
last_result = EXECUTION_SUCCESS;
|
||||
|
||||
/* We need to reset enough of the token state so we can start fresh. */
|
||||
if (current_token == yacc_EOF)
|
||||
current_token = '\n'; /* reset_parser() ? */
|
||||
|
||||
with_input_from_string (string, from_file);
|
||||
clear_shell_input_line ();
|
||||
while (*(bash_input.location.string) || parser_expanding_alias ())
|
||||
{
|
||||
command = (COMMAND *)NULL;
|
||||
|
||||
if (interrupt_state)
|
||||
{
|
||||
last_result = EXECUTION_FAILURE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Provide a location for functions which `longjmp (top_level)' to
|
||||
jump to. This prevents errors in substitution from restarting
|
||||
the reader loop directly, for example. */
|
||||
code = setjmp_nosigs (top_level);
|
||||
|
||||
if (code)
|
||||
{
|
||||
should_jump_to_top_level = 0;
|
||||
switch (code)
|
||||
{
|
||||
case ERREXIT:
|
||||
/* variable_context -> 0 is what eval.c:reader_loop() does in
|
||||
these circumstances. Don't bother with cleanup here because
|
||||
we don't want to run the function execution cleanup stuff
|
||||
that will cause pop_context and other functions to run.
|
||||
We call reset_local_contexts() instead, which just frees
|
||||
context memory.
|
||||
XXX - change that if we want the function context to be
|
||||
unwound. */
|
||||
if (exit_immediately_on_error && variable_context)
|
||||
{
|
||||
discard_unwind_frame ("pe_dispose");
|
||||
reset_local_contexts (); /* not in a function */
|
||||
}
|
||||
should_jump_to_top_level = 1;
|
||||
goto out;
|
||||
case FORCE_EOF:
|
||||
case EXITPROG:
|
||||
if (command)
|
||||
run_unwind_frame ("pe_dispose");
|
||||
/* Remember to call longjmp (top_level) after the old
|
||||
value for it is restored. */
|
||||
should_jump_to_top_level = 1;
|
||||
goto out;
|
||||
|
||||
case EXITBLTIN:
|
||||
if (command)
|
||||
{
|
||||
if (variable_context && signal_is_trapped (0))
|
||||
{
|
||||
/* Let's make sure we run the exit trap in the function
|
||||
context, as we do when not running parse_and_execute.
|
||||
The pe_dispose unwind frame comes before any unwind-
|
||||
protects installed by the string we're evaluating, so
|
||||
it will undo the current function scope. */
|
||||
dispose_command (command);
|
||||
discard_unwind_frame ("pe_dispose");
|
||||
}
|
||||
else
|
||||
run_unwind_frame ("pe_dispose");
|
||||
}
|
||||
should_jump_to_top_level = 1;
|
||||
goto out;
|
||||
|
||||
case DISCARD:
|
||||
if (command)
|
||||
run_unwind_frame ("pe_dispose");
|
||||
last_result = last_command_exit_value = EXECUTION_FAILURE; /* XXX */
|
||||
set_pipestatus_from_exit (last_command_exit_value);
|
||||
if (subshell_environment)
|
||||
{
|
||||
should_jump_to_top_level = 1;
|
||||
goto out;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
dispose_command (command); /* pe_dispose does this */
|
||||
#endif
|
||||
#if defined (HAVE_POSIX_SIGNALS)
|
||||
sigprocmask (SIG_SETMASK, (sigset_t *)&pe_sigmask, (sigset_t *)NULL);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
default:
|
||||
command_error ("parse_and_execute", CMDERR_BADJUMP, code, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (parse_command () == 0)
|
||||
{
|
||||
int local_expalias, local_alflag;
|
||||
|
||||
if ((flags & SEVAL_PARSEONLY) || (interactive_shell == 0 && read_but_dont_execute))
|
||||
{
|
||||
last_result = EXECUTION_SUCCESS;
|
||||
dispose_command (global_command);
|
||||
global_command = (COMMAND *)NULL;
|
||||
}
|
||||
else if (command = global_command)
|
||||
{
|
||||
struct fd_bitmap *bitmap;
|
||||
|
||||
if (flags & SEVAL_FUNCDEF)
|
||||
{
|
||||
char *x;
|
||||
|
||||
/* If the command parses to something other than a straight
|
||||
function definition, or if we have not consumed the entire
|
||||
string, or if the parser has transformed the function
|
||||
name (as parsing will if it begins or ends with shell
|
||||
whitespace, for example), reject the attempt */
|
||||
if (command->type != cm_function_def ||
|
||||
((x = parser_remaining_input ()) && *x) ||
|
||||
(STREQ (from_file, command->value.Function_def->name->word) == 0))
|
||||
{
|
||||
internal_warning (_("%s: ignoring function definition attempt"), from_file);
|
||||
should_jump_to_top_level = 0;
|
||||
last_result = last_command_exit_value = EX_BADUSAGE;
|
||||
set_pipestatus_from_exit (last_command_exit_value);
|
||||
reset_parser ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bitmap = new_fd_bitmap (FD_BITMAP_SIZE);
|
||||
begin_unwind_frame ("pe_dispose");
|
||||
add_unwind_protect (dispose_fd_bitmap, bitmap);
|
||||
add_unwind_protect (dispose_command, command); /* XXX */
|
||||
|
||||
global_command = (COMMAND *)NULL;
|
||||
|
||||
if ((subshell_environment & SUBSHELL_COMSUB) && comsub_ignore_return)
|
||||
command->flags |= CMD_IGNORE_RETURN;
|
||||
|
||||
#if defined (ONESHOT)
|
||||
/*
|
||||
* IF
|
||||
* we were invoked as `bash -c' (startup_state == 2) AND
|
||||
* parse_and_execute has not been called recursively AND
|
||||
* we're not running a trap AND
|
||||
* we have parsed the full command (string == '\0') AND
|
||||
* we're not going to run the exit trap AND
|
||||
* we have a simple command without redirections AND
|
||||
* the command is not being timed AND
|
||||
* the command's return status is not being inverted AND
|
||||
* there aren't any traps in effect
|
||||
* THEN
|
||||
* tell the execution code that we don't need to fork
|
||||
*/
|
||||
if (should_suppress_fork (command))
|
||||
{
|
||||
command->flags |= CMD_NO_FORK;
|
||||
command->value.Simple->flags |= CMD_NO_FORK;
|
||||
}
|
||||
|
||||
/* Can't optimize forks out here execept for simple commands.
|
||||
This knows that the parser sets up commands as left-side heavy
|
||||
(&& and || are left-associative) and after the single parse,
|
||||
if we are at the end of the command string, the last in a
|
||||
series of connection commands is
|
||||
command->value.Connection->second. */
|
||||
else if (command->type == cm_connection &&
|
||||
(flags & SEVAL_NOOPTIMIZE) == 0 &&
|
||||
can_optimize_connection (command))
|
||||
{
|
||||
command->value.Connection->second->flags |= CMD_TRY_OPTIMIZING;
|
||||
command->value.Connection->second->value.Simple->flags |= CMD_TRY_OPTIMIZING;
|
||||
}
|
||||
#endif /* ONESHOT */
|
||||
|
||||
/* We play tricks in the parser and command_substitute() turning
|
||||
expand_aliases on and off depending on which parsing pass and
|
||||
whether or not we're in posix mode. This only matters for
|
||||
parsing, and we let the higher layers deal with that. We just
|
||||
want to ensure that expand_aliases is set to the appropriate
|
||||
global value when we go to execute this command, so we save
|
||||
and restore it around the execution (we don't restore it if
|
||||
the global value of the flag (expaliases_flag) changes). */
|
||||
local_expalias = expand_aliases;
|
||||
local_alflag = expaliases_flag;
|
||||
if (subshell_environment & SUBSHELL_COMSUB)
|
||||
expand_aliases = expaliases_flag;
|
||||
|
||||
/* See if this is a candidate for $( <file ). */
|
||||
if (startup_state == 2 &&
|
||||
(subshell_environment & SUBSHELL_COMSUB) &&
|
||||
*bash_input.location.string == '\0' &&
|
||||
can_optimize_cat_file (command))
|
||||
{
|
||||
int r;
|
||||
r = cat_file (command->value.Simple->redirects);
|
||||
last_result = (r < 0) ? EXECUTION_FAILURE : EXECUTION_SUCCESS;
|
||||
}
|
||||
else
|
||||
last_result = execute_command_internal
|
||||
(command, 0, NO_PIPE, NO_PIPE, bitmap);
|
||||
dispose_command (command);
|
||||
dispose_fd_bitmap (bitmap);
|
||||
discard_unwind_frame ("pe_dispose");
|
||||
|
||||
/* If the global value didn't change, we restore what we had. */
|
||||
if ((subshell_environment & SUBSHELL_COMSUB) && local_alflag == expaliases_flag)
|
||||
expand_aliases = local_expalias;
|
||||
|
||||
if (flags & SEVAL_ONECMD)
|
||||
{
|
||||
reset_parser ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
last_result = EX_BADUSAGE; /* was EXECUTION_FAILURE */
|
||||
|
||||
if (interactive_shell == 0 && this_shell_builtin &&
|
||||
(this_shell_builtin == source_builtin || this_shell_builtin == eval_builtin) &&
|
||||
last_command_exit_value == EX_BADSYNTAX && posixly_correct && executing_command_builtin == 0)
|
||||
{
|
||||
should_jump_to_top_level = 1;
|
||||
code = ERREXIT;
|
||||
last_command_exit_value = EX_BADUSAGE;
|
||||
}
|
||||
|
||||
/* Since we are shell compatible, syntax errors in a script
|
||||
abort the execution of the script. Right? */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
|
||||
run_unwind_frame (PE_TAG);
|
||||
|
||||
if (interrupt_state && parse_and_execute_level == 0)
|
||||
{
|
||||
/* An interrupt during non-interactive execution in an
|
||||
interactive shell (e.g. via $PROMPT_COMMAND) should
|
||||
not cause the shell to exit. */
|
||||
interactive = interactive_shell;
|
||||
throw_to_top_level ();
|
||||
}
|
||||
|
||||
CHECK_TERMSIG;
|
||||
|
||||
if (should_jump_to_top_level)
|
||||
jump_to_top_level (code);
|
||||
|
||||
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, cmdp, endp)
|
||||
char *string;
|
||||
const char *from_file;
|
||||
int flags;
|
||||
COMMAND **cmdp;
|
||||
char **endp;
|
||||
{
|
||||
int code, nc;
|
||||
volatile int should_jump_to_top_level;
|
||||
COMMAND *volatile command, *oglobal;
|
||||
char *ostring;
|
||||
volatile sigset_t ps_sigmask;
|
||||
|
||||
parse_prologue (string, flags, PS_TAG);
|
||||
|
||||
#if defined (HAVE_POSIX_SIGNALS)
|
||||
/* If we longjmp and are going to go on, use this to restore signal mask */
|
||||
sigemptyset ((sigset_t *)&ps_sigmask);
|
||||
sigprocmask (SIG_BLOCK, (sigset_t *)NULL, (sigset_t *)&ps_sigmask);
|
||||
#endif
|
||||
|
||||
/* 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);
|
||||
if (parser_expanding_alias ())
|
||||
/* push current shell_input_line */
|
||||
parser_save_alias ();
|
||||
|
||||
code = should_jump_to_top_level = 0;
|
||||
oglobal = global_command;
|
||||
|
||||
with_input_from_string (string, from_file);
|
||||
ostring = bash_input.location.string;
|
||||
while (*(bash_input.location.string)) /* XXX - parser_expanding_alias () ? */
|
||||
{
|
||||
command = (COMMAND *)NULL;
|
||||
|
||||
#if 0
|
||||
if (interrupt_state)
|
||||
break;
|
||||
#endif
|
||||
|
||||
/* Provide a location for functions which `longjmp (top_level)' to
|
||||
jump to. */
|
||||
code = setjmp_nosigs (top_level);
|
||||
|
||||
if (code)
|
||||
{
|
||||
INTERNAL_DEBUG(("parse_string: longjmp executed: code = %d", code));
|
||||
|
||||
should_jump_to_top_level = 0;
|
||||
switch (code)
|
||||
{
|
||||
case FORCE_EOF:
|
||||
case ERREXIT:
|
||||
case EXITPROG:
|
||||
case EXITBLTIN:
|
||||
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:
|
||||
#if defined (HAVE_POSIX_SIGNALS)
|
||||
sigprocmask (SIG_SETMASK, (sigset_t *)&ps_sigmask, (sigset_t *)NULL);
|
||||
#endif
|
||||
command_error ("parse_string", CMDERR_BADJUMP, code, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (parse_command () == 0)
|
||||
{
|
||||
if (cmdp)
|
||||
*cmdp = global_command;
|
||||
else
|
||||
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)
|
||||
{
|
||||
if (current_token == shell_eof_token)
|
||||
rewind_input_string ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
|
||||
global_command = oglobal;
|
||||
nc = bash_input.location.string - ostring;
|
||||
if (endp)
|
||||
*endp = bash_input.location.string;
|
||||
|
||||
run_unwind_frame (PS_TAG);
|
||||
|
||||
/* If we return < 0, the caller (xparse_dolparen) will jump_to_top_level for
|
||||
us, after doing cleanup */
|
||||
if (should_jump_to_top_level)
|
||||
{
|
||||
if (parse_and_execute_level == 0)
|
||||
top_level_cleanup ();
|
||||
if (code == DISCARD)
|
||||
return -DISCARD;
|
||||
jump_to_top_level (code);
|
||||
}
|
||||
|
||||
return (nc);
|
||||
}
|
||||
|
||||
int
|
||||
open_redir_file (r, fnp)
|
||||
REDIRECT *r;
|
||||
char **fnp;
|
||||
{
|
||||
char *fn;
|
||||
int fd, rval;
|
||||
|
||||
if (r->instruction != r_input_direction)
|
||||
return -1;
|
||||
|
||||
/* Get the filename. */
|
||||
if (posixly_correct && !interactive_shell)
|
||||
disallow_filename_globbing++;
|
||||
fn = redirection_expand (r->redirectee.filename);
|
||||
if (posixly_correct && !interactive_shell)
|
||||
disallow_filename_globbing--;
|
||||
|
||||
if (fn == 0)
|
||||
{
|
||||
redirection_error (r, AMBIGUOUS_REDIRECT, fn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fd = open(fn, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
file_error (fn);
|
||||
free (fn);
|
||||
if (fnp)
|
||||
*fnp = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fnp)
|
||||
*fnp = fn;
|
||||
else
|
||||
free (fn);
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* Handle a $( < file ) command substitution. This expands the filename,
|
||||
returning errors as appropriate, then just cats the file to the standard
|
||||
output. */
|
||||
static int
|
||||
cat_file (r)
|
||||
REDIRECT *r;
|
||||
{
|
||||
char *fn;
|
||||
int fd, rval;
|
||||
|
||||
fd = open_redir_file (r, &fn);
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
|
||||
rval = zcatfd (fd, 1, fn);
|
||||
|
||||
free (fn);
|
||||
close (fd);
|
||||
|
||||
return (rval);
|
||||
}
|
||||
|
||||
int
|
||||
evalstring (string, from_file, flags)
|
||||
char *string;
|
||||
const char *from_file;
|
||||
int flags;
|
||||
{
|
||||
volatile int r, rflag, rcatch;
|
||||
volatile int was_trap;
|
||||
|
||||
/* Are we running a trap when we execute this function? */
|
||||
was_trap = running_trap;
|
||||
|
||||
rcatch = 0;
|
||||
rflag = return_catch_flag;
|
||||
/* If we are in a place where `return' is valid, we have to catch
|
||||
`eval "... return"' and make sure parse_and_execute cleans up. Then
|
||||
we can trampoline to the previous saved return_catch location. */
|
||||
if (rflag)
|
||||
{
|
||||
begin_unwind_frame ("evalstring");
|
||||
|
||||
unwind_protect_int (return_catch_flag);
|
||||
unwind_protect_jmp_buf (return_catch);
|
||||
|
||||
return_catch_flag++; /* increment so we have a counter */
|
||||
rcatch = setjmp_nosigs (return_catch);
|
||||
}
|
||||
|
||||
if (rcatch)
|
||||
{
|
||||
/* We care about whether or not we are running the same trap we were
|
||||
when we entered this function. */
|
||||
parse_and_execute_cleanup (was_trap);
|
||||
r = return_catch_value;
|
||||
}
|
||||
else
|
||||
/* Note that parse_and_execute () frees the string it is passed. */
|
||||
r = parse_and_execute (string, from_file, flags);
|
||||
|
||||
if (rflag)
|
||||
{
|
||||
run_unwind_frame ("evalstring");
|
||||
if (rcatch && return_catch_flag)
|
||||
{
|
||||
return_catch_value = r;
|
||||
sh_longjmp (return_catch, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return (r);
|
||||
}
|
276
builtins/exec.def
Normal file
276
builtins/exec.def
Normal file
|
@ -0,0 +1,276 @@
|
|||
This file is exec.def, from which is created exec.c.
|
||||
It implements the builtin "exec" in Bash.
|
||||
|
||||
Copyright (C) 1987-2021 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 exec.c
|
||||
|
||||
$BUILTIN exec
|
||||
$FUNCTION exec_builtin
|
||||
$SHORT_DOC exec [-cl] [-a name] [command [argument ...]] [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>
|
||||
|
||||
#include "../bashtypes.h"
|
||||
#include "posixstat.h"
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "../findcmd.h"
|
||||
#if defined (JOB_CONTROL)
|
||||
# include "../jobs.h"
|
||||
#endif
|
||||
#include "../flags.h"
|
||||
#include "../trap.h"
|
||||
#if defined (HISTORY)
|
||||
# include "../bashhist.h"
|
||||
#endif
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
#include "input.h"
|
||||
|
||||
/* Not all systems declare ERRNO in errno.h... and some systems #define it! */
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif /* !errno */
|
||||
|
||||
extern REDIRECT *redirection_undo_list;
|
||||
extern char *exec_argv0;
|
||||
|
||||
int no_exit_on_failed_exec;
|
||||
|
||||
/* If the user wants this to look like a login shell, then
|
||||
prepend a `-' onto NAME and return the new name. */
|
||||
static char *
|
||||
mkdashname (name)
|
||||
char *name;
|
||||
{
|
||||
char *ret;
|
||||
|
||||
ret = (char *)xmalloc (2 + strlen (name));
|
||||
ret[0] = '-';
|
||||
strcpy (ret + 1, name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
exec_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int exit_value = EXECUTION_FAILURE;
|
||||
int cleanenv, login, opt, orig_job_control;
|
||||
char *argv0, *command, **args, **env, *newname, *com2;
|
||||
|
||||
cleanenv = login = orig_job_control = 0;
|
||||
exec_argv0 = argv0 = (char *)NULL;
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "cla:")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'c':
|
||||
cleanenv = 1;
|
||||
break;
|
||||
case 'l':
|
||||
login = 1;
|
||||
break;
|
||||
case 'a':
|
||||
argv0 = list_optarg;
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
/* First, let the redirections remain. */
|
||||
dispose_redirects (redirection_undo_list);
|
||||
redirection_undo_list = (REDIRECT *)NULL;
|
||||
|
||||
if (list == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
if (restricted)
|
||||
{
|
||||
sh_restricted ((char *)NULL);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
#endif /* RESTRICTED_SHELL */
|
||||
|
||||
args = strvec_from_word_list (list, 1, 0, (int *)NULL);
|
||||
env = (char **)0;
|
||||
|
||||
/* A command with a slash anywhere in its name is not looked up in $PATH. */
|
||||
command = absolute_program (args[0]) ? args[0] : search_for_command (args[0], 1);
|
||||
|
||||
if (command == 0)
|
||||
{
|
||||
if (file_isdir (args[0]))
|
||||
{
|
||||
#if defined (EISDIR)
|
||||
builtin_error (_("%s: cannot execute: %s"), args[0], strerror (EISDIR));
|
||||
#else
|
||||
builtin_error (_("%s: cannot execute: %s"), args[0], strerror (errno));
|
||||
#endif
|
||||
exit_value = EX_NOEXEC;
|
||||
}
|
||||
else
|
||||
{
|
||||
sh_notfound (args[0]);
|
||||
exit_value = EX_NOTFOUND; /* As per Posix.2, 3.14.6 */
|
||||
}
|
||||
goto failed_exec;
|
||||
}
|
||||
|
||||
com2 = full_pathname (command);
|
||||
if (com2)
|
||||
{
|
||||
if (command != args[0])
|
||||
free (command);
|
||||
command = com2;
|
||||
}
|
||||
|
||||
if (argv0)
|
||||
{
|
||||
free (args[0]);
|
||||
args[0] = login ? mkdashname (argv0) : savestring (argv0);
|
||||
exec_argv0 = savestring (args[0]);
|
||||
}
|
||||
else if (login)
|
||||
{
|
||||
newname = mkdashname (args[0]);
|
||||
free (args[0]);
|
||||
args[0] = newname;
|
||||
}
|
||||
|
||||
/* Decrement SHLVL by 1 so a new shell started here has the same value,
|
||||
preserving the appearance. After we do that, we need to change the
|
||||
exported environment to include the new value. If we've already forked
|
||||
and are in a subshell, we don't want to decrement the shell level,
|
||||
since we are `increasing' the level */
|
||||
|
||||
if (cleanenv == 0 && (subshell_environment & SUBSHELL_PAREN) == 0)
|
||||
adjust_shell_level (-1);
|
||||
|
||||
if (cleanenv)
|
||||
{
|
||||
env = strvec_create (1);
|
||||
env[0] = (char *)0;
|
||||
}
|
||||
else
|
||||
{
|
||||
maybe_make_export_env ();
|
||||
env = export_env;
|
||||
}
|
||||
|
||||
#if defined (HISTORY)
|
||||
if (interactive_shell && subshell_environment == 0)
|
||||
maybe_save_shell_history ();
|
||||
#endif /* HISTORY */
|
||||
|
||||
reset_signal_handlers (); /* leave trap strings in place */
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
orig_job_control = job_control; /* XXX - was also interactive_shell */
|
||||
if (subshell_environment == 0)
|
||||
end_job_control ();
|
||||
if (interactive || job_control)
|
||||
default_tty_job_signals (); /* undo initialize_job_signals */
|
||||
#endif /* JOB_CONTROL */
|
||||
|
||||
#if defined (BUFFERED_INPUT)
|
||||
if (default_buffered_input >= 0)
|
||||
sync_buffered_stream (default_buffered_input);
|
||||
#endif
|
||||
|
||||
exit_value = shell_execve (command, args, env);
|
||||
|
||||
/* We have to set this to NULL because shell_execve has called realloc()
|
||||
to stuff more items at the front of the array, which may have caused
|
||||
the memory to be freed by realloc(). We don't want to free it twice. */
|
||||
args = (char **)NULL;
|
||||
if (cleanenv == 0)
|
||||
adjust_shell_level (1);
|
||||
|
||||
if (exit_value == EX_NOTFOUND) /* no duplicate error message */
|
||||
goto failed_exec;
|
||||
else if (executable_file (command) == 0)
|
||||
{
|
||||
builtin_error (_("%s: cannot execute: %s"), command, strerror (errno));
|
||||
exit_value = EX_NOEXEC; /* As per Posix.2, 3.14.6 */
|
||||
}
|
||||
else
|
||||
file_error (command);
|
||||
|
||||
failed_exec:
|
||||
FREE (command);
|
||||
|
||||
if (subshell_environment || (interactive == 0 && no_exit_on_failed_exec == 0))
|
||||
exit_shell (last_command_exit_value = exit_value);
|
||||
|
||||
if (args)
|
||||
strvec_dispose (args);
|
||||
|
||||
if (env && env != export_env)
|
||||
strvec_dispose (env);
|
||||
|
||||
/* If we're not exiting after the exec fails, we restore the shell signal
|
||||
handlers and then modify the signal dispositions based on the trap strings
|
||||
before the failed exec. */
|
||||
initialize_signals (1);
|
||||
restore_traps ();
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
if (orig_job_control)
|
||||
restart_job_control ();
|
||||
#endif /* JOB_CONTROL */
|
||||
|
||||
return (exit_value);
|
||||
}
|
169
builtins/exit.def
Normal file
169
builtins/exit.def
Normal file
|
@ -0,0 +1,169 @@
|
|||
This file is exit.def, from which is created exit.c.
|
||||
It implements the builtins "exit", and "logout" in Bash.
|
||||
|
||||
Copyright (C) 1987-2021 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 exit.c
|
||||
|
||||
$BUILTIN exit
|
||||
$FUNCTION exit_builtin
|
||||
$SHORT_DOC exit [n]
|
||||
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
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "../bashtypes.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "../jobs.h"
|
||||
#include "../trap.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "builtext.h" /* for jobs_builtin */
|
||||
|
||||
extern int check_jobs_at_exit;
|
||||
|
||||
static int exit_or_logout PARAMS((WORD_LIST *));
|
||||
static int sourced_logout;
|
||||
|
||||
int
|
||||
exit_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
CHECK_HELPOPT (list);
|
||||
|
||||
if (interactive)
|
||||
{
|
||||
fprintf (stderr, login_shell ? _("logout\n") : "exit\n");
|
||||
fflush (stderr);
|
||||
}
|
||||
|
||||
return (exit_or_logout (list));
|
||||
}
|
||||
|
||||
$BUILTIN logout
|
||||
$FUNCTION logout_builtin
|
||||
$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. */
|
||||
int
|
||||
logout_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
CHECK_HELPOPT (list);
|
||||
|
||||
if (login_shell == 0 /* && interactive */)
|
||||
{
|
||||
builtin_error (_("not login shell: use `exit'"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else
|
||||
return (exit_or_logout (list));
|
||||
}
|
||||
|
||||
static int
|
||||
exit_or_logout (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int exit_value;
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
int exit_immediate_okay, stopmsg;
|
||||
|
||||
exit_immediate_okay = (interactive == 0 ||
|
||||
last_shell_builtin == exit_builtin ||
|
||||
last_shell_builtin == logout_builtin ||
|
||||
last_shell_builtin == jobs_builtin);
|
||||
|
||||
/* Check for stopped jobs if the user wants to. */
|
||||
if (exit_immediate_okay == 0)
|
||||
{
|
||||
register int i;
|
||||
for (i = stopmsg = 0; i < js.j_jobslots; i++)
|
||||
if (jobs[i] && STOPPED (i))
|
||||
stopmsg = JSTOPPED;
|
||||
else if (check_jobs_at_exit && stopmsg == 0 && jobs[i] && RUNNING (i))
|
||||
stopmsg = JRUNNING;
|
||||
|
||||
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 */
|
||||
|
||||
/* Get return value if present. This means that you can type
|
||||
`logout 5' to a shell, and it returns 5. */
|
||||
|
||||
/* If we're running the exit trap (running_trap == 1, since running_trap
|
||||
gets set to SIG+1), and we don't have a argument given to `exit'
|
||||
(list == 0), use the exit status we saved before running the trap
|
||||
commands (trap_saved_exit_value). */
|
||||
exit_value = (running_trap == 1 && list == 0) ? trap_saved_exit_value : get_exitstat (list);
|
||||
|
||||
bash_logout ();
|
||||
|
||||
last_command_exit_value = exit_value;
|
||||
|
||||
/* Exit the program. */
|
||||
jump_to_top_level (EXITBLTIN);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
void
|
||||
bash_logout ()
|
||||
{
|
||||
/* Run our `~/.bash_logout' file if it exists, and this is a login shell. */
|
||||
if (login_shell && sourced_logout++ == 0 && subshell_environment == 0)
|
||||
{
|
||||
maybe_execute_file ("~/.bash_logout", 1);
|
||||
#ifdef SYS_BASH_LOGOUT
|
||||
maybe_execute_file (SYS_BASH_LOGOUT, 1);
|
||||
#endif
|
||||
}
|
||||
}
|
785
builtins/fc.def
Normal file
785
builtins/fc.def
Normal file
|
@ -0,0 +1,785 @@
|
|||
This file is fc.def, from which is created fc.c.
|
||||
It implements the builtin "fc" in Bash.
|
||||
|
||||
Copyright (C) 1987-2021 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 fc.c
|
||||
|
||||
$BUILTIN fc
|
||||
$FUNCTION fc_builtin
|
||||
$DEPENDS_ON HISTORY
|
||||
$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.
|
||||
|
||||
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)
|
||||
|
||||
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>
|
||||
|
||||
#if defined (HISTORY)
|
||||
#if defined (HAVE_SYS_PARAM_H)
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
#include "../bashtypes.h"
|
||||
#include "posixstat.h"
|
||||
#if ! defined(_MINIX) && defined (HAVE_SYS_FILE_H)
|
||||
# include <sys/file.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <chartypes.h>
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
#include <errno.h>
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../builtins.h"
|
||||
#include "../flags.h"
|
||||
#include "../parser.h"
|
||||
#include "../bashhist.h"
|
||||
#include "maxpath.h"
|
||||
#include <readline/history.h>
|
||||
#include "bashgetopt.h"
|
||||
#include "common.h"
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif /* !errno */
|
||||
|
||||
#define HIST_INVALID INT_MIN
|
||||
#define HIST_ERANGE INT_MIN+1
|
||||
#define HIST_NOTFOUND INT_MIN+2
|
||||
|
||||
/* Values for the flags argument to fc_gethnum */
|
||||
#define HN_LISTING 0x01
|
||||
#define HN_FIRST 0x02
|
||||
|
||||
extern int unlink PARAMS((const char *));
|
||||
|
||||
extern FILE *sh_mktmpfp PARAMS((char *, int, char **));
|
||||
|
||||
extern int suppress_debug_trap_verbose;
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* The K*rn shell style fc command (Fix Command) */
|
||||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
/* fc builtin command (fix command) for Bash for those who
|
||||
like K*rn-style history better than csh-style.
|
||||
|
||||
fc [-e ename] [-nlr] [first] [last]
|
||||
|
||||
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 the editor which corresponds to the current readline editing
|
||||
mode, then vi.
|
||||
|
||||
-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).
|
||||
|
||||
fc -e - [pat=rep ...] [command]
|
||||
fc -s [pat=rep ...] [command]
|
||||
|
||||
Equivalent to !command:sg/pat/rep execpt there can be multiple PAT=REP's.
|
||||
*/
|
||||
|
||||
/* Data structure describing a list of global replacements to perform. */
|
||||
typedef struct repl {
|
||||
struct repl *next;
|
||||
char *pat;
|
||||
char *rep;
|
||||
} REPL;
|
||||
|
||||
/* Accessors for HIST_ENTRY lists that are called HLIST. */
|
||||
#define histline(i) (hlist[(i)]->line)
|
||||
#define histdata(i) (hlist[(i)]->data)
|
||||
|
||||
#define FREE_RLIST() \
|
||||
do { \
|
||||
for (rl = rlist; rl; ) { \
|
||||
REPL *r; \
|
||||
r = rl->next; \
|
||||
if (rl->pat) \
|
||||
free (rl->pat); \
|
||||
if (rl->rep) \
|
||||
free (rl->rep); \
|
||||
free (rl); \
|
||||
rl = r; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static char *fc_dosubs PARAMS((char *, REPL *));
|
||||
static char *fc_gethist PARAMS((char *, HIST_ENTRY **, int));
|
||||
static int fc_gethnum PARAMS((char *, HIST_ENTRY **, int));
|
||||
static int fc_number PARAMS((WORD_LIST *));
|
||||
static void fc_replhist PARAMS((char *));
|
||||
#ifdef INCLUDE_UNUSED
|
||||
static char *fc_readline PARAMS((FILE *));
|
||||
static void fc_addhist PARAMS((char *));
|
||||
#endif
|
||||
|
||||
static void
|
||||
set_verbose_flag ()
|
||||
{
|
||||
echo_input_at_read = verbose_flag;
|
||||
}
|
||||
|
||||
/* String to execute on a file that we want to edit. */
|
||||
#define FC_EDIT_COMMAND "${FCEDIT:-${EDITOR:-vi}}"
|
||||
#if defined (STRICT_POSIX)
|
||||
# define POSIX_FC_EDIT_COMMAND "${FCEDIT:-ed}"
|
||||
#else
|
||||
# define POSIX_FC_EDIT_COMMAND "${FCEDIT:-${EDITOR:-ed}}"
|
||||
#endif
|
||||
|
||||
int
|
||||
fc_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
register int i;
|
||||
register char *sep;
|
||||
int numbering, reverse, listing, execute;
|
||||
int histbeg, histend, last_hist, retval, opt, rh, real_last;
|
||||
FILE *stream;
|
||||
REPL *rlist, *rl;
|
||||
char *ename, *command, *newcom, *fcedit;
|
||||
HIST_ENTRY **hlist;
|
||||
char *fn;
|
||||
|
||||
numbering = 1;
|
||||
reverse = listing = execute = 0;
|
||||
ename = (char *)NULL;
|
||||
|
||||
/* Parse out the options and set which of the two forms we're in. */
|
||||
reset_internal_getopt ();
|
||||
lcurrent = list; /* XXX */
|
||||
while (fc_number (loptend = lcurrent) == 0 &&
|
||||
(opt = internal_getopt (list, ":e:lnrs")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'n':
|
||||
numbering = 0;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
listing = HN_LISTING; /* for fc_gethnum */
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
reverse = 1;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
execute = 1;
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
ename = list_optarg;
|
||||
break;
|
||||
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
|
||||
list = loptend;
|
||||
|
||||
if (ename && (*ename == '-') && (ename[1] == '\0'))
|
||||
execute = 1;
|
||||
|
||||
/* The "execute" form of the command (re-run, with possible string
|
||||
substitutions). */
|
||||
if (execute)
|
||||
{
|
||||
rlist = (REPL *)NULL;
|
||||
while (list && ((sep = (char *)strchr (list->word->word, '=')) != NULL))
|
||||
{
|
||||
*sep++ = '\0';
|
||||
rl = (REPL *)xmalloc (sizeof (REPL));
|
||||
rl->next = (REPL *)NULL;
|
||||
rl->pat = savestring (list->word->word);
|
||||
rl->rep = savestring (sep);
|
||||
|
||||
if (rlist == NULL)
|
||||
rlist = rl;
|
||||
else
|
||||
{
|
||||
rl->next = rlist;
|
||||
rlist = rl;
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
/* If we have a list of substitutions to do, then reverse it
|
||||
to get the replacements in the proper order. */
|
||||
|
||||
rlist = REVERSE_LIST (rlist, REPL *);
|
||||
|
||||
hlist = history_list ();
|
||||
|
||||
/* If we still have something in list, it is a command spec.
|
||||
Otherwise, we use the most recent command in time. */
|
||||
command = fc_gethist (list ? list->word->word : (char *)NULL, hlist, 0);
|
||||
|
||||
if (command == NULL)
|
||||
{
|
||||
builtin_error (_("no command found"));
|
||||
if (rlist)
|
||||
FREE_RLIST ();
|
||||
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (rlist)
|
||||
{
|
||||
newcom = fc_dosubs (command, rlist);
|
||||
free (command);
|
||||
FREE_RLIST ();
|
||||
command = newcom;
|
||||
}
|
||||
|
||||
fprintf (stderr, "%s\n", command);
|
||||
fc_replhist (command); /* replace `fc -s' with command */
|
||||
/* Posix says that the re-executed commands should be entered into the
|
||||
history. */
|
||||
return (parse_and_execute (command, "fc", SEVAL_NOHIST));
|
||||
}
|
||||
|
||||
/* This is the second form of the command (the list-or-edit-and-rerun
|
||||
form). */
|
||||
hlist = history_list ();
|
||||
if (hlist == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
for (i = 0; hlist[i]; i++);
|
||||
|
||||
/* With the Bash implementation of history, the current command line
|
||||
("fc blah..." and so on) is already part of the history list by
|
||||
the time we get to this point. This just skips over that command
|
||||
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. */
|
||||
|
||||
/* Even though command substitution through parse_and_execute turns off
|
||||
remember_on_history, command substitution in a shell when set -o history
|
||||
has been enabled (interactive or not) should use it in the last_hist
|
||||
calculation as if it were on. */
|
||||
rh = remember_on_history || ((subshell_environment & SUBSHELL_COMSUB) && enable_history_list);
|
||||
last_hist = i - rh - hist_last_line_added;
|
||||
|
||||
/* Make sure that real_last is calculated the same way here and in
|
||||
fc_gethnum. The return value from fc_gethnum is treated specially if
|
||||
it is == real_last and we are listing commands. */
|
||||
real_last = i;
|
||||
/* back up from the end to the last non-null history entry */
|
||||
while (hlist[real_last] == 0 && real_last > 0)
|
||||
real_last--;
|
||||
|
||||
/* XXX */
|
||||
if (i == last_hist && hlist[last_hist] == 0)
|
||||
while (last_hist >= 0 && hlist[last_hist] == 0)
|
||||
last_hist--;
|
||||
if (last_hist < 0)
|
||||
last_hist = 0; /* per POSIX */
|
||||
|
||||
if (list)
|
||||
{
|
||||
histbeg = fc_gethnum (list->word->word, hlist, listing|HN_FIRST);
|
||||
list = list->next;
|
||||
|
||||
if (list)
|
||||
histend = fc_gethnum (list->word->word, hlist, listing);
|
||||
else if (histbeg == real_last)
|
||||
histend = listing ? real_last : histbeg;
|
||||
else
|
||||
histend = listing ? last_hist : histbeg;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The default for listing is the last 16 history items. */
|
||||
if (listing)
|
||||
{
|
||||
histend = last_hist;
|
||||
histbeg = histend - 16 + 1; /* +1 because loop below uses >= */
|
||||
if (histbeg < 0)
|
||||
histbeg = 0;
|
||||
}
|
||||
else
|
||||
/* For editing, it is the last history command. */
|
||||
histbeg = histend = last_hist;
|
||||
}
|
||||
|
||||
if (histbeg == HIST_INVALID || histend == HIST_INVALID)
|
||||
{
|
||||
sh_erange ((char *)NULL, _("history specification"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else if (histbeg == HIST_ERANGE || histend == HIST_ERANGE)
|
||||
{
|
||||
sh_erange ((char *)NULL, _("history specification"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else if (histbeg == HIST_NOTFOUND || histend == HIST_NOTFOUND)
|
||||
{
|
||||
builtin_error (_("no command found"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
/* We don't throw an error for line specifications out of range, per POSIX */
|
||||
if (histbeg < 0)
|
||||
histbeg = 0;
|
||||
if (histend < 0)
|
||||
histend = 0;
|
||||
|
||||
/* "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;
|
||||
|
||||
if (hlist[last_hist] == 0)
|
||||
last_hist--;
|
||||
if (histend >= last_hist)
|
||||
histend = last_hist;
|
||||
else if (histbeg >= last_hist)
|
||||
histbeg = last_hist;
|
||||
}
|
||||
|
||||
if (histbeg == HIST_INVALID || histend == HIST_INVALID)
|
||||
{
|
||||
sh_erange ((char *)NULL, _("history specification"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else if (histbeg == HIST_ERANGE || histend == HIST_ERANGE)
|
||||
{
|
||||
sh_erange ((char *)NULL, _("history specification"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else if (histbeg == HIST_NOTFOUND || histend == HIST_NOTFOUND)
|
||||
{
|
||||
builtin_error (_("no command found"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
/* We don't throw an error for line specifications out of range, per POSIX */
|
||||
if (histbeg < 0)
|
||||
histbeg = 0;
|
||||
if (histend < 0)
|
||||
histend = 0;
|
||||
|
||||
if (histend < histbeg)
|
||||
{
|
||||
i = histend;
|
||||
histend = histbeg;
|
||||
histbeg = i;
|
||||
|
||||
reverse = 1;
|
||||
}
|
||||
|
||||
if (listing)
|
||||
stream = stdout;
|
||||
else
|
||||
{
|
||||
numbering = 0;
|
||||
stream = sh_mktmpfp ("bash-fc", MT_USERANDOM|MT_USETMPDIR, &fn);
|
||||
if (stream == 0)
|
||||
{
|
||||
builtin_error (_("%s: cannot open temp file: %s"), fn ? fn : "", strerror (errno));
|
||||
FREE (fn);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = reverse ? histend : histbeg; reverse ? i >= histbeg : i <= histend; reverse ? i-- : i++)
|
||||
{
|
||||
QUIT;
|
||||
if (hlist[i] == 0)
|
||||
continue;
|
||||
if (numbering)
|
||||
fprintf (stream, "%d", i + history_base);
|
||||
if (listing)
|
||||
{
|
||||
if (posixly_correct)
|
||||
fputs ("\t", stream);
|
||||
else
|
||||
fprintf (stream, "\t%c", histdata (i) ? '*' : ' ');
|
||||
}
|
||||
if (histline (i))
|
||||
fprintf (stream, "%s\n", histline (i));
|
||||
}
|
||||
|
||||
if (listing)
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
|
||||
fflush (stream);
|
||||
if (ferror (stream))
|
||||
{
|
||||
sh_wrerror ();
|
||||
fclose (stream);
|
||||
FREE (fn);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
fclose (stream);
|
||||
|
||||
/* Now edit the file of commands. */
|
||||
if (ename)
|
||||
{
|
||||
command = (char *)xmalloc (strlen (ename) + strlen (fn) + 2);
|
||||
sprintf (command, "%s %s", ename, fn);
|
||||
}
|
||||
else
|
||||
{
|
||||
fcedit = posixly_correct ? POSIX_FC_EDIT_COMMAND : FC_EDIT_COMMAND;
|
||||
command = (char *)xmalloc (3 + strlen (fcedit) + strlen (fn));
|
||||
sprintf (command, "%s %s", fcedit, fn);
|
||||
}
|
||||
retval = parse_and_execute (command, "fc", SEVAL_NOHIST);
|
||||
if (retval != EXECUTION_SUCCESS)
|
||||
{
|
||||
unlink (fn);
|
||||
free (fn);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
#if defined (READLINE)
|
||||
/* If we're executing as part of a dispatched readline command like
|
||||
{emacs,vi}_edit_and_execute_command, the readline state will indicate it.
|
||||
We could remove the partial command from the history, but ksh93 doesn't
|
||||
so we stay compatible. */
|
||||
#endif
|
||||
|
||||
/* Make sure parse_and_execute doesn't turn this off, even though a
|
||||
call to parse_and_execute farther up the function call stack (e.g.,
|
||||
if this is called by vi_edit_and_execute_command) may have already
|
||||
called bash_history_disable. */
|
||||
remember_on_history = 1;
|
||||
|
||||
/* Turn on the `v' flag while fc_execute_file runs so the commands
|
||||
will be echoed as they are read by the parser. */
|
||||
begin_unwind_frame ("fc builtin");
|
||||
add_unwind_protect (xfree, fn);
|
||||
add_unwind_protect (unlink, fn);
|
||||
add_unwind_protect (set_verbose_flag, (char *)NULL);
|
||||
unwind_protect_int (suppress_debug_trap_verbose);
|
||||
echo_input_at_read = 1;
|
||||
suppress_debug_trap_verbose = 1;
|
||||
|
||||
retval = fc_execute_file (fn);
|
||||
run_unwind_frame ("fc builtin");
|
||||
|
||||
return (retval);
|
||||
}
|
||||
|
||||
/* Return 1 if LIST->word->word is a legal number for fc's use. */
|
||||
static int
|
||||
fc_number (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
char *s;
|
||||
|
||||
if (list == 0)
|
||||
return 0;
|
||||
s = list->word->word;
|
||||
if (*s == '-')
|
||||
s++;
|
||||
return (legal_number (s, (intmax_t *)NULL));
|
||||
}
|
||||
|
||||
/* Return an absolute index into HLIST which corresponds to COMMAND. If
|
||||
COMMAND is a number, then it was specified in relative terms. If it
|
||||
is a string, then it is the start of a command line present in HLIST.
|
||||
MODE includes HN_LISTING if we are listing commands, and does not if we
|
||||
are executing them. If MODE includes HN_FIRST we are looking for the
|
||||
first history number specification. */
|
||||
static int
|
||||
fc_gethnum (command, hlist, mode)
|
||||
char *command;
|
||||
HIST_ENTRY **hlist;
|
||||
int mode;
|
||||
{
|
||||
int sign, n, clen, rh;
|
||||
register int i, j, last_hist, real_last, listing;
|
||||
register char *s;
|
||||
|
||||
listing = mode & HN_LISTING;
|
||||
sign = 1;
|
||||
/* Count history elements. */
|
||||
for (i = 0; hlist[i]; i++);
|
||||
|
||||
/* With the Bash implementation of history, the current command line
|
||||
("fc blah..." and so on) is already part of the history list by
|
||||
the time we get to this point. This just skips over that command
|
||||
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. This needs to agree with the
|
||||
calculation of last_hist in fc_builtin above. */
|
||||
/* Even though command substitution through parse_and_execute turns off
|
||||
remember_on_history, command substitution in a shell when set -o history
|
||||
has been enabled (interactive or not) should use it in the last_hist
|
||||
calculation as if it were on. */
|
||||
rh = remember_on_history || ((subshell_environment & SUBSHELL_COMSUB) && enable_history_list);
|
||||
last_hist = i - rh - hist_last_line_added;
|
||||
|
||||
if (i == last_hist && hlist[last_hist] == 0)
|
||||
while (last_hist >= 0 && hlist[last_hist] == 0)
|
||||
last_hist--;
|
||||
if (last_hist < 0)
|
||||
return (-1);
|
||||
|
||||
real_last = i;
|
||||
i = last_hist;
|
||||
|
||||
/* No specification defaults to most recent command. */
|
||||
if (command == NULL)
|
||||
return (i);
|
||||
|
||||
/* back up from the end to the last non-null history entry */
|
||||
while (hlist[real_last] == 0 && real_last > 0)
|
||||
real_last--;
|
||||
|
||||
/* Otherwise, there is a specification. It can be a number relative to
|
||||
the current position, or an absolute history number. */
|
||||
s = command;
|
||||
|
||||
/* Handle possible leading minus sign. */
|
||||
if (s && (*s == '-'))
|
||||
{
|
||||
sign = -1;
|
||||
s++;
|
||||
}
|
||||
|
||||
if (s && DIGIT(*s))
|
||||
{
|
||||
n = atoi (s);
|
||||
n *= sign;
|
||||
|
||||
/* We want to return something that is an offset to HISTORY_BASE. */
|
||||
|
||||
/* If the value is negative or zero, then it is an offset from
|
||||
the current history item. */
|
||||
/* We don't use HN_FIRST here, so we don't return different values
|
||||
depending on whether we're looking for the first or last in a
|
||||
pair of range arguments, but nobody else does, either. */
|
||||
if (n < 0)
|
||||
{
|
||||
n += i + 1;
|
||||
return (n < 0 ? 0 : n);
|
||||
}
|
||||
else if (n == 0)
|
||||
return ((sign == -1) ? (listing ? real_last : HIST_INVALID) : i);
|
||||
else
|
||||
{
|
||||
/* If we're out of range (greater than I (last history entry) or
|
||||
less than HISTORY_BASE, we want to return different values
|
||||
based on whether or not we are looking for the first or last
|
||||
value in a desired range of history entries. */
|
||||
n -= history_base;
|
||||
if (n < 0)
|
||||
return (mode & HN_FIRST ? 0 : i);
|
||||
else if (n >= i)
|
||||
return (mode & HN_FIRST ? 0 : i);
|
||||
else
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
clen = strlen (command);
|
||||
for (j = i; j >= 0; j--)
|
||||
{
|
||||
if (STREQN (command, histline (j), clen))
|
||||
return (j);
|
||||
}
|
||||
return (HIST_NOTFOUND);
|
||||
}
|
||||
|
||||
/* Locate the most recent history line which begins with
|
||||
COMMAND in HLIST, and return a malloc()'ed copy of it.
|
||||
MODE is 1 if we are listing commands, 0 if we are executing them. */
|
||||
static char *
|
||||
fc_gethist (command, hlist, mode)
|
||||
char *command;
|
||||
HIST_ENTRY **hlist;
|
||||
int mode;
|
||||
{
|
||||
int i;
|
||||
|
||||
if (hlist == 0)
|
||||
return ((char *)NULL);
|
||||
|
||||
i = fc_gethnum (command, hlist, mode);
|
||||
|
||||
if (i >= 0)
|
||||
return (savestring (histline (i)));
|
||||
else
|
||||
return ((char *)NULL);
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_UNUSED
|
||||
/* Read the edited history lines from STREAM and return them
|
||||
one at a time. This can read unlimited length lines. The
|
||||
caller should free the storage. */
|
||||
static char *
|
||||
fc_readline (stream)
|
||||
FILE *stream;
|
||||
{
|
||||
register int c;
|
||||
int line_len = 0, lindex = 0;
|
||||
char *line = (char *)NULL;
|
||||
|
||||
while ((c = getc (stream)) != EOF)
|
||||
{
|
||||
if ((lindex + 2) >= line_len)
|
||||
line = (char *)xrealloc (line, (line_len += 128));
|
||||
|
||||
if (c == '\n')
|
||||
{
|
||||
line[lindex++] = '\n';
|
||||
line[lindex++] = '\0';
|
||||
return (line);
|
||||
}
|
||||
else
|
||||
line[lindex++] = c;
|
||||
}
|
||||
|
||||
if (!lindex)
|
||||
{
|
||||
if (line)
|
||||
free (line);
|
||||
|
||||
return ((char *)NULL);
|
||||
}
|
||||
|
||||
if (lindex + 2 >= line_len)
|
||||
line = (char *)xrealloc (line, lindex + 3);
|
||||
|
||||
line[lindex++] = '\n'; /* Finish with newline if none in file */
|
||||
line[lindex++] = '\0';
|
||||
return (line);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Perform the SUBS on COMMAND.
|
||||
SUBS is a list of substitutions, and COMMAND is a simple string.
|
||||
Return a pointer to a malloc'ed string which contains the substituted
|
||||
command. */
|
||||
static char *
|
||||
fc_dosubs (command, subs)
|
||||
char *command;
|
||||
REPL *subs;
|
||||
{
|
||||
register char *new, *t;
|
||||
register REPL *r;
|
||||
|
||||
for (new = savestring (command), r = subs; r; r = r->next)
|
||||
{
|
||||
t = strsub (new, r->pat, r->rep, 1);
|
||||
free (new);
|
||||
new = t;
|
||||
}
|
||||
return (new);
|
||||
}
|
||||
|
||||
/* Use `command' to replace the last entry in the history list, which,
|
||||
by this time, is `fc blah...'. The intent is that the new command
|
||||
become the history entry, and that `fc' should never appear in the
|
||||
history list. This way you can do `r' to your heart's content. */
|
||||
static void
|
||||
fc_replhist (command)
|
||||
char *command;
|
||||
{
|
||||
int n;
|
||||
|
||||
if (command == 0 || *command == '\0')
|
||||
return;
|
||||
|
||||
n = strlen (command);
|
||||
if (command[n - 1] == '\n')
|
||||
command[n - 1] = '\0';
|
||||
|
||||
if (command && *command)
|
||||
{
|
||||
bash_delete_last_history ();
|
||||
maybe_add_history (command); /* Obeys HISTCONTROL setting. */
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_UNUSED
|
||||
/* Add LINE to the history, after removing a single trailing newline. */
|
||||
static void
|
||||
fc_addhist (line)
|
||||
char *line;
|
||||
{
|
||||
register int n;
|
||||
|
||||
if (line == 0 || *line == 0)
|
||||
return;
|
||||
|
||||
n = strlen (line);
|
||||
|
||||
if (line[n - 1] == '\n')
|
||||
line[n - 1] = '\0';
|
||||
|
||||
if (line && *line)
|
||||
maybe_add_history (line); /* Obeys HISTCONTROL setting. */
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HISTORY */
|
189
builtins/fg_bg.def
Normal file
189
builtins/fg_bg.def
Normal file
|
@ -0,0 +1,189 @@
|
|||
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-2020 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 fg_bg.c
|
||||
|
||||
$BUILTIN fg
|
||||
$FUNCTION fg_builtin
|
||||
$DEPENDS_ON JOB_CONTROL
|
||||
$SHORT_DOC fg [job_spec]
|
||||
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>
|
||||
|
||||
#include "../bashtypes.h"
|
||||
#include <signal.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "../jobs.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
static int fg_bg PARAMS((WORD_LIST *, int));
|
||||
|
||||
/* How to bring a job into the foreground. */
|
||||
int
|
||||
fg_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int fg_bit;
|
||||
register WORD_LIST *t;
|
||||
|
||||
CHECK_HELPOPT (list);
|
||||
|
||||
if (job_control == 0)
|
||||
{
|
||||
sh_nojobs ((char *)NULL);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (no_options (list))
|
||||
return (EX_USAGE);
|
||||
list = loptend;
|
||||
|
||||
/* If the last arg on the line is '&', then start this job in the
|
||||
background. Else, fg the job. */
|
||||
for (t = list; t && t->next; t = t->next)
|
||||
;
|
||||
fg_bit = (t && t->word->word[0] == '&' && t->word->word[1] == '\0') == 0;
|
||||
|
||||
return (fg_bg (list, fg_bit));
|
||||
}
|
||||
#endif /* JOB_CONTROL */
|
||||
|
||||
$BUILTIN bg
|
||||
$FUNCTION bg_builtin
|
||||
$DEPENDS_ON JOB_CONTROL
|
||||
$SHORT_DOC bg [job_spec ...]
|
||||
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)
|
||||
/* How to put a job into the background. */
|
||||
int
|
||||
bg_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int r;
|
||||
|
||||
CHECK_HELPOPT (list);
|
||||
|
||||
if (job_control == 0)
|
||||
{
|
||||
sh_nojobs ((char *)NULL);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (no_options (list))
|
||||
return (EX_USAGE);
|
||||
list = loptend;
|
||||
|
||||
/* This relies on the fact that fg_bg() takes a WORD_LIST *, but only acts
|
||||
on the first member (if any) of that list. */
|
||||
r = EXECUTION_SUCCESS;
|
||||
do
|
||||
{
|
||||
if (fg_bg (list, 0) == EXECUTION_FAILURE)
|
||||
r = EXECUTION_FAILURE;
|
||||
if (list)
|
||||
list = list->next;
|
||||
}
|
||||
while (list);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* How to put a job into the foreground/background. */
|
||||
static int
|
||||
fg_bg (list, foreground)
|
||||
WORD_LIST *list;
|
||||
int foreground;
|
||||
{
|
||||
sigset_t set, oset;
|
||||
int job, status, old_async_pid;
|
||||
JOB *j;
|
||||
|
||||
BLOCK_CHILD (set, oset);
|
||||
job = get_job_spec (list);
|
||||
|
||||
if (INVALID_JOB (job))
|
||||
{
|
||||
if (job != DUP_JOB)
|
||||
sh_badjob (list ? list->word->word : _("current"));
|
||||
|
||||
goto failure;
|
||||
}
|
||||
|
||||
j = get_job_by_jid (job);
|
||||
/* Or if j->pgrp == shell_pgrp. */
|
||||
if (IS_JOBCONTROL (job) == 0)
|
||||
{
|
||||
builtin_error (_("job %d started without job control"), job + 1);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
if (foreground == 0)
|
||||
{
|
||||
old_async_pid = last_asynchronous_pid;
|
||||
last_asynchronous_pid = j->pgrp; /* As per Posix.2 5.4.2 */
|
||||
}
|
||||
|
||||
status = start_job (job, foreground);
|
||||
|
||||
if (status >= 0)
|
||||
{
|
||||
/* win: */
|
||||
UNBLOCK_CHILD (oset);
|
||||
return (foreground ? status : EXECUTION_SUCCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (foreground == 0)
|
||||
last_asynchronous_pid = old_async_pid;
|
||||
|
||||
failure:
|
||||
UNBLOCK_CHILD (oset);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
#endif /* JOB_CONTROL */
|
198
builtins/gen-helpfiles.c
Normal file
198
builtins/gen-helpfiles.c
Normal file
|
@ -0,0 +1,198 @@
|
|||
/* gen-helpfiles - create files containing builtin help text */
|
||||
|
||||
/* Copyright (C) 2012-2021 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/>.
|
||||
*/
|
||||
|
||||
/* This links with a specially-generated version of builtins.c and takes
|
||||
the long_doc members of each struct builtin element and writes those to
|
||||
the file named by the `handle' member of the struct builtin element. */
|
||||
|
||||
#if !defined (CROSS_COMPILING)
|
||||
# include <config.h>
|
||||
#else /* CROSS_COMPILING */
|
||||
/* A conservative set of defines based on POSIX/SUS3/XPG6 */
|
||||
# define HAVE_UNISTD_H
|
||||
# define HAVE_STRING_H
|
||||
# define HAVE_STDLIB_H
|
||||
|
||||
# define HAVE_RENAME
|
||||
#endif /* CROSS_COMPILING */
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifndef _MINIX
|
||||
# include "../bashtypes.h"
|
||||
# if defined (HAVE_SYS_FILE_H)
|
||||
# include <sys/file.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "posixstat.h"
|
||||
#include "filecntl.h"
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "stdc.h"
|
||||
|
||||
#include "../builtins.h"
|
||||
#include "tmpbuiltins.h"
|
||||
|
||||
#if defined (USING_BASH_MALLOC)
|
||||
#undef xmalloc
|
||||
#undef xrealloc
|
||||
#undef xfree
|
||||
|
||||
#undef malloc
|
||||
#undef free /* defined in xmalloc.h */
|
||||
#endif
|
||||
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#if !defined (__STDC__) && !defined (strcpy)
|
||||
extern char *strcpy ();
|
||||
#endif /* !__STDC__ && !strcpy */
|
||||
|
||||
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
|
||||
|
||||
/* 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
|
||||
|
||||
/* Non-zero means to produce separate help files for each builtin, named by
|
||||
the builtin name, in `./helpfiles'. */
|
||||
int separate_helpfiles = 0;
|
||||
|
||||
/* Non-zero means to create single C strings for each `longdoc', with
|
||||
embedded newlines, for ease of translation. */
|
||||
int single_longdoc_strings = 1;
|
||||
|
||||
/* The name of a directory into which the separate external help files will
|
||||
eventually be installed. */
|
||||
char *helpfile_directory;
|
||||
|
||||
/* Forward declarations. */
|
||||
|
||||
int write_helpfiles PARAMS((struct builtin *));
|
||||
|
||||
/* For each file mentioned on the command line, process it and
|
||||
write the information to STRUCTFILE and EXTERNFILE, while
|
||||
creating the production file if necessary. */
|
||||
int
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int arg_index = 1;
|
||||
|
||||
while (arg_index < argc && argv[arg_index][0] == '-')
|
||||
{
|
||||
char *arg = argv[arg_index++];
|
||||
|
||||
if (strcmp (arg, "-noproduction") == 0)
|
||||
;
|
||||
else if (strcmp (arg, "-H") == 0)
|
||||
helpfile_directory = argv[arg_index++];
|
||||
else if (strcmp (arg, "-S") == 0)
|
||||
single_longdoc_strings = 0;
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "%s: Unknown flag %s.\n", argv[0], arg);
|
||||
exit (2);
|
||||
}
|
||||
}
|
||||
|
||||
write_helpfiles(shell_builtins);
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
||||
/* Write DOCUMENTATION to STREAM, perhaps surrounding it with double-quotes
|
||||
and quoting special characters in the string. Handle special things for
|
||||
internationalization (gettext) and the single-string vs. multiple-strings
|
||||
issues. */
|
||||
void
|
||||
write_documentation (stream, documentation, indentation)
|
||||
FILE *stream;
|
||||
char *documentation;
|
||||
int indentation;
|
||||
{
|
||||
if (stream == 0)
|
||||
return;
|
||||
|
||||
if (documentation)
|
||||
fprintf (stream, "%*s%s\n", indentation, " ", documentation);
|
||||
}
|
||||
|
||||
int
|
||||
write_helpfiles (builtins)
|
||||
struct builtin *builtins;
|
||||
{
|
||||
char *helpfile, *bname, *fname;
|
||||
FILE *helpfp;
|
||||
int i, hdlen;
|
||||
struct builtin b;
|
||||
|
||||
i = mkdir ("helpfiles", 0777);
|
||||
if (i < 0 && errno != EEXIST)
|
||||
{
|
||||
fprintf (stderr, "write_helpfiles: helpfiles: cannot create directory\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
hdlen = strlen ("helpfiles/");
|
||||
for (i = 0; i < num_shell_builtins; i++)
|
||||
{
|
||||
b = builtins[i];
|
||||
|
||||
fname = (char *)b.handle;
|
||||
helpfile = (char *)malloc (hdlen + strlen (fname) + 1);
|
||||
if (helpfile == 0)
|
||||
{
|
||||
fprintf (stderr, "gen-helpfiles: cannot allocate memory\n");
|
||||
exit (1);
|
||||
}
|
||||
sprintf (helpfile, "helpfiles/%s", fname);
|
||||
|
||||
helpfp = fopen (helpfile, "w");
|
||||
if (helpfp == 0)
|
||||
{
|
||||
fprintf (stderr, "write_helpfiles: cannot open %s\n", helpfile);
|
||||
free (helpfile);
|
||||
continue;
|
||||
}
|
||||
|
||||
write_documentation (helpfp, b.long_doc[0], 4);
|
||||
|
||||
fflush (helpfp);
|
||||
fclose (helpfp);
|
||||
free (helpfile);
|
||||
}
|
||||
return 0;
|
||||
}
|
355
builtins/getopt.c
Normal file
355
builtins/getopt.c
Normal file
|
@ -0,0 +1,355 @@
|
|||
/* getopt.c - getopt for Bash. Used by the getopt builtin. */
|
||||
|
||||
/* Copyright (C) 1993-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/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "memalloc.h"
|
||||
#include "../bashintl.h"
|
||||
#include "../shell.h"
|
||||
#include "getopt.h"
|
||||
|
||||
/* For communication from `sh_getopt' to the caller.
|
||||
When `sh_getopt' finds an option that takes an argument,
|
||||
the argument value is returned here. */
|
||||
char *sh_optarg = 0;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to `sh_getopt'.
|
||||
|
||||
On entry to `sh_getopt', zero means this is the first call; initialize.
|
||||
|
||||
When `sh_getopt' returns EOF, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `sh_optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
/* XXX 1003.2 says this must be 1 before any call. */
|
||||
int sh_optind = 0;
|
||||
|
||||
/* Index of the current argument. */
|
||||
static int sh_curopt;
|
||||
|
||||
/* The next char to be scanned in the option-element
|
||||
in which the last option character we returned was found.
|
||||
This allows us to pick up the scan where we left off.
|
||||
|
||||
If this is zero, or a null string, it means resume the scan
|
||||
by advancing to the next ARGV-element. */
|
||||
|
||||
static char *nextchar;
|
||||
static int sh_charindex;
|
||||
|
||||
/* Callers store zero here to inhibit the error message
|
||||
for unrecognized options. */
|
||||
|
||||
int sh_opterr = 1;
|
||||
|
||||
/* Set to an option character which was unrecognized.
|
||||
This must be initialized on some systems to avoid linking in the
|
||||
system's own getopt implementation. */
|
||||
|
||||
int sh_optopt = '?';
|
||||
|
||||
/* Set to 1 when we see an invalid option; public so getopts can reset it. */
|
||||
int sh_badopt = 0;
|
||||
|
||||
/* Scan elements of ARGV (whose length is ARGC) for option characters
|
||||
given in OPTSTRING.
|
||||
|
||||
If an element of ARGV starts with '-', and is not exactly "-" or "--",
|
||||
then it is an option element. The characters of this element
|
||||
(aside from the initial '-') are option characters. If `sh_getopt'
|
||||
is called repeatedly, it returns successively each of the option characters
|
||||
from each of the option elements.
|
||||
|
||||
If `sh_getopt' finds another option character, it returns that character,
|
||||
updating `sh_optind' and `nextchar' so that the next call to `sh_getopt' can
|
||||
resume the scan with the following option character or ARGV-element.
|
||||
|
||||
If there are no more option characters, `sh_getopt' returns `EOF'.
|
||||
Then `sh_optind' is the index in ARGV of the first ARGV-element
|
||||
that is not an option.
|
||||
|
||||
OPTSTRING is a string containing the legitimate option characters.
|
||||
If an option character is seen that is not listed in OPTSTRING,
|
||||
return '?' after printing an error message. If you set `sh_opterr' to
|
||||
zero, the error message is suppressed but we still return '?'.
|
||||
|
||||
If a char in OPTSTRING is followed by a colon, that means it wants an arg,
|
||||
so the following text in the same ARGV-element, or the text of the following
|
||||
ARGV-element, is returned in `sh_optarg'. */
|
||||
|
||||
/* 1003.2 specifies the format of this message. */
|
||||
#define BADOPT(x) fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], x)
|
||||
#define NEEDARG(x) fprintf (stderr, _("%s: option requires an argument -- %c\n"), argv[0], x)
|
||||
|
||||
int
|
||||
sh_getopt (argc, argv, optstring)
|
||||
int argc;
|
||||
char *const *argv;
|
||||
const char *optstring;
|
||||
{
|
||||
char c, *temp;
|
||||
|
||||
sh_optarg = 0;
|
||||
|
||||
if (sh_optind >= argc || sh_optind < 0) /* XXX was sh_optind > argc */
|
||||
{
|
||||
sh_optind = argc;
|
||||
return (EOF);
|
||||
}
|
||||
|
||||
/* Initialize the internal data when the first call is made.
|
||||
Start processing options with ARGV-element 1 (since ARGV-element 0
|
||||
is the program name); the sequence of previously skipped
|
||||
non-option ARGV-elements is empty. */
|
||||
|
||||
if (sh_optind == 0)
|
||||
{
|
||||
sh_optind = 1;
|
||||
nextchar = (char *)NULL;
|
||||
}
|
||||
|
||||
if (nextchar == 0 || *nextchar == '\0')
|
||||
{
|
||||
/* If we have done all the ARGV-elements, stop the scan. */
|
||||
if (sh_optind >= argc)
|
||||
return EOF;
|
||||
|
||||
temp = argv[sh_optind];
|
||||
|
||||
/* Special ARGV-element `--' means premature end of options.
|
||||
Skip it like a null option, and return EOF. */
|
||||
if (temp[0] == '-' && temp[1] == '-' && temp[2] == '\0')
|
||||
{
|
||||
sh_optind++;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
/* If we have come to a non-option, either stop the scan or describe
|
||||
it to the caller and pass it by. This makes the pseudo-option
|
||||
`-' mean the end of options, but does not skip over it. */
|
||||
if (temp[0] != '-' || temp[1] == '\0')
|
||||
return EOF;
|
||||
|
||||
/* We have found another option-ARGV-element.
|
||||
Start decoding its characters. */
|
||||
nextchar = argv[sh_curopt = sh_optind] + 1;
|
||||
sh_charindex = 1;
|
||||
}
|
||||
|
||||
/* Look at and handle the next option-character. */
|
||||
|
||||
c = *nextchar++; sh_charindex++;
|
||||
temp = strchr (optstring, c);
|
||||
|
||||
sh_optopt = c;
|
||||
|
||||
/* Increment `sh_optind' when we start to process its last character. */
|
||||
if (nextchar == 0 || *nextchar == '\0')
|
||||
{
|
||||
sh_optind++;
|
||||
nextchar = (char *)NULL;
|
||||
}
|
||||
|
||||
if (sh_badopt = (temp == NULL || c == ':'))
|
||||
{
|
||||
if (sh_opterr)
|
||||
BADOPT (c);
|
||||
|
||||
return '?';
|
||||
}
|
||||
|
||||
if (temp[1] == ':')
|
||||
{
|
||||
if (nextchar && *nextchar)
|
||||
{
|
||||
/* This is an option that requires an argument. */
|
||||
sh_optarg = nextchar;
|
||||
/* If we end this ARGV-element by taking the rest as an arg,
|
||||
we must advance to the next element now. */
|
||||
sh_optind++;
|
||||
}
|
||||
else if (sh_optind == argc)
|
||||
{
|
||||
if (sh_opterr)
|
||||
NEEDARG (c);
|
||||
|
||||
sh_optopt = c;
|
||||
sh_optarg = ""; /* Needed by getopts. */
|
||||
c = (optstring[0] == ':') ? ':' : '?';
|
||||
}
|
||||
else
|
||||
/* We already incremented `sh_optind' once;
|
||||
increment it again when taking next ARGV-elt as argument. */
|
||||
sh_optarg = argv[sh_optind++];
|
||||
nextchar = (char *)NULL;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
void
|
||||
sh_getopt_restore_state (argv)
|
||||
char **argv;
|
||||
{
|
||||
if (nextchar)
|
||||
nextchar = argv[sh_curopt] + sh_charindex;
|
||||
}
|
||||
|
||||
sh_getopt_state_t *
|
||||
sh_getopt_alloc_istate ()
|
||||
{
|
||||
sh_getopt_state_t *ret;
|
||||
|
||||
ret = (sh_getopt_state_t *)xmalloc (sizeof (sh_getopt_state_t));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
sh_getopt_dispose_istate (gs)
|
||||
sh_getopt_state_t *gs;
|
||||
{
|
||||
free (gs);
|
||||
}
|
||||
|
||||
sh_getopt_state_t *
|
||||
sh_getopt_save_istate ()
|
||||
{
|
||||
sh_getopt_state_t *ret;
|
||||
|
||||
ret = sh_getopt_alloc_istate ();
|
||||
|
||||
ret->gs_optarg = sh_optarg;
|
||||
ret->gs_optind = sh_optind;
|
||||
ret->gs_curopt = sh_curopt;
|
||||
ret->gs_nextchar = nextchar; /* XXX */
|
||||
ret->gs_charindex = sh_charindex;
|
||||
ret->gs_flags = 0; /* XXX for later use */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
sh_getopt_restore_istate (state)
|
||||
sh_getopt_state_t *state;
|
||||
{
|
||||
sh_optarg = state->gs_optarg;
|
||||
sh_optind = state->gs_optind;
|
||||
sh_curopt = state->gs_curopt;
|
||||
nextchar = state->gs_nextchar; /* XXX - probably not usable */
|
||||
sh_charindex = state->gs_charindex;
|
||||
|
||||
sh_getopt_dispose_istate (state);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void
|
||||
sh_getopt_debug_restore_state (argv)
|
||||
char **argv;
|
||||
{
|
||||
if (nextchar && nextchar != argv[sh_curopt] + sh_charindex)
|
||||
{
|
||||
itrace("sh_getopt_debug_restore_state: resetting nextchar");
|
||||
nextchar = argv[sh_curopt] + sh_charindex;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
/* Compile with -DTEST to make an executable for use in testing
|
||||
the above definition of `sh_getopt'. */
|
||||
|
||||
int
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int c;
|
||||
int digit_sh_optind = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
int this_option_sh_optind = sh_optind ? sh_optind : 1;
|
||||
|
||||
c = sh_getopt (argc, argv, "abc:d:0123456789");
|
||||
if (c == EOF)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if (digit_sh_optind != 0 && digit_sh_optind != this_option_sh_optind)
|
||||
printf ("digits occur in two different argv-elements.\n");
|
||||
digit_sh_optind = this_option_sh_optind;
|
||||
printf ("option %c\n", c);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
printf ("option a\n");
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
printf ("option b\n");
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
printf ("option c with value `%s'\n", sh_optarg);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
break;
|
||||
|
||||
default:
|
||||
printf ("?? sh_getopt returned character code 0%o ??\n", c);
|
||||
}
|
||||
}
|
||||
|
||||
if (sh_optind < argc)
|
||||
{
|
||||
printf ("non-option ARGV-elements: ");
|
||||
while (sh_optind < argc)
|
||||
printf ("%s ", argv[sh_optind++]);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
||||
#endif /* TEST */
|
82
builtins/getopt.h
Normal file
82
builtins/getopt.h
Normal file
|
@ -0,0 +1,82 @@
|
|||
/* getopt.h - declarations for getopt. */
|
||||
|
||||
/* Copyright (C) 1989-2020 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/>.
|
||||
*/
|
||||
|
||||
/* XXX THIS HAS BEEN MODIFIED FOR INCORPORATION INTO BASH XXX */
|
||||
|
||||
#ifndef _SH_GETOPT_H
|
||||
#define _SH_GETOPT_H 1
|
||||
|
||||
#include "stdc.h"
|
||||
|
||||
/* For communication from `getopt' to the caller.
|
||||
When `getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when `ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
|
||||
extern char *sh_optarg;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to `getopt'.
|
||||
|
||||
On entry to `getopt', zero means this is the first call; initialize.
|
||||
|
||||
When `getopt' returns EOF, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `sh_optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
extern int sh_optind;
|
||||
|
||||
/* Callers store zero here to inhibit the error message `getopt' prints
|
||||
for unrecognized options. */
|
||||
|
||||
extern int sh_opterr;
|
||||
|
||||
/* Set to an option character which was unrecognized. */
|
||||
|
||||
extern int sh_optopt;
|
||||
|
||||
/* Set to 1 when an unrecognized option is encountered. */
|
||||
extern int sh_badopt;
|
||||
|
||||
extern int sh_getopt PARAMS((int, char *const *, const char *));
|
||||
|
||||
typedef struct sh_getopt_state
|
||||
{
|
||||
char *gs_optarg;
|
||||
int gs_optind;
|
||||
int gs_curopt;
|
||||
char *gs_nextchar;
|
||||
int gs_charindex;
|
||||
int gs_flags;
|
||||
} sh_getopt_state_t;
|
||||
|
||||
extern void sh_getopt_restore_state PARAMS((char **));
|
||||
|
||||
extern sh_getopt_state_t *sh_getopt_alloc_istate PARAMS((void));
|
||||
extern void sh_getopt_dispose_istate PARAMS((sh_getopt_state_t *));
|
||||
|
||||
extern sh_getopt_state_t *sh_getopt_save_istate PARAMS((void));
|
||||
extern void sh_getopt_restore_istate PARAMS((sh_getopt_state_t *));
|
||||
|
||||
#endif /* _SH_GETOPT_H */
|
343
builtins/getopts.def
Normal file
343
builtins/getopts.def
Normal file
|
@ -0,0 +1,343 @@
|
|||
This file is getopts.def, from which is created getopts.c.
|
||||
It implements the builtin "getopts" in Bash.
|
||||
|
||||
Copyright (C) 1987-2019 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 getopts.c
|
||||
|
||||
$BUILTIN getopts
|
||||
$FUNCTION getopts_builtin
|
||||
$SHORT_DOC getopts optstring name [arg ...]
|
||||
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,
|
||||
which should be separated from it by white space.
|
||||
|
||||
Each time it is invoked, getopts will place the next option in the
|
||||
shell variable $name, initializing name if it does not exist, and
|
||||
the index of the next argument to be processed into the shell
|
||||
variable OPTIND. OPTIND is initialized to 1 each time the shell or
|
||||
a shell script is invoked. When an option requires an argument,
|
||||
getopts places that argument into the shell variable OPTARG.
|
||||
|
||||
getopts reports errors in one of two ways. If the first character
|
||||
of OPTSTRING is a colon, getopts uses silent error reporting. In
|
||||
this mode, no error messages are printed. If an invalid option is
|
||||
seen, getopts places the option character found into OPTARG. If a
|
||||
required argument is not found, getopts places a ':' into NAME and
|
||||
sets OPTARG to the option character found. If getopts is not in
|
||||
silent mode, and an invalid option is seen, getopts places '?' into
|
||||
NAME and unsets OPTARG. If a required argument is not found, a '?'
|
||||
is placed in NAME, OPTARG is unset, and a diagnostic message is
|
||||
printed.
|
||||
|
||||
If the shell variable OPTERR has the value 0, getopts disables the
|
||||
printing of error messages, even if the first character of
|
||||
OPTSTRING is not a colon. OPTERR has the value 1 by default.
|
||||
|
||||
Getopts normally parses the positional parameters, but if arguments
|
||||
are supplied as ARG values, 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>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
#include "getopt.h"
|
||||
|
||||
#define G_EOF -1
|
||||
#define G_INVALID_OPT -2
|
||||
#define G_ARG_MISSING -3
|
||||
|
||||
static int getopts_unbind_variable PARAMS((char *));
|
||||
static int getopts_bind_variable PARAMS((char *, char *));
|
||||
static int dogetopts PARAMS((int, char **));
|
||||
|
||||
/* getopts_reset is magic code for when OPTIND is reset. N is the
|
||||
value that has just been assigned to OPTIND. */
|
||||
void
|
||||
getopts_reset (newind)
|
||||
int newind;
|
||||
{
|
||||
sh_optind = newind;
|
||||
sh_badopt = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
getopts_unbind_variable (name)
|
||||
char *name;
|
||||
{
|
||||
#if 0
|
||||
return (unbind_variable (name));
|
||||
#else
|
||||
return (unbind_variable_noref (name));
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
getopts_bind_variable (name, value)
|
||||
char *name, *value;
|
||||
{
|
||||
SHELL_VAR *v;
|
||||
|
||||
if (legal_identifier (name))
|
||||
{
|
||||
v = bind_variable (name, value, 0);
|
||||
if (v && (readonly_p (v) || noassign_p (v)))
|
||||
return (EX_MISCERROR);
|
||||
return (v ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
|
||||
}
|
||||
else
|
||||
{
|
||||
sh_invalidid (name);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Error handling is now performed as specified by Posix.2, draft 11
|
||||
(identical to that of ksh-88). The special handling is enabled if
|
||||
the first character of the option string is a colon; this handling
|
||||
disables diagnostic messages concerning missing option arguments
|
||||
and invalid option characters. The handling is as follows.
|
||||
|
||||
INVALID OPTIONS:
|
||||
name -> "?"
|
||||
if (special_error) then
|
||||
OPTARG = option character found
|
||||
no error output
|
||||
else
|
||||
OPTARG unset
|
||||
diagnostic message
|
||||
fi
|
||||
|
||||
MISSING OPTION ARGUMENT;
|
||||
if (special_error) then
|
||||
name -> ":"
|
||||
OPTARG = option character found
|
||||
else
|
||||
name -> "?"
|
||||
OPTARG unset
|
||||
diagnostic message
|
||||
fi
|
||||
*/
|
||||
|
||||
static int
|
||||
dogetopts (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int ret, special_error, old_opterr, i, n;
|
||||
char strval[2], numval[16];
|
||||
char *optstr; /* list of options */
|
||||
char *name; /* variable to get flag val */
|
||||
char *t;
|
||||
|
||||
if (argc < 3)
|
||||
{
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
/* argv[0] is "getopts". */
|
||||
|
||||
optstr = argv[1];
|
||||
name = argv[2];
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
|
||||
special_error = optstr[0] == ':';
|
||||
|
||||
if (special_error)
|
||||
{
|
||||
old_opterr = sh_opterr;
|
||||
optstr++;
|
||||
sh_opterr = 0; /* suppress diagnostic messages */
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
sh_getopt_restore_state (argv);
|
||||
t = argv[0];
|
||||
argv[0] = dollar_vars[0];
|
||||
ret = sh_getopt (argc, argv, optstr);
|
||||
argv[0] = t;
|
||||
}
|
||||
else if (rest_of_args == (WORD_LIST *)NULL)
|
||||
{
|
||||
for (i = 0; i < 10 && dollar_vars[i]; i++)
|
||||
;
|
||||
|
||||
sh_getopt_restore_state (dollar_vars);
|
||||
ret = sh_getopt (i, dollar_vars, optstr);
|
||||
}
|
||||
else
|
||||
{
|
||||
register WORD_LIST *words;
|
||||
char **v;
|
||||
|
||||
i = number_of_args () + 1; /* +1 for $0 */
|
||||
v = strvec_create (i + 1);
|
||||
for (i = 0; i < 10 && dollar_vars[i]; i++)
|
||||
v[i] = dollar_vars[i];
|
||||
for (words = rest_of_args; words; words = words->next, i++)
|
||||
v[i] = words->word->word;
|
||||
v[i] = (char *)NULL;
|
||||
sh_getopt_restore_state (v);
|
||||
ret = sh_getopt (i, v, optstr);
|
||||
free (v);
|
||||
}
|
||||
|
||||
if (special_error)
|
||||
sh_opterr = old_opterr;
|
||||
|
||||
/* Set the OPTIND variable in any case, to handle "--" skipping. It's
|
||||
highly unlikely that 14 digits will be too few. */
|
||||
if (sh_optind < 10)
|
||||
{
|
||||
numval[14] = sh_optind + '0';
|
||||
numval[15] = '\0';
|
||||
i = 14;
|
||||
}
|
||||
else
|
||||
{
|
||||
numval[i = 15] = '\0';
|
||||
n = sh_optind;
|
||||
do
|
||||
{
|
||||
numval[--i] = (n % 10) + '0';
|
||||
}
|
||||
while (n /= 10);
|
||||
}
|
||||
bind_variable ("OPTIND", numval + i, 0);
|
||||
|
||||
/* If an error occurred, decide which one it is and set the return
|
||||
code appropriately. In all cases, the option character in error
|
||||
is in OPTOPT. If an invalid option was encountered, OPTARG is
|
||||
NULL. If a required option argument was missing, OPTARG points
|
||||
to a NULL string (that is, sh_optarg[0] == 0). */
|
||||
if (ret == '?')
|
||||
{
|
||||
if (sh_optarg == NULL)
|
||||
ret = G_INVALID_OPT;
|
||||
else if (sh_optarg[0] == '\0')
|
||||
ret = G_ARG_MISSING;
|
||||
}
|
||||
|
||||
if (ret == G_EOF)
|
||||
{
|
||||
getopts_unbind_variable ("OPTARG");
|
||||
getopts_bind_variable (name, "?");
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (ret == G_INVALID_OPT)
|
||||
{
|
||||
/* Invalid option encountered. */
|
||||
ret = getopts_bind_variable (name, "?");
|
||||
|
||||
if (special_error)
|
||||
{
|
||||
strval[0] = (char)sh_optopt;
|
||||
strval[1] = '\0';
|
||||
bind_variable ("OPTARG", strval, 0);
|
||||
}
|
||||
else
|
||||
getopts_unbind_variable ("OPTARG");
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
if (ret == G_ARG_MISSING)
|
||||
{
|
||||
/* Required argument missing. */
|
||||
if (special_error)
|
||||
{
|
||||
ret = getopts_bind_variable (name, ":");
|
||||
|
||||
strval[0] = (char)sh_optopt;
|
||||
strval[1] = '\0';
|
||||
bind_variable ("OPTARG", strval, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = getopts_bind_variable (name, "?");
|
||||
getopts_unbind_variable ("OPTARG");
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
bind_variable ("OPTARG", sh_optarg, 0);
|
||||
|
||||
strval[0] = (char) ret;
|
||||
strval[1] = '\0';
|
||||
return (getopts_bind_variable (name, strval));
|
||||
}
|
||||
|
||||
/* The getopts builtin. Build an argv, and call dogetopts with it. */
|
||||
int
|
||||
getopts_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
char **av;
|
||||
int ac, ret;
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
builtin_usage ();
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
reset_internal_getopt ();
|
||||
if ((ret = internal_getopt (list, "")) != -1)
|
||||
{
|
||||
if (ret == GETOPT_HELP)
|
||||
builtin_help ();
|
||||
else
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
av = make_builtin_argv (list, &ac);
|
||||
ret = dogetopts (ac, av);
|
||||
free ((char *)av);
|
||||
|
||||
return (ret);
|
||||
}
|
305
builtins/hash.def
Normal file
305
builtins/hash.def
Normal file
|
@ -0,0 +1,305 @@
|
|||
This file is hash.def, from which is created hash.c.
|
||||
It implements the builtin "hash" in Bash.
|
||||
|
||||
Copyright (C) 1987-2021 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 hash.c
|
||||
|
||||
$BUILTIN hash
|
||||
$FUNCTION hash_builtin
|
||||
$SHORT_DOC hash [-lr] [-p pathname] [-dt] [name ...]
|
||||
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 as 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>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../bashtypes.h"
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../builtins.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "../flags.h"
|
||||
#include "../findcmd.h"
|
||||
#include "../hashcmd.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
extern int dot_found_in_search;
|
||||
|
||||
static int add_hashed_command PARAMS((char *, int));
|
||||
static int print_hash_info PARAMS((BUCKET_CONTENTS *));
|
||||
static int print_portable_hash_info PARAMS((BUCKET_CONTENTS *));
|
||||
static int print_hashed_commands PARAMS((int));
|
||||
static int list_hashed_filename_targets PARAMS((WORD_LIST *, int));
|
||||
|
||||
/* Print statistics on the current state of hashed commands. If LIST is
|
||||
not empty, then rehash (or hash in the first place) the specified
|
||||
commands. */
|
||||
int
|
||||
hash_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int expunge_hash_table, list_targets, list_portably, delete, opt;
|
||||
char *w, *pathname;
|
||||
|
||||
if (hashing_enabled == 0)
|
||||
{
|
||||
builtin_error (_("hashing disabled"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
expunge_hash_table = list_targets = list_portably = delete = 0;
|
||||
pathname = (char *)NULL;
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "dlp:rt")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'd':
|
||||
delete = 1;
|
||||
break;
|
||||
case 'l':
|
||||
list_portably = 1;
|
||||
break;
|
||||
case 'p':
|
||||
pathname = list_optarg;
|
||||
break;
|
||||
case 'r':
|
||||
expunge_hash_table = 1;
|
||||
break;
|
||||
case 't':
|
||||
list_targets = 1;
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
/* hash -t requires at least one argument. */
|
||||
if (list == 0 && (delete || list_targets))
|
||||
{
|
||||
sh_needarg (delete ? "-d" : "-t");
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
/* We want hash -r to be silent, but hash -- to print hashing info, so
|
||||
we test expunge_hash_table. */
|
||||
if (list == 0 && expunge_hash_table == 0)
|
||||
{
|
||||
opt = print_hashed_commands (list_portably);
|
||||
if (opt == 0 && posixly_correct == 0 &&
|
||||
(list_portably == 0 || shell_compatibility_level <= 50))
|
||||
printf (_("%s: hash table empty\n"), this_command_name);
|
||||
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
if (expunge_hash_table)
|
||||
phash_flush ();
|
||||
|
||||
/* If someone runs `hash -r -t xyz' he will be disappointed. */
|
||||
if (list_targets)
|
||||
return (list_hashed_filename_targets (list, list_portably));
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
if (restricted && pathname)
|
||||
{
|
||||
if (strchr (pathname, '/'))
|
||||
{
|
||||
sh_restricted (pathname);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
/* If we are changing the hash table in a restricted shell, make sure the
|
||||
target pathname can be found using a $PATH search. */
|
||||
w = find_user_command (pathname);
|
||||
if (w == 0 || *w == 0 || executable_file (w) == 0)
|
||||
{
|
||||
sh_notfound (pathname);
|
||||
free (w);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
free (w);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (opt = EXECUTION_SUCCESS; list; list = list->next)
|
||||
{
|
||||
/* Add, remove or rehash the specified commands. */
|
||||
w = list->word->word;
|
||||
if (absolute_program (w))
|
||||
continue;
|
||||
else if (pathname)
|
||||
{
|
||||
if (file_isdir (pathname))
|
||||
{
|
||||
#ifdef EISDIR
|
||||
builtin_error ("%s: %s", pathname, strerror (EISDIR));
|
||||
#else
|
||||
builtin_error (_("%s: is a directory"), pathname);
|
||||
#endif
|
||||
opt = EXECUTION_FAILURE;
|
||||
}
|
||||
else
|
||||
phash_insert (w, pathname, 0, 0);
|
||||
}
|
||||
else if (delete)
|
||||
{
|
||||
if (phash_remove (w))
|
||||
{
|
||||
sh_notfound (w);
|
||||
opt = EXECUTION_FAILURE;
|
||||
}
|
||||
}
|
||||
else if (add_hashed_command (w, 0))
|
||||
opt = EXECUTION_FAILURE;
|
||||
}
|
||||
|
||||
fflush (stdout);
|
||||
return (opt);
|
||||
}
|
||||
|
||||
static int
|
||||
add_hashed_command (w, quiet)
|
||||
char *w;
|
||||
int quiet;
|
||||
{
|
||||
int rv;
|
||||
char *full_path;
|
||||
|
||||
rv = 0;
|
||||
if (find_function (w) == 0 && find_shell_builtin (w) == 0)
|
||||
{
|
||||
phash_remove (w);
|
||||
full_path = find_user_command (w);
|
||||
if (full_path && executable_file (full_path))
|
||||
phash_insert (w, full_path, dot_found_in_search, 0);
|
||||
else
|
||||
{
|
||||
if (quiet == 0)
|
||||
sh_notfound (w);
|
||||
rv++;
|
||||
}
|
||||
FREE (full_path);
|
||||
}
|
||||
return (rv);
|
||||
}
|
||||
|
||||
/* Print information about current hashed info. */
|
||||
static int
|
||||
print_hash_info (item)
|
||||
BUCKET_CONTENTS *item;
|
||||
{
|
||||
printf ("%4d\t%s\n", item->times_found, pathdata(item)->path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
print_portable_hash_info (item)
|
||||
BUCKET_CONTENTS *item;
|
||||
{
|
||||
char *fp, *fn;
|
||||
|
||||
fp = printable_filename (pathdata(item)->path, 1);
|
||||
fn = printable_filename (item->key, 1);
|
||||
printf ("builtin hash -p %s %s\n", fp, fn);
|
||||
if (fp != pathdata(item)->path)
|
||||
free (fp);
|
||||
if (fn != item->key)
|
||||
free (fn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
print_hashed_commands (fmt)
|
||||
int fmt;
|
||||
{
|
||||
if (hashed_filenames == 0 || HASH_ENTRIES (hashed_filenames) == 0)
|
||||
return (0);
|
||||
|
||||
if (fmt == 0)
|
||||
printf (_("hits\tcommand\n"));
|
||||
hash_walk (hashed_filenames, fmt ? print_portable_hash_info : print_hash_info);
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int
|
||||
list_hashed_filename_targets (list, fmt)
|
||||
WORD_LIST *list;
|
||||
int fmt;
|
||||
{
|
||||
int all_found, multiple;
|
||||
char *target;
|
||||
WORD_LIST *l;
|
||||
|
||||
all_found = 1;
|
||||
multiple = list->next != 0;
|
||||
|
||||
for (l = list; l; l = l->next)
|
||||
{
|
||||
target = phash_search (l->word->word);
|
||||
if (target == 0)
|
||||
{
|
||||
all_found = 0;
|
||||
sh_notfound (l->word->word);
|
||||
continue;
|
||||
}
|
||||
if (fmt)
|
||||
printf ("builtin hash -p %s %s\n", target, l->word->word);
|
||||
else
|
||||
{
|
||||
if (multiple)
|
||||
printf ("%s\t", l->word->word);
|
||||
printf ("%s\n", target);
|
||||
}
|
||||
free (target);
|
||||
}
|
||||
|
||||
return (all_found ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
|
||||
}
|
552
builtins/help.def
Normal file
552
builtins/help.def
Normal file
|
@ -0,0 +1,552 @@
|
|||
This file is help.def, from which is created help.c.
|
||||
It implements the builtin "help" in Bash.
|
||||
|
||||
Copyright (C) 1987-2021 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 help.c
|
||||
|
||||
$BUILTIN help
|
||||
$FUNCTION help_builtin
|
||||
$DEPENDS_ON HELP_BUILTIN
|
||||
$SHORT_DOC help [-dms] [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 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 specifying a help topic
|
||||
|
||||
Exit Status:
|
||||
Returns success unless PATTERN is not found or an invalid option is given.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HELP_BUILTIN)
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <filecntl.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../builtins.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "../pathexp.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
#include <glob/strmatch.h>
|
||||
#include <glob/glob.h>
|
||||
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
extern const char * const bash_copyright;
|
||||
extern const char * const bash_license;
|
||||
|
||||
static void show_builtin_command_help PARAMS((void));
|
||||
static int open_helpfile PARAMS((char *));
|
||||
static void show_desc PARAMS((char *, int));
|
||||
static void show_manpage PARAMS((char *, int));
|
||||
static void show_longdoc PARAMS((int));
|
||||
|
||||
/* Print out a list of the known functions in the shell, and what they do.
|
||||
If LIST is supplied, print out the list which matches for each pattern
|
||||
specified. */
|
||||
int
|
||||
help_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
register int i;
|
||||
char *pattern, *name;
|
||||
int plen, match_found, sflag, dflag, mflag, m, pass, this_found;
|
||||
|
||||
dflag = sflag = mflag = 0;
|
||||
reset_internal_getopt ();
|
||||
while ((i = internal_getopt (list, "dms")) != -1)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 'd':
|
||||
dflag = 1;
|
||||
break;
|
||||
case 'm':
|
||||
mflag = 1;
|
||||
break;
|
||||
case 's':
|
||||
sflag = 1;
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
show_shell_version (0);
|
||||
show_builtin_command_help ();
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
/* We should consider making `help bash' do something. */
|
||||
|
||||
if (glob_pattern_p (list->word->word) == 1)
|
||||
{
|
||||
printf ("%s", ngettext ("Shell commands matching keyword `", "Shell commands matching keywords `", (list->next ? 2 : 1)));
|
||||
print_word_list (list, ", ");
|
||||
printf ("%s", _("'\n\n"));
|
||||
}
|
||||
|
||||
for (match_found = 0, pattern = ""; list; list = list->next)
|
||||
{
|
||||
pattern = list->word->word;
|
||||
plen = strlen (pattern);
|
||||
|
||||
for (pass = 1, this_found = 0; pass < 3; pass++)
|
||||
{
|
||||
for (i = 0; name = shell_builtins[i].name; i++)
|
||||
{
|
||||
QUIT;
|
||||
|
||||
/* First pass: look for exact string or pattern matches.
|
||||
Second pass: look for prefix matches like bash-4.2 */
|
||||
if (pass == 1)
|
||||
m = (strcmp (pattern, name) == 0) ||
|
||||
(strmatch (pattern, name, FNMATCH_EXTFLAG) != FNM_NOMATCH);
|
||||
else
|
||||
m = strncmp (pattern, name, plen) == 0;
|
||||
|
||||
if (m)
|
||||
{
|
||||
this_found = 1;
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (pass == 1 && this_found == 1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (match_found == 0)
|
||||
{
|
||||
builtin_error (_("no help topics match `%s'. Try `help help' or `man -k %s' or `info %s'."), pattern, pattern, pattern);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
void
|
||||
builtin_help ()
|
||||
{
|
||||
int ind;
|
||||
ptrdiff_t d;
|
||||
|
||||
current_builtin = builtin_address_internal (this_command_name, 0);
|
||||
if (current_builtin == 0)
|
||||
return;
|
||||
|
||||
d = current_builtin - shell_builtins;
|
||||
|
||||
#if defined (__STDC__)
|
||||
ind = (int)d;
|
||||
#else
|
||||
ind = (int)d / sizeof (struct builtin);
|
||||
#endif
|
||||
|
||||
printf ("%s: %s\n", this_command_name, _(shell_builtins[ind].short_doc));
|
||||
show_longdoc (ind);
|
||||
}
|
||||
|
||||
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. */
|
||||
static void
|
||||
show_longdoc (i)
|
||||
int i;
|
||||
{
|
||||
register int j;
|
||||
char * const *doc;
|
||||
int fd;
|
||||
|
||||
doc = shell_builtins[i].long_doc;
|
||||
|
||||
if (doc && doc[0] && *doc[0] == '/' && doc[1] == (char *)NULL)
|
||||
{
|
||||
fd = open_helpfile (doc[0]);
|
||||
if (fd < 0)
|
||||
return;
|
||||
zcatfd (fd, 1, doc[0]);
|
||||
close (fd);
|
||||
}
|
||||
else if (doc)
|
||||
for (j = 0; doc[j]; j++)
|
||||
printf ("%*s%s\n", BASE_INDENT, " ", _(doc[j]));
|
||||
}
|
||||
|
||||
static void
|
||||
show_desc (name, i)
|
||||
char *name;
|
||||
int i;
|
||||
{
|
||||
register int j, r;
|
||||
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;
|
||||
r = zmapfd (fd, &line, doc[0]);
|
||||
close (fd);
|
||||
/* XXX - handle errors if zmapfd returns < 0 */
|
||||
}
|
||||
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
|
||||
dispcolumn (i, buf, bufsize, width, height)
|
||||
int i;
|
||||
char *buf;
|
||||
size_t bufsize;
|
||||
int width, height;
|
||||
{
|
||||
int j;
|
||||
int dispcols;
|
||||
char *helpdoc;
|
||||
|
||||
/* first column */
|
||||
helpdoc = _(shell_builtins[i].short_doc);
|
||||
|
||||
buf[0] = (shell_builtins[i].flags & BUILTIN_ENABLED) ? ' ' : '*';
|
||||
strncpy (buf + 1, helpdoc, width - 2);
|
||||
buf[width - 2] = '>'; /* indicate truncation */
|
||||
buf[width - 1] = '\0';
|
||||
printf ("%s", buf);
|
||||
if (((i << 1) >= num_shell_builtins) || (i+height >= num_shell_builtins))
|
||||
{
|
||||
printf ("\n");
|
||||
return;
|
||||
}
|
||||
|
||||
dispcols = strlen (buf);
|
||||
/* two spaces */
|
||||
for (j = dispcols; j < width; j++)
|
||||
putc (' ', stdout);
|
||||
|
||||
/* second column */
|
||||
helpdoc = _(shell_builtins[i+height].short_doc);
|
||||
|
||||
buf[0] = (shell_builtins[i+height].flags & BUILTIN_ENABLED) ? ' ' : '*';
|
||||
strncpy (buf + 1, helpdoc, width - 3);
|
||||
buf[width - 3] = '>'; /* indicate truncation */
|
||||
buf[width - 2] = '\0';
|
||||
|
||||
printf ("%s\n", buf);
|
||||
}
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
static void
|
||||
wdispcolumn (i, buf, bufsize, width, height)
|
||||
int i;
|
||||
char *buf;
|
||||
size_t bufsize;
|
||||
int width, height;
|
||||
{
|
||||
int j;
|
||||
int dispcols, dispchars;
|
||||
char *helpdoc;
|
||||
wchar_t *wcstr;
|
||||
size_t slen, n;
|
||||
|
||||
/* first column */
|
||||
helpdoc = _(shell_builtins[i].short_doc);
|
||||
|
||||
wcstr = 0;
|
||||
slen = mbstowcs ((wchar_t *)0, helpdoc, 0);
|
||||
if (slen == -1)
|
||||
{
|
||||
dispcolumn (i, buf, bufsize, width, height);
|
||||
return;
|
||||
}
|
||||
|
||||
/* No bigger than the passed max width */
|
||||
if (slen >= width)
|
||||
slen = width - 2;
|
||||
wcstr = (wchar_t *)xmalloc (sizeof (wchar_t) * (width + 2));
|
||||
n = mbstowcs (wcstr+1, helpdoc, slen + 1);
|
||||
wcstr[n+1] = L'\0';
|
||||
|
||||
/* Turn tabs and newlines into spaces for column display, since wcwidth
|
||||
returns -1 for them */
|
||||
for (j = 1; j < n; j++)
|
||||
if (wcstr[j] == L'\n' || wcstr[j] == L'\t')
|
||||
wcstr[j] = L' ';
|
||||
|
||||
/* dispchars == number of characters that will be displayed */
|
||||
dispchars = wcsnwidth (wcstr+1, slen, width - 2);
|
||||
/* dispcols == number of columns required to display DISPCHARS */
|
||||
dispcols = wcswidth (wcstr+1, dispchars) + 1; /* +1 for ' ' or '*' */
|
||||
|
||||
wcstr[0] = (shell_builtins[i].flags & BUILTIN_ENABLED) ? L' ' : L'*';
|
||||
|
||||
if (dispcols >= width-2)
|
||||
{
|
||||
wcstr[dispchars] = L'>'; /* indicate truncation */
|
||||
wcstr[dispchars+1] = L'\0';
|
||||
}
|
||||
|
||||
printf ("%ls", wcstr);
|
||||
if (((i << 1) >= num_shell_builtins) || (i+height >= num_shell_builtins))
|
||||
{
|
||||
printf ("\n");
|
||||
free (wcstr);
|
||||
return;
|
||||
}
|
||||
|
||||
/* at least one space */
|
||||
for (j = dispcols; j < width; j++)
|
||||
putc (' ', stdout);
|
||||
|
||||
/* second column */
|
||||
helpdoc = _(shell_builtins[i+height].short_doc);
|
||||
slen = mbstowcs ((wchar_t *)0, helpdoc, 0);
|
||||
if (slen == -1)
|
||||
{
|
||||
/* for now */
|
||||
printf ("%c%s\n", (shell_builtins[i+height].flags & BUILTIN_ENABLED) ? ' ' : '*', helpdoc);
|
||||
free (wcstr);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Reuse wcstr since it is already width wide chars long */
|
||||
if (slen >= width)
|
||||
slen = width - 2;
|
||||
n = mbstowcs (wcstr+1, helpdoc, slen + 1);
|
||||
wcstr[n+1] = L'\0'; /* make sure null-terminated */
|
||||
|
||||
/* Turn tabs and newlines into spaces for column display */
|
||||
for (j = 1; j < n; j++)
|
||||
if (wcstr[j] == L'\n' || wcstr[j] == L'\t')
|
||||
wcstr[j] = L' ';
|
||||
|
||||
/* dispchars == number of characters that will be displayed */
|
||||
dispchars = wcsnwidth (wcstr+1, slen, width - 2);
|
||||
dispcols = wcswidth (wcstr+1, dispchars) + 1; /* +1 for ' ' or '*' */
|
||||
|
||||
wcstr[0] = (shell_builtins[i+height].flags & BUILTIN_ENABLED) ? L' ' : L'*';
|
||||
|
||||
/* The dispchars-1 is there for terminals that behave strangely when you
|
||||
have \n in the nth column for terminal width n; this is what bash-4.3
|
||||
did. */
|
||||
if (dispcols >= width - 2)
|
||||
{
|
||||
wcstr[dispchars-1] = L'>'; /* indicate truncation */
|
||||
wcstr[dispchars] = L'\0';
|
||||
}
|
||||
|
||||
printf ("%ls\n", wcstr);
|
||||
|
||||
free (wcstr);
|
||||
}
|
||||
#endif /* HANDLE_MULTIBYTE */
|
||||
|
||||
static void
|
||||
show_builtin_command_help ()
|
||||
{
|
||||
int i, j;
|
||||
int height, width;
|
||||
char *t, blurb[128];
|
||||
|
||||
printf (
|
||||
_("These shell commands are defined internally. Type `help' to see this list.\n\
|
||||
Type `help name' to find out more about the function `name'.\n\
|
||||
Use `info bash' to find out more about the shell in general.\n\
|
||||
Use `man -k' or `info' to find out more about commands not in this list.\n\
|
||||
\n\
|
||||
A star (*) next to a name means that the command is disabled.\n\
|
||||
\n"));
|
||||
|
||||
width = default_columns ();
|
||||
|
||||
width /= 2;
|
||||
if (width > sizeof (blurb))
|
||||
width = sizeof (blurb);
|
||||
if (width <= 3)
|
||||
width = 40;
|
||||
height = (num_shell_builtins + 1) / 2; /* number of rows */
|
||||
|
||||
for (i = 0; i < height; i++)
|
||||
{
|
||||
QUIT;
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1)
|
||||
wdispcolumn (i, blurb, sizeof (blurb), width, height);
|
||||
else
|
||||
#endif
|
||||
dispcolumn (i, blurb, sizeof (blurb), width, height);
|
||||
}
|
||||
}
|
||||
#endif /* HELP_BUILTIN */
|
464
builtins/history.def
Normal file
464
builtins/history.def
Normal file
|
@ -0,0 +1,464 @@
|
|||
This file is history.def, from which is created history.c.
|
||||
It implements the builtin "history" in Bash.
|
||||
|
||||
Copyright (C) 1987-2021 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 history.c
|
||||
|
||||
$BUILTIN history
|
||||
$FUNCTION history_builtin
|
||||
$DEPENDS_ON HISTORY
|
||||
$SHORT_DOC history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
|
||||
Display or manipulate the history list.
|
||||
|
||||
Display the history list with line numbers, prefixing each modified
|
||||
entry with a `*'. An argument of N lists only the last N entries.
|
||||
|
||||
Options:
|
||||
-c clear the history list by deleting all of the entries
|
||||
-d offset delete the history entry at position OFFSET. Negative
|
||||
offsets count back from the end of the history list
|
||||
|
||||
-a append history lines from this session to the history file
|
||||
-n read all history lines not already read from the history file
|
||||
and append them to the history list
|
||||
-r read the history file and append the contents to the history
|
||||
list
|
||||
-w write the current history to the history file
|
||||
|
||||
-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 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>
|
||||
|
||||
#if defined (HISTORY)
|
||||
#include "../bashtypes.h"
|
||||
#if ! defined(_MINIX) && defined (HAVE_SYS_FILE_H)
|
||||
# include <sys/file.h>
|
||||
#endif
|
||||
#include "posixstat.h"
|
||||
#include "filecntl.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../flags.h"
|
||||
#include "../parser.h"
|
||||
#include "../bashhist.h"
|
||||
#include <readline/history.h>
|
||||
#include "bashgetopt.h"
|
||||
#include "common.h"
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
static char *histtime PARAMS((HIST_ENTRY *, const char *));
|
||||
static int display_history PARAMS((WORD_LIST *));
|
||||
static void push_history PARAMS((WORD_LIST *));
|
||||
static int expand_and_print_history PARAMS((WORD_LIST *));
|
||||
|
||||
#define AFLAG 0x01
|
||||
#define RFLAG 0x02
|
||||
#define WFLAG 0x04
|
||||
#define NFLAG 0x08
|
||||
#define SFLAG 0x10
|
||||
#define PFLAG 0x20
|
||||
#define CFLAG 0x40
|
||||
#define DFLAG 0x80
|
||||
|
||||
#ifndef TIMELEN_MAX
|
||||
# define TIMELEN_MAX 128
|
||||
#endif
|
||||
|
||||
int
|
||||
history_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int flags, opt, result, old_history_lines, obase, ind;
|
||||
char *filename, *delete_arg, *range;
|
||||
intmax_t delete_offset;
|
||||
|
||||
flags = 0;
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "acd:npsrw")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'a':
|
||||
flags |= AFLAG;
|
||||
break;
|
||||
case 'c':
|
||||
flags |= CFLAG;
|
||||
break;
|
||||
case 'n':
|
||||
flags |= NFLAG;
|
||||
break;
|
||||
case 'r':
|
||||
flags |= RFLAG;
|
||||
break;
|
||||
case 'w':
|
||||
flags |= WFLAG;
|
||||
break;
|
||||
case 's':
|
||||
flags |= SFLAG;
|
||||
break;
|
||||
case 'd':
|
||||
flags |= DFLAG;
|
||||
delete_arg = list_optarg;
|
||||
break;
|
||||
case 'p':
|
||||
#if defined (BANG_HISTORY)
|
||||
flags |= PFLAG;
|
||||
#endif
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
opt = flags & (AFLAG|RFLAG|WFLAG|NFLAG);
|
||||
if (opt && opt != AFLAG && opt != RFLAG && opt != WFLAG && opt != NFLAG)
|
||||
{
|
||||
builtin_error (_("cannot use more than one of -anrw"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
/* clear the history, but allow other arguments to add to it again. */
|
||||
if (flags & CFLAG)
|
||||
{
|
||||
bash_clear_history ();
|
||||
if (list == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
if (flags & SFLAG)
|
||||
{
|
||||
if (list)
|
||||
push_history (list);
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
#if defined (BANG_HISTORY)
|
||||
else if (flags & PFLAG)
|
||||
{
|
||||
if (list)
|
||||
return (expand_and_print_history (list));
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
#endif
|
||||
else if ((flags & DFLAG) && (range = strchr ((delete_arg[0] == '-') ? delete_arg + 1 : delete_arg, '-')))
|
||||
{
|
||||
intmax_t delete_start, delete_end;
|
||||
*range++ = '\0';
|
||||
if (legal_number (delete_arg, &delete_start) == 0 || legal_number (range, &delete_end) == 0)
|
||||
{
|
||||
range[-1] = '-';
|
||||
sh_erange (delete_arg, _("history position"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
if (delete_arg[0] == '-' && delete_start < 0)
|
||||
/* the_history[history_length] == 0x0, so this is correct */
|
||||
delete_start += history_length;
|
||||
/* numbers as displayed by display_history are offset by history_base */
|
||||
else if (delete_start > 0)
|
||||
delete_start -= history_base;
|
||||
|
||||
if (delete_start < 0 || delete_start >= history_length)
|
||||
{
|
||||
sh_erange (delete_arg, _("history position"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (range[0] == '-' && delete_end < 0)
|
||||
delete_end += history_length;
|
||||
else if (delete_end > 0)
|
||||
delete_end -= history_base;
|
||||
|
||||
if (delete_end < 0 || delete_end >= history_length)
|
||||
{
|
||||
sh_erange (range, _("history position"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
/* XXX - print error if end < start? */
|
||||
result = bash_delete_history_range (delete_start, delete_end);
|
||||
if (where_history () > history_length)
|
||||
history_set_pos (history_length);
|
||||
return (result ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
|
||||
}
|
||||
else if (flags & DFLAG)
|
||||
{
|
||||
if (legal_number (delete_arg, &delete_offset) == 0)
|
||||
{
|
||||
sh_erange (delete_arg, _("history position"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
/* check for negative offsets, count back from end of list */
|
||||
if (delete_arg[0] == '-' && delete_offset < 0)
|
||||
{
|
||||
/* since the_history[history_length] == 0x0, this calculation means
|
||||
that history -d -1 will delete the last history entry, which at
|
||||
this point is the history -d -1 we just added. */
|
||||
ind = history_length + delete_offset;
|
||||
if (ind < 0) /* offset by history_base below */
|
||||
{
|
||||
sh_erange (delete_arg, _("history position"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
opt = ind + history_base; /* compensate for opt - history_base below */
|
||||
}
|
||||
else if ((delete_offset < history_base) || (delete_offset >= (history_base + history_length)))
|
||||
{
|
||||
sh_erange (delete_arg, _("history position"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else
|
||||
opt = delete_offset;
|
||||
|
||||
/* Positive arguments from numbers as displayed by display_history need
|
||||
to be offset by 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)
|
||||
history_set_pos (history_length);
|
||||
return (result ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
|
||||
}
|
||||
else if ((flags & (AFLAG|RFLAG|NFLAG|WFLAG|CFLAG)) == 0)
|
||||
{
|
||||
result = display_history (list);
|
||||
return (sh_chkwrite (result));
|
||||
}
|
||||
|
||||
filename = list ? list->word->word : get_string_value ("HISTFILE");
|
||||
result = EXECUTION_SUCCESS;
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
if (restricted && strchr (filename, '/'))
|
||||
{
|
||||
sh_restricted (filename);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (flags & AFLAG) /* Append session's history to file. */
|
||||
result = maybe_append_history (filename);
|
||||
else if (flags & WFLAG) /* Write entire history. */
|
||||
result = write_history (filename);
|
||||
else if (flags & RFLAG) /* Read entire file. */
|
||||
{
|
||||
result = read_history (filename);
|
||||
history_lines_in_file = history_lines_read_from_file;
|
||||
/* history_lines_in_file = where_history () + history_base - 1; */
|
||||
}
|
||||
else if (flags & NFLAG) /* Read `new' history from file. */
|
||||
{
|
||||
/* Read all of the lines in the file that we haven't already read. */
|
||||
old_history_lines = history_lines_in_file;
|
||||
obase = history_base;
|
||||
|
||||
using_history ();
|
||||
result = read_history_range (filename, history_lines_in_file, -1);
|
||||
using_history ();
|
||||
|
||||
history_lines_in_file = history_lines_read_from_file;
|
||||
/* history_lines_in_file = where_history () + history_base - 1; */
|
||||
|
||||
/* If we're rewriting the history file at shell exit rather than just
|
||||
appending the lines from this session to it, the question is whether
|
||||
we reset history_lines_this_session to 0, losing any history entries
|
||||
we had before we read the new entries from the history file, or
|
||||
whether we count the new entries we just read from the file as
|
||||
history lines added during this session.
|
||||
Right now, we do the latter. This will cause these history entries
|
||||
to be written to the history file along with any intermediate entries
|
||||
we add when we do a `history -a', but the alternative is losing
|
||||
them altogether. */
|
||||
if (force_append_history == 0)
|
||||
history_lines_this_session += history_lines_in_file - old_history_lines +
|
||||
history_base - obase;
|
||||
}
|
||||
|
||||
return (result ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
/* Accessors for HIST_ENTRY lists that are called HLIST. */
|
||||
#define histline(i) (hlist[(i)]->line)
|
||||
#define histdata(i) (hlist[(i)]->data)
|
||||
|
||||
static char *
|
||||
histtime (hlist, histtimefmt)
|
||||
HIST_ENTRY *hlist;
|
||||
const char *histtimefmt;
|
||||
{
|
||||
static char timestr[TIMELEN_MAX];
|
||||
time_t t;
|
||||
struct tm *tm;
|
||||
|
||||
t = history_get_time (hlist);
|
||||
tm = t ? localtime (&t) : 0;
|
||||
if (t && tm)
|
||||
strftime (timestr, sizeof (timestr), histtimefmt, tm);
|
||||
else if (hlist->timestamp && hlist->timestamp[0])
|
||||
snprintf (timestr, sizeof (timestr), _("%s: invalid timestamp"),
|
||||
(hlist->timestamp[0] == '#') ? hlist->timestamp + 1: hlist->timestamp);
|
||||
else
|
||||
strcpy (timestr, "??");
|
||||
return timestr;
|
||||
}
|
||||
|
||||
static int
|
||||
display_history (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
register int i;
|
||||
intmax_t limit;
|
||||
HIST_ENTRY **hlist;
|
||||
char *histtimefmt, *timestr;
|
||||
|
||||
if (list)
|
||||
{
|
||||
if (get_numeric_arg (list, 0, &limit) == 0)
|
||||
return (EXECUTION_FAILURE);
|
||||
|
||||
if (limit < 0)
|
||||
limit = -limit;
|
||||
}
|
||||
else
|
||||
limit = -1;
|
||||
|
||||
hlist = history_list ();
|
||||
|
||||
if (hlist)
|
||||
{
|
||||
for (i = 0; hlist[i]; i++)
|
||||
;
|
||||
|
||||
if (0 <= limit && limit < i)
|
||||
i -= limit;
|
||||
else
|
||||
i = 0;
|
||||
|
||||
histtimefmt = get_string_value ("HISTTIMEFORMAT");
|
||||
|
||||
while (hlist[i])
|
||||
{
|
||||
QUIT;
|
||||
|
||||
timestr = (histtimefmt && *histtimefmt) ? histtime (hlist[i], histtimefmt) : (char *)NULL;
|
||||
printf ("%5d%c %s%s\n", i + history_base,
|
||||
histdata(i) ? '*' : ' ',
|
||||
((timestr && *timestr) ? timestr : ""),
|
||||
histline(i));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
/* Remove the last entry in the history list and add each argument in
|
||||
LIST to the history. */
|
||||
static void
|
||||
push_history (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
char *s;
|
||||
|
||||
/* Delete the last history entry if it was a single entry added to the
|
||||
history list (generally the `history -s' itself), or if `history -s'
|
||||
is being used in a compound command and the compound command was
|
||||
added to the history as a single element (command-oriented history).
|
||||
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 (remember_on_history && hist_last_line_pushed == 0 &&
|
||||
hist_last_line_added && bash_delete_last_history () == 0)
|
||||
#else
|
||||
if (remember_on_history && hist_last_line_pushed == 0 &&
|
||||
(hist_last_line_added ||
|
||||
(current_command_line_count > 0 && current_command_first_line_saved && command_oriented_history))
|
||||
&& bash_delete_last_history () == 0)
|
||||
#endif
|
||||
return;
|
||||
|
||||
s = string_list (list);
|
||||
/* Call check_add_history with FORCE set to 1 to skip the check against
|
||||
current_command_line_count. If history -s is used in a compound
|
||||
command, the above code will delete the compound command's history
|
||||
entry and this call will add the line to the history as a separate
|
||||
entry. Without FORCE=1, if current_command_line_count were > 1, the
|
||||
line would be appended to the entry before the just-deleted entry. */
|
||||
check_add_history (s, 1); /* obeys HISTCONTROL, HISTIGNORE */
|
||||
|
||||
hist_last_line_pushed = 1; /* XXX */
|
||||
free (s);
|
||||
}
|
||||
|
||||
#if defined (BANG_HISTORY)
|
||||
static int
|
||||
expand_and_print_history (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
char *s;
|
||||
int r, result;
|
||||
|
||||
if (hist_last_line_pushed == 0 && hist_last_line_added && bash_delete_last_history () == 0)
|
||||
return EXECUTION_FAILURE;
|
||||
result = EXECUTION_SUCCESS;
|
||||
while (list)
|
||||
{
|
||||
r = history_expand (list->word->word, &s);
|
||||
if (r < 0)
|
||||
{
|
||||
builtin_error (_("%s: history expansion failed"), list->word->word);
|
||||
result = EXECUTION_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
fputs (s, stdout);
|
||||
putchar ('\n');
|
||||
}
|
||||
FREE (s);
|
||||
list = list->next;
|
||||
}
|
||||
fflush (stdout);
|
||||
return result;
|
||||
}
|
||||
#endif /* BANG_HISTORY */
|
||||
#endif /* HISTORY */
|
300
builtins/jobs.def
Normal file
300
builtins/jobs.def
Normal file
|
@ -0,0 +1,300 @@
|
|||
This file is jobs.def, from which is created jobs.c.
|
||||
It implements the builtins "jobs" and "disown" in Bash.
|
||||
|
||||
Copyright (C) 1987-2020 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 jobs.c
|
||||
|
||||
$BUILTIN jobs
|
||||
$FUNCTION jobs_builtin
|
||||
$DEPENDS_ON JOB_CONTROL
|
||||
$SHORT_DOC jobs [-lnprs] [jobspec ...] or jobs -x command [args]
|
||||
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 lists 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>
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
#include "../bashtypes.h"
|
||||
#include <signal.h>
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../jobs.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "bashgetopt.h"
|
||||
#include "common.h"
|
||||
|
||||
#define JSTATE_ANY 0x0
|
||||
#define JSTATE_RUNNING 0x1
|
||||
#define JSTATE_STOPPED 0x2
|
||||
|
||||
static int execute_list_with_replacements PARAMS((WORD_LIST *));
|
||||
|
||||
/* The `jobs' command. Prints outs a list of active jobs. If the
|
||||
argument `-l' is given, then the process id's are printed also.
|
||||
If the argument `-p' is given, print the process group leader's
|
||||
pid only. If `-n' is given, only processes that have changed
|
||||
status since the last notification are printed. If -x is given,
|
||||
replace all job specs with the pid of the appropriate process
|
||||
group leader and execute the command. The -r and -s options mean
|
||||
to print info about running and stopped jobs only, respectively. */
|
||||
int
|
||||
jobs_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int form, execute, state, opt, any_failed, job;
|
||||
sigset_t set, oset;
|
||||
|
||||
execute = any_failed = 0;
|
||||
form = JLIST_STANDARD;
|
||||
state = JSTATE_ANY;
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "lpnxrs")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'l':
|
||||
form = JLIST_LONG;
|
||||
break;
|
||||
case 'p':
|
||||
form = JLIST_PID_ONLY;
|
||||
break;
|
||||
case 'n':
|
||||
form = JLIST_CHANGED_ONLY;
|
||||
break;
|
||||
case 'x':
|
||||
if (form != JLIST_STANDARD)
|
||||
{
|
||||
builtin_error (_("no other options allowed with `-x'"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
execute++;
|
||||
break;
|
||||
case 'r':
|
||||
state = JSTATE_RUNNING;
|
||||
break;
|
||||
case 's':
|
||||
state = JSTATE_STOPPED;
|
||||
break;
|
||||
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
|
||||
list = loptend;
|
||||
|
||||
if (execute)
|
||||
return (execute_list_with_replacements (list));
|
||||
|
||||
if (!list)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case JSTATE_ANY:
|
||||
list_all_jobs (form);
|
||||
break;
|
||||
case JSTATE_RUNNING:
|
||||
list_running_jobs (form);
|
||||
break;
|
||||
case JSTATE_STOPPED:
|
||||
list_stopped_jobs (form);
|
||||
break;
|
||||
}
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
while (list)
|
||||
{
|
||||
BLOCK_CHILD (set, oset);
|
||||
job = get_job_spec (list);
|
||||
|
||||
if ((job == NO_JOB) || jobs == 0 || get_job_by_jid (job) == 0)
|
||||
{
|
||||
sh_badjob (list->word->word);
|
||||
any_failed++;
|
||||
}
|
||||
else if (job != DUP_JOB)
|
||||
list_one_job ((JOB *)NULL, form, 0, job);
|
||||
|
||||
UNBLOCK_CHILD (oset);
|
||||
list = list->next;
|
||||
}
|
||||
return (any_failed ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
static int
|
||||
execute_list_with_replacements (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
register WORD_LIST *l;
|
||||
int job, result;
|
||||
COMMAND *command;
|
||||
JOB *j;
|
||||
|
||||
/* First do the replacement of job specifications with pids. */
|
||||
for (l = list; l; l = l->next)
|
||||
{
|
||||
if (l->word->word[0] == '%') /* we have a winner */
|
||||
{
|
||||
job = get_job_spec (l);
|
||||
|
||||
/* A bad job spec is not really a job spec! Pass it through. */
|
||||
if (INVALID_JOB (job))
|
||||
continue;
|
||||
|
||||
j = get_job_by_jid (job);
|
||||
free (l->word->word);
|
||||
l->word->word = itos (j->pgrp);
|
||||
}
|
||||
}
|
||||
|
||||
/* Next make a new simple command and execute it. */
|
||||
begin_unwind_frame ("jobs_builtin");
|
||||
|
||||
command = make_bare_simple_command ();
|
||||
command->value.Simple->words = copy_word_list (list);
|
||||
command->value.Simple->redirects = (REDIRECT *)NULL;
|
||||
command->flags |= CMD_INHIBIT_EXPANSION;
|
||||
command->value.Simple->flags |= CMD_INHIBIT_EXPANSION;
|
||||
|
||||
add_unwind_protect (dispose_command, command);
|
||||
result = execute_command (command);
|
||||
dispose_command (command);
|
||||
|
||||
discard_unwind_frame ("jobs_builtin");
|
||||
return (result);
|
||||
}
|
||||
#endif /* JOB_CONTROL */
|
||||
|
||||
$BUILTIN disown
|
||||
$FUNCTION disown_builtin
|
||||
$DEPENDS_ON JOB_CONTROL
|
||||
$SHORT_DOC disown [-h] [-ar] [jobspec ... | pid ...]
|
||||
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)
|
||||
int
|
||||
disown_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int opt, job, retval, nohup_only, running_jobs, all_jobs;
|
||||
sigset_t set, oset;
|
||||
intmax_t pid_value;
|
||||
|
||||
nohup_only = running_jobs = all_jobs = 0;
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "ahr")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'a':
|
||||
all_jobs = 1;
|
||||
break;
|
||||
case 'h':
|
||||
nohup_only = 1;
|
||||
break;
|
||||
case 'r':
|
||||
running_jobs = 1;
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
retval = EXECUTION_SUCCESS;
|
||||
|
||||
/* `disown -a' or `disown -r' */
|
||||
if (list == 0 && (all_jobs || running_jobs))
|
||||
{
|
||||
if (nohup_only)
|
||||
nohup_all_jobs (running_jobs);
|
||||
else
|
||||
delete_all_jobs (running_jobs);
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
BLOCK_CHILD (set, oset);
|
||||
job = (list && legal_number (list->word->word, &pid_value) && pid_value == (pid_t) pid_value)
|
||||
? get_job_by_pid ((pid_t) pid_value, 0, 0)
|
||||
: get_job_spec (list);
|
||||
|
||||
if (job == NO_JOB || jobs == 0 || INVALID_JOB (job))
|
||||
{
|
||||
sh_badjob (list ? list->word->word : _("current"));
|
||||
retval = EXECUTION_FAILURE;
|
||||
}
|
||||
else if (nohup_only)
|
||||
nohup_job (job);
|
||||
else
|
||||
delete_job (job, 1);
|
||||
UNBLOCK_CHILD (oset);
|
||||
|
||||
if (list)
|
||||
list = list->next;
|
||||
}
|
||||
while (list);
|
||||
|
||||
return (retval);
|
||||
}
|
||||
#endif /* JOB_CONTROL */
|
276
builtins/kill.def
Normal file
276
builtins/kill.def
Normal file
|
@ -0,0 +1,276 @@
|
|||
This file is kill.def, from which is created kill.c.
|
||||
It implements the builtin "kill" in Bash.
|
||||
|
||||
Copyright (C) 1987-2020 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 kill.c
|
||||
|
||||
$BUILTIN kill
|
||||
$FUNCTION kill_builtin
|
||||
$SHORT_DOC kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
|
||||
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
|
||||
-L synonym for -l
|
||||
|
||||
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>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../trap.h"
|
||||
#include "../jobs.h"
|
||||
#include "common.h"
|
||||
|
||||
/* Not all systems declare ERRNO in errno.h... and some systems #define it! */
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif /* !errno */
|
||||
|
||||
static void kill_error PARAMS((pid_t, int));
|
||||
|
||||
#if !defined (CONTINUE_AFTER_KILL_ERROR)
|
||||
# define CONTINUE_OR_FAIL return (EXECUTION_FAILURE)
|
||||
#else
|
||||
# define CONTINUE_OR_FAIL goto continue_killing
|
||||
#endif /* CONTINUE_AFTER_KILL_ERROR */
|
||||
|
||||
/* Here is the kill builtin. We only have it so that people can type
|
||||
kill -KILL %1? No, if you fill up the process table this way you
|
||||
can still kill some. */
|
||||
int
|
||||
kill_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int sig, any_succeeded, listing, saw_signal, dflags;
|
||||
char *sigspec, *word;
|
||||
pid_t pid;
|
||||
intmax_t pid_value;
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
CHECK_HELPOPT (list);
|
||||
|
||||
any_succeeded = listing = saw_signal = 0;
|
||||
sig = SIGTERM;
|
||||
sigspec = "TERM";
|
||||
|
||||
dflags = DSIG_NOCASE | ((posixly_correct == 0) ? DSIG_SIGPREFIX : 0);
|
||||
/* Process options. */
|
||||
while (list)
|
||||
{
|
||||
word = list->word->word;
|
||||
|
||||
if (ISOPTION (word, 'l') || ISOPTION (word, 'L'))
|
||||
{
|
||||
listing++;
|
||||
list = list->next;
|
||||
}
|
||||
else if (ISOPTION (word, 's') || ISOPTION (word, 'n'))
|
||||
{
|
||||
list = list->next;
|
||||
if (list)
|
||||
{
|
||||
sigspec = list->word->word;
|
||||
use_sigspec:
|
||||
if (sigspec[0] == '0' && sigspec[1] == '\0')
|
||||
sig = 0;
|
||||
else
|
||||
sig = decode_signal (sigspec, dflags);
|
||||
list = list->next;
|
||||
saw_signal++;
|
||||
}
|
||||
else
|
||||
{
|
||||
sh_needarg (word);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
else if (word[0] == '-' && word[1] == 's' && ISALPHA (word[2]))
|
||||
{
|
||||
sigspec = word + 2;
|
||||
goto use_sigspec;
|
||||
}
|
||||
else if (word[0] == '-' && word[1] == 'n' && ISDIGIT (word[2]))
|
||||
{
|
||||
sigspec = word + 2;
|
||||
goto use_sigspec;
|
||||
}
|
||||
else if (ISOPTION (word, '-'))
|
||||
{
|
||||
list = list->next;
|
||||
break;
|
||||
}
|
||||
else if (ISOPTION (word, '?'))
|
||||
{
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
/* If this is a signal specification then process it. We only process
|
||||
the first one seen; other arguments may signify process groups (e.g,
|
||||
-num == process group num). */
|
||||
else if (*word == '-' && saw_signal == 0)
|
||||
{
|
||||
sigspec = word + 1;
|
||||
sig = decode_signal (sigspec, dflags);
|
||||
saw_signal++;
|
||||
list = list->next;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (listing)
|
||||
return (display_signal_list (list, 0));
|
||||
|
||||
/* OK, we are killing processes. */
|
||||
if (sig == NO_SIG)
|
||||
{
|
||||
sh_invalidsig (sigspec);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
while (list)
|
||||
{
|
||||
word = list->word->word;
|
||||
|
||||
if (*word == '-')
|
||||
word++;
|
||||
|
||||
/* Use the entire argument in case of minus sign presence. */
|
||||
if (*word && legal_number (list->word->word, &pid_value) && (pid_value == (pid_t)pid_value))
|
||||
{
|
||||
pid = (pid_t) pid_value;
|
||||
|
||||
if (kill_pid (pid, sig, pid < -1) < 0)
|
||||
{
|
||||
if (errno == EINVAL)
|
||||
sh_invalidsig (sigspec);
|
||||
else
|
||||
kill_error (pid, errno);
|
||||
CONTINUE_OR_FAIL;
|
||||
}
|
||||
else
|
||||
any_succeeded++;
|
||||
}
|
||||
#if defined (JOB_CONTROL)
|
||||
else if (*list->word->word && *list->word->word != '%')
|
||||
{
|
||||
builtin_error (_("%s: arguments must be process or job IDs"), list->word->word);
|
||||
CONTINUE_OR_FAIL;
|
||||
}
|
||||
else if (*word)
|
||||
/* Posix.2 says you can kill without job control active (4.32.4) */
|
||||
{ /* Must be a job spec. Check it out. */
|
||||
int job;
|
||||
sigset_t set, oset;
|
||||
JOB *j;
|
||||
|
||||
BLOCK_CHILD (set, oset);
|
||||
job = get_job_spec (list);
|
||||
|
||||
if (INVALID_JOB (job))
|
||||
{
|
||||
if (job != DUP_JOB)
|
||||
sh_badjob (list->word->word);
|
||||
UNBLOCK_CHILD (oset);
|
||||
CONTINUE_OR_FAIL;
|
||||
}
|
||||
|
||||
j = get_job_by_jid (job);
|
||||
/* Job spec used. Kill the process group. If the job was started
|
||||
without job control, then its pgrp == shell_pgrp, so we have
|
||||
to be careful. We take the pid of the first job in the pipeline
|
||||
in that case. */
|
||||
pid = IS_JOBCONTROL (job) ? j->pgrp : j->pipe->pid;
|
||||
|
||||
UNBLOCK_CHILD (oset);
|
||||
|
||||
if (kill_pid (pid, sig, 1) < 0)
|
||||
{
|
||||
if (errno == EINVAL)
|
||||
sh_invalidsig (sigspec);
|
||||
else
|
||||
kill_error (pid, errno);
|
||||
CONTINUE_OR_FAIL;
|
||||
}
|
||||
else
|
||||
any_succeeded++;
|
||||
}
|
||||
#endif /* !JOB_CONTROL */
|
||||
else
|
||||
{
|
||||
sh_badpid (list->word->word);
|
||||
CONTINUE_OR_FAIL;
|
||||
}
|
||||
continue_killing:
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return (any_succeeded ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
static void
|
||||
kill_error (pid, e)
|
||||
pid_t pid;
|
||||
int e;
|
||||
{
|
||||
char *x;
|
||||
|
||||
x = strerror (e);
|
||||
if (x == 0)
|
||||
x = _("Unknown error");
|
||||
builtin_error ("(%ld) - %s", (long)pid, x);
|
||||
}
|
131
builtins/let.def
Normal file
131
builtins/let.def
Normal file
|
@ -0,0 +1,131 @@
|
|||
This file is let.def, from which is created let.c.
|
||||
It implements the builtin "let" in Bash.
|
||||
|
||||
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 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/>.
|
||||
|
||||
$BUILTIN let
|
||||
$FUNCTION let_builtin
|
||||
$PRODUCES let.c
|
||||
$SHORT_DOC let arg [arg ...]
|
||||
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
|
||||
-, + unary minus, plus
|
||||
!, ~ logical and bitwise negation
|
||||
** exponentiation
|
||||
*, /, % multiplication, division, remainder
|
||||
+, - addition, subtraction
|
||||
<<, >> left and right bitwise shifts
|
||||
<=, >=, <, > comparison
|
||||
==, != equality, inequality
|
||||
& bitwise AND
|
||||
^ bitwise XOR
|
||||
| bitwise OR
|
||||
&& logical AND
|
||||
|| logical OR
|
||||
expr ? expr : expr
|
||||
conditional operator
|
||||
=, *=, /=, %=,
|
||||
+=, -=, <<=, >>=,
|
||||
&=, ^=, |= assignment
|
||||
|
||||
Shell variables are allowed as operands. The name of the variable
|
||||
is replaced by its value (coerced to a fixed-width integer) within
|
||||
an expression. The variable need not have its integer attribute
|
||||
turned on to be used in an expression.
|
||||
|
||||
Operators are evaluated in order of precedence. Sub-expressions in
|
||||
parentheses are evaluated first and may override the precedence
|
||||
rules above.
|
||||
|
||||
Exit Status:
|
||||
If the last ARG evaluates to 0, let returns 1; let returns 0 otherwise.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "common.h"
|
||||
|
||||
/* Arithmetic LET function. */
|
||||
int
|
||||
let_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
intmax_t ret;
|
||||
int expok;
|
||||
|
||||
CHECK_HELPOPT (list);
|
||||
|
||||
/* Skip over leading `--' argument. */
|
||||
if (list && list->word && ISOPTION (list->word->word, '-'))
|
||||
list = list->next;
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
builtin_error (_("expression expected"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
for (; list; list = list->next)
|
||||
{
|
||||
ret = evalexp (list->word->word, EXP_EXPANDED, &expok);
|
||||
if (expok == 0)
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
return ((ret == 0) ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_UNUSED
|
||||
int
|
||||
exp_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
char *exp;
|
||||
intmax_t ret;
|
||||
int expok;
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
builtin_error (_("expression expected"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
exp = string_list (list);
|
||||
ret = evalexp (exp, EXP_EXPANDED, &expok);
|
||||
(void)free (exp);
|
||||
return (((ret == 0) || (expok == 0)) ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
|
||||
}
|
||||
#endif
|
364
builtins/mapfile.def
Normal file
364
builtins/mapfile.def
Normal file
|
@ -0,0 +1,364 @@
|
|||
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-2021 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 [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
|
||||
Read lines from the standard input into an indexed array variable.
|
||||
|
||||
Read lines from the standard input into the indexed array variable ARRAY, or
|
||||
from file descriptor FD if the -u option is supplied. The variable MAPFILE
|
||||
is the default ARRAY.
|
||||
|
||||
Options:
|
||||
-d delim Use DELIM to terminate lines, instead of newline
|
||||
-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 DELIM from each line read (default newline)
|
||||
-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. When
|
||||
CALLBACK is evaluated, it is supplied the index of the next array
|
||||
element to be assigned and the line to be assigned to that element
|
||||
as additional arguments.
|
||||
|
||||
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 or
|
||||
not an indexed array.
|
||||
$END
|
||||
|
||||
$BUILTIN readarray
|
||||
$FUNCTION mapfile_builtin
|
||||
$SHORT_DOC readarray [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
|
||||
Read lines from a file into an array variable.
|
||||
|
||||
A synonym for `mapfile'.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "builtins.h"
|
||||
#include "../bashtypes.h"
|
||||
#include "posixstat.h"
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "bashansi.h"
|
||||
#include "bashintl.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)
|
||||
|
||||
static int run_callback PARAMS((const char *, unsigned int, const char *));
|
||||
|
||||
#define DEFAULT_ARRAY_NAME "MAPFILE"
|
||||
#define DEFAULT_VARIABLE_NAME "MAPLINE" /* not used right now */
|
||||
|
||||
/* 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 delim;
|
||||
|
||||
static int
|
||||
run_callback (callback, curindex, curline)
|
||||
const char *callback;
|
||||
unsigned int curindex;
|
||||
const char *curline;
|
||||
{
|
||||
unsigned int execlen;
|
||||
char *execstr, *qline;
|
||||
int flags;
|
||||
|
||||
qline = sh_single_quote (curline);
|
||||
execlen = strlen (callback) + strlen (qline) + 10;
|
||||
/* 1 for each space between %s and %d,
|
||||
another 1 for the last nul char for C string. */
|
||||
execlen += 3;
|
||||
execstr = xmalloc (execlen);
|
||||
|
||||
flags = SEVAL_NOHIST;
|
||||
#if 0
|
||||
if (interactive)
|
||||
flags |= SEVAL_INTERACT;
|
||||
#endif
|
||||
snprintf (execstr, execlen, "%s %d %s", callback, curindex, qline);
|
||||
free (qline);
|
||||
return evalstring (execstr, NULL, flags);
|
||||
}
|
||||
|
||||
static void
|
||||
do_chop(line, delim)
|
||||
char *line;
|
||||
unsigned char delim;
|
||||
{
|
||||
int length;
|
||||
|
||||
length = strlen (line);
|
||||
if (length && (unsigned char)line[length-1] == delim)
|
||||
line[length-1] = '\0';
|
||||
}
|
||||
|
||||
static int
|
||||
mapfile (fd, line_count_goal, origin, nskip, callback_quantum, callback, array_name, delim, flags)
|
||||
int fd;
|
||||
long line_count_goal, origin, nskip, callback_quantum;
|
||||
char *callback, *array_name;
|
||||
int delim;
|
||||
int flags;
|
||||
{
|
||||
char *line;
|
||||
size_t line_length;
|
||||
unsigned int array_index, line_count;
|
||||
SHELL_VAR *entry;
|
||||
struct stat sb;
|
||||
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 = builtin_find_indexed_array (array_name, flags & MAPF_CLEARARRAY);
|
||||
if (entry == 0)
|
||||
return EXECUTION_FAILURE;
|
||||
|
||||
#ifndef __CYGWIN__
|
||||
/* If the delimiter is a newline, turn on unbuffered reads for pipes
|
||||
(terminals are ok). If the delimiter is not a newline, unbuffered reads
|
||||
for every file descriptor that's not a regular file. */
|
||||
if (delim == '\n')
|
||||
unbuffered_read = (lseek (fd, 0L, SEEK_CUR) < 0) && (errno == ESPIPE);
|
||||
else
|
||||
unbuffered_read = (fstat (fd, &sb) != 0) || (S_ISREG (sb.st_mode) == 0);
|
||||
#else
|
||||
unbuffered_read = 1;
|
||||
#endif
|
||||
|
||||
zreset ();
|
||||
|
||||
/* Skip any lines at beginning of file? */
|
||||
for (line_count = 0; line_count < nskip; line_count++)
|
||||
if (zgetline (fd, &line, &line_length, delim, unbuffered_read) < 0)
|
||||
break;
|
||||
|
||||
line = 0;
|
||||
line_length = 0;
|
||||
|
||||
/* Reset the buffer for bash own stream */
|
||||
for (array_index = origin, line_count = 1;
|
||||
zgetline (fd, &line, &line_length, delim, unbuffered_read) != -1;
|
||||
array_index++)
|
||||
{
|
||||
/* Remove trailing newlines? */
|
||||
if (flags & MAPF_CHOP)
|
||||
do_chop (line, delim);
|
||||
|
||||
/* Has a callback been registered and if so is it time to call it? */
|
||||
if (callback && line_count && (line_count % callback_quantum) == 0)
|
||||
{
|
||||
/* Reset the buffer for bash own stream. */
|
||||
if (unbuffered_read == 0)
|
||||
zsyncfd (fd);
|
||||
|
||||
run_callback (callback, array_index, line);
|
||||
}
|
||||
|
||||
/* XXX - bad things can happen if the callback modifies ENTRY, e.g.,
|
||||
unsetting it or changing it to a non-indexed-array type. */
|
||||
bind_array_element (entry, array_index, line, 0);
|
||||
|
||||
/* Have we exceeded # of lines to store? */
|
||||
line_count++;
|
||||
if (line_count_goal != 0 && line_count > line_count_goal)
|
||||
break;
|
||||
}
|
||||
|
||||
free (line);
|
||||
|
||||
if (unbuffered_read == 0)
|
||||
zsyncfd (fd);
|
||||
|
||||
return EXECUTION_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
mapfile_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int opt, code, fd, flags;
|
||||
intmax_t intval;
|
||||
long lines, origin, nskip, callback_quantum;
|
||||
char *array_name, *callback;
|
||||
|
||||
fd = 0;
|
||||
lines = origin = nskip = 0;
|
||||
flags = MAPF_CLEARARRAY;
|
||||
callback_quantum = DEFAULT_QUANTUM;
|
||||
callback = 0;
|
||||
delim = '\n';
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "d:u:n:O:tC:c:s:")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'd':
|
||||
delim = *list_optarg;
|
||||
break;
|
||||
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;
|
||||
CASE_HELPOPT;
|
||||
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)
|
||||
{
|
||||
sh_invalidid (array_name);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
return mapfile (fd, lines, origin, nskip, callback_quantum, callback, array_name, delim, flags);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
mapfile_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
builtin_error (_("array variable support required"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
#endif /* ARRAY_VARS */
|
1692
builtins/mkbuiltins.c
Normal file
1692
builtins/mkbuiltins.c
Normal file
File diff suppressed because it is too large
Load diff
1355
builtins/printf.def
Normal file
1355
builtins/printf.def
Normal file
File diff suppressed because it is too large
Load diff
79
builtins/psize.c
Normal file
79
builtins/psize.c
Normal file
|
@ -0,0 +1,79 @@
|
|||
/* psize.c - Find pipe size. */
|
||||
|
||||
/* Copyright (C) 1987, 1991 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/>.
|
||||
*/
|
||||
|
||||
/* 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
|
||||
pipe size. */
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#ifndef _MINIX
|
||||
#include "../bashtypes.h"
|
||||
#endif
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../command.h"
|
||||
#include "../general.h"
|
||||
#include "../sig.h"
|
||||
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
int nw;
|
||||
|
||||
sighandler
|
||||
sigpipe (sig)
|
||||
int sig;
|
||||
{
|
||||
fprintf (stderr, "%d\n", nw);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
int
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
char buf[128];
|
||||
register int i;
|
||||
|
||||
for (i = 0; i < 128; i++)
|
||||
buf[i] = ' ';
|
||||
|
||||
signal (SIGPIPE, sigpipe);
|
||||
|
||||
nw = 0;
|
||||
for (;;)
|
||||
{
|
||||
int n;
|
||||
n = write (1, buf, 128);
|
||||
nw += n;
|
||||
}
|
||||
return (0);
|
||||
}
|
45
builtins/psize.sh
Normal file
45
builtins/psize.sh
Normal file
|
@ -0,0 +1,45 @@
|
|||
#! /bin/sh
|
||||
#
|
||||
# psize.sh -- determine this system's pipe size, and write a define to
|
||||
# pipesize.h so ulimit.c can use it.
|
||||
|
||||
: ${TMPDIR:=/tmp}
|
||||
# try to use mktemp(1) if the system supports it
|
||||
{ TMPFILE="`mktemp $TMPDIR/pipsize.XXXXXX 2>/dev/null`"; } 2>/dev/null
|
||||
used_mktemp=true
|
||||
|
||||
if [ -z "$TMPFILE" ]; then
|
||||
TMPNAME=pipsize.$$
|
||||
TMPFILE=$TMPDIR/$TMPNAME
|
||||
used_mktemp=false
|
||||
fi
|
||||
|
||||
trap 'rm -f "$TMPFILE" ; exit 1' 1 2 3 6 15
|
||||
trap 'rm -f "$TMPFILE"' 0
|
||||
|
||||
echo "/*"
|
||||
echo " * pipesize.h"
|
||||
echo " *"
|
||||
echo " * This file is automatically generated by psize.sh"
|
||||
echo " * Do not edit!"
|
||||
echo " */"
|
||||
echo ""
|
||||
|
||||
#
|
||||
# Try to avoid tempfile races. We can't really check for the file's
|
||||
# existence before we run psize.aux, because `test -e' is not portable,
|
||||
# `test -h' (test for symlinks) is not portable, and `test -f' only
|
||||
# checks for regular files. If we used mktemp(1), we're ahead of the
|
||||
# game.
|
||||
#
|
||||
$used_mktemp || rm -f "$TMPFILE"
|
||||
|
||||
./psize.aux 2>"$TMPFILE" | sleep 3
|
||||
|
||||
if [ -s "$TMPFILE" ]; then
|
||||
echo "#define PIPESIZE `cat "$TMPFILE"`"
|
||||
else
|
||||
echo "#define PIPESIZE 512"
|
||||
fi
|
||||
|
||||
exit 0
|
796
builtins/pushd.def
Normal file
796
builtins/pushd.def
Normal file
|
@ -0,0 +1,796 @@
|
|||
This file is pushd.def, from which is created pushd.c. It implements the
|
||||
builtins "pushd", "popd", and "dirs" in Bash.
|
||||
|
||||
Copyright (C) 1987-2020 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 pushd.c
|
||||
|
||||
$BUILTIN pushd
|
||||
$FUNCTION pushd_builtin
|
||||
$DEPENDS_ON PUSHD_AND_POPD
|
||||
$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.
|
||||
|
||||
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
|
||||
from the right of the list shown by `dirs', starting with
|
||||
zero) is at the top.
|
||||
|
||||
dir Adds DIR to the directory stack at the top, making it the
|
||||
new current working directory.
|
||||
|
||||
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]
|
||||
Remove directories from stack.
|
||||
|
||||
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
|
||||
shown by `dirs', starting with zero. For example: `popd -0'
|
||||
removes the last directory, `popd -1' the next to last.
|
||||
|
||||
The `dirs' builtin displays the directory stack.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
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 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>
|
||||
|
||||
#if defined (PUSHD_AND_POPD)
|
||||
#include <stdio.h>
|
||||
#if defined (HAVE_SYS_PARAM_H)
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <tilde/tilde.h>
|
||||
|
||||
#include "../shell.h"
|
||||
#include "maxpath.h"
|
||||
#include "common.h"
|
||||
#include "builtext.h"
|
||||
|
||||
#ifdef LOADABLE_BUILTIN
|
||||
# include "builtins.h"
|
||||
#endif
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif /* !errno */
|
||||
|
||||
/* The list of remembered directories. */
|
||||
static char **pushd_directory_list = (char **)NULL;
|
||||
|
||||
/* Number of existing slots in this list. */
|
||||
static int directory_list_size;
|
||||
|
||||
/* Offset to the end of the list. */
|
||||
static int directory_list_offset;
|
||||
|
||||
static void pushd_error PARAMS((int, char *));
|
||||
static void clear_directory_stack PARAMS((void));
|
||||
static int cd_to_string PARAMS((char *));
|
||||
static int change_to_temp PARAMS((char *));
|
||||
static void add_dirstack_element PARAMS((char *));
|
||||
static int get_dirstack_index PARAMS((intmax_t, int, int *));
|
||||
|
||||
#define NOCD 0x01
|
||||
#define ROTATE 0x02
|
||||
#define LONGFORM 0x04
|
||||
#define CLEARSTAK 0x08
|
||||
|
||||
int
|
||||
pushd_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
WORD_LIST *orig_list;
|
||||
char *temp, *current_directory, *top;
|
||||
int j, flags, skipopt;
|
||||
intmax_t num;
|
||||
char direction;
|
||||
|
||||
orig_list = list;
|
||||
|
||||
CHECK_HELPOPT (list);
|
||||
if (list && list->word && ISOPTION (list->word->word, '-'))
|
||||
{
|
||||
list = list->next;
|
||||
skipopt = 1;
|
||||
}
|
||||
else
|
||||
skipopt = 0;
|
||||
|
||||
/* If there is no argument list then switch current and
|
||||
top of list. */
|
||||
if (list == 0)
|
||||
{
|
||||
if (directory_list_offset == 0)
|
||||
{
|
||||
builtin_error (_("no other directory"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
current_directory = get_working_directory ("pushd");
|
||||
if (current_directory == 0)
|
||||
return (EXECUTION_FAILURE);
|
||||
|
||||
j = directory_list_offset - 1;
|
||||
temp = pushd_directory_list[j];
|
||||
pushd_directory_list[j] = current_directory;
|
||||
j = change_to_temp (temp);
|
||||
free (temp);
|
||||
return j;
|
||||
}
|
||||
|
||||
for (flags = 0; skipopt == 0 && list; list = list->next)
|
||||
{
|
||||
if (ISOPTION (list->word->word, 'n'))
|
||||
{
|
||||
flags |= NOCD;
|
||||
}
|
||||
else if (ISOPTION (list->word->word, '-'))
|
||||
{
|
||||
list = list->next;
|
||||
break;
|
||||
}
|
||||
else if (list->word->word[0] == '-' && list->word->word[1] == '\0')
|
||||
/* Let `pushd -' work like it used to. */
|
||||
break;
|
||||
else if (((direction = list->word->word[0]) == '+') || direction == '-')
|
||||
{
|
||||
if (legal_number (list->word->word + 1, &num) == 0)
|
||||
{
|
||||
sh_invalidnum (list->word->word);
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
if (direction == '-')
|
||||
num = directory_list_offset - num;
|
||||
|
||||
if (num > directory_list_offset || num < 0)
|
||||
{
|
||||
pushd_error (directory_list_offset, list->word->word);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
flags |= ROTATE;
|
||||
}
|
||||
else if (*list->word->word == '-')
|
||||
{
|
||||
sh_invalidopt (list->word->word);
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (flags & ROTATE)
|
||||
{
|
||||
/* Rotate the stack num times. Remember, the current
|
||||
directory acts like it is part of the stack. */
|
||||
temp = get_working_directory ("pushd");
|
||||
|
||||
if (num == 0)
|
||||
{
|
||||
j = ((flags & NOCD) == 0) ? change_to_temp (temp) : EXECUTION_SUCCESS;
|
||||
free (temp);
|
||||
return j;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
top = pushd_directory_list[directory_list_offset - 1];
|
||||
|
||||
for (j = directory_list_offset - 2; j > -1; j--)
|
||||
pushd_directory_list[j + 1] = pushd_directory_list[j];
|
||||
|
||||
pushd_directory_list[j + 1] = temp;
|
||||
|
||||
temp = top;
|
||||
num--;
|
||||
}
|
||||
while (num);
|
||||
|
||||
j = ((flags & NOCD) == 0) ? change_to_temp (temp) : EXECUTION_SUCCESS;
|
||||
free (temp);
|
||||
return j;
|
||||
}
|
||||
|
||||
if (list == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
/* Change to the directory in list->word->word. Save the current
|
||||
directory on the top of the stack. */
|
||||
current_directory = get_working_directory ("pushd");
|
||||
if (current_directory == 0)
|
||||
return (EXECUTION_FAILURE);
|
||||
|
||||
j = ((flags & NOCD) == 0) ? cd_builtin (skipopt ? orig_list : list) : EXECUTION_SUCCESS;
|
||||
if (j == EXECUTION_SUCCESS)
|
||||
{
|
||||
add_dirstack_element ((flags & NOCD) ? savestring (list->word->word) : current_directory);
|
||||
dirs_builtin ((WORD_LIST *)NULL);
|
||||
if (flags & NOCD)
|
||||
free (current_directory);
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
free (current_directory);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Pop the directory stack, and then change to the new top of the stack.
|
||||
If LIST is non-null it should consist of a word +N or -N, which says
|
||||
what element to delete from the stack. The default is the top one. */
|
||||
int
|
||||
popd_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
register int i;
|
||||
intmax_t which;
|
||||
int flags;
|
||||
char direction;
|
||||
char *which_word;
|
||||
|
||||
CHECK_HELPOPT (list);
|
||||
|
||||
which_word = (char *)NULL;
|
||||
for (flags = 0, which = 0, direction = '+'; list; list = list->next)
|
||||
{
|
||||
if (ISOPTION (list->word->word, 'n'))
|
||||
{
|
||||
flags |= NOCD;
|
||||
}
|
||||
else if (ISOPTION (list->word->word, '-'))
|
||||
{
|
||||
list = list->next;
|
||||
break;
|
||||
}
|
||||
else if (((direction = list->word->word[0]) == '+') || direction == '-')
|
||||
{
|
||||
if (legal_number (list->word->word + 1, &which) == 0)
|
||||
{
|
||||
sh_invalidnum (list->word->word);
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
which_word = list->word->word;
|
||||
}
|
||||
else if (*list->word->word == '-')
|
||||
{
|
||||
sh_invalidopt (list->word->word);
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
else if (*list->word->word)
|
||||
{
|
||||
builtin_error (_("%s: invalid argument"), list->word->word);
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (which > directory_list_offset || (which < -directory_list_offset) || (directory_list_offset == 0 && which == 0))
|
||||
{
|
||||
pushd_error (directory_list_offset, which_word ? which_word : "");
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
/* Handle case of no specification, or top of stack specification. */
|
||||
if ((direction == '+' && which == 0) ||
|
||||
(direction == '-' && which == directory_list_offset))
|
||||
{
|
||||
i = ((flags & NOCD) == 0) ? cd_to_string (pushd_directory_list[directory_list_offset - 1])
|
||||
: EXECUTION_SUCCESS;
|
||||
if (i != EXECUTION_SUCCESS)
|
||||
return (i);
|
||||
free (pushd_directory_list[--directory_list_offset]);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Since an offset other than the top directory was specified,
|
||||
remove that directory from the list and shift the remainder
|
||||
of the list into place. */
|
||||
i = (direction == '+') ? directory_list_offset - which : which;
|
||||
if (i < 0 || i > directory_list_offset)
|
||||
{
|
||||
pushd_error (directory_list_offset, which_word ? which_word : "");
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
free (pushd_directory_list[i]);
|
||||
directory_list_offset--;
|
||||
|
||||
/* Shift the remainder of the list into place. */
|
||||
for (; i < directory_list_offset; i++)
|
||||
pushd_directory_list[i] = pushd_directory_list[i + 1];
|
||||
}
|
||||
|
||||
dirs_builtin ((WORD_LIST *)NULL);
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
/* Print the current list of directories on the directory stack. */
|
||||
int
|
||||
dirs_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int flags, desired_index, index_flag, vflag;
|
||||
intmax_t i;
|
||||
char *temp, *w;
|
||||
|
||||
CHECK_HELPOPT (list);
|
||||
for (flags = vflag = index_flag = 0, desired_index = -1, w = ""; list; list = list->next)
|
||||
{
|
||||
if (ISOPTION (list->word->word, 'l'))
|
||||
{
|
||||
flags |= LONGFORM;
|
||||
}
|
||||
else if (ISOPTION (list->word->word, 'c'))
|
||||
{
|
||||
flags |= CLEARSTAK;
|
||||
}
|
||||
else if (ISOPTION (list->word->word, 'v'))
|
||||
{
|
||||
vflag |= 2;
|
||||
}
|
||||
else if (ISOPTION (list->word->word, 'p'))
|
||||
{
|
||||
vflag |= 1;
|
||||
}
|
||||
else if (ISOPTION (list->word->word, '-'))
|
||||
{
|
||||
list = list->next;
|
||||
break;
|
||||
}
|
||||
else if (*list->word->word == '+' || *list->word->word == '-')
|
||||
{
|
||||
int sign;
|
||||
if (legal_number (w = list->word->word + 1, &i) == 0)
|
||||
{
|
||||
sh_invalidnum (list->word->word);
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
sign = (*list->word->word == '+') ? 1 : -1;
|
||||
desired_index = get_dirstack_index (i, sign, &index_flag);
|
||||
}
|
||||
else
|
||||
{
|
||||
sh_invalidopt (list->word->word);
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & CLEARSTAK)
|
||||
{
|
||||
clear_directory_stack ();
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
if (index_flag && (desired_index < 0 || desired_index > directory_list_offset))
|
||||
{
|
||||
pushd_error (directory_list_offset, w);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
#define DIRSTACK_FORMAT(temp) \
|
||||
(flags & LONGFORM) ? temp : polite_directory_format (temp)
|
||||
|
||||
/* The first directory printed is always the current working directory. */
|
||||
if (index_flag == 0 || (index_flag == 1 && desired_index == 0))
|
||||
{
|
||||
temp = get_working_directory ("dirs");
|
||||
if (temp == 0)
|
||||
temp = savestring (_("<no current directory>"));
|
||||
if (vflag & 2)
|
||||
printf ("%2d %s", 0, DIRSTACK_FORMAT (temp));
|
||||
else
|
||||
printf ("%s", DIRSTACK_FORMAT (temp));
|
||||
free (temp);
|
||||
if (index_flag)
|
||||
{
|
||||
putchar ('\n');
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
}
|
||||
|
||||
#define DIRSTACK_ENTRY(i) \
|
||||
(flags & LONGFORM) ? pushd_directory_list[i] \
|
||||
: polite_directory_format (pushd_directory_list[i])
|
||||
|
||||
/* Now print the requested directory stack entries. */
|
||||
if (index_flag)
|
||||
{
|
||||
if (vflag & 2)
|
||||
printf ("%2d %s", directory_list_offset - desired_index,
|
||||
DIRSTACK_ENTRY (desired_index));
|
||||
else
|
||||
printf ("%s", DIRSTACK_ENTRY (desired_index));
|
||||
}
|
||||
else
|
||||
for (i = directory_list_offset - 1; i >= 0; i--)
|
||||
if (vflag >= 2)
|
||||
printf ("\n%2d %s", directory_list_offset - (int)i, DIRSTACK_ENTRY (i));
|
||||
else
|
||||
printf ("%s%s", (vflag & 1) ? "\n" : " ", DIRSTACK_ENTRY (i));
|
||||
|
||||
putchar ('\n');
|
||||
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
static void
|
||||
pushd_error (offset, arg)
|
||||
int offset;
|
||||
char *arg;
|
||||
{
|
||||
if (offset == 0)
|
||||
builtin_error (_("directory stack empty"));
|
||||
else
|
||||
sh_erange (arg, _("directory stack index"));
|
||||
}
|
||||
|
||||
static void
|
||||
clear_directory_stack ()
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (i = 0; i < directory_list_offset; i++)
|
||||
free (pushd_directory_list[i]);
|
||||
directory_list_offset = 0;
|
||||
}
|
||||
|
||||
/* Switch to the directory in NAME. This uses the cd_builtin to do the work,
|
||||
so if the result is EXECUTION_FAILURE then an error message has already
|
||||
been printed. */
|
||||
static int
|
||||
cd_to_string (name)
|
||||
char *name;
|
||||
{
|
||||
WORD_LIST *tlist;
|
||||
WORD_LIST *dir;
|
||||
int result;
|
||||
|
||||
dir = make_word_list (make_word (name), NULL);
|
||||
tlist = make_word_list (make_word ("--"), dir);
|
||||
result = cd_builtin (tlist);
|
||||
dispose_words (tlist);
|
||||
return (result);
|
||||
}
|
||||
|
||||
static int
|
||||
change_to_temp (temp)
|
||||
char *temp;
|
||||
{
|
||||
int tt;
|
||||
|
||||
tt = temp ? cd_to_string (temp) : EXECUTION_FAILURE;
|
||||
|
||||
if (tt == EXECUTION_SUCCESS)
|
||||
dirs_builtin ((WORD_LIST *)NULL);
|
||||
|
||||
return (tt);
|
||||
}
|
||||
|
||||
static void
|
||||
add_dirstack_element (dir)
|
||||
char *dir;
|
||||
{
|
||||
if (directory_list_offset == directory_list_size)
|
||||
pushd_directory_list = strvec_resize (pushd_directory_list, directory_list_size += 10);
|
||||
pushd_directory_list[directory_list_offset++] = dir;
|
||||
}
|
||||
|
||||
static int
|
||||
get_dirstack_index (ind, sign, indexp)
|
||||
intmax_t ind;
|
||||
int sign, *indexp;
|
||||
{
|
||||
if (indexp)
|
||||
*indexp = sign > 0 ? 1 : 2;
|
||||
|
||||
/* dirs +0 prints the current working directory. */
|
||||
/* dirs -0 prints last element in directory stack */
|
||||
if (ind == 0 && sign > 0)
|
||||
return 0;
|
||||
else if (ind == directory_list_offset)
|
||||
{
|
||||
if (indexp)
|
||||
*indexp = sign > 0 ? 2 : 1;
|
||||
return 0;
|
||||
}
|
||||
else if (ind >= 0 && ind <= directory_list_offset)
|
||||
return (sign > 0 ? directory_list_offset - ind : ind);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Used by the tilde expansion code. */
|
||||
char *
|
||||
get_dirstack_from_string (string)
|
||||
char *string;
|
||||
{
|
||||
int ind, sign, index_flag;
|
||||
intmax_t i;
|
||||
|
||||
sign = 1;
|
||||
if (*string == '-' || *string == '+')
|
||||
{
|
||||
sign = (*string == '-') ? -1 : 1;
|
||||
string++;
|
||||
}
|
||||
if (legal_number (string, &i) == 0)
|
||||
return ((char *)NULL);
|
||||
|
||||
index_flag = 0;
|
||||
ind = get_dirstack_index (i, sign, &index_flag);
|
||||
if (index_flag && (ind < 0 || ind > directory_list_offset))
|
||||
return ((char *)NULL);
|
||||
if (index_flag == 0 || (index_flag == 1 && ind == 0))
|
||||
return (get_string_value ("PWD"));
|
||||
else
|
||||
return (pushd_directory_list[ind]);
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_UNUSED
|
||||
char *
|
||||
get_dirstack_element (ind, sign)
|
||||
intmax_t ind;
|
||||
int sign;
|
||||
{
|
||||
int i;
|
||||
|
||||
i = get_dirstack_index (ind, sign, (int *)NULL);
|
||||
return (i < 0 || i > directory_list_offset) ? (char *)NULL
|
||||
: pushd_directory_list[i];
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
set_dirstack_element (ind, sign, value)
|
||||
intmax_t ind;
|
||||
int sign;
|
||||
char *value;
|
||||
{
|
||||
int i;
|
||||
|
||||
i = get_dirstack_index (ind, sign, (int *)NULL);
|
||||
if (ind == 0 || i < 0 || i > directory_list_offset)
|
||||
return;
|
||||
free (pushd_directory_list[i]);
|
||||
pushd_directory_list[i] = savestring (value);
|
||||
}
|
||||
|
||||
WORD_LIST *
|
||||
get_directory_stack (flags)
|
||||
int flags;
|
||||
{
|
||||
register int i;
|
||||
WORD_LIST *ret;
|
||||
char *d, *t;
|
||||
|
||||
for (ret = (WORD_LIST *)NULL, i = 0; i < directory_list_offset; i++)
|
||||
{
|
||||
d = (flags&1) ? polite_directory_format (pushd_directory_list[i])
|
||||
: pushd_directory_list[i];
|
||||
ret = make_word_list (make_word (d), ret);
|
||||
}
|
||||
/* Now the current directory. */
|
||||
d = get_working_directory ("dirstack");
|
||||
i = 0; /* sentinel to decide whether or not to free d */
|
||||
if (d == 0)
|
||||
d = ".";
|
||||
else
|
||||
{
|
||||
t = (flags&1) ? polite_directory_format (d) : d;
|
||||
/* polite_directory_format sometimes returns its argument unchanged.
|
||||
If it does not, we can free d right away. If it does, we need to
|
||||
mark d to be deleted later. */
|
||||
if (t != d)
|
||||
{
|
||||
free (d);
|
||||
d = t;
|
||||
}
|
||||
else /* t == d, so d is what we want */
|
||||
i = 1;
|
||||
}
|
||||
ret = make_word_list (make_word (d), ret);
|
||||
if (i)
|
||||
free (d);
|
||||
return ret; /* was (REVERSE_LIST (ret, (WORD_LIST *)); */
|
||||
}
|
||||
|
||||
#ifdef LOADABLE_BUILTIN
|
||||
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\
|
||||
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\
|
||||
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, 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
|
||||
};
|
||||
|
||||
struct builtin pushd_struct = {
|
||||
"pushd",
|
||||
pushd_builtin,
|
||||
BUILTIN_ENABLED,
|
||||
pushd_doc,
|
||||
"pushd [+N | -N] [-n] [dir]",
|
||||
0
|
||||
};
|
||||
|
||||
struct builtin popd_struct = {
|
||||
"popd",
|
||||
popd_builtin,
|
||||
BUILTIN_ENABLED,
|
||||
popd_doc,
|
||||
"popd [+N | -N] [-n]",
|
||||
0
|
||||
};
|
||||
|
||||
struct builtin dirs_struct = {
|
||||
"dirs",
|
||||
dirs_builtin,
|
||||
BUILTIN_ENABLED,
|
||||
dirs_doc,
|
||||
"dirs [-clpv] [+N] [-N]",
|
||||
0
|
||||
};
|
||||
#endif /* LOADABLE_BUILTIN */
|
||||
|
||||
#endif /* PUSHD_AND_POPD */
|
1273
builtins/read.def
Normal file
1273
builtins/read.def
Normal file
File diff suppressed because it is too large
Load diff
288
builtins/reserved.def
Normal file
288
builtins/reserved.def
Normal file
|
@ -0,0 +1,288 @@
|
|||
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-2019 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/>.
|
||||
|
||||
$BUILTIN for
|
||||
$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
|
||||
COMMANDS
|
||||
(( EXP3 ))
|
||||
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 "$@"'
|
||||
is assumed. The PS3 prompt is then displayed and a line read
|
||||
from the standard input. If the line consists of the number
|
||||
corresponding to one of the displayed words, then NAME is set
|
||||
to that word. If the line is empty, WORDS and the prompt are
|
||||
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
|
||||
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.
|
||||
|
||||
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
|
||||
`then COMMANDS' list is executed and the if command completes. Otherwise,
|
||||
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-2; done
|
||||
Execute commands as long as a test succeeds.
|
||||
|
||||
Expand and execute COMMANDS-2 as long as the final command in 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-2; done
|
||||
Execute commands as long as a test does not succeed.
|
||||
|
||||
Expand and execute COMMANDS-2 as long as the final command in COMMANDS has
|
||||
an exit status which is not zero.
|
||||
|
||||
Exit Status:
|
||||
Returns the status of the last command executed.
|
||||
$END
|
||||
|
||||
$BUILTIN coproc
|
||||
$SHORT_DOC coproc [NAME] command [redirections]
|
||||
Create a coprocess named NAME.
|
||||
|
||||
Execute COMMAND asynchronously, with the standard output and standard
|
||||
input of the command connected via a pipe to file descriptors assigned
|
||||
to indices 0 and 1 of an array variable NAME in the executing shell.
|
||||
The default NAME is "COPROC".
|
||||
|
||||
Exit Status:
|
||||
The coproc command returns an exit status of 0.
|
||||
$END
|
||||
|
||||
$BUILTIN function
|
||||
$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 [&]
|
||||
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:
|
||||
|
||||
( 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.
|
||||
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 - 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 directories given as arguments to `cd'.
|
||||
GLOBIGNORE A colon-separated list of patterns describing filenames to
|
||||
be ignored by pathname expansion.
|
||||
#if defined (HISTORY)
|
||||
HISTFILE The name of the file where your command history is stored.
|
||||
HISTFILESIZE The maximum number of lines this file can contain.
|
||||
HISTSIZE The maximum number of history lines that a running
|
||||
shell can access.
|
||||
#endif /* HISTORY */
|
||||
HOME The complete pathname to your login directory.
|
||||
HOSTNAME The name of the current host.
|
||||
HOSTTYPE The type of CPU this version of Bash is running under.
|
||||
IGNOREEOF Controls the action of the shell on receipt of an EOF
|
||||
character as the sole input. If set, then the value
|
||||
of it is the number of EOF characters that can be seen
|
||||
in a row on an empty line before the shell will exit
|
||||
(default 10). When unset, EOF signifies the end of input.
|
||||
MACHTYPE A string describing the current system Bash is running on.
|
||||
MAILCHECK How often, in seconds, Bash checks for new mail.
|
||||
MAILPATH A colon-separated list of filenames which Bash checks
|
||||
for new mail.
|
||||
OSTYPE The version of Unix this version of Bash is running on.
|
||||
PATH A colon-separated list of directories to search when
|
||||
looking for commands.
|
||||
PROMPT_COMMAND A command to be executed before the printing of each
|
||||
primary prompt.
|
||||
PS1 The primary prompt string.
|
||||
PS2 The secondary prompt string.
|
||||
PWD The full pathname of the current directory.
|
||||
SHELLOPTS A colon-separated list of enabled shell options.
|
||||
TERM The name of the current terminal type.
|
||||
TIMEFORMAT The output format for timing statistics displayed by the
|
||||
`time' reserved word.
|
||||
auto_resume Non-null means a command word appearing on a line by
|
||||
itself is first looked for in the list of currently
|
||||
stopped jobs. If found there, that job is foregrounded.
|
||||
A value of `exact' means that the command word must
|
||||
exactly match a command in the list of stopped jobs. A
|
||||
value of `substring' means that the command word must
|
||||
match a substring of the job. Any other value means that
|
||||
the command must be a prefix of a stopped job.
|
||||
#if defined (HISTORY)
|
||||
# if defined (BANG_HISTORY)
|
||||
histchars Characters controlling history expansion and quick
|
||||
substitution. The first character is the history
|
||||
substitution character, usually `!'. The second is
|
||||
the `quick substitution' character, usually `^'. The
|
||||
third is the `history comment' character, usually `#'.
|
||||
# endif /* BANG_HISTORY */
|
||||
HISTIGNORE A colon-separated list of patterns used to decide which
|
||||
commands should be saved on the history list.
|
||||
#endif /* HISTORY */
|
||||
$END
|
71
builtins/return.def
Normal file
71
builtins/return.def
Normal file
|
@ -0,0 +1,71 @@
|
|||
This file is return.def, from which is created return.c.
|
||||
It implements the builtin "return" in Bash.
|
||||
|
||||
Copyright (C) 1987-2015 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 return.c
|
||||
|
||||
$BUILTIN return
|
||||
|
||||
$FUNCTION return_builtin
|
||||
$SHORT_DOC return [n]
|
||||
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>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
/* If we are executing a user-defined function then exit with the value
|
||||
specified as an argument. if no argument is given, then the last
|
||||
exit status is used. */
|
||||
int
|
||||
return_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
CHECK_HELPOPT (list);
|
||||
|
||||
return_catch_value = get_exitstat (list);
|
||||
|
||||
if (return_catch_flag)
|
||||
sh_longjmp (return_catch, 1);
|
||||
else
|
||||
{
|
||||
builtin_error (_("can only `return' from a function or sourced script"));
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
1028
builtins/set.def
Normal file
1028
builtins/set.def
Normal file
File diff suppressed because it is too large
Load diff
672
builtins/setattr.def
Normal file
672
builtins/setattr.def
Normal file
|
@ -0,0 +1,672 @@
|
|||
This file is setattr.def, from which is created setattr.c.
|
||||
It implements the builtins "export" and "readonly", in Bash.
|
||||
|
||||
Copyright (C) 1987-2021 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 setattr.c
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "../flags.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
extern sh_builtin_func_t *this_shell_builtin;
|
||||
|
||||
#ifdef ARRAY_VARS
|
||||
extern int declare_builtin PARAMS((WORD_LIST *));
|
||||
#endif
|
||||
|
||||
#define READONLY_OR_EXPORT \
|
||||
(this_shell_builtin == readonly_builtin || this_shell_builtin == export_builtin)
|
||||
|
||||
$BUILTIN export
|
||||
$FUNCTION export_builtin
|
||||
$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
|
||||
environment passed to simple commands. If there is no LIST, then
|
||||
print all such variables. An argument of `-n' says to remove the
|
||||
exported attribute from variables named in LIST. An argument of
|
||||
-f indicates that the names present in LIST refer to functions. */
|
||||
int
|
||||
export_builtin (list)
|
||||
register WORD_LIST *list;
|
||||
{
|
||||
return (set_or_show_attributes (list, att_exported, 0));
|
||||
}
|
||||
|
||||
$BUILTIN readonly
|
||||
$FUNCTION readonly_builtin
|
||||
$SHORT_DOC readonly [-aAf] [name[=value] ...] or readonly -p
|
||||
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 or functions,
|
||||
depending on whether or not the -f option is given
|
||||
|
||||
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
|
||||
empty LIST, print out all existing readonly variables. */
|
||||
int
|
||||
readonly_builtin (list)
|
||||
register WORD_LIST *list;
|
||||
{
|
||||
return (set_or_show_attributes (list, att_readonly, 0));
|
||||
}
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
# define ATTROPTS "aAfnp"
|
||||
#else
|
||||
# define ATTROPTS "fnp"
|
||||
#endif
|
||||
|
||||
/* For each variable name in LIST, make that variable have the specified
|
||||
ATTRIBUTE. An arg of `-n' says to remove the attribute from the the
|
||||
remaining names in LIST (doesn't work for readonly). */
|
||||
int
|
||||
set_or_show_attributes (list, attribute, nodefs)
|
||||
register WORD_LIST *list;
|
||||
int attribute, nodefs;
|
||||
{
|
||||
register SHELL_VAR *var;
|
||||
int assign, undo, any_failed, assign_error, opt;
|
||||
int functions_only, arrays_only, assoc_only;
|
||||
int aflags;
|
||||
char *name;
|
||||
#if defined (ARRAY_VARS)
|
||||
WORD_LIST *nlist, *tlist;
|
||||
WORD_DESC *w;
|
||||
char optw[8];
|
||||
int opti;
|
||||
#endif
|
||||
|
||||
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)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'n':
|
||||
undo = 1;
|
||||
break;
|
||||
case 'f':
|
||||
functions_only = 1;
|
||||
break;
|
||||
#if defined (ARRAY_VARS)
|
||||
case 'a':
|
||||
arrays_only = 1;
|
||||
break;
|
||||
case 'A':
|
||||
assoc_only = 1;
|
||||
break;
|
||||
#endif
|
||||
case 'p':
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
if (list)
|
||||
{
|
||||
if (attribute & att_exported)
|
||||
array_needs_making = 1;
|
||||
|
||||
/* Cannot undo readonly status, silently disallowed. */
|
||||
if (undo && (attribute & att_readonly))
|
||||
attribute &= ~att_readonly;
|
||||
|
||||
while (list)
|
||||
{
|
||||
name = list->word->word;
|
||||
|
||||
if (functions_only) /* xxx -f name */
|
||||
{
|
||||
var = find_function (name);
|
||||
if (var == 0)
|
||||
{
|
||||
builtin_error (_("%s: not a function"), name);
|
||||
any_failed++;
|
||||
}
|
||||
else if ((attribute & att_exported) && undo == 0 && exportable_function_name (name) == 0)
|
||||
{
|
||||
builtin_error (_("%s: cannot export"), name);
|
||||
any_failed++;
|
||||
}
|
||||
else
|
||||
SETVARATTR (var, attribute, undo);
|
||||
|
||||
list = list->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* xxx [-np] name[=value] */
|
||||
assign = assignment (name, 0);
|
||||
|
||||
aflags = 0;
|
||||
if (assign)
|
||||
{
|
||||
name[assign] = '\0';
|
||||
if (name[assign - 1] == '+')
|
||||
{
|
||||
aflags |= ASS_APPEND;
|
||||
name[assign - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
if (legal_identifier (name) == 0)
|
||||
{
|
||||
sh_invalidid (name);
|
||||
if (assign)
|
||||
assign_error++;
|
||||
else
|
||||
any_failed++;
|
||||
list = list->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (assign) /* xxx [-np] name=value */
|
||||
{
|
||||
name[assign] = '=';
|
||||
if (aflags & ASS_APPEND)
|
||||
name[assign - 1] = '+';
|
||||
#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 || assoc_only)
|
||||
{
|
||||
tlist = list->next;
|
||||
list->next = (WORD_LIST *)NULL;
|
||||
/* Add -g to avoid readonly/export creating local variables:
|
||||
only local/declare/typeset create local variables */
|
||||
opti = 0;
|
||||
optw[opti++] = '-';
|
||||
optw[opti++] = 'g';
|
||||
if (attribute & att_readonly)
|
||||
optw[opti++] = 'r';
|
||||
if (attribute & att_exported)
|
||||
optw[opti++] = 'x';
|
||||
if (arrays_only)
|
||||
optw[opti++] = 'a';
|
||||
else
|
||||
optw[opti++] = 'A';
|
||||
optw[opti] = '\0';
|
||||
|
||||
w = make_word (optw);
|
||||
nlist = make_word_list (w, list);
|
||||
|
||||
opt = declare_builtin (nlist);
|
||||
if (opt != EXECUTION_SUCCESS)
|
||||
assign_error++;
|
||||
list->next = tlist;
|
||||
dispose_word (w);
|
||||
free (nlist);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
/* This word has already been expanded once with command
|
||||
and parameter expansion. Call do_assignment_no_expand (),
|
||||
which does not do command or parameter substitution. If
|
||||
the assignment is not performed correctly, flag an error. */
|
||||
if (do_assignment_no_expand (name) == 0)
|
||||
assign_error++;
|
||||
name[assign] = '\0';
|
||||
if (aflags & ASS_APPEND)
|
||||
name[assign - 1] = '\0';
|
||||
}
|
||||
|
||||
set_var_attribute (name, attribute, undo);
|
||||
if (assign) /* restore word */
|
||||
{
|
||||
name[assign] = '=';
|
||||
if (aflags & ASS_APPEND)
|
||||
name[assign-1] = '+';
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SHELL_VAR **variable_list;
|
||||
register int i;
|
||||
|
||||
if ((attribute & att_function) || functions_only)
|
||||
{
|
||||
variable_list = all_shell_functions ();
|
||||
if (attribute != att_function)
|
||||
attribute &= ~att_function; /* so declare -xf works, for example */
|
||||
}
|
||||
else
|
||||
variable_list = all_shell_variables ();
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
if (attribute & att_array)
|
||||
{
|
||||
arrays_only++;
|
||||
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)
|
||||
{
|
||||
for (i = 0; var = variable_list[i]; i++)
|
||||
{
|
||||
#if defined (ARRAY_VARS)
|
||||
if (arrays_only && array_p (var) == 0)
|
||||
continue;
|
||||
else if (assoc_only && assoc_p (var) == 0)
|
||||
continue;
|
||||
#endif
|
||||
|
||||
/* If we imported a variable that's not a valid identifier, don't
|
||||
show it in any lists. */
|
||||
if ((var->attributes & (att_invisible|att_imported)) == (att_invisible|att_imported))
|
||||
continue;
|
||||
|
||||
if ((var->attributes & attribute))
|
||||
{
|
||||
show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
|
||||
if (any_failed = sh_chkwrite (any_failed))
|
||||
break;
|
||||
}
|
||||
}
|
||||
free (variable_list);
|
||||
}
|
||||
}
|
||||
|
||||
return (assign_error ? EX_BADASSIGN
|
||||
: ((any_failed == 0) ? EXECUTION_SUCCESS
|
||||
: 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++)
|
||||
{
|
||||
/* There is no equivalent `declare -'. */
|
||||
if (variable_context && var->context == variable_context && STREQ (var->name, "-"))
|
||||
printf ("local -\n");
|
||||
else
|
||||
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 all local variable variables with their attributes. This shows unset
|
||||
local variables (all_local_variables called with 0 argument). */
|
||||
int
|
||||
show_local_var_attributes (v, nodefs)
|
||||
int v, nodefs;
|
||||
{
|
||||
SHELL_VAR **variable_list, *var;
|
||||
int any_failed;
|
||||
register int i;
|
||||
|
||||
variable_list = all_local_variables (0);
|
||||
if (variable_list == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
for (i = any_failed = 0; var = variable_list[i]; i++)
|
||||
{
|
||||
/* There is no equivalent `declare -'. */
|
||||
if (STREQ (var->name, "-"))
|
||||
printf ("local -\n");
|
||||
else
|
||||
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);
|
||||
}
|
||||
|
||||
int
|
||||
var_attribute_string (var, pattr, flags)
|
||||
SHELL_VAR *var;
|
||||
int pattr;
|
||||
char *flags; /* filled in with attributes */
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
|
||||
/* pattr == 0 means we are called from `declare'. */
|
||||
if (pattr == 0 || posixly_correct == 0)
|
||||
{
|
||||
#if defined (ARRAY_VARS)
|
||||
if (array_p (var))
|
||||
flags[i++] = 'a';
|
||||
|
||||
if (assoc_p (var))
|
||||
flags[i++] = 'A';
|
||||
#endif
|
||||
|
||||
if (function_p (var))
|
||||
flags[i++] = 'f';
|
||||
|
||||
if (integer_p (var))
|
||||
flags[i++] = 'i';
|
||||
|
||||
if (nameref_p (var))
|
||||
flags[i++] = 'n';
|
||||
|
||||
if (readonly_p (var))
|
||||
flags[i++] = 'r';
|
||||
|
||||
if (trace_p (var))
|
||||
flags[i++] = 't';
|
||||
|
||||
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))
|
||||
flags[i++] = 'f';
|
||||
}
|
||||
|
||||
flags[i] = '\0';
|
||||
return i;
|
||||
}
|
||||
|
||||
/* 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'.
|
||||
In POSIX mode, this prints the name of the calling builtin (`export'
|
||||
or `readonly') instead of `declare', and doesn't print function defs
|
||||
when called by `export' or `readonly'. */
|
||||
int
|
||||
show_var_attributes (var, pattr, nodefs)
|
||||
SHELL_VAR *var;
|
||||
int pattr, nodefs;
|
||||
{
|
||||
char flags[MAX_ATTRIBUTES], *x;
|
||||
int i;
|
||||
|
||||
i = var_attribute_string (var, pattr, flags);
|
||||
|
||||
/* If we're printing functions with definitions, print the function def
|
||||
first, then the attributes, instead of printing output that can't be
|
||||
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), FUNC_MULTILINE|FUNC_EXTERNAL));
|
||||
nodefs++;
|
||||
if (pattr == 0 && i == 1 && flags[0] == 'f')
|
||||
return 0; /* don't print `declare -f name' */
|
||||
}
|
||||
|
||||
if (pattr == 0 || posixly_correct == 0)
|
||||
printf ("declare -%s ", i ? flags : "-");
|
||||
else if (i)
|
||||
printf ("%s -%s ", this_command_name, flags);
|
||||
else
|
||||
printf ("%s ", this_command_name);
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
if (invisible_p (var) && (array_p (var) || assoc_p (var)))
|
||||
printf ("%s\n", var->name);
|
||||
else if (array_p (var))
|
||||
print_array_assignment (var, 0);
|
||||
else if (assoc_p (var))
|
||||
print_assoc_assignment (var, 0);
|
||||
else
|
||||
#endif
|
||||
/* force `readonly' and `export' to not print out function definitions
|
||||
when in POSIX mode. */
|
||||
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), FUNC_MULTILINE|FUNC_EXTERNAL));
|
||||
else if (invisible_p (var) || var_isset (var) == 0)
|
||||
printf ("%s\n", var->name);
|
||||
else
|
||||
{
|
||||
if (ansic_shouldquote (value_cell (var)))
|
||||
x = ansic_quote (value_cell (var), 0, (int *)0);
|
||||
else
|
||||
x = sh_double_quote (value_cell (var));
|
||||
printf ("%s=%s\n", var->name, x);
|
||||
free (x);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
show_name_attributes (name, nodefs)
|
||||
char *name;
|
||||
int nodefs;
|
||||
{
|
||||
SHELL_VAR *var;
|
||||
|
||||
var = find_variable_noref (name);
|
||||
|
||||
if (var) /* show every variable with attributes, even unset ones */
|
||||
{
|
||||
show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
return (1);
|
||||
}
|
||||
|
||||
int
|
||||
show_localname_attributes (name, nodefs)
|
||||
char *name;
|
||||
int nodefs;
|
||||
{
|
||||
SHELL_VAR *var;
|
||||
|
||||
var = find_variable_noref (name);
|
||||
|
||||
if (var && local_p (var) && var->context == variable_context) /* show every variable with attributes, even unset ones */
|
||||
{
|
||||
show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
return (1);
|
||||
}
|
||||
|
||||
int
|
||||
show_func_attributes (name, nodefs)
|
||||
char *name;
|
||||
int nodefs;
|
||||
{
|
||||
SHELL_VAR *var;
|
||||
|
||||
var = find_function (name);
|
||||
|
||||
if (var)
|
||||
{
|
||||
show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
set_var_attribute (name, attribute, undo)
|
||||
char *name;
|
||||
int attribute, undo;
|
||||
{
|
||||
SHELL_VAR *var, *tv, *v, *refvar;
|
||||
char *tvalue;
|
||||
|
||||
if (undo)
|
||||
var = find_variable (name);
|
||||
else
|
||||
{
|
||||
tv = find_tempenv_variable (name);
|
||||
/* XXX -- need to handle case where tv is a temp variable in a
|
||||
function-scope context, since function_env has been merged into
|
||||
the local variables table. */
|
||||
if (tv && tempvar_p (tv))
|
||||
{
|
||||
tvalue = var_isset (tv) ? savestring (value_cell (tv)) : savestring ("");
|
||||
|
||||
var = bind_variable (tv->name, tvalue, 0);
|
||||
if (var == 0)
|
||||
{
|
||||
free (tvalue);
|
||||
return; /* XXX - no error message here */
|
||||
}
|
||||
var->attributes |= tv->attributes & ~att_tempvar;
|
||||
/* This avoids an error message when propagating a read-only var
|
||||
later on. */
|
||||
if (posixly_correct || shell_compatibility_level <= 44)
|
||||
{
|
||||
if (var->context == 0 && (attribute & att_readonly))
|
||||
{
|
||||
/* Don't bother to set the `propagate to the global variables
|
||||
table' flag if we've just bound the variable in that
|
||||
table */
|
||||
v = find_global_variable (tv->name);
|
||||
if (v != var)
|
||||
VSETATTR (tv, att_propagate);
|
||||
}
|
||||
else
|
||||
VSETATTR (tv, att_propagate);
|
||||
if (var->context != 0)
|
||||
VSETATTR (var, att_propagate);
|
||||
}
|
||||
|
||||
SETVARATTR (tv, attribute, undo); /* XXX */
|
||||
|
||||
stupidly_hack_special_variables (tv->name);
|
||||
|
||||
free (tvalue);
|
||||
}
|
||||
else
|
||||
{
|
||||
var = find_variable_notempenv (name);
|
||||
if (var == 0)
|
||||
{
|
||||
/* We might have a nameref pointing to something that we can't
|
||||
resolve to a shell variable. If we do, skip it. We do a little
|
||||
checking just so we can print an error message. */
|
||||
refvar = find_variable_nameref_for_create (name, 0);
|
||||
if (refvar == INVALID_NAMEREF_VALUE)
|
||||
return;
|
||||
/* Otherwise we probably have a nameref pointing to a variable
|
||||
that hasn't been created yet. bind_variable will take care
|
||||
of that. */
|
||||
}
|
||||
if (var == 0)
|
||||
{
|
||||
var = bind_variable (name, (char *)NULL, 0);
|
||||
if (var)
|
||||
VSETATTR (var, att_invisible);
|
||||
}
|
||||
else if (var->context != 0)
|
||||
VSETATTR (var, att_propagate);
|
||||
}
|
||||
}
|
||||
|
||||
if (var)
|
||||
SETVARATTR (var, attribute, undo);
|
||||
|
||||
if (var && (exported_p (var) || (attribute & att_exported)))
|
||||
array_needs_making++; /* XXX */
|
||||
}
|
90
builtins/shift.def
Normal file
90
builtins/shift.def
Normal file
|
@ -0,0 +1,90 @@
|
|||
This file is shift.def, from which is created shift.c.
|
||||
It implements the builtin "shift" in Bash.
|
||||
|
||||
Copyright (C) 1987-2020 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 shift.c
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "common.h"
|
||||
|
||||
$BUILTIN shift
|
||||
$FUNCTION shift_builtin
|
||||
$SHORT_DOC shift [n]
|
||||
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;
|
||||
|
||||
/* Shift the arguments ``left''. Shift DOLLAR_VARS down then take one
|
||||
off of REST_OF_ARGS and place it into DOLLAR_VARS[9]. If LIST has
|
||||
anything in it, it is a number which says where to start the
|
||||
shifting. Return > 0 if `times' > $#, otherwise 0. */
|
||||
int
|
||||
shift_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
intmax_t times;
|
||||
int itimes, nargs;
|
||||
|
||||
CHECK_HELPOPT (list);
|
||||
|
||||
if (get_numeric_arg (list, 0, ×) == 0)
|
||||
return (EXECUTION_FAILURE);
|
||||
|
||||
if (times == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
else if (times < 0)
|
||||
{
|
||||
sh_erange (list ? list->word->word : NULL, _("shift count"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
nargs = number_of_args ();
|
||||
if (times > nargs)
|
||||
{
|
||||
if (print_shift_error)
|
||||
sh_erange (list ? list->word->word : NULL, _("shift count"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else if (times == nargs)
|
||||
clear_dollar_vars ();
|
||||
else
|
||||
shift_args (itimes = times);
|
||||
|
||||
invalidate_cached_quoted_dollar_at ();
|
||||
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
966
builtins/shopt.def
Normal file
966
builtins/shopt.def
Normal file
|
@ -0,0 +1,966 @@
|
|||
This file is shopt.def, from which is created shopt.c.
|
||||
It implements the Bash `shopt' builtin.
|
||||
|
||||
Copyright (C) 1994-2021 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 shopt.c
|
||||
|
||||
$BUILTIN shopt
|
||||
$FUNCTION shopt_builtin
|
||||
$SHORT_DOC shopt [-pqsu] [-o] [optname ...]
|
||||
Set and unset shell options.
|
||||
|
||||
Change the setting of each shell option OPTNAME. Without any option
|
||||
arguments, list each supplied OPTNAME, or all shell options if no
|
||||
OPTNAMEs are given, 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>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../flags.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
#if defined (READLINE)
|
||||
# include "../bashline.h"
|
||||
#endif
|
||||
|
||||
#if defined (HISTORY)
|
||||
# include "../bashhist.h"
|
||||
#endif
|
||||
|
||||
#define UNSETOPT 0
|
||||
#define SETOPT 1
|
||||
|
||||
#define OPTFMT "%-15s\t%s\n"
|
||||
|
||||
extern int allow_null_glob_expansion, fail_glob_expansion, glob_dot_filenames;
|
||||
extern int cdable_vars, mail_warning, source_uses_path;
|
||||
extern int no_exit_on_failed_exec, print_shift_error;
|
||||
extern int check_hashed_filenames, promptvars;
|
||||
extern int cdspelling, expand_aliases;
|
||||
extern int extended_quote;
|
||||
extern int check_window_size;
|
||||
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;
|
||||
extern int glob_asciirange;
|
||||
extern int glob_always_skip_dot_and_dotdot;
|
||||
extern int lastpipe_opt;
|
||||
extern int inherit_errexit;
|
||||
extern int localvar_inherit;
|
||||
extern int localvar_unset;
|
||||
extern int varassign_redir_autoclose;
|
||||
extern int singlequote_translations;
|
||||
extern int patsub_replacement;
|
||||
|
||||
#if defined (EXTENDED_GLOB)
|
||||
extern int extended_glob;
|
||||
#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, dircomplete_expand;
|
||||
extern int complete_fullquote;
|
||||
|
||||
extern int enable_hostname_completion PARAMS((int));
|
||||
#endif
|
||||
|
||||
#if defined (PROGRAMMABLE_COMPLETION)
|
||||
extern int prog_completion_enabled;
|
||||
extern int progcomp_alias;
|
||||
#endif
|
||||
|
||||
#if defined (DEBUGGER)
|
||||
extern int debugging_mode;
|
||||
#endif
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
extern int assoc_expand_once;
|
||||
extern int array_expand_once;
|
||||
int expand_once_flag;
|
||||
#endif
|
||||
|
||||
#if defined (SYSLOG_HISTORY)
|
||||
extern int syslog_history;
|
||||
#endif
|
||||
|
||||
static void shopt_error PARAMS((char *));
|
||||
|
||||
static int set_shellopts_after_change PARAMS((char *, int));
|
||||
static int set_compatibility_level PARAMS((char *, int));
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
static int set_restricted_shell PARAMS((char *, int));
|
||||
#endif
|
||||
|
||||
#if defined (READLINE)
|
||||
static int shopt_enable_hostname_completion PARAMS((char *, int));
|
||||
static int shopt_set_complete_direxpand PARAMS((char *, int));
|
||||
#endif
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
static int set_assoc_expand PARAMS((char *, int));
|
||||
#endif
|
||||
|
||||
#if defined (EXTENDED_GLOB)
|
||||
int extglob_flag = EXTGLOB_DEFAULT;
|
||||
static int shopt_set_extglob PARAMS((char *, int));
|
||||
#endif
|
||||
|
||||
int expaliases_flag = 0;
|
||||
static int shopt_set_expaliases PARAMS((char *, int));
|
||||
|
||||
static int shopt_set_debug_mode PARAMS((char *, int));
|
||||
|
||||
static int shopt_login_shell;
|
||||
static int shopt_compat31;
|
||||
static int shopt_compat32;
|
||||
static int shopt_compat40;
|
||||
static int shopt_compat41;
|
||||
static int shopt_compat42;
|
||||
static int shopt_compat43;
|
||||
static int shopt_compat44;
|
||||
|
||||
typedef int shopt_set_func_t PARAMS((char *, int));
|
||||
|
||||
/* If you add a new variable name here, make sure to set the default value
|
||||
appropriately in reset_shopt_options. */
|
||||
|
||||
static struct {
|
||||
char *name;
|
||||
int *value;
|
||||
shopt_set_func_t *set_func;
|
||||
} shopt_vars[] = {
|
||||
{ "autocd", &autocd, (shopt_set_func_t *)NULL },
|
||||
#if defined (ARRAY_VARS)
|
||||
{ "assoc_expand_once", &expand_once_flag, set_assoc_expand },
|
||||
#endif
|
||||
{ "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 },
|
||||
{ "compat40", &shopt_compat40, set_compatibility_level },
|
||||
{ "compat41", &shopt_compat41, set_compatibility_level },
|
||||
{ "compat42", &shopt_compat42, set_compatibility_level },
|
||||
{ "compat43", &shopt_compat43, set_compatibility_level },
|
||||
{ "compat44", &shopt_compat44, set_compatibility_level },
|
||||
#if defined (READLINE)
|
||||
{ "complete_fullquote", &complete_fullquote, (shopt_set_func_t *)NULL},
|
||||
{ "direxpand", &dircomplete_expand, shopt_set_complete_direxpand },
|
||||
{ "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", &expaliases_flag, shopt_set_expaliases },
|
||||
#if defined (DEBUGGER)
|
||||
{ "extdebug", &debugging_mode, shopt_set_debug_mode },
|
||||
#endif
|
||||
#if defined (EXTENDED_GLOB)
|
||||
{ "extglob", &extglob_flag, shopt_set_extglob },
|
||||
#endif
|
||||
{ "extquote", &extended_quote, (shopt_set_func_t *)NULL },
|
||||
{ "failglob", &fail_glob_expansion, (shopt_set_func_t *)NULL },
|
||||
#if defined (READLINE)
|
||||
{ "force_fignore", &force_fignore, (shopt_set_func_t *)NULL },
|
||||
#endif
|
||||
{ "globasciiranges", &glob_asciirange, (shopt_set_func_t *)NULL },
|
||||
{ "globskipdots", &glob_always_skip_dot_and_dotdot, (shopt_set_func_t *)NULL },
|
||||
{ "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 },
|
||||
#endif
|
||||
#if defined (READLINE)
|
||||
{ "histreedit", &history_reediting, (shopt_set_func_t *)NULL },
|
||||
{ "histverify", &hist_verify, (shopt_set_func_t *)NULL },
|
||||
{ "hostcomplete", &perform_hostname_completion, shopt_enable_hostname_completion },
|
||||
#endif
|
||||
{ "huponexit", &hup_on_exit, (shopt_set_func_t *)NULL },
|
||||
{ "inherit_errexit", &inherit_errexit, (shopt_set_func_t *)NULL },
|
||||
{ "interactive_comments", &interactive_comments, set_shellopts_after_change },
|
||||
{ "lastpipe", &lastpipe_opt, (shopt_set_func_t *)NULL },
|
||||
#if defined (HISTORY)
|
||||
{ "lithist", &literal_history, (shopt_set_func_t *)NULL },
|
||||
#endif
|
||||
{ "localvar_inherit", &localvar_inherit, (shopt_set_func_t *)NULL },
|
||||
{ "localvar_unset", &localvar_unset, (shopt_set_func_t *)NULL },
|
||||
{ "login_shell", &shopt_login_shell, set_login_shell },
|
||||
{ "mailwarn", &mail_warning, (shopt_set_func_t *)NULL },
|
||||
#if defined (READLINE)
|
||||
{ "no_empty_cmd_completion", &no_empty_command_completion, (shopt_set_func_t *)NULL },
|
||||
#endif
|
||||
{ "nocaseglob", &glob_ignore_case, (shopt_set_func_t *)NULL },
|
||||
{ "nocasematch", &match_ignore_case, (shopt_set_func_t *)NULL },
|
||||
{ "noexpand_translation", &singlequote_translations, (shopt_set_func_t *)NULL },
|
||||
{ "nullglob", &allow_null_glob_expansion, (shopt_set_func_t *)NULL },
|
||||
{ "patsub_replacement", &patsub_replacement, (shopt_set_func_t *)NULL },
|
||||
#if defined (PROGRAMMABLE_COMPLETION)
|
||||
{ "progcomp", &prog_completion_enabled, (shopt_set_func_t *)NULL },
|
||||
# if defined (ALIAS)
|
||||
{ "progcomp_alias", &progcomp_alias, (shopt_set_func_t *)NULL },
|
||||
# endif
|
||||
#endif
|
||||
{ "promptvars", &promptvars, (shopt_set_func_t *)NULL },
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
{ "restricted_shell", &restricted_shell, set_restricted_shell },
|
||||
#endif
|
||||
{ "shift_verbose", &print_shift_error, (shopt_set_func_t *)NULL },
|
||||
{ "sourcepath", &source_uses_path, (shopt_set_func_t *)NULL },
|
||||
#if defined (SYSLOG_HISTORY) && defined (SYSLOG_SHOPT)
|
||||
{ "syslog_history", &syslog_history, (shopt_set_func_t *)NULL },
|
||||
#endif
|
||||
{ "varredir_close", &varassign_redir_autoclose, (shopt_set_func_t *)NULL },
|
||||
{ "xpg_echo", &xpg_echo, (shopt_set_func_t *)NULL },
|
||||
{ (char *)0, (int *)0, (shopt_set_func_t *)NULL }
|
||||
};
|
||||
|
||||
#define N_SHOPT_OPTIONS (sizeof (shopt_vars) / sizeof (shopt_vars[0]))
|
||||
|
||||
#define GET_SHOPT_OPTION_VALUE(i) (*shopt_vars[i].value)
|
||||
|
||||
static const char * const on = "on";
|
||||
static const char * const off = "off";
|
||||
|
||||
static int find_shopt PARAMS((char *));
|
||||
static int toggle_shopts PARAMS((int, WORD_LIST *, int));
|
||||
static void print_shopt PARAMS((char *, int, int));
|
||||
static int list_shopts PARAMS((WORD_LIST *, int));
|
||||
static int list_some_shopts PARAMS((int, int));
|
||||
static int list_shopt_o_options PARAMS((WORD_LIST *, int));
|
||||
static int list_some_o_options PARAMS((int, int));
|
||||
static int set_shopt_o_options PARAMS((int, WORD_LIST *, int));
|
||||
|
||||
#define SFLAG 0x01
|
||||
#define UFLAG 0x02
|
||||
#define QFLAG 0x04
|
||||
#define OFLAG 0x08
|
||||
#define PFLAG 0x10
|
||||
|
||||
int
|
||||
shopt_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int opt, flags, rval;
|
||||
|
||||
flags = 0;
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "psuoq")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 's':
|
||||
flags |= SFLAG;
|
||||
break;
|
||||
case 'u':
|
||||
flags |= UFLAG;
|
||||
break;
|
||||
case 'q':
|
||||
flags |= QFLAG;
|
||||
break;
|
||||
case 'o':
|
||||
flags |= OFLAG;
|
||||
break;
|
||||
case 'p':
|
||||
flags |= PFLAG;
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
if ((flags & (SFLAG|UFLAG)) == (SFLAG|UFLAG))
|
||||
{
|
||||
builtin_error (_("cannot set and unset shell options simultaneously"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
rval = EXECUTION_SUCCESS;
|
||||
if ((flags & OFLAG) && ((flags & (SFLAG|UFLAG)) == 0)) /* shopt -o */
|
||||
rval = list_shopt_o_options (list, flags);
|
||||
else if (list && (flags & OFLAG)) /* shopt -so args */
|
||||
rval = set_shopt_o_options ((flags & SFLAG) ? FLAG_ON : FLAG_OFF, list, flags & QFLAG);
|
||||
else if (flags & OFLAG) /* shopt -so */
|
||||
rval = list_some_o_options ((flags & SFLAG) ? 1 : 0, flags);
|
||||
else if (list && (flags & (SFLAG|UFLAG))) /* shopt -su args */
|
||||
rval = toggle_shopts ((flags & SFLAG) ? SETOPT : UNSETOPT, list, flags & QFLAG);
|
||||
else if ((flags & (SFLAG|UFLAG)) == 0) /* shopt [args] */
|
||||
rval = list_shopts (list, flags);
|
||||
else /* shopt -su */
|
||||
rval = list_some_shopts ((flags & SFLAG) ? SETOPT : UNSETOPT, flags);
|
||||
return (rval);
|
||||
}
|
||||
|
||||
/* Reset the options managed by `shopt' to the values they would have at
|
||||
shell startup. Variables from shopt_vars. */
|
||||
void
|
||||
reset_shopt_options ()
|
||||
{
|
||||
autocd = cdable_vars = cdspelling = 0;
|
||||
check_hashed_filenames = CHECKHASH_DEFAULT;
|
||||
check_window_size = CHECKWINSIZE_DEFAULT;
|
||||
allow_null_glob_expansion = glob_dot_filenames = 0;
|
||||
no_exit_on_failed_exec = 0;
|
||||
expand_aliases = expaliases_flag = 0;
|
||||
extended_quote = 1;
|
||||
fail_glob_expansion = 0;
|
||||
glob_asciirange = GLOBASCII_DEFAULT;
|
||||
glob_star = 0;
|
||||
gnu_error_format = 0;
|
||||
hup_on_exit = 0;
|
||||
inherit_errexit = 0;
|
||||
interactive_comments = 1;
|
||||
lastpipe_opt = 0;
|
||||
localvar_inherit = localvar_unset = 0;
|
||||
mail_warning = 0;
|
||||
glob_ignore_case = match_ignore_case = 0;
|
||||
print_shift_error = 0;
|
||||
source_uses_path = promptvars = 1;
|
||||
varassign_redir_autoclose = 0;
|
||||
singlequote_translations = 0;
|
||||
patsub_replacement = 1;
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
check_jobs_at_exit = 0;
|
||||
#endif
|
||||
|
||||
#if defined (EXTENDED_GLOB)
|
||||
extended_glob = extglob_flag = EXTGLOB_DEFAULT;
|
||||
#endif
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
expand_once_flag = assoc_expand_once = 0;
|
||||
#endif
|
||||
|
||||
#if defined (HISTORY)
|
||||
literal_history = 0;
|
||||
force_append_history = 0;
|
||||
command_oriented_history = 1;
|
||||
#endif
|
||||
|
||||
#if defined (SYSLOG_HISTORY)
|
||||
# if defined (SYSLOG_SHOPT)
|
||||
syslog_history = SYSLOG_SHOPT;
|
||||
# else
|
||||
syslog_history = 1;
|
||||
# endif /* SYSLOG_SHOPT */
|
||||
#endif
|
||||
|
||||
#if defined (READLINE)
|
||||
complete_fullquote = 1;
|
||||
force_fignore = 1;
|
||||
hist_verify = history_reediting = 0;
|
||||
perform_hostname_completion = 1;
|
||||
# if DIRCOMPLETE_EXPAND_DEFAULT
|
||||
dircomplete_expand = 1;
|
||||
# else
|
||||
dircomplete_expand = 0;
|
||||
#endif
|
||||
dircomplete_spelling = 0;
|
||||
no_empty_command_completion = 0;
|
||||
#endif
|
||||
|
||||
#if defined (PROGRAMMABLE_COMPLETION)
|
||||
prog_completion_enabled = 1;
|
||||
# if defined (ALIAS)
|
||||
progcomp_alias = 0;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined (DEFAULT_ECHO_TO_XPG) || defined (STRICT_POSIX)
|
||||
xpg_echo = 1;
|
||||
#else
|
||||
xpg_echo = 0;
|
||||
#endif /* DEFAULT_ECHO_TO_XPG */
|
||||
|
||||
shopt_login_shell = login_shell;
|
||||
}
|
||||
|
||||
static int
|
||||
find_shopt (name)
|
||||
char *name;
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; shopt_vars[i].name; i++)
|
||||
if (STREQ (name, shopt_vars[i].name))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
shopt_error (s)
|
||||
char *s;
|
||||
{
|
||||
builtin_error (_("%s: invalid shell option name"), s);
|
||||
}
|
||||
|
||||
static int
|
||||
toggle_shopts (mode, list, quiet)
|
||||
int mode;
|
||||
WORD_LIST *list;
|
||||
int quiet;
|
||||
{
|
||||
WORD_LIST *l;
|
||||
int ind, rval;
|
||||
SHELL_VAR *v;
|
||||
|
||||
for (l = list, rval = EXECUTION_SUCCESS; l; l = l->next)
|
||||
{
|
||||
ind = find_shopt (l->word->word);
|
||||
if (ind < 0)
|
||||
{
|
||||
shopt_error (l->word->word);
|
||||
rval = EXECUTION_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
*shopt_vars[ind].value = mode; /* 1 for set, 0 for unset */
|
||||
if (shopt_vars[ind].set_func)
|
||||
(*shopt_vars[ind].set_func) (shopt_vars[ind].name, mode);
|
||||
}
|
||||
}
|
||||
|
||||
/* Don't set $BASHOPTS here if it hasn't already been initialized */
|
||||
if (v = find_variable ("BASHOPTS"))
|
||||
set_bashopts ();
|
||||
return (rval);
|
||||
}
|
||||
|
||||
static void
|
||||
print_shopt (name, val, flags)
|
||||
char *name;
|
||||
int val, flags;
|
||||
{
|
||||
if (flags & PFLAG)
|
||||
printf ("shopt %s %s\n", val ? "-s" : "-u", name);
|
||||
else
|
||||
printf (OPTFMT, name, val ? on : off);
|
||||
}
|
||||
|
||||
/* List the values of all or any of the `shopt' options. Returns 0 if
|
||||
all were listed or all variables queried were on; 1 otherwise. */
|
||||
static int
|
||||
list_shopts (list, flags)
|
||||
WORD_LIST *list;
|
||||
int flags;
|
||||
{
|
||||
WORD_LIST *l;
|
||||
int i, val, rval;
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
for (i = 0; shopt_vars[i].name; i++)
|
||||
{
|
||||
val = *shopt_vars[i].value;
|
||||
if ((flags & QFLAG) == 0)
|
||||
print_shopt (shopt_vars[i].name, val, flags);
|
||||
}
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
for (l = list, rval = EXECUTION_SUCCESS; l; l = l->next)
|
||||
{
|
||||
i = find_shopt (l->word->word);
|
||||
if (i < 0)
|
||||
{
|
||||
shopt_error (l->word->word);
|
||||
rval = EXECUTION_FAILURE;
|
||||
continue;
|
||||
}
|
||||
val = *shopt_vars[i].value;
|
||||
if (val == 0)
|
||||
rval = EXECUTION_FAILURE;
|
||||
if ((flags & QFLAG) == 0)
|
||||
print_shopt (l->word->word, val, flags);
|
||||
}
|
||||
|
||||
return (sh_chkwrite (rval));
|
||||
}
|
||||
|
||||
static int
|
||||
list_some_shopts (mode, flags)
|
||||
int mode, flags;
|
||||
{
|
||||
int val, i;
|
||||
|
||||
for (i = 0; shopt_vars[i].name; i++)
|
||||
{
|
||||
val = *shopt_vars[i].value;
|
||||
if (((flags & QFLAG) == 0) && mode == val)
|
||||
print_shopt (shopt_vars[i].name, val, flags);
|
||||
}
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
static int
|
||||
list_shopt_o_options (list, flags)
|
||||
WORD_LIST *list;
|
||||
int flags;
|
||||
{
|
||||
WORD_LIST *l;
|
||||
int val, rval;
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
if ((flags & QFLAG) == 0)
|
||||
list_minus_o_opts (-1, (flags & PFLAG));
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
for (l = list, rval = EXECUTION_SUCCESS; l; l = l->next)
|
||||
{
|
||||
val = minus_o_option_value (l->word->word);
|
||||
if (val == -1)
|
||||
{
|
||||
sh_invalidoptname (l->word->word);
|
||||
rval = EXECUTION_FAILURE;
|
||||
continue;
|
||||
}
|
||||
if (val == 0)
|
||||
rval = EXECUTION_FAILURE;
|
||||
if ((flags & QFLAG) == 0)
|
||||
{
|
||||
if (flags & PFLAG)
|
||||
printf ("set %co %s\n", val ? '-' : '+', l->word->word);
|
||||
else
|
||||
printf (OPTFMT, l->word->word, val ? on : off);
|
||||
}
|
||||
}
|
||||
return (sh_chkwrite (rval));
|
||||
}
|
||||
|
||||
static int
|
||||
list_some_o_options (mode, flags)
|
||||
int mode, flags;
|
||||
{
|
||||
if ((flags & QFLAG) == 0)
|
||||
list_minus_o_opts (mode, (flags & PFLAG));
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
static int
|
||||
set_shopt_o_options (mode, list, quiet)
|
||||
int mode;
|
||||
WORD_LIST *list;
|
||||
int quiet;
|
||||
{
|
||||
WORD_LIST *l;
|
||||
int rval;
|
||||
|
||||
for (l = list, rval = EXECUTION_SUCCESS; l; l = l->next)
|
||||
{
|
||||
if (set_minus_o_option (mode, l->word->word) == EXECUTION_FAILURE)
|
||||
rval = EXECUTION_FAILURE;
|
||||
}
|
||||
set_shellopts ();
|
||||
return rval;
|
||||
}
|
||||
|
||||
/* If we set or unset interactive_comments with shopt, make sure the
|
||||
change is reflected in $SHELLOPTS. */
|
||||
static int
|
||||
set_shellopts_after_change (option_name, mode)
|
||||
char *option_name;
|
||||
int mode;
|
||||
{
|
||||
set_shellopts ();
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
shopt_set_debug_mode (option_name, mode)
|
||||
char *option_name;
|
||||
int mode;
|
||||
{
|
||||
#if defined (DEBUGGER)
|
||||
error_trace_mode = function_trace_mode = debugging_mode;
|
||||
set_shellopts ();
|
||||
if (debugging_mode)
|
||||
init_bash_argv ();
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
shopt_set_expaliases (option_name, mode)
|
||||
char *option_name;
|
||||
int mode;
|
||||
{
|
||||
expand_aliases = expaliases_flag;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined (EXTENDED_GLOB)
|
||||
static int
|
||||
shopt_set_extglob (option_name, mode)
|
||||
char *option_name;
|
||||
int mode;
|
||||
{
|
||||
extended_glob = extglob_flag;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (READLINE)
|
||||
static int
|
||||
shopt_enable_hostname_completion (option_name, mode)
|
||||
char *option_name;
|
||||
int mode;
|
||||
{
|
||||
return (enable_hostname_completion (mode));
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
set_compatibility_level (option_name, mode)
|
||||
char *option_name;
|
||||
int mode;
|
||||
{
|
||||
int ind, oldval;
|
||||
char *rhs;
|
||||
|
||||
/* If we're unsetting one of the compatibility options, make sure the
|
||||
current value is in the range of the compatNN space. */
|
||||
if (mode == 0)
|
||||
oldval = shell_compatibility_level;
|
||||
|
||||
/* If we're setting something, redo some of the work we did above in
|
||||
toggle_shopt(). Unset everything and reset the appropriate option
|
||||
based on OPTION_NAME. */
|
||||
if (mode)
|
||||
{
|
||||
shopt_compat31 = shopt_compat32 = 0;
|
||||
shopt_compat40 = shopt_compat41 = shopt_compat42 = shopt_compat43 = 0;
|
||||
shopt_compat44 = 0;
|
||||
ind = find_shopt (option_name);
|
||||
*shopt_vars[ind].value = mode;
|
||||
}
|
||||
|
||||
/* Then set shell_compatibility_level based on what remains */
|
||||
if (shopt_compat31)
|
||||
shell_compatibility_level = 31;
|
||||
else if (shopt_compat32)
|
||||
shell_compatibility_level = 32;
|
||||
else if (shopt_compat40)
|
||||
shell_compatibility_level = 40;
|
||||
else if (shopt_compat41)
|
||||
shell_compatibility_level = 41;
|
||||
else if (shopt_compat42)
|
||||
shell_compatibility_level = 42;
|
||||
else if (shopt_compat43)
|
||||
shell_compatibility_level = 43;
|
||||
else if (shopt_compat44)
|
||||
shell_compatibility_level = 44;
|
||||
else if (oldval > 44 && shell_compatibility_level < DEFAULT_COMPAT_LEVEL)
|
||||
;
|
||||
else
|
||||
shell_compatibility_level = DEFAULT_COMPAT_LEVEL;
|
||||
|
||||
/* Make sure the current compatibility level is reflected in BASH_COMPAT */
|
||||
rhs = itos (shell_compatibility_level);
|
||||
bind_variable ("BASH_COMPAT", rhs, 0);
|
||||
free (rhs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set and unset the various compatibility options from the value of
|
||||
shell_compatibility_level; used by sv_shcompat */
|
||||
void
|
||||
set_compatibility_opts ()
|
||||
{
|
||||
shopt_compat31 = shopt_compat32 = 0;
|
||||
shopt_compat40 = shopt_compat41 = shopt_compat42 = shopt_compat43 = 0;
|
||||
shopt_compat44 = 0;
|
||||
switch (shell_compatibility_level)
|
||||
{
|
||||
case DEFAULT_COMPAT_LEVEL:
|
||||
case 51: /* completeness */
|
||||
case 50:
|
||||
break;
|
||||
case 44:
|
||||
shopt_compat44 = 1; break;
|
||||
case 43:
|
||||
shopt_compat43 = 1; break;
|
||||
case 42:
|
||||
shopt_compat42 = 1; break;
|
||||
case 41:
|
||||
shopt_compat41 = 1; break;
|
||||
case 40:
|
||||
shopt_compat40 = 1; break;
|
||||
case 32:
|
||||
shopt_compat32 = 1; break;
|
||||
case 31:
|
||||
shopt_compat31 = 1; break;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined (READLINE)
|
||||
static int
|
||||
shopt_set_complete_direxpand (option_name, mode)
|
||||
char *option_name;
|
||||
int mode;
|
||||
{
|
||||
set_directory_hook ();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
/* Don't allow the value of restricted_shell to be modified. */
|
||||
|
||||
static int
|
||||
set_restricted_shell (option_name, mode)
|
||||
char *option_name;
|
||||
int mode;
|
||||
{
|
||||
static int save_restricted = -1;
|
||||
|
||||
if (save_restricted == -1)
|
||||
save_restricted = shell_is_restricted (shell_name);
|
||||
|
||||
restricted_shell = save_restricted;
|
||||
return (0);
|
||||
}
|
||||
#endif /* RESTRICTED_SHELL */
|
||||
|
||||
/* Not static so shell.c can call it to initialize shopt_login_shell */
|
||||
int
|
||||
set_login_shell (option_name, mode)
|
||||
char *option_name;
|
||||
int mode;
|
||||
{
|
||||
shopt_login_shell = login_shell != 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
char **
|
||||
get_shopt_options ()
|
||||
{
|
||||
char **ret;
|
||||
int n, i;
|
||||
|
||||
n = sizeof (shopt_vars) / sizeof (shopt_vars[0]);
|
||||
ret = strvec_create (n + 1);
|
||||
for (i = 0; shopt_vars[i].name; i++)
|
||||
ret[i] = savestring (shopt_vars[i].name);
|
||||
ret[i] = (char *)NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* External interface for other parts of the shell. NAME is a string option;
|
||||
* MODE is 0 if we want to unset an option; 1 if we want to set an option.
|
||||
* REUSABLE is 1 if we want to print output in a form that may be reused.
|
||||
*/
|
||||
int
|
||||
shopt_setopt (name, mode)
|
||||
char *name;
|
||||
int mode;
|
||||
{
|
||||
WORD_LIST *wl;
|
||||
int r;
|
||||
|
||||
wl = add_string_to_list (name, (WORD_LIST *)NULL);
|
||||
r = toggle_shopts (mode, wl, 0);
|
||||
dispose_words (wl);
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
shopt_listopt (name, reusable)
|
||||
char *name;
|
||||
int reusable;
|
||||
{
|
||||
int i;
|
||||
|
||||
if (name == 0)
|
||||
return (list_shopts ((WORD_LIST *)NULL, reusable ? PFLAG : 0));
|
||||
|
||||
i = find_shopt (name);
|
||||
if (i < 0)
|
||||
{
|
||||
shopt_error (name);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
print_shopt (name, *shopt_vars[i].value, reusable ? PFLAG : 0);
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
void
|
||||
set_bashopts ()
|
||||
{
|
||||
char *value;
|
||||
char tflag[N_SHOPT_OPTIONS];
|
||||
int vsize, i, vptr, *ip, exported;
|
||||
SHELL_VAR *v;
|
||||
|
||||
for (vsize = i = 0; shopt_vars[i].name; i++)
|
||||
{
|
||||
tflag[i] = 0;
|
||||
if (GET_SHOPT_OPTION_VALUE (i))
|
||||
{
|
||||
vsize += strlen (shopt_vars[i].name) + 1;
|
||||
tflag[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
value = (char *)xmalloc (vsize + 1);
|
||||
|
||||
for (i = vptr = 0; shopt_vars[i].name; i++)
|
||||
{
|
||||
if (tflag[i])
|
||||
{
|
||||
strcpy (value + vptr, shopt_vars[i].name);
|
||||
vptr += strlen (shopt_vars[i].name);
|
||||
value[vptr++] = ':';
|
||||
}
|
||||
}
|
||||
|
||||
if (vptr)
|
||||
vptr--; /* cut off trailing colon */
|
||||
value[vptr] = '\0';
|
||||
|
||||
v = find_variable ("BASHOPTS");
|
||||
|
||||
/* Turn off the read-only attribute so we can bind the new value, and
|
||||
note whether or not the variable was exported. */
|
||||
if (v)
|
||||
{
|
||||
VUNSETATTR (v, att_readonly);
|
||||
exported = exported_p (v);
|
||||
}
|
||||
else
|
||||
exported = 0;
|
||||
|
||||
v = bind_variable ("BASHOPTS", value, 0);
|
||||
|
||||
/* Turn the read-only attribute back on, and turn off the export attribute
|
||||
if it was set implicitly by mark_modified_vars and SHELLOPTS was not
|
||||
exported before we bound the new value. */
|
||||
VSETATTR (v, att_readonly);
|
||||
if (mark_modified_vars && exported == 0 && exported_p (v))
|
||||
VUNSETATTR (v, att_exported);
|
||||
|
||||
free (value);
|
||||
}
|
||||
|
||||
void
|
||||
parse_bashopts (value)
|
||||
char *value;
|
||||
{
|
||||
char *vname;
|
||||
int vptr, ind;
|
||||
|
||||
vptr = 0;
|
||||
while (vname = extract_colon_unit (value, &vptr))
|
||||
{
|
||||
ind = find_shopt (vname);
|
||||
if (ind >= 0)
|
||||
{
|
||||
*shopt_vars[ind].value = 1;
|
||||
if (shopt_vars[ind].set_func)
|
||||
(*shopt_vars[ind].set_func) (shopt_vars[ind].name, 1);
|
||||
}
|
||||
free (vname);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
initialize_bashopts (no_bashopts)
|
||||
int no_bashopts;
|
||||
{
|
||||
char *temp;
|
||||
SHELL_VAR *var;
|
||||
|
||||
if (no_bashopts == 0)
|
||||
{
|
||||
var = find_variable ("BASHOPTS");
|
||||
/* set up any shell options we may have inherited. */
|
||||
if (var && imported_p (var))
|
||||
{
|
||||
temp = (array_p (var) || assoc_p (var)) ? (char *)NULL : savestring (value_cell (var));
|
||||
if (temp)
|
||||
{
|
||||
parse_bashopts (temp);
|
||||
free (temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set up the $BASHOPTS variable. */
|
||||
set_bashopts ();
|
||||
}
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
static int
|
||||
set_assoc_expand (option_name, mode)
|
||||
char *option_name;
|
||||
int mode;
|
||||
{
|
||||
#if 0 /* leave this disabled */
|
||||
if (shell_compatibility_level <= 51)
|
||||
#endif
|
||||
assoc_expand_once = expand_once_flag;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
200
builtins/source.def
Normal file
200
builtins/source.def
Normal file
|
@ -0,0 +1,200 @@
|
|||
This file is source.def, from which is created source.c.
|
||||
It implements the builtins "." and "source" in Bash.
|
||||
|
||||
Copyright (C) 1987-2020 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 source.c
|
||||
|
||||
$BUILTIN source
|
||||
$FUNCTION source_builtin
|
||||
$SHORT_DOC source filename [arguments]
|
||||
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]
|
||||
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
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "../bashtypes.h"
|
||||
#include "posixstat.h"
|
||||
#include "filecntl.h"
|
||||
#if ! defined(_MINIX) && defined (HAVE_SYS_FILE_H)
|
||||
# include <sys/file.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "../flags.h"
|
||||
#include "../findcmd.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
#include "../trap.h"
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif /* !errno */
|
||||
|
||||
static void maybe_pop_dollar_vars PARAMS((void));
|
||||
|
||||
/* If non-zero, `.' uses $PATH to look up the script to be sourced. */
|
||||
int source_uses_path = 1;
|
||||
|
||||
/* If non-zero, `.' looks in the current directory if the filename argument
|
||||
is not found in the $PATH. */
|
||||
int source_searches_cwd = 1;
|
||||
|
||||
/* If this . script is supplied arguments, we save the dollar vars and
|
||||
replace them with the script arguments for the duration of the script's
|
||||
execution. If the script does not change the dollar vars, we restore
|
||||
what we saved. If the dollar vars are changed in the script, and we are
|
||||
not executing a shell function, we leave the new values alone and free
|
||||
the saved values. */
|
||||
static void
|
||||
maybe_pop_dollar_vars ()
|
||||
{
|
||||
if (variable_context == 0 && (dollar_vars_changed () & ARGS_SETBLTIN))
|
||||
dispose_saved_dollar_vars ();
|
||||
else
|
||||
pop_dollar_vars ();
|
||||
if (debugging_mode)
|
||||
pop_args (); /* restore BASH_ARGC and BASH_ARGV */
|
||||
set_dollar_vars_unchanged ();
|
||||
invalidate_cached_quoted_dollar_at (); /* just invalidate to be safe */
|
||||
}
|
||||
|
||||
/* Read and execute commands from the file passed as argument. Guess what.
|
||||
This cannot be done in a subshell, since things like variable assignments
|
||||
take place in there. So, I open the file, place it into a large string,
|
||||
close the file, and then execute the string. */
|
||||
int
|
||||
source_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int result;
|
||||
char *filename, *debug_trap, *x;
|
||||
|
||||
if (no_options (list))
|
||||
return (EX_USAGE);
|
||||
list = loptend;
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
builtin_error (_("filename argument required"));
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
if (restricted && strchr (list->word->word, '/'))
|
||||
{
|
||||
sh_restricted (list->word->word);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
||||
filename = (char *)NULL;
|
||||
/* 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)
|
||||
{
|
||||
if (source_searches_cwd == 0)
|
||||
{
|
||||
x = printable_filename (list->word->word, 0);
|
||||
builtin_error (_("%s: file not found"), x);
|
||||
if (x != list->word->word)
|
||||
free (x);
|
||||
if (posixly_correct && interactive_shell == 0 && executing_command_builtin == 0)
|
||||
{
|
||||
last_command_exit_value = EXECUTION_FAILURE;
|
||||
jump_to_top_level (EXITPROG);
|
||||
}
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else
|
||||
filename = savestring (list->word->word);
|
||||
}
|
||||
|
||||
begin_unwind_frame ("source");
|
||||
add_unwind_protect (xfree, filename);
|
||||
|
||||
if (list->next)
|
||||
{
|
||||
push_dollar_vars ();
|
||||
add_unwind_protect ((Function *)maybe_pop_dollar_vars, (char *)NULL);
|
||||
if (debugging_mode || shell_compatibility_level <= 44)
|
||||
init_bash_argv (); /* Initialize BASH_ARGV and BASH_ARGC */
|
||||
remember_args (list->next, 1);
|
||||
if (debugging_mode)
|
||||
push_args (list->next); /* Update BASH_ARGV and BASH_ARGC */
|
||||
}
|
||||
set_dollar_vars_unchanged ();
|
||||
|
||||
/* Don't inherit the DEBUG trap unless function_trace_mode (overloaded)
|
||||
is set. XXX - should sourced files inherit the RETURN trap? Functions
|
||||
don't. */
|
||||
debug_trap = TRAP_STRING (DEBUG_TRAP);
|
||||
if (debug_trap && function_trace_mode == 0)
|
||||
{
|
||||
debug_trap = savestring (debug_trap);
|
||||
add_unwind_protect (xfree, debug_trap);
|
||||
add_unwind_protect (maybe_set_debug_trap, debug_trap);
|
||||
restore_default_signal (DEBUG_TRAP);
|
||||
}
|
||||
|
||||
result = source_file (filename, (list && list->next));
|
||||
|
||||
run_unwind_frame ("source");
|
||||
|
||||
return (result);
|
||||
}
|
129
builtins/suspend.def
Normal file
129
builtins/suspend.def
Normal file
|
@ -0,0 +1,129 @@
|
|||
This file is suspend.def, from which is created suspend.c.
|
||||
It implements the builtin "suspend" in Bash.
|
||||
|
||||
Copyright (C) 1987-2022 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 suspend.c
|
||||
|
||||
$BUILTIN suspend
|
||||
$DEPENDS_ON JOB_CONTROL
|
||||
$FUNCTION suspend_builtin
|
||||
$SHORT_DOC suspend [-f]
|
||||
Suspend shell execution.
|
||||
|
||||
Suspend the execution of this shell until it receives a SIGCONT signal.
|
||||
Unless forced, login shells and shells without job control cannot be
|
||||
suspended.
|
||||
|
||||
Options:
|
||||
-f force the suspend, even if the shell is a login shell or job
|
||||
control is not enabled.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless job control is not enabled or an error occurs.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashtypes.h"
|
||||
#include <signal.h>
|
||||
#include "../bashintl.h"
|
||||
#include "../shell.h"
|
||||
#include "../jobs.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
static sighandler suspend_continue PARAMS((int));
|
||||
|
||||
static SigHandler *old_cont;
|
||||
#if 0
|
||||
static SigHandler *old_stop;
|
||||
#endif
|
||||
|
||||
/* Continue handler. */
|
||||
static sighandler
|
||||
suspend_continue (sig)
|
||||
int sig;
|
||||
{
|
||||
set_signal_handler (SIGCONT, old_cont);
|
||||
#if 0
|
||||
set_signal_handler (SIGSTOP, old_stop);
|
||||
#endif
|
||||
SIGRETURN (0);
|
||||
}
|
||||
|
||||
/* Suspending the shell. If -f is the arg, then do the suspend
|
||||
no matter what. Otherwise, complain if a login shell. */
|
||||
int
|
||||
suspend_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int opt, force;
|
||||
|
||||
reset_internal_getopt ();
|
||||
force = 0;
|
||||
while ((opt = internal_getopt (list, "f")) != -1)
|
||||
switch (opt)
|
||||
{
|
||||
case 'f':
|
||||
force++;
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
list = loptend;
|
||||
no_args (list);
|
||||
|
||||
if (force == 0)
|
||||
{
|
||||
if (job_control == 0)
|
||||
{
|
||||
sh_nojobs (_("cannot suspend"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (login_shell)
|
||||
{
|
||||
builtin_error (_("cannot suspend a login shell"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
/* XXX - should we put ourselves back into the original pgrp now? If so,
|
||||
call end_job_control() here and do the right thing in suspend_continue
|
||||
(that is, call restart_job_control()). */
|
||||
old_cont = (SigHandler *)set_signal_handler (SIGCONT, suspend_continue);
|
||||
#if 0
|
||||
old_stop = (SigHandler *)set_signal_handler (SIGSTOP, SIG_DFL);
|
||||
#endif
|
||||
killpg (shell_pgrp, SIGSTOP);
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
#endif /* JOB_CONTROL */
|
159
builtins/test.def
Normal file
159
builtins/test.def
Normal file
|
@ -0,0 +1,159 @@
|
|||
This file is test.def, from which is created test.c.
|
||||
It implements the builtin "test" in Bash.
|
||||
|
||||
Copyright (C) 1987-2015 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 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
|
||||
are string operators and numeric comparison operators as well.
|
||||
|
||||
The behavior of test depends on the number of arguments. Read the
|
||||
bash manual page for the complete specification.
|
||||
|
||||
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.
|
||||
|
||||
FILE1 -nt FILE2 True if file1 is newer than file2 (according to
|
||||
modification date).
|
||||
|
||||
FILE1 -ot FILE2 True if file1 is older than file2.
|
||||
|
||||
FILE1 -ef FILE2 True if file1 is a hard link to file2.
|
||||
|
||||
String operators:
|
||||
|
||||
-z STRING True if string is 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.
|
||||
|
||||
Other operators:
|
||||
|
||||
-o OPTION True if the shell option OPTION is enabled.
|
||||
-v VAR True if the shell variable VAR is set.
|
||||
-R VAR True if the shell variable VAR is set and is a name
|
||||
reference.
|
||||
! 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.
|
||||
|
||||
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... ]
|
||||
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>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "../test.h"
|
||||
#include "common.h"
|
||||
|
||||
/* TEST/[ builtin. */
|
||||
int
|
||||
test_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
char **argv;
|
||||
int argc, result;
|
||||
|
||||
/* We let Matthew Bradburn and Kevin Braunsdorf's code do the
|
||||
actual test command. So turn the list of args into an array
|
||||
of strings, since that is what their code wants. */
|
||||
if (list == 0)
|
||||
{
|
||||
if (this_command_name[0] == '[' && !this_command_name[1])
|
||||
{
|
||||
builtin_error (_("missing `]'"));
|
||||
return (EX_BADUSAGE);
|
||||
}
|
||||
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
argv = make_builtin_argv (list, &argc);
|
||||
result = test_command (argc, argv);
|
||||
free ((char *)argv);
|
||||
|
||||
return (result);
|
||||
}
|
119
builtins/times.def
Normal file
119
builtins/times.def
Normal file
|
@ -0,0 +1,119 @@
|
|||
This file is times.def, from which is created times.c.
|
||||
It implements the builtin "times" in Bash.
|
||||
|
||||
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 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 times.c
|
||||
|
||||
$BUILTIN times
|
||||
$FUNCTION times_builtin
|
||||
$SHORT_DOC times
|
||||
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>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../bashtypes.h"
|
||||
#include "../shell.h"
|
||||
|
||||
#include <posixtime.h>
|
||||
|
||||
#if defined (HAVE_SYS_TIMES_H)
|
||||
# include <sys/times.h>
|
||||
#endif /* HAVE_SYS_TIMES_H */
|
||||
|
||||
#if defined (HAVE_SYS_RESOURCE_H) && !defined (RLIMTYPE)
|
||||
# include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/* Print the totals for system and user time used. */
|
||||
int
|
||||
times_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
#if defined (HAVE_GETRUSAGE) && defined (HAVE_TIMEVAL) && defined (RUSAGE_SELF)
|
||||
struct rusage self, kids;
|
||||
|
||||
USE_VAR(list);
|
||||
|
||||
if (no_options (list))
|
||||
return (EX_USAGE);
|
||||
|
||||
getrusage (RUSAGE_SELF, &self);
|
||||
getrusage (RUSAGE_CHILDREN, &kids); /* terminated child processes */
|
||||
|
||||
print_timeval (stdout, &self.ru_utime);
|
||||
putchar (' ');
|
||||
print_timeval (stdout, &self.ru_stime);
|
||||
putchar ('\n');
|
||||
print_timeval (stdout, &kids.ru_utime);
|
||||
putchar (' ');
|
||||
print_timeval (stdout, &kids.ru_stime);
|
||||
putchar ('\n');
|
||||
|
||||
#else
|
||||
# if defined (HAVE_TIMES)
|
||||
/* This uses the POSIX.1/XPG5 times(2) interface, which fills in a
|
||||
`struct tms' with values of type clock_t. */
|
||||
struct tms t;
|
||||
|
||||
USE_VAR(list);
|
||||
|
||||
if (no_options (list))
|
||||
return (EX_USAGE);
|
||||
|
||||
times (&t);
|
||||
|
||||
print_clock_t (stdout, t.tms_utime);
|
||||
putchar (' ');
|
||||
print_clock_t (stdout, t.tms_stime);
|
||||
putchar ('\n');
|
||||
print_clock_t (stdout, t.tms_cutime);
|
||||
putchar (' ');
|
||||
print_clock_t (stdout, t.tms_cstime);
|
||||
putchar ('\n');
|
||||
|
||||
# else /* !HAVE_TIMES */
|
||||
|
||||
USE_VAR(list);
|
||||
|
||||
if (no_options (list))
|
||||
return (EX_USAGE);
|
||||
printf ("0.00 0.00\n0.00 0.00\n");
|
||||
|
||||
# endif /* HAVE_TIMES */
|
||||
#endif /* !HAVE_TIMES */
|
||||
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
316
builtins/trap.def
Normal file
316
builtins/trap.def
Normal file
|
@ -0,0 +1,316 @@
|
|||
This file is trap.def, from which is created trap.c.
|
||||
It implements the builtin "trap" in Bash.
|
||||
|
||||
Copyright (C) 1987-2021 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 trap.c
|
||||
|
||||
$BUILTIN trap
|
||||
$FUNCTION trap_builtin
|
||||
$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) ARG is executed on exit from the shell. If
|
||||
a SIGNAL_SPEC is DEBUG, ARG is executed before every simple command. If
|
||||
a SIGNAL_SPEC is RETURN, ARG is executed each time a shell function or a
|
||||
script run by the . or source builtins finishes executing. A SIGNAL_SPEC
|
||||
of ERR means to execute ARG each time a command's failure would cause the
|
||||
shell to exit when the -e option is enabled.
|
||||
|
||||
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>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# ifdef _MINIX
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashtypes.h"
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include "../bashansi.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../trap.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
static void showtrap PARAMS((int, int));
|
||||
static int display_traps PARAMS((WORD_LIST *, int));
|
||||
|
||||
/* The trap command:
|
||||
|
||||
trap <arg> <signal ...>
|
||||
trap <signal ...>
|
||||
trap -l
|
||||
trap -p [sigspec ...]
|
||||
trap [--]
|
||||
|
||||
Set things up so that ARG is executed when SIGNAL(s) N is received.
|
||||
If ARG is the empty string, then ignore the SIGNAL(s). If there is
|
||||
no ARG, then set the trap for SIGNAL(s) to its original value. Just
|
||||
plain "trap" means to print out the list of commands associated with
|
||||
each signal number. Single arg of "-l" means list the signal names. */
|
||||
|
||||
/* Possible operations to perform on the list of signals.*/
|
||||
#define SET 0 /* Set this signal to first_arg. */
|
||||
#define REVERT 1 /* Revert to this signals original value. */
|
||||
#define IGNORE 2 /* Ignore this signal. */
|
||||
|
||||
int
|
||||
trap_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int list_signal_names, display, result, opt;
|
||||
|
||||
list_signal_names = display = 0;
|
||||
result = EXECUTION_SUCCESS;
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "lp")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'l':
|
||||
list_signal_names++;
|
||||
break;
|
||||
case 'p':
|
||||
display++;
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
opt = DSIG_NOCASE|DSIG_SIGPREFIX; /* flags for decode_signal */
|
||||
|
||||
if (list_signal_names)
|
||||
return (sh_chkwrite (display_signal_list ((WORD_LIST *)NULL, 1)));
|
||||
else if (display || list == 0)
|
||||
{
|
||||
initialize_terminating_signals ();
|
||||
get_all_original_signals ();
|
||||
return (sh_chkwrite (display_traps (list, display && posixly_correct)));
|
||||
}
|
||||
else
|
||||
{
|
||||
char *first_arg;
|
||||
int operation, sig, first_signal;
|
||||
|
||||
operation = SET;
|
||||
first_arg = list->word->word;
|
||||
first_signal = first_arg && *first_arg && all_digits (first_arg) && signal_object_p (first_arg, opt);
|
||||
|
||||
/* Backwards compatibility. XXX - question about whether or not we
|
||||
should throw an error if an all-digit argument doesn't correspond
|
||||
to a valid signal number (e.g., if it's `50' on a system with only
|
||||
32 signals). */
|
||||
if (first_signal)
|
||||
operation = REVERT;
|
||||
/* When in posix mode, the historical behavior of looking for a
|
||||
missing first argument is disabled. To revert to the original
|
||||
signal handling disposition, use `-' as the first argument. */
|
||||
else if (posixly_correct == 0 && first_arg && *first_arg &&
|
||||
(*first_arg != '-' || first_arg[1]) &&
|
||||
signal_object_p (first_arg, opt) && list->next == 0)
|
||||
operation = REVERT;
|
||||
else
|
||||
{
|
||||
list = list->next;
|
||||
if (list == 0)
|
||||
{
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
else if (*first_arg == '\0')
|
||||
operation = IGNORE;
|
||||
else if (first_arg[0] == '-' && !first_arg[1])
|
||||
operation = REVERT;
|
||||
}
|
||||
|
||||
/* If we're in a command substitution, we haven't freed the trap strings
|
||||
(though we reset the signal handlers). If we're setting a trap to
|
||||
handle a signal here, free the rest of the trap strings since they
|
||||
don't apply any more. */
|
||||
if (subshell_environment & SUBSHELL_RESETTRAP)
|
||||
{
|
||||
free_trap_strings ();
|
||||
subshell_environment &= ~SUBSHELL_RESETTRAP;
|
||||
}
|
||||
|
||||
while (list)
|
||||
{
|
||||
sig = decode_signal (list->word->word, opt);
|
||||
|
||||
if (sig == NO_SIG)
|
||||
{
|
||||
sh_invalidsig (list->word->word);
|
||||
result = EXECUTION_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (operation)
|
||||
{
|
||||
case SET:
|
||||
set_signal (sig, first_arg);
|
||||
break;
|
||||
|
||||
case REVERT:
|
||||
restore_default_signal (sig);
|
||||
|
||||
/* Signals that the shell treats specially need special
|
||||
handling. */
|
||||
switch (sig)
|
||||
{
|
||||
case SIGINT:
|
||||
/* XXX - should we do this if original disposition
|
||||
was SIG_IGN? */
|
||||
if (interactive)
|
||||
set_signal_handler (SIGINT, sigint_sighandler);
|
||||
/* special cases for interactive == 0 */
|
||||
else if (interactive_shell && (sourcelevel||running_trap||parse_and_execute_level))
|
||||
set_signal_handler (SIGINT, sigint_sighandler);
|
||||
else
|
||||
set_signal_handler (SIGINT, termsig_sighandler);
|
||||
break;
|
||||
|
||||
case SIGQUIT:
|
||||
/* Always ignore SIGQUIT. */
|
||||
set_signal_handler (SIGQUIT, SIG_IGN);
|
||||
break;
|
||||
case SIGTERM:
|
||||
#if defined (JOB_CONTROL)
|
||||
case SIGTTIN:
|
||||
case SIGTTOU:
|
||||
case SIGTSTP:
|
||||
#endif /* JOB_CONTROL */
|
||||
if (interactive)
|
||||
set_signal_handler (sig, SIG_IGN);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case IGNORE:
|
||||
ignore_signal (sig);
|
||||
break;
|
||||
}
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
static void
|
||||
showtrap (i, show_default)
|
||||
int i, show_default;
|
||||
{
|
||||
char *t, *p, *sn;
|
||||
int free_t;
|
||||
|
||||
free_t = 1;
|
||||
p = trap_list[i];
|
||||
if (p == (char *)DEFAULT_SIG && signal_is_hard_ignored (i) == 0)
|
||||
{
|
||||
if (show_default)
|
||||
t = "-";
|
||||
else
|
||||
return;
|
||||
free_t = 0;
|
||||
}
|
||||
else if (signal_is_hard_ignored (i))
|
||||
t = (char *)NULL;
|
||||
else
|
||||
t = (p == (char *)IGNORE_SIG) ? (char *)NULL : sh_single_quote (p);
|
||||
|
||||
sn = signal_name (i);
|
||||
/* Make sure that signals whose names are unknown (for whatever reason)
|
||||
are printed as signal numbers. */
|
||||
if (STREQN (sn, "SIGJUNK", 7) || STREQN (sn, "unknown", 7))
|
||||
printf ("trap -- %s %d\n", t ? t : "''", i);
|
||||
else if (posixly_correct)
|
||||
{
|
||||
if (STREQN (sn, "SIG", 3))
|
||||
printf ("trap -- %s %s\n", t ? t : "''", sn+3);
|
||||
else
|
||||
printf ("trap -- %s %s\n", t ? t : "''", sn);
|
||||
}
|
||||
else
|
||||
printf ("trap -- %s %s\n", t ? t : "''", sn);
|
||||
|
||||
if (free_t)
|
||||
FREE (t);
|
||||
}
|
||||
|
||||
static int
|
||||
display_traps (list, show_all)
|
||||
WORD_LIST *list;
|
||||
int show_all;
|
||||
{
|
||||
int result, i;
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
for (i = 0; i < BASH_NSIG; i++)
|
||||
showtrap (i, show_all);
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
for (result = EXECUTION_SUCCESS; list; list = list->next)
|
||||
{
|
||||
i = decode_signal (list->word->word, DSIG_NOCASE|DSIG_SIGPREFIX);
|
||||
if (i == NO_SIG)
|
||||
{
|
||||
sh_invalidsig (list->word->word);
|
||||
result = EXECUTION_FAILURE;
|
||||
}
|
||||
else
|
||||
showtrap (i, show_all);
|
||||
}
|
||||
|
||||
return (result);
|
||||
}
|
420
builtins/type.def
Normal file
420
builtins/type.def
Normal file
|
@ -0,0 +1,420 @@
|
|||
This file is type.def, from which is created type.c.
|
||||
It implements the builtin "type" in Bash.
|
||||
|
||||
Copyright (C) 1987-2020 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 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.
|
||||
|
||||
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
|
||||
|
||||
Arguments:
|
||||
NAME Command name to be interpreted.
|
||||
|
||||
Exit Status:
|
||||
Returns success if all of the NAMEs are found; fails if any are not found.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "../bashtypes.h"
|
||||
#include "posixstat.h"
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../parser.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "../findcmd.h"
|
||||
#include "../hashcmd.h"
|
||||
|
||||
#if defined (ALIAS)
|
||||
#include "../alias.h"
|
||||
#endif /* ALIAS */
|
||||
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
extern int find_reserved_word PARAMS((char *));
|
||||
|
||||
/* For each word in LIST, find out what the shell is going to do with
|
||||
it as a simple command. i.e., which file would this shell use to
|
||||
execve, or if it is a builtin command, or an alias. Possible flag
|
||||
arguments:
|
||||
-t Returns the "type" of the object, one of
|
||||
`alias', `keyword', `function', `builtin',
|
||||
or `file'.
|
||||
|
||||
-p Returns the pathname of the file if -type is
|
||||
a file.
|
||||
|
||||
-a Returns all occurrences of words, whether they
|
||||
be a filename in the path, alias, function,
|
||||
or builtin.
|
||||
|
||||
-f Suppress shell function lookup, like `command'.
|
||||
|
||||
-P Force a path search even in the presence of other
|
||||
definitions.
|
||||
|
||||
Order of evaluation:
|
||||
alias
|
||||
keyword
|
||||
function
|
||||
builtin
|
||||
file
|
||||
*/
|
||||
|
||||
int
|
||||
type_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int dflags, any_failed, opt;
|
||||
WORD_LIST *this;
|
||||
|
||||
if (list == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
dflags = CDESC_SHORTDESC; /* default */
|
||||
any_failed = 0;
|
||||
|
||||
/* Handle the obsolescent `-type', `-path', and `-all' by prescanning
|
||||
the arguments and converting those options to the form that
|
||||
internal_getopt recognizes. Converts `--type', `--path', and `--all'
|
||||
also. THIS SHOULD REALLY GO AWAY. */
|
||||
for (this = list; this && this->word->word[0] == '-'; this = this->next)
|
||||
{
|
||||
char *flag = &(this->word->word[1]);
|
||||
|
||||
if (STREQ (flag, "type") || STREQ (flag, "-type"))
|
||||
{
|
||||
this->word->word[1] = 't';
|
||||
this->word->word[2] = '\0';
|
||||
}
|
||||
else if (STREQ (flag, "path") || STREQ (flag, "-path"))
|
||||
{
|
||||
this->word->word[1] = 'p';
|
||||
this->word->word[2] = '\0';
|
||||
}
|
||||
else if (STREQ (flag, "all") || STREQ (flag, "-all"))
|
||||
{
|
||||
this->word->word[1] = 'a';
|
||||
this->word->word[2] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "afptP")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'a':
|
||||
dflags |= CDESC_ALL;
|
||||
break;
|
||||
case 'f':
|
||||
dflags |= CDESC_NOFUNCS;
|
||||
break;
|
||||
case 'p':
|
||||
dflags |= CDESC_PATH_ONLY;
|
||||
dflags &= ~(CDESC_TYPE|CDESC_SHORTDESC);
|
||||
break;
|
||||
case 't':
|
||||
dflags |= CDESC_TYPE;
|
||||
dflags &= ~(CDESC_PATH_ONLY|CDESC_SHORTDESC);
|
||||
break;
|
||||
case 'P': /* shorthand for type -ap */
|
||||
dflags |= (CDESC_PATH_ONLY|CDESC_FORCE_PATH);
|
||||
dflags &= ~(CDESC_TYPE|CDESC_SHORTDESC);
|
||||
break;
|
||||
CASE_HELPOPT;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
while (list)
|
||||
{
|
||||
int found;
|
||||
|
||||
found = describe_command (list->word->word, dflags);
|
||||
|
||||
if (!found && (dflags & (CDESC_PATH_ONLY|CDESC_TYPE)) == 0)
|
||||
sh_notfound (list->word->word);
|
||||
|
||||
any_failed += found == 0;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
opt = (any_failed == 0) ? EXECUTION_SUCCESS : EXECUTION_FAILURE;
|
||||
return (sh_chkwrite (opt));
|
||||
}
|
||||
|
||||
/*
|
||||
* Describe COMMAND as required by the type and command builtins.
|
||||
*
|
||||
* Behavior is controlled by DFLAGS. Flag values are
|
||||
* CDESC_ALL print all descriptions of a command
|
||||
* CDESC_SHORTDESC print the description for type and command -V
|
||||
* CDESC_REUSABLE print in a format that may be reused as input
|
||||
* CDESC_TYPE print the type for type -t
|
||||
* CDESC_PATH_ONLY print the path for type -p
|
||||
* CDESC_FORCE_PATH force a path search for type -P
|
||||
* CDESC_NOFUNCS skip function lookup for type -f
|
||||
* CDESC_ABSPATH convert to absolute path, no ./ prefix
|
||||
* CDESC_STDPATH command -p standard path list
|
||||
*
|
||||
* CDESC_ALL says whether or not to look for all occurrences of COMMAND, or
|
||||
* return after finding it once.
|
||||
*/
|
||||
int
|
||||
describe_command (command, dflags)
|
||||
char *command;
|
||||
int dflags;
|
||||
{
|
||||
int found, i, found_file, f, all;
|
||||
char *full_path, *x, *pathlist;
|
||||
SHELL_VAR *func;
|
||||
#if defined (ALIAS)
|
||||
alias_t *alias;
|
||||
#endif
|
||||
|
||||
all = (dflags & CDESC_ALL) != 0;
|
||||
found = found_file = 0;
|
||||
full_path = (char *)NULL;
|
||||
|
||||
#if defined (ALIAS)
|
||||
/* Command is an alias? */
|
||||
if (((dflags & CDESC_FORCE_PATH) == 0) && expand_aliases && (alias = find_alias (command)))
|
||||
{
|
||||
if (dflags & CDESC_TYPE)
|
||||
puts ("alias");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
printf (_("%s is aliased to `%s'\n"), command, alias->value);
|
||||
else if (dflags & CDESC_REUSABLE)
|
||||
{
|
||||
x = sh_single_quote (alias->value);
|
||||
printf ("alias %s=%s\n", command, x);
|
||||
free (x);
|
||||
}
|
||||
|
||||
found = 1;
|
||||
|
||||
if (all == 0)
|
||||
return (1);
|
||||
}
|
||||
#endif /* ALIAS */
|
||||
|
||||
/* Command is a shell reserved word? */
|
||||
if (((dflags & CDESC_FORCE_PATH) == 0) && (i = find_reserved_word (command)) >= 0)
|
||||
{
|
||||
if (dflags & CDESC_TYPE)
|
||||
puts ("keyword");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
printf (_("%s is a shell keyword\n"), command);
|
||||
else if (dflags & CDESC_REUSABLE)
|
||||
printf ("%s\n", command);
|
||||
|
||||
found = 1;
|
||||
|
||||
if (all == 0)
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Command is a function? */
|
||||
if (((dflags & (CDESC_FORCE_PATH|CDESC_NOFUNCS)) == 0) && (func = find_function (command)))
|
||||
{
|
||||
if (dflags & CDESC_TYPE)
|
||||
puts ("function");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
{
|
||||
char *result;
|
||||
|
||||
printf (_("%s is a function\n"), command);
|
||||
|
||||
/* We're blowing away THE_PRINTED_COMMAND here... */
|
||||
|
||||
result = named_function_string (command, function_cell (func), FUNC_MULTILINE|FUNC_EXTERNAL);
|
||||
printf ("%s\n", result);
|
||||
}
|
||||
else if (dflags & CDESC_REUSABLE)
|
||||
printf ("%s\n", command);
|
||||
|
||||
found = 1;
|
||||
|
||||
if (all == 0)
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Command is a builtin? */
|
||||
if (((dflags & CDESC_FORCE_PATH) == 0) && find_shell_builtin (command))
|
||||
{
|
||||
if (dflags & CDESC_TYPE)
|
||||
puts ("builtin");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
{
|
||||
if (posixly_correct && find_special_builtin (command) != 0)
|
||||
printf (_("%s is a special shell builtin\n"), command);
|
||||
else
|
||||
printf (_("%s is a shell builtin\n"), command);
|
||||
}
|
||||
else if (dflags & CDESC_REUSABLE)
|
||||
printf ("%s\n", command);
|
||||
|
||||
found = 1;
|
||||
|
||||
if (all == 0)
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Command is a disk file? */
|
||||
/* If the command name given is already an absolute command, just
|
||||
check to see if it is executable. */
|
||||
if (absolute_program (command))
|
||||
{
|
||||
f = file_status (command);
|
||||
if (f & FS_EXECABLE)
|
||||
{
|
||||
if (dflags & CDESC_TYPE)
|
||||
puts ("file");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
printf (_("%s is %s\n"), command, command);
|
||||
else if (dflags & (CDESC_REUSABLE|CDESC_PATH_ONLY))
|
||||
printf ("%s\n", command);
|
||||
|
||||
/* There's no use looking in the hash table or in $PATH,
|
||||
because they're not consulted when an absolute program
|
||||
name is supplied. */
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* If the user isn't doing "-a", then we might care about
|
||||
whether the file is present in our hash table. */
|
||||
if (all == 0 || (dflags & CDESC_FORCE_PATH))
|
||||
{
|
||||
if (full_path = phash_search (command))
|
||||
{
|
||||
if (dflags & CDESC_TYPE)
|
||||
puts ("file");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
printf (_("%s is hashed (%s)\n"), command, full_path);
|
||||
else if (dflags & (CDESC_REUSABLE|CDESC_PATH_ONLY))
|
||||
printf ("%s\n", full_path);
|
||||
|
||||
free (full_path);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Now search through $PATH. */
|
||||
while (1)
|
||||
{
|
||||
if (dflags & CDESC_STDPATH) /* command -p, all cannot be non-zero */
|
||||
{
|
||||
pathlist = conf_standard_path ();
|
||||
full_path = find_in_path (command, pathlist, FS_EXEC_PREFERRED|FS_NODIRS);
|
||||
free (pathlist);
|
||||
/* Will only go through this once, since all == 0 if STDPATH set */
|
||||
}
|
||||
else if (all == 0)
|
||||
full_path = find_user_command (command);
|
||||
else
|
||||
full_path = user_command_matches (command, FS_EXEC_ONLY, found_file); /* XXX - should that be FS_EXEC_PREFERRED? */
|
||||
|
||||
if (full_path == 0)
|
||||
break;
|
||||
|
||||
/* If we found the command as itself by looking through $PATH, it
|
||||
probably doesn't exist. Check whether or not the command is an
|
||||
executable file. If it's not, don't report a match. This is
|
||||
the default posix mode behavior */
|
||||
if (STREQ (full_path, command) || posixly_correct)
|
||||
{
|
||||
f = file_status (full_path);
|
||||
if ((f & FS_EXECABLE) == 0)
|
||||
{
|
||||
free (full_path);
|
||||
full_path = (char *)NULL;
|
||||
if (all == 0)
|
||||
break;
|
||||
}
|
||||
else if (ABSPATH (full_path))
|
||||
; /* placeholder; don't need to do anything yet */
|
||||
else if (dflags & (CDESC_REUSABLE|CDESC_PATH_ONLY|CDESC_SHORTDESC))
|
||||
{
|
||||
f = MP_DOCWD | ((dflags & CDESC_ABSPATH) ? MP_RMDOT : 0);
|
||||
x = sh_makepath ((char *)NULL, full_path, f);
|
||||
free (full_path);
|
||||
full_path = x;
|
||||
}
|
||||
}
|
||||
/* If we require a full path and don't have one, make one */
|
||||
else if ((dflags & CDESC_ABSPATH) && ABSPATH (full_path) == 0)
|
||||
{
|
||||
x = sh_makepath ((char *)NULL, full_path, MP_DOCWD|MP_RMDOT);
|
||||
free (full_path);
|
||||
full_path = x;
|
||||
}
|
||||
|
||||
found_file++;
|
||||
found = 1;
|
||||
|
||||
if (dflags & CDESC_TYPE)
|
||||
puts ("file");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
printf (_("%s is %s\n"), command, full_path);
|
||||
else if (dflags & (CDESC_REUSABLE|CDESC_PATH_ONLY))
|
||||
printf ("%s\n", full_path);
|
||||
|
||||
free (full_path);
|
||||
full_path = (char *)NULL;
|
||||
|
||||
if (all == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return (found);
|
||||
}
|
809
builtins/ulimit.def
Normal file
809
builtins/ulimit.def
Normal file
|
@ -0,0 +1,809 @@
|
|||
This file is ulimit.def, from which is created ulimit.c.
|
||||
It implements the builtin "ulimit" in Bash.
|
||||
|
||||
Copyright (C) 1987-2021 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 ulimit.c
|
||||
|
||||
$BUILTIN ulimit
|
||||
$FUNCTION ulimit_builtin
|
||||
$DEPENDS_ON !_MINIX
|
||||
$SHORT_DOC ulimit [-SHabcdefiklmnpqrstuvxPRT] [limit]
|
||||
Modify shell resource limits.
|
||||
|
||||
Provides control over the resources available to the shell and processes
|
||||
it creates, on systems that allow such control.
|
||||
|
||||
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
|
||||
-k the maximum number of kqueues allocated for this process
|
||||
-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
|
||||
-P the maximum number of pseudoterminals
|
||||
-R the maximum time a real-time process can run before blocking
|
||||
-T the maximum number of threads
|
||||
|
||||
Not all options are available on all platforms.
|
||||
|
||||
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)
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "../bashtypes.h"
|
||||
#if defined (HAVE_SYS_PARAM_H)
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
#include "pipesize.h"
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
/* For some reason, HPUX chose to make these definitions visible only if
|
||||
_KERNEL is defined, so we define _KERNEL before including <sys/resource.h>
|
||||
and #undef it afterward. */
|
||||
#if defined (HAVE_RESOURCE)
|
||||
# include <sys/time.h>
|
||||
# if defined (HPUX) && defined (RLIMIT_NEEDS_KERNEL)
|
||||
# define _KERNEL
|
||||
# endif
|
||||
# include <sys/resource.h>
|
||||
# if defined (HPUX) && defined (RLIMIT_NEEDS_KERNEL)
|
||||
# undef _KERNEL
|
||||
# endif
|
||||
#elif defined (HAVE_SYS_TIMES_H)
|
||||
# include <sys/times.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_LIMITS_H)
|
||||
# include <limits.h>
|
||||
#endif
|
||||
|
||||
/* Check for the most basic symbols. If they aren't present, this
|
||||
system's <sys/resource.h> isn't very useful to us. */
|
||||
#if !defined (RLIMIT_FSIZE) || !defined (HAVE_GETRLIMIT)
|
||||
# undef HAVE_RESOURCE
|
||||
#endif
|
||||
|
||||
#if !defined (HAVE_RESOURCE) && defined (HAVE_ULIMIT_H)
|
||||
# include <ulimit.h>
|
||||
#endif
|
||||
|
||||
#if !defined (RLIMTYPE)
|
||||
# define RLIMTYPE long
|
||||
# define string_to_rlimtype(s) strtol(s, (char **)NULL, 10)
|
||||
# define print_rlimtype(num, nl) printf ("%ld%s", num, nl ? "\n" : "")
|
||||
#endif
|
||||
|
||||
/* Alternate names */
|
||||
|
||||
/* Some systems use RLIMIT_NOFILE, others use RLIMIT_OFILE */
|
||||
#if defined (HAVE_RESOURCE) && defined (RLIMIT_OFILE) && !defined (RLIMIT_NOFILE)
|
||||
# define RLIMIT_NOFILE RLIMIT_OFILE
|
||||
#endif /* HAVE_RESOURCE && RLIMIT_OFILE && !RLIMIT_NOFILE */
|
||||
|
||||
#if defined (HAVE_RESOURCE) && defined (RLIMIT_POSIXLOCKS) && !defined (RLIMIT_LOCKS)
|
||||
# define RLIMIT_LOCKS RLIMIT_POSIXLOCKS
|
||||
#endif /* HAVE_RESOURCE && RLIMIT_POSIXLOCKS && !RLIMIT_LOCKS */
|
||||
|
||||
/* Some systems have these, some do not. */
|
||||
#ifdef RLIMIT_FSIZE
|
||||
# define RLIMIT_FILESIZE RLIMIT_FSIZE
|
||||
#else
|
||||
# define RLIMIT_FILESIZE 256
|
||||
#endif
|
||||
|
||||
#define RLIMIT_PIPESIZE 257
|
||||
|
||||
#ifdef RLIMIT_NOFILE
|
||||
# define RLIMIT_OPENFILES RLIMIT_NOFILE
|
||||
#else
|
||||
# define RLIMIT_OPENFILES 258
|
||||
#endif
|
||||
|
||||
#ifdef RLIMIT_VMEM
|
||||
# define RLIMIT_VIRTMEM RLIMIT_VMEM
|
||||
# define RLIMIT_VMBLKSZ 1024
|
||||
#else
|
||||
# ifdef RLIMIT_AS
|
||||
# define RLIMIT_VIRTMEM RLIMIT_AS
|
||||
# define RLIMIT_VMBLKSZ 1024
|
||||
# else
|
||||
# define RLIMIT_VIRTMEM 259
|
||||
# define RLIMIT_VMBLKSZ 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef RLIMIT_NPROC
|
||||
# define RLIMIT_MAXUPROC RLIMIT_NPROC
|
||||
#else
|
||||
# define RLIMIT_MAXUPROC 260
|
||||
#endif
|
||||
|
||||
#if !defined (RLIMIT_PTHREAD) && defined (RLIMIT_NTHR)
|
||||
# define RLIMIT_PTHREAD RLIMIT_NTHR
|
||||
#endif
|
||||
|
||||
#if !defined (RLIM_INFINITY)
|
||||
# define RLIM_INFINITY 0x7fffffff
|
||||
#endif
|
||||
|
||||
#if !defined (RLIM_SAVED_CUR)
|
||||
# define RLIM_SAVED_CUR RLIM_INFINITY
|
||||
#endif
|
||||
|
||||
#if !defined (RLIM_SAVED_MAX)
|
||||
# define RLIM_SAVED_MAX RLIM_INFINITY
|
||||
#endif
|
||||
|
||||
#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))
|
||||
|
||||
static int _findlim PARAMS((int));
|
||||
|
||||
static int ulimit_internal PARAMS((int, char *, int, int));
|
||||
|
||||
static int get_limit PARAMS((int, RLIMTYPE *, RLIMTYPE *));
|
||||
static int set_limit PARAMS((int, RLIMTYPE, int));
|
||||
|
||||
static void printone PARAMS((int, RLIMTYPE, int));
|
||||
static void print_all_limits PARAMS((int));
|
||||
|
||||
static int set_all_limits PARAMS((int, RLIMTYPE));
|
||||
|
||||
static int filesize PARAMS((RLIMTYPE *));
|
||||
static int pipesize PARAMS((RLIMTYPE *));
|
||||
static int getmaxuprc PARAMS((RLIMTYPE *));
|
||||
static int getmaxvm PARAMS((RLIMTYPE *, RLIMTYPE *));
|
||||
|
||||
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. */
|
||||
const char * const description; /* Descriptive string to output. */
|
||||
const char * const units; /* scale */
|
||||
} RESOURCE_LIMITS;
|
||||
|
||||
static RESOURCE_LIMITS limits[] = {
|
||||
#ifdef RLIMIT_NPTS
|
||||
{ 'P', RLIMIT_NPTS, 1, "number of pseudoterminals", (char *)NULL },
|
||||
#endif
|
||||
#ifdef RLIMIT_RTTIME
|
||||
{ 'R', RLIMIT_RTTIME, 1, "real-time non-blocking time", "microseconds" },
|
||||
#endif
|
||||
#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, POSIXBLK, "core file size", "blocks" },
|
||||
#endif
|
||||
#ifdef RLIMIT_DATA
|
||||
{ 'd', RLIMIT_DATA, 1024, "data seg size", "kbytes" },
|
||||
#endif
|
||||
#ifdef RLIMIT_NICE
|
||||
{ 'e', RLIMIT_NICE, 1, "scheduling priority", (char *)NULL },
|
||||
#endif
|
||||
{ 'f', RLIMIT_FILESIZE, POSIXBLK, "file size", "blocks" },
|
||||
#ifdef RLIMIT_SIGPENDING
|
||||
{ 'i', RLIMIT_SIGPENDING, 1, "pending signals", (char *)NULL },
|
||||
#endif
|
||||
#ifdef RLIMIT_KQUEUES
|
||||
{ 'k', RLIMIT_KQUEUES, 1, "max kqueues", (char *)NULL },
|
||||
#endif
|
||||
#ifdef RLIMIT_MEMLOCK
|
||||
{ 'l', RLIMIT_MEMLOCK, 1024, "max locked memory", "kbytes" },
|
||||
#endif
|
||||
#ifdef RLIMIT_RSS
|
||||
{ 'm', RLIMIT_RSS, 1024, "max memory size", "kbytes" },
|
||||
#endif /* RLIMIT_RSS */
|
||||
{ 'n', RLIMIT_OPENFILES, 1, "open files", (char *)NULL},
|
||||
{ 'p', RLIMIT_PIPESIZE, 512, "pipe size", "512 bytes" },
|
||||
#ifdef RLIMIT_MSGQUEUE
|
||||
{ 'q', RLIMIT_MSGQUEUE, 1, "POSIX message queues", "bytes" },
|
||||
#endif
|
||||
#ifdef RLIMIT_RTPRIO
|
||||
{ 'r', RLIMIT_RTPRIO, 1, "real-time priority", (char *)NULL },
|
||||
#endif
|
||||
#ifdef RLIMIT_STACK
|
||||
{ 's', RLIMIT_STACK, 1024, "stack size", "kbytes" },
|
||||
#endif
|
||||
#ifdef RLIMIT_CPU
|
||||
{ 't', RLIMIT_CPU, 1, "cpu time", "seconds" },
|
||||
#endif /* RLIMIT_CPU */
|
||||
{ 'u', RLIMIT_MAXUPROC, 1, "max user processes", (char *)NULL },
|
||||
#if defined (HAVE_RESOURCE)
|
||||
{ 'v', RLIMIT_VIRTMEM, RLIMIT_VMBLKSZ, "virtual memory", "kbytes" },
|
||||
#endif
|
||||
#ifdef RLIMIT_SWAP
|
||||
{ 'w', RLIMIT_SWAP, 1024, "swap size", "kbytes" },
|
||||
#endif
|
||||
#ifdef RLIMIT_LOCKS
|
||||
{ 'x', RLIMIT_LOCKS, 1, "file locks", (char *)NULL },
|
||||
#endif
|
||||
{ -1, -1, -1, (char *)NULL, (char *)NULL }
|
||||
};
|
||||
#define NCMDS (sizeof(limits) / sizeof(limits[0]))
|
||||
|
||||
typedef struct _cmd {
|
||||
int cmd;
|
||||
char *arg;
|
||||
} ULCMD;
|
||||
|
||||
static ULCMD *cmdlist;
|
||||
static int ncmd;
|
||||
static int cmdlistsz;
|
||||
|
||||
#if !defined (HAVE_RESOURCE) && !defined (HAVE_ULIMIT)
|
||||
long
|
||||
ulimit (cmd, newlim)
|
||||
int cmd;
|
||||
long newlim;
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
#endif /* !HAVE_RESOURCE && !HAVE_ULIMIT */
|
||||
|
||||
static int
|
||||
_findlim (opt)
|
||||
int opt;
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (i = 0; limits[i].option > 0; i++)
|
||||
if (limits[i].option == opt)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static char optstring[4 + 2 * NCMDS];
|
||||
|
||||
/* Report or set limits associated with certain per-process resources.
|
||||
See the help documentation in builtins.c for a full description. */
|
||||
int
|
||||
ulimit_builtin (list)
|
||||
register WORD_LIST *list;
|
||||
{
|
||||
register char *s;
|
||||
int c, limind, mode, opt, all_limits;
|
||||
|
||||
mode = 0;
|
||||
|
||||
all_limits = 0;
|
||||
|
||||
/* Idea stolen from pdksh -- build option string the first time called. */
|
||||
if (optstring[0] == 0)
|
||||
{
|
||||
s = optstring;
|
||||
*s++ = 'a'; *s++ = 'S'; *s++ = 'H';
|
||||
for (c = 0; limits[c].option > 0; c++)
|
||||
{
|
||||
*s++ = limits[c].option;
|
||||
*s++ = ';';
|
||||
}
|
||||
*s = '\0';
|
||||
}
|
||||
|
||||
/* Initialize the command list. */
|
||||
if (cmdlistsz == 0)
|
||||
cmdlist = (ULCMD *)xmalloc ((cmdlistsz = 16) * sizeof (ULCMD));
|
||||
ncmd = 0;
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, optstring)) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'a':
|
||||
all_limits++;
|
||||
break;
|
||||
|
||||
/* -S and -H are modifiers, not real options. */
|
||||
case 'S':
|
||||
mode |= LIMIT_SOFT;
|
||||
break;
|
||||
|
||||
case 'H':
|
||||
mode |= LIMIT_HARD;
|
||||
break;
|
||||
|
||||
CASE_HELPOPT;
|
||||
case '?':
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
|
||||
default:
|
||||
if (ncmd >= cmdlistsz)
|
||||
cmdlist = (ULCMD *)xrealloc (cmdlist, (cmdlistsz *= 2) * sizeof (ULCMD));
|
||||
cmdlist[ncmd].cmd = opt;
|
||||
cmdlist[ncmd++].arg = list_optarg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
if (all_limits)
|
||||
{
|
||||
#ifdef NOTYET
|
||||
if (list) /* setting */
|
||||
{
|
||||
if (STREQ (list->word->word, "unlimited") == 0)
|
||||
{
|
||||
builtin_error (_("%s: invalid limit argument"), list->word->word);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
return (set_all_limits (mode == 0 ? LIMIT_SOFT|LIMIT_HARD : mode, RLIM_INFINITY));
|
||||
}
|
||||
#endif
|
||||
print_all_limits (mode == 0 ? LIMIT_SOFT : mode);
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
/* default is `ulimit -f' */
|
||||
if (ncmd == 0)
|
||||
{
|
||||
cmdlist[ncmd].cmd = 'f';
|
||||
/* `ulimit something' is same as `ulimit -f something' */
|
||||
cmdlist[ncmd++].arg = list ? list->word->word : (char *)NULL;
|
||||
if (list)
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
/* verify each command in the list. */
|
||||
for (c = 0; c < ncmd; c++)
|
||||
{
|
||||
limind = _findlim (cmdlist[c].cmd);
|
||||
if (limind == -1)
|
||||
{
|
||||
builtin_error (_("`%c': bad command"), cmdlist[c].cmd);
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
|
||||
/* POSIX compatibility. If the last item in cmdlist does not have an option
|
||||
argument, but there is an operand (list != 0), treat the operand as if
|
||||
it were an option argument for that last command. */
|
||||
if (list && list->word && cmdlist[ncmd - 1].arg == 0)
|
||||
{
|
||||
cmdlist[ncmd - 1].arg = list->word->word;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
for (c = 0; c < ncmd; c++)
|
||||
if (ulimit_internal (cmdlist[c].cmd, cmdlist[c].arg, mode, ncmd > 1) == EXECUTION_FAILURE)
|
||||
return (EXECUTION_FAILURE);
|
||||
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
static int
|
||||
ulimit_internal (cmd, cmdarg, mode, multiple)
|
||||
int cmd;
|
||||
char *cmdarg;
|
||||
int mode, multiple;
|
||||
{
|
||||
int opt, limind, setting;
|
||||
int block_factor;
|
||||
RLIMTYPE soft_limit, hard_limit, real_limit, limit;
|
||||
|
||||
setting = cmdarg != 0;
|
||||
limind = _findlim (cmd);
|
||||
if (mode == 0)
|
||||
mode = setting ? (LIMIT_HARD|LIMIT_SOFT) : LIMIT_SOFT;
|
||||
opt = get_limit (limind, &soft_limit, &hard_limit);
|
||||
if (opt < 0)
|
||||
{
|
||||
builtin_error (_("%s: cannot get limit: %s"), limits[limind].description,
|
||||
strerror (errno));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (setting == 0) /* print the value of the specified limit */
|
||||
{
|
||||
printone (limind, (mode & LIMIT_SOFT) ? soft_limit : hard_limit, multiple);
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
/* Setting the limit. */
|
||||
if (STREQ (cmdarg, "hard"))
|
||||
real_limit = hard_limit;
|
||||
else if (STREQ (cmdarg, "soft"))
|
||||
real_limit = soft_limit;
|
||||
else if (STREQ (cmdarg, "unlimited"))
|
||||
real_limit = RLIM_INFINITY;
|
||||
else if (all_digits (cmdarg))
|
||||
{
|
||||
limit = string_to_rlimtype (cmdarg);
|
||||
block_factor = BLOCKSIZE(limits[limind].block_factor);
|
||||
real_limit = limit * block_factor;
|
||||
|
||||
if ((real_limit / block_factor) != limit)
|
||||
{
|
||||
sh_erange (cmdarg, _("limit"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sh_invalidnum (cmdarg);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (set_limit (limind, real_limit, mode) < 0)
|
||||
{
|
||||
builtin_error (_("%s: cannot modify limit: %s"), limits[limind].description,
|
||||
strerror (errno));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
static int
|
||||
get_limit (ind, softlim, hardlim)
|
||||
int ind;
|
||||
RLIMTYPE *softlim, *hardlim;
|
||||
{
|
||||
RLIMTYPE value;
|
||||
#if defined (HAVE_RESOURCE)
|
||||
struct rlimit limit;
|
||||
#endif
|
||||
|
||||
if (limits[ind].parameter >= 256)
|
||||
{
|
||||
switch (limits[ind].parameter)
|
||||
{
|
||||
case RLIMIT_FILESIZE:
|
||||
if (filesize (&value) < 0)
|
||||
return -1;
|
||||
break;
|
||||
case RLIMIT_PIPESIZE:
|
||||
if (pipesize (&value) < 0)
|
||||
return -1;
|
||||
break;
|
||||
case RLIMIT_OPENFILES:
|
||||
value = (RLIMTYPE)getdtablesize ();
|
||||
break;
|
||||
case RLIMIT_VIRTMEM:
|
||||
return (getmaxvm (softlim, hardlim));
|
||||
case RLIMIT_MAXUPROC:
|
||||
if (getmaxuprc (&value) < 0)
|
||||
return -1;
|
||||
break;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
*softlim = *hardlim = value;
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined (HAVE_RESOURCE)
|
||||
if (getrlimit (limits[ind].parameter, &limit) < 0)
|
||||
return -1;
|
||||
*softlim = limit.rlim_cur;
|
||||
*hardlim = limit.rlim_max;
|
||||
# if defined (HPUX9)
|
||||
if (limits[ind].parameter == RLIMIT_FILESIZE)
|
||||
{
|
||||
*softlim *= 512;
|
||||
*hardlim *= 512; /* Ugh. */
|
||||
}
|
||||
else
|
||||
# endif /* HPUX9 */
|
||||
return 0;
|
||||
#else
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
set_limit (ind, newlim, mode)
|
||||
int ind;
|
||||
RLIMTYPE newlim;
|
||||
int mode;
|
||||
{
|
||||
#if defined (HAVE_RESOURCE)
|
||||
struct rlimit limit;
|
||||
RLIMTYPE val;
|
||||
#endif
|
||||
|
||||
if (limits[ind].parameter >= 256)
|
||||
switch (limits[ind].parameter)
|
||||
{
|
||||
case RLIMIT_FILESIZE:
|
||||
#if !defined (HAVE_RESOURCE)
|
||||
return (ulimit (2, newlim / 512L));
|
||||
#else
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case RLIMIT_OPENFILES:
|
||||
#if defined (HAVE_SETDTABLESIZE)
|
||||
# if defined (__CYGWIN__)
|
||||
/* Grrr... Cygwin declares setdtablesize as void. */
|
||||
setdtablesize (newlim);
|
||||
return 0;
|
||||
# else
|
||||
return (setdtablesize (newlim));
|
||||
# endif
|
||||
#endif
|
||||
case RLIMIT_PIPESIZE:
|
||||
case RLIMIT_VIRTMEM:
|
||||
case RLIMIT_MAXUPROC:
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined (HAVE_RESOURCE)
|
||||
if (getrlimit (limits[ind].parameter, &limit) < 0)
|
||||
return -1;
|
||||
# if defined (HPUX9)
|
||||
if (limits[ind].parameter == RLIMIT_FILESIZE)
|
||||
newlim /= 512; /* Ugh. */
|
||||
# endif /* HPUX9 */
|
||||
val = (current_user.euid != 0 && newlim == RLIM_INFINITY &&
|
||||
(mode & LIMIT_HARD) == 0 && /* XXX -- test */
|
||||
(limit.rlim_cur <= limit.rlim_max))
|
||||
? limit.rlim_max : newlim;
|
||||
if (mode & LIMIT_SOFT)
|
||||
limit.rlim_cur = val;
|
||||
if (mode & LIMIT_HARD)
|
||||
limit.rlim_max = val;
|
||||
|
||||
return (setrlimit (limits[ind].parameter, &limit));
|
||||
#else
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
getmaxvm (softlim, hardlim)
|
||||
RLIMTYPE *softlim, *hardlim;
|
||||
{
|
||||
#if defined (HAVE_RESOURCE)
|
||||
struct rlimit datalim, stacklim;
|
||||
|
||||
if (getrlimit (RLIMIT_DATA, &datalim) < 0)
|
||||
return -1;
|
||||
|
||||
if (getrlimit (RLIMIT_STACK, &stacklim) < 0)
|
||||
return -1;
|
||||
|
||||
/* Protect against overflow. */
|
||||
*softlim = (datalim.rlim_cur / 1024L) + (stacklim.rlim_cur / 1024L);
|
||||
*hardlim = (datalim.rlim_max / 1024L) + (stacklim.rlim_max / 1024L);
|
||||
return 0;
|
||||
#else
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
#endif /* HAVE_RESOURCE */
|
||||
}
|
||||
|
||||
static int
|
||||
filesize(valuep)
|
||||
RLIMTYPE *valuep;
|
||||
{
|
||||
#if !defined (HAVE_RESOURCE)
|
||||
long result;
|
||||
if ((result = ulimit (1, 0L)) < 0)
|
||||
return -1;
|
||||
else
|
||||
*valuep = (RLIMTYPE) result * 512;
|
||||
return 0;
|
||||
#else
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
pipesize (valuep)
|
||||
RLIMTYPE *valuep;
|
||||
{
|
||||
#if defined (PIPE_BUF)
|
||||
/* This is defined on Posix systems. */
|
||||
*valuep = (RLIMTYPE) PIPE_BUF;
|
||||
return 0;
|
||||
#else
|
||||
# if defined (_POSIX_PIPE_BUF)
|
||||
*valuep = (RLIMTYPE) _POSIX_PIPE_BUF;
|
||||
return 0;
|
||||
# else
|
||||
# if defined (PIPESIZE)
|
||||
/* This is defined by running a program from the Makefile. */
|
||||
*valuep = (RLIMTYPE) PIPESIZE;
|
||||
return 0;
|
||||
# else
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
# endif /* PIPESIZE */
|
||||
# endif /* _POSIX_PIPE_BUF */
|
||||
#endif /* PIPE_BUF */
|
||||
}
|
||||
|
||||
static int
|
||||
getmaxuprc (valuep)
|
||||
RLIMTYPE *valuep;
|
||||
{
|
||||
long maxchild;
|
||||
|
||||
maxchild = getmaxchild ();
|
||||
if (maxchild < 0)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*valuep = (RLIMTYPE) maxchild;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_all_limits (mode)
|
||||
int mode;
|
||||
{
|
||||
register int i;
|
||||
RLIMTYPE softlim, hardlim;
|
||||
|
||||
if (mode == 0)
|
||||
mode |= LIMIT_SOFT;
|
||||
|
||||
for (i = 0; limits[i].option > 0; i++)
|
||||
{
|
||||
if (get_limit (i, &softlim, &hardlim) == 0)
|
||||
printone (i, (mode & LIMIT_SOFT) ? softlim : hardlim, 1);
|
||||
else if (errno != EINVAL)
|
||||
builtin_error ("%s: cannot get limit: %s", limits[i].description,
|
||||
strerror (errno));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
printone (limind, curlim, pdesc)
|
||||
int limind;
|
||||
RLIMTYPE curlim;
|
||||
int pdesc;
|
||||
{
|
||||
char unitstr[64];
|
||||
int factor;
|
||||
|
||||
factor = BLOCKSIZE(limits[limind].block_factor);
|
||||
if (pdesc)
|
||||
{
|
||||
if (limits[limind].units)
|
||||
sprintf (unitstr, "(%s, -%c) ", limits[limind].units, limits[limind].option);
|
||||
else
|
||||
sprintf (unitstr, "(-%c) ", limits[limind].option);
|
||||
|
||||
printf ("%-20s %20s", limits[limind].description, unitstr);
|
||||
}
|
||||
if (curlim == RLIM_INFINITY)
|
||||
puts ("unlimited");
|
||||
else if (curlim == RLIM_SAVED_MAX)
|
||||
puts ("hard");
|
||||
else if (curlim == RLIM_SAVED_CUR)
|
||||
puts ("soft");
|
||||
else
|
||||
print_rlimtype ((curlim / factor), 1);
|
||||
}
|
||||
|
||||
/* Set all limits to NEWLIM. NEWLIM currently must be RLIM_INFINITY, which
|
||||
causes all limits to be set as high as possible depending on mode (like
|
||||
csh `unlimit'). Returns -1 if NEWLIM is invalid, 0 if all limits
|
||||
were set successfully, and 1 if at least one limit could not be set.
|
||||
|
||||
To raise all soft limits to their corresponding hard limits, use
|
||||
ulimit -S -a unlimited
|
||||
To attempt to raise all hard limits to infinity (superuser-only), use
|
||||
ulimit -H -a unlimited
|
||||
To attempt to raise all soft and hard limits to infinity, use
|
||||
ulimit -a unlimited
|
||||
*/
|
||||
|
||||
static int
|
||||
set_all_limits (mode, newlim)
|
||||
int mode;
|
||||
RLIMTYPE newlim;
|
||||
{
|
||||
register int i;
|
||||
int retval = 0;
|
||||
|
||||
if (newlim != RLIM_INFINITY)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mode == 0)
|
||||
mode = LIMIT_SOFT|LIMIT_HARD;
|
||||
|
||||
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,
|
||||
strerror (errno));
|
||||
retval = 1;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* !_MINIX */
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue