commit bash-20120216 snapshot

This commit is contained in:
Chet Ramey
2012-03-05 21:16:53 -05:00
parent 7f947b6872
commit 1f6ec1a86f
37 changed files with 27234 additions and 28 deletions
+62
View File
@@ -13333,3 +13333,65 @@ builtins/declare.def
assignment like declare a[b]=c. Fixes seg fault resulting from
a being an already-declared local associative array variable in a
function. Ubuntu bash bug 928900.
2/14
----
execute_cmd.c
- execute_command_internal: if redirections into or out of a loop fail,
don't try to free ofifo_list unless saved_fifo is non-zero. It's
only valid if saved_fifo is set
2/15
----
{arrayfunc,braces,variables}.c
- last_command_exit_value: make sure it's set before any calls to
report_error, since -e will cause that to exit the shell
builtins/common.c
- get_job_by_name: call internal_error instead of report_error so this
doesn't exit the shell
2/18
----
builtins/evalstring.c
- parse_and_execute: make sure the file descriptor to be redirected to
is 1 before calling cat_file. One fix for bug reported by Dan Douglas
<ormaaj@gmail.com>
parse.y
- read_token_word: don't return NUMBER if a string of all digits
resolves to a number that overflows the bounds of an intmax_t.
Other fix for bug reported by Dan Douglas <ormaaj@gmail.com>
2/19
----
lib/sh/strtrans.c
- ansicstr: use 0x7f as the boundary for characters that translate
directly from ASCII to unicode (\u and \U escapes) instead of
UCHAR_MAX, since everything >= 0x80 requires more than one byte.
Bug and fix from John Kearney <dethrophes@web.de>
builtins/printf.def
- tescape: ditto for printf \u and \U escape sequences
2/20
----
lib/sh/unicode.c
- u32toutf8: fix to handle encodings up to six bytes long correctly
(though technically UTF-8 only has characters up to 4 bytes long).
Report and fix from John Kearney <dethrophes@web.de>
- u32toutf8: first argument is now an unsigned 32-bit quantity,
changed callers (u32cconv) to pass c instead of wc
- u32reset: new function, resets local static state to uninitialized
(locale information, currently)
lib/sh/strtrans.c
- ansicstr: allocate a new string 6 times longer than the original
if the \U escape sequence appears, to accommodate UTF-8 chars
of maximum theoretical length
locale.c
- call u32reset whenever LC_CTYPE/LC_ALL/LANG is changed to reset the
cached locale information used by u32cconv. From a report from
John Kearney <dethrophes@web.de>
+100 -3
View File
@@ -13277,15 +13277,29 @@ lib/readline/isearch.c
builtins/gen-helpfiles.c
- new file: reads struct builtin and writes the long docs to files
in the `helpdirs' subdirectory. The filename is given in the
previously-unused `handle' member of the struct builtin
previously-unused `handle' member of the struct builtin. Links
with `tmpbuiltins.o', which is created by Makefile to have the
right long documentation. When not cross-compiling, gets the
right #defines based on configuration options from config.h instead
of trying to parse conditional parts of def files. Fixes
shortcoming pointed out by Andreas Schwab <schwab@linux-m68k.org>
builtins/Makefile.in
- tmpbuiltins.c: new generated file, created to enable creation of
separate helpfiles based on correct #defines instead of trying to
parse conditional parts of def files
- gen-helpfiles: new program to generate helpfiles
- gen-helpfiles: new program to generate helpfiles, links with
tmpbuiltins.o
- HELPFILES_TARGET: new target, substituted by configure to `helpdoc'
if separate helpfiles requested
- targets: new target, libbuiltins.a and $(HELPFILES_TARGET)
- CREATED_OBJECTS: new variable, holds created object files for
make clean; changed make clean to remove created objects
- helpdoc: changed to call gen-helpfiles instead of mkbuiltins
Makefile.in
- when building libbuiltins.a, recursively call make with `targets'
argument to make sure separate helpfiles get built
configure.in
- substitute `helpdoc' as value of HELPFILES_TARGET if
@@ -13296,4 +13310,87 @@ builtins/mkbuiltins.c
for function implementing a particular builtin to struct builtin
and to write document file name to `handle' member of struct builtin
- no longer writes separate helpfiles; that is left to gen-helpfiles
2/8
---
subst.c
- make sure last_command_exit_value is set to a non-zero value before
any calls to report_error, since `-e' set will short-circuit
report_error. Fixes bug reported by Ewan Mellor
<Ewan.Mellor@eu.citrix.com>
variables.c
- make_local_array_variable: added second argument; if non-zero,
function will return an existing local associative array variable
instead of insisting on an indexed array
variable.h,subst.c
- make_local_array_variable: changed prototype and caller
builtins/declare.def
- declare_internal: add second arg to call to make_local_array_variable;
making_array_special, which indicates we're processing an
assignment like declare a[b]=c. Fixes seg fault resulting from
a being an already-declared local associative array variable in a
function. Ubuntu bash bug 928900.
2/14
----
execute_cmd.c
- execute_command_internal: if redirections into or out of a loop fail,
don't try to free ofifo_list unless saved_fifo is non-zero. It's
only valid if saved_fifo is set
2/15
----
{arrayfunc,braces,variables}.c
- last_command_exit_value: make sure it's set before any calls to
report_error, since -e will cause that to exit the shell
builtins/common.c
- get_job_by_name: call internal_error instead of report_error so this
doesn't exit the shell
2/18
----
builtins/evalstring.c
- parse_and_execute: make sure the file descriptor to be redirected to
is 1 before calling cat_file. One fix for bug reported by Dan Douglas
<ormaaj@gmail.com>
parse.y
- read_token_word: don't return NUMBER if a string of all digits
resolves to a number that overflows the bounds of an intmax_t.
Other fix for bug reported by Dan Douglas <ormaaj@gmail.com>
2/19
----
lib/sh/strtrans.c
- ansicstr: use 0x7f as the boundary for characters that translate
directly from ASCII to unicode (\u and \U escapes) instead of
UCHAR_MAX, since everything >= 0x80 requires more than one byte.
Bug and fix from John Kearney <dethrophes@web.de>
builtins/printf.def
- tescape: ditto for printf \u and \U escape sequences
2/20
----
lib/sh/unicode.c
- u32toutf8: fix to handle encodings up to six bytes long correctly
(though technically UTF-8 only has characters up to 4 bytes long).
Report and fix from John Kearney <dethrophes@web.de>
- u32toutf8: first argument is now an unsigned 32-bit quantity,
changed callers (u32cconv) to pass c instead of wc
- u32reset: new function, resets local static state to uninitialized
(locale information, currently)
lib/sh/strtrans.c
- ansicstr: allocate a new string 6 times longer than the original
if the \U escape sequence appears, to accommodate UTF-8 chars
of maximum theoretical length
locale.c
- call u32reset whenever LC_CTYPE/LC_ALL/LANG is changed to reset the
cached locale information used by u32cconv
+2
View File
@@ -792,6 +792,7 @@ tests/assoc3.sub f
tests/assoc4.sub f
tests/assoc5.sub f
tests/assoc6.sub f
tests/assoc7.sub f
tests/braces.tests f
tests/braces.right f
tests/builtins.tests f
@@ -857,6 +858,7 @@ tests/dstack2.right f
tests/errors.tests f
tests/errors.right f
tests/errors1.sub f
tests/errors2.sub f
tests/execscript f
tests/exec.right f
tests/exec1.sub f 755
+3
View File
@@ -326,6 +326,7 @@ find_or_make_array_variable (name, flags)
}
else if ((flags & 2) && array_p (var))
{
last_command_exit_value = 1;
report_error (_("%s: cannot convert indexed to associative array"), name);
return ((SHELL_VAR *)NULL);
}
@@ -507,6 +508,7 @@ assign_compound_array_list (var, nlist, flags)
if (ALL_ELEMENT_SUB (w[1]) && len == 2)
{
last_command_exit_value = 1;
if (assoc_p (var))
report_error (_("%s: invalid associative array key"), w);
else
@@ -551,6 +553,7 @@ assign_compound_array_list (var, nlist, flags)
}
else if (assoc_p (var))
{
last_command_exit_value = 1;
report_error (_("%s: %s: must use subscript when assigning associative array"), var->name, w);
continue;
}
+3
View File
@@ -47,6 +47,8 @@
extern int asprintf __P((char **, const char *, ...)) __attribute__((__format__ (printf, 2, 3)));
extern int last_command_exit_value;
/* Basic idea:
Segregate the text into 3 sections: preamble (stuff before an open brace),
@@ -172,6 +174,7 @@ brace_expand (text)
if (text[j] == brace_arg_separator)
{ /* { */
strvec_dispose (result);
last_command_exit_value = 1;
report_error ("no closing `%c' in %s", '}', text);
throw_to_top_level ();
}
+1 -1
View File
@@ -628,7 +628,7 @@ get_job_by_name (name, flags)
if (this_shell_builtin)
builtin_error (_("%s: ambiguous job spec"), name);
else
report_error (_("%s: ambiguous job spec"), name);
internal_error (_("%s: ambiguous job spec"), name);
return (DUP_JOB);
}
else
+3 -3
View File
@@ -1,6 +1,6 @@
/* evalstring.c - evaluate a string as one or more shell commands. */
/* Copyright (C) 1996-2010 Free Software Foundation, Inc.
/* Copyright (C) 1996-2012 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -308,7 +308,8 @@ parse_and_execute (string, from_file, flags)
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->instruction == r_input_direction &&
command->value.Simple->redirects->redirector.dest == 1)
{
int r;
r = cat_file (command->value.Simple->redirects);
@@ -317,7 +318,6 @@ parse_and_execute (string, from_file, flags)
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");
+508
View File
@@ -0,0 +1,508 @@
/* evalstring.c - evaluate a string as one or more shell commands. */
/* Copyright (C) 1996-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Bash. If not, see <http://www.gnu.org/licenses/>.
*/
#include <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;
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 sh_builtin_func_t *this_shell_builtin;
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
/* 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;
int x;
orig_string = string;
/* Unwind protect this invocation of parse_and_execute (). */
begin_unwind_frame (tag);
unwind_protect_int (parse_and_execute_level);
unwind_protect_jmp_buf (top_level);
unwind_protect_int (indirection_level);
unwind_protect_int (line_number);
unwind_protect_int (loop_level);
unwind_protect_int (executing_list);
unwind_protect_int (comsub_ignore_return);
if (flags & (SEVAL_NONINT|SEVAL_INTERACT))
unwind_protect_int (interactive);
#if defined (HISTORY)
if (parse_and_execute_level == 0)
add_unwind_protect (set_history_remembering, (char *)NULL);
else
unwind_protect_int (remember_on_history); /* can be used in scripts */
# if defined (BANG_HISTORY)
if (interactive_shell)
unwind_protect_int (history_expansion_inhibited);
# endif /* BANG_HISTORY */
#endif /* HISTORY */
if (interactive_shell)
{
x = get_current_prompt_level ();
add_unwind_protect (set_current_prompt_level, x);
}
add_unwind_protect (pop_stream, (char *)NULL);
if (orig_string && ((flags & SEVAL_NOFREE) == 0))
add_unwind_protect (xfree, orig_string);
end_unwind_frame ();
if (flags & (SEVAL_NONINT|SEVAL_INTERACT))
interactive = (flags & SEVAL_NONINT) ? 0 : 1;
#if defined (HISTORY)
if (flags & SEVAL_NOHIST)
bash_history_disable ();
#endif /* HISTORY */
}
/* Parse and execute the commands in STRING. Returns whatever
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;
parse_prologue (string, flags, PE_TAG);
parse_and_execute_level++;
lreset = flags & SEVAL_RESETLINE;
/* Reset the line number if the caller wants us to. If we don't reset the
line number, we have to subtract one, because we will add one just
before executing the next command (resetting the line number sets it to
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 (top_level);
if (code)
{
should_jump_to_top_level = 0;
switch (code)
{
case FORCE_EOF:
case ERREXIT:
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
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 == 1)
{
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;
parse_prologue (string, flags, PS_TAG);
/* Reset the line number if the caller wants us to. If we don't reset the
line number, we have to subtract one, because we will add one just
before executing the next command (resetting the line number sets it to
0; the first line number is 1). */
push_stream (0);
code = should_jump_to_top_level = 0;
oglobal = global_command;
ostring = string;
with_input_from_string (string, from_file);
while (*(bash_input.location.string))
{
command = (COMMAND *)NULL;
#if 0
if (interrupt_state)
break;
#endif
/* Provide a location for functions which `longjmp (top_level)' to
jump to. */
code = setjmp (top_level);
if (code)
{
#if defined (DEBUG)
itrace("parse_string: longjmp executed: code = %d", code);
#endif
should_jump_to_top_level = 0;
switch (code)
{
case FORCE_EOF:
case ERREXIT:
case EXITPROG:
case DISCARD: /* XXX */
if (command)
dispose_command (command);
/* Remember to call longjmp (top_level) after the old
value for it is restored. */
should_jump_to_top_level = 1;
goto out;
default:
command_error ("parse_string", CMDERR_BADJUMP, code, 0);
break;
}
}
if (parse_command () == 0)
{
dispose_command (global_command);
global_command = (COMMAND *)NULL;
}
else
{
if ((flags & SEVAL_NOLONGJMP) == 0)
{
should_jump_to_top_level = 1;
code = DISCARD;
}
else
reset_parser (); /* XXX - sets token_to_read */
break;
}
if (current_token == yacc_EOF || current_token == shell_eof_token)
break;
}
out:
global_command = oglobal;
nc = bash_input.location.string - ostring;
if (endp)
*endp = bash_input.location.string;
run_unwind_frame (PS_TAG);
if (should_jump_to_top_level)
jump_to_top_level (code);
return (nc);
}
/* Handle a $( < file ) command substitution. This expands the filename,
returning errors as appropriate, then just cats the file to the standard
output. */
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);
}
+1 -1
View File
@@ -870,7 +870,7 @@ tescape (estart, cp, lenp, sawc)
*cp = '\\';
return 0;
}
if (uvalue <= UCHAR_MAX)
if (uvalue <= 0x7f) /* <= 0x7f translates directly */
*cp = uvalue;
else
{
+1252
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -693,7 +693,8 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
redirection_undo_list = (REDIRECT *)NULL;
dispose_exec_redirects ();
#if defined (PROCESS_SUBSTITUTION)
free (ofifo_list);
if (saved_fifo)
free (ofifo_list);
#endif
return (last_command_exit_value = EXECUTION_FAILURE);
}
+5336
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -463,6 +463,7 @@ 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/winsize.c */
extern void get_new_window_size __P((int, int *, int *));
+500
View File
@@ -0,0 +1,500 @@
/* 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 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 *));
/* 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 *));
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 *));
/* 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_ */
+3
View File
@@ -533,6 +533,9 @@ _rl_settracefp (fp)
#if HAVE_DECL_AUDIT_USER_TTY && defined (ENABLE_TTY_AUDIT_SUPPORT)
#include <sys/socket.h>
#include <linux/audit.h>
#include <linux/netlink.h>
/* Report STRING to the audit system. */
void
+5 -2
View File
@@ -60,7 +60,10 @@ ansicstr (string, len, flags, sawc, rlen)
return ((char *)NULL);
#if defined (HANDLE_MULTIBYTE)
ret = (char *)xmalloc (4*len + 1);
if (strstr (string, "\\U") != 0)
ret = (char *)xmalloc (6*len + 1);
else
ret = (char *)xmalloc (4*len + 1);
#else
ret = (char *)xmalloc (2*len + 1); /* 2*len for possible CTLESC */
#endif
@@ -147,7 +150,7 @@ ansicstr (string, len, flags, sawc, rlen)
*r++ = '\\'; /* c remains unchanged */
break;
}
else if (v <= UCHAR_MAX)
else if (v <= 0x7f) /* <= 0x7f translates directly */
{
c = v;
break;
+374
View File
@@ -0,0 +1,374 @@
/* strtrans.c - Translate and untranslate strings with ANSI-C escape sequences. */
/* Copyright (C) 2000-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)
# include <unistd.h>
#endif
#include <bashansi.h>
#include <stdio.h>
#include <chartypes.h>
#include "shell.h"
#include "shmbchar.h"
#include "shmbutil.h"
#ifdef ESC
#undef ESC
#endif
#define ESC '\033' /* ASCII */
/* Convert STRING by expanding the escape sequences specified by the
ANSI C standard. If SAWC is non-null, recognize `\c' and use that
as a string terminator. If we see \c, set *SAWC to 1 before
returning. LEN is the length of STRING. If (FLAGS&1) is non-zero,
that we're translating a string for `echo -e', and therefore should not
treat a single quote as a character that may be escaped with a backslash.
If (FLAGS&2) is non-zero, we're expanding for the parser and want to
quote CTLESC and CTLNUL with CTLESC. If (flags&4) is non-zero, we want
to remove the backslash before any unrecognized escape sequence. */
char *
ansicstr (string, len, flags, sawc, rlen)
char *string;
int len, flags, *sawc, *rlen;
{
int c, temp;
char *ret, *r, *s;
unsigned long v;
if (string == 0 || *string == '\0')
return ((char *)NULL);
#if defined (HANDLE_MULTIBYTE)
ret = (char *)xmalloc (6*len + 1);
#else
ret = (char *)xmalloc (2*len + 1); /* 2*len for possible CTLESC */
#endif
for (r = ret, s = string; s && *s; )
{
c = *s++;
if (c != '\\' || *s == '\0')
*r++ = c;
else
{
switch (c = *s++)
{
#if defined (__STDC__)
case 'a': c = '\a'; break;
case 'v': c = '\v'; break;
#else
case 'a': c = (int) 0x07; break;
case 'v': c = (int) 0x0B; break;
#endif
case 'b': c = '\b'; break;
case 'e': case 'E': /* ESC -- non-ANSI */
c = ESC; break;
case 'f': c = '\f'; break;
case 'n': c = '\n'; break;
case 'r': c = '\r'; break;
case 't': c = '\t'; break;
case '1': case '2': case '3':
case '4': case '5': case '6':
case '7':
#if 1
if (flags & 1)
{
*r++ = '\\';
break;
}
/*FALLTHROUGH*/
#endif
case '0':
/* If (FLAGS & 1), we're translating a string for echo -e (or
the equivalent xpg_echo option), so we obey the SUSv3/
POSIX-2001 requirement and accept 0-3 octal digits after
a leading `0'. */
temp = 2 + ((flags & 1) && (c == '0'));
for (c -= '0'; ISOCTAL (*s) && temp--; s++)
c = (c * 8) + OCTVALUE (*s);
c &= 0xFF;
break;
case 'x': /* Hex digit -- non-ANSI */
if ((flags & 2) && *s == '{')
{
flags |= 16; /* internal flag value */
s++;
}
/* Consume at least two hex characters */
for (temp = 2, c = 0; ISXDIGIT ((unsigned char)*s) && temp--; s++)
c = (c * 16) + HEXVALUE (*s);
/* DGK says that after a `\x{' ksh93 consumes ISXDIGIT chars
until a non-xdigit or `}', so potentially more than two
chars are consumed. */
if (flags & 16)
{
for ( ; ISXDIGIT ((unsigned char)*s); s++)
c = (c * 16) + HEXVALUE (*s);
flags &= ~16;
if (*s == '}')
s++;
}
/* \x followed by non-hex digits is passed through unchanged */
else if (temp == 2)
{
*r++ = '\\';
c = 'x';
}
c &= 0xFF;
break;
#if defined (HANDLE_MULTIBYTE)
case 'u':
case 'U':
temp = (c == 'u') ? 4 : 8; /* \uNNNN \UNNNNNNNN */
for (v = 0; ISXDIGIT ((unsigned char)*s) && temp--; s++)
v = (v * 16) + HEXVALUE (*s);
if (temp == ((c == 'u') ? 4 : 8))
{
*r++ = '\\'; /* c remains unchanged */
break;
}
else if (v <= 0x7f) /* <= 0x7f translates directly */
{
c = v;
break;
}
else
{
temp = u32cconv (v, r);
r += temp;
continue;
}
#endif
case '\\':
break;
case '\'': case '"': case '?':
if (flags & 1)
*r++ = '\\';
break;
case 'c':
if (sawc)
{
*sawc = 1;
*r = '\0';
if (rlen)
*rlen = r - ret;
return ret;
}
else if ((flags & 1) == 0 && *s == 0)
; /* pass \c through */
else if ((flags & 1) == 0 && (c = *s))
{
s++;
if ((flags & 2) && c == '\\' && c == *s)
s++; /* Posix requires $'\c\\' do backslash escaping */
c = TOCTRL(c);
break;
}
/*FALLTHROUGH*/
default:
if ((flags & 4) == 0)
*r++ = '\\';
break;
}
if ((flags & 2) && (c == CTLESC || c == CTLNUL))
*r++ = CTLESC;
*r++ = c;
}
}
*r = '\0';
if (rlen)
*rlen = r - ret;
return ret;
}
/* Take a string STR, possibly containing non-printing characters, and turn it
into a $'...' ANSI-C style quoted string. Returns a new string. */
char *
ansic_quote (str, flags, rlen)
char *str;
int flags, *rlen;
{
char *r, *ret, *s;
int l, rsize, sindex;
unsigned char c;
size_t slen, clen;
#if defined (HANDLE_MULTIBYTE)
int b;
wchar_t wc;
#endif
if (str == 0 || *str == 0)
return ((char *)0);
l = strlen (str);
rsize = 4 * l + 4;
r = ret = (char *)xmalloc (rsize);
*r++ = '$';
*r++ = '\'';
s = str;
slen = strlen (str);
for (s = str; c = *s; s++)
{
l = 1; /* 1 == add backslash; 0 == no backslash */
clen = 1;
switch (c)
{
case ESC: c = 'E'; break;
#ifdef __STDC__
case '\a': c = 'a'; break;
case '\v': c = 'v'; break;
#else
case 0x07: c = 'a'; break;
case 0x0b: c = 'v'; break;
#endif
case '\b': c = 'b'; break;
case '\f': c = 'f'; break;
case '\n': c = 'n'; break;
case '\r': c = 'r'; break;
case '\t': c = 't'; break;
case '\\':
case '\'':
break;
default:
#if defined (HANDLE_MULTIBYTE)
b = is_basic (c);
if ((b == 0 && ((clen = mbrtowc (&wc, s, MB_CUR_MAX, 0)) < 0 || iswprint (wc) == 0)) ||
(b == 1 && ISPRINT (c) == 0))
#else
if (ISPRINT (c) == 0)
#endif
{
*r++ = '\\';
*r++ = TOCHAR ((c >> 6) & 07);
*r++ = TOCHAR ((c >> 3) & 07);
*r++ = TOCHAR (c & 07);
continue;
}
l = 0;
break;
}
if (l)
*r++ = '\\';
if (clen == 1)
*r++ = c;
else
for (b = 0; b < (int)clen; c = b ? *++s : c)
*r++ = c;
}
*r++ = '\'';
*r = '\0';
if (rlen)
*rlen = r - ret;
return ret;
}
#if defined (HANDLE_MULTIBYTE)
int
ansic_wshouldquote (string)
const char *string;
{
const wchar_t *wcs;
wchar_t wcc;
wchar_t *wcstr = NULL;
size_t wclen, slen;
slen = mbstowcs (wcstr, string, 0);
if (slen == -1)
slen = 0;
wcstr = (wchar_t *)xmalloc (sizeof (wchar_t) * (slen + 1));
mbstowcs (wcstr, string, slen + 1);
for (wcs = wcstr; wcc = *wcs; wcs++)
if (iswprint(wcc) == 0)
{
free (wcstr);
return 1;
}
free (wcstr);
return 0;
}
#endif
/* return 1 if we need to quote with $'...' because of non-printing chars. */
int
ansic_shouldquote (string)
const char *string;
{
const char *s;
unsigned char c;
if (string == 0)
return 0;
for (s = string; c = *s; s++)
{
#if defined (HANDLE_MULTIBYTE)
if (is_basic (c) == 0)
return (ansic_wshouldquote (s));
#endif
if (ISPRINT (c) == 0)
return 1;
}
return 0;
}
/* $'...' ANSI-C expand the portion of STRING between START and END and
return the result. The result cannot be longer than the input string. */
char *
ansiexpand (string, start, end, lenp)
char *string;
int start, end, *lenp;
{
char *temp, *t;
int len, tlen;
temp = (char *)xmalloc (end - start + 1);
for (tlen = 0, len = start; len < end; )
temp[tlen++] = string[len++];
temp[tlen] = '\0';
if (*temp)
{
t = ansicstr (temp, tlen, 2, (int *)NULL, lenp);
free (temp);
return (t);
}
else
{
if (lenp)
*lenp = 0;
return (temp);
}
}
+48 -8
View File
@@ -84,6 +84,13 @@ stub_charset ()
}
#endif
void
u32reset ()
{
u32init = 0;
utf8locale = 0;
}
/* u32toascii ? */
int
u32tochar (wc, s)
@@ -114,28 +121,61 @@ u32tochar (wc, s)
return l;
}
/* Convert unsigned 32-bit int to utf-8 character string */
int
u32toutf8 (wc, s)
wchar_t wc;
u_bits32_t wc;
char *s;
{
int l;
l = (wc < 0x0080) ? 1 : ((wc < 0x0800) ? 2 : 3);
if (wc < 0x0080)
s[0] = (unsigned char)wc;
{
s[0] = (char)wc;
l = 1;
}
else if (wc < 0x0800)
{
s[0] = (wc >> 6) | 0xc0;
s[1] = (wc & 0x3f) | 0x80;
l = 2;
}
else
else if (wc < 0x10000)
{
s[0] = (wc >> 12) | 0xe0;
s[1] = ((wc >> 6) & 0x3f) | 0x80;
s[2] = (wc & 0x3f) | 0x80;
l = 3;
}
else if (wc < 0x200000)
{
s[0] = (wc >> 18) | 0xf0;
s[1] = ((wc >> 12) & 0x3f) | 0x80;
s[2] = ((wc >> 6) & 0x3f) | 0x80;
s[3] = (wc & 0x3f) | 0x80;
l = 4;
}
/* Strictly speaking, UTF-8 doesn't have characters longer than 4 bytes */
else if (wc < 0x04000000)
{
s[0] = (wc >> 24) | 0xf8;
s[1] = ((wc >> 18) & 0x3f) | 0x80;
s[2] = ((wc >> 12) & 0x3f) | 0x80;
s[3] = ((wc >> 6) & 0x3f) | 0x80;
s[4] = (wc & 0x3f) | 0x80;
l = 5;
}
else
{
s[0] = (wc >> 30) | 0xf8;
s[1] = ((wc >> 24) & 0x3f) | 0x80;
s[2] = ((wc >> 18) & 0x3f) | 0x80;
s[3] = ((wc >> 12) & 0x3f) | 0x80;
s[4] = ((wc >> 6) & 0x3f) | 0x80;
s[5] = (wc & 0x3f) | 0x80;
l = 6;
}
s[l] = '\0';
return l;
}
@@ -171,7 +211,7 @@ u32cconv (c, s)
codeset = nl_langinfo (CODESET);
if (STREQ (codeset, "UTF-8"))
{
n = u32toutf8 (wc, s);
n = u32toutf8 (c, s);
return n;
}
#endif
@@ -198,7 +238,7 @@ u32cconv (c, s)
if (utf8locale)
{
n = u32toutf8 (wc, s);
n = u32toutf8 (c, s);
return n;
}
@@ -208,7 +248,7 @@ u32cconv (c, s)
return n;
}
n = u32toutf8 (wc, s);
n = u32toutf8 (c, s);
optr = obuf;
obytesleft = sizeof (obuf);
+4
View File
@@ -103,6 +103,7 @@ set_default_locale_vars ()
setlocale (LC_CTYPE, lc_all);
locale_setblanks ();
locale_mb_cur_max = MB_CUR_MAX;
u32reset ();
}
# endif
@@ -206,6 +207,7 @@ set_locale_var (var, value)
}
locale_setblanks ();
locale_mb_cur_max = MB_CUR_MAX;
u32reset ();
return r;
#else
return (1);
@@ -221,6 +223,7 @@ set_locale_var (var, value)
x = setlocale (LC_CTYPE, get_locale_var ("LC_CTYPE"));
locale_setblanks ();
locale_mb_cur_max = MB_CUR_MAX;
u32reset ();
}
# endif
}
@@ -353,6 +356,7 @@ reset_locale_vars ()
locale_setblanks ();
locale_mb_cur_max = MB_CUR_MAX;
u32reset ();
#endif
return 1;
+563
View File
@@ -0,0 +1,563 @@
/* locale.c - Miscellaneous internationalization functions. */
/* 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"
#include "bashtypes.h"
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#if HAVE_LANGINFO_CODESET
# include <langinfo.h>
#endif
#include "bashintl.h"
#include "bashansi.h"
#include <stdio.h>
#include "chartypes.h"
#include <errno.h>
#include "shell.h"
#include "input.h" /* For bash_input */
#ifndef errno
extern int errno;
#endif
int locale_utf8locale; /* unused for now */
int locale_mb_cur_max; /* value of MB_CUR_MAX for current locale (LC_CTYPE) */
extern int dump_translatable_strings, dump_po_strings;
/* The current locale when the program begins */
static char *default_locale;
/* The current domain for textdomain(3). */
static char *default_domain;
static char *default_dir;
/* tracks the value of LC_ALL; used to override values for other locale
categories */
static char *lc_all;
/* tracks the value of LC_ALL; used to provide defaults for locale
categories */
static char *lang;
/* Called to reset all of the locale variables to their appropriate values
if (and only if) LC_ALL has not been assigned a value. */
static int reset_locale_vars __P((void));
static void locale_setblanks __P((void));
static int locale_isutf8 __P((char *));
/* Set the value of default_locale and make the current locale the
system default locale. This should be called very early in main(). */
void
set_default_locale ()
{
#if defined (HAVE_SETLOCALE)
default_locale = setlocale (LC_ALL, "");
if (default_locale)
default_locale = savestring (default_locale);
#endif /* HAVE_SETLOCALE */
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
locale_mb_cur_max = MB_CUR_MAX;
}
/* Set default values for LC_CTYPE, LC_COLLATE, LC_MESSAGES, LC_NUMERIC and
LC_TIME if they are not specified in the environment, but LC_ALL is. This
should be called from main() after parsing the environment. */
void
set_default_locale_vars ()
{
char *val;
#if defined (HAVE_SETLOCALE)
# if defined (LC_CTYPE)
val = get_string_value ("LC_CTYPE");
if (val == 0 && lc_all && *lc_all)
{
setlocale (LC_CTYPE, lc_all);
locale_setblanks ();
locale_mb_cur_max = MB_CUR_MAX;
}
# endif
# if defined (LC_COLLATE)
val = get_string_value ("LC_COLLATE");
if (val == 0 && lc_all && *lc_all)
setlocale (LC_COLLATE, lc_all);
# endif /* LC_COLLATE */
# if defined (LC_MESSAGES)
val = get_string_value ("LC_MESSAGES");
if (val == 0 && lc_all && *lc_all)
setlocale (LC_MESSAGES, lc_all);
# endif /* LC_MESSAGES */
# if defined (LC_NUMERIC)
val = get_string_value ("LC_NUMERIC");
if (val == 0 && lc_all && *lc_all)
setlocale (LC_NUMERIC, lc_all);
# endif /* LC_NUMERIC */
# if defined (LC_TIME)
val = get_string_value ("LC_TIME");
if (val == 0 && lc_all && *lc_all)
setlocale (LC_TIME, lc_all);
# endif /* LC_TIME */
#endif /* HAVE_SETLOCALE */
val = get_string_value ("TEXTDOMAIN");
if (val && *val)
{
FREE (default_domain);
default_domain = savestring (val);
#if 0
/* Don't want to override the shell's textdomain as the default */
textdomain (default_domain);
#endif
}
val = get_string_value ("TEXTDOMAINDIR");
if (val && *val)
{
FREE (default_dir);
default_dir = savestring (val);
if (default_domain && *default_domain)
bindtextdomain (default_domain, default_dir);
}
}
/* Set one of the locale categories (specified by VAR) to VALUE. Returns 1
if successful, 0 otherwise. */
int
set_locale_var (var, value)
char *var, *value;
{
int r;
char *x;
x = "";
errno = 0;
if (var[0] == 'T' && var[10] == 0) /* TEXTDOMAIN */
{
FREE (default_domain);
default_domain = value ? savestring (value) : (char *)NULL;
#if 0
/* Don't want to override the shell's textdomain as the default */
textdomain (default_domain);
#endif
return (1);
}
else if (var[0] == 'T') /* TEXTDOMAINDIR */
{
FREE (default_dir);
default_dir = value ? savestring (value) : (char *)NULL;
if (default_domain && *default_domain)
bindtextdomain (default_domain, default_dir);
return (1);
}
/* var[0] == 'L' && var[1] == 'C' && var[2] == '_' */
else if (var[3] == 'A') /* LC_ALL */
{
FREE (lc_all);
if (value)
lc_all = savestring (value);
else
{
lc_all = (char *)xmalloc (1);
lc_all[0] = '\0';
}
#if defined (HAVE_SETLOCALE)
r = *lc_all ? ((x = setlocale (LC_ALL, lc_all)) != 0) : reset_locale_vars ();
if (x == 0)
{
if (errno == 0)
internal_warning(_("setlocale: LC_ALL: cannot change locale (%s)"), lc_all);
else
internal_warning(_("setlocale: LC_ALL: cannot change locale (%s): %s"), lc_all, strerror (errno));
}
locale_setblanks ();
locale_mb_cur_max = MB_CUR_MAX;
return r;
#else
return (1);
#endif
}
#if defined (HAVE_SETLOCALE)
else if (var[3] == 'C' && var[4] == 'T') /* LC_CTYPE */
{
# if defined (LC_CTYPE)
if (lc_all == 0 || *lc_all == '\0')
{
x = setlocale (LC_CTYPE, get_locale_var ("LC_CTYPE"));
locale_setblanks ();
locale_mb_cur_max = MB_CUR_MAX;
}
# endif
}
else if (var[3] == 'C' && var[4] == 'O') /* LC_COLLATE */
{
# if defined (LC_COLLATE)
if (lc_all == 0 || *lc_all == '\0')
x = setlocale (LC_COLLATE, get_locale_var ("LC_COLLATE"));
# endif /* LC_COLLATE */
}
else if (var[3] == 'M' && var[4] == 'E') /* LC_MESSAGES */
{
# if defined (LC_MESSAGES)
if (lc_all == 0 || *lc_all == '\0')
x = setlocale (LC_MESSAGES, get_locale_var ("LC_MESSAGES"));
# endif /* LC_MESSAGES */
}
else if (var[3] == 'N' && var[4] == 'U') /* LC_NUMERIC */
{
# if defined (LC_NUMERIC)
if (lc_all == 0 || *lc_all == '\0')
x = setlocale (LC_NUMERIC, get_locale_var ("LC_NUMERIC"));
# endif /* LC_NUMERIC */
}
else if (var[3] == 'T' && var[4] == 'I') /* LC_TIME */
{
# if defined (LC_TIME)
if (lc_all == 0 || *lc_all == '\0')
x = setlocale (LC_TIME, get_locale_var ("LC_TIME"));
# endif /* LC_TIME */
}
#endif /* HAVE_SETLOCALE */
if (x == 0)
{
if (errno == 0)
internal_warning(_("setlocale: %s: cannot change locale (%s)"), var, get_locale_var (var));
else
internal_warning(_("setlocale: %s: cannot change locale (%s): %s"), var, get_locale_var (var), strerror (errno));
}
return (x != 0);
}
/* Called when LANG is assigned a value. Tracks value in `lang'. Calls
reset_locale_vars() to reset any default values if LC_ALL is unset or
null. */
int
set_lang (var, value)
char *var, *value;
{
FREE (lang);
if (value)
lang = savestring (value);
else
{
lang = (char *)xmalloc (1);
lang[0] = '\0';
}
return ((lc_all == 0 || *lc_all == 0) ? reset_locale_vars () : 0);
}
/* Set default values for LANG and LC_ALL. Default values for all other
locale-related variables depend on these. */
void
set_default_lang ()
{
char *v;
v = get_string_value ("LC_ALL");
set_locale_var ("LC_ALL", v);
v = get_string_value ("LANG");
set_lang ("LANG", v);
}
/* Get the value of one of the locale variables (LC_MESSAGES, LC_CTYPE).
The precedence is as POSIX.2 specifies: LC_ALL has precedence over
the specific locale variables, and LANG, if set, is used as the default. */
char *
get_locale_var (var)
char *var;
{
char *locale;
locale = lc_all;
if (locale == 0 || *locale == 0)
locale = get_string_value (var); /* XXX - mem leak? */
if (locale == 0 || *locale == 0)
locale = lang;
if (locale == 0 || *locale == 0)
#if 0
locale = default_locale; /* system-dependent; not really portable. should it be "C"? */
#else
locale = "";
#endif
return (locale);
}
/* Called to reset all of the locale variables to their appropriate values
if (and only if) LC_ALL has not been assigned a value. DO NOT CALL THIS
IF LC_ALL HAS BEEN ASSIGNED A VALUE. */
static int
reset_locale_vars ()
{
char *t;
#if defined (HAVE_SETLOCALE)
if (lang == 0 || *lang == '\0')
maybe_make_export_env (); /* trust that this will change environment for setlocale */
if (setlocale (LC_ALL, lang ? lang : "") == 0)
return 0;
# if defined (LC_CTYPE)
t = setlocale (LC_CTYPE, get_locale_var ("LC_CTYPE"));
# endif
# if defined (LC_COLLATE)
t = setlocale (LC_COLLATE, get_locale_var ("LC_COLLATE"));
# endif
# if defined (LC_MESSAGES)
t = setlocale (LC_MESSAGES, get_locale_var ("LC_MESSAGES"));
# endif
# if defined (LC_NUMERIC)
t = setlocale (LC_NUMERIC, get_locale_var ("LC_NUMERIC"));
# endif
# if defined (LC_TIME)
t = setlocale (LC_TIME, get_locale_var ("LC_TIME"));
# endif
locale_setblanks ();
locale_mb_cur_max = MB_CUR_MAX;
#endif
return 1;
}
/* Translate the contents of STRING, a $"..." quoted string, according
to the current locale. In the `C' or `POSIX' locale, or if gettext()
is not available, the passed string is returned unchanged. The
length of the translated string is returned in LENP, if non-null. */
char *
localetrans (string, len, lenp)
char *string;
int len, *lenp;
{
char *locale, *t;
char *translated;
int tlen;
/* Don't try to translate null strings. */
if (string == 0 || *string == 0)
{
if (lenp)
*lenp = 0;
return ((char *)NULL);
}
locale = get_locale_var ("LC_MESSAGES");
/* If we don't have setlocale() or the current locale is `C' or `POSIX',
just return the string. If we don't have gettext(), there's no use
doing anything else. */
if (locale == 0 || locale[0] == '\0' ||
(locale[0] == 'C' && locale[1] == '\0') || STREQ (locale, "POSIX"))
{
t = (char *)xmalloc (len + 1);
strcpy (t, string);
if (lenp)
*lenp = len;
return (t);
}
/* Now try to translate it. */
if (default_domain && *default_domain)
translated = dgettext (default_domain, string);
else
translated = string;
if (translated == string) /* gettext returns its argument if untranslatable */
{
t = (char *)xmalloc (len + 1);
strcpy (t, string);
if (lenp)
*lenp = len;
}
else
{
tlen = strlen (translated);
t = (char *)xmalloc (tlen + 1);
strcpy (t, translated);
if (lenp)
*lenp = tlen;
}
return (t);
}
/* Change a bash string into a string suitable for inclusion in a `po' file.
This backslash-escapes `"' and `\' and changes newlines into \\\n"\n". */
char *
mk_msgstr (string, foundnlp)
char *string;
int *foundnlp;
{
register int c, len;
char *result, *r, *s;
for (len = 0, s = string; s && *s; s++)
{
len++;
if (*s == '"' || *s == '\\')
len++;
else if (*s == '\n')
len += 5;
}
r = result = (char *)xmalloc (len + 3);
*r++ = '"';
for (s = string; s && (c = *s); s++)
{
if (c == '\n') /* <NL> -> \n"<NL>" */
{
*r++ = '\\';
*r++ = 'n';
*r++ = '"';
*r++ = '\n';
*r++ = '"';
if (foundnlp)
*foundnlp = 1;
continue;
}
if (c == '"' || c == '\\')
*r++ = '\\';
*r++ = c;
}
*r++ = '"';
*r++ = '\0';
return result;
}
/* $"..." -- Translate the portion of STRING between START and END
according to current locale using gettext (if available) and return
the result. The caller will take care of leaving the quotes intact.
The string will be left without the leading `$' by the caller.
If translation is performed, the translated string will be double-quoted
by the caller. The length of the translated string is returned in LENP,
if non-null. */
char *
localeexpand (string, start, end, lineno, lenp)
char *string;
int start, end, lineno, *lenp;
{
int len, tlen, foundnl;
char *temp, *t, *t2;
temp = (char *)xmalloc (end - start + 1);
for (tlen = 0, len = start; len < end; )
temp[tlen++] = string[len++];
temp[tlen] = '\0';
/* If we're just dumping translatable strings, don't do anything with the
string itself, but if we're dumping in `po' file format, convert it into
a form more palatable to gettext(3) and friends by quoting `"' and `\'
with backslashes and converting <NL> into `\n"<NL>"'. If we find a
newline in TEMP, we first output a `msgid ""' line and then the
translated string; otherwise we output the `msgid' and translated
string all on one line. */
if (dump_translatable_strings)
{
if (dump_po_strings)
{
foundnl = 0;
t = mk_msgstr (temp, &foundnl);
t2 = foundnl ? "\"\"\n" : "";
printf ("#: %s:%d\nmsgid %s%s\nmsgstr \"\"\n",
yy_input_name (), lineno, t2, t);
free (t);
}
else
printf ("\"%s\"\n", temp);
if (lenp)
*lenp = tlen;
return (temp);
}
else if (*temp)
{
t = localetrans (temp, tlen, &len);
free (temp);
if (lenp)
*lenp = len;
return (t);
}
else
{
if (lenp)
*lenp = 0;
return (temp);
}
}
/* Set every character in the <blank> character class to be a shell break
character for the lexical analyzer when the locale changes. */
static void
locale_setblanks ()
{
int x;
for (x = 0; x < sh_syntabsiz; x++)
{
if (isblank (x))
sh_syntaxtab[x] |= CSHBRK|CBLANK;
else if (member (x, shell_break_chars))
{
sh_syntaxtab[x] |= CSHBRK;
sh_syntaxtab[x] &= ~CBLANK;
}
else
sh_syntaxtab[x] &= ~(CSHBRK|CBLANK);
}
}
static int
locale_isutf8 (lspec)
char *lspec;
{
char *cp;
#if HAVE_LANGINFO_CODESET
cp = nl_langinfo (CODESET);
return (STREQ (cp, "UTF-8") || STREQ (cp, "utf8"));
#else
/* Take a shot */
return (strstr (lspec, "UTF-8") || strstr (lspec, "utf8"));
#endif
}
+4 -4
View File
@@ -4670,10 +4670,10 @@ got_token:
last_read_token == GREATER_AND))
{
if (legal_number (token, &lvalue) && (int)lvalue == lvalue)
yylval.number = lvalue;
else
yylval.number = -1;
return (NUMBER);
{
yylval.number = lvalue;
return (NUMBER);
}
}
/* Check for special case tokens. */
+6086
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1416,7 +1416,7 @@ indent (amount)
for (i = 0; amount > 0; amount--)
indentation_string[i++] = ' ';
indentation_string[i] = '\0';
cprintf (indentation_string);
cprintf ("%s", indentation_string);
}
static void
+1576
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,6 +1,6 @@
/* redir.c -- Functions to perform input and output redirection. */
/* Copyright (C) 1997-2009 Free Software Foundation, Inc.
/* Copyright (C) 1997-2012 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
+1322
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -4,7 +4,7 @@
/* ``Have a little faith, there's magic in the night. You ain't a
beauty, but, hey, you're alright.'' */
/* Copyright (C) 1987-2010 Free Software Foundation, Inc.
/* Copyright (C) 1987-2012 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
+9417
View File
File diff suppressed because it is too large Load Diff
+3
View File
@@ -187,3 +187,6 @@ declare -A foo='(["bar\\]bie"]="doll" )'
bar${foo}bie
doll
declare -A foo='(["bar\${foo}bie"]="doll" )'
bar
after printf
after use: 0
+2
View File
@@ -184,3 +184,5 @@ ${THIS_SH} ./assoc4.sub
${THIS_SH} ./assoc5.sub
${THIS_SH} ./assoc6.sub
${THIS_SH} ./assoc7.sub
+16
View File
@@ -0,0 +1,16 @@
# problem with bash versions through bash-4.2
foo()
{
declare -A hash
declare hash[baz]=bar #bash crashes here
echo ${hash[@]}
}
foo
declare -a ary
printf -v ary[0] "%b" ""
echo "after printf"
x="${ary[*]}" # segfaults here
echo "after use: $?"
+3
View File
@@ -4,3 +4,6 @@ and here
retest
and match
no more clauses
1.0
./case.tests: line 29: xx: readonly variable
1.1
+12
View File
@@ -16,3 +16,15 @@ esac
case a in
a) echo no more clauses;&
esac
x=0 y=1
case 1 in
$((y=0)) ) ;;
$((x=1)) ) ;&
$((x=2)) ) echo $x.$y ;;
esac
unset x
readonly xx=1
case 1 in $((xx++)) ) echo hi1 ;; *) echo hi2; esac
echo ${xx}.$?
+5 -1
View File
@@ -98,9 +98,13 @@ trap: usage: trap [-lp] [[arg] signal_spec ...]
./errors.tests: line 250: kill: `': not a pid or valid job spec
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
./errors.tests: line 255: set: trackall: invalid option name
./errors.tests: line 259: xx: readonly variable
1
./errors1.sub: line 1: .: -i: invalid option
.: usage: . filename [arguments]
./errors1.sub: line 9: shift: -4: shift count out of range
./errors1.sub: line 14: break: -1: loop count out of range
after f
./errors.tests: line 264: `!!': not a valid identifier
./errors2.sub: line 3: ${$NO_SUCH_VAR}: bad substitution
1
./errors.tests: line 270: `!!': not a valid identifier
+6
View File
@@ -254,7 +254,13 @@ kill -INT
# bad shell option names
set -o trackall # bash is not ksh
# problem with versions through bash-4.2
readonly xx=5
echo $((xx=5))
echo $?
${THIS_SH} ./errors1.sub
${THIS_SH} ./errors2.sub
# this must be last!
# in posix mode, a function name must be a valid identifier
+3
View File
@@ -0,0 +1,3 @@
set -e
trap 'echo $?' EXIT
echo ${$NO_SUCH_VAR} # Bad substitution expected here
+5 -1
View File
@@ -87,6 +87,7 @@ extern int line_number, line_number_base;
extern int subshell_environment, indirection_level, subshell_level;
extern int build_version, patch_level;
extern int expanding_redir;
extern int last_command_exit_value;
extern char *dist_version, *release_status;
extern char *shell_name;
extern char *primary_prompt, *secondary_prompt;
@@ -360,7 +361,10 @@ initialize_shell_variables (env, privmode)
array_needs_making = 1;
}
else
report_error (_("error importing function definition for `%s'"), name);
{
last_command_exit_value = 1;
report_error (_("error importing function definition for `%s'"), name);
}
/* ( */
if (name[char_index - 1] == ')' && name[char_index - 2] == '\0')