mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-06-27 15:43:18 +02:00
bash-20121228 remove leftover and stray files
This commit is contained in:
-491
@@ -1,491 +0,0 @@
|
||||
This document details the changes between this version, bash-4.3-alpha,
|
||||
and the previous version, bash-4.2-release.
|
||||
|
||||
1. Changes to Bash
|
||||
|
||||
a. Fixed several bugs concerning incomplete bracket expressions in filename
|
||||
generation (globbing) patterns.
|
||||
|
||||
b. Fixed a bug with single quotes and WORD in ${param op WORD} when running
|
||||
in Posix mode.
|
||||
|
||||
c. Fixed a bug that caused the pattern removal and pattern substitution word
|
||||
expansions and case statement word expansion to not match the empty string.
|
||||
|
||||
d. Fixed a bug that caused the tzset() function to not work after changing
|
||||
the TZ enviroment variable.
|
||||
|
||||
e. Fixed a bug that caused the RHS of an assignment statement to undergo
|
||||
word splitting when it contained an unquoted $@.
|
||||
|
||||
f. Fixed bugs that caused the shell to not react to a SIGINT sent while
|
||||
waiting for a child process to exit.
|
||||
|
||||
g. Bash doesn't try to run things in a signal handler context when it gets a
|
||||
signal (SIGINT/SIGHUP/etc) while reading input using readline but still
|
||||
be responsive to terminating signals.
|
||||
|
||||
h. Fixed a bug that caused bash to go into an infinite loop if a filename
|
||||
to be matched contained an invalid multibyte character.
|
||||
|
||||
i. Fixed a bug that caused PS4 to end up being truncated if it is longer
|
||||
than 128 bytes.
|
||||
|
||||
j. Fixed a bug that caused brace expansion to not skip over double-quoted
|
||||
command substitution.
|
||||
|
||||
k. System-specific updates for: DJGPP, HP/UX, Mac OS X
|
||||
|
||||
l. Fixed a bug in displaying commands that caused redirections to be associated
|
||||
with the wrong part of the command.
|
||||
|
||||
m. Fixed the coproc cleanup to unset the appropriate shell variables when a
|
||||
coproc terminates.
|
||||
|
||||
n. Fixed a bug that caused `fc' to dump core due to incorrect calculation of
|
||||
the last history entry.
|
||||
|
||||
o. Added workarounds for FreeBSD's implementation of faccessat/eaccess and
|
||||
`test -x'.
|
||||
|
||||
p. Fixed a bug that caused the shell to not match patterns containing
|
||||
control-A.
|
||||
|
||||
q. Fixed a bug that could result in doubled error messages when the `printf'
|
||||
builtin got a write error.
|
||||
|
||||
r. Fixed a bug that caused the shell to not correctly expand words containing
|
||||
multiple consecutive quoted empty strings (""""""aa).
|
||||
|
||||
s. Fixed a bug that caused the shell to not correctly parse multi-line
|
||||
process substitutions containing comments and quoted strings.
|
||||
|
||||
t. Fixed a problem with the bash malloc's internal idea of the top of the
|
||||
memory heap that resulted in incorrect decisions to try to reduce the
|
||||
break and give memory back to the kernel.
|
||||
|
||||
u. There are changes to the expansions peformed on compound array assignments,
|
||||
in an effort to make foo=( [ind1]=bar [ind2]=baz ) identical to
|
||||
foo[ind1]=bar foo[ind2]=baz.
|
||||
|
||||
v. Bash now reports an error if `read -a name' is used when `name' is an
|
||||
existing associative array.
|
||||
|
||||
w. Fixed a bug that allowed an attempted assignment to a readonly variable
|
||||
in an arithmetic expression to not return failure.
|
||||
|
||||
x. Fixed several bugs that caused completion functions to be invoked even when
|
||||
the cursor was before the first word in the command.
|
||||
|
||||
y. Fixed a bug that caused parsing a command substitution to overwrite the
|
||||
parsing state associated with the complete input line.
|
||||
|
||||
z. Fixed several bugs with the built-in snprintf replacement and field widths
|
||||
and floating point.
|
||||
|
||||
aa. Fixed a bug that caused incorrect offset calculations and input buffer
|
||||
corruption when reading files longer than 2^31 bytes.
|
||||
|
||||
bb. Fixed several bugs where bash performed arithmetic evaluation in contexts
|
||||
where evaluation is suppressed.
|
||||
|
||||
cc. Fixed a bug that caused bash to close FIFOs used for process substitution
|
||||
too early when a shell function was executing, but protect against using
|
||||
all file descriptors when the shell functions are invoked inside loops.
|
||||
|
||||
dd. Added checks for printable (and non-printable) multibyte characters for
|
||||
use in error messages.
|
||||
|
||||
ee. Fixed a bug that caused ^O (operate-and-get-next) to not work correctly
|
||||
at the end of the history list.
|
||||
|
||||
ff. Fixed a bug that caused command-oriented history to incorrectly combine
|
||||
here documents into one line.
|
||||
|
||||
gg. Fixed a bug that caused importing SHELLOPTS from the environment into a
|
||||
Posix-mode shell to print an error message and refuse to parse it.
|
||||
|
||||
hh. Fixed a bug that caused the shell to delete an extra history entry when
|
||||
using `history -s'.
|
||||
|
||||
ii. Fixed a bug that caused floating-point exceptions and overflow errors
|
||||
for the / and % arithmetic operators when using INTMAX_MIN and -1.
|
||||
|
||||
jj. Fixed a bug that caused parsing errors when reading an arithmetic for
|
||||
loop inside a command substitution.
|
||||
|
||||
kk. Fixed a bug that caused a readonly function to be unset when unset was
|
||||
called without the -f or -v option.
|
||||
|
||||
ll. Fixed several bugs in the code that quotes characters special to regular
|
||||
expressions when used in a quoted string on the RHS of the =~ operator
|
||||
to the [[ command.
|
||||
|
||||
mm. Fixed a bug that caused redirections to fail because the file descriptor
|
||||
limit was set to a value less than 10.
|
||||
|
||||
nn. Fixed a bug that caused the `read' builtin to execute code in a signal
|
||||
handler context if read timed out.
|
||||
|
||||
oo. Fixed a bug that caused extended globbing patterns to not match files
|
||||
beginning with `.' correctly when a `.' was explicitly supplied in the
|
||||
pattern.
|
||||
|
||||
pp. Fixed a bug that caused key sequences longer than two characters to not
|
||||
work when used with `bind -x'.
|
||||
|
||||
qq. Fixed a bug that resulted in redefined functions having the wrong source
|
||||
file names in BASH_SOURCE.
|
||||
|
||||
rr. Fixed a bug that caused the read builtin to assign null strings to variables
|
||||
when using `read -N', which caused core dumps when referenced
|
||||
|
||||
ss. Fixed a bug that caused `bash -m script' to not enable job control while
|
||||
running the script.
|
||||
|
||||
tt. Fixed a bug that caused `printf -v var' to dump core when used with the
|
||||
%b format code.
|
||||
|
||||
uu. Fixed a bug that caused the shell to exit with the wrong status if -e was
|
||||
active and the shell exited on a substitution error.
|
||||
|
||||
vv. Fixed a bug that caused the shell to seg fault if an array variable with
|
||||
the same name as an existing associative array was implicitly created by
|
||||
an assignment (declare a[n]=b).
|
||||
|
||||
ww. Fixed a bug that caused a redirection to misbehave if the number specified
|
||||
for a file descriptor overflows an intmax_t.
|
||||
|
||||
xx. Fixed several bugs with the handling of valid and invalid unicode character
|
||||
values when used with the \u and \U escape sequences to printf and $'...'.
|
||||
|
||||
yy. Fixed a bug that caused tildes to not be escaped in expanded filenames,
|
||||
making them subject to later expansion.
|
||||
|
||||
zz. When using the pattern substitution word expansion, bash now runs the
|
||||
replacement string through quote removal, since it allows quotes in that
|
||||
string to act as escape characters. This is not backwards compatible, so
|
||||
it can be disabled by setting the bash compatibility mode to 4.2.
|
||||
|
||||
aaa. Fixed the rest of the cases where the shell runs non-allowed code in a
|
||||
signal handler context.
|
||||
|
||||
bbb. Fixed a bug that caused spurious DEL characters (\177) to appear in
|
||||
double-quoted expansion where the RHS is evaluated to the empty string.
|
||||
|
||||
ccc. Fixed a bug that caused the use of the shell's internal random number
|
||||
generator for temporary file names to perturb the random number
|
||||
sequence.
|
||||
|
||||
ddd. Fixed several bugs that caused `declare -g' to not set the right global
|
||||
variables or to misbehave when declaring global indexed arrays.
|
||||
|
||||
eee. Fixed a logic bug that caused extended globbing in a multibyte locale to
|
||||
cause failures when using the pattern substititution word expansions.
|
||||
|
||||
fff. Fixed a bug that caused the `lastpipe' option to corrupt the file
|
||||
descriptor used to read the script.
|
||||
|
||||
ggg. Fixed a bug that causes the shell to delete DEL characters in the
|
||||
expanded value of variables used in the same quoted string as variables
|
||||
that expand to nothing.
|
||||
|
||||
hhh. Fixed a bug that caused the shell to assign the wrong value from an
|
||||
assignment like (( x=7 )) when `x' was an existing array variable.
|
||||
|
||||
iii. Fixed a bug that caused the shell to misbehave when generating sequences
|
||||
and the boundary values overflow an intmax_t.
|
||||
|
||||
jjj. Fixed a bug caused expansion errors if an expansion of "$@" appeared
|
||||
next to another expansion (e.g.. "${@}${x}").
|
||||
|
||||
kkk. Fixed a potential buffer overflow bug when performing /dev/fd expansion.
|
||||
|
||||
lll. Fixed a bug that resulted in an extra semicolon being added to compound
|
||||
assignments when they were added to the history list.
|
||||
|
||||
mmm. Fixed a bug that caused mapfile to read one extra line from the input.
|
||||
|
||||
nnn. Fixed a bug that caused the mail checking code to use uninitialized
|
||||
values.
|
||||
|
||||
ooo. Fixed a bug that prevented history timestamps from being saved if the
|
||||
history comment character is unset.
|
||||
|
||||
ppp. Fixed a bug that caused the case-modifying expansions to not work with
|
||||
multibyte characters.
|
||||
|
||||
qqq. Fixed a bug that caused the edit-and-execute bindable readline command
|
||||
to see the wrong data if invoked in the middle of a multi-line quoted
|
||||
string.
|
||||
|
||||
rrr. Fixed a bug that resulted in the shell returning the wrong exit status
|
||||
for a background command on systems that recycle PIDs very quickly.
|
||||
|
||||
sss. Fixed a bug that caused asynchronous group commands to not run any EXIT
|
||||
trap defined in the body of the command.
|
||||
|
||||
ttt. Fixed a bug that caused `eval "... ; return"' to not clean up properly.
|
||||
|
||||
uuu. Fixed a bug that caused the shell to dump core if `read' reads an escaped
|
||||
IFS whitespace character.
|
||||
|
||||
vvv. Fixed a bug that caused BASH_COMMAND to be set to an incorrect value when
|
||||
executing a (...) subshell.
|
||||
|
||||
www. Fixed a pointer aliasing bug with the token string in arithmetic
|
||||
evaluation.
|
||||
|
||||
xxx. Fixed a bug with parsing multi-line command substitutions when reading
|
||||
the `do' keyword followed by whitespace.
|
||||
|
||||
yyy. Fixed a bug that caused the shell to seg fault if the time given to the
|
||||
printf %(...)T format overflowed the value accepted by localtime(3).
|
||||
|
||||
zzz. Fixed a problem with displaying help topics in two columns when the
|
||||
translated text contained multibyte characters.
|
||||
|
||||
aaaa. Fixed a bug with the extended globbing pattern matcher where a `*' was
|
||||
followed by a negated extended glob pattern.
|
||||
|
||||
bbbb. Fixed a race condition with short-lived coproc creation and reaping that
|
||||
caused the child process to be reaped before the various coproc shell
|
||||
variables were initialized.
|
||||
|
||||
cccc. Fixed a bug where turning off `errexit' in command substitution subshells
|
||||
was not reflected in $SHELLOPTS.
|
||||
|
||||
dddd. Partially fixed an inconsistency in how the shell treated shell
|
||||
functions run from an EXIT trap.
|
||||
|
||||
eeee. Fixed a bug in how the shell invalidated FIFOs used for process
|
||||
substitution when executing a pipeline (once rather than in every child).
|
||||
|
||||
ffff. Fixed a bug that occurred when expanding a special variable ($@, $*)
|
||||
within double quotes and the expansion resulted in an empty string.
|
||||
|
||||
gggg. Fixed bugs with executing a SIGCHLD trap handler to make sure that it's
|
||||
executed once per exited child.
|
||||
|
||||
hhhh. Fixed a bug that caused `declare' and `test' to find variables that
|
||||
had been given attributes but not assigned values. Such variables are
|
||||
not set.
|
||||
|
||||
iiii. Fixed a bug that caused commands in process substitutions to not look in
|
||||
the local temporary environment when performing word expansions.
|
||||
|
||||
jjjj. Fixed several problems with globstar expansions (**/**) returning null
|
||||
filenames and multiple instances of the same pathname.
|
||||
|
||||
kkkk. Fixed an oversight that did not allow the exit status of `coproc' to
|
||||
be inverted using `!'.
|
||||
|
||||
llll. Fixed a bug that caused the -e option to be re-enabled using `set -e'
|
||||
even when executing in a context where -e is ignored.
|
||||
|
||||
mmmm. Fixed a (mostly theoretical) bug with input lines longer than SIZE_MAX.
|
||||
|
||||
2. Changes to Readline
|
||||
|
||||
a. Fixed a bug that did not allow the `dd', `cc', or `yy' vi editing mode
|
||||
commands to work on the entire line.
|
||||
|
||||
b. Fixed a bug that caused redisplay problems with prompts longer than 128
|
||||
characters and history searches.
|
||||
|
||||
c. Fixed a bug that caused readline to try and run code to modify its idea
|
||||
of the screen size in a signal handler context upon receiving a SIGWINCH.
|
||||
|
||||
d. Fixed a bug that caused the `meta' key to be enabled beyond the duration
|
||||
of an individual call top readline().
|
||||
|
||||
e. Added a workaround for a wcwidth bug in Mac OS X that caused readline's
|
||||
redisplay to mishandle zero-width combining characters.
|
||||
|
||||
f. Fixed a bug that caused readline to `forget' part of a key sequence when
|
||||
a multiple-key sequence caused it to break out of an incremental search.
|
||||
|
||||
g. Fixed bugs that caused readline to execute code in a signal handler
|
||||
context if interrupted while reading from the file system during completion.
|
||||
|
||||
h. Fixed a bug that caused readline to `forget' part of a key sequence when
|
||||
reading an unbound multi-character key sequence.
|
||||
|
||||
i. Fixed a bug that caused Readline's signal handlers to be installed beyond
|
||||
the bounds of a single call to readline().
|
||||
|
||||
j. Fixed a bug that caused the `.' command to not redo the most recent `R'
|
||||
command in vi mode.
|
||||
|
||||
k. Fixed a bug that caused ignoring case in completion matches to result in
|
||||
readline using the wrong match.
|
||||
|
||||
l. Paren matching now works in vi insert mode.
|
||||
|
||||
m. Fix menu-completion to make show-all-if-ambiguous and menu-complete-display-prefix
|
||||
work together.
|
||||
|
||||
n. Fixed a bug that didn't allow the `cc', `dd', or `yy' commands to be redone
|
||||
in vi editing mode.
|
||||
|
||||
o. Fixed a bug that caused the filename comparison code to not compare
|
||||
multibyte characters correctly when using case-sensitive or case-mapping
|
||||
comparisons.
|
||||
|
||||
p. Fixed the input reading loop to call the input hook function only when there
|
||||
is no terminal input available.
|
||||
|
||||
q. Fixed a bug that caused binding a macro to a multi-character key sequence
|
||||
where the sequence and macro value share a common prefix to not perform
|
||||
the macro replacement.
|
||||
|
||||
r. Fixed several redisplay errors with multibyte characters and prompts
|
||||
containing invisible characters when using horizontal scrolling.
|
||||
|
||||
3. New Features in Bash
|
||||
|
||||
a. The `helptopic' completion action now maps to all the help topics, not just
|
||||
the shell builtins.
|
||||
|
||||
b. The `help' builtin no longer does prefix substring matching, so `help read'
|
||||
does not match `readonly'.
|
||||
|
||||
c. The shell can be compiled to not display a message about processes that
|
||||
terminate due to SIGTERM.
|
||||
|
||||
d. Non-interactive shells now react to the setting of checkwinsize and set
|
||||
LINES and COLUMNS after a foreground job exits.
|
||||
|
||||
e. There is a new shell option, `globasciiranges', which, when set to on,
|
||||
forces globbing range comparisons to use character ordering as if they
|
||||
were run in the C locale.
|
||||
|
||||
f. There is a new shell option, `direxpand', which makes filename completion
|
||||
expand variables in directory names in the way bash-4.1 did.
|
||||
|
||||
g. In Posix mode, the `command' builtin does not change whether or not a
|
||||
builtin it shadows is treated as an assignment builtin.
|
||||
|
||||
h. The `return' and `exit' builtins accept negative exit status arguments.
|
||||
|
||||
i. The word completion code checks whether or not a filename containing a
|
||||
shell variable expands to a directory name and appends `/' to the word
|
||||
as appropriate. The same code expands shell variables in command names
|
||||
when performing command completion.
|
||||
|
||||
j. In Posix mode, it is now an error to attempt to define a shell function
|
||||
with the same name as a Posix special builtin.
|
||||
|
||||
k. When compiled for strict Posix conformance, history expansion is disabled
|
||||
by default.
|
||||
|
||||
l. The history expansion character (!) does not cause history expansion when
|
||||
followed by the closing quote in a double-quoted string.
|
||||
|
||||
m. `complete' and its siblings compgen/compopt now takes a new `-o noquote'
|
||||
option to inhibit quoting of the completions.
|
||||
|
||||
n. Setting HISTSIZE to a value less than zero causes the history list to be
|
||||
unlimited (setting it 0 zero disables the history list).
|
||||
|
||||
o. Setting HISTFILESIZE to a value less than zero causes the history file size
|
||||
to be unlimited (setting it to 0 causes the history file to be truncated
|
||||
to zero size).
|
||||
|
||||
p. The `read' builtin now skips NUL bytes in the input.
|
||||
|
||||
q. There is a new `bind -X' option to print all key sequences bound to Unix
|
||||
commands.
|
||||
|
||||
r. When in Posix mode, `read' is interruptible by a trapped signal. After
|
||||
running the trap handler, read returns 128+signal and throws away any
|
||||
partially-read input.
|
||||
|
||||
s. The command completion code skips whitespace and assignment statements
|
||||
before looking for the command name word to be completed.
|
||||
|
||||
t. The build process has a new mechanism for constructing separate help files
|
||||
that better reflects the current set of compilation options.
|
||||
|
||||
u. The -nt and -ot options to test now work with files with nanosecond
|
||||
timestamp resolution.
|
||||
|
||||
v. The shell saves the command history in any shell for which history is
|
||||
enabled and HISTFILE is set, not just interactive shells.
|
||||
|
||||
w. The shell has `nameref' variables and new -n(/+n) options to declare and
|
||||
unset to use them, and a `test -R' option to test for them.
|
||||
|
||||
x. The shell now allows assigning, referencing, and unsetting elements of
|
||||
indexed arrays using negative subscripts (a[-1]=2, echo ${a[-1]}) which
|
||||
count back from the last element of the array.
|
||||
|
||||
y. The {x}<word redirection feature now allows words like {array[ind]} and
|
||||
can use variables with special meanings to the shell (e.g., BASH_XTRACEFD).
|
||||
|
||||
z. There is a new CHILD_MAX special shell variable; its value controls the
|
||||
number of exited child statues the shell remembers.
|
||||
|
||||
aa. There is a new configuration option (--enable-direxpand-default) that
|
||||
causes the `direxpand' shell option to be enabled by default.
|
||||
|
||||
bb. Bash does not do anything special to ensure that the file descriptor
|
||||
assigned to X in {x}<foo remains open after the block containing it
|
||||
completes.
|
||||
|
||||
cc. The `wait' builtin has a new `-n' option to wait for the next child to
|
||||
change status.
|
||||
|
||||
dd. The `printf' %(...)T format specifier now uses the current time if no
|
||||
argument is supplied.
|
||||
|
||||
4. New Features in Readline
|
||||
|
||||
a. Readline is now more responsive to SIGHUP and other fatal signals when
|
||||
reading input from the terminal or performing word completion but no
|
||||
longer attempts to run any not-allowable functions from a signal handler
|
||||
context.
|
||||
|
||||
b. There are new bindable commands to search the history for the string of
|
||||
characters between the beginning of the line and the point
|
||||
(history-substring-search-forward, history-substring-search-backward)
|
||||
|
||||
c. Readline allows quoted strings as the values of variables when setting
|
||||
them with `set'. As a side effect, trailing spaces and tabs are ignored
|
||||
when setting a string variable's value.
|
||||
|
||||
d. The history library creates a backup of the history file when writing it
|
||||
and restores the backup on a write error.
|
||||
|
||||
e. New application-settable variable: rl_filename_stat_hook: a function called
|
||||
with a filename before using it in a call to stat(2). Bash uses it to
|
||||
expand shell variables so things like $HOME/Downloads have a slash
|
||||
appended.
|
||||
|
||||
f. New bindable function `print-last-kbd-macro', prints the most-recently-
|
||||
defined keyboard macro in a reusable format.
|
||||
|
||||
g. New user-settable variable `colored-stats', enables use of colored text
|
||||
to denote file types when displaying possible completions (colored analog
|
||||
of visible-stats).
|
||||
|
||||
h. New user-settable variable `keyseq-timout', acts as an inter-character
|
||||
timeout when reading input or incremental search strings.
|
||||
|
||||
i. New application-callable function: rl_clear_history. Clears the history list
|
||||
and frees all readline-associated private data.
|
||||
|
||||
j. New user-settable variable, show-mode-in-prompt, adds a characters to the
|
||||
beginning of the prompt indicating the current editing mode.
|
||||
|
||||
k. New application-settable variable: rl_input_available_hook; function to be
|
||||
called when readline detects there is data available on its input file
|
||||
descriptor.
|
||||
|
||||
l. Readline calls an application-set event hook (rl_event_hook) after it gets
|
||||
a signal while reading input (read returns -1/EINTR but readline does not
|
||||
handle the signal immediately) to allow the application to handle or
|
||||
otherwise note it.
|
||||
|
||||
m. If the user-settable variable `history-size' is set to a value less than
|
||||
0, the history list size is unlimited.
|
||||
@@ -1,417 +0,0 @@
|
||||
Compatibility with previous versions
|
||||
====================================
|
||||
|
||||
This document details the incompatibilities between this version of bash,
|
||||
bash-4.2, and the previous widely-available versions, bash-2.x (which is
|
||||
still the `standard' version for a few Linux distributions) and bash-3.x.
|
||||
These were discovered by users of bash-2.x through 4.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 subsitution 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, 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.
|
||||
|
||||
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, and
|
||||
compat41 at this writing). There is only one current compatibility level --
|
||||
each option is mutually exclusive. This list 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).
|
||||
|
||||
compat31 set
|
||||
- the < and > operators to the [[ command do not consider the current
|
||||
locale when comparing strings; they use ASCII ordering
|
||||
- quoting the rhs of the regexp matching operator (=~) has no
|
||||
special effect
|
||||
|
||||
compat32 set
|
||||
- the < and > operators to the [[ command do not consider the current
|
||||
locale when comparing strings; they use ASCII ordering
|
||||
|
||||
compat40 set
|
||||
- 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 entire list to be aborted (in versions before bash-4.0,
|
||||
interrupting one command in a list caused the next to be executed)
|
||||
|
||||
compat41 set
|
||||
- interrupting a command list such as "a ; b ; c" causes the execution
|
||||
of the entire list to be aborted (in versions before bash-4.1,
|
||||
interrupting one command in a list caused the next to be executed)
|
||||
- when in posix mode, single quotes in the `word' portion of a
|
||||
double-quoted parameter expansion define a new quoting context and
|
||||
are treated specially
|
||||
|
||||
compat42 set
|
||||
- the replacement string in double-quoted pattern substitution is not
|
||||
run through quote removal, as in previous versions
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
-4262
File diff suppressed because it is too large
Load Diff
@@ -1,82 +0,0 @@
|
||||
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.2 standard by changing the behavior to match that
|
||||
specified by Posix.2 in areas where the bash default differs.
|
||||
|
||||
The following list is what's changed when `posix mode' is in effect:
|
||||
|
||||
1. 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'.
|
||||
|
||||
2. The >& redirection does not redirect stdout and stderr.
|
||||
|
||||
3. The message printed by the job control code and builtins when a job
|
||||
exits with a non-zero status is `Done(status)'.
|
||||
|
||||
4. Reserved words may not be aliased.
|
||||
|
||||
5. The Posix.2 PS1 and PS2 expansions of `!' -> history number and
|
||||
`!!' -> `!' are enabled, and parameter expansion is performed on
|
||||
the value regardless of the setting of the `promptvars' option.
|
||||
|
||||
6. Interactive comments are enabled by default. (Note that bash has
|
||||
them on by default anyway.)
|
||||
|
||||
7. The Posix.2 startup files are executed ($ENV) rather than the normal
|
||||
bash files.
|
||||
|
||||
8. Tilde expansion is only performed on assignments preceding a command
|
||||
name, rather than on all assignment statements on the line.
|
||||
|
||||
9. The default history file is ~/.sh_history (default value of $HISTFILE).
|
||||
|
||||
10. The output of `kill -l' prints all the signal names on a single line,
|
||||
separated by spaces.
|
||||
|
||||
11. Non-interactive shells exit if `file' in `. file' is not found.
|
||||
|
||||
12. Redirection operators do not perform pathname expansion on the word
|
||||
in the redirection unless the shell is interactive
|
||||
|
||||
13. Function names must be valid shell identifiers. 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 illegal name
|
||||
causes a fatal syntax error in non-interactive shells.
|
||||
|
||||
14. Posix.2 `special' builtins are found before shell functions during command
|
||||
lookup.
|
||||
|
||||
15. If a Posix.2 special builtin returns an error status, a non-interactive
|
||||
shell exits. The fatal errors are those listed in the POSIX.2 standard,
|
||||
and include things like passing incorrect options, redirection errors,
|
||||
variable assignment errors for assignments preceding the command name,
|
||||
and so on.
|
||||
|
||||
16. The environment passed to executed commands is not sorted. Neither is
|
||||
the output of `set'. This is not strictly Posix.2 behavior, but sh
|
||||
does it this way. Ksh does not. It's not necessary to sort the
|
||||
environment; no program should rely on it being sorted.
|
||||
|
||||
17. If the `cd' builtin finds a directory to change to using $CDPATH, the
|
||||
value it assigns to $PWD does not contain any symbolic links, as if
|
||||
`cd -P' had been executed.
|
||||
|
||||
18. 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 read-only variable.
|
||||
|
||||
19. 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 read-only variable.
|
||||
|
||||
20. Process substitution is not available.
|
||||
|
||||
21. Assignment statements preceding POSIX.2 `special' builtins persist in
|
||||
the shell environment after the builtin completes.
|
||||
|
||||
There is other Posix.2 behavior that bash does not implement. Specifically:
|
||||
|
||||
1. Assignment statements affect the execution environment of all builtins,
|
||||
not just special ones.
|
||||
@@ -1,544 +0,0 @@
|
||||
This file is set.def, from which is created set.c.
|
||||
It implements the "set" and "unset" builtins in Bash.
|
||||
|
||||
Copyright (C) 1987, 1989, 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 1, or (at your option) any later
|
||||
version.
|
||||
|
||||
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Bash; see the file COPYING. If not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
$PRODUCES set.c
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../shell.h"
|
||||
#include "../flags.h"
|
||||
|
||||
#include "bashgetopt.h"
|
||||
|
||||
extern int interactive;
|
||||
extern int noclobber, posixly_correct;
|
||||
#if defined (READLINE)
|
||||
extern int rl_editing_mode, no_line_editing;
|
||||
#endif /* READLINE */
|
||||
|
||||
$BUILTIN set
|
||||
$FUNCTION set_builtin
|
||||
$SHORT_DOC set [--abefhkmnptuvxldBCHP] [-o option] [arg ...]
|
||||
-a Mark variables which are modified or created for export.
|
||||
-b Notify of job termination immediately.
|
||||
-e Exit immediately if a command exits with a non-zero status.
|
||||
-f Disable file name generation (globbing).
|
||||
-h Locate and remember function commands as functions are
|
||||
defined. Function commands are normally looked up when
|
||||
the function is executed.
|
||||
-i Force the shell to be an "interactive" one. Interactive shells
|
||||
always read `~/.bashrc' on startup.
|
||||
-k All keyword arguments are placed in the environment for a
|
||||
command, not just those that precede the command name.
|
||||
-m Job control is enabled.
|
||||
-n Read commands but do not execute them.
|
||||
-o option-name
|
||||
Set the variable corresponding to option-name:
|
||||
allexport same as -a
|
||||
braceexpand same as -B
|
||||
#if defined (READLINE)
|
||||
emacs use an emacs-style line editing interface
|
||||
#endif /* READLINE */
|
||||
errexit same as -e
|
||||
histexpand same as -H
|
||||
ignoreeof the shell will not exit upon reading EOF
|
||||
interactive-comments
|
||||
allow comments to appear in interactive commands
|
||||
monitor same as -m
|
||||
noclobber disallow redirection to existing files
|
||||
noexec same as -n
|
||||
noglob same as -f
|
||||
nohash same as -d
|
||||
notify save as -b
|
||||
nounset same as -u
|
||||
physical same as -P
|
||||
posix change the behavior of bash where the default
|
||||
operation differs from the 1003.2 standard to
|
||||
match the standard
|
||||
privileged same as -p
|
||||
verbose same as -v
|
||||
#if defined (READLINE)
|
||||
vi use a vi-style line editing interface
|
||||
#endif /* READLINE */
|
||||
xtrace same as -x
|
||||
-p Turned on whenever the real and effective user ids do not match.
|
||||
Disables processing of the $ENV file and importing of shell
|
||||
functions. Turning this option off causes the effective uid and
|
||||
gid to be set to the real uid and gid.
|
||||
-t Exit after reading and executing one command.
|
||||
-u Treat unset variables as an error when substituting.
|
||||
-v Print shell input lines as they are read.
|
||||
-x Print commands and their arguments as they are executed.
|
||||
-l Save and restore the binding of the NAME in a FOR command.
|
||||
-d Disable the hashing of commands that are looked up for execution.
|
||||
Normally, commands are remembered in a hash table, and once
|
||||
found, do not have to be looked up again.
|
||||
#if defined (BRACE_EXPANSION)
|
||||
-B the shell will perform brace expansion
|
||||
#endif /* BRACE_EXPANSION */
|
||||
#if defined (BANG_HISTORY)
|
||||
-H Enable ! style history substitution. This flag is on
|
||||
by default.
|
||||
#endif /* BANG_HISTORY */
|
||||
-C If set, disallow existing regular files to be overwritten
|
||||
by redirection of output.
|
||||
-P If set, do not follow symbolic links when executing commands
|
||||
such as cd which change the current directory.
|
||||
|
||||
Using + rather than - causes these flags to be turned off. The
|
||||
flags can also be used upon invocation of the shell. The current
|
||||
set of flags may be found in $-. The remaining n ARGs are positional
|
||||
parameters and are assigned, in order, to $1, $2, .. $n. If no
|
||||
ARGs are given, all shell variables are printed.
|
||||
$END
|
||||
|
||||
/* An a-list used to match long options for set -o to the corresponding
|
||||
option letter. */
|
||||
struct {
|
||||
char *name;
|
||||
int letter;
|
||||
} o_options[] = {
|
||||
{ "allexport", 'a' },
|
||||
#if defined (BRACE_EXPANSION)
|
||||
{ "braceexpand",'B' },
|
||||
#endif
|
||||
{ "errexit", 'e' },
|
||||
{ "histexpand", 'H' },
|
||||
{ "monitor", 'm' },
|
||||
{ "noexec", 'n' },
|
||||
{ "noglob", 'f' },
|
||||
{ "nohash", 'd' },
|
||||
#if defined (JOB_CONTROL)
|
||||
{ "notify", 'b' },
|
||||
#endif /* JOB_CONTROL */
|
||||
{"nounset", 'u' },
|
||||
{"physical", 'P' },
|
||||
{"privileged", 'p' },
|
||||
{"verbose", 'v' },
|
||||
{"xtrace", 'x' },
|
||||
{(char *)NULL, 0},
|
||||
};
|
||||
|
||||
#define MINUS_O_FORMAT "%-15s\t%s\n"
|
||||
|
||||
void
|
||||
list_minus_o_opts ()
|
||||
{
|
||||
register int i;
|
||||
char *on = "on", *off = "off";
|
||||
|
||||
printf (MINUS_O_FORMAT, "noclobber", (noclobber == 1) ? on : off);
|
||||
|
||||
if (find_variable ("ignoreeof") || find_variable ("IGNOREEOF"))
|
||||
printf (MINUS_O_FORMAT, "ignoreeof", on);
|
||||
else
|
||||
printf (MINUS_O_FORMAT, "ignoreeof", off);
|
||||
|
||||
printf (MINUS_O_FORMAT, "interactive-comments",
|
||||
interactive_comments ? on : off);
|
||||
|
||||
printf (MINUS_O_FORMAT, "posix", posixly_correct ? on : off);
|
||||
|
||||
#if defined (READLINE)
|
||||
if (no_line_editing)
|
||||
{
|
||||
printf (MINUS_O_FORMAT, "emacs", off);
|
||||
printf (MINUS_O_FORMAT, "vi", off);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Magic. This code `knows' how readline handles rl_editing_mode. */
|
||||
printf (MINUS_O_FORMAT, "emacs", (rl_editing_mode == 1) ? on : off);
|
||||
printf (MINUS_O_FORMAT, "vi", (rl_editing_mode == 0) ? on : off);
|
||||
}
|
||||
#endif /* READLINE */
|
||||
|
||||
for (i = 0; o_options[i].name; i++)
|
||||
{
|
||||
int *on_or_off, zero = 0;
|
||||
|
||||
on_or_off = find_flag (o_options[i].letter);
|
||||
if (on_or_off == FLAG_UNKNOWN)
|
||||
on_or_off = &zero;
|
||||
printf (MINUS_O_FORMAT, o_options[i].name, (*on_or_off == 1) ? on : off);
|
||||
}
|
||||
}
|
||||
|
||||
set_minus_o_option (on_or_off, option_name)
|
||||
int on_or_off;
|
||||
char *option_name;
|
||||
{
|
||||
int option_char = -1;
|
||||
|
||||
if (STREQ (option_name, "noclobber"))
|
||||
{
|
||||
if (on_or_off == FLAG_ON)
|
||||
bind_variable ("noclobber", "");
|
||||
else
|
||||
unbind_variable ("noclobber");
|
||||
stupidly_hack_special_variables ("noclobber");
|
||||
}
|
||||
else if (STREQ (option_name, "ignoreeof"))
|
||||
{
|
||||
unbind_variable ("ignoreeof");
|
||||
unbind_variable ("IGNOREEOF");
|
||||
if (on_or_off == FLAG_ON)
|
||||
bind_variable ("IGNOREEOF", "10");
|
||||
stupidly_hack_special_variables ("IGNOREEOF");
|
||||
}
|
||||
|
||||
#if defined (READLINE)
|
||||
else if ((STREQ (option_name, "emacs")) || (STREQ (option_name, "vi")))
|
||||
{
|
||||
if (on_or_off == FLAG_ON)
|
||||
{
|
||||
rl_variable_bind ("editing-mode", option_name);
|
||||
|
||||
if (interactive)
|
||||
with_input_from_stdin ();
|
||||
no_line_editing = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int isemacs = (rl_editing_mode == 1);
|
||||
if ((isemacs && STREQ (option_name, "emacs")) ||
|
||||
(!isemacs && STREQ (option_name, "vi")))
|
||||
{
|
||||
if (interactive)
|
||||
with_input_from_stream (stdin, "stdin");
|
||||
no_line_editing = 1;
|
||||
}
|
||||
else
|
||||
builtin_error ("not in %s editing mode", option_name);
|
||||
}
|
||||
}
|
||||
#endif /* READLINE */
|
||||
else if (STREQ (option_name, "interactive-comments"))
|
||||
interactive_comments = (on_or_off == FLAG_ON);
|
||||
else if (STREQ (option_name, "posix"))
|
||||
{
|
||||
posixly_correct = (on_or_off == FLAG_ON);
|
||||
unbind_variable ("POSIXLY_CORRECT");
|
||||
unbind_variable ("POSIX_PEDANTIC");
|
||||
if (on_or_off == FLAG_ON)
|
||||
{
|
||||
bind_variable ("POSIXLY_CORRECT", "");
|
||||
stupidly_hack_special_variables ("POSIXLY_CORRECT");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
register int i;
|
||||
for (i = 0; o_options[i].name; i++)
|
||||
{
|
||||
if (STREQ (option_name, o_options[i].name))
|
||||
{
|
||||
option_char = o_options[i].letter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (option_char == -1)
|
||||
{
|
||||
builtin_error ("%s: unknown option name", option_name);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
if (change_flag (option_char, on_or_off) == FLAG_ERROR)
|
||||
{
|
||||
bad_option (option_name);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
/* Set some flags from the word values in the input list. If LIST is empty,
|
||||
then print out the values of the variables instead. If LIST contains
|
||||
non-flags, then set $1 - $9 to the successive words of LIST. */
|
||||
set_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int on_or_off, flag_name, force_assignment = 0;
|
||||
|
||||
if (!list)
|
||||
{
|
||||
SHELL_VAR **vars;
|
||||
|
||||
vars = all_shell_variables ();
|
||||
if (vars)
|
||||
{
|
||||
print_var_list (vars);
|
||||
free (vars);
|
||||
}
|
||||
|
||||
vars = all_shell_functions ();
|
||||
if (vars)
|
||||
{
|
||||
print_var_list (vars);
|
||||
free (vars);
|
||||
}
|
||||
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
/* Check validity of flag arguments. */
|
||||
if (*list->word->word == '-' || *list->word->word == '+')
|
||||
{
|
||||
register char *arg;
|
||||
WORD_LIST *save_list = list;
|
||||
|
||||
while (list && (arg = list->word->word))
|
||||
{
|
||||
char c;
|
||||
|
||||
if (arg[0] != '-' && arg[0] != '+')
|
||||
break;
|
||||
|
||||
/* `-' or `--' signifies end of flag arguments. */
|
||||
if (arg[0] == '-' &&
|
||||
(!arg[1] || (arg[1] == '-' && !arg[2])))
|
||||
break;
|
||||
|
||||
while (c = *++arg)
|
||||
{
|
||||
if (find_flag (c) == FLAG_UNKNOWN && c != 'o')
|
||||
{
|
||||
char s[2];
|
||||
s[0] = c; s[1] = '\0';
|
||||
bad_option (s);
|
||||
if (c == '?')
|
||||
builtin_usage ();
|
||||
return (c == '?' ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
list = save_list;
|
||||
}
|
||||
|
||||
/* Do the set command. While the list consists of words starting with
|
||||
'-' or '+' treat them as flags, otherwise, start assigning them to
|
||||
$1 ... $n. */
|
||||
while (list)
|
||||
{
|
||||
char *string = list->word->word;
|
||||
|
||||
/* If the argument is `--' or `-' then signal the end of the list
|
||||
and remember the remaining arguments. */
|
||||
if (string[0] == '-' && (!string[1] || (string[1] == '-' && !string[2])))
|
||||
{
|
||||
list = list->next;
|
||||
|
||||
/* `set --' unsets the positional parameters. */
|
||||
if (string[1] == '-')
|
||||
force_assignment = 1;
|
||||
|
||||
/* Until told differently, the old shell behaviour of
|
||||
`set - [arg ...]' being equivalent to `set +xv [arg ...]'
|
||||
stands. Posix.2 says the behaviour is marked as obsolescent. */
|
||||
else
|
||||
{
|
||||
change_flag ('x', '+');
|
||||
change_flag ('v', '+');
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ((on_or_off = *string) &&
|
||||
(on_or_off == '-' || on_or_off == '+'))
|
||||
{
|
||||
int i = 1;
|
||||
while (flag_name = string[i++])
|
||||
{
|
||||
if (flag_name == '?')
|
||||
{
|
||||
builtin_usage ();
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
else if (flag_name == 'o') /* -+o option-name */
|
||||
{
|
||||
char *option_name;
|
||||
WORD_LIST *opt;
|
||||
|
||||
opt = list->next;
|
||||
|
||||
if (!opt)
|
||||
{
|
||||
list_minus_o_opts ();
|
||||
continue;
|
||||
}
|
||||
|
||||
option_name = opt->word->word;
|
||||
|
||||
if (!option_name || !*option_name || (*option_name == '-'))
|
||||
{
|
||||
list_minus_o_opts ();
|
||||
continue;
|
||||
}
|
||||
list = list->next; /* Skip over option name. */
|
||||
|
||||
if (set_minus_o_option (on_or_off, option_name) != EXECUTION_SUCCESS)
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (change_flag (flag_name, on_or_off) == FLAG_ERROR)
|
||||
{
|
||||
char opt[3];
|
||||
opt[0] = on_or_off;
|
||||
opt[1] = flag_name;
|
||||
opt[2] = '\0';
|
||||
bad_option (opt);
|
||||
builtin_usage ();
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
/* Assigning $1 ... $n */
|
||||
if (list || force_assignment)
|
||||
remember_args (list, 1);
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
$BUILTIN unset
|
||||
$FUNCTION unset_builtin
|
||||
$SHORT_DOC unset [-f] [-v] [name ...]
|
||||
For each NAME, remove the corresponding variable or function. Given
|
||||
the `-v', unset will only act on variables. Given the `-f' flag,
|
||||
unset will only act on functions. With neither flag, unset first
|
||||
tries to unset a variable, and if that fails, then tries to unset a
|
||||
function. Some variables (such as PATH and IFS) cannot be unset; also
|
||||
see readonly.
|
||||
$END
|
||||
|
||||
#define NEXT_VARIABLE() any_failed++; list = list->next; continue;
|
||||
|
||||
unset_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int unset_function, unset_variable, unset_array, opt, any_failed;
|
||||
char *name;
|
||||
|
||||
unset_function = unset_variable = unset_array = any_failed = 0;
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "fv")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'f':
|
||||
unset_function = 1;
|
||||
break;
|
||||
case 'v':
|
||||
unset_variable = 1;
|
||||
break;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
list = loptend;
|
||||
|
||||
if (unset_function && unset_variable)
|
||||
{
|
||||
builtin_error ("cannot simultaneously unset a function and a variable");
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
while (list)
|
||||
{
|
||||
SHELL_VAR *var;
|
||||
int tem;
|
||||
#if defined (ARRAY_VARS)
|
||||
char *t;
|
||||
#endif
|
||||
|
||||
name = list->word->word;
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
if (!unset_function && valid_array_reference (name))
|
||||
{
|
||||
t = strchr (name, '[');
|
||||
*t++ = '\0';
|
||||
unset_array++;
|
||||
}
|
||||
#endif
|
||||
|
||||
var = unset_function ? find_function (name) : find_variable (name);
|
||||
|
||||
if (var && !unset_function && non_unsettable_p (var))
|
||||
{
|
||||
builtin_error ("%s: cannot unset", name);
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
|
||||
/* Posix.2 says that unsetting readonly variables is an error. */
|
||||
if (var && readonly_p (var))
|
||||
{
|
||||
builtin_error ("%s: cannot unset: readonly %s",
|
||||
name, unset_function ? "function" : "variable");
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
|
||||
/* Unless the -f option is supplied, the name refers to a variable. */
|
||||
#if defined (ARRAY_VARS)
|
||||
if (var && unset_array)
|
||||
{
|
||||
if (array_p (var) == 0)
|
||||
{
|
||||
builtin_error ("%s: not an array variable", name);
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
else
|
||||
tem = unbind_array_element (var, t);
|
||||
}
|
||||
else
|
||||
#endif /* ARRAY_VARS */
|
||||
tem = makunbound (name, unset_function ? shell_functions : shell_variables);
|
||||
|
||||
/* This is what Posix.2 draft 11+ says. ``If neither -f nor -v
|
||||
is specified, the name refers to a variable; if a variable by
|
||||
that name does not exist, a function by that name, if any,
|
||||
shall be unset.'' */
|
||||
if ((tem == -1) && !unset_function && !unset_variable)
|
||||
tem = makunbound (name, shell_functions);
|
||||
|
||||
if (tem == -1)
|
||||
any_failed++;
|
||||
else if (!unset_function)
|
||||
stupidly_hack_special_variables (name);
|
||||
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
if (any_failed)
|
||||
return (EXECUTION_FAILURE);
|
||||
else
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/* unwind_prot.h - Macros and functions for hacking unwind protection. */
|
||||
|
||||
/* Copyright (C) 1993 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
Bash is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Bash; see the file COPYING. If not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
#if !defined (_UNWIND_PROT_H)
|
||||
#define _UNWIND_PROT_H
|
||||
|
||||
/* Run a function without interrupts. */
|
||||
extern void begin_unwind_frame ();
|
||||
extern void discard_unwind_frame ();
|
||||
extern void run_unwind_frame ();
|
||||
extern void add_unwind_protect ();
|
||||
extern void remove_unwind_protect ();
|
||||
extern void run_unwind_protects ();
|
||||
extern void unwind_protect_var ();
|
||||
|
||||
/* Define for people who like their code to look a certain way. */
|
||||
#define end_unwind_frame()
|
||||
|
||||
/* How to protect an integer. */
|
||||
#define unwind_protect_int(X) unwind_protect_var (&(X), (char *)(X), sizeof (int))
|
||||
|
||||
/* How to protect a pointer to a string. */
|
||||
#define unwind_protect_string(X) \
|
||||
unwind_protect_var ((int *)&(X), (X), sizeof (char *))
|
||||
|
||||
/* How to protect any old pointer. */
|
||||
#define unwind_protect_pointer(X) unwind_protect_string (X)
|
||||
|
||||
/* How to protect the contents of a jmp_buf. */
|
||||
#define unwind_protect_jmp_buf(X) \
|
||||
unwind_protect_var ((int *)(X), (char *)(X), sizeof (procenv_t))
|
||||
|
||||
#endif /* _UNWIND_PROT_H */
|
||||
@@ -1,494 +0,0 @@
|
||||
This document details the changes between this version, bash-4.3-alpha,
|
||||
and the previous version, bash-4.2-release.
|
||||
|
||||
1. Changes to Bash
|
||||
|
||||
a. Fixed several bugs concerning incomplete bracket expressions in filename
|
||||
generation (globbing) patterns.
|
||||
|
||||
b. Fixed a bug with single quotes and WORD in ${param op WORD} when running
|
||||
in Posix mode.
|
||||
|
||||
c. Fixed a bug that caused the pattern removal and pattern substitution word
|
||||
expansions and case statement word expansion to not match the empty string.
|
||||
|
||||
d. Fixed a bug that caused the tzset() function to not work after changing
|
||||
the TZ enviroment variable.
|
||||
|
||||
e. Fixed a bug that caused the RHS of an assignment statement to undergo
|
||||
word splitting when it contained an unquoted $@.
|
||||
|
||||
f. Fixed bugs that caused the shell to not react to a SIGINT sent while
|
||||
waiting for a child process to exit.
|
||||
|
||||
g. Bash doesn't try to run things in a signal handler context when it gets a
|
||||
signal (SIGINT/SIGHUP/etc) while reading input using readline but still
|
||||
be responsive to terminating signals.
|
||||
|
||||
h. Fixed a bug that caused bash to go into an infinite loop if a filename
|
||||
to be matched contained an invalid multibyte character.
|
||||
|
||||
i. Fixed a bug that caused PS4 to end up being truncated if it is longer
|
||||
than 128 bytes.
|
||||
|
||||
j. Fixed a bug that caused brace expansion to not skip over double-quoted
|
||||
command substitution.
|
||||
|
||||
k. System-specific updates for: DJGPP, HP/UX, Mac OS X
|
||||
|
||||
l. Fixed a bug in displaying commands that caused redirections to be associated
|
||||
with the wrong part of the command.
|
||||
|
||||
m. Fixed the coproc cleanup to unset the appropriate shell variables when a
|
||||
coproc terminates.
|
||||
|
||||
n. Fixed a bug that caused `fc' to dump core due to incorrect calculation of
|
||||
the last history entry.
|
||||
|
||||
o. Added workarounds for FreeBSD's implementation of faccessat/eaccess and
|
||||
`test -x'.
|
||||
|
||||
p. Fixed a bug that caused the shell to not match patterns containing
|
||||
control-A.
|
||||
|
||||
q. Fixed a bug that could result in doubled error messages when the `printf'
|
||||
builtin got a write error.
|
||||
|
||||
r. Fixed a bug that caused the shell to not correctly expand words containing
|
||||
multiple consecutive quoted empty strings (""""""aa).
|
||||
|
||||
s. Fixed a bug that caused the shell to not correctly parse multi-line
|
||||
process substitutions containing comments and quoted strings.
|
||||
|
||||
t. Fixed a problem with the bash malloc's internal idea of the top of the
|
||||
memory heap that resulted in incorrect decisions to try to reduce the
|
||||
break and give memory back to the kernel.
|
||||
|
||||
u. There are changes to the expansions peformed on compound array assignments,
|
||||
in an effort to make foo=( [ind1]=bar [ind2]=baz ) identical to
|
||||
foo[ind1]=bar foo[ind2]=baz.
|
||||
|
||||
v. Bash now reports an error if `read -a name' is used when `name' is an
|
||||
existing associative array.
|
||||
|
||||
w. Fixed a bug that allowed an attempted assignment to a readonly variable
|
||||
in an arithmetic expression to not return failure.
|
||||
|
||||
x. Fixed several bugs that caused completion functions to be invoked even when
|
||||
the cursor was before the first word in the command.
|
||||
|
||||
y. Fixed a bug that caused parsing a command substitution to overwrite the
|
||||
parsing state associated with the complete input line.
|
||||
|
||||
z. Fixed several bugs with the built-in snprintf replacement and field widths
|
||||
and floating point.
|
||||
|
||||
aa. Fixed a bug that caused incorrect offset calculations and input buffer
|
||||
corruption when reading files longer than 2^31 bytes.
|
||||
|
||||
bb. Fixed several bugs where bash performed arithmetic evaluation in contexts
|
||||
where evaluation is suppressed.
|
||||
|
||||
cc. Fixed a bug that caused bash to close FIFOs used for process substitution
|
||||
too early when a shell function was executing, but protect against using
|
||||
all file descriptors when the shell functions are invoked inside loops.
|
||||
|
||||
dd. Added checks for printable (and non-printable) multibyte characters for
|
||||
use in error messages.
|
||||
|
||||
ee. Fixed a bug that caused ^O (operate-and-get-next) to not work correctly
|
||||
at the end of the history list.
|
||||
|
||||
ff. Fixed a bug that caused command-oriented history to incorrectly combine
|
||||
here documents into one line.
|
||||
|
||||
gg. Fixed a bug that caused importing SHELLOPTS from the environment into a
|
||||
Posix-mode shell to print an error message and refuse to parse it.
|
||||
|
||||
hh. Fixed a bug that caused the shell to delete an extra history entry when
|
||||
using `history -s'.
|
||||
|
||||
ii. Fixed a bug that caused floating-point exceptions and overflow errors
|
||||
for the / and % arithmetic operators when using INTMAX_MIN and -1.
|
||||
|
||||
jj. Fixed a bug that caused parsing errors when reading an arithmetic for
|
||||
loop inside a command substitution.
|
||||
|
||||
kk. Fixed a bug that caused a readonly function to be unset when unset was
|
||||
called without the -f or -v option.
|
||||
|
||||
ll. Fixed several bugs in the code that quotes characters special to regular
|
||||
expressions when used in a quoted string on the RHS of the =~ operator
|
||||
to the [[ command.
|
||||
|
||||
mm. Fixed a bug that caused redirections to fail because the file descriptor
|
||||
limit was set to a value less than 10.
|
||||
|
||||
nn. Fixed a bug that caused the `read' builtin to execute code in a signal
|
||||
handler context if read timed out.
|
||||
|
||||
oo. Fixed a bug that caused extended globbing patterns to not match files
|
||||
beginning with `.' correctly when a `.' was explicitly supplied in the
|
||||
pattern.
|
||||
|
||||
pp. Fixed a bug that caused key sequences longer than two characters to not
|
||||
work when used with `bind -x'.
|
||||
|
||||
qq. Fixed a bug that resulted in redefined functions having the wrong source
|
||||
file names in BASH_SOURCE.
|
||||
|
||||
rr. Fixed a bug that caused the read builtin to assign null strings to variables
|
||||
when using `read -N', which caused core dumps when referenced
|
||||
|
||||
ss. Fixed a bug that caused `bash -m script' to not enable job control while
|
||||
running the script.
|
||||
|
||||
tt. Fixed a bug that caused `printf -v var' to dump core when used with the
|
||||
%b format code.
|
||||
|
||||
uu. Fixed a bug that caused the shell to exit with the wrong status if -e was
|
||||
active and the shell exited on a substitution error.
|
||||
|
||||
vv. Fixed a bug that caused the shell to seg fault if an array variable with
|
||||
the same name as an existing associative array was implicitly created by
|
||||
an assignment (declare a[n]=b).
|
||||
|
||||
ww. Fixed a bug that caused a redirection to misbehave if the number specified
|
||||
for a file descriptor overflows an intmax_t.
|
||||
|
||||
xx. Fixed several bugs with the handling of valid and invalid unicode character
|
||||
values when used with the \u and \U escape sequences to printf and $'...'.
|
||||
|
||||
yy. Fixed a bug that caused tildes to not be escaped in expanded filenames,
|
||||
making them subject to later expansion.
|
||||
|
||||
zz. When using the pattern substitution word expansion, bash now runs the
|
||||
replacement string through quote removal, since it allows quotes in that
|
||||
string to act as escape characters. This is not backwards compatible, so
|
||||
it can be disabled by setting the bash compatibility mode to 4.2.
|
||||
|
||||
aaa. Fixed the rest of the cases where the shell runs non-allowed code in a
|
||||
signal handler context.
|
||||
|
||||
bbb. Fixed a bug that caused spurious DEL characters (\177) to appear in
|
||||
double-quoted expansion where the RHS is evaluated to the empty string.
|
||||
|
||||
ccc. Fixed a bug that caused the use of the shell's internal random number
|
||||
generator for temporary file names to perturb the random number
|
||||
sequence.
|
||||
|
||||
ddd. Fixed several bugs that caused `declare -g' to not set the right global
|
||||
variables or to misbehave when declaring global indexed arrays.
|
||||
|
||||
eee. Fixed a logic bug that caused extended globbing in a multibyte locale to
|
||||
cause failures when using the pattern substititution word expansions.
|
||||
|
||||
fff. Fixed a bug that caused the `lastpipe' option to corrupt the file
|
||||
descriptor used to read the script.
|
||||
|
||||
ggg. Fixed a bug that causes the shell to delete DEL characters in the
|
||||
expanded value of variables used in the same quoted string as variables
|
||||
that expand to nothing.
|
||||
|
||||
hhh. Fixed a bug that caused the shell to assign the wrong value from an
|
||||
assignment like (( x=7 )) when `x' was an existing array variable.
|
||||
|
||||
iii. Fixed a bug that caused the shell to misbehave when generating sequences
|
||||
and the boundary values overflow an intmax_t.
|
||||
|
||||
jjj. Fixed a bug caused expansion errors if an expansion of "$@" appeared
|
||||
next to another expansion (e.g.. "${@}${x}").
|
||||
|
||||
kkk. Fixed a potential buffer overflow bug when performing /dev/fd expansion.
|
||||
|
||||
lll. Fixed a bug that resulted in an extra semicolon being added to compound
|
||||
assignments when they were added to the history list.
|
||||
|
||||
mmm. Fixed a bug that caused mapfile to read one extra line from the input.
|
||||
|
||||
nnn. Fixed a bug that caused the mail checking code to use uninitialized
|
||||
values.
|
||||
|
||||
ooo. Fixed a bug that prevented history timestamps from being saved if the
|
||||
history comment character is unset.
|
||||
|
||||
ppp. Fixed a bug that caused the case-modifying expansions to not work with
|
||||
multibyte characters.
|
||||
|
||||
qqq. Fixed a bug that caused the edit-and-execute bindable readline command
|
||||
to see the wrong data if invoked in the middle of a multi-line quoted
|
||||
string.
|
||||
|
||||
rrr. Fixed a bug that resulted in the shell returning the wrong exit status
|
||||
for a background command on systems that recycle PIDs very quickly.
|
||||
|
||||
sss. Fixed a bug that caused asynchronous group commands to not run any EXIT
|
||||
trap defined in the body of the command.
|
||||
|
||||
ttt. Fixed a bug that caused `eval "... ; return"' to not clean up properly.
|
||||
|
||||
uuu. Fixed a bug that caused the shell to dump core if `read' reads an escaped
|
||||
IFS whitespace character.
|
||||
|
||||
vvv. Fixed a bug that caused BASH_COMMAND to be set to an incorrect value when
|
||||
executing a (...) subshell.
|
||||
|
||||
www. Fixed a pointer aliasing bug with the token string in arithmetic
|
||||
evaluation.
|
||||
|
||||
xxx. Fixed a bug with parsing multi-line command substitutions when reading
|
||||
the `do' keyword followed by whitespace.
|
||||
|
||||
yyy. Fixed a bug that caused the shell to seg fault if the time given to the
|
||||
printf %(...)T format overflowed the value accepted by localtime(3).
|
||||
|
||||
zzz. Fixed a problem with displaying help topics in two columns when the
|
||||
translated text contained multibyte characters.
|
||||
|
||||
aaaa. Fixed a bug with the extended globbing pattern matcher where a `*' was
|
||||
followed by a negated extended glob pattern.
|
||||
|
||||
bbbb. Fixed a race condition with short-lived coproc creation and reaping that
|
||||
caused the child process to be reaped before the various coproc shell
|
||||
variables were initialized.
|
||||
|
||||
cccc. Fixed a bug where turning off `errexit' in command substitution subshells
|
||||
was not reflected in $SHELLOPTS.
|
||||
|
||||
dddd. Partially fixed an inconsistency in how the shell treated shell
|
||||
functions run from an EXIT trap.
|
||||
|
||||
eeee. Fixed a bug in how the shell invalidated FIFOs used for process
|
||||
substitution when executing a pipeline (once rather than in every child).
|
||||
|
||||
ffff. Fixed a bug that occurred when expanding a special variable ($@, $*)
|
||||
within double quotes and the expansion resulted in an empty string.
|
||||
|
||||
gggg. Fixed bugs with executing a SIGCHLD trap handler to make sure that it's
|
||||
executed once per exited child.
|
||||
|
||||
hhhh. Fixed a bug that caused `declare' and `test' to find variables that
|
||||
had been given attributes but not assigned values. Such variables are
|
||||
not set.
|
||||
|
||||
iiii. Fixed a bug that caused commands in process substitutions to not look in
|
||||
the local temporary environment when performing word expansions.
|
||||
|
||||
jjjj. Fixed several problems with globstar expansions (**/**) returning null
|
||||
filenames and multiple instances of the same pathname.
|
||||
|
||||
kkkk. Fixed an oversight that did not allow the exit status of `coproc' to
|
||||
be inverted using `!'.
|
||||
|
||||
llll. Fixed a bug that caused the -e option to be re-enabled using `set -e'
|
||||
even when executing in a context where -e is ignored.
|
||||
|
||||
mmmm. Fixed a (mostly theoretical) bug with input lines longer than SIZE_MAX.
|
||||
|
||||
2. Changes to Readline
|
||||
|
||||
a. Fixed a bug that did not allow the `dd', `cc', or `yy' vi editing mode
|
||||
commands to work on the entire line.
|
||||
|
||||
b. Fixed a bug that caused redisplay problems with prompts longer than 128
|
||||
characters and history searches.
|
||||
|
||||
c. Fixed a bug that caused readline to try and run code to modify its idea
|
||||
of the screen size in a signal handler context upon receiving a SIGWINCH.
|
||||
|
||||
d. Fixed a bug that caused the `meta' key to be enabled beyond the duration
|
||||
of an individual call top readline().
|
||||
|
||||
e. Added a workaround for a wcwidth bug in Mac OS X that caused readline's
|
||||
redisplay to mishandle zero-width combining characters.
|
||||
|
||||
f. Fixed a bug that caused readline to `forget' part of a key sequence when
|
||||
a multiple-key sequence caused it to break out of an incremental search.
|
||||
|
||||
g. Fixed bugs that caused readline to execute code in a signal handler
|
||||
context if interrupted while reading from the file system during completion.
|
||||
|
||||
h. Fixed a bug that caused readline to `forget' part of a key sequence when
|
||||
reading an unbound multi-character key sequence.
|
||||
|
||||
i. Fixed a bug that caused Readline's signal handlers to be installed beyond
|
||||
the bounds of a single call to readline().
|
||||
|
||||
j. Fixed a bug that caused the `.' command to not redo the most recent `R'
|
||||
command in vi mode.
|
||||
|
||||
k. Fixed a bug that caused ignoring case in completion matches to result in
|
||||
readline using the wrong match.
|
||||
|
||||
l. Paren matching now works in vi insert mode.
|
||||
|
||||
m. Fix menu-completion to make show-all-if-ambiguous and menu-complete-display-prefix
|
||||
work together.
|
||||
|
||||
n. Fixed a bug that didn't allow the `cc', `dd', or `yy' commands to be redone
|
||||
in vi editing mode.
|
||||
|
||||
o. Fixed a bug that caused the filename comparison code to not compare
|
||||
multibyte characters correctly when using case-sensitive or case-mapping
|
||||
comparisons.
|
||||
|
||||
p. Fixed the input reading loop to call the input hook function only when there
|
||||
is no terminal input available.
|
||||
|
||||
q. Fixed a bug that caused binding a macro to a multi-character key sequence
|
||||
where the sequence and macro value share a common prefix to not perform
|
||||
the macro replacement.
|
||||
|
||||
r. Fixed several redisplay errors with multibyte characters and prompts
|
||||
containing invisible characters when using horizontal scrolling.
|
||||
|
||||
3. New Features in Bash
|
||||
|
||||
a. The `helptopic' completion action now maps to all the help topics, not just
|
||||
the shell builtins.
|
||||
|
||||
b. The `help' builtin no longer does prefix substring matching, so `help read'
|
||||
does not match `readonly'.
|
||||
|
||||
c. The shell can be compiled to not display a message about processes that
|
||||
terminate due to SIGTERM.
|
||||
|
||||
d. Non-interactive shells now react to the setting of checkwinsize and set
|
||||
LINES and COLUMNS after a foreground job exits.
|
||||
|
||||
e. There is a new shell option, `globasciiranges', which, when set to on,
|
||||
forces globbing range comparisons to use character ordering as if they
|
||||
were run in the C locale.
|
||||
|
||||
f. There is a new shell option, `direxpand', which makes filename completion
|
||||
expand variables in directory names in the way bash-4.1 did.
|
||||
|
||||
g. In Posix mode, the `command' builtin does not change whether or not a
|
||||
builtin it shadows is treated as an assignment builtin.
|
||||
|
||||
h. The `return' and `exit' builtins accept negative exit status arguments.
|
||||
|
||||
i. The word completion code checks whether or not a filename containing a
|
||||
shell variable expands to a directory name and appends `/' to the word
|
||||
as appropriate. The same code expands shell variables in command names
|
||||
when performing command completion.
|
||||
|
||||
j. In Posix mode, it is now an error to attempt to define a shell function
|
||||
with the same name as a Posix special builtin.
|
||||
|
||||
k. When compiled for strict Posix conformance, history expansion is disabled
|
||||
by default.
|
||||
|
||||
l. The history expansion character (!) does not cause history expansion when
|
||||
followed by the closing quote in a double-quoted string.
|
||||
|
||||
m. `complete' and its siblings compgen/compopt now takes a new `-o noquote'
|
||||
option to inhibit quoting of the completions.
|
||||
|
||||
n. Setting HISTSIZE to a value less than zero causes the history list to be
|
||||
unlimited (setting it 0 zero disables the history list).
|
||||
|
||||
o. Setting HISTFILESIZE to a value less than zero causes the history file size
|
||||
to be unlimited (setting it to 0 causes the history file to be truncated
|
||||
to zero size).
|
||||
|
||||
p. The `read' builtin now skips NUL bytes in the input.
|
||||
|
||||
q. There is a new `bind -X' option to print all key sequences bound to Unix
|
||||
commands.
|
||||
|
||||
r. When in Posix mode, `read' is interruptible by a trapped signal. After
|
||||
running the trap handler, read returns 128+signal and throws away any
|
||||
partially-read input.
|
||||
|
||||
s. The command completion code skips whitespace and assignment statements
|
||||
before looking for the command name word to be completed.
|
||||
|
||||
t. The build process has a new mechanism for constructing separate help files
|
||||
that better reflects the current set of compilation options.
|
||||
|
||||
u. The -nt and -ot options to test now work with files with nanosecond
|
||||
timestamp resolution.
|
||||
|
||||
v. The shell saves the command history in any shell for which history is
|
||||
enabled and HISTFILE is set, not just interactive shells.
|
||||
|
||||
w. The shell has `nameref' variables and new -n(/+n) options to declare and
|
||||
unset to use them, and a `test -R' option to test for them.
|
||||
|
||||
x. The shell now allows assigning, referencing, and unsetting elements of
|
||||
indexed arrays using negative subscripts (a[-1]=2, echo ${a[-1]}) which
|
||||
count back from the last element of the array.
|
||||
|
||||
y. The {x}<word redirection feature now allows words like {array[ind]} and
|
||||
can use variables with special meanings to the shell (e.g., BASH_XTRACEFD).
|
||||
|
||||
z. There is a new CHILD_MAX special shell variable; its value controls the
|
||||
number of exited child statues the shell remembers.
|
||||
|
||||
aa. There is a new configuration option (--enable-direxpand-default) that
|
||||
causes the `direxpand' shell option to be enabled by default.
|
||||
|
||||
bb. Bash does not do anything special to ensure that the file descriptor
|
||||
assigned to X in {x}<foo remains open after the block containing it
|
||||
completes.
|
||||
|
||||
cc. The `wait' builtin has a new `-n' option to wait for the next child to
|
||||
change status.
|
||||
|
||||
dd. The `printf' %(...)T format specifier now uses the current time if no
|
||||
argument is supplied.
|
||||
|
||||
ee. There is a new variable, BASH_COMPAT, that controls the current shell
|
||||
compatibility level.
|
||||
|
||||
4. New Features in Readline
|
||||
|
||||
a. Readline is now more responsive to SIGHUP and other fatal signals when
|
||||
reading input from the terminal or performing word completion but no
|
||||
longer attempts to run any not-allowable functions from a signal handler
|
||||
context.
|
||||
|
||||
b. There are new bindable commands to search the history for the string of
|
||||
characters between the beginning of the line and the point
|
||||
(history-substring-search-forward, history-substring-search-backward)
|
||||
|
||||
c. Readline allows quoted strings as the values of variables when setting
|
||||
them with `set'. As a side effect, trailing spaces and tabs are ignored
|
||||
when setting a string variable's value.
|
||||
|
||||
d. The history library creates a backup of the history file when writing it
|
||||
and restores the backup on a write error.
|
||||
|
||||
e. New application-settable variable: rl_filename_stat_hook: a function called
|
||||
with a filename before using it in a call to stat(2). Bash uses it to
|
||||
expand shell variables so things like $HOME/Downloads have a slash
|
||||
appended.
|
||||
|
||||
f. New bindable function `print-last-kbd-macro', prints the most-recently-
|
||||
defined keyboard macro in a reusable format.
|
||||
|
||||
g. New user-settable variable `colored-stats', enables use of colored text
|
||||
to denote file types when displaying possible completions (colored analog
|
||||
of visible-stats).
|
||||
|
||||
h. New user-settable variable `keyseq-timout', acts as an inter-character
|
||||
timeout when reading input or incremental search strings.
|
||||
|
||||
i. New application-callable function: rl_clear_history. Clears the history list
|
||||
and frees all readline-associated private data.
|
||||
|
||||
j. New user-settable variable, show-mode-in-prompt, adds a characters to the
|
||||
beginning of the prompt indicating the current editing mode.
|
||||
|
||||
k. New application-settable variable: rl_input_available_hook; function to be
|
||||
called when readline detects there is data available on its input file
|
||||
descriptor.
|
||||
|
||||
l. Readline calls an application-set event hook (rl_event_hook) after it gets
|
||||
a signal while reading input (read returns -1/EINTR but readline does not
|
||||
handle the signal immediately) to allow the application to handle or
|
||||
otherwise note it.
|
||||
|
||||
m. If the user-settable variable `history-size' is set to a value less than
|
||||
0, the history list size is unlimited.
|
||||
@@ -1,96 +0,0 @@
|
||||
Introduction
|
||||
============
|
||||
|
||||
This is GNU Bash, version 4.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.0 and
|
||||
bash-4.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'.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
@@ -1,175 +0,0 @@
|
||||
/* common.h -- extern declarations for functions defined in common.c. */
|
||||
|
||||
/* Copyright (C) 1993-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/>.
|
||||
*/
|
||||
|
||||
#if !defined (__COMMON_H)
|
||||
# define __COMMON_H
|
||||
|
||||
#include "stdc.h"
|
||||
|
||||
#define ISOPTION(s, c) (s[0] == '-' && !s[2] && s[1] == c)
|
||||
|
||||
/* Flag values for parse_and_execute () */
|
||||
#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
|
||||
|
||||
/* 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 ./ */
|
||||
|
||||
/* 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
|
||||
|
||||
/* Functions from common.c */
|
||||
extern void builtin_error __P((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
|
||||
extern void builtin_warning __P((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
|
||||
extern void builtin_usage __P((void));
|
||||
extern void no_args __P((WORD_LIST *));
|
||||
extern int no_options __P((WORD_LIST *));
|
||||
|
||||
/* common error message functions */
|
||||
extern void sh_needarg __P((char *));
|
||||
extern void sh_neednumarg __P((char *));
|
||||
extern void sh_notfound __P((char *));
|
||||
extern void sh_invalidopt __P((char *));
|
||||
extern void sh_invalidoptname __P((char *));
|
||||
extern void sh_invalidid __P((char *));
|
||||
extern void sh_invalidnum __P((char *));
|
||||
extern void sh_invalidsig __P((char *));
|
||||
extern void sh_erange __P((char *, char *));
|
||||
extern void sh_badpid __P((char *));
|
||||
extern void sh_badjob __P((char *));
|
||||
extern void sh_readonly __P((const char *));
|
||||
extern void sh_nojobs __P((char *));
|
||||
extern void sh_restricted __P((char *));
|
||||
extern void sh_notbuiltin __P((char *));
|
||||
extern void sh_wrerror __P((void));
|
||||
extern void sh_ttyerror __P((int));
|
||||
extern int sh_chkwrite __P((int));
|
||||
|
||||
extern char **make_builtin_argv __P((WORD_LIST *, int *));
|
||||
extern void remember_args __P((WORD_LIST *, int));
|
||||
|
||||
extern int dollar_vars_changed __P((void));
|
||||
extern void set_dollar_vars_unchanged __P((void));
|
||||
extern void set_dollar_vars_changed __P((void));
|
||||
|
||||
extern int get_numeric_arg __P((WORD_LIST *, int, intmax_t *));
|
||||
extern int get_exitstat __P((WORD_LIST *));
|
||||
extern int read_octal __P((char *));
|
||||
|
||||
/* Keeps track of the current working directory. */
|
||||
extern char *the_current_working_directory;
|
||||
extern char *get_working_directory __P((char *));
|
||||
extern void set_working_directory __P((char *));
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
extern int get_job_by_name __P((const char *, int));
|
||||
extern int get_job_spec __P((WORD_LIST *));
|
||||
#endif
|
||||
extern int display_signal_list __P((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 __P((char *, int));
|
||||
extern sh_builtin_func_t *find_shell_builtin __P((char *));
|
||||
extern sh_builtin_func_t *builtin_address __P((char *));
|
||||
extern sh_builtin_func_t *find_special_builtin __P((char *));
|
||||
extern void initialize_shell_builtins __P((void));
|
||||
|
||||
/* Functions from exit.def */
|
||||
extern void bash_logout __P((void));
|
||||
|
||||
/* Functions from getopts.def */
|
||||
extern void getopts_reset __P((int));
|
||||
|
||||
/* Functions from set.def */
|
||||
extern int minus_o_option_value __P((char *));
|
||||
extern void list_minus_o_opts __P((int, int));
|
||||
extern char **get_minus_o_opts __P((void));
|
||||
extern int set_minus_o_option __P((int, char *));
|
||||
|
||||
extern void set_shellopts __P((void));
|
||||
extern void parse_shellopts __P((char *));
|
||||
extern void initialize_shell_options __P((int));
|
||||
|
||||
extern void reset_shell_options __P((void));
|
||||
|
||||
/* Functions from shopt.def */
|
||||
extern void reset_shopt_options __P((void));
|
||||
extern char **get_shopt_options __P((void));
|
||||
|
||||
extern int shopt_setopt __P((char *, int));
|
||||
extern int shopt_listopt __P((char *, int));
|
||||
|
||||
extern int set_login_shell __P((char *, int));
|
||||
|
||||
extern void set_bashopts __P((void));
|
||||
extern void parse_bashopts __P((char *));
|
||||
extern void initialize_bashopts __P((int));
|
||||
|
||||
/* Functions from type.def */
|
||||
extern int describe_command __P((char *, int));
|
||||
|
||||
/* Functions from setattr.def */
|
||||
extern int set_or_show_attributes __P((WORD_LIST *, int, int));
|
||||
extern int show_all_var_attributes __P((int, int));
|
||||
extern int show_var_attributes __P((SHELL_VAR *, int, int));
|
||||
extern int show_name_attributes __P((char *, int));
|
||||
extern void set_var_attribute __P((char *, int, int));
|
||||
|
||||
/* Functions from pushd.def */
|
||||
extern char *get_dirstack_from_string __P((char *));
|
||||
extern char *get_dirstack_element __P((intmax_t, int));
|
||||
extern void set_dirstack_element __P((intmax_t, int, char *));
|
||||
extern WORD_LIST *get_directory_stack __P((int));
|
||||
|
||||
/* Functions from evalstring.c */
|
||||
extern int parse_and_execute __P((char *, const char *, int));
|
||||
extern int evalstring __P((char *, const char *, int));
|
||||
extern void parse_and_execute_cleanup __P((void));
|
||||
extern int parse_string __P((char *, const char *, int, char **));
|
||||
|
||||
/* Functions from evalfile.c */
|
||||
extern int maybe_execute_file __P((const char *, int));
|
||||
extern int source_file __P((const char *, int));
|
||||
extern int fc_execute_file __P((const char *));
|
||||
|
||||
#endif /* !__COMMON_H */
|
||||
@@ -1,694 +0,0 @@
|
||||
This file is declare.def, from which is created declare.c.
|
||||
It implements the builtins "declare" and "local" in Bash.
|
||||
|
||||
Copyright (C) 1987-2012 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 declare.c
|
||||
|
||||
$BUILTIN declare
|
||||
$FUNCTION declare_builtin
|
||||
$SHORT_DOC declare [-aAfFgilnrtux] [-p] [name[=value] ...]
|
||||
Set variable values and attributes.
|
||||
|
||||
Declare variables and give them attributes. If no NAMEs are given,
|
||||
display the attributes and values of all variables.
|
||||
|
||||
Options:
|
||||
-f restrict action or display to function names and definitions
|
||||
-F restrict display to function names only (plus line number and
|
||||
source file when debugging)
|
||||
-g create global variables when used in a shell function; otherwise
|
||||
ignored
|
||||
-p display the attributes and value of each NAME
|
||||
|
||||
Options which set attributes:
|
||||
-a to make NAMEs indexed arrays (if supported)
|
||||
-A to make NAMEs associative arrays (if supported)
|
||||
-i to make NAMEs have the `integer' attribute
|
||||
-l to convert NAMEs to lower case on assignment
|
||||
-n make NAME a reference to the variable named by its value
|
||||
-r to make NAMEs readonly
|
||||
-t to make NAMEs have the `trace' attribute
|
||||
-u to convert NAMEs to upper case on assignment
|
||||
-x to make NAMEs export
|
||||
|
||||
Using `+' instead of `-' turns off the given attribute.
|
||||
|
||||
Variables with the integer attribute have arithmetic evaluation (see
|
||||
the `let' command) performed when the variable is assigned a value.
|
||||
|
||||
When used in a function, `declare' makes NAMEs local, as with the `local'
|
||||
command. The `-g' option suppresses this behavior.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is supplied or a variable
|
||||
assignment error occurs.
|
||||
$END
|
||||
|
||||
$BUILTIN typeset
|
||||
$FUNCTION declare_builtin
|
||||
$SHORT_DOC typeset [-aAfFgilrtux] [-p] name[=value] ...
|
||||
Set variable values and attributes.
|
||||
|
||||
Obsolete. See `help declare'.
|
||||
$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 "common.h"
|
||||
#include "builtext.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
extern int array_needs_making;
|
||||
extern int posixly_correct;
|
||||
|
||||
static int declare_internal __P((register WORD_LIST *, int));
|
||||
|
||||
/* Declare or change variable attributes. */
|
||||
int
|
||||
declare_builtin (list)
|
||||
register WORD_LIST *list;
|
||||
{
|
||||
return (declare_internal (list, 0));
|
||||
}
|
||||
|
||||
$BUILTIN local
|
||||
$FUNCTION local_builtin
|
||||
$SHORT_DOC local [option] name[=value] ...
|
||||
Define local variables.
|
||||
|
||||
Create a local variable called NAME, and give it VALUE. OPTION can
|
||||
be any option accepted by `declare'.
|
||||
|
||||
Local variables can only be used within a function; they are visible
|
||||
only to the function where they are defined and its children.
|
||||
|
||||
Exit Status:
|
||||
Returns success unless an invalid option is supplied, a variable
|
||||
assignment error occurs, or the shell is not executing a function.
|
||||
$END
|
||||
int
|
||||
local_builtin (list)
|
||||
register WORD_LIST *list;
|
||||
{
|
||||
if (variable_context)
|
||||
return (declare_internal (list, 1));
|
||||
else
|
||||
{
|
||||
builtin_error (_("can only be used in a function"));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
# define DECLARE_OPTS "+acfgilnprtuxAF"
|
||||
#else
|
||||
# define DECLARE_OPTS "+cfgilnprtuxF"
|
||||
#endif
|
||||
|
||||
/* The workhorse function. */
|
||||
static int
|
||||
declare_internal (list, local_var)
|
||||
register WORD_LIST *list;
|
||||
int local_var;
|
||||
{
|
||||
int flags_on, flags_off, *flags;
|
||||
int any_failed, assign_error, pflag, nodefs, opt, mkglobal, onref, offref;
|
||||
char *t, *subscript_start;
|
||||
SHELL_VAR *var, *refvar;
|
||||
FUNCTION_DEF *shell_fn;
|
||||
|
||||
flags_on = flags_off = any_failed = assign_error = pflag = nodefs = mkglobal = 0;
|
||||
refvar = (SHELL_VAR *)NULL;
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, DECLARE_OPTS)) != EOF)
|
||||
{
|
||||
flags = list_opttype == '+' ? &flags_off : &flags_on;
|
||||
|
||||
switch (opt)
|
||||
{
|
||||
case 'a':
|
||||
#if defined (ARRAY_VARS)
|
||||
*flags |= att_array;
|
||||
break;
|
||||
#else
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
#endif
|
||||
case 'A':
|
||||
#if defined (ARRAY_VARS)
|
||||
*flags |= att_assoc;
|
||||
break;
|
||||
#else
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
#endif
|
||||
case 'p':
|
||||
if (local_var == 0)
|
||||
pflag++;
|
||||
break;
|
||||
case 'F':
|
||||
nodefs++;
|
||||
*flags |= att_function;
|
||||
break;
|
||||
case 'f':
|
||||
*flags |= att_function;
|
||||
break;
|
||||
case 'g':
|
||||
if (flags == &flags_on)
|
||||
mkglobal = 1;
|
||||
break;
|
||||
case 'i':
|
||||
*flags |= att_integer;
|
||||
break;
|
||||
case 'n':
|
||||
*flags |= att_nameref;
|
||||
break;
|
||||
case 'r':
|
||||
*flags |= att_readonly;
|
||||
break;
|
||||
case 't':
|
||||
*flags |= att_trace;
|
||||
break;
|
||||
case 'x':
|
||||
*flags |= att_exported;
|
||||
array_needs_making = 1;
|
||||
break;
|
||||
#if defined (CASEMOD_ATTRS)
|
||||
# if defined (CASEMOD_CAPCASE)
|
||||
case 'c':
|
||||
*flags |= att_capcase;
|
||||
if (flags == &flags_on)
|
||||
flags_off |= att_uppercase|att_lowercase;
|
||||
break;
|
||||
# endif
|
||||
case 'l':
|
||||
*flags |= att_lowercase;
|
||||
if (flags == &flags_on)
|
||||
flags_off |= att_capcase|att_uppercase;
|
||||
break;
|
||||
case 'u':
|
||||
*flags |= att_uppercase;
|
||||
if (flags == &flags_on)
|
||||
flags_off |= att_capcase|att_lowercase;
|
||||
break;
|
||||
#endif /* CASEMOD_ATTRS */
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
|
||||
list = loptend;
|
||||
|
||||
/* If there are no more arguments left, then we just want to show
|
||||
some variables. */
|
||||
if (list == 0) /* declare -[aAfFirtx] */
|
||||
{
|
||||
/* Show local variables defined at this context level if this is
|
||||
the `local' builtin. */
|
||||
if (local_var)
|
||||
{
|
||||
register SHELL_VAR **vlist;
|
||||
register int i;
|
||||
|
||||
vlist = all_local_variables ();
|
||||
|
||||
if (vlist)
|
||||
{
|
||||
for (i = 0; vlist[i]; i++)
|
||||
print_assignment (vlist[i]);
|
||||
|
||||
free (vlist);
|
||||
}
|
||||
}
|
||||
else if (pflag && (flags_on == 0 || flags_on == att_function))
|
||||
show_all_var_attributes (flags_on == 0, nodefs);
|
||||
else if (flags_on == 0)
|
||||
return (set_builtin ((WORD_LIST *)NULL));
|
||||
else
|
||||
set_or_show_attributes ((WORD_LIST *)NULL, flags_on, nodefs);
|
||||
|
||||
return (sh_chkwrite (EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
if (pflag) /* declare -p [-aAfFirtx] name [name...] */
|
||||
{
|
||||
for (any_failed = 0; list; list = list->next)
|
||||
{
|
||||
pflag = show_name_attributes (list->word->word, nodefs);
|
||||
if (pflag)
|
||||
{
|
||||
sh_notfound (list->word->word);
|
||||
any_failed++;
|
||||
}
|
||||
}
|
||||
return (sh_chkwrite (any_failed ? EXECUTION_FAILURE : EXECUTION_SUCCESS));
|
||||
}
|
||||
|
||||
#define NEXT_VARIABLE() free (name); list = list->next; continue
|
||||
|
||||
/* There are arguments left, so we are making variables. */
|
||||
while (list) /* declare [-aAfFirx] name [name ...] */
|
||||
{
|
||||
char *value, *name;
|
||||
int offset, aflags;
|
||||
#if defined (ARRAY_VARS)
|
||||
int making_array_special, compound_array_assign, simple_array_assign;
|
||||
#endif
|
||||
|
||||
name = savestring (list->word->word);
|
||||
offset = assignment (name, 0);
|
||||
aflags = 0;
|
||||
|
||||
if (offset) /* declare [-aAfFirx] name=value */
|
||||
{
|
||||
name[offset] = '\0';
|
||||
value = name + offset + 1;
|
||||
if (name[offset - 1] == '+')
|
||||
{
|
||||
aflags |= ASS_APPEND;
|
||||
name[offset - 1] = '\0';
|
||||
}
|
||||
}
|
||||
else
|
||||
value = "";
|
||||
|
||||
/* Do some lexical error checking on the LHS and RHS of the assignment
|
||||
that is specific to nameref variables. */
|
||||
if (flags_on & att_nameref)
|
||||
{
|
||||
if (valid_array_reference (name))
|
||||
{
|
||||
builtin_error (_("%s: reference variable cannot be an array"), name);
|
||||
assign_error++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
else if (STREQ (name, value))
|
||||
{
|
||||
builtin_error (_("%s: nameref variable self references not allowed"), name);
|
||||
assign_error++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
compound_array_assign = simple_array_assign = 0;
|
||||
subscript_start = (char *)NULL;
|
||||
if (t = strchr (name, '[')) /* ] */
|
||||
{
|
||||
/* If offset != 0 we have already validated any array reference */
|
||||
if (offset == 0 && valid_array_reference (name) == 0)
|
||||
{
|
||||
sh_invalidid (name);
|
||||
assign_error++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
subscript_start = t;
|
||||
*t = '\0';
|
||||
making_array_special = 1;
|
||||
}
|
||||
else
|
||||
making_array_special = 0;
|
||||
#endif
|
||||
|
||||
/* If we're in posix mode or not looking for a shell function (since
|
||||
shell function names don't have to be valid identifiers when the
|
||||
shell's not in posix mode), check whether or not the argument is a
|
||||
valid, well-formed shell identifier. */
|
||||
if ((posixly_correct || (flags_on & att_function) == 0) && legal_identifier (name) == 0)
|
||||
{
|
||||
sh_invalidid (name);
|
||||
assign_error++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
|
||||
/* If VARIABLE_CONTEXT has a non-zero value, then we are executing
|
||||
inside of a function. This means we should make local variables,
|
||||
not global ones. */
|
||||
|
||||
/* XXX - this has consequences when we're making a local copy of a
|
||||
variable that was in the temporary environment. Watch out
|
||||
for this. */
|
||||
refvar = (SHELL_VAR *)NULL;
|
||||
if (variable_context && mkglobal == 0 && ((flags_on & att_function) == 0))
|
||||
{
|
||||
#if defined (ARRAY_VARS)
|
||||
if (flags_on & att_assoc)
|
||||
var = make_local_assoc_variable (name);
|
||||
else if ((flags_on & att_array) || making_array_special)
|
||||
var = make_local_array_variable (name, making_array_special);
|
||||
else
|
||||
#endif
|
||||
#if 0
|
||||
/* XXX - this doesn't work right yet. */
|
||||
/* See below for rationale for doing this. */
|
||||
if (flags_on & att_nameref)
|
||||
{
|
||||
/* See if we are trying to modify an existing nameref variable */
|
||||
var = find_variable_last_nameref (name);
|
||||
if (var && nameref_p (var) == 0)
|
||||
var = make_local_variable (name);
|
||||
}
|
||||
else if (flags_off & att_nameref)
|
||||
{
|
||||
var = (SHELL_VAR *)NULL;
|
||||
/* See if we are trying to modify an existing nameref variable */
|
||||
refvar = find_variable_last_nameref (name);
|
||||
if (refvar && nameref_p (refvar) == 0)
|
||||
refvar = 0;
|
||||
if (refvar)
|
||||
var = make_local_variable (nameref_cell (refvar));
|
||||
if (var == 0)
|
||||
var = make_local_variable (name);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
var = make_local_variable (name);
|
||||
if (var == 0)
|
||||
{
|
||||
any_failed++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
}
|
||||
else
|
||||
var = (SHELL_VAR *)NULL;
|
||||
|
||||
/* If we are declaring a function, then complain about it in some way.
|
||||
We don't let people make functions by saying `typeset -f foo=bar'. */
|
||||
|
||||
/* There should be a way, however, to let people look at a particular
|
||||
function definition by saying `typeset -f foo'. */
|
||||
|
||||
if (flags_on & att_function)
|
||||
{
|
||||
if (offset) /* declare -f [-rix] foo=bar */
|
||||
{
|
||||
builtin_error (_("cannot use `-f' to make functions"));
|
||||
free (name);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else /* declare -f [-rx] name [name...] */
|
||||
{
|
||||
var = find_function (name);
|
||||
|
||||
if (var)
|
||||
{
|
||||
if (readonly_p (var) && (flags_off & att_readonly))
|
||||
{
|
||||
builtin_error (_("%s: readonly function"), name);
|
||||
any_failed++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
|
||||
/* declare -[Ff] name [name...] */
|
||||
if (flags_on == att_function && flags_off == 0)
|
||||
{
|
||||
#if defined (DEBUGGER)
|
||||
if (nodefs && debugging_mode)
|
||||
{
|
||||
shell_fn = find_function_def (var->name);
|
||||
if (shell_fn)
|
||||
printf ("%s %d %s\n", var->name, shell_fn->line, shell_fn->source_file);
|
||||
else
|
||||
printf ("%s\n", var->name);
|
||||
}
|
||||
else
|
||||
#endif /* DEBUGGER */
|
||||
{
|
||||
t = nodefs ? var->name
|
||||
: named_function_string (name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL);
|
||||
printf ("%s\n", t);
|
||||
any_failed = sh_chkwrite (any_failed);
|
||||
}
|
||||
}
|
||||
else /* declare -[fF] -[rx] name [name...] */
|
||||
{
|
||||
VSETATTR (var, flags_on);
|
||||
VUNSETATTR (var, flags_off);
|
||||
}
|
||||
}
|
||||
else
|
||||
any_failed++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
}
|
||||
else /* declare -[aAirx] name [name...] */
|
||||
{
|
||||
/* Non-null if we just created or fetched a local variable. */
|
||||
/* Here's what ksh93 seems to do. If we are modifying an existing
|
||||
nameref variable, we don't follow the nameref chain past the last
|
||||
nameref, and we set the nameref variable's value so future
|
||||
references to that variable will return the value of the variable
|
||||
we're assigning right now. */
|
||||
if (var == 0 && (flags_on & att_nameref))
|
||||
{
|
||||
/* See if we are trying to modify an existing nameref variable */
|
||||
var = mkglobal ? find_global_variable_last_nameref (name) : find_variable_last_nameref (name);
|
||||
if (var && nameref_p (var) == 0)
|
||||
var = 0;
|
||||
}
|
||||
/* However, if we're turning off the nameref attribute on an existing
|
||||
nameref variable, we first follow the nameref chain to the end,
|
||||
modify the value of the variable this nameref variable references,
|
||||
*CHANGING ITS VALUE AS A SIDE EFFECT* then turn off the nameref
|
||||
flag *LEAVING THE NAMEREF VARIABLE'S VALUE UNCHANGED* */
|
||||
else if (var == 0 && (flags_off & att_nameref))
|
||||
{
|
||||
/* See if we are trying to modify an existing nameref variable */
|
||||
refvar = mkglobal ? find_global_variable_last_nameref (name) : find_variable_last_nameref (name);
|
||||
if (refvar && nameref_p (refvar) == 0)
|
||||
refvar = 0;
|
||||
if (refvar)
|
||||
var = mkglobal ? find_global_variable (nameref_cell (refvar)) : find_variable (nameref_cell (refvar));
|
||||
}
|
||||
|
||||
if (var == 0)
|
||||
var = mkglobal ? find_global_variable (name) : find_variable (name);
|
||||
|
||||
if (var == 0)
|
||||
{
|
||||
#if defined (ARRAY_VARS)
|
||||
if (flags_on & att_assoc)
|
||||
{
|
||||
var = make_new_assoc_variable (name);
|
||||
if (offset == 0)
|
||||
VSETATTR (var, att_invisible);
|
||||
}
|
||||
else if ((flags_on & att_array) || making_array_special)
|
||||
{
|
||||
var = make_new_array_variable (name);
|
||||
if (offset == 0)
|
||||
VSETATTR (var, att_invisible);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
if (offset)
|
||||
var = bind_variable (name, "", 0);
|
||||
else
|
||||
{
|
||||
var = bind_variable (name, (char *)NULL, 0);
|
||||
VSETATTR (var, att_invisible);
|
||||
}
|
||||
}
|
||||
/* Can't take an existing array variable and make it a nameref */
|
||||
else if ((array_p (var) || assoc_p (var)) && (flags_on & att_nameref))
|
||||
{
|
||||
builtin_error (_("%s: reference variable cannot be an array"), name);
|
||||
assign_error++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
|
||||
/* Cannot use declare +r to turn off readonly attribute. */
|
||||
if (readonly_p (var) && (flags_off & att_readonly))
|
||||
{
|
||||
sh_readonly (name);
|
||||
any_failed++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
|
||||
/* Cannot use declare to assign value to readonly or noassign
|
||||
variable. */
|
||||
if ((readonly_p (var) || noassign_p (var)) && offset)
|
||||
{
|
||||
if (readonly_p (var))
|
||||
sh_readonly (name);
|
||||
assign_error++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
if ((making_array_special || (flags_on & (att_array|att_assoc)) || array_p (var) || assoc_p (var)) && offset)
|
||||
{
|
||||
int vlen;
|
||||
vlen = STRLEN (value);
|
||||
|
||||
if (value[0] == '(' && value[vlen-1] == ')')
|
||||
compound_array_assign = 1;
|
||||
else
|
||||
simple_array_assign = 1;
|
||||
}
|
||||
|
||||
/* Cannot use declare +a name or declare +A name to remove an
|
||||
array variable. */
|
||||
if (((flags_off & att_array) && array_p (var)) || ((flags_off & att_assoc) && assoc_p (var)))
|
||||
{
|
||||
builtin_error (_("%s: cannot destroy array variables in this way"), name);
|
||||
any_failed++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
|
||||
if ((flags_on & att_array) && assoc_p (var))
|
||||
{
|
||||
builtin_error (_("%s: cannot convert associative to indexed array"), name);
|
||||
any_failed++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
if ((flags_on & att_assoc) && array_p (var))
|
||||
{
|
||||
builtin_error (_("%s: cannot convert indexed to associative array"), name);
|
||||
any_failed++;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
|
||||
/* declare -A name[[n]] makes name an associative array variable. */
|
||||
if (flags_on & att_assoc)
|
||||
{
|
||||
if (assoc_p (var) == 0)
|
||||
var = convert_var_to_assoc (var);
|
||||
}
|
||||
/* declare -a name[[n]] or declare name[n] makes name an indexed
|
||||
array variable. */
|
||||
else if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0 && assoc_p (var) == 0)
|
||||
var = convert_var_to_array (var);
|
||||
#endif /* ARRAY_VARS */
|
||||
|
||||
/* XXX - we note that we are turning on nameref attribute and defer
|
||||
setting it until the assignment has been made so we don't do an
|
||||
inadvertent nameref lookup. Might have to do the same thing for
|
||||
flags_off&att_nameref. */
|
||||
/* XXX - ksh93 makes it an error to set a readonly nameref variable
|
||||
using a single typeset command. */
|
||||
onref = (flags_on & att_nameref);
|
||||
flags_on &= ~att_nameref;
|
||||
if (array_p (var) || assoc_p (var)
|
||||
|| (offset && compound_array_assign)
|
||||
|| simple_array_assign)
|
||||
onref = 0; /* array variables may not be namerefs */
|
||||
|
||||
/* ksh93 seems to do this */
|
||||
offref = (flags_off & att_nameref);
|
||||
flags_off &= ~att_nameref;
|
||||
|
||||
VSETATTR (var, flags_on);
|
||||
VUNSETATTR (var, flags_off);
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
if (offset && compound_array_assign)
|
||||
assign_array_var_from_string (var, value, aflags);
|
||||
else if (simple_array_assign && subscript_start)
|
||||
{
|
||||
/* declare [-aA] name[N]=value */
|
||||
*subscript_start = '['; /* ] */
|
||||
var = assign_array_element (name, value, 0); /* XXX - not aflags */
|
||||
*subscript_start = '\0';
|
||||
if (var == 0) /* some kind of assignment error */
|
||||
{
|
||||
assign_error++;
|
||||
flags_on |= onref;
|
||||
flags_off |= offref;
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
}
|
||||
else if (simple_array_assign)
|
||||
{
|
||||
/* let bind_{array,assoc}_variable take care of this. */
|
||||
if (assoc_p (var))
|
||||
bind_assoc_variable (var, name, savestring ("0"), value, aflags);
|
||||
else
|
||||
bind_array_variable (name, 0, value, aflags);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
/* bind_variable_value duplicates the essential internals of
|
||||
bind_variable() */
|
||||
if (offset)
|
||||
bind_variable_value (var, value, aflags);
|
||||
|
||||
/* If we found this variable in the temporary environment, as with
|
||||
`var=value declare -x var', make sure it is treated identically
|
||||
to `var=value export var'. Do the same for `declare -r' and
|
||||
`readonly'. Preserve the attributes, except for att_tempvar. */
|
||||
/* XXX -- should this create a variable in the global scope, or
|
||||
modify the local variable flags? ksh93 has it modify the
|
||||
global scope.
|
||||
Need to handle case like in set_var_attribute where a temporary
|
||||
variable is in the same table as the function local vars. */
|
||||
if ((flags_on & (att_exported|att_readonly)) && tempvar_p (var))
|
||||
{
|
||||
SHELL_VAR *tv;
|
||||
char *tvalue;
|
||||
|
||||
tv = find_tempenv_variable (var->name);
|
||||
if (tv)
|
||||
{
|
||||
tvalue = var_isset (var) ? savestring (value_cell (var)) : savestring ("");
|
||||
tv = bind_variable (var->name, tvalue, 0);
|
||||
tv->attributes |= var->attributes & ~att_tempvar;
|
||||
if (tv->context > 0)
|
||||
VSETATTR (tv, att_propagate);
|
||||
free (tvalue);
|
||||
}
|
||||
VSETATTR (var, att_propagate);
|
||||
}
|
||||
}
|
||||
|
||||
/* Turn on nameref attribute we deferred above. */
|
||||
/* XXX - should we turn on the noassign attribute for consistency with
|
||||
ksh93 when we turn on the nameref attribute? */
|
||||
VSETATTR (var, onref);
|
||||
flags_on |= onref;
|
||||
VUNSETATTR (var, offref);
|
||||
flags_off |= offref;
|
||||
/* Yuck. ksh93 compatibility */
|
||||
if (refvar)
|
||||
VUNSETATTR (refvar, flags_off);
|
||||
|
||||
stupidly_hack_special_variables (name);
|
||||
|
||||
NEXT_VARIABLE ();
|
||||
}
|
||||
|
||||
return (assign_error ? EX_BADASSIGN
|
||||
: ((any_failed == 0) ? EXECUTION_SUCCESS
|
||||
: EXECUTION_FAILURE));
|
||||
}
|
||||
@@ -1,348 +0,0 @@
|
||||
/* evalfile.c - read and evaluate commands from a file or file descriptor */
|
||||
|
||||
/* Copyright (C) 1996-2009 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 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 "../jobs.h"
|
||||
#include "../builtins.h"
|
||||
#include "../flags.h"
|
||||
#include "../input.h"
|
||||
#include "../execute_cmd.h"
|
||||
#include "../trap.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
|
||||
|
||||
extern int posixly_correct;
|
||||
extern int indirection_level, subshell_environment;
|
||||
extern int return_catch_flag, return_catch_value;
|
||||
extern int last_command_exit_value;
|
||||
extern int executing_command_builtin;
|
||||
|
||||
/* 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, *nfv, *bash_source_v, *bash_lineno_v;
|
||||
ARRAY *funcname_a, *bash_source_a, *bash_lineno_a;
|
||||
# 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))
|
||||
{
|
||||
file_error_and_exit:
|
||||
if (((flags & FEVAL_ENOENTOK) == 0) || errno != ENOENT)
|
||||
file_error (filename);
|
||||
|
||||
if (flags & FEVAL_LONGJMP)
|
||||
{
|
||||
last_command_exit_value = 1;
|
||||
jump_to_top_level (EXITPROG);
|
||||
}
|
||||
|
||||
return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE
|
||||
: ((errno == ENOENT) ? 0 : -1));
|
||||
}
|
||||
|
||||
errfunc = ((flags & FEVAL_BUILTIN) ? builtin_error : internal_error);
|
||||
|
||||
if (S_ISDIR (finfo.st_mode))
|
||||
{
|
||||
(*errfunc) (_("%s: is a directory"), filename);
|
||||
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);
|
||||
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);
|
||||
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 */
|
||||
# if defined (DEBUGGER)
|
||||
/* Have to figure out a better way to do this when `source' is supplied
|
||||
arguments */
|
||||
if ((flags & FEVAL_NOPUSHARGS) == 0)
|
||||
{
|
||||
array_push (bash_argv_a, (char *)filename);
|
||||
tt[0] = '1'; tt[1] = '\0';
|
||||
array_push (bash_argc_a, tt);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* set the flags to be passed to parse_and_execute */
|
||||
pflags = SEVAL_RESETLINE;
|
||||
pflags |= (flags & FEVAL_HISTORY) ? 0 : SEVAL_NOHIST;
|
||||
|
||||
if (flags & FEVAL_BUILTIN)
|
||||
result = EXECUTION_SUCCESS;
|
||||
|
||||
return_val = setjmp (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 ();
|
||||
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;
|
||||
return_catch_flag--;
|
||||
sourcelevel--;
|
||||
COPY_PROCENV (old_return_catch, return_catch);
|
||||
}
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
/* These two variables cannot be unset, and cannot be affected by the
|
||||
sourced file. */
|
||||
array_pop (bash_source_a);
|
||||
array_pop (bash_lineno_a);
|
||||
|
||||
/* FUNCNAME can be unset, and so can potentially be changed by the
|
||||
sourced file. */
|
||||
GET_ARRAY_FROM_VAR ("FUNCNAME", nfv, funcname_a);
|
||||
if (nfv == funcname_v)
|
||||
array_pop (funcname_a);
|
||||
# if defined (DEBUGGER)
|
||||
if ((flags & FEVAL_NOPUSHARGS) == 0)
|
||||
{
|
||||
array_pop (bash_argc_a);
|
||||
array_pop (bash_argv_a);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#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. */
|
||||
flags = FEVAL_ENOENTOK|FEVAL_HISTORY|FEVAL_REGFILE;
|
||||
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;
|
||||
}
|
||||
@@ -1,604 +0,0 @@
|
||||
/* evalstring.c - evaluate a string as one or more shell commands. */
|
||||
|
||||
/* Copyright (C) 1996-2012 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 "../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)
|
||||
|
||||
extern int indirection_level, subshell_environment;
|
||||
extern int line_number, line_number_for_err_trap;
|
||||
extern int current_token, shell_eof_token;
|
||||
extern int last_command_exit_value;
|
||||
extern int running_trap;
|
||||
extern int loop_level;
|
||||
extern int executing_list;
|
||||
extern int comsub_ignore_return;
|
||||
extern int posixly_correct;
|
||||
extern int return_catch_flag, return_catch_value;
|
||||
extern sh_builtin_func_t *this_shell_builtin;
|
||||
extern char *the_printed_command_except_trap;
|
||||
|
||||
int parse_and_execute_level = 0;
|
||||
|
||||
static int cat_file __P((REDIRECT *));
|
||||
|
||||
#define PE_TAG "parse_and_execute top"
|
||||
#define PS_TAG "parse_string top"
|
||||
|
||||
#if defined (HISTORY)
|
||||
static void
|
||||
set_history_remembering ()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/* How to force parse_and_execute () to clean up after itself. */
|
||||
void
|
||||
parse_and_execute_cleanup ()
|
||||
{
|
||||
if (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)
|
||||
if (interactive_shell)
|
||||
unwind_protect_int (history_expansion_inhibited);
|
||||
# endif /* BANG_HISTORY */
|
||||
#endif /* HISTORY */
|
||||
|
||||
if (interactive_shell)
|
||||
{
|
||||
x = get_current_prompt_level ();
|
||||
add_unwind_protect (set_current_prompt_level, x);
|
||||
}
|
||||
|
||||
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 (orig_string && ((flags & SEVAL_NOFREE) == 0))
|
||||
add_unwind_protect (xfree, orig_string);
|
||||
end_unwind_frame ();
|
||||
|
||||
if (flags & (SEVAL_NONINT|SEVAL_INTERACT))
|
||||
interactive = (flags & SEVAL_NONINT) ? 0 : 1;
|
||||
|
||||
#if defined (HISTORY)
|
||||
if (flags & SEVAL_NOHIST)
|
||||
bash_history_disable ();
|
||||
#endif /* HISTORY */
|
||||
}
|
||||
|
||||
/* Parse and execute the commands in STRING. Returns whatever
|
||||
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
|
||||
*/
|
||||
|
||||
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 (&pe_sigmask);
|
||||
sigprocmask (SIG_BLOCK, (sigset_t *)NULL, &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 (lreset == 0)
|
||||
line_number--;
|
||||
|
||||
indirection_level++;
|
||||
|
||||
code = should_jump_to_top_level = 0;
|
||||
last_result = EXECUTION_SUCCESS;
|
||||
|
||||
with_input_from_string (string, from_file);
|
||||
while (*(bash_input.location.string))
|
||||
{
|
||||
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.
|
||||
XXX - change that if we want the function context to be
|
||||
unwound. */
|
||||
if (exit_immediately_on_error && variable_context)
|
||||
{
|
||||
discard_unwind_frame ("pe_dispose");
|
||||
variable_context = 0; /* 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 DISCARD:
|
||||
if (command)
|
||||
run_unwind_frame ("pe_dispose");
|
||||
last_result = last_command_exit_value = EXECUTION_FAILURE; /* XXX */
|
||||
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, &pe_sigmask, (sigset_t *)NULL);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
default:
|
||||
command_error ("parse_and_execute", CMDERR_BADJUMP, code, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (parse_command () == 0)
|
||||
{
|
||||
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;
|
||||
|
||||
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
|
||||
* THEN
|
||||
* tell the execution code that we don't need to fork
|
||||
*/
|
||||
if (startup_state == 2 && parse_and_execute_level == 1 &&
|
||||
running_trap == 0 &&
|
||||
*bash_input.location.string == '\0' &&
|
||||
command->type == cm_simple &&
|
||||
signal_is_trapped (EXIT_TRAP) == 0 &&
|
||||
command->redirects == 0 && command->value.Simple->redirects == 0 &&
|
||||
((command->flags & CMD_TIME_PIPELINE) == 0) &&
|
||||
((command->flags & CMD_INVERT_RETURN) == 0))
|
||||
{
|
||||
command->flags |= CMD_NO_FORK;
|
||||
command->value.Simple->flags |= CMD_NO_FORK;
|
||||
}
|
||||
#endif /* ONESHOT */
|
||||
|
||||
/* See if this is a candidate for $( <file ). */
|
||||
if (startup_state == 2 &&
|
||||
(subshell_environment & SUBSHELL_COMSUB) &&
|
||||
*bash_input.location.string == '\0' &&
|
||||
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)
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
last_result = 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)
|
||||
{
|
||||
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 ();
|
||||
}
|
||||
|
||||
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, endp)
|
||||
char *string;
|
||||
const char *from_file;
|
||||
int flags;
|
||||
char **endp;
|
||||
{
|
||||
int code, nc;
|
||||
volatile int should_jump_to_top_level;
|
||||
COMMAND *volatile command, *oglobal;
|
||||
char *ostring;
|
||||
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 (&ps_sigmask);
|
||||
sigprocmask (SIG_BLOCK, (sigset_t *)NULL, &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);
|
||||
|
||||
code = should_jump_to_top_level = 0;
|
||||
oglobal = global_command;
|
||||
ostring = string;
|
||||
|
||||
with_input_from_string (string, from_file);
|
||||
while (*(bash_input.location.string))
|
||||
{
|
||||
command = (COMMAND *)NULL;
|
||||
|
||||
#if 0
|
||||
if (interrupt_state)
|
||||
break;
|
||||
#endif
|
||||
|
||||
/* Provide a location for functions which `longjmp (top_level)' to
|
||||
jump to. */
|
||||
code = setjmp_nosigs (top_level);
|
||||
|
||||
if (code)
|
||||
{
|
||||
#if defined (DEBUG)
|
||||
itrace("parse_string: longjmp executed: code = %d", code);
|
||||
#endif
|
||||
should_jump_to_top_level = 0;
|
||||
switch (code)
|
||||
{
|
||||
case FORCE_EOF:
|
||||
case ERREXIT:
|
||||
case EXITPROG:
|
||||
case DISCARD: /* XXX */
|
||||
if (command)
|
||||
dispose_command (command);
|
||||
/* Remember to call longjmp (top_level) after the old
|
||||
value for it is restored. */
|
||||
should_jump_to_top_level = 1;
|
||||
goto out;
|
||||
|
||||
default:
|
||||
#if defined (HAVE_POSIX_SIGNALS)
|
||||
sigprocmask (SIG_SETMASK, &ps_sigmask, (sigset_t *)NULL);
|
||||
#endif
|
||||
command_error ("parse_string", CMDERR_BADJUMP, code, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (parse_command () == 0)
|
||||
{
|
||||
dispose_command (global_command);
|
||||
global_command = (COMMAND *)NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((flags & SEVAL_NOLONGJMP) == 0)
|
||||
{
|
||||
should_jump_to_top_level = 1;
|
||||
code = DISCARD;
|
||||
}
|
||||
else
|
||||
reset_parser (); /* XXX - sets token_to_read */
|
||||
break;
|
||||
}
|
||||
|
||||
if (current_token == yacc_EOF || current_token == shell_eof_token)
|
||||
break;
|
||||
}
|
||||
|
||||
out:
|
||||
|
||||
global_command = oglobal;
|
||||
nc = bash_input.location.string - ostring;
|
||||
if (endp)
|
||||
*endp = bash_input.location.string;
|
||||
|
||||
run_unwind_frame (PS_TAG);
|
||||
|
||||
if (should_jump_to_top_level)
|
||||
jump_to_top_level (code);
|
||||
|
||||
return (nc);
|
||||
}
|
||||
|
||||
/* Handle a $( < file ) command substitution. This expands the filename,
|
||||
returning errors as appropriate, then just cats the file to the standard
|
||||
output. */
|
||||
static int
|
||||
cat_file (r)
|
||||
REDIRECT *r;
|
||||
{
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fd = open(fn, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
file_error (fn);
|
||||
free (fn);
|
||||
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;
|
||||
|
||||
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)
|
||||
{
|
||||
parse_and_execute_cleanup ();
|
||||
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;
|
||||
longjmp (return_catch, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return (r);
|
||||
}
|
||||
-1074
File diff suppressed because it is too large
Load Diff
@@ -1,783 +0,0 @@
|
||||
This file is shopt.def, from which is created shopt.c.
|
||||
It implements the Bash `shopt' builtin.
|
||||
|
||||
Copyright (C) 1994-2012 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 all shell options with an indication of whether or not each
|
||||
is set.
|
||||
|
||||
Options:
|
||||
-o restrict OPTNAMEs to those defined for use with `set -o'
|
||||
-p print each shell option with an indication of its status
|
||||
-q suppress output
|
||||
-s enable (set) each OPTNAME
|
||||
-u disable (unset) each OPTNAME
|
||||
|
||||
Exit Status:
|
||||
Returns success if OPTNAME is enabled; fails if an invalid option is
|
||||
given or OPTNAME is disabled.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#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 lastpipe_opt;
|
||||
|
||||
#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 __P((int));
|
||||
#endif
|
||||
|
||||
#if defined (PROGRAMMABLE_COMPLETION)
|
||||
extern int prog_completion_enabled;
|
||||
#endif
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
extern char *shell_name;
|
||||
#endif
|
||||
|
||||
#if defined (DEBUGGER)
|
||||
extern int debugging_mode;
|
||||
#endif
|
||||
|
||||
static void shopt_error __P((char *));
|
||||
|
||||
static int set_shellopts_after_change __P((char *, int));
|
||||
static int shopt_enable_hostname_completion __P((char *, int));
|
||||
static int set_compatibility_level __P((char *, int));
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
static int set_restricted_shell __P((char *, int));
|
||||
#endif
|
||||
|
||||
#if defined (READLINE)
|
||||
static int shopt_set_complete_direxpand __P((char *, int));
|
||||
#endif
|
||||
|
||||
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;
|
||||
|
||||
typedef int shopt_set_func_t __P((char *, int));
|
||||
|
||||
static struct {
|
||||
char *name;
|
||||
int *value;
|
||||
shopt_set_func_t *set_func;
|
||||
} shopt_vars[] = {
|
||||
{ "autocd", &autocd, (shopt_set_func_t *)NULL },
|
||||
{ "cdable_vars", &cdable_vars, (shopt_set_func_t *)NULL },
|
||||
{ "cdspell", &cdspelling, (shopt_set_func_t *)NULL },
|
||||
{ "checkhash", &check_hashed_filenames, (shopt_set_func_t *)NULL },
|
||||
#if defined (JOB_CONTROL)
|
||||
{ "checkjobs", &check_jobs_at_exit, (shopt_set_func_t *)NULL },
|
||||
#endif
|
||||
{ "checkwinsize", &check_window_size, (shopt_set_func_t *)NULL },
|
||||
#if defined (HISTORY)
|
||||
{ "cmdhist", &command_oriented_history, (shopt_set_func_t *)NULL },
|
||||
#endif
|
||||
{ "compat31", &shopt_compat31, set_compatibility_level },
|
||||
{ "compat32", &shopt_compat32, set_compatibility_level },
|
||||
{ "compat40", &shopt_compat40, set_compatibility_level },
|
||||
{ "compat41", &shopt_compat41, set_compatibility_level },
|
||||
{ "compat42", &shopt_compat41, 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", &expand_aliases, (shopt_set_func_t *)NULL },
|
||||
#if defined (DEBUGGER)
|
||||
{ "extdebug", &debugging_mode, (shopt_set_func_t *)NULL },
|
||||
#endif
|
||||
#if defined (EXTENDED_GLOB)
|
||||
{ "extglob", &extended_glob, (shopt_set_func_t *)NULL },
|
||||
#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
|
||||
{ "globstar", &glob_star, (shopt_set_func_t *)NULL },
|
||||
{ "globasciiranges", &glob_asciirange, (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 },
|
||||
{ "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
|
||||
{ "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 },
|
||||
{ "nullglob", &allow_null_glob_expansion, (shopt_set_func_t *)NULL },
|
||||
#if defined (PROGRAMMABLE_COMPLETION)
|
||||
{ "progcomp", &prog_completion_enabled, (shopt_set_func_t *)NULL },
|
||||
#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 },
|
||||
{ "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 __P((char *));
|
||||
static int toggle_shopts __P((int, WORD_LIST *, int));
|
||||
static void print_shopt __P((char *, int, int));
|
||||
static int list_shopts __P((WORD_LIST *, int));
|
||||
static int list_some_shopts __P((int, int));
|
||||
static int list_shopt_o_options __P((WORD_LIST *, int));
|
||||
static int list_some_o_options __P((int, int));
|
||||
static int set_shopt_o_options __P((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;
|
||||
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. */
|
||||
void
|
||||
reset_shopt_options ()
|
||||
{
|
||||
allow_null_glob_expansion = glob_dot_filenames = 0;
|
||||
cdable_vars = mail_warning = 0;
|
||||
no_exit_on_failed_exec = print_shift_error = 0;
|
||||
check_hashed_filenames = cdspelling = expand_aliases = check_window_size = 0;
|
||||
|
||||
source_uses_path = promptvars = 1;
|
||||
|
||||
#if defined (EXTENDED_GLOB)
|
||||
extended_glob = 0;
|
||||
#endif
|
||||
|
||||
#if defined (HISTORY)
|
||||
literal_history = force_append_history = 0;
|
||||
command_oriented_history = 1;
|
||||
#endif
|
||||
|
||||
#if defined (READLINE)
|
||||
hist_verify = history_reediting = 0;
|
||||
perform_hostname_completion = 1;
|
||||
#endif
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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_enable_hostname_completion (option_name, mode)
|
||||
char *option_name;
|
||||
int mode;
|
||||
{
|
||||
return (enable_hostname_completion (mode));
|
||||
}
|
||||
|
||||
static int
|
||||
set_compatibility_level (option_name, mode)
|
||||
char *option_name;
|
||||
int mode;
|
||||
{
|
||||
/* Need to change logic here as we add more compatibility levels or do
|
||||
this with a shell variable. */
|
||||
|
||||
/* First, check option_name so we can turn off other compat options when
|
||||
one is set. */
|
||||
if (mode && option_name[6] == '3')
|
||||
shopt_compat40 = shopt_compat41 = shopt_compat42 = 0;
|
||||
else if (mode && option_name[6] == '4')
|
||||
shopt_compat31 = shopt_compat32 = 0;
|
||||
|
||||
if (mode && option_name[6] == '3' && option_name[7] == '1')
|
||||
shopt_compat32 = 0;
|
||||
else if (mode && option_name[6] == '3' && option_name[7] == '2')
|
||||
shopt_compat31 = 0;
|
||||
else if (mode && option_name[6] == '4' && option_name[7] == '0')
|
||||
shopt_compat41 = shopt_compat42 = 0;
|
||||
else if (mode && option_name[6] == '4' && option_name[7] == '1')
|
||||
shopt_compat40 = shopt_compat42 = 0;
|
||||
else if (mode && option_name[6] == '4' && option_name[7] == '2')
|
||||
shopt_compat40 = shopt_compat41 = 0;
|
||||
|
||||
/* 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
|
||||
shell_compatibility_level = DEFAULT_COMPAT_LEVEL;
|
||||
|
||||
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 = shopt_compat40 = shopt_compat41 = shopt_compat42 = 0;
|
||||
switch (shell_compatibility_level)
|
||||
{
|
||||
case DEFAULT_COMPAT_LEVEL:
|
||||
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;
|
||||
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 ();
|
||||
}
|
||||
-390
@@ -1,390 +0,0 @@
|
||||
/* command.h -- The structures used internally to represent commands, and
|
||||
the extern declarations of the functions used to create them. */
|
||||
|
||||
/* Copyright (C) 1993-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/>.
|
||||
*/
|
||||
|
||||
#if !defined (_COMMAND_H_)
|
||||
#define _COMMAND_H_
|
||||
|
||||
#include "stdc.h"
|
||||
|
||||
/* Instructions describing what kind of thing to do for a redirection. */
|
||||
enum r_instruction {
|
||||
r_output_direction, r_input_direction, r_inputa_direction,
|
||||
r_appending_to, r_reading_until, r_reading_string,
|
||||
r_duplicating_input, r_duplicating_output, r_deblank_reading_until,
|
||||
r_close_this, r_err_and_out, r_input_output, r_output_force,
|
||||
r_duplicating_input_word, r_duplicating_output_word,
|
||||
r_move_input, r_move_output, r_move_input_word, r_move_output_word,
|
||||
r_append_err_and_out
|
||||
};
|
||||
|
||||
/* Redirection flags; values for rflags */
|
||||
#define REDIR_VARASSIGN 0x01
|
||||
|
||||
/* Redirection errors. */
|
||||
#define AMBIGUOUS_REDIRECT -1
|
||||
#define NOCLOBBER_REDIRECT -2
|
||||
#define RESTRICTED_REDIRECT -3 /* can only happen in restricted shells. */
|
||||
#define HEREDOC_REDIRECT -4 /* here-doc temp file can't be created */
|
||||
#define BADVAR_REDIRECT -5 /* something wrong with {varname}redir */
|
||||
|
||||
#define CLOBBERING_REDIRECT(ri) \
|
||||
(ri == r_output_direction || ri == r_err_and_out)
|
||||
|
||||
#define OUTPUT_REDIRECT(ri) \
|
||||
(ri == r_output_direction || ri == r_input_output || ri == r_err_and_out || ri == r_append_err_and_out)
|
||||
|
||||
#define INPUT_REDIRECT(ri) \
|
||||
(ri == r_input_direction || ri == r_inputa_direction || ri == r_input_output)
|
||||
|
||||
#define WRITE_REDIRECT(ri) \
|
||||
(ri == r_output_direction || \
|
||||
ri == r_input_output || \
|
||||
ri == r_err_and_out || \
|
||||
ri == r_appending_to || \
|
||||
ri == r_append_err_and_out || \
|
||||
ri == r_output_force)
|
||||
|
||||
/* redirection needs translation */
|
||||
#define TRANSLATE_REDIRECT(ri) \
|
||||
(ri == r_duplicating_input_word || ri == r_duplicating_output_word || \
|
||||
ri == r_move_input_word || ri == r_move_output_word)
|
||||
|
||||
/* Command Types: */
|
||||
enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple, cm_select,
|
||||
cm_connection, cm_function_def, cm_until, cm_group,
|
||||
cm_arith, cm_cond, cm_arith_for, cm_subshell, cm_coproc };
|
||||
|
||||
/* Possible values for the `flags' field of a WORD_DESC. */
|
||||
#define W_HASDOLLAR 0x000001 /* Dollar sign present. */
|
||||
#define W_QUOTED 0x000002 /* Some form of quote character is present. */
|
||||
#define W_ASSIGNMENT 0x000004 /* This word is a variable assignment. */
|
||||
#define W_GLOBEXP 0x000008 /* This word is the result of a glob expansion. */
|
||||
#define W_NOSPLIT 0x000010 /* Do not perform word splitting on this word because ifs is empty string. */
|
||||
#define W_NOGLOB 0x000020 /* Do not perform globbing on this word. */
|
||||
#define W_NOSPLIT2 0x000040 /* Don't split word except for $@ expansion (using spaces) because context does not allow it. */
|
||||
#define W_TILDEEXP 0x000080 /* Tilde expand this assignment word */
|
||||
#define W_DOLLARAT 0x000100 /* $@ and its special handling */
|
||||
#define W_DOLLARSTAR 0x000200 /* $* and its special handling */
|
||||
#define W_NOCOMSUB 0x000400 /* Don't perform command substitution on this word */
|
||||
#define W_ASSIGNRHS 0x000800 /* Word is rhs of an assignment statement */
|
||||
#define W_NOTILDE 0x001000 /* Don't perform tilde expansion on this word */
|
||||
#define W_ITILDE 0x002000 /* Internal flag for word expansion */
|
||||
#define W_NOEXPAND 0x004000 /* Don't expand at all -- do quote removal */
|
||||
#define W_COMPASSIGN 0x008000 /* Compound assignment */
|
||||
#define W_ASSNBLTIN 0x010000 /* word is a builtin command that takes assignments */
|
||||
#define W_ASSIGNARG 0x020000 /* word is assignment argument to command */
|
||||
#define W_HASQUOTEDNULL 0x040000 /* word contains a quoted null character */
|
||||
#define W_DQUOTE 0x080000 /* word should be treated as if double-quoted */
|
||||
#define W_NOPROCSUB 0x100000 /* don't perform process substitution */
|
||||
#define W_HASCTLESC 0x200000 /* word contains literal CTLESC characters */
|
||||
#define W_ASSIGNASSOC 0x400000 /* word looks like associative array assignment */
|
||||
#define W_ARRAYIND 0x800000 /* word is an array index being expanded */
|
||||
#define W_ASSNGLOBAL 0x1000000 /* word is a global assignment to declare (declare/typeset -g) */
|
||||
#define W_NOBRACE 0x2000000 /* Don't perform brace expansion */
|
||||
|
||||
/* Possible values for subshell_environment */
|
||||
#define SUBSHELL_ASYNC 0x01 /* subshell caused by `command &' */
|
||||
#define SUBSHELL_PAREN 0x02 /* subshell caused by ( ... ) */
|
||||
#define SUBSHELL_COMSUB 0x04 /* subshell caused by `command` or $(command) */
|
||||
#define SUBSHELL_FORK 0x08 /* subshell caused by executing a disk command */
|
||||
#define SUBSHELL_PIPE 0x10 /* subshell from a pipeline element */
|
||||
#define SUBSHELL_PROCSUB 0x20 /* subshell caused by <(command) or >(command) */
|
||||
#define SUBSHELL_COPROC 0x40 /* subshell from a coproc pipeline */
|
||||
#define SUBSHELL_RESETTRAP 0x80 /* subshell needs to reset trap strings on first call to trap */
|
||||
|
||||
/* A structure which represents a word. */
|
||||
typedef struct word_desc {
|
||||
char *word; /* Zero terminated string. */
|
||||
int flags; /* Flags associated with this word. */
|
||||
} WORD_DESC;
|
||||
|
||||
/* A linked list of words. */
|
||||
typedef struct word_list {
|
||||
struct word_list *next;
|
||||
WORD_DESC *word;
|
||||
} WORD_LIST;
|
||||
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* Shell Command Structs */
|
||||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
/* What a redirection descriptor looks like. If the redirection instruction
|
||||
is ri_duplicating_input or ri_duplicating_output, use DEST, otherwise
|
||||
use the file in FILENAME. Out-of-range descriptors are identified by a
|
||||
negative DEST. */
|
||||
|
||||
typedef union {
|
||||
int dest; /* Place to redirect REDIRECTOR to, or ... */
|
||||
WORD_DESC *filename; /* filename to redirect to. */
|
||||
} REDIRECTEE;
|
||||
|
||||
/* Structure describing a redirection. If REDIRECTOR is negative, the parser
|
||||
(or translator in redir.c) encountered an out-of-range file descriptor. */
|
||||
typedef struct redirect {
|
||||
struct redirect *next; /* Next element, or NULL. */
|
||||
REDIRECTEE redirector; /* Descriptor or varname to be redirected. */
|
||||
int rflags; /* Private flags for this redirection */
|
||||
int flags; /* Flag value for `open'. */
|
||||
enum r_instruction instruction; /* What to do with the information. */
|
||||
REDIRECTEE redirectee; /* File descriptor or filename */
|
||||
char *here_doc_eof; /* The word that appeared in <<foo. */
|
||||
} REDIRECT;
|
||||
|
||||
/* An element used in parsing. A single word or a single redirection.
|
||||
This is an ephemeral construct. */
|
||||
typedef struct element {
|
||||
WORD_DESC *word;
|
||||
REDIRECT *redirect;
|
||||
} ELEMENT;
|
||||
|
||||
/* Possible values for command->flags. */
|
||||
#define CMD_WANT_SUBSHELL 0x01 /* User wants a subshell: ( command ) */
|
||||
#define CMD_FORCE_SUBSHELL 0x02 /* Shell needs to force a subshell. */
|
||||
#define CMD_INVERT_RETURN 0x04 /* Invert the exit value. */
|
||||
#define CMD_IGNORE_RETURN 0x08 /* Ignore the exit value. For set -e. */
|
||||
#define CMD_NO_FUNCTIONS 0x10 /* Ignore functions during command lookup. */
|
||||
#define CMD_INHIBIT_EXPANSION 0x20 /* Do not expand the command words. */
|
||||
#define CMD_NO_FORK 0x40 /* Don't fork; just call execve */
|
||||
#define CMD_TIME_PIPELINE 0x80 /* Time a pipeline */
|
||||
#define CMD_TIME_POSIX 0x100 /* time -p; use POSIX.2 time output spec. */
|
||||
#define CMD_AMPERSAND 0x200 /* command & */
|
||||
#define CMD_STDIN_REDIR 0x400 /* async command needs implicit </dev/null */
|
||||
#define CMD_COMMAND_BUILTIN 0x0800 /* command executed by `command' builtin */
|
||||
#define CMD_COPROC_SUBSHELL 0x1000
|
||||
#define CMD_LASTPIPE 0x2000
|
||||
|
||||
/* What a command looks like. */
|
||||
typedef struct command {
|
||||
enum command_type type; /* FOR CASE WHILE IF CONNECTION or SIMPLE. */
|
||||
int flags; /* Flags controlling execution environment. */
|
||||
int line; /* line number the command starts on */
|
||||
REDIRECT *redirects; /* Special redirects for FOR CASE, etc. */
|
||||
union {
|
||||
struct for_com *For;
|
||||
struct case_com *Case;
|
||||
struct while_com *While;
|
||||
struct if_com *If;
|
||||
struct connection *Connection;
|
||||
struct simple_com *Simple;
|
||||
struct function_def *Function_def;
|
||||
struct group_com *Group;
|
||||
#if defined (SELECT_COMMAND)
|
||||
struct select_com *Select;
|
||||
#endif
|
||||
#if defined (DPAREN_ARITHMETIC)
|
||||
struct arith_com *Arith;
|
||||
#endif
|
||||
#if defined (COND_COMMAND)
|
||||
struct cond_com *Cond;
|
||||
#endif
|
||||
#if defined (ARITH_FOR_COMMAND)
|
||||
struct arith_for_com *ArithFor;
|
||||
#endif
|
||||
struct subshell_com *Subshell;
|
||||
struct coproc_com *Coproc;
|
||||
} value;
|
||||
} COMMAND;
|
||||
|
||||
/* Structure used to represent the CONNECTION type. */
|
||||
typedef struct connection {
|
||||
int ignore; /* Unused; simplifies make_command (). */
|
||||
COMMAND *first; /* Pointer to the first command. */
|
||||
COMMAND *second; /* Pointer to the second command. */
|
||||
int connector; /* What separates this command from others. */
|
||||
} CONNECTION;
|
||||
|
||||
/* Structures used to represent the CASE command. */
|
||||
|
||||
/* Values for FLAGS word in a PATTERN_LIST */
|
||||
#define CASEPAT_FALLTHROUGH 0x01
|
||||
#define CASEPAT_TESTNEXT 0x02
|
||||
|
||||
/* Pattern/action structure for CASE_COM. */
|
||||
typedef struct pattern_list {
|
||||
struct pattern_list *next; /* Clause to try in case this one failed. */
|
||||
WORD_LIST *patterns; /* Linked list of patterns to test. */
|
||||
COMMAND *action; /* Thing to execute if a pattern matches. */
|
||||
int flags;
|
||||
} PATTERN_LIST;
|
||||
|
||||
/* The CASE command. */
|
||||
typedef struct case_com {
|
||||
int flags; /* See description of CMD flags. */
|
||||
int line; /* line number the `case' keyword appears on */
|
||||
WORD_DESC *word; /* The thing to test. */
|
||||
PATTERN_LIST *clauses; /* The clauses to test against, or NULL. */
|
||||
} CASE_COM;
|
||||
|
||||
/* FOR command. */
|
||||
typedef struct for_com {
|
||||
int flags; /* See description of CMD flags. */
|
||||
int line; /* line number the `for' keyword appears on */
|
||||
WORD_DESC *name; /* The variable name to get mapped over. */
|
||||
WORD_LIST *map_list; /* The things to map over. This is never NULL. */
|
||||
COMMAND *action; /* The action to execute.
|
||||
During execution, NAME is bound to successive
|
||||
members of MAP_LIST. */
|
||||
} FOR_COM;
|
||||
|
||||
#if defined (ARITH_FOR_COMMAND)
|
||||
typedef struct arith_for_com {
|
||||
int flags;
|
||||
int line; /* generally used for error messages */
|
||||
WORD_LIST *init;
|
||||
WORD_LIST *test;
|
||||
WORD_LIST *step;
|
||||
COMMAND *action;
|
||||
} ARITH_FOR_COM;
|
||||
#endif
|
||||
|
||||
#if defined (SELECT_COMMAND)
|
||||
/* KSH SELECT command. */
|
||||
typedef struct select_com {
|
||||
int flags; /* See description of CMD flags. */
|
||||
int line; /* line number the `select' keyword appears on */
|
||||
WORD_DESC *name; /* The variable name to get mapped over. */
|
||||
WORD_LIST *map_list; /* The things to map over. This is never NULL. */
|
||||
COMMAND *action; /* The action to execute.
|
||||
During execution, NAME is bound to the member of
|
||||
MAP_LIST chosen by the user. */
|
||||
} SELECT_COM;
|
||||
#endif /* SELECT_COMMAND */
|
||||
|
||||
/* IF command. */
|
||||
typedef struct if_com {
|
||||
int flags; /* See description of CMD flags. */
|
||||
COMMAND *test; /* Thing to test. */
|
||||
COMMAND *true_case; /* What to do if the test returned non-zero. */
|
||||
COMMAND *false_case; /* What to do if the test returned zero. */
|
||||
} IF_COM;
|
||||
|
||||
/* WHILE command. */
|
||||
typedef struct while_com {
|
||||
int flags; /* See description of CMD flags. */
|
||||
COMMAND *test; /* Thing to test. */
|
||||
COMMAND *action; /* Thing to do while test is non-zero. */
|
||||
} WHILE_COM;
|
||||
|
||||
#if defined (DPAREN_ARITHMETIC)
|
||||
/* The arithmetic evaluation command, ((...)). Just a set of flags and
|
||||
a WORD_LIST, of which the first element is the only one used, for the
|
||||
time being. */
|
||||
typedef struct arith_com {
|
||||
int flags;
|
||||
int line;
|
||||
WORD_LIST *exp;
|
||||
} ARITH_COM;
|
||||
#endif /* DPAREN_ARITHMETIC */
|
||||
|
||||
/* The conditional command, [[...]]. This is a binary tree -- we slippped
|
||||
a recursive-descent parser into the YACC grammar to parse it. */
|
||||
#define COND_AND 1
|
||||
#define COND_OR 2
|
||||
#define COND_UNARY 3
|
||||
#define COND_BINARY 4
|
||||
#define COND_TERM 5
|
||||
#define COND_EXPR 6
|
||||
|
||||
typedef struct cond_com {
|
||||
int flags;
|
||||
int line;
|
||||
int type;
|
||||
WORD_DESC *op;
|
||||
struct cond_com *left, *right;
|
||||
} COND_COM;
|
||||
|
||||
/* The "simple" command. Just a collection of words and redirects. */
|
||||
typedef struct simple_com {
|
||||
int flags; /* See description of CMD flags. */
|
||||
int line; /* line number the command starts on */
|
||||
WORD_LIST *words; /* The program name, the arguments,
|
||||
variable assignments, etc. */
|
||||
REDIRECT *redirects; /* Redirections to perform. */
|
||||
} SIMPLE_COM;
|
||||
|
||||
/* The "function definition" command. */
|
||||
typedef struct function_def {
|
||||
int flags; /* See description of CMD flags. */
|
||||
int line; /* Line number the function def starts on. */
|
||||
WORD_DESC *name; /* The name of the function. */
|
||||
COMMAND *command; /* The parsed execution tree. */
|
||||
char *source_file; /* file in which function was defined, if any */
|
||||
} FUNCTION_DEF;
|
||||
|
||||
/* A command that is `grouped' allows pipes and redirections to affect all
|
||||
commands in the group. */
|
||||
typedef struct group_com {
|
||||
int ignore; /* See description of CMD flags. */
|
||||
COMMAND *command;
|
||||
} GROUP_COM;
|
||||
|
||||
typedef struct subshell_com {
|
||||
int flags;
|
||||
COMMAND *command;
|
||||
} SUBSHELL_COM;
|
||||
|
||||
#define COPROC_RUNNING 0x01
|
||||
#define COPROC_DEAD 0x02
|
||||
|
||||
typedef struct coproc {
|
||||
char *c_name;
|
||||
pid_t c_pid;
|
||||
int c_rfd;
|
||||
int c_wfd;
|
||||
int c_rsave;
|
||||
int c_wsave;
|
||||
int c_flags;
|
||||
int c_status;
|
||||
int c_lock;
|
||||
} Coproc;
|
||||
|
||||
typedef struct coproc_com {
|
||||
int flags;
|
||||
char *name;
|
||||
COMMAND *command;
|
||||
} COPROC_COM;
|
||||
|
||||
extern COMMAND *global_command;
|
||||
extern Coproc sh_coproc;
|
||||
|
||||
/* Possible command errors */
|
||||
#define CMDERR_DEFAULT 0
|
||||
#define CMDERR_BADTYPE 1
|
||||
#define CMDERR_BADCONN 2
|
||||
#define CMDERR_BADJUMP 3
|
||||
|
||||
#define CMDERR_LAST 3
|
||||
|
||||
/* Forward declarations of functions declared in copy_cmd.c. */
|
||||
|
||||
extern FUNCTION_DEF *copy_function_def_contents __P((FUNCTION_DEF *, FUNCTION_DEF *));
|
||||
extern FUNCTION_DEF *copy_function_def __P((FUNCTION_DEF *));
|
||||
|
||||
extern WORD_DESC *copy_word __P((WORD_DESC *));
|
||||
extern WORD_LIST *copy_word_list __P((WORD_LIST *));
|
||||
extern REDIRECT *copy_redirect __P((REDIRECT *));
|
||||
extern REDIRECT *copy_redirects __P((REDIRECT *));
|
||||
extern COMMAND *copy_command __P((COMMAND *));
|
||||
|
||||
#endif /* _COMMAND_H_ */
|
||||
-1194
File diff suppressed because it is too large
Load Diff
@@ -1,42 +0,0 @@
|
||||
# This file is a shell script that caches the results of configure
|
||||
# tests for CYGWIN32 so they don't need to be done when cross-compiling.
|
||||
|
||||
# AC_FUNC_GETPGRP should also define GETPGRP_VOID
|
||||
ac_cv_func_getpgrp_void=${ac_cv_func_getpgrp_void='yes'}
|
||||
# AC_FUNC_SETVBUF_REVERSED should not define anything else
|
||||
ac_cv_func_setvbuf_reversed=${ac_cv_func_setvbuf_reversed='no'}
|
||||
# on CYGWIN32, system calls do not restart
|
||||
ac_cv_sys_restartable_syscalls=${ac_cv_sys_restartable_syscalls='no'}
|
||||
bash_cv_sys_restartable_syscalls=${bash_cv_sys_restartable_syscalls='no'}
|
||||
|
||||
# these may be necessary, but they are currently commented out
|
||||
#ac_cv_c_bigendian=${ac_cv_c_bigendian='no'}
|
||||
ac_cv_sizeof_char_p=${ac_cv_sizeof_char_p='4'}
|
||||
ac_cv_sizeof_int=${ac_cv_sizeof_int='4'}
|
||||
ac_cv_sizeof_long=${ac_cv_sizeof_long='4'}
|
||||
ac_cv_sizeof_double=${ac_cv_sizeof_double='8'}
|
||||
|
||||
bash_cv_dup2_broken=${bash_cv_dup2_broken='no'}
|
||||
bash_cv_pgrp_pipe=${bash_cv_pgrp_pipe='no'}
|
||||
bash_cv_type_rlimit=${bash_cv_type_rlimit='long'}
|
||||
bash_cv_decl_under_sys_siglist=${bash_cv_decl_under_sys_siglist='no'}
|
||||
bash_cv_under_sys_siglist=${bash_cv_under_sys_siglist='no'}
|
||||
bash_cv_sys_siglist=${bash_cv_sys_siglist='no'}
|
||||
bash_cv_opendir_not_robust=${bash_cv_opendir_not_robust='no'}
|
||||
bash_cv_getenv_redef=${bash_cv_getenv_redef='yes'}
|
||||
bash_cv_printf_declared=${bash_cv_printf_declared='yes'}
|
||||
bash_cv_ulimit_maxfds=${bash_cv_ulimit_maxfds='no'}
|
||||
bash_cv_getcwd_calls_popen=${bash_cv_getcwd_calls_popen='no'}
|
||||
bash_cv_must_reinstall_sighandlers=${bash_cv_must_reinstall_sighandlers='no'}
|
||||
bash_cv_job_control_missing=${bash_cv_job_control_missing='present'}
|
||||
bash_cv_sys_named_pipes=${bash_cv_sys_named_pipes='missing'}
|
||||
bash_cv_func_sigsetjmp=${bash_cv_func_sigsetjmp='missing'}
|
||||
bash_cv_mail_dir=${bash_cv_mail_dir='unknown'}
|
||||
bash_cv_func_strcoll_broken=${bash_cv_func_strcoll_broken='no'}
|
||||
|
||||
bash_cv_type_int32_t=${bash_cv_type_int32_t='int'}
|
||||
bash_cv_type_u_int32_t=${bash_cv_type_u_int32_t='int'}
|
||||
|
||||
ac_cv_type_bits64_t=${ac_cv_type_bits64_t='no'}
|
||||
|
||||
# end of cross-build/cygwin32.cache
|
||||
-1745
File diff suppressed because it is too large
Load Diff
-10250
File diff suppressed because it is too large
Load Diff
-8651
File diff suppressed because it is too large
Load Diff
@@ -1,10 +0,0 @@
|
||||
@ignore
|
||||
Copyright (C) 1988-2012 Free Software Foundation, Inc.
|
||||
@end ignore
|
||||
|
||||
@set LASTCHANGE Sat Dec 15 17:49:50 EST 2012
|
||||
|
||||
@set EDITION 4.2
|
||||
@set VERSION 4.2
|
||||
@set UPDATED 15 December 2012
|
||||
@set UPDATED-MONTH December 2012
|
||||
@@ -1,288 +0,0 @@
|
||||
/* eval.c -- reading and evaluating commands. */
|
||||
|
||||
/* Copyright (C) 1996-2011 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 "bashansi.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "bashintl.h"
|
||||
|
||||
#include "shell.h"
|
||||
#include "flags.h"
|
||||
#include "trap.h"
|
||||
|
||||
#include "builtins/common.h"
|
||||
|
||||
#include "input.h"
|
||||
#include "execute_cmd.h"
|
||||
|
||||
#if defined (HISTORY)
|
||||
# include "bashhist.h"
|
||||
#endif
|
||||
|
||||
extern int EOF_reached;
|
||||
extern int indirection_level;
|
||||
extern int posixly_correct;
|
||||
extern int subshell_environment, running_under_emacs;
|
||||
extern int last_command_exit_value, stdin_redir;
|
||||
extern int need_here_doc;
|
||||
extern int current_command_number, current_command_line_count, line_number;
|
||||
extern int expand_aliases;
|
||||
extern sigset_t top_level_mask;
|
||||
|
||||
static void send_pwd_to_eterm __P((void));
|
||||
static sighandler alrm_catcher __P((int));
|
||||
|
||||
/* Read and execute commands until EOF is reached. This assumes that
|
||||
the input source has already been initialized. */
|
||||
int
|
||||
reader_loop ()
|
||||
{
|
||||
int our_indirection_level;
|
||||
COMMAND * volatile current_command;
|
||||
|
||||
USE_VAR(current_command);
|
||||
|
||||
current_command = (COMMAND *)NULL;
|
||||
|
||||
our_indirection_level = ++indirection_level;
|
||||
|
||||
while (EOF_Reached == 0)
|
||||
{
|
||||
int code;
|
||||
|
||||
code = setjmp_nosigs (top_level);
|
||||
|
||||
#if defined (PROCESS_SUBSTITUTION)
|
||||
unlink_fifo_list ();
|
||||
#endif /* PROCESS_SUBSTITUTION */
|
||||
|
||||
/* XXX - why do we set this every time through the loop? */
|
||||
if (interactive_shell && signal_is_ignored (SIGINT) == 0)
|
||||
set_signal_handler (SIGINT, sigint_sighandler);
|
||||
|
||||
if (code != NOT_JUMPED)
|
||||
{
|
||||
indirection_level = our_indirection_level;
|
||||
|
||||
switch (code)
|
||||
{
|
||||
/* Some kind of throw to top_level has occured. */
|
||||
case FORCE_EOF:
|
||||
case ERREXIT:
|
||||
case EXITPROG:
|
||||
current_command = (COMMAND *)NULL;
|
||||
if (exit_immediately_on_error)
|
||||
variable_context = 0; /* not in a function */
|
||||
EOF_Reached = EOF;
|
||||
goto exec_done;
|
||||
|
||||
case DISCARD:
|
||||
/* Make sure the exit status is reset to a non-zero value, but
|
||||
leave existing non-zero values (e.g., > 128 on signal)
|
||||
alone. */
|
||||
if (last_command_exit_value == 0)
|
||||
last_command_exit_value = EXECUTION_FAILURE;
|
||||
if (subshell_environment)
|
||||
{
|
||||
current_command = (COMMAND *)NULL;
|
||||
EOF_Reached = EOF;
|
||||
goto exec_done;
|
||||
}
|
||||
/* Obstack free command elements, etc. */
|
||||
if (current_command)
|
||||
{
|
||||
dispose_command (current_command);
|
||||
current_command = (COMMAND *)NULL;
|
||||
}
|
||||
#if defined (HAVE_POSIX_SIGNALS)
|
||||
sigprocmask (SIG_SETMASK, &top_level_mask, (sigset_t *)NULL);
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
command_error ("reader_loop", CMDERR_BADJUMP, code, 0);
|
||||
}
|
||||
}
|
||||
|
||||
executing = 0;
|
||||
if (temporary_env)
|
||||
dispose_used_env_vars ();
|
||||
|
||||
#if (defined (ultrix) && defined (mips)) || defined (C_ALLOCA)
|
||||
/* Attempt to reclaim memory allocated with alloca (). */
|
||||
(void) alloca (0);
|
||||
#endif
|
||||
|
||||
if (read_command () == 0)
|
||||
{
|
||||
if (interactive_shell == 0 && read_but_dont_execute)
|
||||
{
|
||||
last_command_exit_value = EXECUTION_SUCCESS;
|
||||
dispose_command (global_command);
|
||||
global_command = (COMMAND *)NULL;
|
||||
}
|
||||
else if (current_command = global_command)
|
||||
{
|
||||
global_command = (COMMAND *)NULL;
|
||||
current_command_number++;
|
||||
|
||||
executing = 1;
|
||||
stdin_redir = 0;
|
||||
execute_command (current_command);
|
||||
|
||||
exec_done:
|
||||
QUIT;
|
||||
|
||||
if (current_command)
|
||||
{
|
||||
dispose_command (current_command);
|
||||
current_command = (COMMAND *)NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Parse error, maybe discard rest of stream if not interactive. */
|
||||
if (interactive == 0)
|
||||
EOF_Reached = EOF;
|
||||
}
|
||||
if (just_one_command)
|
||||
EOF_Reached = EOF;
|
||||
}
|
||||
indirection_level--;
|
||||
return (last_command_exit_value);
|
||||
}
|
||||
|
||||
static sighandler
|
||||
alrm_catcher(i)
|
||||
int i;
|
||||
{
|
||||
printf (_("\007timed out waiting for input: auto-logout\n"));
|
||||
fflush (stdout);
|
||||
bash_logout (); /* run ~/.bash_logout if this is a login shell */
|
||||
jump_to_top_level (EXITPROG);
|
||||
SIGRETURN (0);
|
||||
}
|
||||
|
||||
/* Send an escape sequence to emacs term mode to tell it the
|
||||
current working directory. */
|
||||
static void
|
||||
send_pwd_to_eterm ()
|
||||
{
|
||||
char *pwd, *f;
|
||||
|
||||
f = 0;
|
||||
pwd = get_string_value ("PWD");
|
||||
if (pwd == 0)
|
||||
f = pwd = get_working_directory ("eterm");
|
||||
fprintf (stderr, "\032/%s\n", pwd);
|
||||
free (f);
|
||||
}
|
||||
|
||||
/* Call the YACC-generated parser and return the status of the parse.
|
||||
Input is read from the current input stream (bash_input). yyparse
|
||||
leaves the parsed command in the global variable GLOBAL_COMMAND.
|
||||
This is where PROMPT_COMMAND is executed. */
|
||||
int
|
||||
parse_command ()
|
||||
{
|
||||
int r;
|
||||
char *command_to_execute;
|
||||
|
||||
need_here_doc = 0;
|
||||
run_pending_traps ();
|
||||
|
||||
/* Allow the execution of a random command just before the printing
|
||||
of each primary prompt. If the shell variable PROMPT_COMMAND
|
||||
is set then the value of it is the command to execute. */
|
||||
if (interactive && bash_input.type != st_string)
|
||||
{
|
||||
command_to_execute = get_string_value ("PROMPT_COMMAND");
|
||||
if (command_to_execute)
|
||||
execute_variable_command (command_to_execute, "PROMPT_COMMAND");
|
||||
|
||||
if (running_under_emacs == 2)
|
||||
send_pwd_to_eterm (); /* Yuck */
|
||||
}
|
||||
|
||||
current_command_line_count = 0;
|
||||
r = yyparse ();
|
||||
|
||||
if (need_here_doc)
|
||||
gather_here_documents ();
|
||||
|
||||
return (r);
|
||||
}
|
||||
|
||||
/* Read and parse a command, returning the status of the parse. The command
|
||||
is left in the globval variable GLOBAL_COMMAND for use by reader_loop.
|
||||
This is where the shell timeout code is executed. */
|
||||
int
|
||||
read_command ()
|
||||
{
|
||||
SHELL_VAR *tmout_var;
|
||||
int tmout_len, result;
|
||||
SigHandler *old_alrm;
|
||||
|
||||
set_current_prompt_level (1);
|
||||
global_command = (COMMAND *)NULL;
|
||||
|
||||
/* Only do timeouts if interactive. */
|
||||
tmout_var = (SHELL_VAR *)NULL;
|
||||
tmout_len = 0;
|
||||
old_alrm = (SigHandler *)NULL;
|
||||
|
||||
if (interactive)
|
||||
{
|
||||
tmout_var = find_variable ("TMOUT");
|
||||
|
||||
if (tmout_var && var_isset (tmout_var))
|
||||
{
|
||||
tmout_len = atoi (value_cell (tmout_var));
|
||||
if (tmout_len > 0)
|
||||
{
|
||||
old_alrm = set_signal_handler (SIGALRM, alrm_catcher);
|
||||
alarm (tmout_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QUIT;
|
||||
|
||||
current_command_line_count = 0;
|
||||
result = parse_command ();
|
||||
|
||||
if (interactive && tmout_var && (tmout_len > 0))
|
||||
{
|
||||
alarm(0);
|
||||
set_signal_handler (SIGALRM, old_alrm);
|
||||
}
|
||||
|
||||
return (result);
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
#
|
||||
# Simple makefile for the sample loadable builtins
|
||||
#
|
||||
# Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
|
||||
# Include some boilerplate Gnu makefile definitions.
|
||||
prefix = @prefix@
|
||||
|
||||
exec_prefix = @exec_prefix@
|
||||
bindir = @bindir@
|
||||
libdir = @libdir@
|
||||
infodir = @infodir@
|
||||
includedir = @includedir@
|
||||
|
||||
topdir = @top_srcdir@
|
||||
BUILD_DIR = @BUILD_DIR@
|
||||
srcdir = @srcdir@
|
||||
VPATH = .:@srcdir@
|
||||
|
||||
@SET_MAKE@
|
||||
CC = @CC@
|
||||
RM = rm -f
|
||||
|
||||
SHELL = @MAKE_SHELL@
|
||||
|
||||
host_os = @host_os@
|
||||
host_cpu = @host_cpu@
|
||||
host_vendor = @host_vendor@
|
||||
|
||||
CFLAGS = @CFLAGS@
|
||||
LOCAL_CFLAGS = @LOCAL_CFLAGS@
|
||||
DEFS = @DEFS@
|
||||
LOCAL_DEFS = @LOCAL_DEFS@
|
||||
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
|
||||
BASHINCDIR = ${topdir}/include
|
||||
|
||||
LIBBUILD = ${BUILD_DIR}/lib
|
||||
|
||||
INTL_LIBSRC = ${topdir}/lib/intl
|
||||
INTL_BUILDDIR = ${LIBBUILD}/intl
|
||||
INTL_INC = @INTL_INC@
|
||||
LIBINTL_H = @LIBINTL_H@
|
||||
|
||||
CCFLAGS = $(DEFS) $(LOCAL_DEFS) $(LOCAL_CFLAGS) $(CFLAGS)
|
||||
|
||||
#
|
||||
# These values are generated for configure by ${topdir}/support/shobj-conf.
|
||||
# If your system is not supported by that script, but includes facilities for
|
||||
# dynamic loading of shared objects, please update the script and send the
|
||||
# changes to bash-maintainers@gnu.org.
|
||||
#
|
||||
SHOBJ_CC = @SHOBJ_CC@
|
||||
SHOBJ_CFLAGS = @SHOBJ_CFLAGS@
|
||||
SHOBJ_LD = @SHOBJ_LD@
|
||||
SHOBJ_LDFLAGS = @SHOBJ_LDFLAGS@
|
||||
SHOBJ_XLDFLAGS = @SHOBJ_XLDFLAGS@
|
||||
SHOBJ_LIBS = @SHOBJ_LIBS@
|
||||
SHOBJ_STATUS = @SHOBJ_STATUS@
|
||||
|
||||
INC = -I. -I.. -I$(topdir) -I$(topdir)/lib -I$(topdir)/builtins \
|
||||
-I$(BASHINCDIR) -I$(BUILD_DIR) -I$(LIBBUILD) \
|
||||
-I$(BUILD_DIR)/builtins $(INTL_INC)
|
||||
|
||||
.c.o:
|
||||
$(SHOBJ_CC) $(SHOBJ_CFLAGS) $(CCFLAGS) $(INC) -c -o $@ $<
|
||||
|
||||
|
||||
ALLPROG = print truefalse sleep pushd finfo logname basename dirname \
|
||||
tty pathchk tee head mkdir rmdir printenv id whoami \
|
||||
uname sync push ln unlink cut realpath getconf strftime
|
||||
OTHERPROG = necho hello cat
|
||||
|
||||
all: $(SHOBJ_STATUS)
|
||||
|
||||
supported: $(ALLPROG)
|
||||
others: $(OTHERPROG)
|
||||
|
||||
unsupported:
|
||||
@echo "Your system (${host_os}) is not supported by the"
|
||||
@echo "${topdir}/support/shobj-conf script."
|
||||
@echo "If your operating system provides facilities for dynamic"
|
||||
@echo "loading of shared objects using the dlopen(3) interface,"
|
||||
@echo "please update the script and re-run configure.
|
||||
@echo "Please send the changes you made to bash-maintainers@gnu.org"
|
||||
@echo "for inclusion in future bash releases."
|
||||
|
||||
everything: supported others
|
||||
|
||||
print: print.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ print.o $(SHOBJ_LIBS)
|
||||
|
||||
necho: necho.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ necho.o $(SHOBJ_LIBS)
|
||||
|
||||
getconf: getconf.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ getconf.o $(SHOBJ_LIBS)
|
||||
|
||||
hello: hello.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ hello.o $(SHOBJ_LIBS)
|
||||
|
||||
truefalse: truefalse.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ truefalse.o $(SHOBJ_LIBS)
|
||||
|
||||
sleep: sleep.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ sleep.o $(SHOBJ_LIBS)
|
||||
|
||||
finfo: finfo.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ finfo.o $(SHOBJ_LIBS)
|
||||
|
||||
cat: cat.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ cat.o $(SHOBJ_LIBS)
|
||||
|
||||
logname: logname.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ logname.o $(SHOBJ_LIBS)
|
||||
|
||||
basename: basename.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ basename.o $(SHOBJ_LIBS)
|
||||
|
||||
dirname: dirname.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ dirname.o $(SHOBJ_LIBS)
|
||||
|
||||
tty: tty.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ tty.o $(SHOBJ_LIBS)
|
||||
|
||||
pathchk: pathchk.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ pathchk.o $(SHOBJ_LIBS)
|
||||
|
||||
tee: tee.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ tee.o $(SHOBJ_LIBS)
|
||||
|
||||
mkdir: mkdir.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ mkdir.o $(SHOBJ_LIBS)
|
||||
|
||||
rmdir: rmdir.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ rmdir.o $(SHOBJ_LIBS)
|
||||
|
||||
head: head.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ head.o $(SHOBJ_LIBS)
|
||||
|
||||
printenv: printenv.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ printenv.o $(SHOBJ_LIBS)
|
||||
|
||||
id: id.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ id.o $(SHOBJ_LIBS)
|
||||
|
||||
whoami: whoami.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ whoami.o $(SHOBJ_LIBS)
|
||||
|
||||
uname: uname.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ uname.o $(SHOBJ_LIBS)
|
||||
|
||||
sync: sync.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ sync.o $(SHOBJ_LIBS)
|
||||
|
||||
push: push.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ push.o $(SHOBJ_LIBS)
|
||||
|
||||
ln: ln.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ ln.o $(SHOBJ_LIBS)
|
||||
|
||||
unlink: unlink.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ unlink.o $(SHOBJ_LIBS)
|
||||
|
||||
cut: cut.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ cut.o $(SHOBJ_LIBS)
|
||||
|
||||
realpath: realpath.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ realpath.o $(SHOBJ_LIBS)
|
||||
|
||||
strftime: strftime.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ strftime.o $(SHOBJ_LIBS)
|
||||
|
||||
# pushd is a special case. We use the same source that the builtin version
|
||||
# uses, with special compilation options.
|
||||
#
|
||||
pushd.c: ${topdir}/builtins/pushd.def
|
||||
$(RM) $@
|
||||
${BUILD_DIR}/builtins/mkbuiltins -D ${topdir}/builtins ${topdir}/builtins/pushd.def
|
||||
|
||||
pushd.o: pushd.c
|
||||
$(RM) $@
|
||||
$(SHOBJ_CC) -DHAVE_CONFIG_H -DPUSHD_AND_POPD -DLOADABLE_BUILTIN $(SHOBJ_CFLAGS) $(CFLAGS) $(CPPFLAGS) $(INC) -c -o $@ $<
|
||||
|
||||
pushd: pushd.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ pushd.o $(SHOBJ_LIBS)
|
||||
|
||||
clean:
|
||||
$(RM) $(ALLPROG) $(OTHERPROG) *.o
|
||||
-( cd perl && ${MAKE} ${MFLAGS} $@ )
|
||||
|
||||
mostlyclean: clean
|
||||
-( cd perl && ${MAKE} ${MFLAGS} $@ )
|
||||
|
||||
distclean maintainer-clean: clean
|
||||
$(RM) Makefile pushd.c
|
||||
-( cd perl && ${MAKE} ${MFLAGS} $@ )
|
||||
|
||||
print.o: print.c
|
||||
truefalse.o: truefalse.c
|
||||
sleep.o: sleep.c
|
||||
finfo.o: finfo.c
|
||||
logname.o: logname.c
|
||||
basename.o: basename.c
|
||||
dirname.o: dirname.c
|
||||
tty.o: tty.c
|
||||
pathchk.o: pathchk.c
|
||||
tee.o: tee.c
|
||||
head.o: head.c
|
||||
rmdir.o: rmdir.c
|
||||
necho.o: necho.c
|
||||
getconf.o: getconf.c
|
||||
hello.o: hello.c
|
||||
cat.o: cat.c
|
||||
printenv.o: printenv.c
|
||||
id.o: id.c
|
||||
whoami.o: whoami.c
|
||||
uname.o: uname.c
|
||||
sync.o: sync.c
|
||||
push.o: push.c
|
||||
mkdir.o: mkdir.c
|
||||
realpath.o: realpath.c
|
||||
strftime.o: strftime.c
|
||||
@@ -1,549 +0,0 @@
|
||||
#!/bin/bash
|
||||
# ash -- "Adventure shell"
|
||||
# last edit: 86/04/21 D A Gwyn
|
||||
# SCCS ID: @(#)ash.sh 1.4
|
||||
|
||||
OPATH=$PATH
|
||||
|
||||
ask()
|
||||
{
|
||||
echo -n "$@" '[y/n] '
|
||||
read ans
|
||||
|
||||
case "$ans" in
|
||||
y*|Y*)
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
CAT=${PAGER:-more}
|
||||
|
||||
ash_inst()
|
||||
{
|
||||
cat <<- EOF
|
||||
|
||||
Instructions for the Adventure shell
|
||||
|
||||
Welcome to the Adventure shell! In this exploration of the UNIX file
|
||||
system, I will act as your eyes and hands. As you move around, I will
|
||||
describe whatever is visible and will carry out your commands. The
|
||||
general form of a command is
|
||||
Verb Object Extra_stuff.
|
||||
Most commands pay no attention to the "Extra_stuff", and many do not
|
||||
need an "Object". A typical command is
|
||||
get all
|
||||
which picks up all files in the current "room" (directory). You can
|
||||
find out what you are carrying by typing the command
|
||||
inventory
|
||||
The command "help" results in a full description of all commands that I
|
||||
understand. To quit the Adventure shell, type
|
||||
quit
|
||||
|
||||
There are UNIX monsters lurking in the background. These are also
|
||||
known as "commands with arguments".
|
||||
|
||||
Good luck!
|
||||
EOF
|
||||
}
|
||||
|
||||
ash_help()
|
||||
{
|
||||
echo "I understand the following commands (synonyms in parentheses):"
|
||||
echo ""
|
||||
|
||||
echo "change OBJECT to NEW_NAME changes the name of the object"
|
||||
echo "clone OBJECT as NEW_NAME duplicates the object"
|
||||
echo "drop OBJECTS leaves the objects in the room"
|
||||
echo "enter (go) PASSAGE takes the labeled passage"
|
||||
echo "examine OBJECTS describes the objects in detail"
|
||||
echo "feed OBJECT to MONSTER stuffs the object into a UNIX monster"
|
||||
echo "get (take) OBJECTS picks up the specified objects"
|
||||
echo "gripe (bug) report a problem with the Adventure shell"
|
||||
echo "help prints this summary"
|
||||
echo "inventory (i) tells what you are carrying"
|
||||
echo "kill (destroy) OBJECTS destroys the objects"
|
||||
echo "look (l) describes the room, including hidden objects"
|
||||
echo "open (read) OBJECT shows the contents of an object"
|
||||
echo "quit (exit) leaves the Adventure shell"
|
||||
echo "resurrect OBJECTS attempts to restore dead objects"
|
||||
echo "steal OBJECT from MONSTER obtains the object from a UNIX monster"
|
||||
echo "throw OBJECT at daemon feeds the object to the printer daemon"
|
||||
echo "up takes the overhead passage"
|
||||
echo "wake MONSTER awakens a UNIX monster"
|
||||
echo "where (w) tells you where you are"
|
||||
echo "xyzzy moves you to your home"
|
||||
}
|
||||
|
||||
MAINT=chet@ins.cwru.edu
|
||||
|
||||
PATH=/usr/ucb:/bin:/usr/bin:/usr/local/bin:.
|
||||
export PATH
|
||||
|
||||
trap 'echo Ouch!' 2 3
|
||||
#trap '' 18 # disable Berkeley job control
|
||||
|
||||
ash_lk(){ echo " $1 " | fgrep " $2 " >&- 2>&-; }
|
||||
ash_pr(){ echo $* | tr ' ' '\012' | pr -5 -t -w75 -l$[ ( $# + 4 ) / 5 ]; }
|
||||
ash_rm(){ echo " $1 " | sed -e "s/ $2 / /" -e 's/^ //' -e 's/ $//'; }
|
||||
|
||||
# enable history, bang history expansion, and emacs editing
|
||||
set -o history
|
||||
set -o histexpand
|
||||
set -o emacs
|
||||
|
||||
cd
|
||||
LIM=.limbo # $HOME/$LIM contains "destroyed" objects
|
||||
mkdir $LIM >&- 2>&-
|
||||
KNAP=.knapsack # $HOME/$KNAP contains objects being "carried"
|
||||
if [ ! -d $KNAP ]
|
||||
then mkdir $KNAP >&- 2>&-
|
||||
if [ $? = 0 ]
|
||||
then echo 'You found a discarded empty knapsack.'
|
||||
else echo 'You have no knapsack to carry things in.'
|
||||
exit 1
|
||||
fi
|
||||
else echo 'One moment while I peek in your old knapsack...'
|
||||
fi
|
||||
|
||||
kn=`echo \`ls -a $KNAP | sed -e '/^\.$/d' -e '/^\.\.$/d'\``
|
||||
|
||||
if ask 'Welcome to the Adventure shell! Do you need instructions?'
|
||||
then
|
||||
ash_inst
|
||||
echo -n 'Type a newline to continue: '
|
||||
read
|
||||
fi
|
||||
|
||||
wiz=false
|
||||
cha=false
|
||||
prev=$LIM
|
||||
while :
|
||||
do room=`pwd`
|
||||
if [ $room != $prev ]
|
||||
then if [ $room = $HOME ]
|
||||
then echo 'You are in your own home.'
|
||||
else echo "You have entered $room."
|
||||
fi
|
||||
exs=
|
||||
obs=
|
||||
hexs=
|
||||
hobs=
|
||||
f=false
|
||||
for i in `ls -a`
|
||||
do case $i in
|
||||
.|..) ;;
|
||||
.*) if [ -f $i ]
|
||||
then hobs="$hobs $i"
|
||||
elif [ -d $i ]
|
||||
then hexs="$hexs $i"
|
||||
else f=true
|
||||
fi
|
||||
;;
|
||||
*) if [ -f $i ]
|
||||
then obs="$obs $i"
|
||||
elif [ -d $i ]
|
||||
then exs="$exs $i"
|
||||
else f=true
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [ "$obs" ]
|
||||
then echo 'This room contains:'
|
||||
ash_pr $obs
|
||||
else echo 'The room looks empty.'
|
||||
fi
|
||||
if [ "$exs" ]
|
||||
then echo 'There are exits labeled:'
|
||||
ash_pr $exs
|
||||
echo 'as well as a passage overhead.'
|
||||
else echo 'There is a passage overhead.'
|
||||
fi
|
||||
if sh -c $f
|
||||
then echo 'There are shadowy figures in the corner.'
|
||||
fi
|
||||
prev=$room
|
||||
fi
|
||||
|
||||
read -e -p '-advsh> ' verb obj x # prompt is '-advsh> '
|
||||
if [ $? != 0 ]
|
||||
then verb=quit # EOF
|
||||
fi
|
||||
|
||||
case $verb in
|
||||
change) if [ "$obj" ]
|
||||
then if ash_lk "$obs $hobs" "$obj"
|
||||
then set -- $x
|
||||
case "$1" in
|
||||
to) if [ "$2" ]
|
||||
then if [ -f $2 ]
|
||||
then echo "You must destroy $2 first."
|
||||
set --
|
||||
fi
|
||||
if [ "$2" ]
|
||||
then if mv $obj $2 >&- 2>&-
|
||||
then echo "The $obj shimmers and turns into $2."
|
||||
obs=`ash_rm "$2 $obs" "$obj"`
|
||||
else echo "There is a cloud of smoke but the $obj is unchanged."
|
||||
fi
|
||||
fi
|
||||
else echo 'To what?'
|
||||
fi
|
||||
;;
|
||||
*) echo "Change $obj to what?"
|
||||
;;
|
||||
esac
|
||||
else if ash_lk "$kn" "$obj"
|
||||
then echo 'You must drop it first.'
|
||||
else echo "I see no $obj here."
|
||||
fi
|
||||
fi
|
||||
else echo 'Change what?'
|
||||
fi
|
||||
;;
|
||||
clone) if [ "$obj" ]
|
||||
then if ash_lk "$obs $hobs" "$obj"
|
||||
then if [ ! -r $obj ]
|
||||
then echo "The $obj does not wish to be cloned."
|
||||
else set -- $x
|
||||
case "$1" in
|
||||
as) if [ "$2" ]
|
||||
then if [ -f $2 ]
|
||||
then echo "You must destroy $2 first."
|
||||
else if cp $obj $2 >&- 2>&-
|
||||
then echo "Poof! When the smoke clears, you see the new $2."
|
||||
obs="$obs $2"
|
||||
else echo 'You hear a dull thud but no clone appears.'
|
||||
fi
|
||||
fi
|
||||
else echo 'As what?'
|
||||
fi
|
||||
;;
|
||||
*) echo "Clone $obj as what?"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
else if ash_lk "$kn" "$obj"
|
||||
then echo 'You must drop it first.'
|
||||
else echo "I see no $obj here."
|
||||
fi
|
||||
fi
|
||||
else echo 'Clone what?'
|
||||
fi
|
||||
;;
|
||||
drop) if [ "$obj" ]
|
||||
then for it in $obj $x
|
||||
do if ash_lk "$kn" "$it"
|
||||
then if [ -w $it ]
|
||||
then echo "You must destroy $it first."
|
||||
else if mv $HOME/$KNAP/$it $it >&- 2>&-
|
||||
then echo "$it: dropped."
|
||||
kn=`ash_rm "$kn" "$it"`
|
||||
obs=`echo $it $obs`
|
||||
else echo "The $it is caught in your knapsack."
|
||||
fi
|
||||
fi
|
||||
else echo "You're not carrying the $it!"
|
||||
fi
|
||||
done
|
||||
else echo 'Drop what?'
|
||||
fi
|
||||
;;
|
||||
enter|go) if [ "$obj" ]
|
||||
then if [ $obj != up ]
|
||||
then if ash_lk "$exs $hexs" "$obj"
|
||||
then if [ -x $obj ]
|
||||
then if cd $obj
|
||||
then echo 'You squeeze through the passage.'
|
||||
else echo "You can't go that direction."
|
||||
fi
|
||||
else echo 'An invisible force blocks your way.'
|
||||
fi
|
||||
else echo 'I see no such passage.'
|
||||
fi
|
||||
else if cd ..
|
||||
then echo 'You struggle upwards.'
|
||||
else echo "You can't reach that high."
|
||||
fi
|
||||
fi
|
||||
else echo 'Which passage?'
|
||||
fi
|
||||
;;
|
||||
examine) if [ "$obj" ]
|
||||
then if [ $obj = all ]
|
||||
then $obj=`echo $obs $exs`
|
||||
x=
|
||||
fi
|
||||
for it in $obj $x
|
||||
do if ash_lk "$obs $hobs $exs $hexs" "$it"
|
||||
then echo "Upon close inspection of the $it, you see:"
|
||||
ls -ld $it 2>&-
|
||||
if [ $? != 0 ]
|
||||
then echo "-- when you look directly at the $it, it vanishes."
|
||||
fi
|
||||
else if ash_lk "$kn" "$it"
|
||||
then echo 'You must drop it first.'
|
||||
else echo "I see no $it here."
|
||||
fi
|
||||
fi
|
||||
done
|
||||
else echo 'Examine what?'
|
||||
fi
|
||||
;;
|
||||
feed) if [ "$obj" ]
|
||||
then if ash_lk "$obs $hobs" "$obj"
|
||||
then set -- $x
|
||||
case "$1" in
|
||||
to) if [ "$2" ]
|
||||
then shift
|
||||
if PATH=$OPATH $* <$obj 2>&-
|
||||
then echo "The $1 monster devours your $obj."
|
||||
if rm -f $obj >&- 2>&-
|
||||
then obs=`ash_rm "$obs" "$obj"`
|
||||
else echo 'But he spits it back up.'
|
||||
fi
|
||||
else echo "The $1 monster holds his nose in disdain."
|
||||
fi
|
||||
else echo 'To what?'
|
||||
fi
|
||||
;;
|
||||
*) echo "Feed $obj to what?"
|
||||
;;
|
||||
esac
|
||||
else if ash_lk "$kn" "$obj"
|
||||
then echo 'You must drop it first.'
|
||||
else echo "I see no $obj here."
|
||||
fi
|
||||
fi
|
||||
else echo 'Feed what?'
|
||||
fi
|
||||
;;
|
||||
get|take) if [ "$obj" ]
|
||||
then if [ $obj = all ]
|
||||
then obj="$obs"
|
||||
x=
|
||||
fi
|
||||
for it in $obj $x
|
||||
do if ash_lk "$obs $hobs" "$it"
|
||||
then if ash_lk "$kn" "$it"
|
||||
then echo 'You already have one.'
|
||||
else if mv $it $HOME/$KNAP/$it >&- 2>&-
|
||||
then echo "$it: taken."
|
||||
kn="$it $kn"
|
||||
obs=`ash_rm "$obs" "$it"`
|
||||
else echo "The $it is too heavy."
|
||||
fi
|
||||
fi
|
||||
else echo "I see no $it here."
|
||||
fi
|
||||
done
|
||||
else echo 'Get what?'
|
||||
fi
|
||||
;;
|
||||
gripe|bug) echo 'Please describe the problem and your situation at the time it failed.\nEnd the bug report with a line containing just a Ctrl-D.'
|
||||
cat | mail $MAINT -s 'ash bug'
|
||||
echo 'Thank you!'
|
||||
;;
|
||||
help) ash_help
|
||||
;;
|
||||
inventory|i) if [ "$kn" ]
|
||||
then echo 'Your knapsack contains:'
|
||||
ash_pr $kn
|
||||
else echo 'You are poverty-stricken.'
|
||||
fi
|
||||
;;
|
||||
kill|destroy) if [ "$obj" ]
|
||||
then if [ $obj = all ]
|
||||
then x=
|
||||
if ask "Do you really want to attempt to $verb them all?"
|
||||
then obj=`echo $obs`
|
||||
else echo 'Chicken!'
|
||||
obj=
|
||||
fi
|
||||
fi
|
||||
for it in $obj $x
|
||||
do if ash_lk "$obs $hobs" "$it"
|
||||
then if mv $it $HOME/$LIM <&- >&- 2>&-
|
||||
then if [ $verb = kill ]
|
||||
then echo "The $it cannot defend himself; he dies."
|
||||
else echo "You have destroyed the $it; it vanishes."
|
||||
fi
|
||||
obs=`ash_rm "$obs" "$it"`
|
||||
else if [ $verb = kill ]
|
||||
then echo "Your feeble blows are no match for the $it."
|
||||
else echo "The $it is indestructible."
|
||||
fi
|
||||
fi
|
||||
else if ash_lk "$kn" "$it"
|
||||
then echo "You must drop the $it first."
|
||||
found=false
|
||||
else echo "I see no $it here."
|
||||
fi
|
||||
fi
|
||||
done
|
||||
else echo 'Kill what?'
|
||||
fi
|
||||
;;
|
||||
look|l) obs=`echo $obs $hobs`
|
||||
hobs=
|
||||
if [ "$obs" ]
|
||||
then echo 'The room contains:'
|
||||
ash_pr $obs
|
||||
else echo 'The room is empty.'
|
||||
fi
|
||||
exs=`echo $exs $hexs`
|
||||
hexs=
|
||||
if [ "$exs" ]
|
||||
then echo 'There are exits plainly labeled:'
|
||||
ash_pr $exs
|
||||
echo 'and a passage directly overhead.'
|
||||
else echo 'The only exit is directly overhead.'
|
||||
fi
|
||||
;;
|
||||
magic) if [ "$obj" = mode ]
|
||||
then if sh -c $cha
|
||||
then echo 'You had your chance and you blew it.'
|
||||
else if ask 'Are you a wizard?'
|
||||
then echo -n 'Prove it! Say the magic word: '
|
||||
read obj
|
||||
if [ "$obj" = armadillo ]
|
||||
then echo 'Yes, master!!'
|
||||
wiz=true
|
||||
else echo "Homie says: I don't think so"
|
||||
cha=true
|
||||
fi
|
||||
else echo "I didn't think so."
|
||||
fi
|
||||
fi
|
||||
else echo 'Nice try.'
|
||||
fi
|
||||
;;
|
||||
open|read) if [ "$obj" ]
|
||||
then if ash_lk "$obs $hobs" "$obj"
|
||||
then if [ -r $obj ]
|
||||
then if [ -s $obj ]
|
||||
then echo "Opening the $obj reveals:"
|
||||
$CAT < $obj
|
||||
if [ $? != 0 ]
|
||||
then echo '-- oops, you lost the contents!'
|
||||
fi
|
||||
else echo "There is nothing inside the $obj."
|
||||
fi
|
||||
else echo "You do not have the proper tools to open the $obj."
|
||||
fi
|
||||
else if ash_lk "$kn" "$obj"
|
||||
then echo 'You must drop it first.'
|
||||
found=false
|
||||
else echo "I see no $obj here."
|
||||
fi
|
||||
fi
|
||||
else echo 'Open what?'
|
||||
fi
|
||||
;;
|
||||
quit|exit) if ask 'Do you really want to quit now?'
|
||||
then if [ "$kn" ]
|
||||
then echo 'The contents of your knapsack will still be there next time.'
|
||||
fi
|
||||
rm -rf $HOME/$LIM
|
||||
echo 'See you later!'
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
resurrect) if [ "$obj" ]
|
||||
then for it in $obj $x
|
||||
do if ash_lk "$obs $hobs" "$it"
|
||||
then echo "The $it is already alive and well."
|
||||
else if mv $HOME/$LIM/$it $it <&- >&- 2>&-
|
||||
then echo "The $it staggers to his feet."
|
||||
obs=`echo $it $obs`
|
||||
else echo "There are sparks but no $it appears."
|
||||
fi
|
||||
fi
|
||||
done
|
||||
else echo 'Resurrect what?'
|
||||
fi
|
||||
;;
|
||||
steal) if [ "$obj" ]
|
||||
then if ash_lk "$obs $hobs" "$obj"
|
||||
then echo 'There is already one here.'
|
||||
else set -- $x
|
||||
case "$1" in
|
||||
from) if [ "$2" ]
|
||||
then shift
|
||||
if PATH=$OPATH $* >$obj 2>&-
|
||||
then echo "The $1 monster drops the $obj."
|
||||
obs=`echo $obj $obs`
|
||||
else echo "The $1 monster runs away as you approach."
|
||||
rm -f $obj >&- 2>&-
|
||||
fi
|
||||
else echo 'From what?'
|
||||
fi
|
||||
;;
|
||||
*) echo "Steal $obj from what?"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
else echo 'Steal what?'
|
||||
fi
|
||||
;;
|
||||
throw) if [ "$obj" ]
|
||||
then if ash_lk "$obs $hobs" "$obj"
|
||||
then set -- $x
|
||||
case "$1" in
|
||||
at) case "$2" in
|
||||
daemon) if sh -c "lpr -r $obj"
|
||||
then echo "The daemon catches the $obj, turns it into paper,\nand leaves it in the basket."
|
||||
obs=`ash_rm "$obs" "$obj"`
|
||||
else echo "The daemon is nowhere to be found."
|
||||
fi
|
||||
;;
|
||||
*) echo 'At what?'
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*) echo "Throw $obj at what?"
|
||||
;;
|
||||
esac
|
||||
else if ash_lk "$kn" "$obj"
|
||||
then echo 'It is in your knapsack.'
|
||||
found=false
|
||||
else echo "I see no $obj here."
|
||||
fi
|
||||
fi
|
||||
else echo 'Throw what?'
|
||||
fi
|
||||
;;
|
||||
u|up) if cd ..
|
||||
then echo 'You pull yourself up a level.'
|
||||
else echo "You can't reach that high."
|
||||
fi
|
||||
;;
|
||||
wake) if [ "$obj" ]
|
||||
then echo "You awaken the $obj monster:"
|
||||
PATH=$OPATH $obj $x
|
||||
echo 'The monster slithers back into the darkness.'
|
||||
else echo 'Wake what?'
|
||||
fi
|
||||
;;
|
||||
w|where) echo "You are in $room."
|
||||
;;
|
||||
xyzzy) if cd
|
||||
then echo 'A strange feeling comes over you.'
|
||||
else echo 'Your spell fizzles out.'
|
||||
fi
|
||||
;;
|
||||
*) if [ "$verb" ]
|
||||
then if sh -c $wiz
|
||||
then PATH=$OPATH $verb $obj $x
|
||||
else echo "I don't know how to \"$verb\"."
|
||||
echo 'Type "help" for assistance.'
|
||||
fi
|
||||
else echo 'Say something!'
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
-5397
File diff suppressed because it is too large
Load Diff
-508
@@ -1,508 +0,0 @@
|
||||
/* externs.h -- extern function declarations which do not appear in their
|
||||
own header file. */
|
||||
|
||||
/* Copyright (C) 1993-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/>.
|
||||
*/
|
||||
|
||||
/* Make sure that this is included *after* config.h! */
|
||||
|
||||
#if !defined (_EXTERNS_H_)
|
||||
# define _EXTERNS_H_
|
||||
|
||||
#include "stdc.h"
|
||||
|
||||
/* Functions from expr.c. */
|
||||
extern intmax_t evalexp __P((char *, int *));
|
||||
|
||||
/* Functions from print_cmd.c. */
|
||||
#define FUNC_MULTILINE 0x01
|
||||
#define FUNC_EXTERNAL 0x02
|
||||
|
||||
extern char *make_command_string __P((COMMAND *));
|
||||
extern char *named_function_string __P((char *, COMMAND *, int));
|
||||
|
||||
extern void print_command __P((COMMAND *));
|
||||
extern void print_simple_command __P((SIMPLE_COM *));
|
||||
extern void print_word_list __P((WORD_LIST *, char *));
|
||||
|
||||
/* debugger support */
|
||||
extern void print_for_command_head __P((FOR_COM *));
|
||||
#if defined (SELECT_COMMAND)
|
||||
extern void print_select_command_head __P((SELECT_COM *));
|
||||
#endif
|
||||
extern void print_case_command_head __P((CASE_COM *));
|
||||
#if defined (DPAREN_ARITHMETIC)
|
||||
extern void print_arith_command __P((WORD_LIST *));
|
||||
#endif
|
||||
#if defined (COND_COMMAND)
|
||||
extern void print_cond_command __P((COND_COM *));
|
||||
#endif
|
||||
|
||||
/* set -x support */
|
||||
extern void xtrace_init __P((void));
|
||||
#ifdef NEED_XTRACE_SET_DECL
|
||||
extern void xtrace_set __P((int, FILE *));
|
||||
#endif
|
||||
extern void xtrace_fdchk __P((int));
|
||||
extern void xtrace_reset __P((void));
|
||||
extern char *indirection_level_string __P((void));
|
||||
extern void xtrace_print_assignment __P((char *, char *, int, int));
|
||||
extern void xtrace_print_word_list __P((WORD_LIST *, int));
|
||||
extern void xtrace_print_for_command_head __P((FOR_COM *));
|
||||
#if defined (SELECT_COMMAND)
|
||||
extern void xtrace_print_select_command_head __P((SELECT_COM *));
|
||||
#endif
|
||||
extern void xtrace_print_case_command_head __P((CASE_COM *));
|
||||
#if defined (DPAREN_ARITHMETIC)
|
||||
extern void xtrace_print_arith_cmd __P((WORD_LIST *));
|
||||
#endif
|
||||
#if defined (COND_COMMAND)
|
||||
extern void xtrace_print_cond_term __P((int, int, WORD_DESC *, char *, char *));
|
||||
#endif
|
||||
|
||||
/* Functions from shell.c. */
|
||||
extern void exit_shell __P((int)) __attribute__((__noreturn__));
|
||||
extern void sh_exit __P((int)) __attribute__((__noreturn__));
|
||||
extern void subshell_exit __P((int)) __attribute__((__noreturn__));
|
||||
extern void disable_priv_mode __P((void));
|
||||
extern void unbind_args __P((void));
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
extern int shell_is_restricted __P((char *));
|
||||
extern int maybe_make_restricted __P((char *));
|
||||
#endif
|
||||
|
||||
extern void unset_bash_input __P((int));
|
||||
extern void get_current_user_info __P((void));
|
||||
|
||||
/* Functions from eval.c. */
|
||||
extern int reader_loop __P((void));
|
||||
extern int parse_command __P((void));
|
||||
extern int read_command __P((void));
|
||||
|
||||
/* Functions from braces.c. */
|
||||
#if defined (BRACE_EXPANSION)
|
||||
extern char **brace_expand __P((char *));
|
||||
#endif
|
||||
|
||||
/* Miscellaneous functions from parse.y */
|
||||
extern int yyparse __P((void));
|
||||
extern int return_EOF __P((void));
|
||||
extern char *xparse_dolparen __P((char *, char *, int *, int));
|
||||
extern void reset_parser __P((void));
|
||||
extern WORD_LIST *parse_string_to_word_list __P((char *, int, const char *));
|
||||
|
||||
extern int parser_in_command_position __P((void));
|
||||
|
||||
extern void free_pushed_string_input __P((void));
|
||||
|
||||
extern char *decode_prompt_string __P((char *));
|
||||
|
||||
extern int get_current_prompt_level __P((void));
|
||||
extern void set_current_prompt_level __P((int));
|
||||
|
||||
#if defined (HISTORY)
|
||||
extern char *history_delimiting_chars __P((const char *));
|
||||
#endif
|
||||
|
||||
/* Declarations for functions defined in locale.c */
|
||||
extern void set_default_locale __P((void));
|
||||
extern void set_default_locale_vars __P((void));
|
||||
extern int set_locale_var __P((char *, char *));
|
||||
extern int set_lang __P((char *, char *));
|
||||
extern void set_default_lang __P((void));
|
||||
extern char *get_locale_var __P((char *));
|
||||
extern char *localetrans __P((char *, int, int *));
|
||||
extern char *mk_msgstr __P((char *, int *));
|
||||
extern char *localeexpand __P((char *, int, int, int, int *));
|
||||
|
||||
/* Declarations for functions defined in list.c. */
|
||||
extern void list_walk __P((GENERIC_LIST *, sh_glist_func_t *));
|
||||
extern void wlist_walk __P((WORD_LIST *, sh_icpfunc_t *));
|
||||
extern GENERIC_LIST *list_reverse ();
|
||||
extern int list_length ();
|
||||
extern GENERIC_LIST *list_append ();
|
||||
extern GENERIC_LIST *list_remove ();
|
||||
|
||||
/* Declarations for functions defined in stringlib.c */
|
||||
extern int find_string_in_alist __P((char *, STRING_INT_ALIST *, int));
|
||||
extern char *find_token_in_alist __P((int, STRING_INT_ALIST *, int));
|
||||
extern int find_index_in_alist __P((char *, STRING_INT_ALIST *, int));
|
||||
|
||||
extern char *substring __P((const char *, int, int));
|
||||
extern char *strsub __P((char *, char *, char *, int));
|
||||
extern char *strcreplace __P((char *, int, char *, int));
|
||||
extern void strip_leading __P((char *));
|
||||
extern void strip_trailing __P((char *, int, int));
|
||||
extern void xbcopy __P((char *, char *, int));
|
||||
|
||||
/* Functions from version.c. */
|
||||
extern char *shell_version_string __P((void));
|
||||
extern void show_shell_version __P((int));
|
||||
|
||||
/* Functions from the bash library, lib/sh/libsh.a. These should really
|
||||
go into a separate include file. */
|
||||
|
||||
/* declarations for functions defined in lib/sh/casemod.c */
|
||||
extern char *sh_modcase __P((const char *, char *, int));
|
||||
|
||||
/* Defines for flags argument to sh_modcase. These need to agree with what's
|
||||
in lib/sh/casemode.c */
|
||||
#define CASE_LOWER 0x0001
|
||||
#define CASE_UPPER 0x0002
|
||||
#define CASE_CAPITALIZE 0x0004
|
||||
#define CASE_UNCAP 0x0008
|
||||
#define CASE_TOGGLE 0x0010
|
||||
#define CASE_TOGGLEALL 0x0020
|
||||
#define CASE_UPFIRST 0x0040
|
||||
#define CASE_LOWFIRST 0x0080
|
||||
|
||||
#define CASE_USEWORDS 0x1000
|
||||
|
||||
/* declarations for functions defined in lib/sh/clktck.c */
|
||||
extern long get_clk_tck __P((void));
|
||||
|
||||
/* declarations for functions defined in lib/sh/clock.c */
|
||||
extern void clock_t_to_secs ();
|
||||
extern void print_clock_t ();
|
||||
|
||||
/* Declarations for functions defined in lib/sh/dprintf.c */
|
||||
#if !defined (HAVE_DPRINTF)
|
||||
extern void dprintf __P((int, const char *, ...)) __attribute__((__format__ (printf, 2, 3)));
|
||||
#endif
|
||||
|
||||
/* Declarations for functions defined in lib/sh/fmtulong.c */
|
||||
#define FL_PREFIX 0x01 /* add 0x, 0X, or 0 prefix as appropriate */
|
||||
#define FL_ADDBASE 0x02 /* add base# prefix to converted value */
|
||||
#define FL_HEXUPPER 0x04 /* use uppercase when converting to hex */
|
||||
#define FL_UNSIGNED 0x08 /* don't add any sign */
|
||||
|
||||
extern char *fmtulong __P((unsigned long int, int, char *, size_t, int));
|
||||
|
||||
/* Declarations for functions defined in lib/sh/fmtulong.c */
|
||||
#if defined (HAVE_LONG_LONG)
|
||||
extern char *fmtullong __P((unsigned long long int, int, char *, size_t, int));
|
||||
#endif
|
||||
|
||||
/* Declarations for functions defined in lib/sh/fmtumax.c */
|
||||
extern char *fmtumax __P((uintmax_t, int, char *, size_t, int));
|
||||
|
||||
/* Declarations for functions defined in lib/sh/fnxform.c */
|
||||
extern char *fnx_fromfs __P((char *, size_t));
|
||||
extern char *fnx_tofs __P((char *, size_t));
|
||||
|
||||
/* Declarations for functions defined in lib/sh/fpurge.c */
|
||||
|
||||
#if defined NEED_FPURGE_DECL
|
||||
#if !HAVE_DECL_FPURGE
|
||||
|
||||
#if HAVE_FPURGE
|
||||
# define fpurge _bash_fpurge
|
||||
#endif
|
||||
extern int fpurge __P((FILE *stream));
|
||||
|
||||
#endif /* HAVE_DECL_FPURGE */
|
||||
#endif /* NEED_FPURGE_DECL */
|
||||
|
||||
/* Declarations for functions defined in lib/sh/getcwd.c */
|
||||
#if !defined (HAVE_GETCWD)
|
||||
extern char *getcwd __P((char *, size_t));
|
||||
#endif
|
||||
|
||||
/* Declarations for functions defined in lib/sh/input_avail.c */
|
||||
extern int input_avail __P((int));
|
||||
|
||||
/* Declarations for functions defined in lib/sh/itos.c */
|
||||
extern char *inttostr __P((intmax_t, char *, size_t));
|
||||
extern char *itos __P((intmax_t));
|
||||
extern char *uinttostr __P((uintmax_t, char *, size_t));
|
||||
extern char *uitos __P((uintmax_t));
|
||||
|
||||
/* declarations for functions defined in lib/sh/makepath.c */
|
||||
#define MP_DOTILDE 0x01
|
||||
#define MP_DOCWD 0x02
|
||||
#define MP_RMDOT 0x04
|
||||
#define MP_IGNDOT 0x08
|
||||
|
||||
extern char *sh_makepath __P((const char *, const char *, int));
|
||||
|
||||
/* declarations for functions defined in lib/sh/mbscasecmp.c */
|
||||
#if !defined (HAVE_MBSCASECMP)
|
||||
extern char *mbscasecmp __P((const char *, const char *));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/mbschr.c */
|
||||
#if !defined (HAVE_MBSCHR)
|
||||
extern char *mbschr __P((const char *, int));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/mbscmp.c */
|
||||
#if !defined (HAVE_MBSCMP)
|
||||
extern char *mbscmp __P((const char *, const char *));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/netconn.c */
|
||||
extern int isnetconn __P((int));
|
||||
|
||||
/* declarations for functions defined in lib/sh/netopen.c */
|
||||
extern int netopen __P((char *));
|
||||
|
||||
/* Declarations for functions defined in lib/sh/oslib.c */
|
||||
|
||||
#if !defined (HAVE_DUP2) || defined (DUP2_BROKEN)
|
||||
extern int dup2 __P((int, int));
|
||||
#endif
|
||||
|
||||
#if !defined (HAVE_GETDTABLESIZE)
|
||||
extern int getdtablesize __P((void));
|
||||
#endif /* !HAVE_GETDTABLESIZE */
|
||||
|
||||
#if !defined (HAVE_GETHOSTNAME)
|
||||
extern int gethostname __P((char *, int));
|
||||
#endif /* !HAVE_GETHOSTNAME */
|
||||
|
||||
extern int getmaxgroups __P((void));
|
||||
extern long getmaxchild __P((void));
|
||||
|
||||
/* declarations for functions defined in lib/sh/pathcanon.c */
|
||||
#define PATH_CHECKDOTDOT 0x0001
|
||||
#define PATH_CHECKEXISTS 0x0002
|
||||
#define PATH_HARDPATH 0x0004
|
||||
#define PATH_NOALLOC 0x0008
|
||||
|
||||
extern char *sh_canonpath __P((char *, int));
|
||||
|
||||
/* declarations for functions defined in lib/sh/pathphys.c */
|
||||
extern char *sh_physpath __P((char *, int));
|
||||
extern char *sh_realpath __P((const char *, char *));
|
||||
|
||||
/* declarations for functions defined in lib/sh/setlinebuf.c */
|
||||
#ifdef NEED_SH_SETLINEBUF_DECL
|
||||
extern int sh_setlinebuf __P((FILE *));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/shaccess.c */
|
||||
extern int sh_eaccess __P((char *, int));
|
||||
|
||||
/* declarations for functions defined in lib/sh/shmatch.c */
|
||||
extern int sh_regmatch __P((const char *, const char *, int));
|
||||
|
||||
/* defines for flags argument to sh_regmatch. */
|
||||
#define SHMAT_SUBEXP 0x001 /* save subexpressions in SH_REMATCH */
|
||||
#define SHMAT_PWARN 0x002 /* print a warning message on invalid regexp */
|
||||
|
||||
/* declarations for functions defined in lib/sh/shmbchar.c */
|
||||
extern size_t mbstrlen __P((const char *));
|
||||
extern char *mbsmbchar __P((const char *));
|
||||
extern int sh_mbsnlen __P((const char *, size_t, int));
|
||||
|
||||
/* declarations for functions defined in lib/sh/shquote.c */
|
||||
extern char *sh_single_quote __P((const char *));
|
||||
extern char *sh_double_quote __P((const char *));
|
||||
extern char *sh_mkdoublequoted __P((const char *, int, int));
|
||||
extern char *sh_un_double_quote __P((char *));
|
||||
extern char *sh_backslash_quote __P((char *, const char *, int));
|
||||
extern char *sh_backslash_quote_for_double_quotes __P((char *));
|
||||
extern int sh_contains_shell_metas __P((char *));
|
||||
|
||||
/* declarations for functions defined in lib/sh/spell.c */
|
||||
extern int spname __P((char *, char *));
|
||||
extern char *dirspell __P((char *));
|
||||
|
||||
/* declarations for functions defined in lib/sh/strcasecmp.c */
|
||||
#if !defined (HAVE_STRCASECMP)
|
||||
extern int strncasecmp __P((const char *, const char *, int));
|
||||
extern int strcasecmp __P((const char *, const char *));
|
||||
#endif /* HAVE_STRCASECMP */
|
||||
|
||||
/* declarations for functions defined in lib/sh/strcasestr.c */
|
||||
#if ! HAVE_STRCASESTR
|
||||
extern char *strcasestr __P((const char *, const char *));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/strchrnul.c */
|
||||
#if ! HAVE_STRCHRNUL
|
||||
extern char *strchrnul __P((const char *, int));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/strerror.c */
|
||||
#if !defined (HAVE_STRERROR) && !defined (strerror)
|
||||
extern char *strerror __P((int));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/strftime.c */
|
||||
#if !defined (HAVE_STRFTIME) && defined (NEED_STRFTIME_DECL)
|
||||
extern size_t strftime __P((char *, size_t, const char *, const struct tm *));
|
||||
#endif
|
||||
|
||||
/* declarations for functions and structures defined in lib/sh/stringlist.c */
|
||||
|
||||
/* This is a general-purpose argv-style array struct. */
|
||||
typedef struct _list_of_strings {
|
||||
char **list;
|
||||
int list_size;
|
||||
int list_len;
|
||||
} STRINGLIST;
|
||||
|
||||
typedef int sh_strlist_map_func_t __P((char *));
|
||||
|
||||
extern STRINGLIST *strlist_create __P((int));
|
||||
extern STRINGLIST *strlist_resize __P((STRINGLIST *, int));
|
||||
extern void strlist_flush __P((STRINGLIST *));
|
||||
extern void strlist_dispose __P((STRINGLIST *));
|
||||
extern int strlist_remove __P((STRINGLIST *, char *));
|
||||
extern STRINGLIST *strlist_copy __P((STRINGLIST *));
|
||||
extern STRINGLIST *strlist_merge __P((STRINGLIST *, STRINGLIST *));
|
||||
extern STRINGLIST *strlist_append __P((STRINGLIST *, STRINGLIST *));
|
||||
extern STRINGLIST *strlist_prefix_suffix __P((STRINGLIST *, char *, char *));
|
||||
extern void strlist_print __P((STRINGLIST *, char *));
|
||||
extern void strlist_walk __P((STRINGLIST *, sh_strlist_map_func_t *));
|
||||
extern void strlist_sort __P((STRINGLIST *));
|
||||
|
||||
/* declarations for functions defined in lib/sh/stringvec.c */
|
||||
|
||||
extern char **strvec_create __P((int));
|
||||
extern char **strvec_resize __P((char **, int));
|
||||
extern void strvec_flush __P((char **));
|
||||
extern void strvec_dispose __P((char **));
|
||||
extern int strvec_remove __P((char **, char *));
|
||||
extern int strvec_len __P((char **));
|
||||
extern int strvec_search __P((char **, char *));
|
||||
extern char **strvec_copy __P((char **));
|
||||
extern int strvec_strcmp __P((char **, char **));
|
||||
extern void strvec_sort __P((char **));
|
||||
|
||||
extern char **strvec_from_word_list __P((WORD_LIST *, int, int, int *));
|
||||
extern WORD_LIST *strvec_to_word_list __P((char **, int, int));
|
||||
|
||||
/* declarations for functions defined in lib/sh/strnlen.c */
|
||||
#if !defined (HAVE_STRNLEN)
|
||||
extern size_t strnlen __P((const char *, size_t));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/strpbrk.c */
|
||||
#if !defined (HAVE_STRPBRK)
|
||||
extern char *strpbrk __P((const char *, const char *));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/strtod.c */
|
||||
#if !defined (HAVE_STRTOD)
|
||||
extern double strtod __P((const char *, char **));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/strtol.c */
|
||||
#if !HAVE_DECL_STRTOL
|
||||
extern long strtol __P((const char *, char **, int));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/strtoll.c */
|
||||
#if defined (HAVE_LONG_LONG) && !HAVE_DECL_STRTOLL
|
||||
extern long long strtoll __P((const char *, char **, int));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/strtoul.c */
|
||||
#if !HAVE_DECL_STRTOUL
|
||||
extern unsigned long strtoul __P((const char *, char **, int));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/strtoull.c */
|
||||
#if defined (HAVE_LONG_LONG) && !HAVE_DECL_STRTOULL
|
||||
extern unsigned long long strtoull __P((const char *, char **, int));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/strimax.c */
|
||||
#if !HAVE_DECL_STRTOIMAX
|
||||
extern intmax_t strtoimax __P((const char *, char **, int));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/strumax.c */
|
||||
#if !HAVE_DECL_STRTOUMAX
|
||||
extern uintmax_t strtoumax __P((const char *, char **, int));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/strtrans.c */
|
||||
extern char *ansicstr __P((char *, int, int, int *, int *));
|
||||
extern char *ansic_quote __P((char *, int, int *));
|
||||
extern int ansic_shouldquote __P((const char *));
|
||||
extern char *ansiexpand __P((char *, int, int, int *));
|
||||
|
||||
/* declarations for functions defined in lib/sh/timeval.c. No prototypes
|
||||
so we don't have to count on having a definition of struct timeval in
|
||||
scope when this file is included. */
|
||||
extern void timeval_to_secs ();
|
||||
extern void print_timeval ();
|
||||
|
||||
/* declarations for functions defined in lib/sh/tmpfile.c */
|
||||
#define MT_USETMPDIR 0x0001
|
||||
#define MT_READWRITE 0x0002
|
||||
#define MT_USERANDOM 0x0004
|
||||
|
||||
extern char *sh_mktmpname __P((char *, int));
|
||||
extern int sh_mktmpfd __P((char *, int, char **));
|
||||
/* extern FILE *sh_mktmpfp __P((char *, int, char **)); */
|
||||
|
||||
/* declarations for functions defined in lib/sh/uconvert.c */
|
||||
extern int uconvert __P((char *, long *, long *));
|
||||
|
||||
/* declarations for functions defined in lib/sh/ufuncs.c */
|
||||
extern unsigned int falarm __P((unsigned int, unsigned int));
|
||||
extern unsigned int fsleep __P((unsigned int, unsigned int));
|
||||
|
||||
/* declarations for functions defined in lib/sh/unicode.c */
|
||||
extern int u32cconv __P((unsigned long, char *));
|
||||
extern void u32reset __P((void));
|
||||
|
||||
/* declarations for functions defined in lib/sh/wcsnwidth.c */
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
extern int wcsnwidth __P((const wchar_t *, size_t, int));
|
||||
#endif
|
||||
|
||||
/* declarations for functions defined in lib/sh/winsize.c */
|
||||
extern void get_new_window_size __P((int, int *, int *));
|
||||
|
||||
/* declarations for functions defined in lib/sh/zcatfd.c */
|
||||
extern int zcatfd __P((int, int, char *));
|
||||
|
||||
/* declarations for functions defined in lib/sh/zgetline.c */
|
||||
extern ssize_t zgetline __P((int, char **, size_t *, int));
|
||||
|
||||
/* declarations for functions defined in lib/sh/zmapfd.c */
|
||||
extern int zmapfd __P((int, char **, char *));
|
||||
|
||||
/* declarations for functions defined in lib/sh/zread.c */
|
||||
extern ssize_t zread __P((int, char *, size_t));
|
||||
extern ssize_t zreadretry __P((int, char *, size_t));
|
||||
extern ssize_t zreadintr __P((int, char *, size_t));
|
||||
extern ssize_t zreadc __P((int, char *));
|
||||
extern ssize_t zreadcintr __P((int, char *));
|
||||
extern void zreset __P((void));
|
||||
extern void zsyncfd __P((int));
|
||||
|
||||
/* declarations for functions defined in lib/sh/zwrite.c */
|
||||
extern int zwrite __P((int, char *, size_t));
|
||||
|
||||
/* declarations for functions defined in lib/glob/gmisc.c */
|
||||
extern int match_pattern_char __P((char *, char *));
|
||||
extern int umatchlen __P((char *, size_t));
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
extern int match_pattern_wchar __P((wchar_t *, wchar_t *));
|
||||
extern int wmatchlen __P((wchar_t *, size_t));
|
||||
#endif
|
||||
|
||||
#endif /* _EXTERNS_H_ */
|
||||
@@ -1,364 +0,0 @@
|
||||
/* flags.c -- Everything about flags except the `set' command. That
|
||||
is in builtins.c */
|
||||
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "shell.h"
|
||||
#include "flags.h"
|
||||
|
||||
#if defined (BANG_HISTORY)
|
||||
# include "bashhist.h"
|
||||
#endif
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
extern int set_job_control __P((int));
|
||||
#endif
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
extern char *shell_name;
|
||||
#endif
|
||||
|
||||
extern int shell_initialized;
|
||||
extern int builtin_ignoring_errexit;
|
||||
|
||||
/* -c, -s invocation options -- not really flags, but they show up in $- */
|
||||
extern int want_pending_command, read_from_stdin;
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* The Standard sh Flags. */
|
||||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
/* Non-zero means automatically mark variables which are modified or created
|
||||
as auto export variables. */
|
||||
int mark_modified_vars = 0;
|
||||
|
||||
/* Non-zero causes asynchronous job notification. Otherwise, job state
|
||||
notification only takes place just before a primary prompt is printed. */
|
||||
int asynchronous_notification = 0;
|
||||
|
||||
/* Non-zero means exit immediately if a command exits with a non-zero
|
||||
exit status. The first is what controls set -e; the second is what
|
||||
bash uses internally. */
|
||||
int errexit_flag = 0;
|
||||
int exit_immediately_on_error = 0;
|
||||
|
||||
/* Non-zero means disable filename globbing. */
|
||||
int disallow_filename_globbing = 0;
|
||||
|
||||
/* Non-zero means that all keyword arguments are placed into the environment
|
||||
for a command, not just those that appear on the line before the command
|
||||
name. */
|
||||
int place_keywords_in_env = 0;
|
||||
|
||||
/* Non-zero means read commands, but don't execute them. This is useful
|
||||
for debugging shell scripts that should do something hairy and possibly
|
||||
destructive. */
|
||||
int read_but_dont_execute = 0;
|
||||
|
||||
/* Non-zero means end of file is after one command. */
|
||||
int just_one_command = 0;
|
||||
|
||||
/* Non-zero means don't overwrite existing files while doing redirections. */
|
||||
int noclobber = 0;
|
||||
|
||||
/* Non-zero means trying to get the value of $i where $i is undefined
|
||||
causes an error, instead of a null substitution. */
|
||||
int unbound_vars_is_error = 0;
|
||||
|
||||
/* Non-zero means type out input lines after you read them. */
|
||||
int echo_input_at_read = 0;
|
||||
|
||||
/* Non-zero means type out the command definition after reading, but
|
||||
before executing. */
|
||||
int echo_command_at_execute = 0;
|
||||
|
||||
/* Non-zero means turn on the job control features. */
|
||||
int jobs_m_flag = 0;
|
||||
|
||||
/* Non-zero means this shell is interactive, even if running under a
|
||||
pipe. */
|
||||
int forced_interactive = 0;
|
||||
|
||||
/* By default, follow the symbolic links as if they were real directories
|
||||
while hacking the `cd' command. This means that `cd ..' moves up in
|
||||
the string of symbolic links that make up the current directory, instead
|
||||
of the absolute directory. The shell variable `nolinks' also controls
|
||||
this flag. */
|
||||
int no_symbolic_links = 0;
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* Non-Standard Flags Follow Here. */
|
||||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
#if 0
|
||||
/* Non-zero means do lexical scoping in the body of a FOR command. */
|
||||
int lexical_scoping = 0;
|
||||
#endif
|
||||
|
||||
/* Non-zero means no such thing as invisible variables. */
|
||||
int no_invisible_vars = 0;
|
||||
|
||||
/* Non-zero means look up and remember command names in a hash table, */
|
||||
int hashing_enabled = 1;
|
||||
|
||||
#if defined (BANG_HISTORY)
|
||||
/* Non-zero means that we are doing history expansion. The default.
|
||||
This means !22 gets the 22nd line of history. */
|
||||
# if defined (STRICT_POSIX)
|
||||
int history_expansion = 0;
|
||||
# else
|
||||
int history_expansion = 1;
|
||||
# endif
|
||||
#endif /* BANG_HISTORY */
|
||||
|
||||
/* Non-zero means that we allow comments to appear in interactive commands. */
|
||||
int interactive_comments = 1;
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
/* Non-zero means that this shell is `restricted'. A restricted shell
|
||||
disallows: changing directories, command or path names containing `/',
|
||||
unsetting or resetting the values of $PATH and $SHELL, and any type of
|
||||
output redirection. */
|
||||
int restricted = 0; /* currently restricted */
|
||||
int restricted_shell = 0; /* shell was started in restricted mode. */
|
||||
#endif /* RESTRICTED_SHELL */
|
||||
|
||||
/* Non-zero means that this shell is running in `privileged' mode. This
|
||||
is required if the shell is to run setuid. If the `-p' option is
|
||||
not supplied at startup, and the real and effective uids or gids
|
||||
differ, disable_priv_mode is called to relinquish setuid status. */
|
||||
int privileged_mode = 0;
|
||||
|
||||
#if defined (BRACE_EXPANSION)
|
||||
/* Zero means to disable brace expansion: foo{a,b} -> fooa foob */
|
||||
int brace_expansion = 1;
|
||||
#endif
|
||||
|
||||
/* Non-zero means that shell functions inherit the DEBUG trap. */
|
||||
int function_trace_mode = 0;
|
||||
|
||||
/* Non-zero means that shell functions inherit the ERR trap. */
|
||||
int error_trace_mode = 0;
|
||||
|
||||
/* Non-zero means that the rightmost non-zero exit status in a pipeline
|
||||
is the exit status of the entire pipeline. If each processes exits
|
||||
with a 0 status, the status of the pipeline is 0. */
|
||||
int pipefail_opt = 0;
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* The Flags ALIST. */
|
||||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
const struct flags_alist shell_flags[] = {
|
||||
/* Standard sh flags. */
|
||||
{ 'a', &mark_modified_vars },
|
||||
#if defined (JOB_CONTROL)
|
||||
{ 'b', &asynchronous_notification },
|
||||
#endif /* JOB_CONTROL */
|
||||
{ 'e', &errexit_flag },
|
||||
{ 'f', &disallow_filename_globbing },
|
||||
{ 'h', &hashing_enabled },
|
||||
{ 'i', &forced_interactive },
|
||||
{ 'k', &place_keywords_in_env },
|
||||
#if defined (JOB_CONTROL)
|
||||
{ 'm', &jobs_m_flag },
|
||||
#endif /* JOB_CONTROL */
|
||||
{ 'n', &read_but_dont_execute },
|
||||
{ 'p', &privileged_mode },
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
{ 'r', &restricted },
|
||||
#endif /* RESTRICTED_SHELL */
|
||||
{ 't', &just_one_command },
|
||||
{ 'u', &unbound_vars_is_error },
|
||||
{ 'v', &echo_input_at_read },
|
||||
{ 'x', &echo_command_at_execute },
|
||||
|
||||
/* New flags that control non-standard things. */
|
||||
#if 0
|
||||
{ 'l', &lexical_scoping },
|
||||
#endif
|
||||
#if defined (BRACE_EXPANSION)
|
||||
{ 'B', &brace_expansion },
|
||||
#endif
|
||||
{ 'C', &noclobber },
|
||||
{ 'E', &error_trace_mode },
|
||||
#if defined (BANG_HISTORY)
|
||||
{ 'H', &history_expansion },
|
||||
#endif /* BANG_HISTORY */
|
||||
{ 'I', &no_invisible_vars },
|
||||
{ 'P', &no_symbolic_links },
|
||||
{ 'T', &function_trace_mode },
|
||||
{0, (int *)NULL}
|
||||
};
|
||||
|
||||
#define NUM_SHELL_FLAGS (sizeof (shell_flags) / sizeof (struct flags_alist))
|
||||
|
||||
char optflags[NUM_SHELL_FLAGS+4] = { '+' };
|
||||
|
||||
int *
|
||||
find_flag (name)
|
||||
int name;
|
||||
{
|
||||
int i;
|
||||
for (i = 0; shell_flags[i].name; i++)
|
||||
{
|
||||
if (shell_flags[i].name == name)
|
||||
return (shell_flags[i].value);
|
||||
}
|
||||
return (FLAG_UNKNOWN);
|
||||
}
|
||||
|
||||
/* Change the state of a flag, and return it's original value, or return
|
||||
FLAG_ERROR if there is no flag FLAG. ON_OR_OFF must be either
|
||||
FLAG_ON or FLAG_OFF. */
|
||||
int
|
||||
change_flag (flag, on_or_off)
|
||||
int flag;
|
||||
int on_or_off;
|
||||
{
|
||||
int *value, old_value;
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
/* Don't allow "set +r" in a shell which is `restricted'. */
|
||||
if (restricted && flag == 'r' && on_or_off == FLAG_OFF)
|
||||
return (FLAG_ERROR);
|
||||
#endif /* RESTRICTED_SHELL */
|
||||
|
||||
value = find_flag (flag);
|
||||
|
||||
if ((value == (int *)FLAG_UNKNOWN) || (on_or_off != FLAG_ON && on_or_off != FLAG_OFF))
|
||||
return (FLAG_ERROR);
|
||||
|
||||
old_value = *value;
|
||||
*value = (on_or_off == FLAG_ON) ? 1 : 0;
|
||||
|
||||
/* Special cases for a few flags. */
|
||||
switch (flag)
|
||||
{
|
||||
#if defined (BANG_HISTORY)
|
||||
case 'H':
|
||||
if (on_or_off == FLAG_ON)
|
||||
bash_initialize_history ();
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
case 'm':
|
||||
set_job_control (on_or_off == FLAG_ON);
|
||||
break;
|
||||
#endif /* JOB_CONTROL */
|
||||
|
||||
case 'e':
|
||||
exit_immediately_on_error = errexit_flag;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
if (interactive_shell)
|
||||
read_but_dont_execute = 0;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
if (on_or_off == FLAG_OFF)
|
||||
disable_priv_mode ();
|
||||
break;
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
case 'r':
|
||||
if (on_or_off == FLAG_ON && shell_initialized)
|
||||
maybe_make_restricted (shell_name);
|
||||
break;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
return (old_value);
|
||||
}
|
||||
|
||||
/* Return a string which is the names of all the currently
|
||||
set shell flags. */
|
||||
char *
|
||||
which_set_flags ()
|
||||
{
|
||||
char *temp;
|
||||
int i, string_index;
|
||||
|
||||
temp = (char *)xmalloc (1 + NUM_SHELL_FLAGS + read_from_stdin + want_pending_command);
|
||||
for (i = string_index = 0; shell_flags[i].name; i++)
|
||||
if (*(shell_flags[i].value))
|
||||
temp[string_index++] = shell_flags[i].name;
|
||||
|
||||
if (want_pending_command)
|
||||
temp[string_index++] = 'c';
|
||||
if (read_from_stdin)
|
||||
temp[string_index++] = 's';
|
||||
|
||||
temp[string_index] = '\0';
|
||||
return (temp);
|
||||
}
|
||||
|
||||
void
|
||||
reset_shell_flags ()
|
||||
{
|
||||
mark_modified_vars = exit_immediately_on_error = disallow_filename_globbing = 0;
|
||||
place_keywords_in_env = read_but_dont_execute = just_one_command = 0;
|
||||
noclobber = unbound_vars_is_error = echo_input_at_read = 0;
|
||||
echo_command_at_execute = jobs_m_flag = forced_interactive = 0;
|
||||
no_symbolic_links = no_invisible_vars = privileged_mode = pipefail_opt = 0;
|
||||
|
||||
hashing_enabled = interactive_comments = 1;
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
asynchronous_notification = 0;
|
||||
#endif
|
||||
|
||||
#if defined (BANG_HISTORY)
|
||||
history_expansion = 1;
|
||||
#endif
|
||||
|
||||
#if defined (BRACE_EXPANSION)
|
||||
brace_expansion = 1;
|
||||
#endif
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
restricted = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
initialize_flags ()
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (i = 0; shell_flags[i].name; i++)
|
||||
optflags[i+1] = shell_flags[i].name;
|
||||
optflags[++i] = 'o';
|
||||
optflags[++i] = ';';
|
||||
optflags[i+1] = '\0';
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/* flags.h -- a list of all the flags that the shell knows about. You add
|
||||
a flag to this program by adding the name here, and in flags.c. */
|
||||
|
||||
/* 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 (_FLAGS_H_)
|
||||
#define _FLAGS_H_
|
||||
|
||||
#include "stdc.h"
|
||||
|
||||
/* Welcome to the world of Un*x, where everything is slightly backwards. */
|
||||
#define FLAG_ON '-'
|
||||
#define FLAG_OFF '+'
|
||||
|
||||
#define FLAG_ERROR -1
|
||||
#define FLAG_UNKNOWN (int *)0
|
||||
|
||||
/* The thing that we build the array of flags out of. */
|
||||
struct flags_alist {
|
||||
char name;
|
||||
int *value;
|
||||
};
|
||||
|
||||
extern const struct flags_alist shell_flags[];
|
||||
extern char optflags[];
|
||||
|
||||
extern int
|
||||
mark_modified_vars, exit_immediately_on_error, disallow_filename_globbing,
|
||||
place_keywords_in_env, read_but_dont_execute,
|
||||
just_one_command, unbound_vars_is_error, echo_input_at_read,
|
||||
echo_command_at_execute, no_invisible_vars, noclobber,
|
||||
hashing_enabled, forced_interactive, privileged_mode, jobs_m_flag,
|
||||
asynchronous_notification, interactive_comments, no_symbolic_links,
|
||||
function_trace_mode, error_trace_mode, pipefail_opt;
|
||||
|
||||
#if 0
|
||||
extern int lexical_scoping;
|
||||
#endif
|
||||
|
||||
#if defined (BRACE_EXPANSION)
|
||||
extern int brace_expansion;
|
||||
#endif
|
||||
|
||||
#if defined (BANG_HISTORY)
|
||||
extern int history_expansion;
|
||||
#endif /* BANG_HISTORY */
|
||||
|
||||
#if defined (RESTRICTED_SHELL)
|
||||
extern int restricted;
|
||||
extern int restricted_shell;
|
||||
#endif /* RESTRICTED_SHELL */
|
||||
|
||||
extern int *find_flag __P((int));
|
||||
extern int change_flag __P((int, int));
|
||||
extern char *which_set_flags __P((void));
|
||||
extern void reset_shell_flags __P((void));
|
||||
|
||||
extern void initialize_flags __P((void));
|
||||
|
||||
/* A macro for efficiency. */
|
||||
#define change_flag_char(flag, on_or_off) change_flag (flag, on_or_off)
|
||||
|
||||
#endif /* _FLAGS_H_ */
|
||||
-1176
File diff suppressed because it is too large
Load Diff
@@ -1,40 +0,0 @@
|
||||
/* posixjmp.h -- wrapper for setjmp.h with changes for POSIX systems. */
|
||||
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _POSIXJMP_H_
|
||||
#define _POSIXJMP_H_
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
/* This *must* be included *after* config.h */
|
||||
|
||||
#if defined (HAVE_POSIX_SIGSETJMP)
|
||||
# define procenv_t sigjmp_buf
|
||||
# if !defined (__OPENNT)
|
||||
# undef setjmp
|
||||
# define setjmp(x) sigsetjmp((x), 1)
|
||||
# undef longjmp
|
||||
# define longjmp(x, n) siglongjmp((x), (n))
|
||||
# endif /* !__OPENNT */
|
||||
#else
|
||||
# define procenv_t jmp_buf
|
||||
#endif
|
||||
|
||||
#endif /* _POSIXJMP_H_ */
|
||||
@@ -1,663 +0,0 @@
|
||||
/* input.c -- functions to perform buffered input with synchronization. */
|
||||
|
||||
/* Copyright (C) 1992-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"
|
||||
|
||||
#include "bashtypes.h"
|
||||
#if !defined (_MINIX) && defined (HAVE_SYS_FILE_H)
|
||||
# include <sys/file.h>
|
||||
#endif
|
||||
#include "filecntl.h"
|
||||
#include "posixstat.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "bashansi.h"
|
||||
#include "bashintl.h"
|
||||
|
||||
#include "command.h"
|
||||
#include "general.h"
|
||||
#include "input.h"
|
||||
#include "error.h"
|
||||
#include "externs.h"
|
||||
#include "quit.h"
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif /* !errno */
|
||||
|
||||
#if defined (EAGAIN)
|
||||
# define X_EAGAIN EAGAIN
|
||||
#else
|
||||
# define X_EAGAIN -99
|
||||
#endif
|
||||
|
||||
#if defined (EWOULDBLOCK)
|
||||
# define X_EWOULDBLOCK EWOULDBLOCK
|
||||
#else
|
||||
# define X_EWOULDBLOCK -99
|
||||
#endif
|
||||
|
||||
extern void termsig_handler __P((int));
|
||||
|
||||
/* Functions to handle reading input on systems that don't restart read(2)
|
||||
if a signal is received. */
|
||||
|
||||
static char localbuf[128];
|
||||
static int local_index = 0, local_bufused = 0;
|
||||
|
||||
/* Posix and USG systems do not guarantee to restart read () if it is
|
||||
interrupted by a signal. We do the read ourselves, and restart it
|
||||
if it returns EINTR. */
|
||||
int
|
||||
getc_with_restart (stream)
|
||||
FILE *stream;
|
||||
{
|
||||
unsigned char uc;
|
||||
|
||||
CHECK_TERMSIG;
|
||||
|
||||
/* Try local buffering to reduce the number of read(2) calls. */
|
||||
if (local_index == local_bufused || local_bufused == 0)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
CHECK_TERMSIG;
|
||||
QUIT;
|
||||
run_pending_traps ();
|
||||
|
||||
local_bufused = read (fileno (stream), localbuf, sizeof(localbuf));
|
||||
if (local_bufused > 0)
|
||||
break;
|
||||
else if (local_bufused == 0)
|
||||
{
|
||||
local_index = 0;
|
||||
return EOF;
|
||||
}
|
||||
else if (errno == X_EAGAIN || errno == X_EWOULDBLOCK)
|
||||
{
|
||||
if (sh_unset_nodelay_mode (fileno (stream)) < 0)
|
||||
{
|
||||
sys_error (_("cannot reset nodelay mode for fd %d"), fileno (stream));
|
||||
return EOF;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (errno != EINTR)
|
||||
{
|
||||
local_index = 0;
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
local_index = 0;
|
||||
}
|
||||
uc = localbuf[local_index++];
|
||||
return uc;
|
||||
}
|
||||
|
||||
int
|
||||
ungetc_with_restart (c, stream)
|
||||
int c;
|
||||
FILE *stream;
|
||||
{
|
||||
if (local_index == 0 || c == EOF)
|
||||
return EOF;
|
||||
localbuf[--local_index] = c;
|
||||
return c;
|
||||
}
|
||||
|
||||
#if defined (BUFFERED_INPUT)
|
||||
|
||||
/* A facility similar to stdio, but input-only. */
|
||||
|
||||
#if defined (USING_BASH_MALLOC)
|
||||
# define MAX_INPUT_BUFFER_SIZE 8176
|
||||
#else
|
||||
# define MAX_INPUT_BUFFER_SIZE 8192
|
||||
#endif
|
||||
|
||||
#if !defined (SEEK_CUR)
|
||||
# define SEEK_CUR 1
|
||||
#endif /* !SEEK_CUR */
|
||||
|
||||
#ifdef max
|
||||
# undef max
|
||||
#endif
|
||||
#define max(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#ifdef min
|
||||
# undef min
|
||||
#endif
|
||||
#define min(a, b) ((a) > (b) ? (b) : (a))
|
||||
|
||||
extern int interactive_shell;
|
||||
|
||||
int bash_input_fd_changed;
|
||||
|
||||
/* This provides a way to map from a file descriptor to the buffer
|
||||
associated with that file descriptor, rather than just the other
|
||||
way around. This is needed so that buffers are managed properly
|
||||
in constructs like 3<&4. buffers[x]->b_fd == x -- that is how the
|
||||
correspondence is maintained. */
|
||||
static BUFFERED_STREAM **buffers = (BUFFERED_STREAM **)NULL;
|
||||
static int nbuffers;
|
||||
|
||||
#define ALLOCATE_BUFFERS(n) \
|
||||
do { if ((n) >= nbuffers) allocate_buffers (n); } while (0)
|
||||
|
||||
/* Make sure `buffers' has at least N elements. */
|
||||
static void
|
||||
allocate_buffers (n)
|
||||
int n;
|
||||
{
|
||||
register int i, orig_nbuffers;
|
||||
|
||||
orig_nbuffers = nbuffers;
|
||||
nbuffers = n + 20;
|
||||
buffers = (BUFFERED_STREAM **)xrealloc
|
||||
(buffers, nbuffers * sizeof (BUFFERED_STREAM *));
|
||||
|
||||
/* Zero out the new buffers. */
|
||||
for (i = orig_nbuffers; i < nbuffers; i++)
|
||||
buffers[i] = (BUFFERED_STREAM *)NULL;
|
||||
}
|
||||
|
||||
/* Construct and return a BUFFERED_STREAM corresponding to file descriptor
|
||||
FD, using BUFFER. */
|
||||
static BUFFERED_STREAM *
|
||||
make_buffered_stream (fd, buffer, bufsize)
|
||||
int fd;
|
||||
char *buffer;
|
||||
size_t bufsize;
|
||||
{
|
||||
BUFFERED_STREAM *bp;
|
||||
|
||||
bp = (BUFFERED_STREAM *)xmalloc (sizeof (BUFFERED_STREAM));
|
||||
ALLOCATE_BUFFERS (fd);
|
||||
buffers[fd] = bp;
|
||||
bp->b_fd = fd;
|
||||
bp->b_buffer = buffer;
|
||||
bp->b_size = bufsize;
|
||||
bp->b_used = bp->b_inputp = bp->b_flag = 0;
|
||||
if (bufsize == 1)
|
||||
bp->b_flag |= B_UNBUFF;
|
||||
if (O_TEXT && (fcntl (fd, F_GETFL) & O_TEXT) != 0)
|
||||
bp->b_flag |= O_TEXT;
|
||||
return (bp);
|
||||
}
|
||||
|
||||
/* Allocate a new BUFFERED_STREAM, copy BP to it, and return the new copy. */
|
||||
static BUFFERED_STREAM *
|
||||
copy_buffered_stream (bp)
|
||||
BUFFERED_STREAM *bp;
|
||||
{
|
||||
BUFFERED_STREAM *nbp;
|
||||
|
||||
if (!bp)
|
||||
return ((BUFFERED_STREAM *)NULL);
|
||||
|
||||
nbp = (BUFFERED_STREAM *)xmalloc (sizeof (BUFFERED_STREAM));
|
||||
xbcopy ((char *)bp, (char *)nbp, sizeof (BUFFERED_STREAM));
|
||||
return (nbp);
|
||||
}
|
||||
|
||||
int
|
||||
set_bash_input_fd (fd)
|
||||
int fd;
|
||||
{
|
||||
if (bash_input.type == st_bstream)
|
||||
bash_input.location.buffered_fd = fd;
|
||||
else if (interactive_shell == 0)
|
||||
default_buffered_input = fd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
fd_is_bash_input (fd)
|
||||
int fd;
|
||||
{
|
||||
if (bash_input.type == st_bstream && bash_input.location.buffered_fd == fd)
|
||||
return 1;
|
||||
else if (interactive_shell == 0 && default_buffered_input == fd)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Save the buffered stream corresponding to file descriptor FD (which bash
|
||||
is using to read input) to a buffered stream associated with NEW_FD. If
|
||||
NEW_FD is -1, a new file descriptor is allocated with fcntl. The new
|
||||
file descriptor is returned on success, -1 on error. */
|
||||
int
|
||||
save_bash_input (fd, new_fd)
|
||||
int fd, new_fd;
|
||||
{
|
||||
int nfd;
|
||||
|
||||
/* Sync the stream so we can re-read from the new file descriptor. We
|
||||
might be able to avoid this by copying the buffered stream verbatim
|
||||
to the new file descriptor. */
|
||||
if (buffers[fd])
|
||||
sync_buffered_stream (fd);
|
||||
|
||||
/* Now take care of duplicating the file descriptor that bash is
|
||||
using for input, so we can reinitialize it later. */
|
||||
nfd = (new_fd == -1) ? fcntl (fd, F_DUPFD, 10) : new_fd;
|
||||
if (nfd == -1)
|
||||
{
|
||||
if (fcntl (fd, F_GETFD, 0) == 0)
|
||||
sys_error (_("cannot allocate new file descriptor for bash input from fd %d"), fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (buffers[nfd])
|
||||
{
|
||||
/* What's this? A stray buffer without an associated open file
|
||||
descriptor? Free up the buffer and report the error. */
|
||||
internal_error (_("save_bash_input: buffer already exists for new fd %d"), nfd);
|
||||
free_buffered_stream (buffers[nfd]);
|
||||
}
|
||||
|
||||
/* Reinitialize bash_input.location. */
|
||||
if (bash_input.type == st_bstream)
|
||||
{
|
||||
bash_input.location.buffered_fd = nfd;
|
||||
fd_to_buffered_stream (nfd);
|
||||
close_buffered_fd (fd); /* XXX */
|
||||
}
|
||||
else
|
||||
/* If the current input type is not a buffered stream, but the shell
|
||||
is not interactive and therefore using a buffered stream to read
|
||||
input (e.g. with an `eval exec 3>output' inside a script), note
|
||||
that the input fd has been changed. pop_stream() looks at this
|
||||
value and adjusts the input fd to the new value of
|
||||
default_buffered_input accordingly. */
|
||||
bash_input_fd_changed++;
|
||||
|
||||
if (default_buffered_input == fd)
|
||||
default_buffered_input = nfd;
|
||||
|
||||
SET_CLOSE_ON_EXEC (nfd);
|
||||
return nfd;
|
||||
}
|
||||
|
||||
/* Check that file descriptor FD is not the one that bash is currently
|
||||
using to read input from a script. FD is about to be duplicated onto,
|
||||
which means that the kernel will close it for us. If FD is the bash
|
||||
input file descriptor, we need to seek backwards in the script (if
|
||||
possible and necessary -- scripts read from stdin are still unbuffered),
|
||||
allocate a new file descriptor to use for bash input, and re-initialize
|
||||
the buffered stream. Make sure the file descriptor used to save bash
|
||||
input is set close-on-exec. Returns 0 on success, -1 on failure. This
|
||||
works only if fd is > 0 -- if fd == 0 and bash is reading input from
|
||||
fd 0, save_bash_input is used instead, to cooperate with input
|
||||
redirection (look at redir.c:add_undo_redirect()). */
|
||||
int
|
||||
check_bash_input (fd)
|
||||
int fd;
|
||||
{
|
||||
if (fd_is_bash_input (fd))
|
||||
{
|
||||
if (fd > 0)
|
||||
return ((save_bash_input (fd, -1) == -1) ? -1 : 0);
|
||||
else if (fd == 0)
|
||||
return ((sync_buffered_stream (fd) == -1) ? -1 : 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This is the buffered stream analogue of dup2(fd1, fd2). The
|
||||
BUFFERED_STREAM corresponding to fd2 is deallocated, if one exists.
|
||||
BUFFERS[fd1] is copied to BUFFERS[fd2]. This is called by the
|
||||
redirect code for constructs like 4<&0 and 3</etc/rc.local. */
|
||||
int
|
||||
duplicate_buffered_stream (fd1, fd2)
|
||||
int fd1, fd2;
|
||||
{
|
||||
int is_bash_input, m;
|
||||
|
||||
if (fd1 == fd2)
|
||||
return 0;
|
||||
|
||||
m = max (fd1, fd2);
|
||||
ALLOCATE_BUFFERS (m);
|
||||
|
||||
/* If FD2 is the file descriptor bash is currently using for shell input,
|
||||
we need to do some extra work to make sure that the buffered stream
|
||||
actually exists (it might not if fd1 was not active, and the copy
|
||||
didn't actually do anything). */
|
||||
is_bash_input = (bash_input.type == st_bstream) &&
|
||||
(bash_input.location.buffered_fd == fd2);
|
||||
|
||||
if (buffers[fd2])
|
||||
{
|
||||
/* If the two objects share the same b_buffer, don't free it. */
|
||||
if (buffers[fd1] && buffers[fd1]->b_buffer && buffers[fd1]->b_buffer == buffers[fd2]->b_buffer)
|
||||
buffers[fd2] = (BUFFERED_STREAM *)NULL;
|
||||
else
|
||||
free_buffered_stream (buffers[fd2]);
|
||||
}
|
||||
buffers[fd2] = copy_buffered_stream (buffers[fd1]);
|
||||
if (buffers[fd2])
|
||||
buffers[fd2]->b_fd = fd2;
|
||||
|
||||
if (is_bash_input)
|
||||
{
|
||||
if (!buffers[fd2])
|
||||
fd_to_buffered_stream (fd2);
|
||||
buffers[fd2]->b_flag |= B_WASBASHINPUT;
|
||||
}
|
||||
|
||||
return (fd2);
|
||||
}
|
||||
|
||||
/* Return 1 if a seek on FD will succeed. */
|
||||
#define fd_is_seekable(fd) (lseek ((fd), 0L, SEEK_CUR) >= 0)
|
||||
|
||||
/* Take FD, a file descriptor, and create and return a buffered stream
|
||||
corresponding to it. If something is wrong and the file descriptor
|
||||
is invalid, return a NULL stream. */
|
||||
BUFFERED_STREAM *
|
||||
fd_to_buffered_stream (fd)
|
||||
int fd;
|
||||
{
|
||||
char *buffer;
|
||||
size_t size;
|
||||
struct stat sb;
|
||||
|
||||
if (fstat (fd, &sb) < 0)
|
||||
{
|
||||
close (fd);
|
||||
return ((BUFFERED_STREAM *)NULL);
|
||||
}
|
||||
|
||||
size = (fd_is_seekable (fd)) ? min (sb.st_size, MAX_INPUT_BUFFER_SIZE) : 1;
|
||||
if (size == 0)
|
||||
size = 1;
|
||||
buffer = (char *)xmalloc (size);
|
||||
|
||||
return (make_buffered_stream (fd, buffer, size));
|
||||
}
|
||||
|
||||
/* Return a buffered stream corresponding to FILE, a file name. */
|
||||
BUFFERED_STREAM *
|
||||
open_buffered_stream (file)
|
||||
char *file;
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open (file, O_RDONLY);
|
||||
return ((fd >= 0) ? fd_to_buffered_stream (fd) : (BUFFERED_STREAM *)NULL);
|
||||
}
|
||||
|
||||
/* Deallocate a buffered stream and free up its resources. Make sure we
|
||||
zero out the slot in BUFFERS that points to BP. */
|
||||
void
|
||||
free_buffered_stream (bp)
|
||||
BUFFERED_STREAM *bp;
|
||||
{
|
||||
int n;
|
||||
|
||||
if (!bp)
|
||||
return;
|
||||
|
||||
n = bp->b_fd;
|
||||
if (bp->b_buffer)
|
||||
free (bp->b_buffer);
|
||||
free (bp);
|
||||
buffers[n] = (BUFFERED_STREAM *)NULL;
|
||||
}
|
||||
|
||||
/* Close the file descriptor associated with BP, a buffered stream, and free
|
||||
up the stream. Return the status of closing BP's file descriptor. */
|
||||
int
|
||||
close_buffered_stream (bp)
|
||||
BUFFERED_STREAM *bp;
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (!bp)
|
||||
return (0);
|
||||
fd = bp->b_fd;
|
||||
free_buffered_stream (bp);
|
||||
return (close (fd));
|
||||
}
|
||||
|
||||
/* Deallocate the buffered stream associated with file descriptor FD, and
|
||||
close FD. Return the status of the close on FD. */
|
||||
int
|
||||
close_buffered_fd (fd)
|
||||
int fd;
|
||||
{
|
||||
if (fd < 0)
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
if (fd >= nbuffers || !buffers || !buffers[fd])
|
||||
return (close (fd));
|
||||
return (close_buffered_stream (buffers[fd]));
|
||||
}
|
||||
|
||||
/* Make the BUFFERED_STREAM associcated with buffers[FD] be BP, and return
|
||||
the old BUFFERED_STREAM. */
|
||||
BUFFERED_STREAM *
|
||||
set_buffered_stream (fd, bp)
|
||||
int fd;
|
||||
BUFFERED_STREAM *bp;
|
||||
{
|
||||
BUFFERED_STREAM *ret;
|
||||
|
||||
ret = buffers[fd];
|
||||
buffers[fd] = bp;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Read a buffer full of characters from BP, a buffered stream. */
|
||||
static int
|
||||
b_fill_buffer (bp)
|
||||
BUFFERED_STREAM *bp;
|
||||
{
|
||||
ssize_t nr;
|
||||
off_t o;
|
||||
|
||||
CHECK_TERMSIG;
|
||||
/* In an environment where text and binary files are treated differently,
|
||||
compensate for lseek() on text files returning an offset different from
|
||||
the count of characters read() returns. Text-mode streams have to be
|
||||
treated as unbuffered. */
|
||||
if ((bp->b_flag & (B_TEXT | B_UNBUFF)) == B_TEXT)
|
||||
{
|
||||
o = lseek (bp->b_fd, 0, SEEK_CUR);
|
||||
nr = zread (bp->b_fd, bp->b_buffer, bp->b_size);
|
||||
if (nr > 0 && nr < lseek (bp->b_fd, 0, SEEK_CUR) - o)
|
||||
{
|
||||
lseek (bp->b_fd, o, SEEK_SET);
|
||||
bp->b_flag |= B_UNBUFF;
|
||||
bp->b_size = 1;
|
||||
nr = zread (bp->b_fd, bp->b_buffer, bp->b_size);
|
||||
}
|
||||
}
|
||||
else
|
||||
nr = zread (bp->b_fd, bp->b_buffer, bp->b_size);
|
||||
if (nr <= 0)
|
||||
{
|
||||
bp->b_used = 0;
|
||||
bp->b_buffer[0] = 0;
|
||||
if (nr == 0)
|
||||
bp->b_flag |= B_EOF;
|
||||
else
|
||||
bp->b_flag |= B_ERROR;
|
||||
return (EOF);
|
||||
}
|
||||
|
||||
bp->b_used = nr;
|
||||
bp->b_inputp = 0;
|
||||
return (bp->b_buffer[bp->b_inputp++] & 0xFF);
|
||||
}
|
||||
|
||||
/* Get a character from buffered stream BP. */
|
||||
#define bufstream_getc(bp) \
|
||||
(bp->b_inputp == bp->b_used || !bp->b_used) \
|
||||
? b_fill_buffer (bp) \
|
||||
: bp->b_buffer[bp->b_inputp++] & 0xFF
|
||||
|
||||
/* Push C back onto buffered stream BP. */
|
||||
static int
|
||||
bufstream_ungetc(c, bp)
|
||||
int c;
|
||||
BUFFERED_STREAM *bp;
|
||||
{
|
||||
if (c == EOF || bp->b_inputp == 0)
|
||||
return (EOF);
|
||||
|
||||
bp->b_buffer[--bp->b_inputp] = c;
|
||||
return (c);
|
||||
}
|
||||
|
||||
/* Seek backwards on file BFD to synchronize what we've read so far
|
||||
with the underlying file pointer. */
|
||||
int
|
||||
sync_buffered_stream (bfd)
|
||||
int bfd;
|
||||
{
|
||||
BUFFERED_STREAM *bp;
|
||||
off_t chars_left;
|
||||
|
||||
if (buffers == 0 || (bp = buffers[bfd]) == 0)
|
||||
return (-1);
|
||||
|
||||
chars_left = bp->b_used - bp->b_inputp;
|
||||
if (chars_left)
|
||||
lseek (bp->b_fd, -chars_left, SEEK_CUR);
|
||||
bp->b_used = bp->b_inputp = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
buffered_getchar ()
|
||||
{
|
||||
CHECK_TERMSIG;
|
||||
|
||||
#if !defined (DJGPP)
|
||||
return (bufstream_getc (buffers[bash_input.location.buffered_fd]));
|
||||
#else
|
||||
/* On DJGPP, ignore \r. */
|
||||
int ch;
|
||||
while ((ch = bufstream_getc (buffers[bash_input.location.buffered_fd])) == '\r')
|
||||
;
|
||||
return ch;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
buffered_ungetchar (c)
|
||||
int c;
|
||||
{
|
||||
return (bufstream_ungetc (c, buffers[bash_input.location.buffered_fd]));
|
||||
}
|
||||
|
||||
/* Make input come from file descriptor BFD through a buffered stream. */
|
||||
void
|
||||
with_input_from_buffered_stream (bfd, name)
|
||||
int bfd;
|
||||
char *name;
|
||||
{
|
||||
INPUT_STREAM location;
|
||||
BUFFERED_STREAM *bp;
|
||||
|
||||
location.buffered_fd = bfd;
|
||||
/* Make sure the buffered stream exists. */
|
||||
bp = fd_to_buffered_stream (bfd);
|
||||
init_yy_io (bp == 0 ? return_EOF : buffered_getchar,
|
||||
buffered_ungetchar, st_bstream, name, location);
|
||||
}
|
||||
|
||||
#if defined (TEST)
|
||||
void *
|
||||
xmalloc(s)
|
||||
int s;
|
||||
{
|
||||
return (malloc (s));
|
||||
}
|
||||
|
||||
void *
|
||||
xrealloc(s, size)
|
||||
char *s;
|
||||
int size;
|
||||
{
|
||||
if (!s)
|
||||
return(malloc (size));
|
||||
else
|
||||
return(realloc (s, size));
|
||||
}
|
||||
|
||||
void
|
||||
init_yy_io ()
|
||||
{
|
||||
}
|
||||
|
||||
process(bp)
|
||||
BUFFERED_STREAM *bp;
|
||||
{
|
||||
int c;
|
||||
|
||||
while ((c = bufstream_getc(bp)) != EOF)
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
BASH_INPUT bash_input;
|
||||
|
||||
struct stat dsb; /* can be used from gdb */
|
||||
|
||||
/* imitate /bin/cat */
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
register int i;
|
||||
BUFFERED_STREAM *bp;
|
||||
|
||||
if (argc == 1) {
|
||||
bp = fd_to_buffered_stream (0);
|
||||
process(bp);
|
||||
exit(0);
|
||||
}
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-' && argv[i][1] == '\0') {
|
||||
bp = fd_to_buffered_stream (0);
|
||||
if (!bp)
|
||||
continue;
|
||||
process(bp);
|
||||
free_buffered_stream (bp);
|
||||
} else {
|
||||
bp = open_buffered_stream (argv[i]);
|
||||
if (!bp)
|
||||
continue;
|
||||
process(bp);
|
||||
close_buffered_stream (bp);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
#endif /* TEST */
|
||||
#endif /* BUFFERED_INPUT */
|
||||
-1291
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
-1359
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,76 +0,0 @@
|
||||
# This makefile for Readline library documentation is in -*- text -*- mode.
|
||||
# Emacs likes it that way.
|
||||
RM = rm -f
|
||||
|
||||
MAKEINFO = makeinfo
|
||||
TEXI2DVI = texi2dvi
|
||||
TEXI2HTML = texi2html
|
||||
QUIETPS = #set this to -q to shut up dvips
|
||||
DVIPS = dvips -D 300 $(QUIETPS) -o $@ # tricky
|
||||
|
||||
INSTALL_DATA = cp
|
||||
infodir = /usr/local/info
|
||||
|
||||
RLSRC = rlman.texinfo rluser.texinfo rltech.texinfo
|
||||
HISTSRC = hist.texinfo hsuser.texinfo hstech.texinfo
|
||||
|
||||
DVIOBJ = readline.dvi history.dvi
|
||||
INFOOBJ = readline.info history.info
|
||||
PSOBJ = readline.ps history.ps
|
||||
HTMLOBJ = readline.html history.html
|
||||
|
||||
all: info dvi html ps
|
||||
nodvi: info html
|
||||
|
||||
readline.dvi: $(RLSRC)
|
||||
$(TEXI2DVI) rlman.texinfo
|
||||
mv rlman.dvi readline.dvi
|
||||
|
||||
readline.info: $(RLSRC)
|
||||
$(MAKEINFO) --no-split -o $@ rlman.texinfo
|
||||
|
||||
history.dvi: ${HISTSRC}
|
||||
$(TEXI2DVI) hist.texinfo
|
||||
mv hist.dvi history.dvi
|
||||
|
||||
history.info: ${HISTSRC}
|
||||
$(MAKEINFO) --no-split -o $@ hist.texinfo
|
||||
|
||||
readline.ps: readline.dvi
|
||||
$(RM) $@
|
||||
$(DVIPS) readline.dvi
|
||||
|
||||
history.ps: history.dvi
|
||||
$(RM) $@
|
||||
$(DVIPS) history.dvi
|
||||
|
||||
readline.html: ${RLSRC}
|
||||
$(TEXI2HTML) rlman.texinfo
|
||||
sed -e 's:rlman.html:readline.html:' -e 's:rlman_toc.html:readline_toc.html:' rlman.html > readline.html
|
||||
sed -e 's:rlman.html:readline.html:' -e 's:rlman_toc.html:readline_toc.html:' rlman_toc.html > readline_toc.html
|
||||
$(RM) rlman.html rlman_toc.html
|
||||
|
||||
history.html: ${HISTSRC}
|
||||
$(TEXI2HTML) hist.texinfo
|
||||
sed -e 's:hist.html:history.html:' -e 's:hist_toc.html:history_toc.html:' hist.html > history.html
|
||||
sed -e 's:hist.html:history.html:' -e 's:hist_toc.html:history_toc.html:' hist_toc.html > history_toc.html
|
||||
$(RM) hist.html hist_toc.html
|
||||
|
||||
info: $(INFOOBJ)
|
||||
dvi: $(DVIOBJ)
|
||||
ps: $(PSOBJ)
|
||||
html: $(HTMLOBJ)
|
||||
|
||||
clean:
|
||||
$(RM) *.aux *.cp *.fn *.ky *.log *.pg *.toc *.tp *.vr *.cps *.pgs \
|
||||
*.fns *.kys *.tps *.vrs *.o core
|
||||
|
||||
distclean: clean
|
||||
mostlyclean: clean
|
||||
|
||||
maintainer-clean: clean
|
||||
$(RM) *.dvi *.info *.info-* *.ps *.html
|
||||
|
||||
install: info
|
||||
${INSTALL_DATA} readline.info $(infodir)/readline.info
|
||||
${INSTALL_DATA} history.info $(infodir)/history.info
|
||||
-200
@@ -1,200 +0,0 @@
|
||||
/* zread - read data from file descriptor into buffer with retries */
|
||||
|
||||
/* Copyright (C) 1999-2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 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>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_CUR
|
||||
# define SEEK_CUR 1
|
||||
#endif
|
||||
|
||||
extern void check_signals_and_traps (void);
|
||||
|
||||
/* Read LEN bytes from FD into BUF. Retry the read on EINTR. Any other
|
||||
error causes the loop to break. */
|
||||
ssize_t
|
||||
zread (fd, buf, len)
|
||||
int fd;
|
||||
char *buf;
|
||||
size_t len;
|
||||
{
|
||||
ssize_t r;
|
||||
|
||||
while ((r = read (fd, buf, len)) < 0 && errno == EINTR)
|
||||
check_signals_and_traps (); /* XXX */
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Read LEN bytes from FD into BUF. Retry the read on EINTR, up to three
|
||||
interrupts. Any other error causes the loop to break. */
|
||||
|
||||
#ifdef NUM_INTR
|
||||
# undef NUM_INTR
|
||||
#endif
|
||||
#define NUM_INTR 3
|
||||
|
||||
ssize_t
|
||||
zreadretry (fd, buf, len)
|
||||
int fd;
|
||||
char *buf;
|
||||
size_t len;
|
||||
{
|
||||
ssize_t r;
|
||||
int nintr;
|
||||
|
||||
for (nintr = 0; ; )
|
||||
{
|
||||
r = read (fd, buf, len);
|
||||
if (r >= 0)
|
||||
return r;
|
||||
if (r == -1 && errno == EINTR)
|
||||
{
|
||||
if (++nintr >= NUM_INTR)
|
||||
return -1;
|
||||
continue;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
/* Call read(2) and allow it to be interrupted. Just a stub for now. */
|
||||
ssize_t
|
||||
zreadintr (fd, buf, len)
|
||||
int fd;
|
||||
char *buf;
|
||||
size_t len;
|
||||
{
|
||||
return (read (fd, buf, len));
|
||||
}
|
||||
|
||||
/* Read one character from FD and return it in CP. Return values are as
|
||||
in read(2). This does some local buffering to avoid many one-character
|
||||
calls to read(2), like those the `read' builtin performs. */
|
||||
|
||||
static char lbuf[128];
|
||||
static size_t lind, lused;
|
||||
|
||||
ssize_t
|
||||
zreadc (fd, cp)
|
||||
int fd;
|
||||
char *cp;
|
||||
{
|
||||
ssize_t nr;
|
||||
|
||||
if (lind == lused || lused == 0)
|
||||
{
|
||||
nr = zread (fd, lbuf, sizeof (lbuf));
|
||||
lind = 0;
|
||||
if (nr <= 0)
|
||||
{
|
||||
lused = 0;
|
||||
return nr;
|
||||
}
|
||||
lused = nr;
|
||||
}
|
||||
if (cp)
|
||||
*cp = lbuf[lind++];
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Don't mix calls to zreadc and zreadcintr in the same function, since they
|
||||
use the same local buffer. */
|
||||
ssize_t
|
||||
zreadcintr (fd, cp)
|
||||
int fd;
|
||||
char *cp;
|
||||
{
|
||||
ssize_t nr;
|
||||
|
||||
if (lind == lused || lused == 0)
|
||||
{
|
||||
nr = zreadintr (fd, lbuf, sizeof (lbuf));
|
||||
lind = 0;
|
||||
if (nr <= 0)
|
||||
{
|
||||
lused = 0;
|
||||
return nr;
|
||||
}
|
||||
lused = nr;
|
||||
}
|
||||
if (cp)
|
||||
*cp = lbuf[lind++];
|
||||
return 1;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
zreadn (fd, cp, len)
|
||||
int fd;
|
||||
char *cp;
|
||||
size_t len;
|
||||
{
|
||||
ssize_t nr;
|
||||
|
||||
if (lind == lused || lused == 0)
|
||||
{
|
||||
if (len > sizeof (lbuf))
|
||||
len = sizeof (lbuf);
|
||||
nr = zread (fd, lbuf, len);
|
||||
lind = 0;
|
||||
if (nr <= 0)
|
||||
{
|
||||
lused = 0;
|
||||
return nr;
|
||||
}
|
||||
lused = nr;
|
||||
}
|
||||
if (cp)
|
||||
*cp = lbuf[lind++];
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
zreset ()
|
||||
{
|
||||
lind = lused = 0;
|
||||
}
|
||||
|
||||
/* Sync the seek pointer for FD so that the kernel's idea of the last char
|
||||
read is the last char returned by zreadc. */
|
||||
void
|
||||
zsyncfd (fd)
|
||||
int fd;
|
||||
{
|
||||
off_t off, r;
|
||||
|
||||
off = lused - lind;
|
||||
r = 0;
|
||||
if (off > 0)
|
||||
r = lseek (fd, -off, SEEK_CUR);
|
||||
|
||||
if (r != -1)
|
||||
lused = lind = 0;
|
||||
}
|
||||
-6114
File diff suppressed because it is too large
Load Diff
@@ -1,30 +0,0 @@
|
||||
/* patchlevel.h -- current bash patch level */
|
||||
|
||||
/* Copyright (C) 2001-2012 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 (_PATCHLEVEL_H_)
|
||||
#define _PATCHLEVEL_H_
|
||||
|
||||
/* It's important that there be no other strings in this file that match the
|
||||
regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
|
||||
looks for to find the patch level (for the sccs version string). */
|
||||
|
||||
#define PATCHLEVEL 39
|
||||
|
||||
#endif /* _PATCHLEVEL_H_ */
|
||||
-186
@@ -1,186 +0,0 @@
|
||||
/* shell.h -- The data structures used by the shell */
|
||||
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "bashjmp.h"
|
||||
|
||||
#include "command.h"
|
||||
#include "syntax.h"
|
||||
#include "general.h"
|
||||
#include "error.h"
|
||||
#include "variables.h"
|
||||
#include "arrayfunc.h"
|
||||
#include "quit.h"
|
||||
#include "maxpath.h"
|
||||
#include "unwind_prot.h"
|
||||
#include "dispose_cmd.h"
|
||||
#include "make_cmd.h"
|
||||
#include "ocache.h"
|
||||
#include "subst.h"
|
||||
#include "sig.h"
|
||||
#include "pathnames.h"
|
||||
#include "externs.h"
|
||||
|
||||
extern int EOF_Reached;
|
||||
|
||||
#define NO_PIPE -1
|
||||
#define REDIRECT_BOTH -2
|
||||
|
||||
#define NO_VARIABLE -1
|
||||
|
||||
/* Values that can be returned by execute_command (). */
|
||||
#define EXECUTION_FAILURE 1
|
||||
#define EXECUTION_SUCCESS 0
|
||||
|
||||
/* Usage messages by builtins result in a return status of 2. */
|
||||
#define EX_BADUSAGE 2
|
||||
|
||||
#define EX_MISCERROR 2
|
||||
|
||||
/* Special exit statuses used by the shell, internally and externally. */
|
||||
#define EX_RETRYFAIL 124
|
||||
#define EX_WEXPCOMSUB 125
|
||||
#define EX_BINARY_FILE 126
|
||||
#define EX_NOEXEC 126
|
||||
#define EX_NOINPUT 126
|
||||
#define EX_NOTFOUND 127
|
||||
|
||||
#define EX_SHERRBASE 256 /* all special error values are > this. */
|
||||
|
||||
#define EX_BADSYNTAX 257 /* shell syntax error */
|
||||
#define EX_USAGE 258 /* syntax error in usage */
|
||||
#define EX_REDIRFAIL 259 /* redirection failed */
|
||||
#define EX_BADASSIGN 260 /* variable assignment error */
|
||||
#define EX_EXPFAIL 261 /* word expansion failed */
|
||||
|
||||
/* Flag values that control parameter pattern substitution. */
|
||||
#define MATCH_ANY 0x000
|
||||
#define MATCH_BEG 0x001
|
||||
#define MATCH_END 0x002
|
||||
|
||||
#define MATCH_TYPEMASK 0x003
|
||||
|
||||
#define MATCH_GLOBREP 0x010
|
||||
#define MATCH_QUOTED 0x020
|
||||
#define MATCH_STARSUB 0x040
|
||||
|
||||
/* Some needed external declarations. */
|
||||
extern char **shell_environment;
|
||||
extern WORD_LIST *rest_of_args;
|
||||
|
||||
/* Generalized global variables. */
|
||||
extern int debugging_mode;
|
||||
extern int executing, login_shell;
|
||||
extern int interactive, interactive_shell;
|
||||
extern int startup_state;
|
||||
extern int subshell_environment;
|
||||
extern int shell_compatibility_level;
|
||||
|
||||
extern int locale_mb_cur_max;
|
||||
|
||||
/* Structure to pass around that holds a bitmap of file descriptors
|
||||
to close, and the size of that structure. Used in execute_cmd.c. */
|
||||
struct fd_bitmap {
|
||||
int size;
|
||||
char *bitmap;
|
||||
};
|
||||
|
||||
#define FD_BITMAP_SIZE 32
|
||||
|
||||
#define CTLESC '\001'
|
||||
#define CTLNUL '\177'
|
||||
|
||||
/* Information about the current user. */
|
||||
struct user_info {
|
||||
uid_t uid, euid;
|
||||
gid_t gid, egid;
|
||||
char *user_name;
|
||||
char *shell; /* shell from the password file */
|
||||
char *home_dir;
|
||||
};
|
||||
|
||||
extern struct user_info current_user;
|
||||
|
||||
/* Force gcc to not clobber X on a longjmp(). Old versions of gcc mangle
|
||||
this badly. */
|
||||
#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ > 8)
|
||||
# define USE_VAR(x) ((void) &(x))
|
||||
#else
|
||||
# define USE_VAR(x)
|
||||
#endif
|
||||
|
||||
/* Structure in which to save partial parsing state when doing things like
|
||||
PROMPT_COMMAND and bash_execute_unix_command execution. */
|
||||
|
||||
typedef struct _sh_parser_state_t {
|
||||
|
||||
/* parsing state */
|
||||
int parser_state;
|
||||
int *token_state;
|
||||
|
||||
char *token;
|
||||
int token_buffer_size;
|
||||
|
||||
/* input line state -- line number saved elsewhere */
|
||||
int input_line_terminator;
|
||||
int eof_encountered;
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
/* Nothing right now for multibyte state, but might want something later. */
|
||||
#endif
|
||||
|
||||
char **prompt_string_pointer;
|
||||
|
||||
/* history state affecting or modified by the parser */
|
||||
int current_command_line_count;
|
||||
#if defined (HISTORY)
|
||||
int remember_on_history;
|
||||
int history_expansion_inhibited;
|
||||
#endif
|
||||
|
||||
/* execution state possibly modified by the parser */
|
||||
int last_command_exit_value;
|
||||
#if defined (ARRAY_VARS)
|
||||
ARRAY *pipestatus;
|
||||
#endif
|
||||
sh_builtin_func_t *last_shell_builtin, *this_shell_builtin;
|
||||
|
||||
/* flags state affecting the parser */
|
||||
int expand_aliases;
|
||||
int echo_input_at_read;
|
||||
|
||||
} sh_parser_state_t;
|
||||
|
||||
typedef struct _sh_input_line_state_t {
|
||||
char *input_line;
|
||||
int input_line_index;
|
||||
int input_line_size;
|
||||
int input_line_len;
|
||||
} sh_input_line_state_t;
|
||||
|
||||
/* Let's try declaring these here. */
|
||||
extern sh_parser_state_t *save_parser_state __P((sh_parser_state_t *));
|
||||
extern void restore_parser_state __P((sh_parser_state_t *));
|
||||
|
||||
extern sh_input_line_state_t *save_input_line_state __P((sh_input_line_state_t *));
|
||||
extern void restore_input_line_state __P((sh_input_line_state_t *));
|
||||
@@ -1,186 +0,0 @@
|
||||
/* shell.h -- The data structures used by the shell */
|
||||
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "bashjmp.h"
|
||||
|
||||
#include "command.h"
|
||||
#include "syntax.h"
|
||||
#include "general.h"
|
||||
#include "error.h"
|
||||
#include "variables.h"
|
||||
#include "arrayfunc.h"
|
||||
#include "quit.h"
|
||||
#include "maxpath.h"
|
||||
#include "unwind_prot.h"
|
||||
#include "dispose_cmd.h"
|
||||
#include "make_cmd.h"
|
||||
#include "ocache.h"
|
||||
#include "subst.h"
|
||||
#include "sig.h"
|
||||
#include "pathnames.h"
|
||||
#include "externs.h"
|
||||
|
||||
extern int EOF_Reached;
|
||||
|
||||
#define NO_PIPE -1
|
||||
#define REDIRECT_BOTH -2
|
||||
|
||||
#define NO_VARIABLE -1
|
||||
|
||||
/* Values that can be returned by execute_command (). */
|
||||
#define EXECUTION_FAILURE 1
|
||||
#define EXECUTION_SUCCESS 0
|
||||
|
||||
/* Usage messages by builtins result in a return status of 2. */
|
||||
#define EX_BADUSAGE 2
|
||||
|
||||
#define EX_MISCERROR 2
|
||||
|
||||
/* Special exit statuses used by the shell, internally and externally. */
|
||||
#define EX_RETRYFAIL 124
|
||||
#define EX_WEXPCOMSUB 125
|
||||
#define EX_BINARY_FILE 126
|
||||
#define EX_NOEXEC 126
|
||||
#define EX_NOINPUT 126
|
||||
#define EX_NOTFOUND 127
|
||||
|
||||
#define EX_SHERRBASE 256 /* all special error values are > this. */
|
||||
|
||||
#define EX_BADSYNTAX 257 /* shell syntax error */
|
||||
#define EX_USAGE 258 /* syntax error in usage */
|
||||
#define EX_REDIRFAIL 259 /* redirection failed */
|
||||
#define EX_BADASSIGN 260 /* variable assignment error */
|
||||
#define EX_EXPFAIL 261 /* word expansion failed */
|
||||
|
||||
/* Flag values that control parameter pattern substitution. */
|
||||
#define MATCH_ANY 0x000
|
||||
#define MATCH_BEG 0x001
|
||||
#define MATCH_END 0x002
|
||||
|
||||
#define MATCH_TYPEMASK 0x003
|
||||
|
||||
#define MATCH_GLOBREP 0x010
|
||||
#define MATCH_QUOTED 0x020
|
||||
#define MATCH_STARSUB 0x040
|
||||
|
||||
/* Some needed external declarations. */
|
||||
extern char **shell_environment;
|
||||
extern WORD_LIST *rest_of_args;
|
||||
|
||||
/* Generalized global variables. */
|
||||
extern int debugging_mode;
|
||||
extern int executing, login_shell;
|
||||
extern int interactive, interactive_shell;
|
||||
extern int startup_state;
|
||||
extern int subshell_environment;
|
||||
extern int shell_compatibility_level;
|
||||
|
||||
extern int locale_mb_cur_max;
|
||||
|
||||
/* Structure to pass around that holds a bitmap of file descriptors
|
||||
to close, and the size of that structure. Used in execute_cmd.c. */
|
||||
struct fd_bitmap {
|
||||
int size;
|
||||
char *bitmap;
|
||||
};
|
||||
|
||||
#define FD_BITMAP_SIZE 32
|
||||
|
||||
#define CTLESC '\001'
|
||||
#define CTLNUL '\177'
|
||||
|
||||
/* Information about the current user. */
|
||||
struct user_info {
|
||||
uid_t uid, euid;
|
||||
gid_t gid, egid;
|
||||
char *user_name;
|
||||
char *shell; /* shell from the password file */
|
||||
char *home_dir;
|
||||
};
|
||||
|
||||
extern struct user_info current_user;
|
||||
|
||||
/* Force gcc to not clobber X on a longjmp(). Old versions of gcc mangle
|
||||
this badly. */
|
||||
#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ > 8)
|
||||
# define USE_VAR(x) ((void) &(x))
|
||||
#else
|
||||
# define USE_VAR(x)
|
||||
#endif
|
||||
|
||||
/* Structure in which to save partial parsing state when doing things like
|
||||
PROMPT_COMMAND and bash_execute_unix_command execution. */
|
||||
|
||||
typedef struct _sh_parser_state_t {
|
||||
|
||||
/* parsing state */
|
||||
int parser_state;
|
||||
int *token_state;
|
||||
|
||||
char *token;
|
||||
int token_buffer_size;
|
||||
|
||||
/* input line state -- line number saved elsewhere */
|
||||
int input_line_terminator;
|
||||
int eof_encountered;
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
/* Nothing right now for multibyte state, but might want something later. */
|
||||
#endif
|
||||
|
||||
char **prompt_string_pointer;
|
||||
|
||||
/* history state affecting or modified by the parser */
|
||||
int current_command_line_count;
|
||||
#if defined (HISTORY)
|
||||
int remember_on_history;
|
||||
int history_expansion_inhibited;
|
||||
#endif
|
||||
|
||||
/* execution state possibly modified by the parser */
|
||||
int last_command_exit_value;
|
||||
#if defined (ARRAY_VARS)
|
||||
ARRAY *pipestatus;
|
||||
#endif
|
||||
sh_builtin_func_t *last_shell_builtin, *this_shell_builtin;
|
||||
|
||||
/* flags state affecting the parser */
|
||||
int expand_aliases;
|
||||
int echo_input_at_read;
|
||||
|
||||
} sh_parser_state_t;
|
||||
|
||||
typedef struct _sh_input_line_state_t {
|
||||
char *input_line;
|
||||
int input_line_index;
|
||||
int input_line_size;
|
||||
int input_line_len;
|
||||
} sh_input_line_state_t;
|
||||
|
||||
/* Let's try declaring these here. */
|
||||
extern sh_parser_state_t *save_parser_state __P((sh_parser_state_t *));
|
||||
extern void restore_parser_state __P((sh_parser_state_t *));
|
||||
|
||||
extern sh_input_line_state_t *save_input_line_state __P((sh_input_line_state_t *));
|
||||
extern void restore_input_line_state __P((sh_input_line_state_t *));
|
||||
@@ -1,313 +0,0 @@
|
||||
/* subst.h -- Names of externally visible functions in subst.c. */
|
||||
|
||||
/* Copyright (C) 1993-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/>.
|
||||
*/
|
||||
|
||||
#if !defined (_SUBST_H_)
|
||||
#define _SUBST_H_
|
||||
|
||||
#include "stdc.h"
|
||||
|
||||
/* Constants which specify how to handle backslashes and quoting in
|
||||
expand_word_internal (). Q_DOUBLE_QUOTES means to use the function
|
||||
slashify_in_quotes () to decide whether the backslash should be
|
||||
retained. Q_HERE_DOCUMENT means slashify_in_here_document () to
|
||||
decide whether to retain the backslash. Q_KEEP_BACKSLASH means
|
||||
to unconditionally retain the backslash. Q_PATQUOTE means that we're
|
||||
expanding a pattern ${var%#[#%]pattern} in an expansion surrounded
|
||||
by double quotes. Q_DOLBRACE means we are expanding a ${...} word, so
|
||||
backslashes should also escape { and } and be removed. */
|
||||
#define Q_DOUBLE_QUOTES 0x01
|
||||
#define Q_HERE_DOCUMENT 0x02
|
||||
#define Q_KEEP_BACKSLASH 0x04
|
||||
#define Q_PATQUOTE 0x08
|
||||
#define Q_QUOTED 0x10
|
||||
#define Q_ADDEDQUOTES 0x20
|
||||
#define Q_QUOTEDNULL 0x40
|
||||
#define Q_DOLBRACE 0x80
|
||||
|
||||
/* Flag values controlling how assignment statements are treated. */
|
||||
#define ASS_APPEND 0x01
|
||||
#define ASS_MKLOCAL 0x02
|
||||
#define ASS_MKASSOC 0x04
|
||||
|
||||
/* Flags for the string extraction functions. */
|
||||
#define SX_NOALLOC 0x0001 /* just skip; don't return substring */
|
||||
#define SX_VARNAME 0x0002 /* variable name; for string_extract () */
|
||||
#define SX_REQMATCH 0x0004 /* closing/matching delimiter required */
|
||||
#define SX_COMMAND 0x0008 /* extracting a shell script/command */
|
||||
#define SX_NOCTLESC 0x0010 /* don't honor CTLESC quoting */
|
||||
#define SX_NOESCCTLNUL 0x0020 /* don't let CTLESC quote CTLNUL */
|
||||
#define SX_NOLONGJMP 0x0040 /* don't longjmp on fatal error */
|
||||
#define SX_ARITHSUB 0x0080 /* extracting $(( ... )) (currently unused) */
|
||||
#define SX_POSIXEXP 0x0100 /* extracting new Posix pattern removal expansions in extract_dollar_brace_string */
|
||||
#define SX_WORD 0x0200 /* extracting word in ${param op word} */
|
||||
|
||||
/* Remove backslashes which are quoting backquotes from STRING. Modifies
|
||||
STRING, and returns a pointer to it. */
|
||||
extern char * de_backslash __P((char *));
|
||||
|
||||
/* Replace instances of \! in a string with !. */
|
||||
extern void unquote_bang __P((char *));
|
||||
|
||||
/* Extract the $( construct in STRING, and return a new string.
|
||||
Start extracting at (SINDEX) as if we had just seen "$(".
|
||||
Make (SINDEX) get the position just after the matching ")".
|
||||
XFLAGS is additional flags to pass to other extraction functions, */
|
||||
extern char *extract_command_subst __P((char *, int *, int));
|
||||
|
||||
/* Extract the $[ construct in STRING, and return a new string.
|
||||
Start extracting at (SINDEX) as if we had just seen "$[".
|
||||
Make (SINDEX) get the position just after the matching "]". */
|
||||
extern char *extract_arithmetic_subst __P((char *, int *));
|
||||
|
||||
#if defined (PROCESS_SUBSTITUTION)
|
||||
/* Extract the <( or >( construct in STRING, and return a new string.
|
||||
Start extracting at (SINDEX) as if we had just seen "<(".
|
||||
Make (SINDEX) get the position just after the matching ")". */
|
||||
extern char *extract_process_subst __P((char *, char *, int *));
|
||||
#endif /* PROCESS_SUBSTITUTION */
|
||||
|
||||
/* Extract the name of the variable to bind to from the assignment string. */
|
||||
extern char *assignment_name __P((char *));
|
||||
|
||||
/* Return a single string of all the words present in LIST, separating
|
||||
each word with SEP. */
|
||||
extern char *string_list_internal __P((WORD_LIST *, char *));
|
||||
|
||||
/* Return a single string of all the words present in LIST, separating
|
||||
each word with a space. */
|
||||
extern char *string_list __P((WORD_LIST *));
|
||||
|
||||
/* Turn $* into a single string, obeying POSIX rules. */
|
||||
extern char *string_list_dollar_star __P((WORD_LIST *));
|
||||
|
||||
/* Expand $@ into a single string, obeying POSIX rules. */
|
||||
extern char *string_list_dollar_at __P((WORD_LIST *, int));
|
||||
|
||||
/* Turn the positional paramters into a string, understanding quoting and
|
||||
the various subtleties of using the first character of $IFS as the
|
||||
separator. Calls string_list_dollar_at, string_list_dollar_star, and
|
||||
string_list as appropriate. */
|
||||
extern char *string_list_pos_params __P((int, WORD_LIST *, int));
|
||||
|
||||
/* Perform quoted null character removal on each element of LIST.
|
||||
This modifies LIST. */
|
||||
extern void word_list_remove_quoted_nulls __P((WORD_LIST *));
|
||||
|
||||
/* This performs word splitting and quoted null character removal on
|
||||
STRING. */
|
||||
extern WORD_LIST *list_string __P((char *, char *, int));
|
||||
|
||||
extern char *ifs_firstchar __P((int *));
|
||||
extern char *get_word_from_string __P((char **, char *, char **));
|
||||
extern char *strip_trailing_ifs_whitespace __P((char *, char *, int));
|
||||
|
||||
/* Given STRING, an assignment string, get the value of the right side
|
||||
of the `=', and bind it to the left side. If EXPAND is true, then
|
||||
perform tilde expansion, parameter expansion, command substitution,
|
||||
and arithmetic expansion on the right-hand side. Do not perform word
|
||||
splitting on the result of expansion. */
|
||||
extern int do_assignment __P((char *));
|
||||
extern int do_assignment_no_expand __P((char *));
|
||||
extern int do_word_assignment __P((WORD_DESC *, int));
|
||||
|
||||
/* Append SOURCE to TARGET at INDEX. SIZE is the current amount
|
||||
of space allocated to TARGET. SOURCE can be NULL, in which
|
||||
case nothing happens. Gets rid of SOURCE by free ()ing it.
|
||||
Returns TARGET in case the location has changed. */
|
||||
extern char *sub_append_string __P((char *, char *, int *, int *));
|
||||
|
||||
/* Append the textual representation of NUMBER to TARGET.
|
||||
INDEX and SIZE are as in SUB_APPEND_STRING. */
|
||||
extern char *sub_append_number __P((intmax_t, char *, int *, int *));
|
||||
|
||||
/* Return the word list that corresponds to `$*'. */
|
||||
extern WORD_LIST *list_rest_of_args __P((void));
|
||||
|
||||
/* Make a single large string out of the dollar digit variables,
|
||||
and the rest_of_args. If DOLLAR_STAR is 1, then obey the special
|
||||
case of "$*" with respect to IFS. */
|
||||
extern char *string_rest_of_args __P((int));
|
||||
|
||||
extern int number_of_args __P((void));
|
||||
|
||||
/* Expand STRING by performing parameter expansion, command substitution,
|
||||
and arithmetic expansion. Dequote the resulting WORD_LIST before
|
||||
returning it, but do not perform word splitting. The call to
|
||||
remove_quoted_nulls () is made here because word splitting normally
|
||||
takes care of quote removal. */
|
||||
extern WORD_LIST *expand_string_unsplit __P((char *, int));
|
||||
|
||||
/* Expand the rhs of an assignment statement. */
|
||||
extern WORD_LIST *expand_string_assignment __P((char *, int));
|
||||
|
||||
/* Expand a prompt string. */
|
||||
extern WORD_LIST *expand_prompt_string __P((char *, int, int));
|
||||
|
||||
/* Expand STRING just as if you were expanding a word. This also returns
|
||||
a list of words. Note that filename globbing is *NOT* done for word
|
||||
or string expansion, just when the shell is expanding a command. This
|
||||
does parameter expansion, command substitution, arithmetic expansion,
|
||||
and word splitting. Dequote the resultant WORD_LIST before returning. */
|
||||
extern WORD_LIST *expand_string __P((char *, int));
|
||||
|
||||
/* Convenience functions that expand strings to strings, taking care of
|
||||
converting the WORD_LIST * returned by the expand_string* functions
|
||||
to a string and deallocating the WORD_LIST *. */
|
||||
extern char *expand_string_to_string __P((char *, int));
|
||||
extern char *expand_string_unsplit_to_string __P((char *, int));
|
||||
extern char *expand_assignment_string_to_string __P((char *, int));
|
||||
|
||||
/* Expand an arithmetic expression string */
|
||||
extern char *expand_arith_string __P((char *, int));
|
||||
|
||||
/* De-quote quoted characters in STRING. */
|
||||
extern char *dequote_string __P((char *));
|
||||
|
||||
/* De-quote CTLESC-escaped CTLESC or CTLNUL characters in STRING. */
|
||||
extern char *dequote_escapes __P((char *));
|
||||
|
||||
/* De-quote quoted characters in each word in LIST. */
|
||||
extern WORD_LIST *dequote_list __P((WORD_LIST *));
|
||||
|
||||
/* Expand WORD, performing word splitting on the result. This does
|
||||
parameter expansion, command substitution, arithmetic expansion,
|
||||
word splitting, and quote removal. */
|
||||
extern WORD_LIST *expand_word __P((WORD_DESC *, int));
|
||||
|
||||
/* Expand WORD, but do not perform word splitting on the result. This
|
||||
does parameter expansion, command substitution, arithmetic expansion,
|
||||
and quote removal. */
|
||||
extern WORD_LIST *expand_word_unsplit __P((WORD_DESC *, int));
|
||||
extern WORD_LIST *expand_word_leave_quoted __P((WORD_DESC *, int));
|
||||
|
||||
/* Return the value of a positional parameter. This handles values > 10. */
|
||||
extern char *get_dollar_var_value __P((intmax_t));
|
||||
|
||||
/* Quote a string to protect it from word splitting. */
|
||||
extern char *quote_string __P((char *));
|
||||
|
||||
/* Quote escape characters (characters special to interals of expansion)
|
||||
in a string. */
|
||||
extern char *quote_escapes __P((char *));
|
||||
|
||||
/* And remove such quoted special characters. */
|
||||
extern char *remove_quoted_escapes __P((char *));
|
||||
|
||||
/* Remove CTLNUL characters from STRING unless they are quoted with CTLESC. */
|
||||
extern char *remove_quoted_nulls __P((char *));
|
||||
|
||||
/* Perform quote removal on STRING. If QUOTED > 0, assume we are obeying the
|
||||
backslash quoting rules for within double quotes. */
|
||||
extern char *string_quote_removal __P((char *, int));
|
||||
|
||||
/* Perform quote removal on word WORD. This allocates and returns a new
|
||||
WORD_DESC *. */
|
||||
extern WORD_DESC *word_quote_removal __P((WORD_DESC *, int));
|
||||
|
||||
/* Perform quote removal on all words in LIST. If QUOTED is non-zero,
|
||||
the members of the list are treated as if they are surrounded by
|
||||
double quotes. Return a new list, or NULL if LIST is NULL. */
|
||||
extern WORD_LIST *word_list_quote_removal __P((WORD_LIST *, int));
|
||||
|
||||
/* Called when IFS is changed to maintain some private variables. */
|
||||
extern void setifs __P((SHELL_VAR *));
|
||||
|
||||
/* Return the value of $IFS, or " \t\n" if IFS is unset. */
|
||||
extern char *getifs __P((void));
|
||||
|
||||
/* This splits a single word into a WORD LIST on $IFS, but only if the word
|
||||
is not quoted. list_string () performs quote removal for us, even if we
|
||||
don't do any splitting. */
|
||||
extern WORD_LIST *word_split __P((WORD_DESC *, char *));
|
||||
|
||||
/* Take the list of words in LIST and do the various substitutions. Return
|
||||
a new list of words which is the expanded list, and without things like
|
||||
variable assignments. */
|
||||
extern WORD_LIST *expand_words __P((WORD_LIST *));
|
||||
|
||||
/* Same as expand_words (), but doesn't hack variable or environment
|
||||
variables. */
|
||||
extern WORD_LIST *expand_words_no_vars __P((WORD_LIST *));
|
||||
|
||||
/* Perform the `normal shell expansions' on a WORD_LIST. These are
|
||||
brace expansion, tilde expansion, parameter and variable substitution,
|
||||
command substitution, arithmetic expansion, and word splitting. */
|
||||
extern WORD_LIST *expand_words_shellexp __P((WORD_LIST *));
|
||||
|
||||
extern WORD_DESC *command_substitute __P((char *, int));
|
||||
extern char *pat_subst __P((char *, char *, char *, int));
|
||||
|
||||
extern int fifos_pending __P((void));
|
||||
extern int num_fifos __P((void));
|
||||
extern void unlink_fifo_list __P((void));
|
||||
extern void unlink_fifo __P((int));
|
||||
|
||||
extern char *copy_fifo_list __P((int *));
|
||||
extern void unlink_new_fifos __P((char *, int));
|
||||
extern void close_new_fifos __P((char *, int));
|
||||
|
||||
extern WORD_LIST *list_string_with_quotes __P((char *));
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
extern char *extract_array_assignment_list __P((char *, int *));
|
||||
#endif
|
||||
|
||||
#if defined (COND_COMMAND)
|
||||
extern char *remove_backslashes __P((char *));
|
||||
extern char *cond_expand_word __P((WORD_DESC *, int));
|
||||
#endif
|
||||
|
||||
/* Flags for skip_to_delim */
|
||||
#define SD_NOJMP 0x01 /* don't longjmp on fatal error. */
|
||||
#define SD_INVERT 0x02 /* look for chars NOT in passed set */
|
||||
#define SD_NOQUOTEDELIM 0x04 /* don't let single or double quotes act as delimiters */
|
||||
#define SD_NOSKIPCMD 0x08 /* don't skip over $(, <(, or >( command/process substitution */
|
||||
#define SD_EXTGLOB 0x10 /* skip over extended globbing patterns if appropriate */
|
||||
|
||||
extern int skip_to_delim __P((char *, int, char *, int));
|
||||
|
||||
#if defined (READLINE)
|
||||
extern int char_is_quoted __P((char *, int));
|
||||
extern int unclosed_pair __P((char *, int, char *));
|
||||
extern WORD_LIST *split_at_delims __P((char *, int, char *, int, int, int *, int *));
|
||||
#endif
|
||||
|
||||
/* Variables used to keep track of the characters in IFS. */
|
||||
extern SHELL_VAR *ifs_var;
|
||||
extern char *ifs_value;
|
||||
extern unsigned char ifs_cmap[];
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
extern unsigned char ifs_firstc[];
|
||||
extern size_t ifs_firstc_len;
|
||||
#else
|
||||
extern unsigned char ifs_firstc;
|
||||
#endif
|
||||
|
||||
/* Evaluates to 1 if C is a character in $IFS. */
|
||||
#define isifs(c) (ifs_cmap[(unsigned char)(c)] != 0)
|
||||
|
||||
/* How to determine the quoted state of the character C. */
|
||||
#define QUOTED_CHAR(c) ((c) == CTLESC)
|
||||
|
||||
/* Is the first character of STRING a quoted NULL character? */
|
||||
#define QUOTED_NULL(string) ((string)[0] == CTLNUL && (string)[1] == '\0')
|
||||
|
||||
#endif /* !_SUBST_H_ */
|
||||
@@ -1,856 +0,0 @@
|
||||
/* test.c - GNU test program (ksb and mjb) */
|
||||
|
||||
/* Modified to run with the GNU shell Apr 25, 1988 by bfox. */
|
||||
|
||||
/* Copyright (C) 1987-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/>.
|
||||
*/
|
||||
|
||||
/* Define PATTERN_MATCHING to get the csh-like =~ and !~ pattern-matching
|
||||
binary operators. */
|
||||
/* #define PATTERN_MATCHING */
|
||||
|
||||
#if defined (HAVE_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "bashtypes.h"
|
||||
|
||||
#if !defined (HAVE_LIMITS_H) && defined (HAVE_SYS_PARAM_H)
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif /* !errno */
|
||||
|
||||
#if !defined (_POSIX_VERSION) && defined (HAVE_SYS_FILE_H)
|
||||
# include <sys/file.h>
|
||||
#endif /* !_POSIX_VERSION */
|
||||
#include "posixstat.h"
|
||||
#include "filecntl.h"
|
||||
#include "stat-time.h"
|
||||
|
||||
#include "bashintl.h"
|
||||
|
||||
#include "shell.h"
|
||||
#include "pathexp.h"
|
||||
#include "test.h"
|
||||
#include "builtins/common.h"
|
||||
|
||||
#include <glob/strmatch.h>
|
||||
|
||||
#if !defined (STRLEN)
|
||||
# define STRLEN(s) ((s)[0] ? ((s)[1] ? ((s)[2] ? strlen(s) : 2) : 1) : 0)
|
||||
#endif
|
||||
|
||||
#if !defined (STREQ)
|
||||
# define STREQ(a, b) ((a)[0] == (b)[0] && strcmp ((a), (b)) == 0)
|
||||
#endif /* !STREQ */
|
||||
#define STRCOLLEQ(a, b) ((a)[0] == (b)[0] && strcoll ((a), (b)) == 0)
|
||||
|
||||
#if !defined (R_OK)
|
||||
#define R_OK 4
|
||||
#define W_OK 2
|
||||
#define X_OK 1
|
||||
#define F_OK 0
|
||||
#endif /* R_OK */
|
||||
|
||||
#define EQ 0
|
||||
#define NE 1
|
||||
#define LT 2
|
||||
#define GT 3
|
||||
#define LE 4
|
||||
#define GE 5
|
||||
|
||||
#define NT 0
|
||||
#define OT 1
|
||||
#define EF 2
|
||||
|
||||
/* The following few defines control the truth and false output of each stage.
|
||||
TRUE and FALSE are what we use to compute the final output value.
|
||||
SHELL_BOOLEAN is the form which returns truth or falseness in shell terms.
|
||||
Default is TRUE = 1, FALSE = 0, SHELL_BOOLEAN = (!value). */
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define SHELL_BOOLEAN(value) (!(value))
|
||||
|
||||
#define TEST_ERREXIT_STATUS 2
|
||||
|
||||
static procenv_t test_exit_buf;
|
||||
static int test_error_return;
|
||||
#define test_exit(val) \
|
||||
do { test_error_return = val; longjmp (test_exit_buf, 1); } while (0)
|
||||
|
||||
extern int sh_stat __P((const char *, struct stat *));
|
||||
|
||||
static int pos; /* The offset of the current argument in ARGV. */
|
||||
static int argc; /* The number of arguments present in ARGV. */
|
||||
static char **argv; /* The argument list. */
|
||||
static int noeval;
|
||||
|
||||
static void test_syntax_error __P((char *, char *)) __attribute__((__noreturn__));
|
||||
static void beyond __P((void)) __attribute__((__noreturn__));
|
||||
static void integer_expected_error __P((char *)) __attribute__((__noreturn__));
|
||||
|
||||
static int unary_operator __P((void));
|
||||
static int binary_operator __P((void));
|
||||
static int two_arguments __P((void));
|
||||
static int three_arguments __P((void));
|
||||
static int posixtest __P((void));
|
||||
|
||||
static int expr __P((void));
|
||||
static int term __P((void));
|
||||
static int and __P((void));
|
||||
static int or __P((void));
|
||||
|
||||
static int filecomp __P((char *, char *, int));
|
||||
static int arithcomp __P((char *, char *, int, int));
|
||||
static int patcomp __P((char *, char *, int));
|
||||
|
||||
static void
|
||||
test_syntax_error (format, arg)
|
||||
char *format, *arg;
|
||||
{
|
||||
builtin_error (format, arg);
|
||||
test_exit (TEST_ERREXIT_STATUS);
|
||||
}
|
||||
|
||||
/*
|
||||
* beyond - call when we're beyond the end of the argument list (an
|
||||
* error condition)
|
||||
*/
|
||||
static void
|
||||
beyond ()
|
||||
{
|
||||
test_syntax_error (_("argument expected"), (char *)NULL);
|
||||
}
|
||||
|
||||
/* Syntax error for when an integer argument was expected, but
|
||||
something else was found. */
|
||||
static void
|
||||
integer_expected_error (pch)
|
||||
char *pch;
|
||||
{
|
||||
test_syntax_error (_("%s: integer expression expected"), pch);
|
||||
}
|
||||
|
||||
/* Increment our position in the argument list. Check that we're not
|
||||
past the end of the argument list. This check is supressed if the
|
||||
argument is FALSE. Made a macro for efficiency. */
|
||||
#define advance(f) do { ++pos; if (f && pos >= argc) beyond (); } while (0)
|
||||
#define unary_advance() do { advance (1); ++pos; } while (0)
|
||||
|
||||
/*
|
||||
* expr:
|
||||
* or
|
||||
*/
|
||||
static int
|
||||
expr ()
|
||||
{
|
||||
if (pos >= argc)
|
||||
beyond ();
|
||||
|
||||
return (FALSE ^ or ()); /* Same with this. */
|
||||
}
|
||||
|
||||
/*
|
||||
* or:
|
||||
* and
|
||||
* and '-o' or
|
||||
*/
|
||||
static int
|
||||
or ()
|
||||
{
|
||||
int value, v2;
|
||||
|
||||
value = and ();
|
||||
if (pos < argc && argv[pos][0] == '-' && argv[pos][1] == 'o' && !argv[pos][2])
|
||||
{
|
||||
advance (0);
|
||||
v2 = or ();
|
||||
return (value || v2);
|
||||
}
|
||||
|
||||
return (value);
|
||||
}
|
||||
|
||||
/*
|
||||
* and:
|
||||
* term
|
||||
* term '-a' and
|
||||
*/
|
||||
static int
|
||||
and ()
|
||||
{
|
||||
int value, v2;
|
||||
|
||||
value = term ();
|
||||
if (pos < argc && argv[pos][0] == '-' && argv[pos][1] == 'a' && !argv[pos][2])
|
||||
{
|
||||
advance (0);
|
||||
v2 = and ();
|
||||
return (value && v2);
|
||||
}
|
||||
return (value);
|
||||
}
|
||||
|
||||
/*
|
||||
* term - parse a term and return 1 or 0 depending on whether the term
|
||||
* evaluates to true or false, respectively.
|
||||
*
|
||||
* term ::=
|
||||
* '-'('a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'k'|'p'|'r'|'s'|'u'|'w'|'x') filename
|
||||
* '-'('G'|'L'|'O'|'S'|'N') filename
|
||||
* '-t' [int]
|
||||
* '-'('z'|'n') string
|
||||
* '-o' option
|
||||
* string
|
||||
* string ('!='|'='|'==') string
|
||||
* <int> '-'(eq|ne|le|lt|ge|gt) <int>
|
||||
* file '-'(nt|ot|ef) file
|
||||
* '(' <expr> ')'
|
||||
* int ::=
|
||||
* positive and negative integers
|
||||
*/
|
||||
static int
|
||||
term ()
|
||||
{
|
||||
int value;
|
||||
|
||||
if (pos >= argc)
|
||||
beyond ();
|
||||
|
||||
/* Deal with leading `not's. */
|
||||
if (argv[pos][0] == '!' && argv[pos][1] == '\0')
|
||||
{
|
||||
value = 0;
|
||||
while (pos < argc && argv[pos][0] == '!' && argv[pos][1] == '\0')
|
||||
{
|
||||
advance (1);
|
||||
value = 1 - value;
|
||||
}
|
||||
|
||||
return (value ? !term() : term());
|
||||
}
|
||||
|
||||
/* A paren-bracketed argument. */
|
||||
if (argv[pos][0] == '(' && argv[pos][1] == '\0') /* ) */
|
||||
{
|
||||
advance (1);
|
||||
value = expr ();
|
||||
if (argv[pos] == 0) /* ( */
|
||||
test_syntax_error (_("`)' expected"), (char *)NULL);
|
||||
else if (argv[pos][0] != ')' || argv[pos][1]) /* ( */
|
||||
test_syntax_error (_("`)' expected, found %s"), argv[pos]);
|
||||
advance (0);
|
||||
return (value);
|
||||
}
|
||||
|
||||
/* are there enough arguments left that this could be dyadic? */
|
||||
if ((pos + 3 <= argc) && test_binop (argv[pos + 1]))
|
||||
value = binary_operator ();
|
||||
|
||||
/* Might be a switch type argument */
|
||||
else if (argv[pos][0] == '-' && argv[pos][2] == '\0')
|
||||
{
|
||||
if (test_unop (argv[pos]))
|
||||
value = unary_operator ();
|
||||
else
|
||||
test_syntax_error (_("%s: unary operator expected"), argv[pos]);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = argv[pos][0] != '\0';
|
||||
advance (0);
|
||||
}
|
||||
|
||||
return (value);
|
||||
}
|
||||
|
||||
static int
|
||||
stat_mtime (fn, st, ts)
|
||||
char *fn;
|
||||
struct stat *st;
|
||||
struct timespec *ts;
|
||||
{
|
||||
int r;
|
||||
|
||||
r = sh_stat (fn, st);
|
||||
if (r < 0)
|
||||
return r;
|
||||
*ts = get_stat_mtime (st);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
filecomp (s, t, op)
|
||||
char *s, *t;
|
||||
int op;
|
||||
{
|
||||
struct stat st1, st2;
|
||||
struct timespec ts1, ts2;
|
||||
int r1, r2;
|
||||
|
||||
if ((r1 = stat_mtime (s, &st1, &ts1)) < 0)
|
||||
{
|
||||
if (op == EF)
|
||||
return (FALSE);
|
||||
}
|
||||
if ((r2 = stat_mtime (t, &st2, &ts2)) < 0)
|
||||
{
|
||||
if (op == EF)
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case OT: return (r1 < r2 || (r2 == 0 && timespec_cmp (ts1, ts2) < 0));
|
||||
case NT: return (r1 > r2 || (r1 == 0 && timespec_cmp (ts1, ts2) > 0));
|
||||
case EF: return (same_file (s, t, &st1, &st2));
|
||||
}
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
static int
|
||||
arithcomp (s, t, op, flags)
|
||||
char *s, *t;
|
||||
int op, flags;
|
||||
{
|
||||
intmax_t l, r;
|
||||
int expok;
|
||||
|
||||
if (flags & TEST_ARITHEXP)
|
||||
{
|
||||
l = evalexp (s, &expok);
|
||||
if (expok == 0)
|
||||
return (FALSE); /* should probably longjmp here */
|
||||
r = evalexp (t, &expok);
|
||||
if (expok == 0)
|
||||
return (FALSE); /* ditto */
|
||||
}
|
||||
else
|
||||
{
|
||||
if (legal_number (s, &l) == 0)
|
||||
integer_expected_error (s);
|
||||
if (legal_number (t, &r) == 0)
|
||||
integer_expected_error (t);
|
||||
}
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case EQ: return (l == r);
|
||||
case NE: return (l != r);
|
||||
case LT: return (l < r);
|
||||
case GT: return (l > r);
|
||||
case LE: return (l <= r);
|
||||
case GE: return (l >= r);
|
||||
}
|
||||
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
static int
|
||||
patcomp (string, pat, op)
|
||||
char *string, *pat;
|
||||
int op;
|
||||
{
|
||||
int m;
|
||||
|
||||
m = strmatch (pat, string, FNMATCH_EXTFLAG|FNMATCH_IGNCASE);
|
||||
return ((op == EQ) ? (m == 0) : (m != 0));
|
||||
}
|
||||
|
||||
int
|
||||
binary_test (op, arg1, arg2, flags)
|
||||
char *op, *arg1, *arg2;
|
||||
int flags;
|
||||
{
|
||||
int patmatch;
|
||||
|
||||
patmatch = (flags & TEST_PATMATCH);
|
||||
|
||||
if (op[0] == '=' && (op[1] == '\0' || (op[1] == '=' && op[2] == '\0')))
|
||||
return (patmatch ? patcomp (arg1, arg2, EQ) : STREQ (arg1, arg2));
|
||||
else if ((op[0] == '>' || op[0] == '<') && op[1] == '\0')
|
||||
{
|
||||
if (shell_compatibility_level > 40 && flags & TEST_LOCALE)
|
||||
return ((op[0] == '>') ? (strcoll (arg1, arg2) > 0) : (strcoll (arg1, arg2) < 0));
|
||||
else
|
||||
return ((op[0] == '>') ? (strcmp (arg1, arg2) > 0) : (strcmp (arg1, arg2) < 0));
|
||||
}
|
||||
else if (op[0] == '!' && op[1] == '=' && op[2] == '\0')
|
||||
return (patmatch ? patcomp (arg1, arg2, NE) : (STREQ (arg1, arg2) == 0));
|
||||
|
||||
|
||||
else if (op[2] == 't')
|
||||
{
|
||||
switch (op[1])
|
||||
{
|
||||
case 'n': return (filecomp (arg1, arg2, NT)); /* -nt */
|
||||
case 'o': return (filecomp (arg1, arg2, OT)); /* -ot */
|
||||
case 'l': return (arithcomp (arg1, arg2, LT, flags)); /* -lt */
|
||||
case 'g': return (arithcomp (arg1, arg2, GT, flags)); /* -gt */
|
||||
}
|
||||
}
|
||||
else if (op[1] == 'e')
|
||||
{
|
||||
switch (op[2])
|
||||
{
|
||||
case 'f': return (filecomp (arg1, arg2, EF)); /* -ef */
|
||||
case 'q': return (arithcomp (arg1, arg2, EQ, flags)); /* -eq */
|
||||
}
|
||||
}
|
||||
else if (op[2] == 'e')
|
||||
{
|
||||
switch (op[1])
|
||||
{
|
||||
case 'n': return (arithcomp (arg1, arg2, NE, flags)); /* -ne */
|
||||
case 'g': return (arithcomp (arg1, arg2, GE, flags)); /* -ge */
|
||||
case 'l': return (arithcomp (arg1, arg2, LE, flags)); /* -le */
|
||||
}
|
||||
}
|
||||
|
||||
return (FALSE); /* should never get here */
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
binary_operator ()
|
||||
{
|
||||
int value;
|
||||
char *w;
|
||||
|
||||
w = argv[pos + 1];
|
||||
if ((w[0] == '=' && (w[1] == '\0' || (w[1] == '=' && w[2] == '\0'))) || /* =, == */
|
||||
((w[0] == '>' || w[0] == '<') && w[1] == '\0') || /* <, > */
|
||||
(w[0] == '!' && w[1] == '=' && w[2] == '\0')) /* != */
|
||||
{
|
||||
value = binary_test (w, argv[pos], argv[pos + 2], 0);
|
||||
pos += 3;
|
||||
return (value);
|
||||
}
|
||||
|
||||
#if defined (PATTERN_MATCHING)
|
||||
if ((w[0] == '=' || w[0] == '!') && w[1] == '~' && w[2] == '\0')
|
||||
{
|
||||
value = patcomp (argv[pos], argv[pos + 2], w[0] == '=' ? EQ : NE);
|
||||
pos += 3;
|
||||
return (value);
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((w[0] != '-' || w[3] != '\0') || test_binop (w) == 0)
|
||||
{
|
||||
test_syntax_error (_("%s: binary operator expected"), w);
|
||||
/* NOTREACHED */
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
value = binary_test (w, argv[pos], argv[pos + 2], 0);
|
||||
pos += 3;
|
||||
return value;
|
||||
}
|
||||
|
||||
static int
|
||||
unary_operator ()
|
||||
{
|
||||
char *op;
|
||||
intmax_t r;
|
||||
|
||||
op = argv[pos];
|
||||
if (test_unop (op) == 0)
|
||||
return (FALSE);
|
||||
|
||||
/* the only tricky case is `-t', which may or may not take an argument. */
|
||||
if (op[1] == 't')
|
||||
{
|
||||
advance (0);
|
||||
if (pos < argc)
|
||||
{
|
||||
if (legal_number (argv[pos], &r))
|
||||
{
|
||||
advance (0);
|
||||
return (unary_test (op, argv[pos - 1]));
|
||||
}
|
||||
else
|
||||
return (FALSE);
|
||||
}
|
||||
else
|
||||
return (unary_test (op, "1"));
|
||||
}
|
||||
|
||||
/* All of the unary operators take an argument, so we first call
|
||||
unary_advance (), which checks to make sure that there is an
|
||||
argument, and then advances pos right past it. This means that
|
||||
pos - 1 is the location of the argument. */
|
||||
unary_advance ();
|
||||
return (unary_test (op, argv[pos - 1]));
|
||||
}
|
||||
|
||||
int
|
||||
unary_test (op, arg)
|
||||
char *op, *arg;
|
||||
{
|
||||
intmax_t r;
|
||||
struct stat stat_buf;
|
||||
SHELL_VAR *v;
|
||||
|
||||
switch (op[1])
|
||||
{
|
||||
case 'a': /* file exists in the file system? */
|
||||
case 'e':
|
||||
return (sh_stat (arg, &stat_buf) == 0);
|
||||
|
||||
case 'r': /* file is readable? */
|
||||
return (sh_eaccess (arg, R_OK) == 0);
|
||||
|
||||
case 'w': /* File is writeable? */
|
||||
return (sh_eaccess (arg, W_OK) == 0);
|
||||
|
||||
case 'x': /* File is executable? */
|
||||
return (sh_eaccess (arg, X_OK) == 0);
|
||||
|
||||
case 'O': /* File is owned by you? */
|
||||
return (sh_stat (arg, &stat_buf) == 0 &&
|
||||
(uid_t) current_user.euid == (uid_t) stat_buf.st_uid);
|
||||
|
||||
case 'G': /* File is owned by your group? */
|
||||
return (sh_stat (arg, &stat_buf) == 0 &&
|
||||
(gid_t) current_user.egid == (gid_t) stat_buf.st_gid);
|
||||
|
||||
case 'N':
|
||||
return (sh_stat (arg, &stat_buf) == 0 &&
|
||||
stat_buf.st_atime <= stat_buf.st_mtime);
|
||||
|
||||
case 'f': /* File is a file? */
|
||||
if (sh_stat (arg, &stat_buf) < 0)
|
||||
return (FALSE);
|
||||
|
||||
/* -f is true if the given file exists and is a regular file. */
|
||||
#if defined (S_IFMT)
|
||||
return (S_ISREG (stat_buf.st_mode) || (stat_buf.st_mode & S_IFMT) == 0);
|
||||
#else
|
||||
return (S_ISREG (stat_buf.st_mode));
|
||||
#endif /* !S_IFMT */
|
||||
|
||||
case 'd': /* File is a directory? */
|
||||
return (sh_stat (arg, &stat_buf) == 0 && (S_ISDIR (stat_buf.st_mode)));
|
||||
|
||||
case 's': /* File has something in it? */
|
||||
return (sh_stat (arg, &stat_buf) == 0 && stat_buf.st_size > (off_t) 0);
|
||||
|
||||
case 'S': /* File is a socket? */
|
||||
#if !defined (S_ISSOCK)
|
||||
return (FALSE);
|
||||
#else
|
||||
return (sh_stat (arg, &stat_buf) == 0 && S_ISSOCK (stat_buf.st_mode));
|
||||
#endif /* S_ISSOCK */
|
||||
|
||||
case 'c': /* File is character special? */
|
||||
return (sh_stat (arg, &stat_buf) == 0 && S_ISCHR (stat_buf.st_mode));
|
||||
|
||||
case 'b': /* File is block special? */
|
||||
return (sh_stat (arg, &stat_buf) == 0 && S_ISBLK (stat_buf.st_mode));
|
||||
|
||||
case 'p': /* File is a named pipe? */
|
||||
#ifndef S_ISFIFO
|
||||
return (FALSE);
|
||||
#else
|
||||
return (sh_stat (arg, &stat_buf) == 0 && S_ISFIFO (stat_buf.st_mode));
|
||||
#endif /* S_ISFIFO */
|
||||
|
||||
case 'L': /* Same as -h */
|
||||
case 'h': /* File is a symbolic link? */
|
||||
#if !defined (S_ISLNK) || !defined (HAVE_LSTAT)
|
||||
return (FALSE);
|
||||
#else
|
||||
return ((arg[0] != '\0') &&
|
||||
(lstat (arg, &stat_buf) == 0) && S_ISLNK (stat_buf.st_mode));
|
||||
#endif /* S_IFLNK && HAVE_LSTAT */
|
||||
|
||||
case 'u': /* File is setuid? */
|
||||
return (sh_stat (arg, &stat_buf) == 0 && (stat_buf.st_mode & S_ISUID) != 0);
|
||||
|
||||
case 'g': /* File is setgid? */
|
||||
return (sh_stat (arg, &stat_buf) == 0 && (stat_buf.st_mode & S_ISGID) != 0);
|
||||
|
||||
case 'k': /* File has sticky bit set? */
|
||||
#if !defined (S_ISVTX)
|
||||
/* This is not Posix, and is not defined on some Posix systems. */
|
||||
return (FALSE);
|
||||
#else
|
||||
return (sh_stat (arg, &stat_buf) == 0 && (stat_buf.st_mode & S_ISVTX) != 0);
|
||||
#endif
|
||||
|
||||
case 't': /* File fd is a terminal? */
|
||||
if (legal_number (arg, &r) == 0)
|
||||
return (FALSE);
|
||||
return ((r == (int)r) && isatty ((int)r));
|
||||
|
||||
case 'n': /* True if arg has some length. */
|
||||
return (arg[0] != '\0');
|
||||
|
||||
case 'z': /* True if arg has no length. */
|
||||
return (arg[0] == '\0');
|
||||
|
||||
case 'o': /* True if option `arg' is set. */
|
||||
return (minus_o_option_value (arg) == 1);
|
||||
|
||||
case 'v':
|
||||
v = find_variable (arg);
|
||||
return (v && invisible_p (v) == 0 && var_isset (v) ? TRUE : FALSE);
|
||||
|
||||
case 'R':
|
||||
v = find_variable (arg);
|
||||
return (v && invisible_p (v) == 0 && var_isset (v) && nameref_p (v) ? TRUE : FALSE);
|
||||
}
|
||||
|
||||
/* We can't actually get here, but this shuts up gcc. */
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/* Return TRUE if OP is one of the test command's binary operators. */
|
||||
int
|
||||
test_binop (op)
|
||||
char *op;
|
||||
{
|
||||
if (op[0] == '=' && op[1] == '\0')
|
||||
return (1); /* '=' */
|
||||
else if ((op[0] == '<' || op[0] == '>') && op[1] == '\0') /* string <, > */
|
||||
return (1);
|
||||
else if ((op[0] == '=' || op[0] == '!') && op[1] == '=' && op[2] == '\0')
|
||||
return (1); /* `==' and `!=' */
|
||||
#if defined (PATTERN_MATCHING)
|
||||
else if (op[2] == '\0' && op[1] == '~' && (op[0] == '=' || op[0] == '!'))
|
||||
return (1);
|
||||
#endif
|
||||
else if (op[0] != '-' || op[2] == '\0' || op[3] != '\0')
|
||||
return (0);
|
||||
else
|
||||
{
|
||||
if (op[2] == 't')
|
||||
switch (op[1])
|
||||
{
|
||||
case 'n': /* -nt */
|
||||
case 'o': /* -ot */
|
||||
case 'l': /* -lt */
|
||||
case 'g': /* -gt */
|
||||
return (1);
|
||||
default:
|
||||
return (0);
|
||||
}
|
||||
else if (op[1] == 'e')
|
||||
switch (op[2])
|
||||
{
|
||||
case 'q': /* -eq */
|
||||
case 'f': /* -ef */
|
||||
return (1);
|
||||
default:
|
||||
return (0);
|
||||
}
|
||||
else if (op[2] == 'e')
|
||||
switch (op[1])
|
||||
{
|
||||
case 'n': /* -ne */
|
||||
case 'g': /* -ge */
|
||||
case 'l': /* -le */
|
||||
return (1);
|
||||
default:
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Return non-zero if OP is one of the test command's unary operators. */
|
||||
int
|
||||
test_unop (op)
|
||||
char *op;
|
||||
{
|
||||
if (op[0] != '-' || op[2] != 0)
|
||||
return (0);
|
||||
|
||||
switch (op[1])
|
||||
{
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e':
|
||||
case 'f': case 'g': case 'h': case 'k': case 'n':
|
||||
case 'o': case 'p': case 'r': case 's': case 't':
|
||||
case 'u': case 'v': case 'w': case 'x': case 'z':
|
||||
case 'G': case 'L': case 'O': case 'S': case 'N':
|
||||
return (1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
two_arguments ()
|
||||
{
|
||||
if (argv[pos][0] == '!' && argv[pos][1] == '\0')
|
||||
return (argv[pos + 1][0] == '\0');
|
||||
else if (argv[pos][0] == '-' && argv[pos][2] == '\0')
|
||||
{
|
||||
if (test_unop (argv[pos]))
|
||||
return (unary_operator ());
|
||||
else
|
||||
test_syntax_error (_("%s: unary operator expected"), argv[pos]);
|
||||
}
|
||||
else
|
||||
test_syntax_error (_("%s: unary operator expected"), argv[pos]);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#define ANDOR(s) (s[0] == '-' && !s[2] && (s[1] == 'a' || s[1] == 'o'))
|
||||
|
||||
/* This could be augmented to handle `-t' as equivalent to `-t 1', but
|
||||
POSIX requires that `-t' be given an argument. */
|
||||
#define ONE_ARG_TEST(s) ((s)[0] != '\0')
|
||||
|
||||
static int
|
||||
three_arguments ()
|
||||
{
|
||||
int value;
|
||||
|
||||
if (test_binop (argv[pos+1]))
|
||||
{
|
||||
value = binary_operator ();
|
||||
pos = argc;
|
||||
}
|
||||
else if (ANDOR (argv[pos+1]))
|
||||
{
|
||||
if (argv[pos+1][1] == 'a')
|
||||
value = ONE_ARG_TEST(argv[pos]) && ONE_ARG_TEST(argv[pos+2]);
|
||||
else
|
||||
value = ONE_ARG_TEST(argv[pos]) || ONE_ARG_TEST(argv[pos+2]);
|
||||
pos = argc;
|
||||
}
|
||||
else if (argv[pos][0] == '!' && argv[pos][1] == '\0')
|
||||
{
|
||||
advance (1);
|
||||
value = !two_arguments ();
|
||||
}
|
||||
else if (argv[pos][0] == '(' && argv[pos+2][0] == ')')
|
||||
{
|
||||
value = ONE_ARG_TEST(argv[pos+1]);
|
||||
pos = argc;
|
||||
}
|
||||
else
|
||||
test_syntax_error (_("%s: binary operator expected"), argv[pos+1]);
|
||||
|
||||
return (value);
|
||||
}
|
||||
|
||||
/* This is an implementation of a Posix.2 proposal by David Korn. */
|
||||
static int
|
||||
posixtest ()
|
||||
{
|
||||
int value;
|
||||
|
||||
switch (argc - 1) /* one extra passed in */
|
||||
{
|
||||
case 0:
|
||||
value = FALSE;
|
||||
pos = argc;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
value = ONE_ARG_TEST(argv[1]);
|
||||
pos = argc;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
value = two_arguments ();
|
||||
pos = argc;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
value = three_arguments ();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
if (argv[pos][0] == '!' && argv[pos][1] == '\0')
|
||||
{
|
||||
advance (1);
|
||||
value = !three_arguments ();
|
||||
break;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
value = expr ();
|
||||
}
|
||||
|
||||
return (value);
|
||||
}
|
||||
|
||||
/*
|
||||
* [:
|
||||
* '[' expr ']'
|
||||
* test:
|
||||
* test expr
|
||||
*/
|
||||
int
|
||||
test_command (margc, margv)
|
||||
int margc;
|
||||
char **margv;
|
||||
{
|
||||
int value;
|
||||
int code;
|
||||
|
||||
USE_VAR(margc);
|
||||
|
||||
code = setjmp (test_exit_buf);
|
||||
|
||||
if (code)
|
||||
return (test_error_return);
|
||||
|
||||
argv = margv;
|
||||
|
||||
if (margv[0] && margv[0][0] == '[' && margv[0][1] == '\0')
|
||||
{
|
||||
--margc;
|
||||
|
||||
if (margv[margc] && (margv[margc][0] != ']' || margv[margc][1]))
|
||||
test_syntax_error (_("missing `]'"), (char *)NULL);
|
||||
|
||||
if (margc < 2)
|
||||
test_exit (SHELL_BOOLEAN (FALSE));
|
||||
}
|
||||
|
||||
argc = margc;
|
||||
pos = 1;
|
||||
|
||||
if (pos >= argc)
|
||||
test_exit (SHELL_BOOLEAN (FALSE));
|
||||
|
||||
noeval = 0;
|
||||
value = posixtest ();
|
||||
|
||||
if (pos != argc)
|
||||
test_syntax_error (_("too many arguments"), (char *)NULL);
|
||||
|
||||
test_exit (SHELL_BOOLEAN (value));
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
BUILD_DIR=/usr/local/build/chet/bash/bash-current
|
||||
THIS_SH=$BUILD_DIR/bash
|
||||
PATH=$PATH:$BUILD_DIR
|
||||
|
||||
export THIS_SH PATH
|
||||
|
||||
rm -f /tmp/xx
|
||||
|
||||
/bin/sh "$@"
|
||||
@@ -1,41 +0,0 @@
|
||||
: ${TMPDIR:=/var/tmp}
|
||||
dir=$PWD
|
||||
|
||||
shopt -s globstar
|
||||
|
||||
export LANG=C LC_ALL=C LC_COLLATE=C
|
||||
|
||||
GDIR=$TMPDIR/globstar-$$
|
||||
|
||||
mkdir $GDIR || exit 1
|
||||
cd $GDIR || exit 1
|
||||
|
||||
mkdir lib builtins
|
||||
mkdir lib/glob lib/readline lib/sh
|
||||
|
||||
touch builtins/history.o builtins/jobs.o builtins/kill.o builtins/let.o builtins/mapfile.o
|
||||
touch lib/glob/glob.o lib/glob/smatch.o lib/glob/strmatch.o
|
||||
touch lib/readline/bind.o lib/readline/callback.o lib/readline/compat.o lib/readline/complete.o lib/readline/display.o
|
||||
|
||||
touch lib/sh/casemod.o lib/sh/clktck.o lib/sh/clock.o lib/sh/eaccess.o
|
||||
touch lib/sh/fdprintf.o lib/sh/fmtullong.o lib/sh/fmtulong.o lib/sh/fmtumax.o
|
||||
touch lib/sh/fpurge.o lib/sh/getenv.o lib/sh/input_avail.o lib/sh/itos.o
|
||||
|
||||
touch alias.o
|
||||
touch pcomplib.o print_cmd.o redir.o shell.o sig.o stringlib.o subst.o syntax.o
|
||||
touch test.o trap.o unwind_prot.o variables.o version.o xmalloc.o y.tab.o
|
||||
|
||||
ls lib/**
|
||||
|
||||
ls lib/**/*.o
|
||||
|
||||
echo **/*.o
|
||||
|
||||
ls **
|
||||
|
||||
echo **
|
||||
|
||||
cd $dir
|
||||
rm -rf $GDIR
|
||||
|
||||
${THIS_SH} ./globstar1.sub
|
||||
@@ -1,50 +0,0 @@
|
||||
:; ./shx
|
||||
|
||||
sh:
|
||||
<&$fd ok
|
||||
nlbq Mon Aug 3 02:45:00 EDT 1992
|
||||
bang geoff
|
||||
quote 712824302
|
||||
setbq defmsgid=<1992Aug3.024502.6176@host>
|
||||
bgwait sleep done... wait 6187
|
||||
|
||||
|
||||
bash:
|
||||
<&$fd ok
|
||||
nlbq Mon Aug 3 02:45:09 EDT 1992
|
||||
bang geoff
|
||||
quote 712824311
|
||||
setbq defmsgid=<1992Aug3.024512.6212@host>
|
||||
bgwait sleep done... wait 6223
|
||||
|
||||
|
||||
ash:
|
||||
<&$fd shx1: 4: Syntax error: Bad fd number
|
||||
nlbq Mon Aug 3 02:45:19 EDT 1992
|
||||
bang geoff
|
||||
quote getdate: `"now"' not a valid date
|
||||
|
||||
setbq defmsgid=<1992Aug3.` echo 024521
|
||||
bgwait sleep done... wait 6241
|
||||
|
||||
|
||||
ksh:
|
||||
<&$fd ok
|
||||
nlbq ./shx: 6248 Memory fault - core dumped
|
||||
bang geoff
|
||||
quote getdate: `"now"' not a valid date
|
||||
|
||||
setbq defmsgid=<1992Aug3.024530.6257@host>
|
||||
bgwait no such job: 6265
|
||||
wait 6265
|
||||
sleep done...
|
||||
|
||||
zsh:
|
||||
<&$fd ok
|
||||
nlbq Mon Aug 3 02:45:36 EDT 1992
|
||||
bang shx3: event not found: /s/ [4]
|
||||
quote 712824337
|
||||
setbq defmsgid=<..6290@host>
|
||||
bgwait shx7: unmatched " [9]
|
||||
sleep done...
|
||||
:;
|
||||
@@ -1,10 +0,0 @@
|
||||
#! /bin/sh
|
||||
for cmd in sh bash ash ksh zsh
|
||||
do
|
||||
echo
|
||||
echo $cmd:
|
||||
for demo in shx?
|
||||
do
|
||||
$cmd $demo
|
||||
done
|
||||
done
|
||||
@@ -1,111 +0,0 @@
|
||||
echo "Single Quote"
|
||||
echo 'foo
|
||||
bar'
|
||||
echo 'foo
|
||||
bar'
|
||||
echo 'foo\
|
||||
bar'
|
||||
|
||||
echo "Double Quote"
|
||||
echo "foo
|
||||
bar"
|
||||
echo "foo
|
||||
bar"
|
||||
echo "foo\
|
||||
bar"
|
||||
|
||||
echo "Backslash Single Quote"
|
||||
echo `echo 'foo
|
||||
bar'`
|
||||
echo `echo 'foo
|
||||
bar'`
|
||||
echo `echo 'foo\
|
||||
bar'`
|
||||
|
||||
echo "Backslash Double Quote"
|
||||
echo `echo "foo
|
||||
bar"`
|
||||
echo `echo "foo
|
||||
bar"`
|
||||
echo `echo "foo\
|
||||
bar"`
|
||||
|
||||
echo "Double Quote Backslash Single Quote"
|
||||
echo "`echo 'foo
|
||||
bar'`"
|
||||
echo "`echo 'foo
|
||||
bar'`"
|
||||
echo "`echo 'foo\
|
||||
bar'`"
|
||||
|
||||
echo "Dollar Paren Single Quote"
|
||||
echo $(echo 'foo
|
||||
bar')
|
||||
echo $(echo 'foo
|
||||
bar')
|
||||
echo $(echo 'foo\
|
||||
bar')
|
||||
|
||||
echo "Dollar Paren Double Quote"
|
||||
echo $(echo "foo
|
||||
bar")
|
||||
echo $(echo "foo
|
||||
bar")
|
||||
echo $(echo "foo\
|
||||
bar")
|
||||
|
||||
echo "Double Quote Dollar Paren Single Quote"
|
||||
echo "$(echo 'foo
|
||||
bar')"
|
||||
echo "$(echo 'foo
|
||||
bar')"
|
||||
echo "$(echo 'foo\
|
||||
bar')"
|
||||
|
||||
# old-style command substitution parsing compatibility tests -- post bash-3.1
|
||||
recho 'foo \\
|
||||
bar'
|
||||
|
||||
recho 'foo \
|
||||
bar'
|
||||
|
||||
echo `recho sed -e 's/[ :]/\\
|
||||
/g'`
|
||||
|
||||
echo `recho sed -e 's/[ :]/\
|
||||
/g'`
|
||||
|
||||
echo `recho 'foo\\
|
||||
bar'`
|
||||
|
||||
echo `recho 'foo\
|
||||
bar'`
|
||||
|
||||
echo $(recho 'foo\
|
||||
bar')
|
||||
|
||||
a=`echo 'a b c' | sed 's/ /\\
|
||||
/g' | grep 'b'`
|
||||
echo $a
|
||||
a=`echo 'a b c' | sed 's/ /\\
|
||||
/g'`
|
||||
echo "$a"
|
||||
|
||||
recho `echo 'a\' b`
|
||||
|
||||
recho `echo '\$' bab`
|
||||
recho `echo '\$foo' bab`
|
||||
recho `echo '$foo' bab`
|
||||
|
||||
recho `echo '\`' ab`
|
||||
|
||||
recho `echo '\\' ab`
|
||||
|
||||
echo `echo '${'`
|
||||
|
||||
recho `echo "(\\")"`
|
||||
# produces no output
|
||||
: `: "\\""`
|
||||
# ultimate workaround
|
||||
recho `echo "(\")"`
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
test="weferfds'dsfsdf"
|
||||
|
||||
# why does this work, this list was born of frustration, I tried
|
||||
# everything I could think of.
|
||||
echo \'${test//"'"/\'\\\'\'}\'" "
|
||||
|
||||
#but none of the following
|
||||
|
||||
echo "'${test//"'"/}'"
|
||||
|
||||
echo "'${test//"'"/"'\\''"}'"
|
||||
|
||||
echo "'${test//"'"/\'\\'\'}'"
|
||||
|
||||
#echo "'${test//'/}'" # hangs waiting for '
|
||||
#echo "'${test//"'"/'\\''}'" # hangs waiting for '
|
||||
|
||||
unset test
|
||||
test=teststrtest
|
||||
echo "${test//str/"dd dd"}"
|
||||
echo ${test//str/"dd '\''dd"}
|
||||
|
||||
unset test
|
||||
test=teststring
|
||||
|
||||
echo "${test//str/"dddd"}"
|
||||
|
||||
echo ${test//str/"dddd"}
|
||||
|
||||
echo ${test//str/"'"}
|
||||
|
||||
echo "${test//str/"'"}"
|
||||
|
||||
#echo "${test//str/'}" # hangs
|
||||
|
||||
test=test\'string
|
||||
echo "${test//"'"/"'"}"
|
||||
-5243
File diff suppressed because it is too large
Load Diff
-411
@@ -1,411 +0,0 @@
|
||||
/* variables.h -- data structures for shell variables. */
|
||||
|
||||
/* Copyright (C) 1987-2012 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 (_VARIABLES_H_)
|
||||
#define _VARIABLES_H_
|
||||
|
||||
#include "stdc.h"
|
||||
#include "array.h"
|
||||
#include "assoc.h"
|
||||
|
||||
/* Shell variables and functions are stored in hash tables. */
|
||||
#include "hashlib.h"
|
||||
|
||||
#include "conftypes.h"
|
||||
|
||||
/* A variable context. */
|
||||
typedef struct var_context {
|
||||
char *name; /* empty or NULL means global context */
|
||||
int scope; /* 0 means global context */
|
||||
int flags;
|
||||
struct var_context *up; /* previous function calls */
|
||||
struct var_context *down; /* down towards global context */
|
||||
HASH_TABLE *table; /* variables at this scope */
|
||||
} VAR_CONTEXT;
|
||||
|
||||
/* Flags for var_context->flags */
|
||||
#define VC_HASLOCAL 0x01
|
||||
#define VC_HASTMPVAR 0x02
|
||||
#define VC_FUNCENV 0x04 /* also function if name != NULL */
|
||||
#define VC_BLTNENV 0x08 /* builtin_env */
|
||||
#define VC_TEMPENV 0x10 /* temporary_env */
|
||||
|
||||
#define VC_TEMPFLAGS (VC_FUNCENV|VC_BLTNENV|VC_TEMPENV)
|
||||
|
||||
/* Accessing macros */
|
||||
#define vc_isfuncenv(vc) (((vc)->flags & VC_FUNCENV) != 0)
|
||||
#define vc_isbltnenv(vc) (((vc)->flags & VC_BLTNENV) != 0)
|
||||
#define vc_istempenv(vc) (((vc)->flags & (VC_TEMPFLAGS)) == VC_TEMPENV)
|
||||
|
||||
#define vc_istempscope(vc) (((vc)->flags & (VC_TEMPENV|VC_BLTNENV)) != 0)
|
||||
|
||||
#define vc_haslocals(vc) (((vc)->flags & VC_HASLOCAL) != 0)
|
||||
#define vc_hastmpvars(vc) (((vc)->flags & VC_HASTMPVAR) != 0)
|
||||
|
||||
/* What a shell variable looks like. */
|
||||
|
||||
typedef struct variable *sh_var_value_func_t __P((struct variable *));
|
||||
typedef struct variable *sh_var_assign_func_t __P((struct variable *, char *, arrayind_t, char *));
|
||||
|
||||
/* For the future */
|
||||
union _value {
|
||||
char *s; /* string value */
|
||||
intmax_t i; /* int value */
|
||||
COMMAND *f; /* function */
|
||||
ARRAY *a; /* array */
|
||||
HASH_TABLE *h; /* associative array */
|
||||
double d; /* floating point number */
|
||||
#if defined (HAVE_LONG_DOUBLE)
|
||||
long double ld; /* long double */
|
||||
#endif
|
||||
struct variable *v; /* possible indirect variable use */
|
||||
void *opaque; /* opaque data for future use */
|
||||
};
|
||||
|
||||
typedef struct variable {
|
||||
char *name; /* Symbol that the user types. */
|
||||
char *value; /* Value that is returned. */
|
||||
char *exportstr; /* String for the environment. */
|
||||
sh_var_value_func_t *dynamic_value; /* Function called to return a `dynamic'
|
||||
value for a variable, like $SECONDS
|
||||
or $RANDOM. */
|
||||
sh_var_assign_func_t *assign_func; /* Function called when this `special
|
||||
variable' is assigned a value in
|
||||
bind_variable. */
|
||||
int attributes; /* export, readonly, array, invisible... */
|
||||
int context; /* Which context this variable belongs to. */
|
||||
} SHELL_VAR;
|
||||
|
||||
typedef struct _vlist {
|
||||
SHELL_VAR **list;
|
||||
int list_size; /* allocated size */
|
||||
int list_len; /* current number of entries */
|
||||
} VARLIST;
|
||||
|
||||
/* The various attributes that a given variable can have. */
|
||||
/* First, the user-visible attributes */
|
||||
#define att_exported 0x0000001 /* export to environment */
|
||||
#define att_readonly 0x0000002 /* cannot change */
|
||||
#define att_array 0x0000004 /* value is an array */
|
||||
#define att_function 0x0000008 /* value is a function */
|
||||
#define att_integer 0x0000010 /* internal representation is int */
|
||||
#define att_local 0x0000020 /* variable is local to a function */
|
||||
#define att_assoc 0x0000040 /* variable is an associative array */
|
||||
#define att_trace 0x0000080 /* function is traced with DEBUG trap */
|
||||
#define att_uppercase 0x0000100 /* word converted to uppercase on assignment */
|
||||
#define att_lowercase 0x0000200 /* word converted to lowercase on assignment */
|
||||
#define att_capcase 0x0000400 /* word capitalized on assignment */
|
||||
#define att_nameref 0x0000800 /* word is a name reference */
|
||||
|
||||
#define user_attrs (att_exported|att_readonly|att_integer|att_local|att_trace|att_uppercase|att_lowercase|att_capcase|att_nameref)
|
||||
|
||||
#define attmask_user 0x0000fff
|
||||
|
||||
/* Internal attributes used for bookkeeping */
|
||||
#define att_invisible 0x0001000 /* cannot see */
|
||||
#define att_nounset 0x0002000 /* cannot unset */
|
||||
#define att_noassign 0x0004000 /* assignment not allowed */
|
||||
#define att_imported 0x0008000 /* came from environment */
|
||||
#define att_special 0x0010000 /* requires special handling */
|
||||
#define att_nofree 0x0020000 /* do not free value on unset */
|
||||
|
||||
#define attmask_int 0x00ff000
|
||||
|
||||
/* Internal attributes used for variable scoping. */
|
||||
#define att_tempvar 0x0100000 /* variable came from the temp environment */
|
||||
#define att_propagate 0x0200000 /* propagate to previous scope */
|
||||
|
||||
#define attmask_scope 0x0f00000
|
||||
|
||||
#define exported_p(var) ((((var)->attributes) & (att_exported)))
|
||||
#define readonly_p(var) ((((var)->attributes) & (att_readonly)))
|
||||
#define array_p(var) ((((var)->attributes) & (att_array)))
|
||||
#define function_p(var) ((((var)->attributes) & (att_function)))
|
||||
#define integer_p(var) ((((var)->attributes) & (att_integer)))
|
||||
#define local_p(var) ((((var)->attributes) & (att_local)))
|
||||
#define assoc_p(var) ((((var)->attributes) & (att_assoc)))
|
||||
#define trace_p(var) ((((var)->attributes) & (att_trace)))
|
||||
#define uppercase_p(var) ((((var)->attributes) & (att_uppercase)))
|
||||
#define lowercase_p(var) ((((var)->attributes) & (att_lowercase)))
|
||||
#define capcase_p(var) ((((var)->attributes) & (att_capcase)))
|
||||
#define nameref_p(var) ((((var)->attributes) & (att_nameref)))
|
||||
|
||||
#define invisible_p(var) ((((var)->attributes) & (att_invisible)))
|
||||
#define non_unsettable_p(var) ((((var)->attributes) & (att_nounset)))
|
||||
#define noassign_p(var) ((((var)->attributes) & (att_noassign)))
|
||||
#define imported_p(var) ((((var)->attributes) & (att_imported)))
|
||||
#define specialvar_p(var) ((((var)->attributes) & (att_special)))
|
||||
#define nofree_p(var) ((((var)->attributes) & (att_nofree)))
|
||||
|
||||
#define tempvar_p(var) ((((var)->attributes) & (att_tempvar)))
|
||||
|
||||
/* Acessing variable values: rvalues */
|
||||
#define value_cell(var) ((var)->value)
|
||||
#define function_cell(var) (COMMAND *)((var)->value)
|
||||
#define array_cell(var) (ARRAY *)((var)->value)
|
||||
#define assoc_cell(var) (HASH_TABLE *)((var)->value)
|
||||
#define nameref_cell(var) ((var)->value) /* so it can change later */
|
||||
|
||||
#define NAMEREF_MAX 8 /* only 8 levels of nameref indirection */
|
||||
|
||||
#define var_isnull(var) ((var)->value == 0)
|
||||
#define var_isset(var) ((var)->value != 0)
|
||||
|
||||
/* Assigning variable values: lvalues */
|
||||
#define var_setvalue(var, str) ((var)->value = (str))
|
||||
#define var_setfunc(var, func) ((var)->value = (char *)(func))
|
||||
#define var_setarray(var, arr) ((var)->value = (char *)(arr))
|
||||
#define var_setassoc(var, arr) ((var)->value = (char *)(arr))
|
||||
#define var_setref(var, str) ((var)->value = (str))
|
||||
|
||||
/* Make VAR be auto-exported. */
|
||||
#define set_auto_export(var) \
|
||||
do { (var)->attributes |= att_exported; array_needs_making = 1; } while (0)
|
||||
|
||||
#define SETVARATTR(var, attr, undo) \
|
||||
((undo == 0) ? ((var)->attributes |= (attr)) \
|
||||
: ((var)->attributes &= ~(attr)))
|
||||
|
||||
#define VSETATTR(var, attr) ((var)->attributes |= (attr))
|
||||
#define VUNSETATTR(var, attr) ((var)->attributes &= ~(attr))
|
||||
|
||||
#define VGETFLAGS(var) ((var)->attributes)
|
||||
|
||||
#define VSETFLAGS(var, flags) ((var)->attributes = (flags))
|
||||
#define VCLRFLAGS(var) ((var)->attributes = 0)
|
||||
|
||||
/* Macros to perform various operations on `exportstr' member of a SHELL_VAR. */
|
||||
#define CLEAR_EXPORTSTR(var) (var)->exportstr = (char *)NULL
|
||||
#define COPY_EXPORTSTR(var) ((var)->exportstr) ? savestring ((var)->exportstr) : (char *)NULL
|
||||
#define SET_EXPORTSTR(var, value) (var)->exportstr = (value)
|
||||
#define SAVE_EXPORTSTR(var, value) (var)->exportstr = (value) ? savestring (value) : (char *)NULL
|
||||
|
||||
#define FREE_EXPORTSTR(var) \
|
||||
do { if ((var)->exportstr) free ((var)->exportstr); } while (0)
|
||||
|
||||
#define CACHE_IMPORTSTR(var, value) \
|
||||
(var)->exportstr = savestring (value)
|
||||
|
||||
#define INVALIDATE_EXPORTSTR(var) \
|
||||
do { \
|
||||
if ((var)->exportstr) \
|
||||
{ \
|
||||
free ((var)->exportstr); \
|
||||
(var)->exportstr = (char *)NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* Stuff for hacking variables. */
|
||||
typedef int sh_var_map_func_t __P((SHELL_VAR *));
|
||||
|
||||
/* Where we keep the variables and functions */
|
||||
extern VAR_CONTEXT *global_variables;
|
||||
extern VAR_CONTEXT *shell_variables;
|
||||
|
||||
extern HASH_TABLE *shell_functions;
|
||||
extern HASH_TABLE *temporary_env;
|
||||
|
||||
extern int variable_context;
|
||||
extern char *dollar_vars[];
|
||||
extern char **export_env;
|
||||
|
||||
extern void initialize_shell_variables __P((char **, int));
|
||||
extern SHELL_VAR *set_if_not __P((char *, char *));
|
||||
|
||||
extern void sh_set_lines_and_columns __P((int, int));
|
||||
extern void set_pwd __P((void));
|
||||
extern void set_ppid __P((void));
|
||||
extern void make_funcname_visible __P((int));
|
||||
|
||||
extern SHELL_VAR *var_lookup __P((const char *, VAR_CONTEXT *));
|
||||
|
||||
extern SHELL_VAR *find_function __P((const char *));
|
||||
extern FUNCTION_DEF *find_function_def __P((const char *));
|
||||
extern SHELL_VAR *find_variable __P((const char *));
|
||||
extern SHELL_VAR *find_variable_noref __P((const char *));
|
||||
extern SHELL_VAR *find_variable_last_nameref __P((const char *));
|
||||
extern SHELL_VAR *find_global_variable_last_nameref __P((const char *));
|
||||
extern SHELL_VAR *find_variable_nameref __P((SHELL_VAR *));
|
||||
extern SHELL_VAR *find_variable_internal __P((const char *, int));
|
||||
extern SHELL_VAR *find_variable_tempenv __P((const char *));
|
||||
extern SHELL_VAR *find_variable_notempenv __P((const char *));
|
||||
extern SHELL_VAR *find_global_variable __P((const char *));
|
||||
extern SHELL_VAR *find_global_variable_noref __P((const char *));
|
||||
extern SHELL_VAR *find_shell_variable __P((const char *));
|
||||
extern SHELL_VAR *find_tempenv_variable __P((const char *));
|
||||
extern SHELL_VAR *copy_variable __P((SHELL_VAR *));
|
||||
extern SHELL_VAR *make_local_variable __P((const char *));
|
||||
extern SHELL_VAR *bind_variable __P((const char *, char *, int));
|
||||
extern SHELL_VAR *bind_global_variable __P((const char *, char *, int));
|
||||
extern SHELL_VAR *bind_function __P((const char *, COMMAND *));
|
||||
|
||||
extern void bind_function_def __P((const char *, FUNCTION_DEF *));
|
||||
|
||||
extern SHELL_VAR **map_over __P((sh_var_map_func_t *, VAR_CONTEXT *));
|
||||
SHELL_VAR **map_over_funcs __P((sh_var_map_func_t *));
|
||||
|
||||
extern SHELL_VAR **all_shell_variables __P((void));
|
||||
extern SHELL_VAR **all_shell_functions __P((void));
|
||||
extern SHELL_VAR **all_visible_variables __P((void));
|
||||
extern SHELL_VAR **all_visible_functions __P((void));
|
||||
extern SHELL_VAR **all_exported_variables __P((void));
|
||||
extern SHELL_VAR **local_exported_variables __P((void));
|
||||
extern SHELL_VAR **all_local_variables __P((void));
|
||||
#if defined (ARRAY_VARS)
|
||||
extern SHELL_VAR **all_array_variables __P((void));
|
||||
#endif
|
||||
extern char **all_variables_matching_prefix __P((const char *));
|
||||
|
||||
extern char **make_var_array __P((HASH_TABLE *));
|
||||
extern char **add_or_supercede_exported_var __P((char *, int));
|
||||
|
||||
extern char *get_variable_value __P((SHELL_VAR *));
|
||||
extern char *get_string_value __P((const char *));
|
||||
extern char *sh_get_env_value __P((const char *));
|
||||
extern char *make_variable_value __P((SHELL_VAR *, char *, int));
|
||||
|
||||
extern SHELL_VAR *bind_variable_value __P((SHELL_VAR *, char *, int));
|
||||
extern SHELL_VAR *bind_int_variable __P((char *, char *));
|
||||
extern SHELL_VAR *bind_var_to_int __P((char *, intmax_t));
|
||||
|
||||
extern int assign_in_env __P((WORD_DESC *, int));
|
||||
|
||||
extern int unbind_variable __P((const char *));
|
||||
extern int unbind_nameref __P((const char *));
|
||||
extern int unbind_func __P((const char *));
|
||||
extern int unbind_function_def __P((const char *));
|
||||
extern int makunbound __P((const char *, VAR_CONTEXT *));
|
||||
extern int kill_local_variable __P((const char *));
|
||||
extern void delete_all_variables __P((HASH_TABLE *));
|
||||
extern void delete_all_contexts __P((VAR_CONTEXT *));
|
||||
|
||||
extern VAR_CONTEXT *new_var_context __P((char *, int));
|
||||
extern void dispose_var_context __P((VAR_CONTEXT *));
|
||||
extern VAR_CONTEXT *push_var_context __P((char *, int, HASH_TABLE *));
|
||||
extern void pop_var_context __P((void));
|
||||
extern VAR_CONTEXT *push_scope __P((int, HASH_TABLE *));
|
||||
extern void pop_scope __P((int));
|
||||
|
||||
extern void push_context __P((char *, int, HASH_TABLE *));
|
||||
extern void pop_context __P((void));
|
||||
extern void push_dollar_vars __P((void));
|
||||
extern void pop_dollar_vars __P((void));
|
||||
extern void dispose_saved_dollar_vars __P((void));
|
||||
|
||||
extern void push_args __P((WORD_LIST *));
|
||||
extern void pop_args __P((void));
|
||||
|
||||
extern void adjust_shell_level __P((int));
|
||||
extern void non_unsettable __P((char *));
|
||||
extern void dispose_variable __P((SHELL_VAR *));
|
||||
extern void dispose_used_env_vars __P((void));
|
||||
extern void dispose_function_env __P((void));
|
||||
extern void dispose_builtin_env __P((void));
|
||||
extern void merge_temporary_env __P((void));
|
||||
extern void merge_builtin_env __P((void));
|
||||
extern void kill_all_local_variables __P((void));
|
||||
|
||||
extern void set_var_read_only __P((char *));
|
||||
extern void set_func_read_only __P((const char *));
|
||||
extern void set_var_auto_export __P((char *));
|
||||
extern void set_func_auto_export __P((const char *));
|
||||
|
||||
extern void sort_variables __P((SHELL_VAR **));
|
||||
|
||||
extern int chkexport __P((char *));
|
||||
extern void maybe_make_export_env __P((void));
|
||||
extern void update_export_env_inplace __P((char *, int, char *));
|
||||
extern void put_command_name_into_env __P((char *));
|
||||
extern void put_gnu_argv_flags_into_env __P((intmax_t, char *));
|
||||
|
||||
extern void print_var_list __P((SHELL_VAR **));
|
||||
extern void print_func_list __P((SHELL_VAR **));
|
||||
extern void print_assignment __P((SHELL_VAR *));
|
||||
extern void print_var_value __P((SHELL_VAR *, int));
|
||||
extern void print_var_function __P((SHELL_VAR *));
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
extern SHELL_VAR *make_new_array_variable __P((char *));
|
||||
extern SHELL_VAR *make_local_array_variable __P((char *, int));
|
||||
|
||||
extern SHELL_VAR *make_new_assoc_variable __P((char *));
|
||||
extern SHELL_VAR *make_local_assoc_variable __P((char *));
|
||||
|
||||
extern void set_pipestatus_array __P((int *, int));
|
||||
extern ARRAY *save_pipestatus_array __P((void));
|
||||
extern void restore_pipestatus_array __P((ARRAY *));
|
||||
#endif
|
||||
|
||||
extern void set_pipestatus_from_exit __P((int));
|
||||
|
||||
/* The variable in NAME has just had its state changed. Check to see if it
|
||||
is one of the special ones where something special happens. */
|
||||
extern void stupidly_hack_special_variables __P((char *));
|
||||
|
||||
/* Reinitialize some special variables that have external effects upon unset
|
||||
when the shell reinitializes itself. */
|
||||
extern void reinit_special_variables __P((void));
|
||||
|
||||
extern int get_random_number __P((void));
|
||||
|
||||
/* The `special variable' functions that get called when a particular
|
||||
variable is set. */
|
||||
extern void sv_ifs __P((char *));
|
||||
extern void sv_path __P((char *));
|
||||
extern void sv_mail __P((char *));
|
||||
extern void sv_funcnest __P((char *));
|
||||
extern void sv_globignore __P((char *));
|
||||
extern void sv_ignoreeof __P((char *));
|
||||
extern void sv_strict_posix __P((char *));
|
||||
extern void sv_optind __P((char *));
|
||||
extern void sv_opterr __P((char *));
|
||||
extern void sv_locale __P((char *));
|
||||
extern void sv_xtracefd __P((char *));
|
||||
|
||||
#if defined (READLINE)
|
||||
extern void sv_comp_wordbreaks __P((char *));
|
||||
extern void sv_terminal __P((char *));
|
||||
extern void sv_hostfile __P((char *));
|
||||
extern void sv_winsize __P((char *));
|
||||
#endif
|
||||
|
||||
#if defined (__CYGWIN__)
|
||||
extern void sv_home __P((char *));
|
||||
#endif
|
||||
|
||||
#if defined (HISTORY)
|
||||
extern void sv_histsize __P((char *));
|
||||
extern void sv_histignore __P((char *));
|
||||
extern void sv_history_control __P((char *));
|
||||
# if defined (BANG_HISTORY)
|
||||
extern void sv_histchars __P((char *));
|
||||
# endif
|
||||
extern void sv_histtimefmt __P((char *));
|
||||
#endif /* HISTORY */
|
||||
|
||||
#if defined (HAVE_TZSET)
|
||||
extern void sv_tz __P((char *));
|
||||
#endif
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
extern void sv_childmax __P((char *));
|
||||
#endif
|
||||
|
||||
#endif /* !_VARIABLES_H_ */
|
||||
-94
@@ -1,94 +0,0 @@
|
||||
/* version.c -- distribution and version numbers. */
|
||||
|
||||
/* Copyright (C) 1989-2011 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>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "stdc.h"
|
||||
|
||||
#include "version.h"
|
||||
#include "patchlevel.h"
|
||||
#include "conftypes.h"
|
||||
|
||||
#include "bashintl.h"
|
||||
|
||||
extern char *shell_name;
|
||||
|
||||
/* Defines from version.h */
|
||||
const char * const dist_version = DISTVERSION;
|
||||
const int patch_level = PATCHLEVEL;
|
||||
const int build_version = BUILDVERSION;
|
||||
#ifdef RELSTATUS
|
||||
const char * const release_status = RELSTATUS;
|
||||
#else
|
||||
const char * const release_status = (char *)0;
|
||||
#endif
|
||||
const char * const sccs_version = SCCSVERSION;
|
||||
|
||||
const char * const bash_copyright = N_("Copyright (C) 2011 Free Software Foundation, Inc.");
|
||||
const char * const bash_license = N_("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
|
||||
|
||||
/* If == 31, shell compatible with bash-3.1, == 32 with bash-3.2, and so on */
|
||||
int shell_compatibility_level = DEFAULT_COMPAT_LEVEL;
|
||||
|
||||
/* Functions for getting, setting, and displaying the shell version. */
|
||||
|
||||
/* Forward declarations so we don't have to include externs.h */
|
||||
extern char *shell_version_string __P((void));
|
||||
extern void show_shell_version __P((int));
|
||||
|
||||
/* Give version information about this shell. */
|
||||
char *
|
||||
shell_version_string ()
|
||||
{
|
||||
static char tt[32] = { '\0' };
|
||||
|
||||
if (tt[0] == '\0')
|
||||
{
|
||||
if (release_status)
|
||||
#if defined (HAVE_SNPRINTF)
|
||||
snprintf (tt, sizeof (tt), "%s.%d(%d)-%s", dist_version, patch_level, build_version, release_status);
|
||||
#else
|
||||
sprintf (tt, "%s.%d(%d)-%s", dist_version, patch_level, build_version, release_status);
|
||||
#endif
|
||||
else
|
||||
#if defined (HAVE_SNPRINTF)
|
||||
snprintf (tt, sizeof (tt), "%s.%d(%d)", dist_version, patch_level, build_version);
|
||||
#else
|
||||
sprintf (tt, "%s.%d(%d)", dist_version, patch_level, build_version);
|
||||
#endif
|
||||
}
|
||||
return tt;
|
||||
}
|
||||
|
||||
void
|
||||
show_shell_version (extended)
|
||||
int extended;
|
||||
{
|
||||
printf (_("GNU bash, version %s (%s)\n"), shell_version_string (), MACHTYPE);
|
||||
if (extended)
|
||||
{
|
||||
printf ("%s\n", _(bash_copyright));
|
||||
printf ("%s\n", _(bash_license));
|
||||
printf ("%s\n", _("This is free software; you are free to change and redistribute it."));
|
||||
printf ("%s\n", _("There is NO WARRANTY, to the extent permitted by law."));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user