summaryrefslogtreecommitdiff
path: root/builtins
diff options
context:
space:
mode:
Diffstat (limited to 'builtins')
-rw-r--r--builtins/Makefile.in44
-rw-r--r--builtins/alias.def22
-rw-r--r--builtins/caller.def146
-rw-r--r--builtins/cd.def6
-rw-r--r--builtins/common.c21
-rw-r--r--builtins/common.h6
-rw-r--r--builtins/complete.def18
-rw-r--r--builtins/declare.def27
-rw-r--r--builtins/evalfile.c68
-rw-r--r--builtins/evalstring.c25
-rw-r--r--builtins/exec.def3
-rw-r--r--builtins/exit.def18
-rw-r--r--builtins/fc.def2
-rw-r--r--builtins/getopts.def2
-rw-r--r--builtins/history.def68
-rw-r--r--builtins/jobs.def22
-rw-r--r--builtins/kill.def42
-rw-r--r--builtins/let.def2
-rw-r--r--builtins/mkbuiltins.c6
-rw-r--r--builtins/printf.def2
-rw-r--r--builtins/read.def1
-rw-r--r--builtins/set.def10
-rw-r--r--builtins/setattr.def7
-rw-r--r--builtins/shift.def2
-rw-r--r--builtins/shopt.def22
-rw-r--r--builtins/source.def34
-rw-r--r--builtins/suspend.def3
-rw-r--r--builtins/trap.def14
-rw-r--r--builtins/type.def3
-rw-r--r--builtins/umask.def2
30 files changed, 530 insertions, 118 deletions
diff --git a/builtins/Makefile.in b/builtins/Makefile.in
index 53ae75ac..ce650e7b 100644
--- a/builtins/Makefile.in
+++ b/builtins/Makefile.in
@@ -106,7 +106,8 @@ RL_LIBSRC = $(topdir)/lib/readline
$(CC) -c $(CCFLAGS) $<
DEFSRC = $(srcdir)/alias.def $(srcdir)/bind.def $(srcdir)/break.def \
- $(srcdir)/builtin.def $(srcdir)/cd.def $(srcdir)/colon.def \
+ $(srcdir)/builtin.def $(srcdir)/caller.def \
+ $(srcdir)/cd.def $(srcdir)/colon.def \
$(srcdir)/command.def $(srcdir)/declare.def $(srcdir)/echo.def \
$(srcdir)/enable.def $(srcdir)/eval.def $(srcdir)/getopts.def \
$(srcdir)/exec.def $(srcdir)/exit.def $(srcdir)/fc.def \
@@ -124,7 +125,7 @@ STATIC_SOURCE = common.c evalstring.c evalfile.c getopt.c bashgetopt.c \
getopt.h
OFILES = builtins.o \
- alias.o bind.o break.o builtin.o cd.o colon.o command.o \
+ alias.o bind.o break.o builtin.o caller.o cd.o colon.o command.o \
common.o declare.o echo.o enable.o eval.o evalfile.o \
evalstring.o exec.o \
exit.o fc.o fg_bg.o hash.o help.o history.o jobs.o kill.o let.o \
@@ -214,10 +215,14 @@ distclean maintainer-clean: clean
$(OFILES): $(MKBUILTINS) ../config.h
+../version.h: ../config.h ../Makefile Makefile
+ -( cd ${BUILD_DIR} && ${MAKE} ${MFLAGS} version.h )
+
alias.o: alias.def
bind.o: bind.def
break.o: break.def
builtin.o: builtin.def
+caller.o: caller.def
cd.o: cd.def
colon.o: colon.def
command.o: command.def
@@ -263,7 +268,7 @@ bashgetopt.o: $(topdir)/command.h $(topdir)/general.h $(topdir)/xmalloc.h $(topd
bashgetopt.o: $(topdir)/variables.h $(topdir)/conftypes.h $(topdir)/quit.h $(BASHINCDIR)/maxpath.h
bashgetopt.o: $(topdir)/unwind_prot.h $(topdir)/dispose_cmd.h
bashgetopt.o: $(topdir)/make_cmd.h $(topdir)/subst.h $(topdir)/sig.h
-bashgetopt.o: $(topdir)/pathnames.h $(topdir)/externs.h $(srcdir)/common.h
+bashgetopt.o: ../pathnames.h $(topdir)/externs.h $(srcdir)/common.h
bashgetopt.o: $(BASHINCDIR)/chartypes.h
common.o: $(topdir)/bashtypes.h $(BASHINCDIR)/posixstat.h $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h
common.o: $(topdir)/shell.h $(topdir)/syntax.h ../config.h $(topdir)/bashjmp.h $(BASHINCDIR)/posixjmp.h
@@ -274,7 +279,7 @@ common.o: $(topdir)/siglist.h $(topdir)/bashhist.h $(topdir)/quit.h
common.o: $(topdir)/unwind_prot.h $(BASHINCDIR)/maxpath.h $(topdir)/jobs.h
common.o: $(topdir)/builtins.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
common.o: $(topdir)/subst.h $(topdir)/execute_cmd.h $(topdir)/error.h
-common.o: $(topdir)/externs.h $(topdir)/pathnames.h ./builtext.h
+common.o: $(topdir)/externs.h ../pathnames.h ./builtext.h
common.o: $(BASHINCDIR)/chartypes.h
evalfile.o: $(topdir)/bashtypes.h $(BASHINCDIR)/posixstat.h ${BASHINCDIR}/filecntl.h
evalfile.o: $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h
@@ -283,7 +288,7 @@ evalfile.o: $(topdir)/command.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir
evalfile.o: $(topdir)/variables.h $(topdir)/conftypes.h $(topdir)/quit.h $(BASHINCDIR)/maxpath.h
evalfile.o: $(topdir)/unwind_prot.h $(topdir)/dispose_cmd.h
evalfile.o: $(topdir)/make_cmd.h $(topdir)/subst.h $(topdir)/sig.h
-evalfile.o: $(topdir)/pathnames.h $(topdir)/externs.h
+evalfile.o: ../pathnames.h $(topdir)/externs.h
evalfile.o: $(topdir)/jobs.h $(topdir)/builtins.h $(topdir)/flags.h
evalfile.o: $(topdir)/input.h $(topdir)/execute_cmd.h
evalfile.o: $(topdir)/bashhist.h $(srcdir)/common.h
@@ -303,8 +308,8 @@ getopt.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/bashjmp.h $(topdir)/com
getopt.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/error.h $(topdir)/variables.h $(topdir)/conftypes.h
getopt.o: $(topdir)/quit.h $(BASHINCDIR)/maxpath.h $(topdir)/unwind_prot.h
getopt.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
-getopt.o: $(topdir)/sig.h $(topdir)/pathnames.h $(topdir)/externs.h
-getopt.o: $(srcdir)/getopt.h
+getopt.o: $(topdir)/sig.h ../pathnames.h $(topdir)/externs.h
+getopt.o: $(srcdir)/getopt.h
mkbuiltins.o: ../config.h $(topdir)/bashtypes.h $(BASHINCDIR)/posixstat.h
mkbuiltins.o: ${BASHINCDIR}/filecntl.h
mkbuiltins.o: $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h
@@ -331,6 +336,12 @@ builtin.o: $(topdir)/quit.h $(srcdir)/common.h $(BASHINCDIR)/maxpath.h
builtin.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
builtin.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
builtin.o: $(srcdir)/bashgetopt.h
+caller.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
+caller.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/quit.h $(topdir)/dispose_cmd.h
+caller.o: $(topdir)/make_cmd.h $(topdir)/subst.h $(topdir)/externs.h
+caller.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
+caller.o: $(srcdir)/common.h $(BASHINCDIR)/maxpath.h ./builtext.h
+caller.o: ${BASHINCDIR}/chartypes.h $(topdir)/bashtypes.h
cd.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
cd.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/quit.h $(topdir)/dispose_cmd.h
cd.o: $(topdir)/make_cmd.h $(topdir)/subst.h $(topdir)/externs.h
@@ -347,6 +358,7 @@ declare.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
declare.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
declare.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
declare.o: $(topdir)/arrayfunc.h $(srcdir)/bashgetopt.h
+declare.o: ./builtext.h
echo.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
echo.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/subst.h $(topdir)/externs.h
echo.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
@@ -362,7 +374,7 @@ enable.o: $(topdir)/pcomplete.h
eval.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
eval.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
eval.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
-eval.o: $(topdir)/subst.h $(topdir)/externs.h
+eval.o: $(topdir)/subst.h $(topdir)/externs.h
eval.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
eval.o: $(BASHINCDIR)/maxpath.h
exec.o: $(topdir)/bashtypes.h
@@ -377,7 +389,7 @@ exit.o: $(topdir)/bashtypes.h
exit.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
exit.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
exit.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
-exit.o: $(topdir)/subst.h $(topdir)/externs.h
+exit.o: $(topdir)/subst.h $(topdir)/externs.h
exit.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
exit.o: $(BASHINCDIR)/maxpath.h ./builtext.h
fc.o: $(topdir)/bashtypes.h $(BASHINCDIR)/posixstat.h
@@ -416,7 +428,7 @@ history.o: $(topdir)/bashtypes.h
history.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
history.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
history.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
-history.o: $(topdir)/subst.h $(topdir)/externs.h
+history.o: $(topdir)/subst.h $(topdir)/externs.h
history.o: ${BASHINCDIR}/filecntl.h $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h
history.o: $(topdir)/variables.h $(topdir)/conftypes.h $(topdir)/bashhist.h $(BASHINCDIR)/maxpath.h
inlib.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
@@ -426,7 +438,7 @@ inlib.o: $(BASHINCDIR)/maxpath.h $(topdir)/subst.h $(topdir)/externs.h
inlib.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
jobs.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
jobs.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/quit.h $(srcdir)/bashgetopt.h
-jobs.o: $(BASHINCDIR)/maxpath.h $(topdir)/externs.h
+jobs.o: $(BASHINCDIR)/maxpath.h $(topdir)/externs.h
jobs.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
jobs.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
kill.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
@@ -443,13 +455,13 @@ printf.o: ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/bashjmp.h
printf.o: $(topdir)/command.h $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
printf.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
printf.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/sig.h
-printf.o: $(topdir)/pathnames.h $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h
+printf.o: ../pathnames.h $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h
printf.o: $(topdir)/variables.h $(topdir)/conftypes.h $(BASHINCDIR)/stdc.h $(srcdir)/bashgetopt.h
printf.o: $(topdir)/bashtypes.h ${srcdir}/common.h $(BASHINCDIR)/chartypes.h
pushd.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
pushd.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
pushd.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
-pushd.o: $(topdir)/subst.h $(topdir)/externs.h
+pushd.o: $(topdir)/subst.h $(topdir)/externs.h
pushd.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
pushd.o: $(BASHINCDIR)/maxpath.h $(srcdir)/common.h ./builtext.h
read.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
@@ -474,7 +486,7 @@ setattr.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
setattr.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(BASHINCDIR)/maxpath.h
setattr.o: $(topdir)/quit.h $(srcdir)/common.h $(srcdir)/bashgetopt.h
setattr.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
-setattr.o: $(topdir)/externs.h
+setattr.o: $(topdir)/externs.h
setattr.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
setattr.o: $(topdir)/arrayfunc.h
shift.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
@@ -487,7 +499,7 @@ source.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/fi
source.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
source.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
source.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-source.o: $(srcdir)/bashgetopt.h
+source.o: $(srcdir)/bashgetopt.h $(topdir)/flags.h $(topdir)/trap.h
suspend.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
suspend.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
suspend.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
@@ -541,7 +553,7 @@ shopt.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
shopt.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
shopt.o: $(srcdir)/common.h $(srcdir)/bashgetopt.h
-complete.o: ../config.h
+complete.o: ../config.h
complete.o: ${topdir}/shell.h $(topdir)/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h ${topdir}/sig.h
complete.o: ${topdir}/unwind_prot.h ${topdir}/variables.h
complete.o: ${topdir}/bashtypes.h ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
diff --git a/builtins/alias.def b/builtins/alias.def
index f51df948..5c7ed3d5 100644
--- a/builtins/alias.def
+++ b/builtins/alias.def
@@ -51,17 +51,23 @@ $END
# include "common.h"
# include "bashgetopt.h"
-static void print_alias __P((alias_t *));
+/* Flags for print_alias */
+#define AL_REUSABLE 0x01
+
+static void print_alias __P((alias_t *, int));
+
+extern int posixly_correct;
/* Hack the alias command in a Korn shell way. */
int
alias_builtin (list)
WORD_LIST *list;
{
- int any_failed, offset, pflag;
+ int any_failed, offset, pflag, dflags;
alias_t **alias_list, *t;
char *name, *value;
+ dflags = posixly_correct ? 0 : AL_REUSABLE;
pflag = 0;
reset_internal_getopt ();
while ((offset = internal_getopt (list, "p")) != -1)
@@ -70,6 +76,7 @@ alias_builtin (list)
{
case 'p':
pflag = 1;
+ dflags |= AL_REUSABLE;
break;
default:
builtin_usage ();
@@ -90,7 +97,7 @@ alias_builtin (list)
return (EXECUTION_SUCCESS);
for (offset = 0; alias_list[offset]; offset++)
- print_alias (alias_list[offset]);
+ print_alias (alias_list[offset], dflags);
free (alias_list); /* XXX - Do not free the strings. */
@@ -117,7 +124,7 @@ alias_builtin (list)
{
t = find_alias (name);
if (t)
- print_alias (t);
+ print_alias (t, dflags);
else
{
sh_notfound (name);
@@ -192,13 +199,16 @@ unalias_builtin (list)
/* Output ALIAS in such a way as to allow it to be read back in. */
static void
-print_alias (alias)
+print_alias (alias, flags)
alias_t *alias;
+ int flags;
{
char *value;
value = sh_single_quote (alias->value);
- printf ("alias %s=%s\n", alias->name, value);
+ if (flags & AL_REUSABLE)
+ printf ("alias ");
+ printf ("%s=%s\n", alias->name, value);
free (value);
fflush (stdout);
diff --git a/builtins/caller.def b/builtins/caller.def
new file mode 100644
index 00000000..868b2ee8
--- /dev/null
+++ b/builtins/caller.def
@@ -0,0 +1,146 @@
+This file is caller.def, from which is created caller.c. It implements the
+builtin "caller" in Bash.
+
+Copyright (C) 2002 Rocky Bernstein for 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, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+
+$PRODUCES caller.c
+
+$BUILTIN caller
+$FUNCTION caller_builtin
+$DEPENDS_ON DEBUGGER
+$SHORT_DOC caller [EXPR]
+
+Returns the context of the current subroutine call.
+
+Without EXPR, returns returns "$line $filename". With EXPR,
+returns "$line $subroutine $filename"; this extra information
+can be used used to provide a stack trace.
+
+The value of EXPR indicates how many call frames to go back before the
+current one; the top frame is frame 0.
+$END
+
+#include <config.h>
+#include <stdio.h>
+#include "chartypes.h"
+#include "bashtypes.h"
+
+#if defined (HAVE_UNISTD_H)
+# ifdef _MINIX
+# include <sys/types.h>
+# endif
+# include <unistd.h>
+#endif
+
+#include <errno.h>
+
+#include "../shell.h"
+#include "common.h"
+#include "builtext.h"
+
+#ifdef LOADABLE_BUILTIN
+# include "builtins.h"
+#endif
+
+#if !defined (errno)
+extern int errno;
+#endif /* !errno */
+
+int
+caller_builtin (list)
+ WORD_LIST *list;
+{
+#if !defined (ARRAY_VARS)
+ printf ("1 NULL\n");
+ return (EXECUTION_FAILURE);
+#else
+ SHELL_VAR *funcname_v, *bash_source_v, *bash_lineno_v;
+ ARRAY *funcname_a, *bash_source_a, *bash_lineno_a;
+ char *funcname_s, *source_s, *lineno_s;
+ ARRAY_ELEMENT *ae;
+ intmax_t num;
+
+ GET_ARRAY_FROM_VAR ("FUNCNAME", funcname_v, funcname_a);
+ GET_ARRAY_FROM_VAR ("BASH_SOURCE", bash_source_v, bash_source_a);
+ GET_ARRAY_FROM_VAR ("BASH_LINENO", bash_lineno_v, bash_lineno_a);
+
+ if (bash_lineno_a == 0 || array_empty (bash_lineno_a))
+ return (EXECUTION_FAILURE);
+
+ if (bash_source_a == 0 || array_empty (bash_source_a))
+ return (EXECUTION_FAILURE);
+
+ /* If there is no argument list, then give short form: line filename. */
+ if (list == 0)
+ {
+ lineno_s = array_reference (bash_lineno_a, 0);
+ source_s = array_reference (bash_source_a, 1);
+ printf("%s %s\n", lineno_s ? lineno_s : "NULL", source_s ? source_s : "NULL");
+ return (EXECUTION_SUCCESS);
+ }
+
+ if (funcname_a == 0 || array_empty (funcname_a))
+ return (EXECUTION_FAILURE);
+
+ if (legal_number (list->word->word, &num))
+ {
+ lineno_s = array_reference (bash_lineno_a, num);
+ source_s = array_reference (bash_source_a, num+1);
+ funcname_s = array_reference (funcname_a, num+1);
+
+ if (lineno_s == NULL|| source_s == NULL || funcname_s == NULL)
+ return (EXECUTION_FAILURE);
+
+ printf("%s %s %s\n", lineno_s, funcname_s, source_s);
+ }
+ else
+ {
+ sh_invalidnum (list->word->word);
+ builtin_usage ();
+ return (EXECUTION_FAILURE);
+ }
+
+ return (EXECUTION_SUCCESS);
+#endif
+}
+
+
+#ifdef LOADABLE_BUILTIN
+static char *caller_doc[] = {
+ "Returns the context of the current subroutine call.",
+ "",
+ "Without EXPR, returns returns \"$line $filename\". With EXPR,",
+ "returns \"$line $subroutine $filename\"; this extra information",
+ "can be used used to provide a stack trace.",
+ "",
+ "The value of EXPR indicates how many call frames to go back before the",
+ "current one; the top frame is frame 0.",
+ (char *)NULL
+};
+
+struct builtin caller_struct = {
+ "caller",
+ caller_builtin,
+ BUILTIN_ENABLED,
+ caller_doc,
+ "caller [EXPR]",
+ 0
+};
+
+#endif /* LOADABLE_BUILTIN */
diff --git a/builtins/cd.def b/builtins/cd.def
index 1c58c7c1..c13a78a5 100644
--- a/builtins/cd.def
+++ b/builtins/cd.def
@@ -199,7 +199,11 @@ cd_builtin (list)
builtin_error ("OLDPWD not set");
return (EXECUTION_FAILURE);
}
+#if 0
lflag = interactive ? LCD_PRINTPATH : 0;
+#else
+ lflag = LCD_PRINTPATH; /* According to SUSv3 */
+#endif
}
else if (absolute_pathname (list->word->word))
dirname = list->word->word;
@@ -343,8 +347,10 @@ pwd_builtin (list)
if (ferror (stdout))
{
builtin_error ("write error: %s", strerror (errno));
+ clearerr (stdout);
return (EXECUTION_FAILURE);
}
+
return (EXECUTION_SUCCESS);
}
else
diff --git a/builtins/common.c b/builtins/common.c
index b8186002..e780be5a 100644
--- a/builtins/common.c
+++ b/builtins/common.c
@@ -244,7 +244,7 @@ sh_nojobs (s)
char *s;
{
if (s)
- builtin_error ("%s: no job control");
+ builtin_error ("%s: no job control", s);
else
builtin_error ("no job control");
}
@@ -602,6 +602,9 @@ get_job_spec (list)
}
#endif /* JOB_CONTROL */
+/*
+ * NOTE: `kill' calls this function with forcecols == 0
+ */
int
display_signal_list (list, forcecols)
WORD_LIST *list;
@@ -609,8 +612,7 @@ display_signal_list (list, forcecols)
{
register int i, column;
char *name;
- int result;
- int signum;
+ int result, signum, dflags;
intmax_t lsignum;
result = EXECUTION_SUCCESS;
@@ -623,7 +625,13 @@ display_signal_list (list, forcecols)
continue;
if (posixly_correct && !forcecols)
- printf ("%s%s", name, (i == NSIG - 1) ? "" : " ");
+ {
+ /* This is for the kill builtin. POSIX.2 says the signal names
+ are displayed without the `SIG' prefix. */
+ if (STREQN (name, "SIG", 3))
+ name += 3;
+ printf ("%s%s", name, (i == NSIG - 1) ? "" : " ");
+ }
else
{
printf ("%2d) %s", i, name);
@@ -677,7 +685,10 @@ display_signal_list (list, forcecols)
}
else
{
- signum = decode_signal (list->word->word);
+ dflags = DSIG_NOCASE;
+ if (posixly_correct == 0 || this_shell_builtin != kill_builtin)
+ dflags |= DSIG_SIGPREFIX;
+ signum = decode_signal (list->word->word, dflags);
if (signum == NO_SIG)
{
sh_invalidsig (list->word->word);
diff --git a/builtins/common.h b/builtins/common.h
index a971bcda..c8438638 100644
--- a/builtins/common.h
+++ b/builtins/common.h
@@ -30,6 +30,7 @@
#define SEVAL_INTERACT 0x002
#define SEVAL_NOHIST 0x004
#define SEVAL_NOFREE 0x008
+#define SEVAL_RESETLINE 0x010
/* Flags for describe_command, shared between type.def and command.def */
#define CDESC_ALL 0x001 /* type -a */
@@ -105,6 +106,9 @@ 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));
@@ -150,7 +154,7 @@ extern void parse_and_execute_cleanup __P((void));
/* Functions from evalfile.c */
extern int maybe_execute_file __P((const char *, int));
-extern int source_file __P((const char *));
+extern int source_file __P((const char *, int));
extern int fc_execute_file __P((const char *));
#endif /* !__COMMON_H */
diff --git a/builtins/complete.def b/builtins/complete.def
index f3916204..06f0c957 100644
--- a/builtins/complete.def
+++ b/builtins/complete.def
@@ -47,6 +47,7 @@ $END
#include "../shell.h"
#include "../builtins.h"
#include "../pcomplete.h"
+#include "../bashline.h"
#include "common.h"
#include "bashgetopt.h"
@@ -106,10 +107,12 @@ static struct _compopt {
char *optname;
int optflag;
} compopts[] = {
+ { "bashdefault", COPT_BASHDEFAULT },
{ "default", COPT_DEFAULT },
{ "dirnames", COPT_DIRNAMES },
{ "filenames",COPT_FILENAMES},
{ "nospace", COPT_NOSPACE },
+ { "plusdirs", COPT_PLUSDIRS },
{ (char *)NULL, 0 },
};
@@ -428,10 +431,12 @@ print_one_completion (cmd, cs)
copts = cs->options;
/* First, print the -o options. */
+ PRINTCOMPOPT (COPT_BASHDEFAULT, "bashdefault");
PRINTCOMPOPT (COPT_DEFAULT, "default");
PRINTCOMPOPT (COPT_DIRNAMES, "dirnames");
PRINTCOMPOPT (COPT_FILENAMES, "filenames");
PRINTCOMPOPT (COPT_NOSPACE, "nospace");
+ PRINTCOMPOPT (COPT_PLUSDIRS, "plusdirs");
acts = cs->actions;
@@ -540,7 +545,7 @@ compgen_builtin (list)
unsigned long acts, copts;
COMPSPEC *cs;
STRINGLIST *sl;
- char *word;
+ char *word, **matches;
if (list == 0)
return (EXECUTION_SUCCESS);
@@ -583,12 +588,19 @@ compgen_builtin (list)
rval = EXECUTION_FAILURE;
sl = gen_compspec_completions (cs, "compgen", word, 0, 0);
+ /* If the compspec wants the bash default completions, temporarily
+ turn off programmable completion and call the bash completion code. */
+ if ((sl == 0 || sl->list_len == 0) && (copts & COPT_BASHDEFAULT))
+ {
+ matches = bash_default_completion (word, 0, 0, 0, 0);
+ sl = completions_to_stringlist (matches);
+ strvec_dispose (matches);
+ }
+
/* This isn't perfect, but it's the best we can do, given what readline
exports from its set of completion utility functions. */
if ((sl == 0 || sl->list_len == 0) && (copts & COPT_DEFAULT))
{
- char **matches;
-
matches = rl_completion_matches (word, rl_filename_completion_function);
sl = completions_to_stringlist (matches);
strvec_dispose (matches);
diff --git a/builtins/declare.def b/builtins/declare.def
index 75b154f8..0b151498 100644
--- a/builtins/declare.def
+++ b/builtins/declare.def
@@ -1,7 +1,7 @@
This file is declare.def, from which is created declare.c.
It implements the builtins "declare" and "local" in Bash.
-Copyright (C) 1987-2002 Free Software Foundation, Inc.
+Copyright (C) 1987-2003 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -23,7 +23,7 @@ $PRODUCES declare.c
$BUILTIN declare
$FUNCTION declare_builtin
-$SHORT_DOC declare [-afFirtx] [-p] name[=value] ...
+$SHORT_DOC declare [-afFirtx] [-p] [name[=value] ...]
Declare variables and/or give them attributes. If no NAMEs are
given, then display the values of variables instead. The -p option
will display the attributes and values of each NAME.
@@ -32,7 +32,8 @@ The flags are:
-a to make NAMEs arrays (if supported)
-f to select from among function names only
- -F to display function names without definitions
+ -F to display function names (and line number and source file name if
+ debugging) without definitions
-i to make NAMEs have the `integer' attribute
-r to make NAMEs readonly
-t to make NAMEs have the `trace' attribute
@@ -120,6 +121,7 @@ declare_internal (list, local_var)
int flags_on, flags_off, *flags, any_failed, assign_error, pflag, nodefs, opt;
char *t, *subscript_start;
SHELL_VAR *var;
+ FUNCTION_DEF *shell_fn;
flags_on = flags_off = any_failed = assign_error = pflag = nodefs = 0;
reset_internal_getopt ();
@@ -309,9 +311,22 @@ declare_internal (list, local_var)
/* declare -[Ff] name [name...] */
if (flags_on == att_function && flags_off == 0)
{
- t = nodefs ? var->name
- : named_function_string (name, function_cell (var), 1);
- printf ("%s\n", t);
+#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), 1);
+ printf ("%s\n", t);
+ }
}
else /* declare -[fF] -[rx] name [name...] */
{
diff --git a/builtins/evalfile.c b/builtins/evalfile.c
index 0675753e..850acbd6 100644
--- a/builtins/evalfile.c
+++ b/builtins/evalfile.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2003 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -58,6 +58,7 @@ extern int errno;
#define FEVAL_HISTORY 0x020
#define FEVAL_CHECKBINARY 0x040
#define FEVAL_REGFILE 0x080
+#define FEVAL_NOPUSHARGS 0x100
extern int posixly_correct;
extern int indirection_level, startup_state, subshell_environment;
@@ -79,9 +80,28 @@ _evalfile (filename, flags)
struct stat finfo;
size_t file_size;
sh_vmsg_func_t *errfunc;
+#if defined (ARRAY_VARS)
+ SHELL_VAR *funcname_v, *bash_source_v, *bash_lineno_v;
+ ARRAY *funcname_a, *bash_source_a, *bash_lineno_a;
+# 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))
@@ -176,8 +196,27 @@ file_error_and_exit:
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 = (flags & FEVAL_HISTORY) ? 0 : SEVAL_NOHIST;
+ pflags = SEVAL_RESETLINE;
+ pflags |= (flags & FEVAL_HISTORY) ? 0 : SEVAL_NOHIST;
if (flags & FEVAL_BUILTIN)
result = EXECUTION_SUCCESS;
@@ -205,6 +244,19 @@ file_error_and_exit:
COPY_PROCENV (old_return_catch, return_catch);
}
+#if defined (ARRAY_VARS)
+ array_pop (bash_source_a);
+ array_pop (bash_lineno_a);
+ 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);
}
@@ -240,14 +292,20 @@ fc_execute_file (filename)
#endif /* HISTORY */
int
-source_file (filename)
+source_file (filename, sflags)
const char *filename;
+ int sflags;
{
- int flags;
+ 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)
flags |= FEVAL_LONGJMP;
- return (_evalfile (filename, flags));
+ rval = _evalfile (filename, flags);
+
+ run_return_trap ();
+ return rval;
}
diff --git a/builtins/evalstring.c b/builtins/evalstring.c
index 860a3de8..88d6a9e5 100644
--- a/builtins/evalstring.c
+++ b/builtins/evalstring.c
@@ -84,6 +84,7 @@ parse_and_execute_cleanup ()
(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
@@ -92,7 +93,7 @@ parse_and_execute (string, from_file, flags)
const char *from_file;
int flags;
{
- int code, x;
+ int code, x, lreset;
volatile int should_jump_to_top_level, last_result;
char *orig_string;
COMMAND *volatile command;
@@ -107,6 +108,8 @@ parse_and_execute (string, from_file, flags)
if (flags & (SEVAL_NONINT|SEVAL_INTERACT))
unwind_protect_int (interactive);
+ lreset = flags & SEVAL_RESETLINE;
+
#if defined (HISTORY)
unwind_protect_int (remember_on_history); /* can be used in scripts */
# if defined (BANG_HISTORY)
@@ -129,7 +132,15 @@ parse_and_execute (string, from_file, flags)
end_unwind_frame ();
parse_and_execute_level++;
- push_stream (1); /* reset the line number */
+
+ /* 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++;
if (flags & (SEVAL_NONINT|SEVAL_INTERACT))
interactive = (flags & SEVAL_NONINT) ? 0 : 1;
@@ -141,11 +152,12 @@ parse_and_execute (string, from_file, flags)
code = should_jump_to_top_level = 0;
last_result = EXECUTION_SUCCESS;
- command = (COMMAND *)NULL;
with_input_from_string (string, from_file);
while (*(bash_input.location.string))
{
+ command = (COMMAND *)NULL;
+
if (interrupt_state)
{
last_result = EXECUTION_FAILURE;
@@ -163,15 +175,18 @@ parse_and_execute (string, from_file, flags)
switch (code)
{
case FORCE_EOF:
+ case ERREXIT:
case EXITPROG:
- run_unwind_frame ("pe_dispose");
+ 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:
- run_unwind_frame ("pe_dispose");
+ if (command)
+ run_unwind_frame ("pe_dispose");
last_result = last_command_exit_value = EXECUTION_FAILURE; /* XXX */
if (subshell_environment)
{
diff --git a/builtins/exec.def b/builtins/exec.def
index a6881b88..73a42f69 100644
--- a/builtins/exec.def
+++ b/builtins/exec.def
@@ -208,8 +208,7 @@ exec_builtin (list)
file_error (command);
failed_exec:
- if (command)
- free (command);
+ FREE (command);
if (subshell_environment || (interactive == 0 && no_exit_on_failed_exec == 0))
exit_shell (exit_value);
diff --git a/builtins/exit.def b/builtins/exit.def
index bf1d9205..735fecc2 100644
--- a/builtins/exit.def
+++ b/builtins/exit.def
@@ -122,6 +122,18 @@ exit_or_logout (list)
exit_value = get_exitstat (list);
+ bash_logout ();
+
+ last_command_exit_value = exit_value;
+
+ /* Exit the program. */
+ jump_to_top_level (EXITPROG);
+ /*NOTREACHED*/
+}
+
+void
+bash_logout ()
+{
/* Run our `~/.bash_logout' file if it exists, and this is a login shell. */
if (login_shell && sourced_logout++ == 0 && subshell_environment == 0)
{
@@ -130,10 +142,4 @@ exit_or_logout (list)
maybe_execute_file (SYS_BASH_LOGOUT, 1);
#endif
}
-
- last_command_exit_value = exit_value;
-
- /* Exit the program. */
- jump_to_top_level (EXITPROG);
- /*NOTREACHED*/
}
diff --git a/builtins/fc.def b/builtins/fc.def
index c300066f..0e6ab990 100644
--- a/builtins/fc.def
+++ b/builtins/fc.def
@@ -54,7 +54,7 @@ $END
#endif
#include "../bashtypes.h"
#include "posixstat.h"
-#ifndef _MINIX
+#if ! defined(_MINIX) && defined (HAVE_SYS_FILE_H)
# include <sys/file.h>
#endif
diff --git a/builtins/getopts.def b/builtins/getopts.def
index a2a82ff4..6cd40d32 100644
--- a/builtins/getopts.def
+++ b/builtins/getopts.def
@@ -44,7 +44,7 @@ seen, getopts places the option character found into OPTARG. If a
required argument is not found, getopts places a ':' into NAME and
sets OPTARG to the option character found. If getopts is not in
silent mode, and an invalid option is seen, getopts places '?' into
-NAME and unsets OPTARG. If a required option is not found, a '?'
+NAME and unsets OPTARG. If a required argument is not found, a '?'
is placed in NAME, OPTARG is unset, and a diagnostic message is
printed.
diff --git a/builtins/history.def b/builtins/history.def
index 7311705d..5c1a829d 100644
--- a/builtins/history.def
+++ b/builtins/history.def
@@ -34,20 +34,25 @@ current history to the history file; `-r' means to read the file and
append the contents to the history list instead. `-a' means
to append history lines from this session to the history file.
Argument `-n' means to read all history lines not already read
-from the history file and append them to the history list. If
-FILENAME is given, then that is used as the history file else
+from the history file and append them to the history list.
+
+If FILENAME is given, then that is used as the history file else
if $HISTFILE has a value, that is used, else ~/.bash_history.
If the -s option is supplied, the non-option ARGs are appended to
the history list as a single entry. The -p option means to perform
history expansion on each ARG and display the result, without storing
anything in the history list.
+
+If the $HISTTIMEFORMAT variable is set and not null, its value is used
+as a format string for strftime(3) to print the time stamp associated
+with each displayed history entry. No time stamps are printed otherwise.
$END
#include <config.h>
#if defined (HISTORY)
#include "../bashtypes.h"
-#ifndef _MINIX
+#if ! defined(_MINIX) && defined (HAVE_SYS_FILE_H)
# include <sys/file.h>
#endif
#include "posixstat.h"
@@ -72,6 +77,7 @@ extern int errno;
extern int current_command_line_count;
+static char *histtime __P((HIST_ENTRY *, const char *));
static void display_history __P((WORD_LIST *));
static int delete_histent __P((int));
static int delete_last_history __P((void));
@@ -91,7 +97,7 @@ int
history_builtin (list)
WORD_LIST *list;
{
- int flags, opt, result, old_history_lines;
+ int flags, opt, result, old_history_lines, obase;
char *filename, *delete_arg;
intmax_t delete_offset;
@@ -200,11 +206,23 @@ history_builtin (list)
{
/* Read all of the lines in the file that we haven't already read. */
old_history_lines = history_lines_in_file;
+ obase = history_base;
+
using_history ();
result = read_history_range (filename, history_lines_in_file, -1);
using_history ();
+
history_lines_in_file = where_history ();
- history_lines_this_session += history_lines_in_file - old_history_lines;
+ /* The question is whether we reset history_lines_this_session to 0,
+ losing any history entries we had before we read the new entries
+ from the history file, or whether we count the new entries we just
+ read from the file as history lines added during this session.
+ Right now, we do the latter. This will cause these history entries
+ to be written to the history file along with any intermediate entries
+ we add when we do a `history -a', but the alternative is losing
+ them altogether. */
+ history_lines_this_session += history_lines_in_file - old_history_lines +
+ history_base - obase;
}
return (result ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
@@ -214,6 +232,22 @@ history_builtin (list)
#define histline(i) (hlist[(i)]->line)
#define histdata(i) (hlist[(i)]->data)
+static char *
+histtime (hlist, histtimefmt)
+ HIST_ENTRY *hlist;
+ const char *histtimefmt;
+{
+ static char timestr[128];
+ time_t t;
+
+ t = history_get_time (hlist);
+ if (t)
+ strftime (timestr, sizeof (timestr), histtimefmt, localtime (&t));
+ else
+ strcpy (timestr, "??");
+ return timestr;
+}
+
static void
display_history (list)
WORD_LIST *list;
@@ -221,6 +255,7 @@ display_history (list)
register int i;
intmax_t limit;
HIST_ENTRY **hlist;
+ char *histtimefmt, *timestr;
if (list)
{
@@ -243,11 +278,17 @@ display_history (list)
else
i = 0;
+
+ histtimefmt = get_string_value ("HISTTIMEFORMAT");
+
while (hlist[i])
{
QUIT;
- printf ("%5d%c %s\n", i + history_base,
+
+ timestr = (histtimefmt && *histtimefmt) ? histtime (hlist[i], histtimefmt) : (char *)NULL;
+ printf ("%5d%c %s%s\n", i + history_base,
histdata(i) ? '*' : ' ',
+ ((timestr && *timestr) ? timestr : ""),
histline(i));
i++;
}
@@ -263,11 +304,8 @@ delete_histent (i)
discard = remove_history (i);
if (discard)
- {
- if (discard->line)
- free (discard->line);
- free ((char *) discard);
- }
+ free_history_entry (discard);
+
return 1;
}
@@ -276,6 +314,7 @@ delete_last_history ()
{
register int i;
HIST_ENTRY **hlist, *histent;
+ int r;
hlist = history_list ();
if (hlist == NULL)
@@ -290,7 +329,12 @@ delete_last_history ()
if (histent == NULL)
return 0;
- return (delete_histent (i));
+ r = delete_histent (i);
+
+ if (where_history () > history_length)
+ history_set_pos (history_length);
+
+ return r;
}
/* Remove the last entry in the history list and add each argument in
diff --git a/builtins/jobs.def b/builtins/jobs.def
index 54f50ca3..51b7c267 100644
--- a/builtins/jobs.def
+++ b/builtins/jobs.def
@@ -163,6 +163,7 @@ execute_list_with_replacements (list)
{
register WORD_LIST *l;
int job, result;
+ COMMAND *command;
/* First do the replacement of job specifications with pids. */
for (l = list; l; l = l->next)
@@ -182,21 +183,18 @@ execute_list_with_replacements (list)
/* Next make a new simple command and execute it. */
begin_unwind_frame ("jobs_builtin");
- {
- COMMAND *command = (COMMAND *)NULL;
- add_unwind_protect (dispose_command, command);
+ command = make_bare_simple_command ();
+ command->value.Simple->words = copy_word_list (list);
+ command->value.Simple->redirects = (REDIRECT *)NULL;
+ command->flags |= CMD_INHIBIT_EXPANSION;
+ command->value.Simple->flags |= CMD_INHIBIT_EXPANSION;
- command = make_bare_simple_command ();
- command->value.Simple->words = copy_word_list (list);
- command->value.Simple->redirects = (REDIRECT *)NULL;
- command->flags |= CMD_INHIBIT_EXPANSION;
- command->value.Simple->flags |= CMD_INHIBIT_EXPANSION;
+ add_unwind_protect (dispose_command, command);
+ result = execute_command (command);
+ dispose_command (command);
- result = execute_command (command);
- }
-
- run_unwind_frame ("jobs_builtin");
+ discard_unwind_frame ("jobs_builtin");
return (result);
}
#endif /* JOB_CONTROL */
diff --git a/builtins/kill.def b/builtins/kill.def
index 96b34fcb..12074917 100644
--- a/builtins/kill.def
+++ b/builtins/kill.def
@@ -1,7 +1,7 @@
This file is kill.def, from which is created kill.c.
It implements the builtin "kill" in Bash.
-Copyright (C) 1987-2002 Free Software Foundation, Inc.
+Copyright (C) 1987-2003 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -23,7 +23,6 @@ $PRODUCES kill.c
$BUILTIN kill
$FUNCTION kill_builtin
-$DEPENDS_ON JOB_CONTROL
$SHORT_DOC kill [-s sigspec | -n signum | -sigspec] [pid | job]... or kill -l [sigspec]
Send the processes named by PID (or JOB) the signal SIGSPEC. If
SIGSPEC is not present, then SIGTERM is assumed. An argument of `-l'
@@ -57,9 +56,10 @@ $END
extern int errno;
#endif /* !errno */
-#if defined (JOB_CONTROL)
extern int posixly_correct;
+static void kill_error __P((pid_t, int));
+
#if !defined (CONTINUE_AFTER_KILL_ERROR)
# define CONTINUE_OR_FAIL return (EXECUTION_FAILURE)
#else
@@ -73,7 +73,7 @@ int
kill_builtin (list)
WORD_LIST *list;
{
- int sig, any_succeeded, listing, saw_signal;
+ int sig, any_succeeded, listing, saw_signal, dflags;
char *sigspec, *word;
pid_t pid;
intmax_t pid_value;
@@ -88,6 +88,7 @@ kill_builtin (list)
sig = SIGTERM;
sigspec = "TERM";
+ dflags = DSIG_NOCASE | ((posixly_correct == 0) ? DSIG_SIGPREFIX : 0);
/* Process options. */
while (list)
{
@@ -107,7 +108,7 @@ kill_builtin (list)
if (sigspec[0] == '0' && sigspec[1] == '\0')
sig = 0;
else
- sig = decode_signal (sigspec);
+ sig = decode_signal (sigspec, dflags);
list = list->next;
}
else
@@ -132,7 +133,7 @@ kill_builtin (list)
else if ((*word == '-') && !saw_signal)
{
sigspec = word + 1;
- sig = decode_signal (sigspec);
+ sig = decode_signal (sigspec, dflags);
saw_signal++;
list = list->next;
}
@@ -169,13 +170,20 @@ kill_builtin (list)
pid = (pid_t) pid_value;
if ((pid < -1 ? kill_pid (-pid, sig, 1) : kill_pid (pid, sig, 0)) < 0)
- goto signal_error;
+ {
+ if (errno == EINVAL)
+ sh_invalidsig (sigspec);
+ else
+ kill_error (pid, errno);
+ CONTINUE_OR_FAIL;
+ }
else
any_succeeded++;
}
+#if defined (JOB_CONTROL)
else if (*list->word->word && *list->word->word != '%')
{
- builtin_error ("%s: no such pid", list->word->word);
+ builtin_error ("%s: arguments must be process or job IDs", list->word->word);
CONTINUE_OR_FAIL;
}
else if (*word && (interactive || job_control))
@@ -205,16 +213,16 @@ kill_builtin (list)
if (kill_pid (pid, sig, 1) < 0)
{
- signal_error:
if (errno == EINVAL)
sh_invalidsig (sigspec);
else
- builtin_error ("(%ld) - %s", (long)pid, strerror (errno));
+ kill_error (pid, errno);
CONTINUE_OR_FAIL;
}
else
any_succeeded++;
}
+#endif /* !JOB_CONTROL */
else
{
sh_badpid (list->word->word);
@@ -226,4 +234,16 @@ kill_builtin (list)
return (any_succeeded ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
}
-#endif /* JOB_CONTROL */
+
+static void
+kill_error (pid, e)
+ pid_t pid;
+ int e;
+{
+ char *x;
+
+ x = strerror (e);
+ if (x == 0)
+ x = "Unknown error";
+ builtin_error ("(%ld) - %s", (long)pid, x);
+}
diff --git a/builtins/let.def b/builtins/let.def
index 7c9341ed..85131b04 100644
--- a/builtins/let.def
+++ b/builtins/let.def
@@ -45,7 +45,7 @@ The levels are listed in order of decreasing precedence.
&& logical AND
|| logical OR
expr ? expr : expr
- conditional expression
+ conditional operator
=, *=, /=, %=,
+=, -=, <<=, >>=,
&=, ^=, |= assignment
diff --git a/builtins/mkbuiltins.c b/builtins/mkbuiltins.c
index c911f86e..f8d82f11 100644
--- a/builtins/mkbuiltins.c
+++ b/builtins/mkbuiltins.c
@@ -29,8 +29,10 @@ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#endif
#ifndef _MINIX
-#include "../bashtypes.h"
-#include <sys/file.h>
+# include "../bashtypes.h"
+# if defined (HAVE_SYS_FILE_H)
+# include <sys/file.h>
+# endif
#endif
#include "posixstat.h"
diff --git a/builtins/printf.def b/builtins/printf.def
index 8821ecb2..705f5b6e 100644
--- a/builtins/printf.def
+++ b/builtins/printf.def
@@ -114,7 +114,7 @@ static int getint __P((void));
static intmax_t getintmax __P((void));
static uintmax_t getuintmax __P((void));
-#if defined (HAVE_LONG_DOUBLE) && HAVE_DECL_STRTOLD
+#if defined (HAVE_LONG_DOUBLE) && HAVE_DECL_STRTOLD && !defined(STRTOLD_BROKEN)
typedef long double floatmax_t;
# define FLOATMAX_CONV "L"
# define strtofltmax strtold
diff --git a/builtins/read.def b/builtins/read.def
index 46a0407b..7f6a83c1 100644
--- a/builtins/read.def
+++ b/builtins/read.def
@@ -505,6 +505,7 @@ read_builtin (list)
alist = list_string (input_string, ifs_chars, 0);
if (alist)
{
+ word_list_remove_quoted_nulls (alist);
assign_array_var_from_word_list (var, alist);
dispose_words (alist);
}
diff --git a/builtins/set.def b/builtins/set.def
index 10aaf5ff..4f900dd6 100644
--- a/builtins/set.def
+++ b/builtins/set.def
@@ -77,6 +77,8 @@ $SHORT_DOC set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
emacs use an emacs-style line editing interface
#endif /* READLINE */
errexit same as -e
+ errtrace same as -E
+ functrace same as -T
hashall same as -h
#if defined (BANG_HISTORY)
histexpand same as -H
@@ -97,6 +99,9 @@ $SHORT_DOC set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
nounset same as -u
onecmd same as -t
physical same as -P
+ pipefail the return value of a pipeline is the status of
+ the last command to exit with a non-zero status,
+ or zero if no command exited with a non-zero status
posix change the behavior of bash where the default
operation differs from the 1003.2 standard to
match the standard
@@ -119,12 +124,14 @@ $SHORT_DOC set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
#endif /* BRACE_EXPANSION */
-C If set, disallow existing regular files to be overwritten
by redirection of output.
+ -E If set, the ERR trap is inherited by shell functions.
#if defined (BANG_HISTORY)
-H Enable ! style history substitution. This flag is on
by default.
#endif /* BANG_HISTORY */
-P If set, do not follow symbolic links when executing commands
such as cd which change the current directory.
+ -T If set, the DEBUG trap is inherited by shell functions.
Using + rather than - causes these flags to be turned off. The
flags can also be used upon invocation of the shell. The current
@@ -172,6 +179,8 @@ struct {
{ "emacs", '\0', (int *)NULL, set_edit_mode, get_edit_mode },
#endif
{ "errexit", 'e', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
+ { "errtrace", 'E', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
+ { "functrace", 'T', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "hashall", 'h', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#if defined (BANG_HISTORY)
{ "histexpand", 'H', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
@@ -195,6 +204,7 @@ struct {
{ "nounset", 'u', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "onecmd", 't', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "physical", 'P', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
+ { "pipefail", '\0', &pipefail_opt, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "posix", '\0', &posixly_correct, set_posix_mode, (setopt_get_func_t *)NULL },
{ "privileged", 'p', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "verbose", 'v', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
diff --git a/builtins/setattr.def b/builtins/setattr.def
index 8465e7d3..0ef5041e 100644
--- a/builtins/setattr.def
+++ b/builtins/setattr.def
@@ -75,13 +75,12 @@ export_builtin (list)
$BUILTIN readonly
$FUNCTION readonly_builtin
-$SHORT_DOC readonly [-anf] [name[=value] ...] or readonly -p
+$SHORT_DOC readonly [-af] [name[=value] ...] or readonly -p
The given NAMEs are marked readonly and the values of these NAMEs may
not be changed by subsequent assignment. If the -f option is given,
then functions corresponding to the NAMEs are so marked. If no
arguments are given, or if `-p' is given, a list of all readonly names
-is printed. An argument of `-n' says to remove the readonly property
-from subsequent NAMEs. The `-a' option means to treat each NAME as
+is printed. The `-a' option means to treat each NAME as
an array variable. An argument of `--' disables further option
processing.
$END
@@ -103,7 +102,7 @@ readonly_builtin (list)
/* For each variable name in LIST, make that variable have the specified
ATTRIBUTE. An arg of `-n' says to remove the attribute from the the
- remaining names in LIST. */
+ remaining names in LIST (doesn't work for readonly). */
int
set_or_show_attributes (list, attribute, nodefs)
register WORD_LIST *list;
diff --git a/builtins/shift.def b/builtins/shift.def
index dbff0622..236f10ff 100644
--- a/builtins/shift.def
+++ b/builtins/shift.def
@@ -68,7 +68,7 @@ shift_builtin (list)
else if (times > number_of_args ())
{
if (print_shift_error)
- sh_erange (list->word->word, "shift count");
+ sh_erange (list ? list->word->word : NULL, "shift count");
return (EXECUTION_FAILURE);
}
diff --git a/builtins/shopt.def b/builtins/shopt.def
index ae15330d..88ecbb2d 100644
--- a/builtins/shopt.def
+++ b/builtins/shopt.def
@@ -55,15 +55,17 @@ $END
#define OPTFMT "%-15s\t%s\n"
-extern int allow_null_glob_expansion, glob_dot_filenames;
+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;
extern int hup_on_exit;
extern int xpg_echo;
+extern int gnu_error_format;
#if defined (EXTENDED_GLOB)
extern int extended_glob;
@@ -77,6 +79,7 @@ extern int force_append_history;
#if defined (READLINE)
extern int hist_verify, history_reediting, perform_hostname_completion;
extern int no_empty_command_completion;
+extern int force_fignore;
extern int enable_hostname_completion __P((int));
#endif
@@ -88,9 +91,13 @@ extern int prog_completion_enabled;
extern char *shell_name;
#endif
+#if defined (DEBUGGER)
+extern int debugging_mode;
+#endif
+
static void shopt_error __P((char *));
-static int set_interactive_comments __P((int));
+static int set_shellopts_after_change __P((int));
#if defined (RESTRICTED_SHELL)
static int set_restricted_shell __P((int));
@@ -115,10 +122,17 @@ static struct {
{ "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 },
+ { "gnu_errfmt", &gnu_error_format, (shopt_set_func_t *)NULL },
{ "histreedit", &history_reediting, (shopt_set_func_t *)NULL },
#endif
#if defined (HISTORY)
@@ -129,7 +143,7 @@ static struct {
{ "hostcomplete", &perform_hostname_completion, enable_hostname_completion },
#endif
{ "huponexit", &hup_on_exit, (shopt_set_func_t *)NULL },
- { "interactive_comments", &interactive_comments, set_interactive_comments },
+ { "interactive_comments", &interactive_comments, set_shellopts_after_change },
#if defined (HISTORY)
{ "lithist", &literal_history, (shopt_set_func_t *)NULL },
#endif
@@ -435,7 +449,7 @@ set_shopt_o_options (mode, list, quiet)
/* If we set or unset interactive_comments with shopt, make sure the
change is reflected in $SHELLOPTS. */
static int
-set_interactive_comments (mode)
+set_shellopts_after_change (mode)
int mode;
{
set_shellopts ();
diff --git a/builtins/source.def b/builtins/source.def
index ffb23f07..422e293e 100644
--- a/builtins/source.def
+++ b/builtins/source.def
@@ -23,16 +23,20 @@ $PRODUCES source.c
$BUILTIN source
$FUNCTION source_builtin
-$SHORT_DOC source filename
+$SHORT_DOC source filename [arguments]
Read and execute commands from FILENAME and return. The pathnames
-in $PATH are used to find the directory containing FILENAME.
+in $PATH are used to find the directory containing FILENAME. If any
+ARGUMENTS are supplied, they become the positional parameters when
+FILENAME is executed.
$END
$BUILTIN .
$DOCNAME dot
$FUNCTION source_builtin
-$SHORT_DOC . filename
+$SHORT_DOC . filename [arguments]
Read and execute commands from FILENAME and return. The pathnames
-in $PATH are used to find the directory containing FILENAME.
+in $PATH are used to find the directory containing FILENAME. If any
+ARGUMENTS are supplied, they become the positional parameters when
+FILENAME is executed.
$END
/* source.c - Implements the `.' and `source' builtins. */
@@ -41,7 +45,7 @@ $END
#include "../bashtypes.h"
#include "posixstat.h"
#include "filecntl.h"
-#ifndef _MINIX
+#if ! defined(_MINIX) && defined (HAVE_SYS_FILE_H)
# include <sys/file.h>
#endif
#include <errno.h>
@@ -53,9 +57,11 @@ $END
#include "../bashansi.h"
#include "../shell.h"
+#include "../flags.h"
#include "../findcmd.h"
#include "common.h"
#include "bashgetopt.h"
+#include "../trap.h"
#if !defined (errno)
extern int errno;
@@ -85,6 +91,7 @@ maybe_pop_dollar_vars ()
dispose_saved_dollar_vars ();
else
pop_dollar_vars ();
+ pop_args (); /* restore BASH_ARGC and BASH_ARGV */
set_dollar_vars_unchanged ();
}
@@ -97,7 +104,7 @@ source_builtin (list)
WORD_LIST *list;
{
int result;
- char *filename;
+ char *filename, *debug_trap;
if (no_options (list))
return (EX_USAGE);
@@ -140,10 +147,23 @@ source_builtin (list)
push_dollar_vars ();
add_unwind_protect ((Function *)maybe_pop_dollar_vars, (char *)NULL);
remember_args (list->next, 1);
+ push_args (list->next); /* Update BASH_ARGV and BASH_ARGC */
}
set_dollar_vars_unchanged ();
- result = source_file (filename);
+ /* Don't inherit the DEBUG trap unless function_trace_mode (overloaded)
+ is set. XXX - should sourced files inherit the RETURN trap? Functions
+ don't. */
+ debug_trap = TRAP_STRING (DEBUG_TRAP);
+ if (debug_trap && function_trace_mode == 0)
+ {
+ debug_trap = savestring (debug_trap);
+ add_unwind_protect (xfree, debug_trap);
+ add_unwind_protect (set_debug_trap, debug_trap);
+ restore_default_signal (DEBUG_TRAP);
+ }
+
+ result = source_file (filename, (list && list->next));
run_unwind_frame ("source");
diff --git a/builtins/suspend.def b/builtins/suspend.def
index 43391c0d..6a77210f 100644
--- a/builtins/suspend.def
+++ b/builtins/suspend.def
@@ -104,6 +104,9 @@ suspend_builtin (list)
}
}
+ /* XXX - should we put ourselves back into the original pgrp now? If so,
+ call end_job_control() here and do the right thing in suspend_continue
+ (that is, call restart_job_control()). */
old_cont = (SigHandler *)set_signal_handler (SIGCONT, suspend_continue);
#if 0
old_stop = (SigHandler *)set_signal_handler (SIGSTOP, SIG_DFL);
diff --git a/builtins/trap.def b/builtins/trap.def
index af9e6d6c..70b90fa5 100644
--- a/builtins/trap.def
+++ b/builtins/trap.def
@@ -108,6 +108,8 @@ trap_builtin (list)
}
list = loptend;
+ opt = DSIG_NOCASE|DSIG_SIGPREFIX; /* flags for decode_signal */
+
if (list_signal_names)
return (display_signal_list ((WORD_LIST *)NULL, 1));
else if (display || list == 0)
@@ -119,8 +121,12 @@ trap_builtin (list)
operation = SET;
first_arg = list->word->word;
- if (first_arg && *first_arg && (*first_arg != '-' || first_arg[1]) &&
- signal_object_p (first_arg))
+ /* When not in posix mode, the historical behavior of looking for a
+ missing first argument is disabled. To revert to the original
+ signal handling disposition, use `-' as the first argument. */
+ if (posixly_correct == 0 && first_arg && *first_arg &&
+ (*first_arg != '-' || first_arg[1]) &&
+ signal_object_p (first_arg, opt))
operation = REVERT;
else
{
@@ -133,7 +139,7 @@ trap_builtin (list)
while (list)
{
- sig = decode_signal (list->word->word);
+ sig = decode_signal (list->word->word, opt);
if (sig == NO_SIG)
{
@@ -235,7 +241,7 @@ display_traps (list)
for (result = EXECUTION_SUCCESS; list; list = list->next)
{
- i = decode_signal (list->word->word);
+ i = decode_signal (list->word->word, DSIG_NOCASE|DSIG_SIGPREFIX);
if (i == NO_SIG)
{
sh_invalidsig (list->word->word);
diff --git a/builtins/type.def b/builtins/type.def
index 2d9d2a56..8e5028a0 100644
--- a/builtins/type.def
+++ b/builtins/type.def
@@ -73,6 +73,7 @@ $END
extern int find_reserved_word __P((char *));
extern char *this_command_name;
+extern int expand_aliases;
/* For each word in LIST, find out what the shell is going to do with
it as a simple command. i.e., which file would this shell use to
@@ -221,7 +222,7 @@ describe_command (command, dflags)
#if defined (ALIAS)
/* Command is an alias? */
- if (((dflags & CDESC_FORCE_PATH) == 0) && (alias = find_alias (command)))
+ if (((dflags & CDESC_FORCE_PATH) == 0) && expand_aliases && (alias = find_alias (command)))
{
if (dflags & CDESC_TYPE)
puts ("alias");
diff --git a/builtins/umask.def b/builtins/umask.def
index 19a0ac0d..f1693316 100644
--- a/builtins/umask.def
+++ b/builtins/umask.def
@@ -37,7 +37,7 @@ $END
#include "../bashtypes.h"
#include "filecntl.h"
-#ifndef _MINIX
+#if ! defined(_MINIX) && defined (HAVE_SYS_FILE_H)
# include <sys/file.h>
#endif