summaryrefslogtreecommitdiff
path: root/builtins
diff options
context:
space:
mode:
authorChet Ramey <chet.ramey@case.edu>2011-12-07 09:23:10 -0500
committerChet Ramey <chet.ramey@case.edu>2011-12-07 09:23:10 -0500
commit4ac1ff9885b94a76a1cb4283d66cb422fc1f8cc5 (patch)
tree92bbb2ec2e050ab7d6e7d9078728a7bd458c4608 /builtins
parent245a493cfba3bd1e3d431c7241fc8e6c62b595e6 (diff)
downloadbash-4ac1ff9885b94a76a1cb4283d66cb422fc1f8cc5.tar.gz
commit bash-20080501 snapshot
Diffstat (limited to 'builtins')
-rw-r--r--builtins/fc.def12
-rw-r--r--builtins/fc.def~17
-rw-r--r--builtins/read.def43
-rw-r--r--builtins/read.def~46
-rw-r--r--builtins/shopt.def5
-rw-r--r--builtins/shopt.def~6
6 files changed, 88 insertions, 41 deletions
diff --git a/builtins/fc.def b/builtins/fc.def
index 26c9dd64..32cd57ac 100644
--- a/builtins/fc.def
+++ b/builtins/fc.def
@@ -325,7 +325,17 @@ fc_builtin (list)
/* "When not listing, the fc command that caused the editing shall not be
entered into the history list." */
if (listing == 0 && hist_last_line_added)
- delete_last_history ();
+ {
+ delete_last_history ();
+ /* If we're editing a single command -- the last command in the
+ history -- and we just removed the dummy command added by
+ edit_and_execute_command (), we need to check whether or not we
+ just removed the last command in the history and need to back
+ the pointer up. remember_on_history is off because we're running
+ in parse_and_execute(). */
+ if (histbeg == histend && histend == last_hist && hlist[last_hist] == 0)
+ last_hist = histbeg = --histend;
+ }
/* We print error messages for line specifications out of range. */
if ((histbeg < 0) || (histend < 0))
diff --git a/builtins/fc.def~ b/builtins/fc.def~
index 08abb317..078e2410 100644
--- a/builtins/fc.def~
+++ b/builtins/fc.def~
@@ -45,6 +45,9 @@ re-executed after the substitution OLD=NEW is performed.
A useful alias to use with this is r='fc -s', so that typing `r cc'
runs the last command beginning with `cc' and typing `r' re-executes
the last command.
+
+Exit Status:
+Returns success or status of executed command; non-zero if an error occurs.
$END
#include <config.h>
@@ -322,7 +325,19 @@ fc_builtin (list)
/* "When not listing, the fc command that caused the editing shall not be
entered into the history list." */
if (listing == 0 && hist_last_line_added)
- delete_last_history ();
+ {
+ delete_last_history ();
+ /* If we're editing a single command -- the last command in the
+ history -- and we just removed the dummy command added by
+ edit_and_execute_command (), we need to check whether or not we
+ just removed the last command in the history and need to back
+ the pointer up. remember_on_history is off because we're running
+ in parse_and_execute(). */
+ if (histbeg == histend && histend == last_hist && hlist[last_hist] == 0)
+ last_hist = histbeg = --histend;
+ }
+
+itrace ("fc: last_hist = %d histbeg = %d histend = %d", last_hist, histbeg, histend);
/* We print error messages for line specifications out of range. */
if ((histbeg < 0) || (histend < 0))
diff --git a/builtins/read.def b/builtins/read.def
index 0f0ecf91..d7a43202 100644
--- a/builtins/read.def
+++ b/builtins/read.def
@@ -50,7 +50,8 @@ Options:
-s do not echo input coming from a terminal
-t timeout time out and return failure if a complete line of input is
not read withint TIMEOUT seconds. The value of the TMOUT
- variable is the default timeout.
+ variable is the default timeout. TIMEOUT may be a
+ fractional number.
-u fd read from file descriptor FD instead of the standard input
Exit Status:
@@ -135,7 +136,7 @@ static void
reset_alarm ()
{
set_signal_handler (SIGALRM, old_alrm);
- alarm (0);
+ falarm (0, 0);
}
/* Read the value of the shell variables whose names follow.
@@ -152,7 +153,8 @@ read_builtin (list)
int size, i, nr, pass_next, saw_escape, eof, opt, retval, code, print_ps2;
int input_is_tty, input_is_pipe, unbuffered_read, skip_ctlesc, skip_ctlnul;
int raw, edit, nchars, silent, have_timeout, fd;
- unsigned int tmout;
+ unsigned int tmsec, tmusec;
+ long ival, uval;
intmax_t intval;
char c;
char *input_string, *orig_input_string, *ifs_chars, *prompt, *arrayname;
@@ -177,7 +179,8 @@ read_builtin (list)
USE_VAR(input_is_pipe);
/* USE_VAR(raw); */
USE_VAR(edit);
- USE_VAR(tmout);
+ USE_VAR(tmsec);
+ USE_VAR(tmusec);
USE_VAR(nchars);
USE_VAR(silent);
USE_VAR(ifs_chars);
@@ -202,7 +205,7 @@ read_builtin (list)
rlind = 0;
#endif
- tmout = 0; /* no timeout */
+ tmsec = tmusec = 0; /* no timeout */
nr = nchars = input_is_tty = input_is_pipe = unbuffered_read = have_timeout = 0;
delim = '\n'; /* read until newline */
@@ -236,8 +239,8 @@ read_builtin (list)
break;
#endif
case 't':
- code = legal_number (list_optarg, &intval);
- if (code == 0 || intval < 0 || intval != (unsigned int)intval)
+ code = uconvert (list_optarg, &ival, &uval);
+ if (code == 0 || ival < 0 || uval < 0)
{
builtin_error (_("%s: invalid timeout specification"), list_optarg);
return (EXECUTION_FAILURE);
@@ -245,7 +248,8 @@ read_builtin (list)
else
{
have_timeout = 1;
- tmout = intval;
+ tmsec = ival;
+ tmusec = uval;
}
break;
case 'n':
@@ -286,7 +290,7 @@ read_builtin (list)
/* `read -t 0 var' returns failure immediately. XXX - should it test
whether input is available with select/FIONREAD, and fail if those
are unavailable? */
- if (have_timeout && tmout == 0)
+ if (have_timeout && tmsec == 0 && tmusec == 0)
return (EXECUTION_FAILURE);
/* IF IFS is unset, we use the default of " \t\n". */
@@ -302,11 +306,14 @@ read_builtin (list)
/* $TMOUT, if set, is the default timeout for read. */
if (have_timeout == 0 && (e = get_string_value ("TMOUT")))
{
- code = legal_number (e, &intval);
- if (code == 0 || intval < 0 || intval != (unsigned int)intval)
- tmout = 0;
+ code = uconvert (e, &ival, &uval);
+ if (code == 0 || ival < 0 || uval < 0)
+ tmsec = tmusec = 0;
else
- tmout = intval;
+ {
+ tmsec = ival;
+ tmusec = uval;
+ }
}
begin_unwind_frame ("read_builtin");
@@ -349,15 +356,15 @@ read_builtin (list)
pass_next = 0; /* Non-zero signifies last char was backslash. */
saw_escape = 0; /* Non-zero signifies that we saw an escape char */
- if (tmout > 0)
+ if (tmsec > 0 || tmusec > 0)
{
/* Turn off the timeout if stdin is a regular file (e.g. from
input redirection). */
if ((fstat (fd, &tsb) < 0) || S_ISREG (tsb.st_mode))
- tmout = 0;
+ tmsec = tmusec = 0;
}
- if (tmout > 0)
+ if (tmsec > 0 || tmusec > 0)
{
code = setjmp (alrmbuf);
if (code)
@@ -377,7 +384,7 @@ read_builtin (list)
if (edit)
add_unwind_protect (reset_attempted_completion_function, (char *)NULL);
#endif
- alarm (tmout);
+ falarm (tmsec, tmusec);
}
/* If we've been asked to read only NCHARS chars, or we're using some
@@ -563,7 +570,7 @@ add_char:
}
#endif
- if (tmout > 0)
+ if (tmsec > 0 || tmusec > 0)
reset_alarm ();
if (nchars > 0 || delim != '\n')
diff --git a/builtins/read.def~ b/builtins/read.def~
index 20bec10e..bf1e0300 100644
--- a/builtins/read.def~
+++ b/builtins/read.def~
@@ -50,9 +50,11 @@ Options:
-s do not echo input coming from a terminal
-t timeout time out and return failure if a complete line of input is
not read withint TIMEOUT seconds. The value of the TMOUT
- variable is the default timeout.
+ variable is the default timeout. TIMEOUT may be a
+ fractional number.
-u fd read from file descriptor FD instead of the standard input
+Exit Status:
The return code is zero, unless end-of-file is encountered, read times out,
or an invalid file descriptor is supplied as the argument to -u.
$END
@@ -134,7 +136,7 @@ static void
reset_alarm ()
{
set_signal_handler (SIGALRM, old_alrm);
- alarm (0);
+ falarm (0, 0);
}
/* Read the value of the shell variables whose names follow.
@@ -151,7 +153,8 @@ read_builtin (list)
int size, i, nr, pass_next, saw_escape, eof, opt, retval, code, print_ps2;
int input_is_tty, input_is_pipe, unbuffered_read, skip_ctlesc, skip_ctlnul;
int raw, edit, nchars, silent, have_timeout, fd;
- unsigned int tmout;
+ unsigned int tmsec, tmusec;
+ long ival, uval;
intmax_t intval;
char c;
char *input_string, *orig_input_string, *ifs_chars, *prompt, *arrayname;
@@ -176,7 +179,8 @@ read_builtin (list)
USE_VAR(input_is_pipe);
/* USE_VAR(raw); */
USE_VAR(edit);
- USE_VAR(tmout);
+ USE_VAR(tmsec);
+ USE_VAR(tmusec);
USE_VAR(nchars);
USE_VAR(silent);
USE_VAR(ifs_chars);
@@ -201,7 +205,7 @@ read_builtin (list)
rlind = 0;
#endif
- tmout = 0; /* no timeout */
+ tmsec = tmusec = 0; /* no timeout */
nr = nchars = input_is_tty = input_is_pipe = unbuffered_read = have_timeout = 0;
delim = '\n'; /* read until newline */
@@ -235,8 +239,8 @@ read_builtin (list)
break;
#endif
case 't':
- code = legal_number (list_optarg, &intval);
- if (code == 0 || intval < 0 || intval != (unsigned int)intval)
+ code = uconvert (list_optarg, &ival, &uval);
+ if (code == 0 || ival < 0 || uval < 0)
{
builtin_error (_("%s: invalid timeout specification"), list_optarg);
return (EXECUTION_FAILURE);
@@ -244,7 +248,8 @@ read_builtin (list)
else
{
have_timeout = 1;
- tmout = intval;
+ tmsec = ival;
+ tmusec = uval;
}
break;
case 'n':
@@ -285,7 +290,7 @@ read_builtin (list)
/* `read -t 0 var' returns failure immediately. XXX - should it test
whether input is available with select/FIONREAD, and fail if those
are unavailable? */
- if (have_timeout && tmout == 0)
+ if (have_timeout && tmsec == 0 && tmusec == 0)
return (EXECUTION_FAILURE);
/* IF IFS is unset, we use the default of " \t\n". */
@@ -301,11 +306,14 @@ read_builtin (list)
/* $TMOUT, if set, is the default timeout for read. */
if (have_timeout == 0 && (e = get_string_value ("TMOUT")))
{
- code = legal_number (e, &intval);
- if (code == 0 || intval < 0 || intval != (unsigned int)intval)
- tmout = 0;
+ code = uconvert (e, &ival, &uval);
+ if (code == 0 || ival < 0 || uval < 0)
+ tmsec = tmusec = 0;
else
- tmout = intval;
+ {
+ tmsec = ival;
+ tmusec = uval;
+ }
}
begin_unwind_frame ("read_builtin");
@@ -348,15 +356,15 @@ read_builtin (list)
pass_next = 0; /* Non-zero signifies last char was backslash. */
saw_escape = 0; /* Non-zero signifies that we saw an escape char */
- if (tmout > 0)
+ if (tmsec > 0 || tmusec > 0)
{
/* Turn off the timeout if stdin is a regular file (e.g. from
input redirection). */
if ((fstat (fd, &tsb) < 0) || S_ISREG (tsb.st_mode))
- tmout = 0;
+ tmsec = tmusec = 0;
}
- if (tmout > 0)
+ if (tmsec > 0 || tmusec > 0)
{
code = setjmp (alrmbuf);
if (code)
@@ -376,7 +384,7 @@ read_builtin (list)
if (edit)
add_unwind_protect (reset_attempted_completion_function, (char *)NULL);
#endif
- alarm (tmout);
+ falarm (tmsec, tmusec);
}
/* If we've been asked to read only NCHARS chars, or we're using some
@@ -562,10 +570,10 @@ add_char:
}
#endif
- if (tmout > 0)
+ if (tmsec > 0 || tmusec > 0)
reset_alarm ();
- if (nchars > 0 || delim != '\n')
+< if (nchars > 0 || delim != '\n')
{
#if defined (READLINE)
if (edit)
diff --git a/builtins/shopt.def b/builtins/shopt.def
index b2522974..52324296 100644
--- a/builtins/shopt.def
+++ b/builtins/shopt.def
@@ -71,7 +71,7 @@ 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 cdspelling, dircomplete_spelling, expand_aliases;
extern int extended_quote;
extern int check_window_size;
extern int glob_ignore_case, match_ignore_case;
@@ -80,6 +80,7 @@ extern int xpg_echo;
extern int gnu_error_format;
extern int check_jobs_at_exit;
extern int autocd;
+extern int glob_star;
#if defined (EXTENDED_GLOB)
extern int extended_glob;
@@ -142,6 +143,7 @@ static struct {
{ "cmdhist", &command_oriented_history, (shopt_set_func_t *)NULL },
#endif
{ "compat31", &shopt_compat31, set_compatibility_level },
+ { "dirspell", &dircomplete_spelling, (shopt_set_func_t *)NULL },
{ "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 },
@@ -156,6 +158,7 @@ static struct {
#if defined (READLINE)
{ "force_fignore", &force_fignore, (shopt_set_func_t *)NULL },
#endif
+ { "globstar", &glob_star, (shopt_set_func_t *)NULL },
{ "gnu_errfmt", &gnu_error_format, (shopt_set_func_t *)NULL },
#if defined (HISTORY)
{ "histappend", &force_append_history, (shopt_set_func_t *)NULL },
diff --git a/builtins/shopt.def~ b/builtins/shopt.def~
index 9cc63b6d..8061a3f2 100644
--- a/builtins/shopt.def~
+++ b/builtins/shopt.def~
@@ -71,7 +71,7 @@ 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 cdspelling, dircomplete_spelling, expand_aliases;
extern int extended_quote;
extern int check_window_size;
extern int glob_ignore_case, match_ignore_case;
@@ -80,6 +80,7 @@ extern int xpg_echo;
extern int gnu_error_format;
extern int check_jobs_at_exit;
extern int autocd;
+extern int glob_star;
#if defined (EXTENDED_GLOB)
extern int extended_glob;
@@ -134,7 +135,9 @@ static struct {
{ "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 },
@@ -154,6 +157,7 @@ static struct {
#if defined (READLINE)
{ "force_fignore", &force_fignore, (shopt_set_func_t *)NULL },
#endif
+ { "globstar", &glob_star, (shopt_set_func_t *)NULL },
{ "gnu_errfmt", &gnu_error_format, (shopt_set_func_t *)NULL },
#if defined (HISTORY)
{ "histappend", &force_append_history, (shopt_set_func_t *)NULL },