diff options
| author | Jari Aalto <jari.aalto@cante.net> | 2001-11-13 17:56:06 +0000 |
|---|---|---|
| committer | Jari Aalto <jari.aalto@cante.net> | 2009-09-12 16:46:54 +0000 |
| commit | f73dda092b33638d2d5e9c35375f687a607b5403 (patch) | |
| tree | f21584e70a444d6a1ecba0fb5e2cf79e8cce91db /builtins | |
| parent | 28ef6c316f1aff914bb95ac09787a3c83c1815fd (diff) | |
| download | android_external_bash-f73dda092b33638d2d5e9c35375f687a607b5403.tar.gz android_external_bash-f73dda092b33638d2d5e9c35375f687a607b5403.tar.bz2 android_external_bash-f73dda092b33638d2d5e9c35375f687a607b5403.zip | |
Imported from ../bash-2.05a.tar.gz.
Diffstat (limited to 'builtins')
47 files changed, 1295 insertions, 682 deletions
diff --git a/builtins/ChangeLog b/builtins/ChangeLog deleted file mode 100644 index e69de29..0000000 --- a/builtins/ChangeLog +++ /dev/null diff --git a/builtins/Makefile.in b/builtins/Makefile.in index 688e55d..837b53e 100644 --- a/builtins/Makefile.in +++ b/builtins/Makefile.in @@ -36,7 +36,7 @@ BUILD_DIR = @BUILD_DIR@ PROFILE_FLAGS = @PROFILE_FLAGS@ CFLAGS = @CFLAGS@ -LOCAL_CFLAGS = @LOCAL_CFLAGS@ +LOCAL_CFLAGS = @LOCAL_CFLAGS@ ${DEBUG} CPPFLAGS = @CPPFLAGS@ DEFS = @DEFS@ LOCAL_DEFS = @LOCAL_DEFS@ @@ -46,10 +46,18 @@ LIBS = @LIBS@ BASHINCDIR = ${topdir}/include +RL_INCLUDEDIR = @RL_INCLUDEDIR@ + INCLUDES = -I. -I.. @RL_INCLUDE@ -I$(topdir) -I$(BASHINCDIR) -I$(topdir)/lib -I$(srcdir) -CCFLAGS = ${PROFILE_FLAGS} $(DEFS) $(LOCAL_DEFS) $(SYSTEM_FLAGS) $(CPPFLAGS) \ - ${INCLUDES} $(LOCAL_CFLAGS) $(CFLAGS) +CCFLAGS_FOR_BUILD = ${PROFILE_FLAGS} $(DEFS) $(LOCAL_DEFS) $(SYSTEM_FLAGS) \ + $(CPPFLAGS) ${INCLUDES} $(LOCAL_CFLAGS) + +CCFLAGS = $(CCFLAGS_FOR_BUILD) $(CFLAGS) + +GCC_LINT_FLAGS = -Wall -Wshadow -Wpointer-arith -Wcast-qual \ + -Wcast-align -Wstrict-prototypes -Wconversion \ + -Wmissing-prototypes -Wtraditional -Wredundant-decls -pedantic MKBUILTINS = mkbuiltins$(EXEEXT) DIRECTDEFINE = -D $(srcdir) @@ -131,7 +139,7 @@ builtext.h builtins.c: $(MKBUILTINS) $(DEFSRC) mkbuiltins.o: ../config.h mkbuiltins.o: mkbuiltins.c $(RM) $@ - $(CC_FOR_BUILD) -c $(CCFLAGS) $< + $(CC_FOR_BUILD) -c $(CCFLAGS_FOR_BUILD) $< mkbuiltins$(EXEEXT): mkbuiltins.o $(CC_FOR_BUILD) $(PROFILE_FLAGS) $(LDFLAGS) -o $(MKBUILTINS) mkbuiltins.o $(LIBS) @@ -151,7 +159,7 @@ pipesize.h: psize.aux $(SHELL) $(srcdir)/psize.sh > $@ psize.aux: psize.c - $(CC_FOR_BUILD) $(CCFLAGS) -o $@ $(srcdir)/psize.c + $(CC_FOR_BUILD) $(CCFLAGS_FOR_BUILD) -o $@ $(srcdir)/psize.c documentation: builtins.texi @@ -214,26 +222,28 @@ complete.o: complete.def # C files bashgetopt.o: ../config.h $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h bashgetopt.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/bashjmp.h -bashgetopt.o: $(topdir)/command.h $(topdir)/general.h $(topdir)/error.h -bashgetopt.o: $(topdir)/variables.h $(topdir)/quit.h $(BASHINCDIR)/maxpath.h +bashgetopt.o: $(topdir)/command.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/error.h +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: $(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 common.o: $(topdir)/sig.h $(topdir)/command.h -common.o: $(topdir)/general.h $(BASHINCDIR)/stdc.h $(BASHINCDIR)/memalloc.h -common.o: $(topdir)/variables.h $(topdir)/input.h +common.o: $(topdir)/general.h $(topdir)/xmalloc.h $(BASHINCDIR)/stdc.h $(BASHINCDIR)/memalloc.h +common.o: $(topdir)/variables.h $(topdir)/conftypes.h $(topdir)/input.h 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: $(BASHINCDIR)/chartypes.h evalfile.o: $(topdir)/bashtypes.h $(BASHINCDIR)/posixstat.h ${BASHINCDIR}/filecntl.h evalfile.o: $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h evalfile.o: $(topdir)/shell.h $(topdir)/syntax.h ../config.h $(topdir)/bashjmp.h -evalfile.o: $(topdir)/command.h $(topdir)/general.h $(topdir)/error.h -evalfile.o: $(topdir)/variables.h $(topdir)/quit.h $(BASHINCDIR)/maxpath.h +evalfile.o: $(topdir)/command.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/error.h +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 @@ -243,16 +253,17 @@ evalfile.o: $(topdir)/bashhist.h $(srcdir)/common.h evalstring.o: ../config.h $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h evalstring.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/bashjmp.h $(BASHINCDIR)/posixjmp.h evalstring.o: $(topdir)/sig.h $(topdir)/command.h $(topdir)/siglist.h -evalstring.o: $(BASHINCDIR)/memalloc.h $(topdir)/variables.h $(topdir)/input.h +evalstring.o: $(BASHINCDIR)/memalloc.h $(topdir)/variables.h $(topdir)/conftypes.h $(topdir)/input.h evalstring.o: $(topdir)/quit.h $(topdir)/unwind_prot.h evalstring.o: $(BASHINCDIR)/maxpath.h $(topdir)/jobs.h $(topdir)/builtins.h evalstring.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h evalstring.o: $(topdir)/externs.h $(topdir)/jobs.h $(topdir)/builtins.h evalstring.o: $(topdir)/flags.h $(topdir)/input.h $(topdir)/execute_cmd.h evalstring.o: $(topdir)/bashhist.h $(srcdir)/common.h +evalstring.o: $(topdir)/trap.h $(topdir)/redir.h getopt.o: ../config.h $(BASHINCDIR)/memalloc.h getopt.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/bashjmp.h $(topdir)/command.h -getopt.o: $(topdir)/general.h $(topdir)/error.h $(topdir)/variables.h +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 @@ -263,224 +274,232 @@ mkbuiltins.o: $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h # def files alias.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -alias.o: $(topdir)/error.h $(topdir)/general.h $(BASHINCDIR)/maxpath.h +alias.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(BASHINCDIR)/maxpath.h alias.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h alias.o: $(topdir)/subst.h $(topdir)/externs.h $(srcdir)/common.h -alias.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +alias.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h bind.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h bind.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h bind.o: $(topdir)/subst.h $(topdir)/externs.h $(srcdir)/bashgetopt.h -bind.o: $(topdir)/general.h $(BASHINCDIR)/maxpath.h $(topdir)/bashline.h -bind.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +bind.o: $(topdir)/general.h $(topdir)/xmalloc.h $(BASHINCDIR)/maxpath.h $(topdir)/bashline.h +bind.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h break.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -break.o: $(topdir)/error.h $(topdir)/general.h +break.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h break.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h break.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h -break.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +break.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h builtin.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -builtin.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/externs.h +builtin.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/externs.h 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 +builtin.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h cd.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h -cd.o: $(topdir)/general.h $(topdir)/quit.h $(topdir)/dispose_cmd.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 -cd.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +cd.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h cd.o: $(srcdir)/common.h $(BASHINCDIR)/maxpath.h command.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -command.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/externs.h +command.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/externs.h command.o: $(topdir)/quit.h $(srcdir)/bashgetopt.h $(BASHINCDIR)/maxpath.h command.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h -command.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +command.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h declare.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -declare.o: $(topdir)/error.h $(topdir)/general.h +declare.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h 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 +declare.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h +declare.o: $(topdir)/arrayfunc.h echo.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h -echo.o: $(topdir)/general.h $(topdir)/subst.h $(topdir)/externs.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 -echo.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +echo.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h echo.o: $(BASHINCDIR)/maxpath.h enable.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -enable.o: $(topdir)/error.h $(topdir)/general.h +enable.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h enable.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h enable.o: $(topdir)/subst.h $(topdir)/externs.h -enable.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +enable.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h enable.o: $(BASHINCDIR)/maxpath.h enable.o: $(topdir)/pcomplete.h eval.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -eval.o: $(topdir)/error.h $(topdir)/general.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)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.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 exec.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -exec.o: $(topdir)/error.h $(topdir)/general.h +exec.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h exec.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h exec.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/flags.h -exec.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +exec.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h exec.o: $(srcdir)/common.h $(topdir)/execute_cmd.h $(BASHINCDIR)/maxpath.h exec.o: $(topdir)/findcmd.h exit.o: $(topdir)/bashtypes.h exit.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -exit.o: $(topdir)/error.h $(topdir)/general.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)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.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 fc.o: $(topdir)/builtins.h $(topdir)/command.h $(srcdir)/bashgetopt.h fc.o: $(topdir)/bashhist.h fc.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h -fc.o: $(topdir)/general.h $(BASHINCDIR)/maxpath.h +fc.o: $(topdir)/general.h $(topdir)/xmalloc.h $(BASHINCDIR)/maxpath.h fc.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h fc.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/shell.h $(topdir)/syntax.h -fc.o: $(topdir)/flags.h $(topdir)/unwind_prot.h $(topdir)/variables.h -fc.o: $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h +fc.o: $(topdir)/flags.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h +fc.o: $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h $(BASHINCDIR)/chartypes.h fg_bg.o: $(topdir)/bashtypes.h fg_bg.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -fg_bg.o: $(topdir)/error.h $(topdir)/general.h +fg_bg.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h fg_bg.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h fg_bg.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h -fg_bg.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +fg_bg.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h getopts.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -getopts.o: $(topdir)/error.h $(topdir)/general.h +getopts.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h getopts.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h getopts.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h -getopts.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +getopts.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h hash.o: $(topdir)/builtins.h $(topdir)/command.h $(topdir)/quit.h hash.o: $(topdir)/findcmd.h $(topdir)/hashlib.h hash.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -hash.o: $(topdir)/error.h $(topdir)/general.h -hash.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +hash.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h +hash.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h hash.o: $(srcdir)/common.h $(BASHINCDIR)/maxpath.h help.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -help.o: $(topdir)/error.h $(topdir)/general.h +help.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h help.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h help.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h -help.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +help.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h +help.o: ${srcdir}/common.h ../version.h history.o: $(topdir)/bashtypes.h history.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -history.o: $(topdir)/error.h $(topdir)/general.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: ${BASHINCDIR}/filecntl.h $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h -history.o: $(topdir)/variables.h $(topdir)/bashhist.h $(BASHINCDIR)/maxpath.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 -inlib.o: $(topdir)/error.h $(topdir)/general.h -inlib.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +inlib.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h +inlib.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h 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)/quit.h $(srcdir)/bashgetopt.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: $(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 +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 -kill.o: $(topdir)/general.h $(topdir)/subst.h $(topdir)/externs.h +kill.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/subst.h $(topdir)/externs.h kill.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h kill.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/trap.h $(topdir)/unwind_prot.h -kill.o: $(topdir)/variables.h $(BASHINCDIR)/maxpath.h +kill.o: $(topdir)/variables.h $(topdir)/conftypes.h $(BASHINCDIR)/maxpath.h let.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -let.o: $(topdir)/error.h $(topdir)/general.h +let.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h let.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h let.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h -let.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +let.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h printf.o: ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/bashjmp.h -printf.o: $(topdir)/command.h $(topdir)/error.h $(topdir)/general.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: $(topdir)/variables.h $(BASHINCDIR)/stdc.h $(srcdir)/bashgetopt.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 +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)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.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 -read.o: $(topdir)/error.h $(topdir)/general.h +read.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h read.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h read.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h -read.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +read.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h read.o: $(BASHINCDIR)/shtty.h +read.o: $(topdir)/arrayfunc.h return.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -return.o: $(topdir)/error.h $(topdir)/general.h +return.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h return.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h return.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h -return.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +return.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h set.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -set.o: $(topdir)/general.h $(topdir)/subst.h $(topdir)/externs.h +set.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/subst.h $(topdir)/externs.h set.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h -set.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +set.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h set.o: $(BASHINCDIR)/maxpath.h $(topdir)/error.h +set.o: $(topdir)/arrayfunc.h setattr.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -setattr.o: $(topdir)/error.h $(topdir)/general.h $(BASHINCDIR)/maxpath.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)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.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 -shift.o: $(topdir)/error.h $(topdir)/general.h +shift.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h shift.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h shift.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h -shift.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +shift.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h source.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -source.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/findcmd.h +source.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/findcmd.h 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 +source.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h suspend.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -suspend.o: $(topdir)/error.h $(topdir)/general.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 suspend.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h -suspend.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +suspend.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h test.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -test.o: $(topdir)/error.h $(topdir)/general.h +test.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h test.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h test.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h -test.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +test.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h test.o: $(topdir)/test.h times.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -times.o: $(topdir)/error.h $(topdir)/general.h +times.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h times.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h times.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h -times.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +times.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h times.o: $(BASHINCDIR)/posixtime.h trap.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -trap.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/externs.h +trap.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/externs.h trap.o: $(topdir)/quit.h $(srcdir)/common.h $(BASHINCDIR)/maxpath.h trap.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h -trap.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +trap.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h trap.o: $(topdir)/findcmd.h type.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -type.o: $(topdir)/error.h $(topdir)/general.h +type.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h type.o: $(topdir)/quit.h $(srcdir)/common.h $(BASHINCDIR)/maxpath.h type.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h type.o: $(topdir)/externs.h $(topdir)/hashcmd.h -type.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +type.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h ulimit.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -ulimit.o: $(topdir)/error.h $(topdir)/general.h +ulimit.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h ulimit.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h ulimit.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h -ulimit.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +ulimit.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h umask.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -umask.o: $(topdir)/error.h $(topdir)/general.h +umask.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h umask.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h umask.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h -umask.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +umask.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h +umask.o: $(BASHINCDIR)/chartypes.h wait.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -wait.o: $(topdir)/error.h $(topdir)/general.h +wait.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h wait.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h wait.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h -wait.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h +wait.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h +wait.o: $(BASHINCDIR)/chartypes.h shopt.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h -shopt.o: $(topdir)/error.h $(topdir)/general.h +shopt.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h shopt.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h 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 +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 diff --git a/builtins/alias.def b/builtins/alias.def index 5f7bfe7..e279d4d 100644 --- a/builtins/alias.def +++ b/builtins/alias.def @@ -51,8 +51,7 @@ $END # include "common.h" # include "bashgetopt.h" -extern int interactive; -static void print_alias (); +static void print_alias __P((alias_t *)); /* Hack the alias command in a Korn shell way. */ int diff --git a/builtins/bashgetopt.c b/builtins/bashgetopt.c index 17bb578..a0b14c0 100644 --- a/builtins/bashgetopt.c +++ b/builtins/bashgetopt.c @@ -25,6 +25,7 @@ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #endif #include "../bashansi.h" +#include <chartypes.h> #include <errno.h> #include "../shell.h" @@ -124,7 +125,7 @@ char *opts; } else if (*cp == '#') { /* optional numeric argument */ if (lcurrent->word->word[sp+1]) { - if (digit(lcurrent->word->word[sp+1])) { + if (DIGIT(lcurrent->word->word[sp+1])) { list_optarg = lcurrent->word->word + sp + 1; lcurrent = lcurrent->next; } else diff --git a/builtins/bashgetopt.h b/builtins/bashgetopt.h index 773fc00..93cf590 100644 --- a/builtins/bashgetopt.h +++ b/builtins/bashgetopt.h @@ -23,6 +23,8 @@ #if !defined (__BASH_GETOPT_H) # define __BASH_GETOPT_H +#include <stdc.h> + extern char *list_optarg; extern int list_optopt; @@ -30,8 +32,8 @@ extern int list_optopt; extern WORD_LIST *lcurrent; extern WORD_LIST *loptend; -extern int internal_getopt (); -extern void reset_internal_getopt (); -extern void report_bad_option (); +extern int internal_getopt __P((WORD_LIST *, char *)); +extern void reset_internal_getopt __P((void)); +extern void report_bad_option __P((void)); #endif /* !__BASH_GETOPT_H */ diff --git a/builtins/bind.def b/builtins/bind.def index ce996a0..40c8c9f 100644 --- a/builtins/bind.def +++ b/builtins/bind.def @@ -76,8 +76,8 @@ extern int errno; #include "bashgetopt.h" #include "common.h" -static int query_bindings (); -static int unbind_command (); +static int query_bindings __P((char *)); +static int unbind_command __P((char *)); extern int no_line_editing; @@ -102,7 +102,6 @@ bind_builtin (list) WORD_LIST *list; { int return_code; - FILE *old_rl_outstream; Keymap kmap, saved_keymap; int flags, opt; char *initfile, *map_name, *fun_name, *unbind_name, *remove_seq, *cmd_seq; @@ -118,10 +117,9 @@ bind_builtin (list) if (!bash_readline_initialized) initialize_readline (); - /* Cannot use unwind_protect_pointer () on "FILE *", it is only - guaranteed to work for strings. */ - /* XXX -- see if we can use unwind_protect here */ - old_rl_outstream = rl_outstream; + begin_unwind_frame ("bind_builtin"); + unwind_protect_var (rl_outstream); + rl_outstream = stdout; reset_internal_getopt (); @@ -242,7 +240,7 @@ bind_builtin (list) if ((flags & RFLAG) && remove_seq) { - if (rl_set_key (remove_seq, (Function *)NULL, rl_get_keymap ()) != 0) + if (rl_set_key (remove_seq, (rl_command_func_t *)NULL, rl_get_keymap ()) != 0) { builtin_error ("cannot unbind %s", remove_seq); BIND_RETURN (EXECUTION_FAILURE); @@ -263,7 +261,8 @@ bind_builtin (list) if (saved_keymap) rl_set_keymap (saved_keymap); - rl_outstream = old_rl_outstream; + run_unwind_frame ("bind_builtin"); + return (return_code); } @@ -271,7 +270,7 @@ static int query_bindings (name) char *name; { - Function *function; + rl_command_func_t *function; char **keyseqs; int j; @@ -303,7 +302,7 @@ static int unbind_command (name) char *name; { - Function *function; + rl_command_func_t *function; function = rl_named_function (name); if (function == 0) diff --git a/builtins/break.def b/builtins/break.def index 778d1f8..e90a32b 100644 --- a/builtins/break.def +++ b/builtins/break.def @@ -42,7 +42,7 @@ $END extern char *this_command_name; extern int posixly_correct; -static int check_loop_level (); +static int check_loop_level __P((void)); /* The depth of while's and until's. */ int loop_level = 0; @@ -59,7 +59,7 @@ int break_builtin (list) WORD_LIST *list; { - int newbreak; + long newbreak; if (check_loop_level () == 0) return (EXECUTION_SUCCESS); @@ -94,7 +94,7 @@ int continue_builtin (list) WORD_LIST *list; { - int newcont; + long newcont; if (check_loop_level () == 0) return (EXECUTION_SUCCESS); diff --git a/builtins/builtin.def b/builtins/builtin.def index 21dbb59..f3de5d6 100644 --- a/builtins/builtin.def +++ b/builtins/builtin.def @@ -48,7 +48,7 @@ int builtin_builtin (list) WORD_LIST *list; { - Function *function; + sh_builtin_func_t *function; register char *command; if (!list) diff --git a/builtins/cd.def b/builtins/cd.def index 57306a5..77e8f82 100644 --- a/builtins/cd.def +++ b/builtins/cd.def @@ -53,13 +53,14 @@ $PRODUCES cd.c extern int errno; #endif /* !errno */ -extern int posixly_correct, interactive; +extern int posixly_correct; extern int array_needs_making; extern char *bash_getcwd_errstr; -static int change_to_directory (); +static int bindpwd __P((int)); +static int change_to_directory __P((char *, int)); -static char *cdspell (); +static char *cdspell __P((char *)); /* Change this to 1 to get cd spelling correction by default. */ int cdspelling = 0; @@ -87,7 +88,7 @@ bindpwd (no_symlinks) int no_symlinks; { char *dirname, *pwdvar; - int old_symlinks, old_anm; + int old_anm; SHELL_VAR *tvar; #define tcwd the_current_working_directory @@ -424,7 +425,7 @@ cdspell (dirname) char *guess; n = (strlen (dirname) * 3 + 1) / 2 + 1; - guess = xmalloc (n); + guess = (char *)xmalloc (n); switch (spname (dirname, guess)) { diff --git a/builtins/command.def b/builtins/command.def index a3f25f2..28515be 100644 --- a/builtins/command.def +++ b/builtins/command.def @@ -49,10 +49,14 @@ $END #include "bashgetopt.h" #include "common.h" +#if defined (_CS_PATH) && defined (HAVE_CONFSTR) && !HAVE_DECL_CONFSTR +extern size_t confstr __P((int, char *, size_t)); +#endif + extern int subshell_environment; -static void restore_path (); -static char *get_standard_path (); +static void restore_path __P((char *)); +static char *get_standard_path __P((void)); /* Run the commands mentioned in LIST without paying attention to shell functions. */ @@ -131,11 +135,13 @@ command_builtin (list) FREE (standard_path); } +#define COMMAND_BUILTIN_FLAGS (CMD_NO_FUNCTIONS | CMD_INHIBIT_EXPANSION | CMD_COMMAND_BUILTIN) + command = make_bare_simple_command (); command->value.Simple->words = (WORD_LIST *)copy_word_list (list); command->value.Simple->redirects = (REDIRECT *)NULL; - command->flags |= (CMD_NO_FUNCTIONS | CMD_INHIBIT_EXPANSION); - command->value.Simple->flags |= (CMD_NO_FUNCTIONS | CMD_INHIBIT_EXPANSION); + command->flags |= COMMAND_BUILTIN_FLAGS; + command->value.Simple->flags |= COMMAND_BUILTIN_FLAGS; #if 0 /* This breaks for things like ( cd /tmp ; command z ababa ; echo next ) or $(command echo a ; command echo b;) or even @@ -184,7 +190,7 @@ get_standard_path () len = (size_t)confstr (_CS_PATH, (char *)NULL, (size_t)0); if (len > 0) { - p = xmalloc ((int)len + 2); + p = (char *)xmalloc (len + 2); *p = '\0'; confstr (_CS_PATH, p, len); return (p); diff --git a/builtins/common.c b/builtins/common.c index e3e9cc3..19a76ea 100644 --- a/builtins/common.c +++ b/builtins/common.c @@ -26,6 +26,7 @@ #endif #include <stdio.h> +#include <chartypes.h> #include "../bashtypes.h" #include "posixstat.h" #include <signal.h> @@ -63,26 +64,18 @@ extern int errno; #endif /* !errno */ -#ifdef __STDC__ -typedef int QSFUNC (const void *, const void *); -#else -typedef int QSFUNC (); -#endif - -extern int no_symbolic_links, interactive, interactive_shell; +extern int no_symbolic_links; extern int indirection_level, startup_state, subshell_environment; extern int line_number; extern int last_command_exit_value; extern int running_trap; -extern int variable_context; extern int posixly_correct; extern char *this_command_name, *shell_name; -extern COMMAND *global_command; extern char *bash_getcwd_errstr; /* Used by some builtins and the mainline code. */ -Function *last_shell_builtin = (Function *)NULL; -Function *this_shell_builtin = (Function *)NULL; +sh_builtin_func_t *last_shell_builtin = (sh_builtin_func_t *)NULL; +sh_builtin_func_t *this_shell_builtin = (sh_builtin_func_t *)NULL; /* **************************************************************** */ /* */ @@ -337,7 +330,7 @@ set_dollar_vars_changed () follow. If FATAL is true, call throw_to_top_level, which exits the shell; if not, call jump_to_top_level (DISCARD), which aborts the current command. */ -int +long get_numeric_arg (list, fatal) WORD_LIST *list; int fatal; @@ -359,9 +352,31 @@ get_numeric_arg (list, fatal) } no_args (list->next); } + return (count); } +/* Get an eight-bit status value from LIST */ +int +get_exitstat (list) + WORD_LIST *list; +{ + int status; + long sval; + char *arg; + + arg = list->word->word; + if (arg == 0 || legal_number (arg, &sval) == 0) + { + builtin_error ("bad non-numeric arg `%s'", list->word->word); + return 255; + } + no_args (list->next); + + status = sval & 255; + return status; +} + /* Return the octal number parsed from STRING, or -1 to indicate that the string contained a bad number. */ int @@ -375,9 +390,11 @@ read_octal (string) { digits++; result = (result * 8) + (*string++ - '0'); + if (result > 0777) + return -1; } - if (!digits || result > 0777 || *string) + if (digits == 0 || *string) result = -1; return (result); @@ -409,7 +426,7 @@ get_working_directory (for_whom) if (the_current_working_directory == 0) { - the_current_working_directory = xmalloc (PATH_MAX); + the_current_working_directory = (char *)xmalloc (PATH_MAX); the_current_working_directory[0] = '\0'; directory = getcwd (the_current_working_directory, PATH_MAX); if (directory == 0) @@ -449,7 +466,7 @@ get_job_spec (list) WORD_LIST *list; { register char *word; - int job, substring; + int job, substring_search; if (list == 0) return (current_job); @@ -462,13 +479,13 @@ get_job_spec (list) if (*word == '%') word++; - if (digit (*word) && all_digits (word)) + if (DIGIT (*word) && all_digits (word)) { job = atoi (word); return (job >= job_slots ? NO_JOB : job - 1); } - substring = 0; + substring_search = 0; switch (*word) { case 0: @@ -480,7 +497,7 @@ get_job_spec (list) return (previous_job); case '?': /* Substring search requested. */ - substring++; + substring_search++; word++; /* FALLTHROUGH */ @@ -498,15 +515,17 @@ get_job_spec (list) p = jobs[i]->pipe; do { - if ((substring && strindex (p->command, word)) || + if ((substring_search && strindex (p->command, word)) || (STREQN (p->command, word, wl))) - if (job != NO_JOB) - { - builtin_error ("ambigious job spec: %s", word); - return (DUP_JOB); - } - else - job = i; + { + if (job != NO_JOB) + { + builtin_error ("ambigious job spec: %s", word); + return (DUP_JOB); + } + else + job = i; + } p = p->next; } @@ -658,33 +677,33 @@ builtin_address_internal (name, disabled_okay) } /* Return the pointer to the function implementing builtin command NAME. */ -Function * +sh_builtin_func_t * find_shell_builtin (name) char *name; { current_builtin = builtin_address_internal (name, 0); - return (current_builtin ? current_builtin->function : (Function *)NULL); + return (current_builtin ? current_builtin->function : (sh_builtin_func_t *)NULL); } /* Return the address of builtin with NAME, whether it is enabled or not. */ -Function * +sh_builtin_func_t * builtin_address (name) char *name; { current_builtin = builtin_address_internal (name, 1); - return (current_builtin ? current_builtin->function : (Function *)NULL); + return (current_builtin ? current_builtin->function : (sh_builtin_func_t *)NULL); } /* Return the function implementing the builtin NAME, but only if it is a POSIX.2 special builtin. */ -Function * +sh_builtin_func_t * find_special_builtin (name) char *name; { current_builtin = builtin_address_internal (name, 0); return ((current_builtin && (current_builtin->flags & SPECIAL_BUILTIN)) ? current_builtin->function : - (Function *)NULL); + (sh_builtin_func_t *)NULL); } static int diff --git a/builtins/common.h b/builtins/common.h index 8f3366b..dbebeda 100644 --- a/builtins/common.h +++ b/builtins/common.h @@ -31,7 +31,7 @@ #define SEVAL_NOHIST 0x04 /* Functions from common.c */ -extern void builtin_error __P((const char *, ...)); +extern void builtin_error __P((const char *, ...)) __attribute__((__format__ (printf, 1, 2))); extern void builtin_usage __P((void)); extern void no_args __P((WORD_LIST *)); extern void bad_option __P((char *)); @@ -49,7 +49,8 @@ extern int dollar_vars_changed __P((void)); extern void set_dollar_vars_unchanged __P((void)); extern void set_dollar_vars_changed __P((void)); -extern int get_numeric_arg __P((WORD_LIST *, int)); +extern long get_numeric_arg __P((WORD_LIST *, int)); +extern int get_exitstat __P((WORD_LIST *)); extern int read_octal __P((char *)); /* Keeps track of the current working directory. */ @@ -65,23 +66,35 @@ extern int display_signal_list __P((WORD_LIST *, int)); /* It's OK to declare a function as returning a Function * without providing a definition of what a `Function' is. */ extern struct builtin *builtin_address_internal __P((char *, int)); -extern Function *find_shell_builtin __P((char *)); -extern Function *builtin_address __P((char *)); -extern Function *find_special_builtin __P((char *)); +extern sh_builtin_func_t *find_shell_builtin __P((char *)); +extern sh_builtin_func_t *builtin_address __P((char *)); +extern sh_builtin_func_t *find_special_builtin __P((char *)); extern void initialize_shell_builtins __P((void)); +/* Functions from getopts.def */ +extern void getopts_reset __P((int)); + /* Functions from set.def */ -extern void initialize_shell_options __P((int)); +extern int minus_o_option_value __P((char *)); extern void list_minus_o_opts __P((int, int)); +extern char **get_minus_o_opts __P((void)); extern int set_minus_o_option __P((int, char *)); -extern int minus_o_option_value __P((char *)); + +extern void set_shellopts __P((void)); +extern void parse_shellopts __P((char *)); +extern void initialize_shell_options __P((int)); + extern void reset_shell_options __P((void)); -extern char **get_minus_o_opts __P((void)); /* Functions from shopt.def */ extern void reset_shopt_options __P((void)); extern char **get_shopt_options __P((void)); +extern int shopt_setopt __P((char *, int)); +extern int shopt_listopt __P((char *, int)); + +extern int set_login_shell __P((int)); + /* Functions from type.def */ extern int describe_command __P((char *, int, int)); @@ -93,17 +106,17 @@ extern void set_var_attribute __P((char *, int, int)); /* Functions from pushd.def */ extern char *get_dirstack_from_string __P((char *)); -extern char *get_dirstack_element __P((int, int)); -extern void set_dirstack_element __P((int, int, char *)); +extern char *get_dirstack_element __P((long, int)); +extern void set_dirstack_element __P((long, int, char *)); extern WORD_LIST *get_directory_stack __P((void)); /* Functions from evalstring.c */ -extern int parse_and_execute __P((char *, char *, int)); +extern int parse_and_execute __P((char *, const char *, int)); extern void parse_and_execute_cleanup __P((void)); /* Functions from evalfile.c */ -extern int maybe_execute_file __P((char *, int)); -extern int source_file __P((char *)); -extern int fc_execute_file __P((char *)); +extern int maybe_execute_file __P((const char *, int)); +extern int source_file __P((const char *)); +extern int fc_execute_file __P((const char *)); #endif /* !__COMMON_H */ diff --git a/builtins/complete.def b/builtins/complete.def index 3ac41d0..732ba03 100644 --- a/builtins/complete.def +++ b/builtins/complete.def @@ -24,7 +24,7 @@ $PRODUCES complete.c $BUILTIN complete $DEPENDS_ON PROGRAMMABLE_COMPLETION $FUNCTION complete_builtin -$SHORT_DOC complete [-abcdefjkvu] [-pr] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [name ...] +$SHORT_DOC complete [-abcdefgjkvu] [-pr] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [name ...] For each NAME, specify how arguments are to be completed. If the -p option is supplied, or if no options are supplied, existing completion specifications are printed in a way that allows them to be @@ -51,12 +51,20 @@ $END #include "common.h" #include "bashgetopt.h" +#include <readline/readline.h> + #define STRDUP(x) ((x) ? savestring (x) : (char *)NULL) -static int remove_cmd_completions (); +static int find_compact __P((char *)); +static int find_compopt __P((char *)); + +static int build_actions __P((WORD_LIST *, int *, int *, unsigned long *, unsigned long *)); + +static int remove_cmd_completions __P((WORD_LIST *)); -static void print_all_completions (); -static int print_cmd_completions (); +static void print_one_completion __P((char *, COMPSPEC *)); +static void print_all_completions __P((void)); +static int print_cmd_completions __P((WORD_LIST *)); static char *Aarg, *Garg, *Warg, *Parg, *Sarg, *Xarg, *Farg, *Carg; @@ -78,6 +86,7 @@ static struct _compacts { { "function", CA_FUNCTION, 0 }, { "helptopic", CA_BUILTIN, 0 }, /* for now */ { "hostname", CA_HOSTNAME, 0 }, + { "group", CA_GROUP, 'g' }, { "job", CA_JOB, 'j' }, { "keyword", CA_KEYWORD, 'k' }, { "running", CA_RUNNING, 0 }, @@ -144,14 +153,14 @@ build_actions (list, pp, rp, actp, optp) int *pp, *rp; unsigned long *actp, *optp; { - int opt, ind, pflag, rflag, opt_given; + int opt, ind, opt_given; unsigned long acts, copts; acts = copts = (unsigned long)0L; opt_given = 0; reset_internal_getopt (); - while ((opt = internal_getopt (list, "abcdefjko:pruvA:G:W:P:S:X:F:C:")) != -1) + while ((opt = internal_getopt (list, "abcdefgjko:pruvA:G:W:P:S:X:F:C:")) != -1) { opt_given = 1; switch (opt) @@ -200,6 +209,9 @@ build_actions (list, pp, rp, actp, optp) case 'f': acts |= CA_FILE; break; + case 'g': + acts |= CA_GROUP; + break; case 'j': acts |= CA_JOB; break; @@ -424,6 +436,7 @@ print_one_completion (cmd, cs) PRINTOPT (CA_DIRECTORY, "-d"); PRINTOPT (CA_EXPORT, "-e"); PRINTOPT (CA_FILE, "-f"); + PRINTOPT (CA_GROUP, "-g"); PRINTOPT (CA_KEYWORD, "-k"); PRINTOPT (CA_JOB, "-j"); PRINTOPT (CA_USER, "-u"); @@ -490,7 +503,7 @@ print_cmd_completions (list) $BUILTIN compgen $DEPENDS_ON PROGRAMMABLE_COMPLETION $FUNCTION compgen_builtin -$SHORT_DOC compgen [-abcdefjkvu] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [word] +$SHORT_DOC compgen [-abcdefgjkvu] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [word] Display the possible completions depending on the options. Intended to be used from within a shell function generating possible completions. If the optional WORD argument is supplied, matches against WORD are @@ -547,9 +560,21 @@ compgen_builtin (list) rval = EXECUTION_FAILURE; sl = gen_compspec_completions (cs, "compgen", word, 0, 0); + + /* 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); + free_array (matches); + } + if (sl) { - if (sl->list) + if (sl->list && sl->list_len) { rval = EXECUTION_SUCCESS; print_stringlist (sl, (char *)NULL); diff --git a/builtins/declare.def b/builtins/declare.def index 6686f0a..98f1cb1 100644 --- a/builtins/declare.def +++ b/builtins/declare.def @@ -71,9 +71,9 @@ $END #include "common.h" #include "builtext.h" -extern int variable_context, array_needs_making; +extern int array_needs_making; -static int declare_internal (); +static int declare_internal __P((register WORD_LIST *, int)); /* Declare or change variable attributes. */ int @@ -110,7 +110,7 @@ declare_internal (list, local_var) int local_var; { int flags_on, flags_off, *flags, any_failed, assign_error, pflag, nodefs; - char *t; + char *t, *subscript_start; SHELL_VAR *var; flags_on = flags_off = any_failed = assign_error = pflag = nodefs = 0; @@ -215,7 +215,7 @@ declare_internal (list, local_var) char *value, *name; int offset; #if defined (ARRAY_VARS) - int making_array_special, assigning_array_special; + int making_array_special, compound_array_assign, simple_array_assign; #endif name = savestring (list->word->word); @@ -230,9 +230,11 @@ declare_internal (list, local_var) value = ""; #if defined (ARRAY_VARS) - assigning_array_special = 0; - if (t = strchr (name, '[')) + compound_array_assign = simple_array_assign = 0; + subscript_start = (char *)NULL; + if (t = strchr (name, '[')) /* ] */ { + subscript_start = t; *t = '\0'; making_array_special = 1; } @@ -344,18 +346,12 @@ declare_internal (list, local_var) } #if defined (ARRAY_VARS) - /* declare -a name=value does not work; declare name=value when - name is already an array does not work. */ if ((making_array_special || (flags_on & att_array) || array_p (var)) && offset) { if (value[0] == '(' && strchr (value, ')')) - assigning_array_special = 1; + compound_array_assign = 1; else - { - builtin_error ("%s: cannot assign to array variables in this way", name); - assign_error++; - NEXT_VARIABLE (); - } + simple_array_assign = 1; } /* Cannot use declare +a name to remove an array variable. */ @@ -375,8 +371,18 @@ declare_internal (list, local_var) VUNSETATTR (var, flags_off); #if defined (ARRAY_VARS) - if (offset && assigning_array_special) + if (offset && compound_array_assign) assign_array_var_from_string (var, value); + else if (simple_array_assign && subscript_start) + { + /* declare [-a] name[N]=value */ + *subscript_start = '['; /* ] */ + var = assign_array_element (name, value); + *subscript_start = '\0'; + } + else if (simple_array_assign) + /* let bind_array_variable take care of this. */ + bind_array_variable (name, 0, value); else #endif /* bind_variable_value duplicates the essential internals of diff --git a/builtins/enable.def b/builtins/enable.def index b6ac483..50b4dc7 100644 --- a/builtins/enable.def +++ b/builtins/enable.def @@ -60,14 +60,6 @@ $END # include "../pcomplete.h" #endif -#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM) -static int dyn_load_builtin (); -#endif - -#if defined (HAVE_DLCLOSE) -static int dyn_unload_builtin (); -#endif - #define ENABLED 1 #define DISABLED 2 #define SPECIAL 4 @@ -79,8 +71,18 @@ static int dyn_unload_builtin (); #define PFLAG 0x10 #define SFLAG 0x20 -static int enable_shell_command (); -static void list_some_builtins (); +#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM) +static int dyn_load_builtin __P((WORD_LIST *, int, char *)); +#endif + +#if defined (HAVE_DLCLOSE) +static int dyn_unload_builtin __P((char *)); +static void delete_builtin __P((struct builtin *)); +static int local_dlclose __P((void *)); +#endif + +static void list_some_builtins __P((int)); +static int enable_shell_command __P((char *, int)); /* Enable/disable shell commands present in LIST. If list is not specified, then print out a list of shell commands showing which are enabled and @@ -305,7 +307,7 @@ dyn_load_builtin (list, flags, filename) name = list->word->word; size = strlen (name); - struct_name = xmalloc (size + 8); + struct_name = (char *)xmalloc (size + 8); strcpy (struct_name, name); strcpy (struct_name + size, "_struct"); @@ -355,7 +357,7 @@ dyn_load_builtin (list, flags, filename) sizeof (struct builtin)); new_shell_builtins[total].name = (char *)0; - new_shell_builtins[total].function = (Function *)0; + new_shell_builtins[total].function = (sh_builtin_func_t *)0; new_shell_builtins[total].flags = 0; if (shell_builtins != static_shell_builtins) @@ -427,7 +429,6 @@ dyn_unload_builtin (name) struct builtin *b; void *handle; int ref, i; - char *uerror; b = builtin_address_internal (name, 1); if (b == 0) diff --git a/builtins/evalfile.c b/builtins/evalfile.c index 1116b09..f334221 100644 --- a/builtins/evalfile.c +++ b/builtins/evalfile.c @@ -57,8 +57,9 @@ extern int errno; #define FEVAL_LONGJMP 0x010 #define FEVAL_HISTORY 0x020 #define FEVAL_CHECKBINARY 0x040 +#define FEVAL_REGFILE 0x080 -extern int interactive, interactive_shell, posixly_correct; +extern int posixly_correct; extern int indirection_level, startup_state, subshell_environment; extern int return_catch_flag, return_catch_value; extern int last_command_exit_value; @@ -68,7 +69,7 @@ int sourcelevel = 0; static int _evalfile (filename, flags) - char *filename; + const char *filename; int flags; { volatile int old_interactive; @@ -77,7 +78,9 @@ _evalfile (filename, flags) char *string; struct stat finfo; size_t file_size; - VFunction *errfunc; + sh_vmsg_func_t *errfunc; + + USE_VAR(pflags); fd = open (filename, O_RDONLY); @@ -97,14 +100,14 @@ file_error_and_exit: : ((errno == ENOENT) ? 0 : -1)); } - errfunc = (VFunction *)((flags & FEVAL_BUILTIN) ? builtin_error : internal_error); + errfunc = ((flags & FEVAL_BUILTIN) ? builtin_error : internal_error); if (S_ISDIR (finfo.st_mode)) { (*errfunc) ("%s: is a directory", filename); return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE : -1); } - else if (S_ISREG (finfo.st_mode) == 0) + else if ((flags & FEVAL_REGFILE) && S_ISREG (finfo.st_mode) == 0) { (*errfunc) ("%s: not a regular file", filename); return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE : -1); @@ -122,7 +125,7 @@ file_error_and_exit: setmode (fd, O_TEXT); #endif - string = xmalloc (1 + file_size); + string = (char *)xmalloc (1 + file_size); result = read (fd, string, file_size); string[result] = '\0'; @@ -143,7 +146,7 @@ file_error_and_exit: } if ((flags & FEVAL_CHECKBINARY) && - check_binary_file ((unsigned char *)string, (result > 80) ? 80 : result)) + check_binary_file (string, (result > 80) ? 80 : result)) { free (string); (*errfunc) ("%s: cannot execute binary file", filename); @@ -207,7 +210,7 @@ file_error_and_exit: int maybe_execute_file (fname, force_noninteractive) - char *fname; + const char *fname; int force_noninteractive; { char *filename; @@ -225,20 +228,20 @@ maybe_execute_file (fname, force_noninteractive) #if defined (HISTORY) int fc_execute_file (filename) - char *filename; + const char *filename; { int flags; /* We want these commands to show up in the history list if remember_on_history is set. */ - flags = FEVAL_ENOENTOK|FEVAL_HISTORY; + flags = FEVAL_ENOENTOK|FEVAL_HISTORY|FEVAL_REGFILE; return (_evalfile (filename, flags)); } #endif /* HISTORY */ int source_file (filename) - char *filename; + const char *filename; { int flags; diff --git a/builtins/evalstring.c b/builtins/evalstring.c index 21e4772..b164e74 100644 --- a/builtins/evalstring.c +++ b/builtins/evalstring.c @@ -40,6 +40,7 @@ #include "../input.h" #include "../execute_cmd.h" #include "../redir.h" +#include "../trap.h" #if defined (HISTORY) # include "../bashhist.h" @@ -53,20 +54,15 @@ extern int errno; #define IS_BUILTIN(s) (builtin_address_internal(s, 0) != (struct builtin *)NULL) -extern void run_trap_cleanup (); -extern int zwrite (); - -extern int interactive, interactive_shell; extern int indirection_level, startup_state, subshell_environment; extern int line_number; extern int last_command_exit_value; extern int running_trap; extern int posixly_correct; -extern COMMAND *global_command; int parse_and_execute_level = 0; -static int cat_file (); +static int cat_file __P((REDIRECT *)); /* How to force parse_and_execute () to clean up after itself. */ void @@ -92,7 +88,7 @@ parse_and_execute_cleanup () int parse_and_execute (string, from_file, flags) char *string; - char *from_file; + const char *from_file; int flags; { int code, x; @@ -297,7 +293,8 @@ cat_file (r) REDIRECT *r; { char lbuf[128], *fn; - int nr, fd, rval; + int fd, rval; + ssize_t nr; if (r->instruction != r_input_direction) return -1; @@ -344,5 +341,5 @@ cat_file (r) free (fn); close (fd); - return (0); + return (rval); } diff --git a/builtins/exec.def b/builtins/exec.def index d578b63..c7137e3 100644 --- a/builtins/exec.def +++ b/builtins/exec.def @@ -66,7 +66,7 @@ $END extern int errno; #endif /* !errno */ -extern int interactive, interactive_shell, subshell_environment; +extern int subshell_environment; extern REDIRECT *redirection_undo_list; int no_exit_on_failed_exec; @@ -79,7 +79,7 @@ mkdashname (name) { char *ret; - ret = xmalloc (2 + strlen (name)); + ret = (char *)xmalloc (2 + strlen (name)); ret[0] = '-'; strcpy (ret + 1, name); return ret; diff --git a/builtins/exit.def b/builtins/exit.def index 5ebb877..54b6760 100644 --- a/builtins/exit.def +++ b/builtins/exit.def @@ -43,12 +43,12 @@ $END #include "common.h" #include "builtext.h" /* for jobs_builtin */ -extern int interactive, login_shell; extern int last_command_exit_value; -extern Function *this_shell_builtin; -extern Function *last_shell_builtin; +extern int subshell_environment; +extern sh_builtin_func_t *this_shell_builtin; +extern sh_builtin_func_t *last_shell_builtin; -static int exit_or_logout (); +static int exit_or_logout __P((WORD_LIST *)); static int sourced_logout; int @@ -119,10 +119,10 @@ exit_or_logout (list) /* Get return value if present. This means that you can type `logout 5' to a shell, and it returns 5. */ - exit_value = list ? get_numeric_arg (list, 1) : last_command_exit_value; + exit_value = list ? get_exitstat (list) : last_command_exit_value; /* Run our `~/.bash_logout' file if it exists, and this is a login shell. */ - if (login_shell && sourced_logout++ == 0) + if (login_shell && sourced_logout++ == 0 && subshell_environment == 0) { maybe_execute_file ("~/.bash_logout", 1); #ifdef SYS_BASH_LOGOUT diff --git a/builtins/fc.def b/builtins/fc.def index 60a940e..af99579 100644 --- a/builtins/fc.def +++ b/builtins/fc.def @@ -63,6 +63,7 @@ $END #endif #include <stdio.h> +#include <chartypes.h> #include "../bashansi.h" #include <errno.h> @@ -84,7 +85,7 @@ extern int echo_input_at_read; extern int current_command_line_count; extern int literal_history; -extern int unlink (); +extern int unlink __P((const char *)); extern FILE *sh_mktmpfp __P((char *, int, char **)); @@ -117,10 +118,6 @@ extern FILE *sh_mktmpfp __P((char *, int, char **)); Equivalent to !command:sg/pat/rep execpt there can be multiple PAT=REP's. */ -static char *fc_dosubs (), *fc_gethist (), *fc_readline (); -static int fc_gethnum (), fc_number (); -static void fc_replhist (), fc_addhist (); - /* Data structure describing a list of global replacements to perform. */ typedef struct repl { struct repl *next; @@ -146,6 +143,16 @@ typedef struct repl { } \ } while (0) +static char *fc_dosubs __P((char *, REPL *)); +static char *fc_gethist __P((char *, HIST_ENTRY **)); +static int fc_gethnum __P((char *, HIST_ENTRY **)); +static int fc_number __P((WORD_LIST *)); +static void fc_replhist __P((char *)); +#ifdef INCLUDE_UNUSED +static char *fc_readline __P((FILE *)); +static void fc_addhist __P((char *)); +#endif + /* String to execute on a file that we want to edit. */ #define FC_EDIT_COMMAND "${FCEDIT:-${EDITOR:-vi}}" @@ -159,7 +166,7 @@ fc_builtin (list) int histbeg, histend, last_hist, retval, opt; FILE *stream; REPL *rlist, *rl; - char *ename, *command, *newcom, *line; + char *ename, *command, *newcom; HIST_ENTRY **hlist; char *fn; @@ -445,7 +452,7 @@ fc_gethnum (command, hlist) s++; } - if (s && digit(*s)) + if (s && DIGIT(*s)) { n = atoi (s); n *= sign; @@ -494,6 +501,7 @@ fc_gethist (command, hlist) return ((char *)NULL); } +#ifdef INCLUDE_UNUSED /* Read the edited history lines from STREAM and return them one at a time. This can read unlimited length lines. The caller should free the storage. */ @@ -508,7 +516,7 @@ fc_readline (stream) while ((c = getc (stream)) != EOF) { if ((lindex + 2) >= line_len) - line = (char *) xrealloc (line, (line_len += 128)); + line = (char *)xrealloc (line, (line_len += 128)); if (c == '\n') { @@ -535,6 +543,7 @@ fc_readline (stream) line[lindex++] = '\0'; return (line); } +#endif /* Perform the SUBS on COMMAND. SUBS is a list of substitutions, and COMMAND is a simple string. @@ -604,6 +613,7 @@ fc_replhist (command) } } +#ifdef INCLUDE_UNUSED /* Add LINE to the history, after removing a single trailing newline. */ static void fc_addhist (line) @@ -619,4 +629,6 @@ fc_addhist (line) if (line && *line) maybe_add_history (line); } +#endif + #endif /* HISTORY */ diff --git a/builtins/fg_bg.def b/builtins/fg_bg.def index 0a694f3..9d379e8 100644 --- a/builtins/fg_bg.def +++ b/builtins/fg_bg.def @@ -46,7 +46,7 @@ $END #if defined (JOB_CONTROL) extern char *this_command_name; -static int fg_bg (); +static int fg_bg __P((WORD_LIST *, int)); /* How to bring a job into the foreground. */ int diff --git a/builtins/getopt.h b/builtins/getopt.h index 997bfd7..7a4afb1 100644 --- a/builtins/getopt.h +++ b/builtins/getopt.h @@ -20,6 +20,8 @@ #ifndef _SH_GETOPT_H #define _SH_GETOPT_H 1 +#include "stdc.h" + /* For communication from `getopt' to the caller. When `getopt' finds an option that takes an argument, the argument value is returned here. @@ -54,7 +56,7 @@ extern int sh_optopt; /* Set to 1 when an unrecognized option is encountered. */ extern int sh_badopt; -extern int sh_getopt (); -extern void sh_getopt_restore_state (); +extern int sh_getopt __P((int, char *const *, const char *)); +extern void sh_getopt_restore_state __P((char **)); #endif /* _SH_GETOPT_H */ diff --git a/builtins/getopts.def b/builtins/getopts.def index 6abd1e4..0e881d2 100644 --- a/builtins/getopts.def +++ b/builtins/getopts.def @@ -79,7 +79,6 @@ $END #define G_ARG_MISSING -3 extern char *this_command_name; -extern WORD_LIST *rest_of_args; /* getopts_reset is magic code for when OPTIND is reset. N is the value that has just been assigned to OPTIND. */ @@ -304,14 +303,10 @@ getopts_builtin (list) } reset_internal_getopt (); - while ((ret = internal_getopt (list, "")) != -1) + if (internal_getopt (list, "") != -1) { - switch (ret) - { - default: - builtin_usage (); - return (EX_USAGE); - } + builtin_usage (); + return (EX_USAGE); } list = loptend; diff --git a/builtins/hash.def b/builtins/hash.def index 7598d1b..35d5086 100644 --- a/builtins/hash.def +++ b/builtins/hash.def @@ -23,12 +23,15 @@ $PRODUCES hash.c $BUILTIN hash $FUNCTION hash_builtin -$SHORT_DOC hash [-r] [-p pathname] [name ...] +$SHORT_DOC hash [-r] [-p pathname] [-t] [name ...] For each NAME, the full pathname of the command is determined and remembered. If the -p option is supplied, PATHNAME is used as the full pathname of NAME, and no path search is performed. The -r -option causes the shell to forget all remembered locations. If no -arguments are given, information about remembered commands is displayed. +option causes the shell to forget all remembered locations. +If the -t option is supplied the full pathname to which each NAME +corresponds is printed. If multiple NAME arguments are supplied with +-t, the NAME is printed before the hashed full pathname. If no arguments +are given, information about remembered commands is displayed. $END #include <config.h> @@ -56,8 +59,9 @@ $END extern int dot_found_in_search; extern char *this_command_name; -static int add_hashed_command (); -static int print_hashed_commands (); +static int add_hashed_command __P((char *, int)); +static int print_hashed_commands __P((void)); +static int list_hashed_filename_targets __P((WORD_LIST *)); /* Print statistics on the current state of hashed commands. If LIST is not empty, then rehash (or hash in the first place) the specified @@ -66,7 +70,7 @@ int hash_builtin (list) WORD_LIST *list; { - int expunge_hash_table, opt; + int expunge_hash_table, list_targets, opt; char *w, *pathname; if (hashing_enabled == 0) @@ -75,10 +79,10 @@ hash_builtin (list) return (EXECUTION_FAILURE); } - expunge_hash_table = 0; + expunge_hash_table = list_targets = 0; pathname = (char *)NULL; reset_internal_getopt (); - while ((opt = internal_getopt (list, "rp:")) != -1) + while ((opt = internal_getopt (list, "rp:t")) != -1) { switch (opt) { @@ -88,6 +92,9 @@ hash_builtin (list) case 'p': pathname = list_optarg; break; + case 't': + list_targets = 1; + break; default: builtin_usage (); return (EX_USAGE); @@ -95,6 +102,13 @@ hash_builtin (list) } list = loptend; + /* hash -t requires at least one argument. */ + if (list == 0 && list_targets) + { + builtin_error("-t: argument required"); + return (EXECUTION_FAILURE); + } + /* We want hash -r to be silent, but hash -- to print hashing info. That is the reason for the test of expunge_hash_table. */ if (list == 0 && expunge_hash_table == 0) @@ -108,6 +122,12 @@ hash_builtin (list) if (expunge_hash_table) flush_hashed_filenames (); + /* If someone runs `hash -r -t xyz' he will be disappointed. */ + if (list_targets) + { + return (list_hashed_filename_targets (list)); + } + #if defined (RESTRICTED_SHELL) if (restricted && pathname && strchr (pathname, '/')) { @@ -198,3 +218,31 @@ print_hashed_commands () } return (any_printed); } + +static int +list_hashed_filename_targets (list) + WORD_LIST *list; +{ + int all_found, multiple; + char *target; + WORD_LIST *l; + + all_found = 1; + multiple = list->next != 0; + + for (l = list; l; l = l->next) + { + target = find_hashed_filename (l->word->word); + if (target == 0) + { + all_found = 0; + builtin_error ("%s: not found", l->word->word); + continue; + } + if (multiple) + printf ("%s\t", l->word->word); + printf ("%s\n", target); + } + + return (all_found ? EXECUTION_SUCCESS : EXECUTION_FAILURE); +} diff --git a/builtins/help.def b/builtins/help.def index 4382229..22181b1 100644 --- a/builtins/help.def +++ b/builtins/help.def @@ -47,15 +47,13 @@ $END #include "../shell.h" #include "../builtins.h" #include "../pathexp.h" +#include "common.h" #include "bashgetopt.h" -#include <glob/fnmatch.h> +#include <glob/strmatch.h> #include <glob/glob.h> -extern void builtin_error (); -extern void builtin_usage (); - -static void show_builtin_command_help (); +static void show_builtin_command_help __P((void)); /* Print out a list of the known functions in the shell, and what they do. If LIST is supplied, print out the list which matches for each pattern @@ -109,7 +107,7 @@ help_builtin (list) { QUIT; if ((strncmp (pattern, name, plen) == 0) || - (fnmatch (pattern, name, FNMATCH_EXTFLAG) != FNM_NOMATCH)) + (strmatch (pattern, name, FNMATCH_EXTFLAG) != FNM_NOMATCH)) { printf ("%s: %s\n", name, shell_builtins[i].short_doc); diff --git a/builtins/history.def b/builtins/history.def index 1ea3489..df416ae 100644 --- a/builtins/history.def +++ b/builtins/history.def @@ -70,10 +70,11 @@ $END extern int errno; #endif -static void display_history (); -static void push_history (); -static int expand_and_print_history (); -static int delete_histent (); +static void display_history __P((WORD_LIST *)); +static int delete_histent __P((int)); +static int delete_last_history __P((void)); +static void push_history __P((WORD_LIST *)); +static int expand_and_print_history __P((WORD_LIST *)); #define AFLAG 0x01 #define RFLAG 0x02 @@ -163,17 +164,14 @@ history_builtin (list) #endif else if (flags & DFLAG) { - if (legal_number (delete_arg, &delete_offset) == 0) + if ((legal_number (delete_arg, &delete_offset) == 0) + || (delete_offset < history_base) + || (delete_offset > (history_base + history_length))) { builtin_error ("%s: not a valid history position", delete_arg); return (EXECUTION_FAILURE); } opt = delete_offset; - if (opt < history_base || opt < 0 || opt > (history_base + history_length)) - { - builtin_error ("%d: not a valid history position", opt); - return (EXECUTION_FAILURE); - } result = delete_histent (opt - history_base); /* Since remove_history changes history_length, this can happen if we delete the last history entry. */ @@ -217,16 +215,17 @@ display_history (list) WORD_LIST *list; { register int i; - int limited, limit; + long limit; HIST_ENTRY **hlist; if (list) { - limited = 1; limit = get_numeric_arg (list, 0); + if (limit < 0) + limit = -limit; } else - limited = limit = 0; + limit = -1; hlist = history_list (); @@ -235,10 +234,9 @@ display_history (list) for (i = 0; hlist[i]; i++) ; - if (limit < 0) - limit = -limit; - - if ((limited == 0) || ((i -= limit) < 0)) + if (0 <= limit && limit < i) + i -= limit; + else i = 0; while (hlist[i]) diff --git a/builtins/jobs.def b/builtins/jobs.def index 3b573b5..f8a2b00 100644 --- a/builtins/jobs.def +++ b/builtins/jobs.def @@ -57,8 +57,7 @@ $END #define JSTATE_RUNNING 0x1 #define JSTATE_STOPPED 0x2 -extern int job_control, interactive_shell; -static int execute_list_with_replacements (); +static int execute_list_with_replacements __P((WORD_LIST *)); /* The `jobs' command. Prints outs a list of active jobs. If the argument `-l' is given, then the process id's are printed also. @@ -220,6 +219,7 @@ disown_builtin (list) { int opt, job, retval, nohup_only, running_jobs, all_jobs; sigset_t set, oset; + long pid_value; nohup_only = running_jobs = all_jobs = 0; reset_internal_getopt (); @@ -257,8 +257,8 @@ disown_builtin (list) do { BLOCK_CHILD (set, oset); - job = (list && all_digits(list->word->word)) - ? get_job_by_pid (atoi(list->word->word), 0) + job = (list && legal_number (list->word->word, &pid_value) && pid_value == (pid_t) pid_value) + ? get_job_by_pid ((pid_t) pid_value, 0) : get_job_spec (list); if (job == NO_JOB || jobs == 0 || job < 0 || job >= job_slots || jobs[job] == 0) diff --git a/builtins/kill.def b/builtins/kill.def index 4392717..d7aba5b 100644 --- a/builtins/kill.def +++ b/builtins/kill.def @@ -58,8 +58,6 @@ extern int errno; #endif /* !errno */ #if defined (JOB_CONTROL) -extern int interactive; -extern int job_control; extern int posixly_correct; #if !defined (CONTINUE_AFTER_KILL_ERROR) @@ -78,6 +76,7 @@ kill_builtin (list) int signal, any_succeeded, listing, saw_signal; char *sigspec, *word; pid_t pid; + long pid_value; if (list == 0) { @@ -164,10 +163,10 @@ kill_builtin (list) if (*word == '-') word++; - if (*word && all_digits (word)) + if (*word && legal_number (word, &pid_value) && (pid_value == (pid_t)pid_value)) { /* Use the entire argument in case of minus sign presence. */ - pid = (pid_t) atoi (list->word->word); + pid = (pid_t) pid_value; if (kill_pid (pid, signal, 0) < 0) goto signal_error; @@ -207,12 +206,10 @@ kill_builtin (list) if (kill_pid (pid, signal, 1) < 0) { signal_error: - if (errno == EPERM) - builtin_error ("(%d) - Not owner", (int)pid); - else if (errno == ESRCH) - builtin_error ("(%d) - No such pid", (int)pid); - else + if (errno == EINVAL) builtin_error ("Invalid signal %d", signal); + else + builtin_error ("(%ld) - %s", (long)pid, strerror (errno)); CONTINUE_OR_FAIL; } else diff --git a/builtins/let.def b/builtins/let.def index 1dbe0a8..1d8c25e 100644 --- a/builtins/let.def +++ b/builtins/let.def @@ -93,7 +93,7 @@ let_builtin (list) return (EXECUTION_FAILURE); } - return ((ret == 0L) ? EXECUTION_FAILURE : EXECUTION_SUCCESS); + return ((ret == 0) ? EXECUTION_FAILURE : EXECUTION_SUCCESS); } #ifdef INCLUDE_UNUSED @@ -113,6 +113,6 @@ exp_builtin (list) exp = string_list (list); ret = evalexp (exp, &expok); (void)free (exp); - return (((ret == 0L) || (expok == 0)) ? EXECUTION_FAILURE : EXECUTION_SUCCESS); + return (((ret == 0) || (expok == 0)) ? EXECUTION_FAILURE : EXECUTION_SUCCESS); } #endif diff --git a/builtins/mkbuiltins.c b/builtins/mkbuiltins.c index 139a46f..7532866 100644 --- a/builtins/mkbuiltins.c +++ b/builtins/mkbuiltins.c @@ -39,6 +39,8 @@ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #include "../bashansi.h" #include <stdio.h> +#include "stdc.h" + #define DOCFILE "builtins.texi" static char *xmalloc (), *xrealloc (); @@ -223,7 +225,7 @@ main (argc, argv) if (struct_filename) { temp_struct_filename = xmalloc (15); - sprintf (temp_struct_filename, "mk-%d", (int) getpid ()); + sprintf (temp_struct_filename, "mk-%ld", (long) getpid ()); structfile = fopen (temp_struct_filename, "w"); if (!structfile) @@ -378,17 +380,22 @@ array_free (array) /* The definition of a function. */ typedef int Function (); +typedef int mk_handler_func_t __P((char *, DEF_FILE *, char *)); /* Structure handles processor directives. */ typedef struct { char *directive; - Function *function; + mk_handler_func_t *function; } HANDLER_ENTRY; -extern int - builtin_handler (), function_handler (), short_doc_handler (), - comment_handler (), depends_on_handler (), produces_handler (), - end_handler (), docname_handler (); +extern int builtin_handler __P((char *, DEF_FILE *, char *)); +extern int function_handler __P((char *, DEF_FILE *, char *)); +extern int short_doc_handler __P((char *, DEF_FILE *, char *)); +extern int comment_handler __P((char *, DEF_FILE *, char *)); +extern int depends_on_handler __P((char *, DEF_FILE *, char *)); +extern int produces_handler __P((char *, DEF_FILE *, char *)); +extern int end_handler __P((char *, DEF_FILE *, char *)); +extern int docname_handler __P((char *, DEF_FILE *, char *)); HANDLER_ENTRY handlers[] = { { "BUILTIN", builtin_handler }, @@ -400,7 +407,7 @@ HANDLER_ENTRY handlers[] = { { "DEPENDS_ON", depends_on_handler }, { "PRODUCES", produces_handler }, { "END", end_handler }, - { (char *)NULL, (Function *)NULL } + { (char *)NULL, (mk_handler_func_t *)NULL } }; /* Return the entry in the table of handlers for NAME. */ @@ -724,8 +731,9 @@ add_documentation (defs, line) /* How to handle the $BUILTIN directive. */ int builtin_handler (self, defs, arg) - char *self, *arg; + char *self; DEF_FILE *defs; + char *arg; { BUILTIN_DESC *new; char *name; @@ -769,8 +777,9 @@ builtin_handler (self, defs, arg) /* How to handle the $FUNCTION directive. */ int function_handler (self, defs, arg) - char *self, *arg; + char *self; DEF_FILE *defs; + char *arg; { register BUILTIN_DESC *builtin; @@ -793,8 +802,9 @@ function_handler (self, defs, arg) /* How to handle the $DOCNAME directive. */ int docname_handler (self, defs, arg) - char *self, *arg; + char *self; DEF_FILE *defs; + char *arg; { register BUILTIN_DESC *builtin; @@ -812,8 +822,9 @@ docname_handler (self, defs, arg) /* How to handle the $SHORT_DOC directive. */ int short_doc_handler (self, defs, arg) - char *self, *arg; + char *self; DEF_FILE *defs; + char *arg; { register BUILTIN_DESC *builtin; @@ -830,9 +841,10 @@ short_doc_handler (self, defs, arg) /* How to handle the $COMMENT directive. */ int -comment_handler (self, defs) +comment_handler (self, defs, arg) char *self; DEF_FILE *defs; + char *arg; { return (0); } @@ -840,8 +852,9 @@ comment_handler (self, defs) /* How to handle the $DEPENDS_ON directive. */ int depends_on_handler (self, defs, arg) - char *self, *arg; + char *self; DEF_FILE *defs; + char *arg; { register BUILTIN_DESC *builtin; char *dependent; @@ -860,8 +873,9 @@ depends_on_handler (self, defs, arg) /* How to handle the $PRODUCES directive. */ int produces_handler (self, defs, arg) - char *self, *arg; + char *self; DEF_FILE *defs; + char *arg; { /* If just hacking documentation, don't change any of the production files. */ @@ -893,8 +907,9 @@ produces_handler (self, defs, arg) /* How to handle the $END directive. */ int end_handler (self, defs, arg) - char *self, *arg; + char *self; DEF_FILE *defs; + char *arg; { must_be_building (self, defs); building_builtin = 0; @@ -1056,7 +1071,7 @@ char *structfile_header[] = { "", " Functions which need to look at only the simple commands (e.g.", " the enable_builtin ()), should ignore entries where", - " (array[i].function == (Function *)NULL). Such entries are for", + " (array[i].function == (sh_builtin_func_t *)NULL). Such entries are for", " the list of shell reserved control structures, like `if' and `while'.", " The end of the list is denoted with a NULL name field. */", "", @@ -1065,7 +1080,7 @@ char *structfile_header[] = { }; char *structfile_footer[] = { - " { (char *)0x0, (Function *)0x0, 0, (char **)0x0, (char *)0x0 }", + " { (char *)0x0, (sh_builtin_func_t *)0x0, 0, (char **)0x0, (char *)0x0 }", "};", "", "struct builtin *shell_builtins = static_shell_builtins;", @@ -1147,7 +1162,7 @@ write_builtins (defs, structfile, externfile) if (externfile) { if (builtin->function) - fprintf (externfile, "extern int %s ();\n", + fprintf (externfile, "extern int %s __P((WORD_LIST *));\n", builtin->function); fprintf (externfile, "extern char *%s_doc[];\n", @@ -1162,7 +1177,7 @@ write_builtins (defs, structfile, externfile) if (builtin->function) fprintf (structfile, "%s, ", builtin->function); else - fprintf (structfile, "(Function *)0x0, "); + fprintf (structfile, "(sh_builtin_func_t *)0x0, "); fprintf (structfile, "%s%s%s, %s_doc,\n", "BUILTIN_ENABLED | STATIC_BUILTIN", diff --git a/builtins/printf.def b/builtins/printf.def index 1d40608..bcf625c 100644 --- a/builtins/printf.def +++ b/builtins/printf.def @@ -42,20 +42,33 @@ $END #if defined (HAVE_LIMITS_H) # include <limits.h> #else - /* Assume 32-bit ints and longs. */ -# define LONG_MAX 2147483647L -# define LONG_MIN (-2147483647L-1) + /* Assume 32-bit ints. */ # define INT_MAX 2147483647 # define INT_MIN (-2147483647-1) #endif #include <stdio.h> -#include <ctype.h> +#include <chartypes.h> + +#ifdef HAVE_INTTYPES_H +# include <inttypes.h> +#endif #include "../bashansi.h" + +#define NEED_STRTOIMAX_DECL + #include "../shell.h" #include "stdc.h" #include "bashgetopt.h" +#include "common.h" + +/* This should use the ISO C constant format strings; I'll do that later. */ +#if SIZEOF_LONG < SIZEOF_LONG_LONG +# define INTMAX_CONV "ll" +#else +# define INTMAX_CONV "l" +#endif #if !defined (errno) extern int errno; @@ -63,57 +76,78 @@ extern int errno; #define PF(f, func) \ do { \ - if (fieldwidth && precision) \ - (void)printf(f, fieldwidth, precision, func); \ - else if (fieldwidth && precision == 0) \ - (void)printf(f, fieldwidth, func); \ - else if (precision) \ - (void)printf(f, precision, func); \ + if (have_fieldwidth && have_precision) \ + tw += printf(f, fieldwidth, precision, func); \ + else if (have_fieldwidth) \ + tw += printf(f, fieldwidth, func); \ + else if (have_precision) \ + tw += printf(f, precision, func); \ else \ - (void)printf(f, func); \ + tw += printf(f, func); \ } while (0) +/* We free the buffer used by mklong() if it's `too big'. */ #define PRETURN(value) \ - do { /* free (format); */ fflush (stdout); return (value); } while (0) - -#define SKIP1 "#-+ 0" -#define SKIP2 "*0123456789" + do \ + { \ + if (conv_bufsize > 4096 ) \ + { \ + free(conv_buf); \ + conv_bufsize = 0; \ + conv_buf = 0; \ + } \ + fflush (stdout); \ + return (value); \ + } \ + while (0) + +#define SKIP1 "#'-+ 0" +#define LENMODS "hjlLtz" static void printstr __P((char *, char *, int, int, int)); static int tescape __P((char *, int, char *, int *)); static char *bexpand __P((char *, int, int *, int *)); -static char *mklong __P((char *, int)); +static char *mklong __P((char *, char *)); static int getchr __P((void)); static char *getstr __P((void)); static int getint __P((void)); -static int getlong __P((long *)); -static int getulong __P((unsigned long *)); -static int getdouble __P((double *)); +static long getlong __P((void)); +static unsigned long getulong __P((void)); +#if defined (HAVE_LONG_LONG) +static long long getllong __P((void)); +static unsigned long long getullong __P((void)); +#endif +static intmax_t getintmax __P((void)); +static uintmax_t getuintmax __P((void)); +static double getdouble __P((void)); +#if defined (HAVE_LONG_DOUBLE) && HAVE_DECL_STRTOLD +static long double getldouble __P((void)); +#endif static int asciicode __P((void)); static WORD_LIST *garglist; static int retval; +static int conversion_error; -extern char *sh_backslash_quote (); +static char *conv_buf; +static size_t conv_bufsize; int printf_builtin (list) WORD_LIST *list; { - int ch, end, fieldwidth, precision, foundmod, fmtlen; - char convch, nextch, *format, *fmt, *start; + int ch, fieldwidth, precision; + int have_fieldwidth, have_precision; + long tw; + char convch, thisch, nextch, *format, *modstart, *fmt, *start; + conversion_error = 0; retval = EXECUTION_SUCCESS; reset_internal_getopt (); - while ((ch = internal_getopt (list, "")) != -1) + if (internal_getopt (list, "") != -1) { - switch (ch) - { - case '?': - default: - builtin_usage(); - return (EX_USAGE); - } + builtin_usage(); + return (EX_USAGE); } list = loptend; @@ -140,18 +174,20 @@ printf_builtin (list) format strings are reused as necessary to use up the provided arguments, arguments of zero/null string are provided to use up the format string. */ - do { + tw = 0; /* find next format specification */ for (fmt = format; *fmt; fmt++) { - precision = fieldwidth = foundmod = 0; + precision = fieldwidth = 0; + have_fieldwidth = have_precision = 0; + if (*fmt == '\\') { fmt++; - /* A NULL third argument to tescape means to not do special + /* A NULL fourth argument to tescape means to not do special processing for \c. */ fmt += tescape (fmt, 1, &nextch, (int *)NULL); putchar (nextch); @@ -177,27 +213,37 @@ printf_builtin (list) /* found format specification, skip to field width */ for (; *fmt && strchr(SKIP1, *fmt); ++fmt) ; - fieldwidth = (*fmt == '*') ? getint () : 0; - /* skip to possible '.', get following precision */ - for (; *fmt && strchr(SKIP2, *fmt); ++fmt) - ; + /* Skip optional field width. */ + if (*fmt == '*') + { + fmt++; + have_fieldwidth = 1; + fieldwidth = getint (); + } + else + while (DIGIT (*fmt)) + fmt++; + + /* Skip optional '.' and precision */ if (*fmt == '.') { ++fmt; - precision = (*fmt == '*') ? getint () : 0; + if (*fmt == '*') + { + fmt++; + have_precision = 1; + precision = getint (); + } + else + while (DIGIT (*fmt)) + fmt++; } - /* skip to conversion char */ - for (; *fmt && strchr(SKIP2, *fmt); ++fmt) - ; - /* skip possible format modifiers */ - if (*fmt == 'l' || *fmt == 'L' || *fmt == 'h') - { - fmt++; - foundmod = 1; - } + modstart = fmt; + while (*fmt && strchr (LENMODS, *fmt)) + fmt++; if (*fmt == 0) { @@ -206,8 +252,11 @@ printf_builtin (list) } convch = *fmt; - nextch = fmt[1]; - fmt[1] = '\0'; + thisch = modstart[0]; + nextch = modstart[1]; + modstart[0] = convch; + modstart[1] = '\0'; + switch(convch) { case 'c': @@ -228,6 +277,24 @@ printf_builtin (list) break; } + case 'n': + { + char *var; + + var = getstr (); + if (var && *var) + { + if (legal_identifier (var)) + bind_var_to_int (var, tw); + else + { + builtin_error ("%s: invalid variable name", var); + PRETURN (EXECUTION_FAILURE); + } + } + break; + } + case 'b': /* expand escapes in argument */ { char *p, *xp; @@ -268,16 +335,34 @@ printf_builtin (list) case 'd': case 'i': { - long p; char *f; +#if defined (HAVE_LONG_LONG) + if (thisch == 'l' && nextch == 'l') + { + long long p; + + p = getllong (); + f = mklong (start, "ll"); + PF(f, p); + } + else +#endif + if (thisch == 'j') + { + intmax_t p; - if (foundmod == 0 && ((f = mklong (start, convch)) == NULL)) - PRETURN (EXECUTION_FAILURE); + p = getintmax (); + f = mklong (start, INTMAX_CONV); + PF(f, p); + } else - f = start; - if (getlong (&p)) - PRETURN (EXECUTION_FAILURE); - PF(f, p); + { + long p; + + p = getlong (); + f = mklong (start, "l"); + PF(f, p); + } break; } @@ -286,30 +371,67 @@ printf_builtin (list) case 'x': case 'X': { - unsigned long p; char *f; +#if defined (HAVE_LONG_LONG) + if (thisch == 'l' && nextch == 'l') + { + unsigned long long p; + + p = getullong (); + f = mklong (start, "ll"); + PF(f, p); + } + else +#endif + if (thisch == 'j') + { + uintmax_t p; - if (foundmod == 0 && ((f = mklong (start, convch)) == NULL)) - PRETURN (EXECUTION_FAILURE); + p = getuintmax (); + f = mklong (start, INTMAX_CONV); + PF(f, p); + } else - f = start; - if (getulong (&p)) - PRETURN (EXECUTION_FAILURE); - PF (f, p); + { + unsigned long p; + + p = getulong (); + f = mklong (start, "l"); + PF (f, p); + } break; } case 'e': case 'E': case 'f': + case 'F': case 'g': case 'G': +#if defined (HAVE_PRINTF_A_FORMAT) + case 'a': + case 'A': +#endif { - double p; + char *f; +#if defined (HAVE_LONG_DOUBLE) && HAVE_DECL_STRTOLD + if (thisch == 'L') + { + long double p; - if (getdouble (&p)) - PRETURN (EXECUTION_FAILURE); - PF(start, p); + p = getldouble (); + f = mklong (start, "L"); + PF (f, p); + } + else +#endif + { + double p; + + p = getdouble (); + f = mklong (start, ""); + PF (f, p); + } break; } @@ -320,11 +442,15 @@ printf_builtin (list) PRETURN (EXECUTION_FAILURE); } - fmt[1] = nextch; + modstart[0] = thisch; + modstart[1] = nextch; } } while (garglist && garglist != list->next); + if (conversion_error) + retval = EXECUTION_FAILURE; + PRETURN (retval); } @@ -352,10 +478,11 @@ printstr (fmt, string, len, fieldwidth, precision) if (*fmt == '%') fmt++; - ljust = fw = pr = 0; + ljust = fw = 0; + pr = -1; /* skip flags */ - while (*fmt == '#' || *fmt == '-' || *fmt == '+' || *fmt == ' ' || *fmt == '0') + while (strchr (SKIP1, *fmt)) { if (*fmt == '-') ljust = 1; @@ -367,11 +494,16 @@ printstr (fmt, string, len, fieldwidth, precision) { fmt++; fw = fieldwidth; + if (fw < 0) + { + fw = -fw; + ljust = 1; + } } - else if (isdigit (*fmt)) + else if (DIGIT (*fmt)) { fw = *fmt++ - '0'; - while (isdigit (*fmt)) + while (DIGIT (*fmt)) fw = (fw * 10) + (*fmt++ - '0'); } @@ -384,10 +516,10 @@ printstr (fmt, string, len, fieldwidth, precision) fmt++; pr = precision; } - else if (isdigit (*fmt)) + else if (DIGIT (*fmt)) { pr = *fmt++ - '0'; - while (isdigit (*fmt)) + while (DIGIT (*fmt)) pr = (pr * 10) + (*fmt++ - '0'); } } @@ -402,7 +534,7 @@ printstr (fmt, string, len, fieldwidth, precision) #endif /* chars from string to print */ - nc = (pr > 0 && pr <= len) ? pr : len; + nc = (pr >= 0 && pr <= len) ? pr : len; padlen = fw - nc; if (padlen < 0) @@ -428,21 +560,6 @@ printstr (fmt, string, len, fieldwidth, precision) 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. */ -#ifdef isoctal -#undef isoctal -#endif - -#define isoctal(c) ((c) >= '0' && (c) <= '7') - -#define OCTVALUE(c) ((c) - '0') - -#ifndef isxdigit -# define isxdigit(c) (isdigit((c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) -#endif - -#define HEXVALUE(c) \ - ((c) >= 'a' && (c) <= 'f' ? (c)-'a'+10 : (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0') - /* Translate a single backslash-escape sequence starting at ESTART (the character after the backslash) and return the number of characters consumed by the sequence. CP is the place to return the translated @@ -488,32 +605,32 @@ tescape (estart, trans_squote, cp, sawc) /* %b octal constants are `\0' followed by one, two, or three octal digits... */ case '0': - for (temp = 3, evalue = 0; isoctal (*p) && temp--; p++) + for (temp = 3, evalue = 0; ISOCTAL (*p) && temp--; p++) evalue = (evalue * 8) + OCTVALUE (*p); - *cp = evalue; + *cp = evalue & 0xFF; break; /* but, as an extension, the other echo-like octal escape sequences are supported as well. */ case '1': case '2': case '3': case '4': case '5': case '6': case '7': - for (temp = 2, evalue = c - '0'; isoctal (*p) && temp--; p++) + for (temp = 2, evalue = c - '0'; ISOCTAL (*p) && temp--; p++) evalue = (evalue * 8) + OCTVALUE (*p); - *cp = evalue; + *cp = evalue & 0xFF; break; /* And, as another extension, we allow \xNNN, where each N is a hex digit. */ case 'x': - for (temp = 3, evalue = 0; isxdigit (*p) && temp--; p++) + for (temp = 2, evalue = 0; ISXDIGIT ((unsigned char)*p) && temp--; p++) evalue = (evalue * 16) + HEXVALUE (*p); - if (temp == 3) + if (temp == 2) { builtin_error ("missing hex digit for \\x"); *cp = '\\'; return 0; } - *cp = evalue; + *cp = evalue & 0xFF; break; case '\\': /* \\ -> \ */ @@ -561,7 +678,7 @@ bexpand (string, len, sawc, lenp) return ((char *)NULL); } - ret = xmalloc (len + 1); + ret = (char *)xmalloc (len + 1); for (r = ret, s = string; s && *s; ) { c = *s++; @@ -589,19 +706,28 @@ bexpand (string, len, sawc, lenp) } static char * -mklong (str, ch) +mklong (str, modifiers) char *str; - int ch; + char *modifiers; { - static char copy[64]; - int len; - - len = strlen (str) + 2; - FASTCOPY (str, copy, len - 3); - copy[len - 3] = 'l'; - copy[len - 2] = ch; - copy[len - 1] = '\0'; - return (copy); + size_t len, slen, mlen; + + slen = strlen (str); + mlen = strlen (modifiers); + len = slen + mlen + 1; + + if (len > conv_bufsize) + { + conv_bufsize = (((len + 1023) >> 10) << 10); + conv_buf = (char *)xrealloc (conv_buf, conv_bufsize); + } + + FASTCOPY (str, conv_buf, slen - 1); + FASTCOPY (modifiers, conv_buf + slen - 1, mlen); + + conv_buf[len - 2] = str[slen - 1]; + conv_buf[len - 1] = '\0'; + return (conv_buf); } static int @@ -635,8 +761,7 @@ getint () { long ret; - if (getlong (&ret)) - return (0); + ret = getlong (); if (ret > INT_MAX) { @@ -652,112 +777,255 @@ getint () return ((int)ret); } -static int -getlong (lp) - long *lp; +static long +getlong () { long ret; char *ep; if (garglist == 0) - { - *lp = 0L; - return (0); - } + return (0); if (garglist->word->word[0] == '\'' || garglist->word->word[0] == '"') - { - *lp = (long)asciicode (); - return (0); - } + return asciicode (); errno = 0; - /* If we use 0 as the third argument, we can handle octal and hex, which - legal_number does not. (This was - if (legal_number (garglist->word->word, &ret) == 0) - ) */ ret = strtol (garglist->word->word, &ep, 0); - if (*ep != '\0') + + if (*ep) { builtin_error ("%s: invalid number", garglist->word->word); - return (1); + /* POSIX.2 says ``...a diagnostic message shall be written to standard + error, and the utility shall not exit with a zero exit status, but + shall continue processing any remaining operands and shall write the + value accumulated at the time the error was detected to standard + output.'' Yecch. */ + ret = 0; + conversion_error = 1; } else if (errno == ERANGE) builtin_error ("warning: %s: %s", garglist->word->word, strerror(ERANGE)); - *lp = ret; garglist = garglist->next; - return (0); + return (ret); } -static int -getulong (ulp) - unsigned long *ulp; +static unsigned long +getulong () { unsigned long ret; char *ep; if (garglist == 0) + return (0); + + if (garglist->word->word[0] == '\'' || garglist->word->word[0] == '"') + return asciicode (); + + errno = 0; + ret = strtoul (garglist->word->word, &ep, 0); + + if (*ep) { - *ulp = (unsigned long)0; - return (0); + builtin_error ("%s: invalid number", garglist->word->word); + /* Same thing about POSIX.2 conversion error requirements as getlong(). */ + ret = 0; + conversion_error = 1; } + else if (errno == ERANGE) + builtin_error ("warning: %s: %s", garglist->word->word, strerror(ERANGE)); + + garglist = garglist->next; + return (ret); +} + +#if defined (HAVE_LONG_LONG) + +static long long +getllong () +{ + long long ret; + char *ep; + + if (garglist == 0) + return (0); if (garglist->word->word[0] == '\'' || garglist->word->word[0] == '"') + return asciicode (); + + errno = 0; + ret = strtoll (garglist->word->word, &ep, 0); + + if (*ep) { - *ulp = (unsigned long)asciicode (); - return (0); + builtin_error ("%s: invalid number", garglist->word->word); + /* POSIX.2 says ``...a diagnostic message shall be written to standard + error, and the utility shall not exit with a zero exit status, but + shall continue processing any remaining operands and shall write the + value accumulated at the time the error was detected to standard + output.'' Yecch. */ + ret = 0; + conversion_error = 1; } + else if (errno == ERANGE) + builtin_error ("warning: %s: %s", garglist->word->word, strerror(ERANGE)); + + garglist = garglist->next; + return (ret); +} + +static unsigned long long +getullong () +{ + unsigned long long ret; + char *ep; + + if (garglist == 0) + return (0); + + if (garglist->word->word[0] == '\'' || garglist->word->word[0] == '"') + return asciicode (); errno = 0; - ret = strtoul (garglist->word->word, &ep, 0); + ret = strtoull (garglist->word->word, &ep, 0); if (*ep) { builtin_error ("%s: invalid number", garglist->word->word); - return (1); + /* Same thing about POSIX.2 conversion error requirements as getlong(). */ + ret = 0; + conversion_error = 1; } else if (errno == ERANGE) builtin_error ("warning: %s: %s", garglist->word->word, strerror(ERANGE)); - *ulp = ret; garglist = garglist->next; - return (0); + return (ret); } -static int -getdouble (dp) - double *dp; +#endif /* HAVE_LONG_LONG */ + +static intmax_t +getintmax () { - double ret; + intmax_t ret; char *ep; if (garglist == 0) + return (0); + + if (garglist->word->word[0] == '\'' || garglist->word->word[0] == '"') + return asciicode (); + + errno = 0; + ret = strtoimax (garglist->word->word, &ep, 0); + + if (*ep) { - *dp = (double)0; - return (0); + builtin_error ("%s: invalid number", garglist->word->word); + /* POSIX.2 says ``...a diagnostic message shall be written to standard + error, and the utility shall not exit with a zero exit status, but + shall continue processing any remaining operands and shall write the + value accumulated at the time the error was detected to standard + output.'' Yecch. */ + ret = 0; + conversion_error = 1; } + else if (errno == ERANGE) + builtin_error ("warning: %s: %s", garglist->word->word, strerror(ERANGE)); + + garglist = garglist->next; + return (ret); +} + +static uintmax_t +getuintmax () +{ + uintmax_t ret; + char *ep; + + if (garglist == 0) + return (0); if (garglist->word->word[0] == '\'' || garglist->word->word[0] == '"') + return asciicode (); + + errno = 0; + ret = strtoumax (garglist->word->word, &ep, 0); + + if (*ep) { - *dp = (double)asciicode (); - return (0); + builtin_error ("%s: invalid number", garglist->word->word); + /* Same thing about POSIX.2 conversion error requirements as getlong(). */ + ret = 0; + conversion_error = 1; } + else if (errno == ERANGE) + builtin_error ("warning: %s: %s", garglist->word->word, strerror(ERANGE)); + + garglist = garglist->next; + return (ret); +} + +static double +getdouble () +{ + double ret; + char *ep; + + if (garglist == 0) + return (0); + + if (garglist->word->word[0] == '\'' || garglist->word->word[0] == '"') + return asciicode (); errno = 0; ret = strtod (garglist->word->word, &ep); + + if (*ep) + { + builtin_error ("%s: invalid number", garglist->word->word); + /* Same thing about POSIX.2 conversion error requirements. */ + ret = 0; + conversion_error = 1; + } + else if (errno == ERANGE) + builtin_error ("warning: %s: %s", garglist->word->word, strerror(ERANGE)); + + garglist = garglist->next; + return (ret); +} + +#if defined (HAVE_LONG_DOUBLE) && HAVE_DECL_STRTOLD +static long double +getldouble () +{ + long double ret; + char *ep; + + if (garglist == 0) + return (0); + + if (garglist->word->word[0] == '\'' || garglist->word->word[0] == '"') + return (asciicode ()); + + errno = 0; + ret = strtold (garglist->word->word, &ep); + if (*ep) { builtin_error ("%s: invalid number", garglist->word->word); - return (1); + /* Same thing about POSIX.2 conversion error requirements. */ + ret = 0; + conversion_error = 1; } else if (errno == ERANGE) builtin_error ("warning: %s: %s", garglist->word->word, strerror(ERANGE)); - *dp = ret; garglist = garglist->next; - return (0); + return (ret); } +#endif /* HAVE_LONG_DOUBLE && HAVE_DECL_STRTOLD */ /* NO check is needed for garglist here. */ static int diff --git a/builtins/psize.sh b/builtins/psize.sh index 2c874f5..c4d73e1 100755..100644 --- a/builtins/psize.sh +++ b/builtins/psize.sh @@ -4,10 +4,18 @@ # pipesize.h so ulimit.c can use it. : ${TMPDIR:=/tmp} -TMPNAME=pipsize.$$ -TMPFILE=$TMPDIR/$TMPNAME +# try to use mktemp(1) if the system supports it +{ TMPFILE="`mktemp $TMPDIR/pipsize.XXXXXX 2>/dev/null`"; } 2>/dev/null +used_mktemp=true -trap 'rm -f $TMPFILE' 0 1 2 3 6 15 +if [ -z "$TMPFILE" ]; then + TMPNAME=pipsize.$$ + TMPFILE=$TMPDIR/$TMPNAME + used_mktemp=false +fi + +trap 'rm -f "$TMPFILE" ; exit 1' 1 2 3 6 15 +trap 'rm -f "$TMPFILE"' 0 echo "/*" echo " * pipesize.h" @@ -21,14 +29,15 @@ echo "" # Try to avoid tempfile races. We can't really check for the file's # existance before we run psize.aux, because `test -e' is not portable, # `test -h' (test for symlinks) is not portable, and `test -f' only -# checks for regular files +# checks for regular files. If we used mktemp(1), we're ahead of the +# game. # -rm -f $TMPFILE +$used_mktemp || rm -f "$TMPFILE" -./psize.aux 2>$TMPFILE | sleep 3 +./psize.aux 2>"$TMPFILE" | sleep 3 -if [ -s $TMPFILE ]; then - echo "#define PIPESIZE `cat $TMPFILE`" +if [ -s "$TMPFILE" ]; then + echo "#define PIPESIZE `cat "$TMPFILE"`" else echo "#define PIPESIZE 512" fi diff --git a/builtins/pushd.def b/builtins/pushd.def index 83f7e9b..f47b294 100644 --- a/builtins/pushd.def +++ b/builtins/pushd.def @@ -136,12 +136,12 @@ static int directory_list_size; /* Offset to the end of the list. */ static int directory_list_offset; -static void pushd_error (); -static void clear_directory_stack (); -static int cd_to_string (); -static int change_to_temp (); -static int get_dirstack_index (); -static void add_dirstack_element (); +static void pushd_error __P((int, char *)); +static void clear_directory_stack __P((void)); +static int cd_to_string __P((char *)); +static int change_to_temp __P((char *)); +static void add_dirstack_element __P((char *)); +static int get_dirstack_index __P((long, int, int *)); #define NOCD 0x01 #define ROTATE 0x02 @@ -293,7 +293,7 @@ popd_builtin (list) char *which_word; which_word = (char *)NULL; - for (flags = 0, which = 0L, direction = '+'; list; list = list->next) + for (flags = 0, which = 0, direction = '+'; list; list = list->next) { if (ISOPTION (list->word->word, 'n')) { @@ -537,7 +537,8 @@ add_dirstack_element (dir) static int get_dirstack_index (ind, sign, indexp) - int ind, sign, *indexp; + long ind; + int sign, *indexp; { if (indexp) *indexp = sign > 0 ? 1 : 2; @@ -552,8 +553,10 @@ get_dirstack_index (ind, sign, indexp) *indexp = sign > 0 ? 2 : 1; return 0; } - else + else if (ind >= 0 && ind <= directory_list_offset) return (sign > 0 ? directory_list_offset - ind : ind); + else + return -1; } /* Used by the tilde expansion code. */ @@ -586,7 +589,8 @@ get_dirstack_from_string (string) #ifdef INCLUDE_UNUSED char * get_dirstack_element (ind, sign) - int ind, sign; + long ind; + int sign; { int i; @@ -598,7 +602,8 @@ get_dirstack_element (ind, sign) void set_dirstack_element (ind, sign, value) - int ind, sign; + long ind; + int sign; char *value; { int i; diff --git a/builtins/read.def b/builtins/read.def index d63f27a..a9d4a40 100644 --- a/builtins/read.def +++ b/builtins/read.def @@ -83,15 +83,18 @@ extern int errno; extern int interrupt_immediately; #if defined (READLINE) -static char *edit_line (); -static void set_eol_delim (); -static void reset_eol_delim (); +static char *edit_line __P((char *)); +static void set_eol_delim __P((int)); +static void reset_eol_delim __P((char *)); #endif -static SHELL_VAR *bind_read_variable (); +static SHELL_VAR *bind_read_variable __P((char *, char *)); + +static sighandler sigalrm __P((int)); +static void reset_alarm __P((void)); static procenv_t alrmbuf; static SigHandler *old_alrm; -static int delim; +static unsigned char delim; static sighandler sigalrm (s) @@ -120,7 +123,8 @@ read_builtin (list) register char *varname; int size, i, pass_next, saw_escape, eof, opt, retval, code; int input_is_tty, input_is_pipe, unbuffered_read; - int raw, edit, tmout, nchars, silent; + int raw, edit, nchars, silent, have_timeout; + unsigned int tmout; long timeoutval, ncharsval; char c; char *input_string, *orig_input_string, *ifs_chars, *prompt, *arrayname; @@ -135,6 +139,25 @@ read_builtin (list) int rlind; #endif + USE_VAR(size); + USE_VAR(i); + USE_VAR(pass_next); + USE_VAR(saw_escape); + USE_VAR(input_is_pipe); +/* USE_VAR(raw); */ + USE_VAR(edit); + USE_VAR(tmout); + USE_VAR(nchars); + USE_VAR(silent); + USE_VAR(ifs_chars); + USE_VAR(prompt); + USE_VAR(arrayname); +#if defined (READLINE) + USE_VAR(rlbuf); + USE_VAR(rlind); +#endif + USE_VAR(list); + i = 0; /* Index into the string that we are reading. */ raw = edit = 0; /* Not reading raw input by default. */ silent = 0; @@ -145,8 +168,8 @@ read_builtin (list) rlind = 0; #endif - tmout = -1; /* no timeout */ - nchars = input_is_tty = input_is_pipe = unbuffered_read = 0; + tmout = 0; /* no timeout */ + nchars = input_is_tty = input_is_pipe = unbuffered_read = have_timeout = 0; delim = '\n'; /* read until newline */ reset_internal_getopt (); @@ -175,17 +198,20 @@ read_builtin (list) #endif case 't': code = legal_number (list_optarg, &timeoutval); - if (code == 0 || timeoutval < 0) + if (code == 0 || timeoutval < 0 || timeoutval != (unsigned int)timeoutval) { builtin_error ("%s: invalid timeout specification", list_optarg); return (EXECUTION_FAILURE); } else - tmout = timeoutval; + { + have_timeout = 1; + tmout = timeoutval; + } break; case 'n': code = legal_number (list_optarg, &ncharsval); - if (code == 0 || ncharsval < 0) + if (code == 0 || ncharsval < 0 || ncharsval != (int)ncharsval) { builtin_error ("%s: invalid number specification", list_optarg); return (EXECUTION_FAILURE); @@ -204,7 +230,7 @@ read_builtin (list) list = loptend; /* `read -t 0 var' returns failure immediately. */ - if (tmout == 0) + if (have_timeout && tmout == 0) return (EXECUTION_FAILURE); /* IF IFS is unset, we use the default of " \t\n". */ @@ -213,7 +239,7 @@ read_builtin (list) if (ifs_chars == 0) /* XXX */ ifs_chars = ""; /* XXX */ - input_string = xmalloc (size = 128); + input_string = (char *)xmalloc (size = 128); begin_unwind_frame ("read_builtin"); #if defined (READLINE) @@ -250,7 +276,7 @@ read_builtin (list) /* Turn off the timeout if stdin is a regular file (e.g. from input redirection). */ if ((fstat (0, &tsb) < 0) || S_ISREG (tsb.st_mode)) - tmout = -1; + tmout = 0; } if (tmout > 0) @@ -358,7 +384,7 @@ read_builtin (list) if (i + 2 >= size) { - input_string = xrealloc (input_string, size += 128); + input_string = (char *)xrealloc (input_string, size += 128); remove_unwind_protect (); add_unwind_protect (xfree, input_string); } @@ -383,7 +409,7 @@ read_builtin (list) continue; } - if (c == delim) + if ((unsigned char)c == delim) break; if (c == CTLESC || c == CTLNUL) @@ -410,7 +436,7 @@ read_builtin (list) if (nchars > 0) rl_num_chars_to_read = 0; if (delim != '\n') - reset_eol_delim (); + reset_eol_delim ((char *)NULL); } else #endif @@ -433,12 +459,9 @@ read_builtin (list) an assign them to `arrayname' in turn. */ if (arrayname) { - var = find_variable (arrayname); + var = find_or_make_array_variable (arrayname, 1); if (var == 0) - var = make_new_array_variable (arrayname); - else if (array_p (var) == 0) - var = convert_var_to_array (var); - + return EXECUTION_FAILURE; /* readonly or noassign */ empty_array (array_cell (var)); alist = list_string (input_string, ifs_chars, 0); @@ -504,7 +527,7 @@ read_builtin (list) #endif { builtin_error ("`%s': not a valid identifier", varname); - free (orig_input_string); + xfree (orig_input_string); return (EXECUTION_FAILURE); } @@ -522,7 +545,7 @@ read_builtin (list) { t1 = dequote_string (t); var = bind_read_variable (varname, t1); - free (t1); + xfree (t1); } else var = bind_read_variable (varname, t); @@ -536,7 +559,7 @@ read_builtin (list) FREE (t); if (var == 0) { - free (orig_input_string); + xfree (orig_input_string); return (EXECUTION_FAILURE); } @@ -552,7 +575,7 @@ read_builtin (list) #endif { builtin_error ("`%s': not a valid identifier", list->word->word); - free (orig_input_string); + xfree (orig_input_string); return (EXECUTION_FAILURE); } @@ -565,14 +588,14 @@ read_builtin (list) { t = dequote_string (input_string); var = bind_read_variable (list->word->word, t); - free (t); + xfree (t); } else var = bind_read_variable (list->word->word, input_string); stupidly_hack_special_variables (list->word->word); if (var) VUNSETATTR (var, att_invisible); - free (orig_input_string); + xfree (orig_input_string); return (retval); } @@ -583,21 +606,12 @@ bind_read_variable (name, value) { #if defined (ARRAY_VARS) if (valid_array_reference (name) == 0) - { -#if 0 - if (legal_identifier (name) == 0) - { - builtin_error ("`%s': not a valid identifier", name); - return ((SHELL_VAR *)NULL); - } -#endif - return (bind_variable (name, value)); - } + return (bind_variable (name, value)); else - return (do_array_element_assignment (name, value)); -#else + return (assign_array_element (name, value)); +#else /* !ARRAY_VARS */ return bind_variable (name, value); -#endif +#endif /* !ARRAY_VARS */ } #if defined (READLINE) @@ -614,18 +628,18 @@ edit_line (p) if (ret == 0) return ret; len = strlen (ret); - ret = xrealloc (ret, len + 2); + ret = (char *)xrealloc (ret, len + 2); ret[len++] = delim; ret[len] = '\0'; return ret; } static int old_delim_ctype; -static Function *old_delim_func; +static rl_command_func_t *old_delim_func; static int old_newline_ctype; -static Function *old_newline_func; +static rl_command_func_t *old_newline_func; -static int delim_char; +static unsigned char delim_char; static void set_eol_delim (c) @@ -653,8 +667,8 @@ set_eol_delim (c) } static void -reset_eol_delim (c) - int c; +reset_eol_delim (cp) + char *cp; { Keymap cmap; diff --git a/builtins/reserved.def b/builtins/reserved.def index cf970e9..2897900 100644 --- a/builtins/reserved.def +++ b/builtins/reserved.def @@ -159,6 +159,6 @@ histchars Characters controlling history expansion and quick third is the `history comment' character, usually `#'. # endif /* BANG_HISTORY */ HISTIGNORE A colon-separated list of patterns used to decide which - command should be saved on the history list. + commands should be saved on the history list. #endif /* HISTORY */ $END diff --git a/builtins/return.def b/builtins/return.def index 9f9b528..529e04c 100644 --- a/builtins/return.def +++ b/builtins/return.def @@ -52,7 +52,7 @@ int return_builtin (list) WORD_LIST *list; { - return_catch_value = list ? get_numeric_arg (list, 1) : last_command_exit_value; + return_catch_value = list ? get_exitstat (list) : last_command_exit_value; if (return_catch_flag) longjmp (return_catch, 1); diff --git a/builtins/set.def b/builtins/set.def index 700b518..8f96017 100644 --- a/builtins/set.def +++ b/builtins/set.def @@ -49,8 +49,10 @@ $PRODUCES set.c # include "../bashhist.h" #endif -extern int interactive; extern int noclobber, posixly_correct, ignoreeof, eof_encountered_limit; +#if defined (HISTORY) +extern int dont_save_function_defs; +#endif #if defined (READLINE) extern int no_line_editing; #endif /* READLINE */ @@ -92,6 +94,7 @@ $SHORT_DOC set [--abefhkmnptuvxBCHP] [-o option] [arg ...] noclobber same as -C noexec same as -n noglob same as -f + nolog currently accepted but ignored notify same as -b nounset same as -u onecmd same as -t @@ -132,16 +135,19 @@ parameters and are assigned, in order, to $1, $2, .. $n. If no ARGs are given, all shell variables are printed. $END -static int set_ignoreeof (); -static int set_posix_mode (); +static void print_minus_o_option __P((char *, int, int)); +static void print_all_shell_variables __P((void)); + +static int set_ignoreeof __P((int, char *)); +static int set_posix_mode __P((int, char *)); #if defined (READLINE) -static int set_edit_mode (); -static int get_edit_mode (); +static int set_edit_mode __P((int, char *)); +static int get_edit_mode __P((char *)); #endif #if defined (HISTORY) -static int bash_set_history (); +static int bash_set_history __P((int, char *)); #endif static char *on = "on"; @@ -179,23 +185,29 @@ struct { {(char *)NULL, 0 }, }; +typedef int setopt_set_func_t __P((int, char *)); +typedef int setopt_get_func_t __P((char *)); + struct { char *name; int *variable; - Function *set_func; - Function *get_func; + setopt_set_func_t *set_func; + setopt_get_func_t *get_func; } binary_o_options[] = { #if defined (HISTORY) - { "history", &remember_on_history, bash_set_history, (Function *)NULL }, + { "history", &remember_on_history, bash_set_history, (setopt_get_func_t *)NULL }, +#endif + { "ignoreeof", &ignoreeof, set_ignoreeof, (setopt_get_func_t *)NULL }, + { "interactive-comments", &interactive_comments, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL }, +#if defined (HISTORY) + { "nolog", &dont_save_function_defs, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL }, #endif - { "ignoreeof", &ignoreeof, set_ignoreeof, (Function *)NULL }, - { "interactive-comments", &interactive_comments, (Function *)NULL, (Function *)NULL }, - { "posix", &posixly_correct, set_posix_mode, (Function *)NULL }, + { "posix", &posixly_correct, set_posix_mode, (setopt_get_func_t *)NULL }, #if defined (READLINE) { "emacs", (int *)NULL, set_edit_mode, get_edit_mode }, { "vi", (int *)NULL, set_edit_mode, get_edit_mode }, #endif - { (char *)NULL, (int *)NULL } + { (char *)NULL, (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL } }; #define GET_BINARY_O_OPTION_VALUE(i, name) \ @@ -375,7 +387,6 @@ set_minus_o_option (on_or_off, option_name) char *option_name; { int option_char; - VFunction *set_func; register int i; for (i = 0; binary_o_options[i].name; i++) @@ -387,7 +398,7 @@ set_minus_o_option (on_or_off, option_name) } } - for (i = 0, option_char = -1, set_func = 0; o_options[i].name; i++) + for (i = 0, option_char = -1; o_options[i].name; i++) { if (STREQ (option_name, o_options[i].name)) { @@ -450,7 +461,7 @@ set_shellopts () if (GET_BINARY_O_OPTION_VALUE (i, binary_o_options[i].name)) vsize += strlen (binary_o_options[i].name) + 1; - value = xmalloc (vsize + 1); + value = (char *)xmalloc (vsize + 1); for (i = vptr = 0; o_options[i].name; i++) { @@ -752,6 +763,7 @@ unset_builtin (list) name = list->word->word; #if defined (ARRAY_VARS) + unset_array = 0; if (!unset_function && valid_array_reference (name)) { t = strchr (name, '['); diff --git a/builtins/setattr.def b/builtins/setattr.def index 2e3ad84..dad11fd 100644 --- a/builtins/setattr.def +++ b/builtins/setattr.def @@ -40,7 +40,7 @@ $PRODUCES setattr.c extern int posixly_correct; extern int array_needs_making; extern char *this_command_name; -extern Function *this_shell_builtin; +extern sh_builtin_func_t *this_shell_builtin; #ifdef ARRAY_VARS extern int declare_builtin (); @@ -248,7 +248,11 @@ set_or_show_attributes (list, attribute, nodefs) if (arrays_only && array_p (var) == 0) continue; #endif +#if 0 if ((var->attributes & attribute) && invisible_p (var) == 0) +#else + if ((var->attributes & attribute)) +#endif show_var_attributes (var, READONLY_OR_EXPORT, nodefs); } free (variable_list); @@ -327,6 +331,8 @@ show_var_attributes (var, pattr, nodefs) printf ("%s\n", var->name); else if (function_p (var)) printf ("%s\n", named_function_string (var->name, function_cell (var), 1)); + else if (invisible_p (var)) + printf ("%s\n", var->name); else { x = sh_double_quote (value_cell (var) ? value_cell (var) : ""); @@ -342,7 +348,6 @@ show_name_attributes (name, nodefs) int nodefs; { SHELL_VAR *var; - int ret; var = find_tempenv_variable (name); if (var == 0) diff --git a/builtins/shift.def b/builtins/shift.def index e028d36..6db7c7f 100644 --- a/builtins/shift.def +++ b/builtins/shift.def @@ -52,7 +52,7 @@ int shift_builtin (list) WORD_LIST *list; { - int times; + long times; register int count; WORD_LIST *temp; diff --git a/builtins/shopt.def b/builtins/shopt.def index 138b88d..8de2aad 100644 --- a/builtins/shopt.def +++ b/builtins/shopt.def @@ -78,7 +78,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 void enable_hostname_completion (); +extern int enable_hostname_completion __P((int)); #endif #if defined (PROGRAMMABLE_COMPLETION) @@ -90,72 +90,80 @@ extern int restricted_shell; extern char *shell_name; #endif -extern void set_shellopts (); - -static int set_interactive_comments (); +static int set_interactive_comments __P((int)); #if defined (RESTRICTED_SHELL) -static int set_restricted_shell (); +static int set_restricted_shell __P((int)); #endif +static int shopt_login_shell; + +typedef int shopt_set_func_t __P((int)); + static struct { char *name; int *value; - Function *set_func; + shopt_set_func_t *set_func; } shopt_vars[] = { - { "cdable_vars", &cdable_vars, (Function *)NULL }, - { "cdspell", &cdspelling, (Function *)NULL }, - { "checkhash", &check_hashed_filenames, (Function *)NULL }, - { "checkwinsize", &check_window_size, (Function *)NULL }, + { "cdable_vars", &cdable_vars, (shopt_set_func_t *)NULL }, + { "cdspell", &cdspelling, (shopt_set_func_t *)NULL }, + { "checkhash", &check_hashed_filenames, (shopt_set_func_t *)NULL }, + { "checkwinsize", &check_window_size, (shopt_set_func_t *)NULL }, #if defined (HISTORY) - { "cmdhist", &command_oriented_history, (Function *)NULL }, + { "cmdhist", &command_oriented_history, (shopt_set_func_t *)NULL }, #endif - { "dotglob", &glob_dot_filenames, (Function *)NULL }, - { "execfail", &no_exit_on_failed_exec, (Function *)NULL }, - { "expand_aliases", &expand_aliases, (Function *)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 }, #if defined (EXTENDED_GLOB) - { "extglob", &extended_glob, (Function *)NULL }, + { "extglob", &extended_glob, (shopt_set_func_t *)NULL }, #endif #if defined (READLINE) - { "histreedit", &history_reediting, (Function *)NULL }, + { "histreedit", &history_reediting, (shopt_set_func_t *)NULL }, #endif #if defined (HISTORY) - { "histappend", &force_append_history, (Function *)NULL }, + { "histappend", &force_append_history, (shopt_set_func_t *)NULL }, #endif #if defined (READLINE) - { "histverify", &hist_verify, (Function *)NULL }, - { "hostcomplete", &perform_hostname_completion, (Function *)enable_hostname_completion }, + { "histverify", &hist_verify, (shopt_set_func_t *)NULL }, + { "hostcomplete", &perform_hostname_completion, enable_hostname_completion }, #endif - { "huponexit", &hup_on_exit, (Function *)NULL }, + { "huponexit", &hup_on_exit, (shopt_set_func_t *)NULL }, { "interactive_comments", &interactive_comments, set_interactive_comments }, #if defined (HISTORY) - { "lithist", &literal_history, (Function *)NULL }, + { "lithist", &literal_history, (shopt_set_func_t *)NULL }, #endif - { "mailwarn", &mail_warning, (Function *)NULL }, + { "login_shell", &shopt_login_shell, set_login_shell }, + { "mailwarn", &mail_warning, (shopt_set_func_t *)NULL }, #if defined (READLINE) - { "no_empty_cmd_completion", &no_empty_command_completion, (Function *)NULL }, + { "no_empty_cmd_completion", &no_empty_command_completion, (shopt_set_func_t *)NULL }, #endif - { "nocaseglob", &glob_ignore_case, (Function *)NULL }, - { "nullglob", &allow_null_glob_expansion, (Function *)NULL }, + { "nocaseglob", &glob_ignore_case, (shopt_set_func_t *)NULL }, + { "nullglob", &allow_null_glob_expansion, (shopt_set_func_t *)NULL }, #if defined (PROGRAMMABLE_COMPLETION) - { "progcomp", &prog_completion_enabled, (Function *)NULL }, + { "progcomp", &prog_completion_enabled, (shopt_set_func_t *)NULL }, #endif - { "promptvars", &promptvars, (Function *)NULL }, + { "promptvars", &promptvars, (shopt_set_func_t *)NULL }, #if defined (RESTRICTED_SHELL) { "restricted_shell", &restricted_shell, set_restricted_shell }, #endif - { "shift_verbose", &print_shift_error, (Function *)NULL }, - { "sourcepath", &source_uses_path, (Function *)NULL }, - { "xpg_echo", &xpg_echo, (Function *)NULL }, - { (char *)0, (int *)0, (Function *)NULL } + { "shift_verbose", &print_shift_error, (shopt_set_func_t *)NULL }, + { "sourcepath", &source_uses_path, (shopt_set_func_t *)NULL }, + { "xpg_echo", &xpg_echo, (shopt_set_func_t *)NULL }, + { (char *)0, (int *)0, (shopt_set_func_t *)NULL } }; static char *on = "on"; static char *off = "off"; -static int list_shopt_o_options (); -static int list_some_o_options (), list_some_shopts (); -static int toggle_shopts (), list_shopts (), set_shopt_o_options (); +static int find_shopt __P((char *)); +static int toggle_shopts __P((int, WORD_LIST *, int)); +static void print_shopt __P((char *, int, int)); +static int list_shopts __P((WORD_LIST *, int)); +static int list_some_shopts __P((int, int)); +static int list_shopt_o_options __P((WORD_LIST *, int)); +static int list_some_o_options __P((int, int)); +static int set_shopt_o_options __P((int, WORD_LIST *, int)); #define SFLAG 0x01 #define UFLAG 0x02 @@ -244,6 +252,8 @@ reset_shopt_options () hist_verify = history_reediting = 0; perform_hostname_completion = 1; #endif + + shopt_login_shell = login_shell; } static int @@ -444,6 +454,15 @@ set_restricted_shell (mode) } #endif /* RESTRICTED_SHELL */ +/* Not static so shell.c can call it to initialize shopt_login_shell */ +int +set_login_shell (mode) + int mode; +{ + shopt_login_shell = login_shell != 0; + return (0); +} + char ** get_shopt_options () { @@ -457,3 +476,43 @@ get_shopt_options () ret[i] = (char *)NULL; return ret; } + +/* + * External interface for other parts of the shell. NAME is a string option; + * MODE is 0 if we want to unset an option; 1 if we want to set an option. + * REUSABLE is 1 if we want to print output in a form that may be reused. + */ +int +shopt_setopt (name, mode) + char *name; + int mode; +{ + WORD_LIST *wl; + int r; + + wl = add_string_to_list (name, (WORD_LIST *)NULL); + r = toggle_shopts (mode, wl, 0); + dispose_words (wl); + return r; +} + +int +shopt_listopt (name, reusable) + char *name; + int reusable; +{ + int i; + + if (name == 0) + return (list_shopts ((WORD_LIST *)NULL, reusable ? PFLAG : 0)); + + i = find_shopt (name); + if (i < 0) + { + SHOPT_ERROR (name); + return (EXECUTION_FAILURE); + } + + print_shopt (name, *shopt_vars[i].value, reusable ? PFLAG : 0); + return (EXECUTION_SUCCESS); +} diff --git a/builtins/suspend.def b/builtins/suspend.def index 62a2b4e..c1dc6d1 100644 --- a/builtins/suspend.def +++ b/builtins/suspend.def @@ -47,8 +47,6 @@ $END #include "common.h" #include "bashgetopt.h" -extern int job_control; - static SigHandler *old_cont; #if 0 static SigHandler *old_stop; diff --git a/builtins/test.def b/builtins/test.def index f8445de..d328876 100644 --- a/builtins/test.def +++ b/builtins/test.def @@ -31,6 +31,7 @@ are string operators as well, and numeric comparison operators. File operators: + -a FILE True if file exists. -b FILE True if file is block special. -c FILE True if file is character special. -d FILE True if file is a directory. diff --git a/builtins/trap.def b/builtins/trap.def index 8503035..933bd25 100644 --- a/builtins/trap.def +++ b/builtins/trap.def @@ -58,7 +58,8 @@ $END #include "common.h" #include "bashgetopt.h" -static int display_traps (); +static void showtrap __P((int)); +static int display_traps __P((WORD_LIST *)); /* The trap command: @@ -79,7 +80,7 @@ static int display_traps (); #define REVERT 1 /* Revert to this signals original value. */ #define IGNORE 2 /* Ignore this signal. */ -extern int interactive, posixly_correct; +extern int posixly_correct; int trap_builtin (list) @@ -228,7 +229,7 @@ display_traps (list) if (list == 0) { - for (i = 0; i <= NSIG; i++) + for (i = 0; i < BASH_NSIG; i++) showtrap (i); return (EXECUTION_SUCCESS); } diff --git a/builtins/type.def b/builtins/type.def index a60db0a..9510a0e 100644 --- a/builtins/type.def +++ b/builtins/type.def @@ -64,7 +64,7 @@ $END #include "common.h" #include "bashgetopt.h" -extern int find_reserved_word (); +extern int find_reserved_word __P((char *)); extern char *this_command_name; @@ -213,7 +213,7 @@ describe_command (command, verbose, all) int verbose, all; { int found, i, found_file, f; - char *full_path, *x, *cwd; + char *full_path, *x; SHELL_VAR *func; #if defined (ALIAS) alias_t *alias; diff --git a/builtins/ulimit.def b/builtins/ulimit.def index a9d5d6a..a830fb5 100644 --- a/builtins/ulimit.def +++ b/builtins/ulimit.def @@ -44,7 +44,9 @@ option is given, it is interpreted as follows: -u the maximum number of user processes -v the size of virtual memory -If LIMIT is given, it is the new value of the specified resource. +If LIMIT is given, it is the new value of the specified resource; +the special LIMIT values `soft', `hard', and `unlimited' stand for +the current soft limit, the current hard limit, and no limit, respectively. Otherwise, the current value of the specified resource is printed. If no option is given, then -f is assumed. Values are in 1024-byte increments, except for -t, which is in seconds, -p, which is in @@ -109,8 +111,6 @@ extern int errno; # define print_rlimtype(num, nl) printf ("%ld%s", num, nl ? "\n" : "") #endif -#define DESCFMT "%-28s" - /* Some systems use RLIMIT_NOFILE, others use RLIMIT_OFILE */ #if defined (HAVE_RESOURCE) && defined (RLIMIT_OFILE) && !defined (RLIMIT_NOFILE) # define RLIMIT_NOFILE RLIMIT_OFILE @@ -154,58 +154,72 @@ extern int errno; # define RLIM_INFINITY 0x7fffffff #endif +#if !defined (RLIM_SAVED_CUR) +# define RLIM_SAVED_CUR RLIM_INFINITY +#endif + +#if !defined (RLIM_SAVED_MAX) +# define RLIM_SAVED_MAX RLIM_INFINITY +#endif + #define LIMIT_HARD 0x01 #define LIMIT_SOFT 0x02 +static int _findlim __P((int)); + static int ulimit_internal __P((int, char *, int, int)); + +static int get_limit __P((int, RLIMTYPE *, RLIMTYPE *)); +static int set_limit __P((int, RLIMTYPE, int)); + static void printone __P((int, RLIMTYPE, int)); static void print_all_limits __P((int)); -static int get_limit __P((int, int, RLIMTYPE *)); -static int set_limit __P((int, RLIMTYPE, int)); +static int set_all_limits __P((int, RLIMTYPE)); static int filesize __P((RLIMTYPE *)); static int pipesize __P((RLIMTYPE *)); -static int getmaxuprc __P((int, RLIMTYPE *)); -static int getmaxvm __P((int, RLIMTYPE *)); +static int getmaxuprc __P((RLIMTYPE *)); +static int getmaxvm __P((RLIMTYPE *, RLIMTYPE *)); typedef struct { int option; /* The ulimit option for this limit. */ int parameter; /* Parameter to pass to get_limit (). */ int block_factor; /* Blocking factor for specific limit. */ char *description; /* Descriptive string to output. */ + char *units; /* scale */ } RESOURCE_LIMITS; static RESOURCE_LIMITS limits[] = { #ifdef RLIMIT_CORE - { 'c', RLIMIT_CORE, 1024, "core file size (blocks)" }, + { 'c', RLIMIT_CORE, 1024, "core file size", "blocks" }, #endif #ifdef RLIMIT_DATA - { 'd', RLIMIT_DATA, 1024, "data seg size (kbytes)" }, + { 'd', RLIMIT_DATA, 1024, "data seg size", "kbytes" }, #endif - { 'f', RLIMIT_FILESIZE, 1024, "file size (blocks)" }, + { 'f', RLIMIT_FILESIZE, 1024, "file size", "blocks" }, #ifdef RLIMIT_MEMLOCK - { 'l', RLIMIT_MEMLOCK, 1024, "max locked memory (kbytes)" }, + { 'l', RLIMIT_MEMLOCK, 1024, "max locked memory", "kbytes" }, #endif #ifdef RLIMIT_RSS - { 'm', RLIMIT_RSS, 1024, "max memory size (kbytes)" }, + { 'm', RLIMIT_RSS, 1024, "max memory size", "kbytes" }, #endif /* RLIMIT_RSS */ - { 'n', RLIMIT_OPENFILES, 1, "open files" }, - { 'p', RLIMIT_PIPESIZE, 512, "pipe size (512 bytes)" }, + { 'n', RLIMIT_OPENFILES, 1, "open files", (char *)NULL}, + { 'p', RLIMIT_PIPESIZE, 512, "pipe size", "512 bytes" }, #ifdef RLIMIT_STACK - { 's', RLIMIT_STACK, 1024, "stack size (kbytes)" }, + { 's', RLIMIT_STACK, 1024, "stack size", "kbytes" }, #endif #ifdef RLIMIT_CPU - { 't', RLIMIT_CPU, 1, "cpu time (seconds)" }, + { 't', RLIMIT_CPU, 1, "cpu time", "seconds" }, #endif /* RLIMIT_CPU */ - { 'u', RLIMIT_MAXUPROC, 1, "max user processes" }, + { 'u', RLIMIT_MAXUPROC, 1, "max user processes", (char *)NULL }, #if defined (HAVE_RESOURCE) - { 'v', RLIMIT_VIRTMEM, RLIMIT_VMBLKSZ, "virtual memory (kbytes)" }, + { 'v', RLIMIT_VIRTMEM, RLIMIT_VMBLKSZ, "virtual memory", "kbytes" }, #endif #ifdef RLIMIT_SWAP - { 'w', RLIMIT_SWAP, 1024, "swap size (kbytes)" }, + { 'w', RLIMIT_SWAP, 1024, "swap size", "kbytes" }, #endif - { -1, -1, -1, (char *)NULL } + { -1, -1, -1, (char *)NULL, (char *)NULL } }; #define NCMDS (sizeof(limits) / sizeof(limits[0])) @@ -308,6 +322,17 @@ ulimit_builtin (list) if (all_limits) { +#ifdef NOTYET + if (list) /* setting */ + { + if (STREQ (list->word->word, "unlimited") == 0) + { + builtin_error ("invalid limit argument: %s", list->word->word); + return (EXECUTION_FAILURE); + } + return (set_all_limits (mode == 0 ? LIMIT_SOFT|LIMIT_HARD : mode, RLIM_INFINITY)); + } +#endif print_all_limits (mode == 0 ? LIMIT_SOFT : mode); return (EXECUTION_SUCCESS); } @@ -347,58 +372,66 @@ ulimit_internal (cmd, cmdarg, mode, multiple) int mode, multiple; { int opt, limind, setting; - long block_factor; - RLIMTYPE current_limit, real_limit, limit; + int block_factor; + RLIMTYPE soft_limit, hard_limit, real_limit, limit; setting = cmdarg != 0; limind = _findlim (cmd); if (mode == 0) mode = setting ? (LIMIT_HARD|LIMIT_SOFT) : LIMIT_SOFT; - opt = get_limit (limind, mode, ¤t_limit); + opt = get_limit (limind, &soft_limit, &hard_limit); if (opt < 0) { - builtin_error ("cannot get limit: %s", strerror (errno)); + builtin_error ("cannot get %s limit: %s", limits[limind].description, + strerror (errno)); return (EXECUTION_FAILURE); } if (setting == 0) /* print the value of the specified limit */ { - printone (limind, current_limit, multiple); + printone (limind, (mode & LIMIT_SOFT) ? soft_limit : hard_limit, multiple); return (EXECUTION_SUCCESS); } /* Setting the limit. */ - if (STREQ (cmdarg, "unlimited")) - limit = RLIM_INFINITY; + if (STREQ (cmdarg, "hard")) + real_limit = hard_limit; + else if (STREQ (cmdarg, "soft")) + real_limit = soft_limit; + else if (STREQ (cmdarg, "unlimited")) + real_limit = RLIM_INFINITY; else if (all_digits (cmdarg)) - limit = string_to_rlimtype (cmdarg); - else { - builtin_error ("bad non-numeric arg `%s'", cmdarg); - return (EXECUTION_FAILURE); - } - - block_factor = (limit == RLIM_INFINITY) ? 1 : limits[limind].block_factor; - real_limit = limit * block_factor; + limit = string_to_rlimtype (cmdarg); + block_factor = limits[limind].block_factor; + real_limit = limit * block_factor; - if (real_limit < 0 || (real_limit == 0 && limit != 0)) + if ((real_limit / block_factor) != limit) + { + builtin_error ("limit out of range: %s", cmdarg); + return (EXECUTION_FAILURE); + } + } + else { - builtin_error ("limit out of range: %d", limit); + builtin_error ("bad non-numeric arg `%s'", cmdarg); return (EXECUTION_FAILURE); } if (set_limit (limind, real_limit, mode) < 0) { - builtin_error ("cannot modify limit: %s", strerror (errno)); + builtin_error ("cannot modify %s limit: %s", limits[limind].description, + strerror (errno)); return (EXECUTION_FAILURE); } + return (EXECUTION_SUCCESS); } static int -get_limit (ind, mode, limptr) - int ind, mode; - RLIMTYPE *limptr; +get_limit (ind, softlim, hardlim) + int ind; + RLIMTYPE *softlim, *hardlim; { RLIMTYPE value; #if defined (HAVE_RESOURCE) @@ -421,18 +454,16 @@ get_limit (ind, mode, limptr) value = (RLIMTYPE)getdtablesize (); break; case RLIMIT_VIRTMEM: - if (getmaxvm (mode, &value) < 0) - return -1; - break; + return (getmaxvm (softlim, hardlim)); case RLIMIT_MAXUPROC: - if (getmaxuprc (mode, &value) < 0) + if (getmaxuprc (&value) < 0) return -1; break; default: errno = EINVAL; return -1; } - *limptr = value; + *softlim = *hardlim = value; return (0); } else @@ -440,13 +471,16 @@ get_limit (ind, mode, limptr) #if defined (HAVE_RESOURCE) if (getrlimit (limits[ind].parameter, &limit) < 0) return -1; - value = (mode & LIMIT_SOFT) ? limit.rlim_cur : limit.rlim_max; + *softlim = limit.rlim_cur; + *hardlim = limit.rlim_max; # if defined (HPUX9) if (limits[ind].parameter == RLIMIT_FILESIZE) - *limptr = value * 512; /* Ugh. */ + { + *softlim *= 512; + *hardlim *= 512; /* Ugh. */ + } else # endif /* HPUX9 */ - *limptr = value; return 0; #else errno = EINVAL; @@ -521,26 +555,21 @@ set_limit (ind, newlim, mode) } static int -getmaxvm (mode, valuep) - int mode; - RLIMTYPE *valuep; +getmaxvm (softlim, hardlim) + RLIMTYPE *softlim, *hardlim; { #if defined (HAVE_RESOURCE) - struct rlimit rl; - RLIMTYPE maxdata, maxstack; + struct rlimit datalim, stacklim; - if (getrlimit (RLIMIT_DATA, &rl) < 0) + if (getrlimit (RLIMIT_DATA, &datalim) < 0) return -1; - else - maxdata = (mode & LIMIT_SOFT) ? rl.rlim_cur : rl.rlim_max; - if (getrlimit (RLIMIT_STACK, &rl) < 0) + if (getrlimit (RLIMIT_STACK, &stacklim) < 0) return -1; - else - maxstack = (mode & LIMIT_SOFT) ? rl.rlim_cur : rl.rlim_max; /* Protect against overflow. */ - *valuep = (maxdata / 1024L) + (maxstack / 1024L); + *softlim = (datalim.rlim_cur / 1024L) + (stacklim.rlim_cur / 1024L); + *hardlim = (datalim.rlim_max / 1024L) + (stacklim.rlim_max / 1024L); return 0; #else errno = EINVAL; @@ -557,11 +586,7 @@ filesize(valuep) if ((result = ulimit (1, 0L)) < 0) return -1; else -# if 0 - *valuep = (RLIMTYPE) result; -# else - *valuep = (RLIMTYPE) result * 512L; -# endif + *valuep = (RLIMTYPE) result * 512; return 0; #else errno = EINVAL; @@ -590,8 +615,7 @@ pipesize (valuep) } static int -getmaxuprc (mode, valuep) - int mode; +getmaxuprc (valuep) RLIMTYPE *valuep; { # if defined (HAVE_SYSCONF) && defined (_SC_CHILD_MAX) @@ -618,20 +642,17 @@ print_all_limits (mode) int mode; { register int i; - RLIMTYPE value; + RLIMTYPE softlim, hardlim; if (mode == 0) mode |= LIMIT_SOFT; for (i = 0; limits[i].option > 0; i++) { - if (get_limit (i, mode, &value) < 0) - { - fprintf (stderr, DESCFMT, limits[i].description); - builtin_error ("cannot get limit: %s", strerror (errno)); - } + if (get_limit (i, &softlim, &hardlim) < 0) + builtin_error ("cannot get %s limit: %s", limits[i].description, strerror (errno)); else - printone (i, value, 1); + printone (i, (mode & LIMIT_SOFT) ? softlim : hardlim, 1); } } @@ -641,11 +662,65 @@ printone (limind, curlim, pdesc) RLIMTYPE curlim; int pdesc; { + char unitstr[64]; + if (pdesc) - printf (DESCFMT, limits[limind].description); + { + if (limits[limind].units) + sprintf (unitstr, "(%s, -%c) ", limits[limind].units, limits[limind].option); + else + sprintf (unitstr, "(-%c) ", limits[limind].option); + + printf ("%-18s %16s", limits[limind].description, unitstr); + } if (curlim == RLIM_INFINITY) puts ("unlimited"); + else if (curlim == RLIM_SAVED_MAX) + puts ("hard"); + else if (curlim == RLIM_SAVED_CUR) + puts ("soft"); else print_rlimtype ((curlim / limits[limind].block_factor), 1); } + +/* Set all limits to NEWLIM. NEWLIM currently must be RLIM_INFINITY, which + causes all limits to be set as high as possible depending on mode (like + csh `unlimit'). Returns -1 if NEWLIM is invalid, 0 if all limits + were set successfully, and 1 if at least one limit could not be set. + + To raise all soft limits to their corresponding hard limits, use + ulimit -S -a unlimited + To attempt to raise all hard limits to infinity (superuser-only), use + ulimit -H -a unlimited + To attempt to raise all soft and hard limits to infinity, use + ulimit -a unlimited +*/ + +static int +set_all_limits (mode, newlim) + int mode; + RLIMTYPE newlim; +{ + register int i; + int retval = 0; + + if (newlim != RLIM_INFINITY) + { + errno = EINVAL; + return -1; + } + + if (mode == 0) + mode = LIMIT_SOFT|LIMIT_HARD; + + for (retval = i = 0; limits[i].option > 0; i++) + if (set_limit (i, newlim, mode) < 0) + { + builtin_error ("cannot modify %s limit: %s", limits[i].description, + strerror (errno)); + retval = 1; + } + return retval; +} + #endif /* !_MINIX */ diff --git a/builtins/umask.def b/builtins/umask.def index 1c1591e..4d62184 100644 --- a/builtins/umask.def +++ b/builtins/umask.def @@ -46,20 +46,25 @@ $END #endif #include <stdio.h> +#include <chartypes.h> #include "../shell.h" #include "posixstat.h" #include "common.h" #include "bashgetopt.h" +#ifdef __LCC__ +#define mode_t int +#endif + /* **************************************************************** */ /* */ /* UMASK Builtin and Helpers */ /* */ /* **************************************************************** */ -static void print_symbolic_umask (); -static int symbolic_umask (); +static void print_symbolic_umask __P((mode_t)); +static int symbolic_umask __P((WORD_LIST *)); /* Set or display the mask used by the system when creating files. Flag of -S means display the umask in a symbolic mode. */ @@ -92,7 +97,7 @@ umask_builtin (list) if (list) { - if (digit (*list->word->word)) + if (DIGIT (*list->word->word)) { umask_value = read_octal (list->word->word); @@ -128,7 +133,7 @@ umask_builtin (list) if (print_symbolically) print_symbolic_umask (umask_arg); else - printf ("%03o\n", umask_arg); + printf ("%04lo\n", (unsigned long)umask_arg); } fflush (stdout); @@ -179,12 +184,12 @@ parse_symbolic_mode (mode, initial_bits) char *mode; int initial_bits; { - int who, op, perm, mask, bits, c; + int who, op, perm, bits, c; char *s; for (s = mode, bits = initial_bits;;) { - who = op = perm = mask = 0; + who = op = perm = 0; /* Parse the `who' portion of the symbolic mode clause. */ while (member (*s, "agou")) diff --git a/builtins/wait.def b/builtins/wait.def index 5154a77..f34da8d 100644 --- a/builtins/wait.def +++ b/builtins/wait.def @@ -50,6 +50,8 @@ $END # include <unistd.h> #endif +#include <chartypes.h> + #include "../bashansi.h" #include "../shell.h" @@ -81,6 +83,8 @@ wait_builtin (list) int status, code; volatile int old_interrupt_immediately; + USE_VAR(list); + if (no_options (list)) return (EX_USAGE); if (list != loptend) @@ -120,13 +124,14 @@ wait_builtin (list) { pid_t pid; char *w; + long pid_value; w = list->word->word; - if (digit (*w)) + if (DIGIT (*w)) { - if (all_digits (w + 1)) + if (legal_number (w, &pid_value) && pid_value == (pid_t)pid_value) { - pid = (pid_t)atoi (w); + pid = (pid_t)pid_value; status = wait_for_single_pid (pid); } else |
