aboutsummaryrefslogtreecommitdiffstats
path: root/builtins
diff options
context:
space:
mode:
authorJari Aalto <jari.aalto@cante.net>2008-11-18 13:15:12 +0000
committerJari Aalto <jari.aalto@cante.net>2009-09-12 16:46:59 +0000
commitf1be666c7d78939ad775078d290bec2758fa29a2 (patch)
tree4f4b8ed6eb250653e0bb44685eb5ffa9d3805e91 /builtins
parent0628567a28f3510f506ae46cb9b24b73a6d2dc5d (diff)
downloadandroid_external_bash-f1be666c7d78939ad775078d290bec2758fa29a2.tar.gz
android_external_bash-f1be666c7d78939ad775078d290bec2758fa29a2.tar.bz2
android_external_bash-f1be666c7d78939ad775078d290bec2758fa29a2.zip
Imported from ../bash-3.2.48.tar.gz.
Diffstat (limited to 'builtins')
-rw-r--r--builtins/common.c12
-rw-r--r--builtins/evalstring.c17
-rw-r--r--builtins/printf.def16
-rw-r--r--builtins/read.def31
-rw-r--r--builtins/set.def12
-rw-r--r--builtins/shopt.def16
6 files changed, 89 insertions, 15 deletions
diff --git a/builtins/common.c b/builtins/common.c
index 7b9613e..89c6a87 100644
--- a/builtins/common.c
+++ b/builtins/common.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2007 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -131,6 +131,7 @@ no_args (list)
if (list)
{
builtin_error (_("too many arguments"));
+ top_level_cleanup ();
jump_to_top_level (DISCARD);
}
}
@@ -395,7 +396,10 @@ get_numeric_arg (list, fatal)
if (fatal)
throw_to_top_level ();
else
- jump_to_top_level (DISCARD);
+ {
+ top_level_cleanup ();
+ jump_to_top_level (DISCARD);
+ }
}
no_args (list->next);
}
@@ -475,7 +479,11 @@ get_working_directory (for_whom)
if (the_current_working_directory == 0)
{
+#if defined (GETCWD_BROKEN)
+ the_current_working_directory = getcwd (0, PATH_MAX);
+#else
the_current_working_directory = getcwd (0, 0);
+#endif
if (the_current_working_directory == 0)
{
fprintf (stderr, _("%s: error retrieving current directory: %s: %s\n"),
diff --git a/builtins/evalstring.c b/builtins/evalstring.c
index 36f0ad3..511ce86 100644
--- a/builtins/evalstring.c
+++ b/builtins/evalstring.c
@@ -67,6 +67,14 @@ int parse_and_execute_level = 0;
static int cat_file __P((REDIRECT *));
+#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 ()
@@ -115,7 +123,10 @@ parse_and_execute (string, from_file, flags)
lreset = flags & SEVAL_RESETLINE;
#if defined (HISTORY)
- unwind_protect_int (remember_on_history); /* can be used in scripts */
+ 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)
{
@@ -237,6 +248,7 @@ parse_and_execute (string, from_file, flags)
* 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
@@ -247,7 +259,8 @@ parse_and_execute (string, from_file, flags)
running_trap == 0 &&
*bash_input.location.string == '\0' &&
command->type == cm_simple &&
- !command->redirects && !command->value.Simple->redirects &&
+ 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))
{
diff --git a/builtins/printf.def b/builtins/printf.def
index 0e1d4aa..5a63167 100644
--- a/builtins/printf.def
+++ b/builtins/printf.def
@@ -1,7 +1,7 @@
This file is printf.def, from which is created printf.c.
It implements the builtin "printf" in Bash.
-Copyright (C) 1997-2005 Free Software Foundation, Inc.
+Copyright (C) 1997-2007 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -49,6 +49,12 @@ $END
# define INT_MIN (-2147483647-1)
#endif
+#if defined (PREFER_STDARG)
+# include <stdarg.h>
+#else
+# include <varargs.h>
+#endif
+
#include <stdio.h>
#include <chartypes.h>
@@ -64,6 +70,10 @@ $END
#include "bashgetopt.h"
#include "common.h"
+#if defined (PRI_MACROS_BROKEN)
+# undef PRIdMAX
+#endif
+
#if !defined (PRIdMAX)
# if HAVE_LONG_LONG
# define PRIdMAX "lld"
@@ -151,6 +161,10 @@ extern int errno;
#define SKIP1 "#'-+ 0"
#define LENMODS "hjlLtz"
+#ifndef HAVE_ASPRINTF
+extern int asprintf __P((char **, const char *, ...)) __attribute__((__format__ (printf, 2, 3)));
+#endif
+
static void printf_erange __P((char *));
static int printstr __P((char *, char *, int, int, int));
static int tescape __P((char *, char *, int *));
diff --git a/builtins/read.def b/builtins/read.def
index 21521db..afa549e 100644
--- a/builtins/read.def
+++ b/builtins/read.def
@@ -127,14 +127,14 @@ read_builtin (list)
WORD_LIST *list;
{
register char *varname;
- int size, i, nr, pass_next, saw_escape, eof, opt, retval, code;
- int input_is_tty, input_is_pipe, unbuffered_read;
+ int size, i, nr, pass_next, saw_escape, eof, opt, retval, code, print_ps2;
+ int input_is_tty, input_is_pipe, unbuffered_read, skip_ctlesc, skip_ctlnul;
int raw, edit, nchars, silent, have_timeout, fd;
unsigned int tmout;
intmax_t intval;
char c;
char *input_string, *orig_input_string, *ifs_chars, *prompt, *arrayname;
- char *e, *t, *t1;
+ char *e, *t, *t1, *ps2, *tofree;
struct stat tsb;
SHELL_VAR *var;
#if defined (ARRAY_VARS)
@@ -148,6 +148,7 @@ read_builtin (list)
USE_VAR(size);
USE_VAR(i);
USE_VAR(pass_next);
+ USE_VAR(print_ps2);
USE_VAR(saw_escape);
USE_VAR(input_is_pipe);
/* USE_VAR(raw); */
@@ -163,6 +164,7 @@ read_builtin (list)
USE_VAR(rlind);
#endif
USE_VAR(list);
+ USE_VAR(ps2);
i = 0; /* Index into the string that we are reading. */
raw = edit = 0; /* Not reading raw input by default. */
@@ -386,7 +388,8 @@ read_builtin (list)
setmode (0, O_TEXT);
#endif
- for (eof = retval = 0;;)
+ ps2 = 0;
+ for (print_ps2 = eof = retval = 0;;)
{
#if defined (READLINE)
if (edit)
@@ -412,6 +415,15 @@ read_builtin (list)
{
#endif
+ if (print_ps2)
+ {
+ if (ps2 == 0)
+ ps2 = get_string_value ("PS2");
+ fprintf (stderr, "%s", ps2 ? ps2 : "");
+ fflush (stderr);
+ print_ps2 = 0;
+ }
+
if (unbuffered_read)
retval = zread (fd, &c, 1);
else
@@ -440,7 +452,11 @@ read_builtin (list)
{
pass_next = 0;
if (c == '\n')
- i--; /* back up over the CTLESC */
+ {
+ i--; /* back up over the CTLESC */
+ if (interactive && input_is_tty && raw == 0)
+ print_ps2 = 1;
+ }
else
goto add_char;
continue;
@@ -658,12 +674,13 @@ add_char:
#else
/* Check whether or not the number of fields is exactly the same as the
number of variables. */
+ tofree = NULL;
if (*input_string)
{
t1 = input_string;
t = get_word_from_string (&input_string, ifs_chars, &e);
if (*input_string == 0)
- input_string = t;
+ tofree = input_string = t;
else
input_string = strip_trailing_ifs_whitespace (t1, ifs_chars, saw_escape);
}
@@ -678,6 +695,8 @@ add_char:
else
var = bind_read_variable (list->word->word, input_string);
stupidly_hack_special_variables (list->word->word);
+ FREE (tofree);
+
if (var)
VUNSETATTR (var, att_invisible);
xfree (orig_input_string);
diff --git a/builtins/set.def b/builtins/set.def
index d108669..9d86319 100644
--- a/builtins/set.def
+++ b/builtins/set.def
@@ -189,7 +189,7 @@ struct {
{ "histexpand", 'H', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#endif /* BANG_HISTORY */
#if defined (HISTORY)
- { "history", '\0', &remember_on_history, bash_set_history, (setopt_get_func_t *)NULL },
+ { "history", '\0', &enable_history_list, bash_set_history, (setopt_get_func_t *)NULL },
#endif
{ "ignoreeof", '\0', &ignoreeof, set_ignoreeof, (setopt_get_func_t *)NULL },
{ "interactive-comments", '\0', &interactive_comments, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
@@ -381,13 +381,17 @@ bash_set_history (on_or_off, option_name)
{
if (on_or_off == FLAG_ON)
{
+ enable_history_list = 1;
bash_history_enable ();
if (history_lines_this_session == 0)
load_history ();
}
else
- bash_history_disable ();
- return (1 - remember_on_history);
+ {
+ enable_history_list = 0;
+ bash_history_disable ();
+ }
+ return (1 - enable_history_list);
}
#endif
@@ -565,7 +569,7 @@ void
reset_shell_options ()
{
#if defined (HISTORY)
- remember_on_history = 1;
+ remember_on_history = enable_history_list = 1;
#endif
ignoreeof = 0;
}
diff --git a/builtins/shopt.def b/builtins/shopt.def
index ae100ac..db46c31 100644
--- a/builtins/shopt.def
+++ b/builtins/shopt.def
@@ -101,11 +101,14 @@ static void shopt_error __P((char *));
static int set_shellopts_after_change __P((int));
+static int set_compatibility_level __P((int));
+
#if defined (RESTRICTED_SHELL)
static int set_restricted_shell __P((int));
#endif
static int shopt_login_shell;
+static int shopt_compat31;
typedef int shopt_set_func_t __P((int));
@@ -121,6 +124,7 @@ static struct {
#if defined (HISTORY)
{ "cmdhist", &command_oriented_history, (shopt_set_func_t *)NULL },
#endif
+ { "compat31", &shopt_compat31, set_compatibility_level },
{ "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 },
@@ -459,6 +463,18 @@ set_shellopts_after_change (mode)
return (0);
}
+static int
+set_compatibility_level (mode)
+ int mode;
+{
+ /* Need to change logic here as we add more compatibility levels */
+ if (shopt_compat31)
+ shell_compatibility_level = 31;
+ else
+ shell_compatibility_level = 32;
+ return 0;
+}
+
#if defined (RESTRICTED_SHELL)
/* Don't allow the value of restricted_shell to be modified. */