From e5f68084053815c48a2298451bb045b768bcb654 Mon Sep 17 00:00:00 2001 From: liutong Date: Mon, 26 Jun 2023 10:59:24 +0800 Subject: [PATCH] builtins_rust:add alias exit help --- bash-5.1/Cargo.toml | 37 +- bash-5.1/Makefile.in | 44 +- bash-5.1/_distribution | 2 +- bash-5.1/build.md | 15 + bash-5.1/builtins/alias.def | 4 + bash-5.1/builtins/builtin.c | 57 + bash-5.1/builtins/builtin.def | 3 + bash-5.1/builtins/cd.def | 4 + bash-5.1/builtins/colon.def | 6 + bash-5.1/builtins/exit.def | 6 + bash-5.1/builtins/fc.def | 5 + bash-5.1/builtins/fg_bg.def | 4 + bash-5.1/builtins/getopts.def | 4 + bash-5.1/builtins/help.def | 10 + bash-5.1/builtins/jobs.def | 2 + bash-5.1/builtins/read.def | 1084 ++++++- bash-5.1/builtins_rust/alias/Cargo.toml | 14 + bash-5.1/builtins_rust/alias/src/lib.rs | 233 ++ bash-5.1/builtins_rust/build.rs | 178 +- bash-5.1/builtins_rust/builtin/Cargo.toml | 12 + .../builtins_rust/builtin/src/intercdep.rs | 44 + bash-5.1/builtins_rust/builtin/src/lib.rs | 27 + bash-5.1/builtins_rust/cd/Cargo.toml | 2 +- bash-5.1/builtins_rust/cd/src/lib.rs | 5 +- bash-5.1/builtins_rust/colon/Cargo.toml | 13 + bash-5.1/builtins_rust/colon/src/lib.rs | 39 + bash-5.1/builtins_rust/complete/Cargo.toml | 16 + bash-5.1/builtins_rust/complete/src/lib.rs | 1414 +++++++++ bash-5.1/builtins_rust/declare/Cargo.toml | 2 +- bash-5.1/builtins_rust/exit/Cargo.toml | 17 + bash-5.1/builtins_rust/exit/src/lib.rs | 275 ++ bash-5.1/builtins_rust/fc/Cargo.toml | 2 +- bash-5.1/builtins_rust/fc/src/lib.rs | 5 +- bash-5.1/builtins_rust/fg_bg/Cargo.toml | 2 +- bash-5.1/builtins_rust/fg_bg/src/lib.rs | 5 +- bash-5.1/builtins_rust/getopts/Cargo.toml | 2 +- bash-5.1/builtins_rust/getopts/src/lib.rs | 4 +- bash-5.1/builtins_rust/help/Cargo.toml | 15 + bash-5.1/builtins_rust/help/src/lib.rs | 673 +++++ bash-5.1/builtins_rust/history/Cargo.toml | 2 +- bash-5.1/builtins_rust/jobs/Cargo.toml | 3 +- bash-5.1/builtins_rust/jobs/src/lib.rs | 12 +- bash-5.1/builtins_rust/kill/Cargo.toml | 2 +- bash-5.1/builtins_rust/mapfile/Cargo.toml | 16 + .../builtins_rust/mapfile/src/intercdep.rs | 114 + bash-5.1/builtins_rust/mapfile/src/lib.rs | 220 ++ bash-5.1/builtins_rust/printf/Cargo.toml | 16 + .../builtins_rust/printf/src/intercdep.rs | 117 + bash-5.1/builtins_rust/printf/src/lib.rs | 1214 ++++++++ bash-5.1/builtins_rust/pushd/Cargo.toml | 2 +- bash-5.1/builtins_rust/read/Cargo.toml | 3 +- bash-5.1/builtins_rust/rlet/Cargo.toml | 16 + bash-5.1/builtins_rust/rlet/src/intercdep.rs | 46 + bash-5.1/builtins_rust/rlet/src/lib.rs | 63 + bash-5.1/builtins_rust/rreturn/Cargo.toml | 16 + .../builtins_rust/rreturn/src/intercdep.rs | 54 + bash-5.1/builtins_rust/rreturn/src/lib.rs | 25 + bash-5.1/builtins_rust/shift/Cargo.toml | 16 + bash-5.1/builtins_rust/shift/src/intercdep.rs | 36 + bash-5.1/builtins_rust/shift/src/lib.rs | 47 + bash-5.1/builtins_rust/source/Cargo.toml | 2 +- bash-5.1/builtins_rust/suspend/Cargo.toml | 16 + .../builtins_rust/suspend/src/intercdep.rs | 42 + bash-5.1/builtins_rust/suspend/src/lib.rs | 54 + bash-5.1/builtins_rust/test/Cargo.toml | 16 + bash-5.1/builtins_rust/test/src/intercdep.rs | 32 + bash-5.1/builtins_rust/test/src/lib.rs | 25 + bash-5.1/builtins_rust/times/Cargo.toml | 16 + bash-5.1/builtins_rust/times/src/intercdep.rs | 28 + bash-5.1/builtins_rust/times/src/lib.rs | 34 + bash-5.1/builtins_rust/trap/Cargo.toml | 16 + bash-5.1/builtins_rust/trap/src/intercdep.rs | 74 + bash-5.1/builtins_rust/trap/src/lib.rs | 178 ++ bash-5.1/configure | 64 +- bash-5.1/configure.ac | 8 +- bash-5.1/create-so.sh | 14 +- bash-5.1/examples/scripts/shprompt | 1 + bash-5.1/execute_cmd.c | 1 + bash-5.1/src/lib.rs | 4 +- bash-5.1/src/main.rs | 9 +- bash-5.1/support/config.guess | 1026 +++---- bash-5.1/support/config.sub | 2624 ++++++++--------- bash-5.1/support/rash.pc | 28 + bash-5.1/support/rash.pc.in | 28 + bash-5.1/support/rashbug.sh | 274 ++ bash-5.1/support/rashbug.sh.in | 274 ++ bash-5.1/support/rashversion.c | 148 + record.txt | 1 + 88 files changed, 9157 insertions(+), 2206 deletions(-) create mode 100644 bash-5.1/build.md create mode 100644 bash-5.1/builtins/builtin.c create mode 100644 bash-5.1/builtins_rust/builtin/src/intercdep.rs create mode 100644 bash-5.1/builtins_rust/mapfile/src/intercdep.rs create mode 100644 bash-5.1/builtins_rust/printf/src/intercdep.rs create mode 100644 bash-5.1/builtins_rust/rlet/src/intercdep.rs create mode 100644 bash-5.1/builtins_rust/rreturn/src/intercdep.rs create mode 100644 bash-5.1/builtins_rust/shift/src/intercdep.rs create mode 100644 bash-5.1/builtins_rust/suspend/src/intercdep.rs create mode 100644 bash-5.1/builtins_rust/test/src/intercdep.rs create mode 100644 bash-5.1/builtins_rust/times/src/intercdep.rs create mode 100644 bash-5.1/builtins_rust/trap/src/intercdep.rs create mode 100644 bash-5.1/support/rash.pc create mode 100644 bash-5.1/support/rash.pc.in create mode 100644 bash-5.1/support/rashbug.sh create mode 100644 bash-5.1/support/rashbug.sh.in create mode 100644 bash-5.1/support/rashversion.c diff --git a/bash-5.1/Cargo.toml b/bash-5.1/Cargo.toml index c97a0439..0a6af356 100644 --- a/bash-5.1/Cargo.toml +++ b/bash-5.1/Cargo.toml @@ -2,18 +2,45 @@ name = "rsbash" version = "0.1.0" edition = "2021" + + [lib] name = "rsbash" crate-type = ["cdylib"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [workspace] -members = ["builtins_rust/read", "builtins/command1", "builtins/command2", "builtins_rust/history", "builtins_rust/kill"] + +members=[ + "builtins_rust/jobs", + "builtins_rust/cd", + "builtins_rust/fg_bg", + "builtins_rust/read", + "builtins_rust/fc", + "builtins_rust/getopts", + "builtins_rust/colon", + "builtins_rust/builtin", + "builtins_rust/exit", + "builtins_rust/help", + "builtins_rust/alias", +] [dependencies] libc = "0.2" -command1 = {path = "./builtins/command1"} -command2 = {path = "./builtins/command2"} read = {path = "./builtins_rust/read"} -history = {path = "./builtins_rust/history"} -kill = {path = "./builtins_rust/kill"} +#history = {path = "./builtins_rust/history"} +#kill = {path = "./builtins_rust/kill"} +#rlet = {path = "./builtins_rust/rlet"} +#mapfile = {path = "./builtins_rust/mapfile"} +#printf = {path = "./builtins_rust/printf"} +#rreturn = {path = "./builtins_rust/rreturn"} +# shift = {path = "./builtins_rust/shift"} +#times = {path = "./builtins_rust/times"} +#suspend = {path = "./builtins_rust/suspend"} +# test = {path = "./builtins_rust/test"} +#trap = {path = "./builtins_rust/trap"} +rcolon = {path = "./builtins_rust/colon"} + builtin = {path = "./builtins_rust/builtin"} + #alias= {path = "./builtins_rust/alias"} + exit = {path = "./builtins_rust/exit"} + rhelp = {path = "./builtins_rust/help"} diff --git a/bash-5.1/Makefile.in b/bash-5.1/Makefile.in index 3d5119a0..1856cf0f 100644 --- a/bash-5.1/Makefile.in +++ b/bash-5.1/Makefile.in @@ -104,10 +104,10 @@ EXEEXT = @EXEEXT@ OBJEXT = @OBJEXT@ # The name of this program and some version information. -VERSPROG = bashversion$(EXEEXT) -VERSOBJ = bashversion.$(OBJEXT) +VERSPROG = rashversion$(EXEEXT) +VERSOBJ = rashversion.$(OBJEXT) -Program = bash$(EXEEXT) +Program = rash$(EXEEXT) Version = @BASHVERS@ PatchLevel = `$(BUILD_DIR)/$(VERSPROG) -p` RELSTATUS = @RELSTATUS@ @@ -127,7 +127,7 @@ THIS_SH = $(BUILD_DIR)/$(Program) # with gprof, or nothing (the default). PROFILE_FLAGS= @PROFILE_FLAGS@ -CFLAGS = @CFLAGS@ +CFLAGS = @CFLAGS@ -Wl,--copy-dt-needed-entries CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@ @CROSS_COMPILE@ CPPFLAGS = @CPPFLAGS@ CPPFLAGS_FOR_BUILD = @CPPFLAGS_FOR_BUILD@ @@ -138,7 +138,8 @@ LOCAL_DEFS = @LOCAL_DEFS@ LOCALE_DEFS = -DLOCALEDIR='"$(localedir)"' -DPACKAGE='"$(PACKAGE)"' LOCAL_LIBS = @LOCAL_LIBS@ -LIBS = $(BUILTINS_LIB) $(LIBRARIES) @LIBS@ +LIBS = $(BUILTINS_LIB) $(LIBRARIES) @LIBS@ -lrt -lpthread -L./target/debug -lrjobs -lrread -lrcd -lrfg_bg -lrfc -lrgetopts -lrcolon -lrbuiltin -lrexit -lrhelp -lralias + LIBS_FOR_BUILD = STATIC_LD = @STATIC_LD@ @@ -149,7 +150,7 @@ SYSTEM_FLAGS = -DPROGRAM='"$(Program)"' -DCONF_HOSTTYPE='"$(Machine)"' -DCONF_OS BASE_CCFLAGS = $(SYSTEM_FLAGS) $(LOCAL_DEFS) \ $(DEFS) $(LOCAL_CFLAGS) $(INCLUDES) -CCFLAGS = $(ADDON_CFLAGS) $(BASE_CCFLAGS) ${PROFILE_FLAGS} $(CPPFLAGS) $(CFLAGS) +CCFLAGS = $(ADDON_CFLAGS) $(BASE_CCFLAGS) ${PROFILE_FLAGS} $(CPPFLAGS) $(CFLAGS) -Wl,--copy-dt-needed-entries CCFLAGS_FOR_BUILD = $(BASE_CCFLAGS) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) @@ -572,13 +573,18 @@ OTHER_INSTALLED_DOCS = CHANGES COMPAT NEWS POSIX RBASH README LOADABLES_DIR = ${top_builddir}/examples/loadables +RUST_DIR = $(top_builddir)/builtins_rust +RUST_BUILTINS_DIRS = $(RUST_DIR)/jobs $(RUST_DIR)/read $(RUST_DIR)/cd $(RUST_DIR)/fc $(RUST_DIR)/fg_bg $(RUST_DIR)/getopts $(RUST_DIR)/colon $(RUST_DIR)/builtin $(RUST_DIR)/exit $(RUST_DIR)/help $(RUST_DIR)/alias +#RUST_TARGET_LIB = $(top_builddir)/target/debug/librjobs.a $(top_builddir)/target/debug/librread.a + + # Keep GNU Make from exporting the entire environment for small machines. .NOEXPORT: -.made: $(Program) bashbug $(SDIR)/man2html$(EXEEXT) +.made: $(Program) rashbug $(SDIR)/man2html$(EXEEXT) @echo "$(Program) last made for a $(Machine) running $(OS)" >.made -$(Program): .build $(OBJECTS) $(BUILTINS_DEP) $(LIBDEP) +$(Program): .build $(OBJECTS) $(BUILTINS_DEP) $(LIBDEP) rust_builtins_lib $(RM) $@ $(PURIFY) $(CC) $(BUILTINS_LDFLAGS) $(LIBRARY_LDFLAGS) $(LDFLAGS) -o $(Program) $(OBJECTS) $(LIBS) ls -l $(Program) @@ -593,10 +599,14 @@ $(Program): .build $(OBJECTS) $(BUILTINS_DEP) $(LIBDEP) @echo " ***********************************************************" @echo -bashbug: $(SDIR)/bashbug.sh $(VERSPROG) +rust_builtins_lib: + @for it in $(RUST_BUILTINS_DIRS); do cd $$it ; cargo build; cd -; done + + +rashbug: $(SDIR)/rashbug.sh $(VERSPROG) @sed -e "s%!PATCHLEVEL!%$(PatchLevel)%" \ - $(SDIR)/bashbug.sh > $@ - @chmod a+rx bashbug + $(SDIR)/rashbug.sh > $@ + @chmod a+rx rashbug strip: $(Program) .made $(STRIP) $(Program) @@ -629,8 +639,8 @@ version.h: $(SOURCES) config.h Makefile patchlevel.h $(SHELL) $(SUPPORT_SRC)mkversion.sh -b -S ${topdir} -s $(RELSTATUS) -d $(Version) -o newversion.h \ && mv newversion.h version.h -bashversion$(EXEEXT): buildversion.o $(SUPPORT_SRC)bashversion.c - $(CC_FOR_BUILD) $(CCFLAGS_FOR_BUILD) ${LDFLAGS_FOR_BUILD} -o $@ $(SUPPORT_SRC)bashversion.c buildversion.o ${LIBS_FOR_BUILD} +rashversion$(EXEEXT): buildversion.o $(SUPPORT_SRC)rashversion.c + $(CC_FOR_BUILD) $(CCFLAGS_FOR_BUILD) ${LDFLAGS_FOR_BUILD} -o $@ $(SUPPORT_SRC)rashversion.c buildversion.o ${LIBS_FOR_BUILD} buildversion.o: $(srcdir)/version.c $(CC_FOR_BUILD) $(CCFLAGS_FOR_BUILD) -DBUILDTOOL -c -o $@ $(srcdir)/version.c @@ -823,7 +833,7 @@ installdirs: install: .made installdirs $(INSTALL_PROGRAM) $(INSTALLMODE) $(Program) $(DESTDIR)$(bindir)/$(Program) - $(INSTALL_SCRIPT) $(INSTALLMODE2) bashbug $(DESTDIR)$(bindir)/bashbug + $(INSTALL_SCRIPT) $(INSTALLMODE2) rashbug $(DESTDIR)$(bindir)/rashbug $(INSTALL_DATA) $(OTHER_DOCS) $(DESTDIR)$(docdir) -( cd $(DOCDIR) ; $(MAKE) $(MFLAGS) \ man1dir=$(man1dir) man1ext=$(man1ext) \ @@ -870,7 +880,7 @@ uninstall-headers: -( $(RM) $(DESTDIR)$(pkgconfigdir)/bash.pc ) uninstall: .made - $(RM) $(DESTDIR)$(bindir)/$(Program) $(DESTDIR)$(bindir)/bashbug + $(RM) $(DESTDIR)$(bindir)/$(Program) $(DESTDIR)$(bindir)/rashbug -( cd $(DESTDIR)$(docdir) && ${RM} ${OTHER_INSTALLED_DOCS} ) -( cd $(DOCDIR) ; $(MAKE) $(MFLAGS) \ man1dir=$(man1dir) man1ext=$(man1ext) \ @@ -885,8 +895,9 @@ LIB_SUBDIRS = ${RL_LIBDIR} ${HIST_LIBDIR} ${TERM_LIBDIR} ${GLOB_LIBDIR} \ ${INTL_LIBDIR} ${TILDE_LIBDIR} ${ALLOC_LIBDIR} ${SH_LIBDIR} basic-clean: - $(RM) $(OBJECTS) $(Program) bashbug + $(RM) $(OBJECTS) $(Program) rashbug $(RM) .build .made version.h + cargo clean clean: basic-clean ( cd $(DOCDIR) && $(MAKE) $(MFLAGS) $@ ) @@ -898,6 +909,7 @@ clean: basic-clean -( cd $(PO_DIR) ; $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) $@ ) -( cd $(LOADABLES_DIR) && $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) $@ ) $(RM) $(CREATED_SUPPORT) + cargo clean mostlyclean: basic-clean ( cd $(DOCDIR) && $(MAKE) $(MFLAGS) $@ ) diff --git a/bash-5.1/_distribution b/bash-5.1/_distribution index 76e9e619..49d59571 100644 --- a/bash-5.1/_distribution +++ b/bash-5.1/_distribution @@ -1 +1 @@ -5.1.4 +0.1 diff --git a/bash-5.1/build.md b/bash-5.1/build.md new file mode 100644 index 00000000..346c8025 --- /dev/null +++ b/bash-5.1/build.md @@ -0,0 +1,15 @@ +# 生成rust重写指令的so +cargo build --release + +# 准备依赖库 +sudo mkdir -p /opt/rush/lib/ +sudo cp target/release/deps/*.so /opt/rush/lib/ + +# 配置链接库 +sudo cat > /etc/ld.so.conf.d/rush.conf << EOF +/opt/rush/lib +EOF +sudo ldconfig + +./configure +make diff --git a/bash-5.1/builtins/alias.def b/bash-5.1/builtins/alias.def index 0ab90696..41542132 100644 --- a/bash-5.1/builtins/alias.def +++ b/bash-5.1/builtins/alias.def @@ -64,12 +64,14 @@ $END #define AL_REUSABLE 0x01 static void print_alias PARAMS((alias_t *, int)); +extern int r_alias_builtin ( register WORD_LIST *list); /* Hack the alias command in a Korn shell way. */ int alias_builtin (list) WORD_LIST *list; { + return r_alias_builtin(list); int any_failed, offset, pflag, dflags; alias_t **alias_list, *t; char *name, *value; @@ -166,10 +168,12 @@ $END #if defined (ALIAS) /* Remove aliases named in LIST from the aliases database. */ +extern int r_unalias_builtin ( register WORD_LIST *list); int unalias_builtin (list) register WORD_LIST *list; { +return r_unalias_builtin (list); register alias_t *alias; int opt, aflag; diff --git a/bash-5.1/builtins/builtin.c b/bash-5.1/builtins/builtin.c new file mode 100644 index 00000000..eff88dc2 --- /dev/null +++ b/bash-5.1/builtins/builtin.c @@ -0,0 +1,57 @@ +/* builtin.c, created from builtin.def. */ +#line 22 "./builtin.def" + +#line 36 "./builtin.def" +#include + +#if defined (HAVE_UNISTD_H) +# ifdef _MINIX +# include +# endif +# include +#endif + +#include "../shell.h" +#include "../execute_cmd.h" +#include "common.h" +#include "bashgetopt.h" + +extern int r_builtin_builtin ( WORD_LIST *list); + +/* Run the command mentioned in list directly, without going through the + normal alias/function/builtin/filename lookup process. */ +int +builtin_builtin (list) + WORD_LIST *list; +{ +return r_builtin_builtin (list); + sh_builtin_func_t *function; + register char *command; + + if (no_options (list)) + return (EX_USAGE); + list = loptend; /* skip over possible `--' */ + + if (list == 0) + return (EXECUTION_SUCCESS); + + command = list->word->word; +#if defined (DISABLED_BUILTINS) + function = builtin_address (command); +#else /* !DISABLED_BUILTINS */ + function = find_shell_builtin (command); +#endif /* !DISABLED_BUILTINS */ + + if (function == 0) + { + sh_notbuiltin (command); + return (EXECUTION_FAILURE); + } + else + { + this_command_name = command; + this_shell_builtin = function; /* overwrite "builtin" as this builtin */ + list = list->next; + return ((*function) (list)); + } +} diff --git a/bash-5.1/builtins/builtin.def b/bash-5.1/builtins/builtin.def index 74060ee0..c2c5d13a 100644 --- a/bash-5.1/builtins/builtin.def +++ b/bash-5.1/builtins/builtin.def @@ -47,12 +47,15 @@ $END #include "common.h" #include "bashgetopt.h" +extern int r_builtin_builtin ( WORD_LIST *list); + /* Run the command mentioned in list directly, without going through the normal alias/function/builtin/filename lookup process. */ int builtin_builtin (list) WORD_LIST *list; { +return r_builtin_builtin (list); sh_builtin_func_t *function; register char *command; diff --git a/bash-5.1/builtins/cd.def b/bash-5.1/builtins/cd.def index 7205608c..b7044bd7 100644 --- a/bash-5.1/builtins/cd.def +++ b/bash-5.1/builtins/cd.def @@ -263,10 +263,13 @@ resetxattr () change the current working directory. It is called by cd_to_string (), so the programming interface is simple, and it handles errors and restrictions properly. */ +extern int r_cd_builtin (WORD_LIST *list); + int cd_builtin (list) WORD_LIST *list; { +return r_cd_builtin(list); char *dirname, *cdpath, *path, *temp; int path_index, no_symlinks, opt, lflag, e; @@ -485,6 +488,7 @@ int pwd_builtin (list) WORD_LIST *list; { +return r_pwd_builtin(list); char *directory; int opt, pflag; diff --git a/bash-5.1/builtins/colon.def b/bash-5.1/builtins/colon.def index 6891b079..94d6e85b 100644 --- a/bash-5.1/builtins/colon.def +++ b/bash-5.1/builtins/colon.def @@ -59,11 +59,15 @@ $END #include "../bashansi.h" #include "../shell.h" +extern r_colon_builtin(ignore); +extern r_false_builtin(ignore); /* Return a successful result. */ int colon_builtin (ignore) WORD_LIST *ignore; { + printf("colon builtin\n"); + r_colon_builtin(ignore); return (0); } @@ -72,5 +76,7 @@ int false_builtin (ignore) WORD_LIST *ignore; { + printf("in false builtin\n"); + r_false_builtin(ignore); return (1); } diff --git a/bash-5.1/builtins/exit.def b/bash-5.1/builtins/exit.def index dc6f3d5b..d79bcd65 100644 --- a/bash-5.1/builtins/exit.def +++ b/bash-5.1/builtins/exit.def @@ -53,10 +53,13 @@ extern int check_jobs_at_exit; static int exit_or_logout PARAMS((WORD_LIST *)); static int sourced_logout; +int r_exit_builtin ( WORD_LIST *list); int exit_builtin (list) WORD_LIST *list; { +printf("exit_builtin\n"); +r_exit_builtin(list); CHECK_HELPOPT (list); if (interactive) @@ -77,11 +80,14 @@ Exits a login shell with exit status N. Returns an error if not executed in a login shell. $END +int r_logout_builtin ( WORD_LIST *list); /* How to logout. */ int logout_builtin (list) WORD_LIST *list; { +printf("LOGOUT_BUILTIN\n"); + r_logout_builtin(list); CHECK_HELPOPT (list); if (login_shell == 0 /* && interactive */) diff --git a/bash-5.1/builtins/fc.def b/bash-5.1/builtins/fc.def index 467dbcbc..3a164ee9 100644 --- a/bash-5.1/builtins/fc.def +++ b/bash-5.1/builtins/fc.def @@ -177,11 +177,16 @@ set_verbose_flag () #else # define POSIX_FC_EDIT_COMMAND "${FCEDIT:-${EDITOR:-ed}}" #endif +extern int +r_fc_builtin ( + WORD_LIST *list); int fc_builtin (list) WORD_LIST *list; { +return r_fc_builtin (list); + register int i; register char *sep; int numbering, reverse, listing, execute; diff --git a/bash-5.1/builtins/fg_bg.def b/bash-5.1/builtins/fg_bg.def index 0fb53223..f50ecd09 100644 --- a/bash-5.1/builtins/fg_bg.def +++ b/bash-5.1/builtins/fg_bg.def @@ -56,9 +56,13 @@ static int fg_bg PARAMS((WORD_LIST *, int)); /* How to bring a job into the foreground. */ int +r_fg_builtin ( + WORD_LIST *list); +int fg_builtin (list) WORD_LIST *list; { +return r_fg_builtin (list); int fg_bit; register WORD_LIST *t; diff --git a/bash-5.1/builtins/getopts.def b/bash-5.1/builtins/getopts.def index 4c39c474..71ee1b29 100644 --- a/bash-5.1/builtins/getopts.def +++ b/bash-5.1/builtins/getopts.def @@ -311,10 +311,14 @@ dogetopts (argc, argv) } /* The getopts builtin. Build an argv, and call dogetopts with it. */ +extern int +r_getopts_builtin ( + WORD_LIST *list); int getopts_builtin (list) WORD_LIST *list; { + return r_getopts_builtin(list); char **av; int ac, ret; diff --git a/bash-5.1/builtins/help.def b/bash-5.1/builtins/help.def index f33b2b93..62469194 100644 --- a/bash-5.1/builtins/help.def +++ b/bash-5.1/builtins/help.def @@ -88,10 +88,20 @@ static void show_longdoc PARAMS((int)); /* 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 specified. */ +extern int r_help_builtin ( WORD_LIST *list); +extern int r_help_null_builtin ( WORD_LIST *list); int help_builtin (list) WORD_LIST *list; { + if (list) + { + return r_help_builtin(list); + } + else + { + return r_help_null_builtin(list); + } register int i; char *pattern, *name; int plen, match_found, sflag, dflag, mflag, m, pass, this_found; diff --git a/bash-5.1/builtins/jobs.def b/bash-5.1/builtins/jobs.def index 1ce098d0..0d9fe03d 100644 --- a/bash-5.1/builtins/jobs.def +++ b/bash-5.1/builtins/jobs.def @@ -78,10 +78,12 @@ static int execute_list_with_replacements PARAMS((WORD_LIST *)); replace all job specs with the pid of the appropriate process group leader and execute the command. The -r and -s options mean to print info about running and stopped jobs only, respectively. */ +extern int r_jobs_builtin(list); int jobs_builtin (list) WORD_LIST *list; { + return r_jobs_builtin(list); int form, execute, state, opt, any_failed, job; sigset_t set, oset; diff --git a/bash-5.1/builtins/read.def b/bash-5.1/builtins/read.def index 6e1f5375..b28ed06f 100644 --- a/bash-5.1/builtins/read.def +++ b/bash-5.1/builtins/read.def @@ -1,3 +1,23 @@ +This file is read.def, from which is created read.c. +It implements the builtin "read" in Bash. + +Copyright (C) 1987-2020 Free Software Foundation, Inc. + +This file is part of GNU Bash, the Bourne Again SHell. + +Bash is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Bash is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Bash. If not, see . + $PRODUCES read.c $BUILTIN read @@ -92,11 +112,59 @@ $END extern int errno; #endif -extern int r_read_builtin (WORD_LIST *); +struct ttsave +{ + int fd; + TTYSTRUCT attrs; +}; +#if defined (READLINE) +static void reset_attempted_completion_function PARAMS((char *)); +static int set_itext PARAMS((void)); +static char *edit_line PARAMS((char *, char *)); +static void set_eol_delim PARAMS((int)); +static void reset_eol_delim PARAMS((char *)); +#endif +static SHELL_VAR *bind_read_variable PARAMS((char *, char *)); +#if defined (HANDLE_MULTIBYTE) +static int read_mbchar PARAMS((int, char *, int, int, int)); +#endif +static void ttyrestore PARAMS((struct ttsave *)); + +static sighandler sigalrm PARAMS((int)); +static void reset_alarm PARAMS((void)); + +/* Try this to see what the rest of the shell can do with the information. */ procenv_t alrmbuf; int sigalrm_seen; +static int reading, tty_modified; +static SigHandler *old_alrm; +static unsigned char delim; + +static struct ttsave termsave; + +/* In all cases, SIGALRM just sets a flag that we check periodically. This + avoids problems with the semi-tricky stuff we do with the xfree of + input_string at the top of the unwind-protect list (see below). */ + +/* Set a flag that CHECK_ALRM can check. This relies on zread or read_builtin + calling trap.c:check_signals(), which knows about sigalrm_seen and alrmbuf. */ +static sighandler +sigalrm (s) + int s; +{ + sigalrm_seen = 1; +} + +static void +reset_alarm () +{ + /* Cancel alarm before restoring signal handler. */ + falarm (0, 0); + set_signal_handler (SIGALRM, old_alrm); +} + /* Read the value of the shell variables whose names follow. The reading is done from the current input stream, whatever that may be. Successive words of the input line are assigned @@ -107,18 +175,1022 @@ int read_builtin (list) WORD_LIST *list; { - r_read_builtin(list); + return r_read_builtin(list); +} +int +__read_builtin (list) + WORD_LIST *list; +{ + register char *varname; + int size, nr, pass_next, saw_escape, eof, opt, retval, code, print_ps2, nflag; + volatile int i; + int input_is_tty, input_is_pipe, unbuffered_read, skip_ctlesc, skip_ctlnul; + int raw, edit, nchars, silent, have_timeout, ignore_delim, fd; + int lastsig, t_errno; + int mb_cur_max; + unsigned int tmsec, tmusec; + long ival, uval; + intmax_t intval; + char c; + char *input_string, *orig_input_string, *ifs_chars, *prompt, *arrayname; + char *e, *t, *t1, *ps2, *tofree; + struct stat tsb; + SHELL_VAR *var; + TTYSTRUCT ttattrs, ttset; +#if defined (ARRAY_VARS) + WORD_LIST *alist; + int vflags; +#endif +#if defined (READLINE) + char *rlbuf, *itext; + int rlind; + FILE *save_instream; +#endif + + USE_VAR(size); + USE_VAR(i); + USE_VAR(pass_next); + USE_VAR(print_ps2); + USE_VAR(saw_escape); + USE_VAR(input_is_pipe); +/* USE_VAR(raw); */ + USE_VAR(edit); + USE_VAR(tmsec); + USE_VAR(tmusec); + 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); + USE_VAR(itext); +#endif + USE_VAR(list); + USE_VAR(ps2); + USE_VAR(lastsig); + + sigalrm_seen = reading = tty_modified = 0; + + i = 0; /* Index into the string that we are reading. */ + raw = edit = 0; /* Not reading raw input by default. */ + silent = 0; + arrayname = prompt = (char *)NULL; + fd = 0; /* file descriptor to read from */ + +#if defined (READLINE) + rlbuf = itext = (char *)0; + rlind = 0; +#endif + + mb_cur_max = MB_CUR_MAX; + tmsec = tmusec = 0; /* no timeout */ + nr = nchars = input_is_tty = input_is_pipe = unbuffered_read = have_timeout = 0; + delim = '\n'; /* read until newline */ + ignore_delim = nflag = 0; + + reset_internal_getopt (); + while ((opt = internal_getopt (list, "ersa:d:i:n:p:t:u:N:")) != -1) + { + switch (opt) + { + case 'r': + raw = 1; + break; + case 'p': + prompt = list_optarg; + break; + case 's': + silent = 1; + break; + case 'e': +#if defined (READLINE) + edit = 1; +#endif + break; + case 'i': +#if defined (READLINE) + itext = list_optarg; +#endif + break; +#if defined (ARRAY_VARS) + case 'a': + arrayname = list_optarg; + break; +#endif + case 't': + code = uconvert (list_optarg, &ival, &uval, (char **)NULL); + if (code == 0 || ival < 0 || uval < 0) + { + builtin_error (_("%s: invalid timeout specification"), list_optarg); + return (EXECUTION_FAILURE); + } + else + { + have_timeout = 1; + tmsec = ival; + tmusec = uval; + } + break; + case 'N': + ignore_delim = 1; + delim = -1; + case 'n': + nflag = 1; + code = legal_number (list_optarg, &intval); + if (code == 0 || intval < 0 || intval != (int)intval) + { + sh_invalidnum (list_optarg); + return (EXECUTION_FAILURE); + } + else + nchars = intval; + break; + case 'u': + code = legal_number (list_optarg, &intval); + if (code == 0 || intval < 0 || intval != (int)intval) + { + builtin_error (_("%s: invalid file descriptor specification"), list_optarg); + return (EXECUTION_FAILURE); + } + else + fd = intval; + if (sh_validfd (fd) == 0) + { + builtin_error (_("%d: invalid file descriptor: %s"), fd, strerror (errno)); + return (EXECUTION_FAILURE); + } + break; + case 'd': + delim = *list_optarg; + break; + CASE_HELPOPT; + default: + builtin_usage (); + return (EX_USAGE); + } + } + list = loptend; + + /* `read -t 0 var' tests whether input is available with select/FIONREAD, + and fails if those are unavailable */ + if (have_timeout && tmsec == 0 && tmusec == 0) +#if 0 + return (EXECUTION_FAILURE); +#else + return (input_avail (fd) ? EXECUTION_SUCCESS : EXECUTION_FAILURE); +#endif + + /* Convenience: check early whether or not the first of possibly several + variable names is a valid identifier, and bail early if so. */ +#if defined (ARRAY_VARS) + vflags = assoc_expand_once ? (VA_NOEXPAND|VA_ONEWORD) : 0; + if (list && legal_identifier (list->word->word) == 0 && valid_array_reference (list->word->word, vflags) == 0) +#else + if (list && legal_identifier (list->word->word) == 0) +#endif + { + sh_invalidid (list->word->word); + return (EXECUTION_FAILURE); + } + + /* If we're asked to ignore the delimiter, make sure we do. */ + if (ignore_delim) + delim = -1; + + /* IF IFS is unset, we use the default of " \t\n". */ + ifs_chars = getifs (); + if (ifs_chars == 0) /* XXX - shouldn't happen */ + ifs_chars = ""; + /* If we want to read exactly NCHARS chars, don't split on IFS */ + if (ignore_delim) + ifs_chars = ""; + for (skip_ctlesc = skip_ctlnul = 0, e = ifs_chars; *e; e++) + skip_ctlesc |= *e == CTLESC, skip_ctlnul |= *e == CTLNUL; + + input_string = (char *)xmalloc (size = 112); /* XXX was 128 */ + input_string[0] = '\0'; + + /* More input and options validation */ + if (nflag == 1 && nchars == 0) + { + retval = read (fd, &c, 0); + retval = (retval >= 0) ? EXECUTION_SUCCESS : EXECUTION_FAILURE; + goto assign_vars; /* bail early if asked to read 0 chars */ + } + + /* $TMOUT, if set, is the default timeout for read. */ + if (have_timeout == 0 && (e = get_string_value ("TMOUT"))) + { + code = uconvert (e, &ival, &uval, (char **)NULL); + if (code == 0 || ival < 0 || uval < 0) + tmsec = tmusec = 0; + else + { + tmsec = ival; + tmusec = uval; + } + } + + begin_unwind_frame ("read_builtin"); + +#if defined (BUFFERED_INPUT) + if (interactive == 0 && default_buffered_input >= 0 && fd_is_bash_input (fd)) + sync_buffered_stream (default_buffered_input); +#endif + +#if 1 + input_is_tty = isatty (fd); +#else + input_is_tty = 1; +#endif + if (input_is_tty == 0) +#ifndef __CYGWIN__ + input_is_pipe = (lseek (fd, 0L, SEEK_CUR) < 0) && (errno == ESPIPE); +#else + input_is_pipe = 1; +#endif + + /* If the -p, -e or -s flags were given, but input is not coming from the + terminal, turn them off. */ + if ((prompt || edit || silent) && input_is_tty == 0) + { + prompt = (char *)NULL; +#if defined (READLINE) + itext = (char *)NULL; +#endif + edit = silent = 0; + } + +#if defined (READLINE) + if (edit) + add_unwind_protect (xfree, rlbuf); +#endif + + pass_next = 0; /* Non-zero signifies last char was backslash. */ + saw_escape = 0; /* Non-zero signifies that we saw an escape char */ + + if (tmsec > 0 || tmusec > 0) + { + /* Turn off the timeout if stdin is a regular file (e.g. from + input redirection). */ + if ((fstat (fd, &tsb) < 0) || S_ISREG (tsb.st_mode)) + tmsec = tmusec = 0; + } + + if (tmsec > 0 || tmusec > 0) + { + code = setjmp_nosigs (alrmbuf); + if (code) + { + sigalrm_seen = 0; + /* Tricky. The top of the unwind-protect stack is the free of + input_string. We want to run all the rest and use input_string, + so we have to save input_string temporarily, run the unwind- + protects, then restore input_string so we can use it later */ + orig_input_string = 0; + input_string[i] = '\0'; /* make sure it's terminated */ + if (i == 0) + { + t = (char *)xmalloc (1); + t[0] = 0; + } + else + t = savestring (input_string); + + run_unwind_frame ("read_builtin"); + input_string = t; + retval = 128+SIGALRM; + goto assign_vars; + } + if (interactive_shell == 0) + initialize_terminating_signals (); + old_alrm = set_signal_handler (SIGALRM, sigalrm); + add_unwind_protect (reset_alarm, (char *)NULL); +#if defined (READLINE) + if (edit) + { + add_unwind_protect (reset_attempted_completion_function, (char *)NULL); + add_unwind_protect (bashline_reset_event_hook, (char *)NULL); + } +#endif + falarm (tmsec, tmusec); + } + + /* If we've been asked to read only NCHARS chars, or we're using some + character other than newline to terminate the line, do the right + thing to readline or the tty. */ + if (nchars > 0 || delim != '\n') + { +#if defined (READLINE) + if (edit) + { + if (nchars > 0) + { + unwind_protect_int (rl_num_chars_to_read); + rl_num_chars_to_read = nchars; + } + if (delim != '\n') + { + set_eol_delim (delim); + add_unwind_protect (reset_eol_delim, (char *)NULL); + } + } + else +#endif + if (input_is_tty) + { + /* ttsave() */ + termsave.fd = fd; + ttgetattr (fd, &ttattrs); + termsave.attrs = ttattrs; + + ttset = ttattrs; + i = silent ? ttfd_cbreak (fd, &ttset) : ttfd_onechar (fd, &ttset); + if (i < 0) + sh_ttyerror (1); + tty_modified = 1; + add_unwind_protect ((Function *)ttyrestore, (char *)&termsave); + if (interactive_shell == 0) + initialize_terminating_signals (); + } + } + else if (silent) /* turn off echo but leave term in canonical mode */ + { + /* ttsave (); */ + termsave.fd = fd; + ttgetattr (fd, &ttattrs); + termsave.attrs = ttattrs; + + ttset = ttattrs; + i = ttfd_noecho (fd, &ttset); /* ttnoecho (); */ + if (i < 0) + sh_ttyerror (1); + + tty_modified = 1; + add_unwind_protect ((Function *)ttyrestore, (char *)&termsave); + if (interactive_shell == 0) + initialize_terminating_signals (); + } + +#if defined (READLINE) + save_instream = 0; + if (edit && fd != 0) + { + if (bash_readline_initialized == 0) + initialize_readline (); + + unwind_protect_var (rl_instream); + save_instream = rl_instream; + rl_instream = fdopen (fd, "r"); + } +#endif + + /* This *must* be the top unwind-protect on the stack, so the manipulation + of the unwind-protect stack after the realloc() works right. */ + add_unwind_protect (xfree, input_string); + + CHECK_ALRM; + if ((nchars > 0) && (input_is_tty == 0) && ignore_delim) /* read -N */ + unbuffered_read = 2; + else if ((nchars > 0) || (delim != '\n') || input_is_pipe) + unbuffered_read = 1; + + if (prompt && edit == 0) + { + fprintf (stderr, "%s", prompt); + fflush (stderr); + } + +#if defined (__CYGWIN__) && defined (O_TEXT) + setmode (0, O_TEXT); +#endif + + ps2 = 0; + for (print_ps2 = eof = retval = 0;;) + { + CHECK_ALRM; + +#if defined (READLINE) + if (edit) + { + /* If we have a null delimiter, don't treat NULL as ending the line */ + if (rlbuf && rlbuf[rlind] == '\0' && delim != '\0') + { + free (rlbuf); + rlbuf = (char *)0; + } + if (rlbuf == 0) + { + reading = 1; + rlbuf = edit_line (prompt ? prompt : "", itext); + reading = 0; + rlind = 0; + } + if (rlbuf == 0) + { + eof = 1; + break; + } + c = rlbuf[rlind++]; + } + else + { +#endif + + if (print_ps2) + { + if (ps2 == 0) + ps2 = get_string_value ("PS2"); + fprintf (stderr, "%s", ps2 ? ps2 : ""); + fflush (stderr); + print_ps2 = 0; + } + + reading = 1; + CHECK_ALRM; + errno = 0; + if (unbuffered_read == 2) + retval = posixly_correct ? zreadintr (fd, &c, 1) : zreadn (fd, &c, nchars - nr); + else if (unbuffered_read) + retval = posixly_correct ? zreadintr (fd, &c, 1) : zread (fd, &c, 1); + else + retval = posixly_correct ? zreadcintr (fd, &c) : zreadc (fd, &c); + reading = 0; + + if (retval <= 0) + { + int t; + + t = errno; + if (retval < 0 && errno == EINTR) + { + check_signals (); /* in case we didn't call zread via zreadc */ + lastsig = LASTSIG(); + if (lastsig == 0) + lastsig = trapped_signal_received; +#if 0 + run_pending_traps (); /* because interrupt_immediately is not set */ +#endif + } + else + lastsig = 0; + if (terminating_signal && tty_modified) + ttyrestore (&termsave); /* fix terminal before exiting */ + CHECK_TERMSIG; + eof = 1; + errno = t; /* preserve it for the error message below */ + break; + } + + QUIT; /* in case we didn't call check_signals() */ +#if defined (READLINE) + } +#endif + + if (retval <= 0) /* XXX shouldn't happen */ + CHECK_ALRM; + + /* XXX -- use i + mb_cur_max (at least 4) for multibyte/read_mbchar */ + if (i + (mb_cur_max > 4 ? mb_cur_max : 4) >= size) + { + char *t; + t = (char *)xrealloc (input_string, size += 128); + + /* Only need to change unwind-protect if input_string changes */ + if (t != input_string) + { + input_string = t; + remove_unwind_protect (); + add_unwind_protect (xfree, input_string); + } + } + + /* If the next character is to be accepted verbatim, a backslash + newline pair still disappears from the input. */ + if (pass_next) + { + pass_next = 0; + if (c == '\n') + { + if (skip_ctlesc == 0 && i > 0) + i--; /* back up over the CTLESC */ + if (interactive && input_is_tty && raw == 0) + print_ps2 = 1; + } + else + goto add_char; + continue; + } + + /* This may cause problems if IFS contains CTLESC */ + if (c == '\\' && raw == 0) + { + pass_next++; + if (skip_ctlesc == 0) + { + saw_escape++; + input_string[i++] = CTLESC; + } + continue; + } + + if (ignore_delim == 0 && (unsigned char)c == delim) + break; + + if (c == '\0' && delim != '\0') + continue; /* skip NUL bytes in input */ + + if ((skip_ctlesc == 0 && c == CTLESC) || (skip_ctlnul == 0 && c == CTLNUL)) + { + saw_escape++; + input_string[i++] = CTLESC; + } + +add_char: + input_string[i++] = c; + CHECK_ALRM; + +#if defined (HANDLE_MULTIBYTE) + /* XXX - what if C == 127? Can DEL introduce a multibyte sequence? */ + if (mb_cur_max > 1 && is_basic (c) == 0) + { + input_string[i] = '\0'; /* for simplicity and debugging */ + /* If we got input from readline, grab the next multibyte char from + rlbuf. */ +# if defined (READLINE) + if (edit) + { + size_t clen; + clen = mbrlen (rlbuf + rlind - 1, mb_cur_max, (mbstate_t *)NULL); + /* We only deal with valid multibyte sequences longer than one + byte. If we get anything else, we leave the one character + copied and move on to the next. */ + if ((int)clen > 1) + { + memcpy (input_string+i, rlbuf+rlind, clen-1); + i += clen - 1; + rlind += clen - 1; + } + } + else +# endif + if (locale_utf8locale == 0 || ((c & 0x80) != 0)) + i += read_mbchar (fd, input_string, i, c, unbuffered_read); + } +#endif + + nr++; + + if (nchars > 0 && nr >= nchars) + break; + } + input_string[i] = '\0'; + CHECK_ALRM; + +#if defined (READLINE) + if (edit) + free (rlbuf); +#endif + + if (retval < 0) + { + t_errno = errno; + if (errno != EINTR) + builtin_error (_("read error: %d: %s"), fd, strerror (errno)); + run_unwind_frame ("read_builtin"); + return ((t_errno != EINTR) ? EXECUTION_FAILURE : 128+lastsig); + } + + if (tmsec > 0 || tmusec > 0) + reset_alarm (); + + if (nchars > 0 || delim != '\n') + { +#if defined (READLINE) + if (edit) + { + if (nchars > 0) + rl_num_chars_to_read = 0; + if (delim != '\n') + reset_eol_delim ((char *)NULL); + } + else +#endif + if (input_is_tty) + ttyrestore (&termsave); + } + else if (silent) + ttyrestore (&termsave); + + if (unbuffered_read == 0) + zsyncfd (fd); + +#if defined (READLINE) + if (save_instream) + rl_instream = save_instream; /* can't portably free it */ +#endif + + discard_unwind_frame ("read_builtin"); + + retval = eof ? EXECUTION_FAILURE : EXECUTION_SUCCESS; + +assign_vars: + +#if defined (ARRAY_VARS) + /* If -a was given, take the string read, break it into a list of words, + an assign them to `arrayname' in turn. */ + if (arrayname) + { + if (legal_identifier (arrayname) == 0) + { + sh_invalidid (arrayname); + free (input_string); + return (EXECUTION_FAILURE); + } + + var = find_or_make_array_variable (arrayname, 1); + if (var == 0) + { + free (input_string); + return EXECUTION_FAILURE; /* readonly or noassign */ + } + if (assoc_p (var)) + { + builtin_error (_("%s: cannot convert associative to indexed array"), arrayname); + free (input_string); + return EXECUTION_FAILURE; /* existing associative array */ + } + else if (invisible_p (var)) + VUNSETATTR (var, att_invisible); + array_flush (array_cell (var)); + + alist = list_string (input_string, ifs_chars, 0); + if (alist) + { + if (saw_escape) + dequote_list (alist); + else + word_list_remove_quoted_nulls (alist); + assign_array_var_from_word_list (var, alist, 0); + dispose_words (alist); + } + free (input_string); + return (retval); + } +#endif /* ARRAY_VARS */ + + /* If there are no variables, save the text of the line read to the + variable $REPLY. ksh93 strips leading and trailing IFS whitespace, + so that `read x ; echo "$x"' and `read ; echo "$REPLY"' behave the + same way, but I believe that the difference in behaviors is useful + enough to not do it. Without the bash behavior, there is no way + to read a line completely without interpretation or modification + unless you mess with $IFS (e.g., setting it to the empty string). + If you disagree, change the occurrences of `#if 0' to `#if 1' below. */ + if (list == 0) + { +#if 0 + orig_input_string = input_string; + for (t = input_string; ifs_chars && *ifs_chars && spctabnl(*t) && isifs(*t); t++) + ; + input_string = t; + input_string = strip_trailing_ifs_whitespace (input_string, ifs_chars, saw_escape); +#endif + + if (saw_escape) + { + t = dequote_string (input_string); + var = bind_variable ("REPLY", t, 0); + free (t); + } + else + var = bind_variable ("REPLY", input_string, 0); + if (var == 0 || readonly_p (var) || noassign_p (var)) + retval = EXECUTION_FAILURE; + else + VUNSETATTR (var, att_invisible); + + free (input_string); + return (retval); + } + + /* This code implements the Posix.2 spec for splitting the words + read and assigning them to variables. */ + orig_input_string = input_string; + + /* Remove IFS white space at the beginning of the input string. If + $IFS is null, no field splitting is performed. */ + for (t = input_string; ifs_chars && *ifs_chars && spctabnl(*t) && isifs(*t); t++) + ; + input_string = t; + for (; list->next; list = list->next) + { + varname = list->word->word; +#if defined (ARRAY_VARS) + if (legal_identifier (varname) == 0 && valid_array_reference (varname, vflags) == 0) +#else + if (legal_identifier (varname) == 0) +#endif + { + sh_invalidid (varname); + free (orig_input_string); + return (EXECUTION_FAILURE); + } + + /* If there are more variables than words read from the input, + the remaining variables are set to the empty string. */ + if (*input_string) + { + /* This call updates INPUT_STRING. */ + t = get_word_from_string (&input_string, ifs_chars, &e); + if (t) + *e = '\0'; + /* Don't bother to remove the CTLESC unless we added one + somewhere while reading the string. */ + if (t && saw_escape) + { + t1 = dequote_string (t); + var = bind_read_variable (varname, t1); + free (t1); + } + else + var = bind_read_variable (varname, t ? t : ""); + } + else + { + t = (char *)0; + var = bind_read_variable (varname, ""); + } + + FREE (t); + if (var == 0) + { + free (orig_input_string); + return (EXECUTION_FAILURE); + } + + stupidly_hack_special_variables (varname); + VUNSETATTR (var, att_invisible); + } + + /* Now assign the rest of the line to the last variable argument. */ +#if defined (ARRAY_VARS) + if (legal_identifier (list->word->word) == 0 && valid_array_reference (list->word->word, vflags) == 0) +#else + if (legal_identifier (list->word->word) == 0) +#endif + { + sh_invalidid (list->word->word); + free (orig_input_string); + return (EXECUTION_FAILURE); + } + +#if 0 + /* This has to be done this way rather than using string_list + and list_string because Posix.2 says that the last variable gets the + remaining words and their intervening separators. */ + input_string = strip_trailing_ifs_whitespace (input_string, ifs_chars, saw_escape); +#else + /* Check whether or not the number of fields is exactly the same as the + number of variables. */ + tofree = NULL; + if (*input_string) + { + t1 = input_string; + t = get_word_from_string (&input_string, ifs_chars, &e); + if (*input_string == 0) + tofree = input_string = t; + else + { + input_string = strip_trailing_ifs_whitespace (t1, ifs_chars, saw_escape); + tofree = t; + } + } +#endif + + if (saw_escape && input_string && *input_string) + { + t = dequote_string (input_string); + var = bind_read_variable (list->word->word, t); + free (t); + } + else + var = bind_read_variable (list->word->word, input_string ? input_string : ""); + + if (var) + { + stupidly_hack_special_variables (list->word->word); + VUNSETATTR (var, att_invisible); + } + else + retval = EXECUTION_FAILURE; + + FREE (tofree); + free (orig_input_string); + + return (retval); +} + +static SHELL_VAR * +bind_read_variable (name, value) + char *name, *value; +{ + SHELL_VAR *v; + + v = builtin_bind_variable (name, value, 0); + return (v == 0 ? v + : ((readonly_p (v) || noassign_p (v)) ? (SHELL_VAR *)NULL : v)); +} + +#if defined (HANDLE_MULTIBYTE) +static int +read_mbchar (fd, string, ind, ch, unbuffered) + int fd; + char *string; + int ind, ch, unbuffered; +{ + char mbchar[MB_LEN_MAX + 1]; + int i, n, r; + char c; + size_t ret; + mbstate_t ps, ps_back; + wchar_t wc; + + memset (&ps, '\0', sizeof (mbstate_t)); + memset (&ps_back, '\0', sizeof (mbstate_t)); + + mbchar[0] = ch; + i = 1; + for (n = 0; n <= MB_LEN_MAX; n++) + { + ps_back = ps; + ret = mbrtowc (&wc, mbchar, i, &ps); + if (ret == (size_t)-2) + { + ps = ps_back; + + /* We don't want to be interrupted during a multibyte char read */ + if (unbuffered == 2) + r = zreadn (fd, &c, 1); + else if (unbuffered) + r = zread (fd, &c, 1); + else + r = zreadc (fd, &c); + if (r <= 0) + goto mbchar_return; + mbchar[i++] = c; + continue; + } + else if (ret == (size_t)-1 || ret == (size_t)0 || ret > (size_t)0) + break; + } + +mbchar_return: + if (i > 1) /* read a multibyte char */ + /* mbchar[0] is already string[ind-1] */ + for (r = 1; r < i; r++) + string[ind+r-1] = mbchar[r]; + return i - 1; +} +#endif + + +static void +ttyrestore (ttp) + struct ttsave *ttp; +{ + ttsetattr (ttp->fd, &(ttp->attrs)); + tty_modified = 0; } void -read_tty_cleanup () +__read_tty_cleanup () { - ; + if (tty_modified) + ttyrestore (&termsave); } int -read_tty_modified () +__read_tty_modified () +{ + return (tty_modified); +} + +#if defined (READLINE) +static rl_completion_func_t *old_attempted_completion_function = 0; +static rl_hook_func_t *old_startup_hook; +static char *deftext; + +static void +reset_attempted_completion_function (cp) + char *cp; +{ + if (rl_attempted_completion_function == 0 && old_attempted_completion_function) + rl_attempted_completion_function = old_attempted_completion_function; +} + +static int +set_itext () +{ + int r1, r2; + + r1 = r2 = 0; + if (old_startup_hook) + r1 = (*old_startup_hook) (); + if (deftext) + { + r2 = rl_insert_text (deftext); + deftext = (char *)NULL; + rl_startup_hook = old_startup_hook; + old_startup_hook = (rl_hook_func_t *)NULL; + } + return (r1 || r2); +} + +static char * +edit_line (p, itext) + char *p; + char *itext; +{ + char *ret; + int len; + + if (bash_readline_initialized == 0) + initialize_readline (); + + old_attempted_completion_function = rl_attempted_completion_function; + rl_attempted_completion_function = (rl_completion_func_t *)NULL; + bashline_set_event_hook (); + if (itext) + { + old_startup_hook = rl_startup_hook; + rl_startup_hook = set_itext; + deftext = itext; + } + + ret = readline (p); + + rl_attempted_completion_function = old_attempted_completion_function; + old_attempted_completion_function = (rl_completion_func_t *)NULL; + bashline_reset_event_hook (); + + if (ret == 0) + return ret; + len = strlen (ret); + ret = (char *)xrealloc (ret, len + 2); + ret[len++] = delim; + ret[len] = '\0'; + return ret; +} + +static int old_delim_ctype; +static rl_command_func_t *old_delim_func; +static int old_newline_ctype; +static rl_command_func_t *old_newline_func; + +static unsigned char delim_char; + +static void +set_eol_delim (c) + int c; { - return 0; + Keymap cmap; + + if (bash_readline_initialized == 0) + initialize_readline (); + cmap = rl_get_keymap (); + + /* Save the old delimiter char binding */ + old_newline_ctype = cmap[RETURN].type; + old_newline_func = cmap[RETURN].function; + old_delim_ctype = cmap[c].type; + old_delim_func = cmap[c].function; + + /* Change newline to self-insert */ + cmap[RETURN].type = ISFUNC; + cmap[RETURN].function = rl_insert; + + /* Bind the delimiter character to accept-line. */ + cmap[c].type = ISFUNC; + cmap[c].function = rl_newline; + + delim_char = c; } +static void +reset_eol_delim (cp) + char *cp; +{ + Keymap cmap; + + cmap = rl_get_keymap (); + + cmap[RETURN].type = old_newline_ctype; + cmap[RETURN].function = old_newline_func; + + cmap[delim_char].type = old_delim_ctype; + cmap[delim_char].function = old_delim_func; +} +#endif diff --git a/bash-5.1/builtins_rust/alias/Cargo.toml b/bash-5.1/builtins_rust/alias/Cargo.toml index e69de29b..339bc539 100644 --- a/bash-5.1/builtins_rust/alias/Cargo.toml +++ b/bash-5.1/builtins_rust/alias/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "alias" +version = "0.1.0" +edition = "2021" +authors = ["liutong"] + + +[lib] +name = "ralias" +crate-type = ["staticlib"] + +[dependencies] +libc = "0.2" +# nix = "0.23" diff --git a/bash-5.1/builtins_rust/alias/src/lib.rs b/bash-5.1/builtins_rust/alias/src/lib.rs index e69de29b..3e02eb74 100644 --- a/bash-5.1/builtins_rust/alias/src/lib.rs +++ b/bash-5.1/builtins_rust/alias/src/lib.rs @@ -0,0 +1,233 @@ + +use std::ffi::CStr; +extern "C" { + fn free(__ptr: *mut libc::c_void); + fn dcgettext( + __domainname: *const libc::c_char, + __msgid: *const libc::c_char, + __category: libc::c_int, + ) -> *mut libc::c_char; + fn printf(_: *const libc::c_char, _: ...) -> libc::c_int; + fn legal_alias_name(_: *const libc::c_char, _: libc::c_int) -> libc::c_int; + fn sh_single_quote(_: *const libc::c_char) -> *mut libc::c_char; + static mut posixly_correct: libc::c_int; + static mut aliases: *mut HASH_TABLE; + fn find_alias(_: *mut libc::c_char) -> *mut alias_t; + fn add_alias(_: *mut libc::c_char, _: *mut libc::c_char); + fn remove_alias(_: *mut libc::c_char) -> libc::c_int; + fn delete_all_aliases(); + fn all_aliases() -> *mut *mut alias_t; + fn builtin_error(_: *const libc::c_char, _: ...); + fn builtin_usage(); + fn sh_notfound(_: *mut libc::c_char); + fn sh_chkwrite(_: libc::c_int) -> libc::c_int; + fn builtin_help(); + static mut loptend: *mut WORD_LIST; + fn internal_getopt(_: *mut WORD_LIST, _: *mut libc::c_char) -> libc::c_int; + fn reset_internal_getopt(); +} +pub type size_t = libc::c_ulong; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct word_desc { + pub word: *mut libc::c_char, + pub flags: libc::c_int, +} +pub type WORD_DESC = word_desc; +#[derive(Copy, Clone)] +#[repr(C)] +pub struct word_list { + pub next: *mut word_list, + pub word: *mut WORD_DESC, +} +pub type WORD_LIST = word_list; +#[derive(Copy, Clone)] +#[repr(C)] +pub struct bucket_contents { + pub next: *mut bucket_contents, + pub key: *mut libc::c_char, + pub data: *mut libc::c_void, + pub khash: libc::c_uint, + pub times_found: libc::c_int, +} +pub type BUCKET_CONTENTS = bucket_contents; +#[derive(Copy, Clone)] +#[repr(C)] +pub struct hash_table { + pub bucket_array: *mut *mut BUCKET_CONTENTS, + pub nbuckets: libc::c_int, + pub nentries: libc::c_int, +} +pub type HASH_TABLE = hash_table; +#[derive(Copy, Clone)] +#[repr(C)] +pub struct alias { + pub name: *mut libc::c_char, + pub value: *mut libc::c_char, + pub flags: libc::c_char, +} +pub type alias_t = alias; +#[no_mangle] +pub unsafe extern "C" fn r_alias_builtin(mut list: *mut WORD_LIST) -> libc::c_int { + println!("alias_builtin run!"); + let mut any_failed: libc::c_int = 0; + let mut offset: libc::c_int = 0; + let mut pflag: libc::c_int = 0; + let mut dflags: libc::c_int = 0; + let mut alias_list: *mut *mut alias_t = 0 as *mut *mut alias_t; + let mut t: *mut alias_t = 0 as *mut alias_t; + let mut name: *mut libc::c_char = 0 as *mut libc::c_char; + let mut value: *mut libc::c_char = 0 as *mut libc::c_char; + dflags = if posixly_correct != 0 { 0 as libc::c_int } else { 0x1 as libc::c_int }; + pflag = 0 as libc::c_int; + reset_internal_getopt(); + loop { + offset = internal_getopt( + list, + b"p\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + ); + if !(offset != -(1 as libc::c_int)) { + break; + } + match offset as u8 { + b'p' => { + pflag = 1 as libc::c_int; + dflags |= 0x1 as libc::c_int; + } + _ => { + builtin_usage(); + return 258 as libc::c_int; + } + } + } + list = loptend; + if list.is_null() || pflag != 0 { + if aliases.is_null() { + return 0 as libc::c_int; + } + alias_list = all_aliases(); + if alias_list.is_null() { + return 0 as libc::c_int; + } + offset = 0 as libc::c_int; + while !(*alias_list.offset(offset as isize)).is_null() { + print_alias(*alias_list.offset(offset as isize), dflags); + offset += 1; + } + free(alias_list as *mut libc::c_void); + if list.is_null() { + return sh_chkwrite(0 as libc::c_int); + } + } + any_failed = 0 as libc::c_int; + while !list.is_null() { + name = (*(*list).word).word; + offset = 0 as libc::c_int; + while *name.offset(offset as isize) as libc::c_int != 0 + && *name.offset(offset as isize) as libc::c_int != '=' as i32 + { + offset += 1; + } + if offset != 0 && *name.offset(offset as isize) as libc::c_int == '=' as i32 { + *name.offset(offset as isize) = '\u{0}' as i32 as libc::c_char; + value = name.offset(offset as isize).offset(1 as libc::c_int as isize); + if legal_alias_name(name, 0 as libc::c_int) == 0 as libc::c_int { + builtin_error( + dcgettext( + 0 as *const libc::c_char, + b"`%s': invalid alias name\0" as *const u8 + as *const libc::c_char, + 5 as libc::c_int, + ), + name, + ); + any_failed += 1; + } else { + add_alias(name, value); + } + } else { + t = find_alias(name); + if !t.is_null() { + print_alias(t, dflags); + } else { + sh_notfound(name); + any_failed += 1; + } + } + list = (*list).next; + } + return if any_failed != 0 { 1 as libc::c_int } else { 0 as libc::c_int }; +} +#[no_mangle] +pub unsafe extern "C" fn r_unalias_builtin(mut list: *mut WORD_LIST) -> libc::c_int { + let mut alias: *mut alias_t = 0 as *mut alias_t; + let mut opt: libc::c_int = 0; + let mut aflag: libc::c_int = 0; + aflag = 0 as libc::c_int; + reset_internal_getopt(); + loop { + opt = internal_getopt( + list, + b"a\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + ); + if !(opt != -(1 as libc::c_int)) { + break; + } + match opt { + 97 => { + aflag = 1 as libc::c_int; + } + -99 => { + builtin_help(); + return 258 as libc::c_int; + } + _ => { + builtin_usage(); + return 258 as libc::c_int; + } + } + } + list = loptend; + if aflag != 0 { + delete_all_aliases(); + return 0 as libc::c_int; + } + if list.is_null() { + builtin_usage(); + return 258 as libc::c_int; + } + aflag = 0 as libc::c_int; + while !list.is_null() { + alias = find_alias((*(*list).word).word); + if !alias.is_null() { + remove_alias((*alias).name); + } else { + sh_notfound((*(*list).word).word); + aflag += 1; + } + list = (*list).next; + } + return if aflag != 0 { 1 as libc::c_int } else { 0 as libc::c_int }; +} +unsafe extern "C" fn print_alias(mut alias: *mut alias_t, mut flags: libc::c_int) { + let mut value: *mut libc::c_char = 0 as *mut libc::c_char; + value = sh_single_quote((*alias).value); + if flags & 0x1 as libc::c_int != 0 { + printf( + b"alias %s\0" as *const u8 as *const libc::c_char, + if !((*alias).name).is_null() + && *((*alias).name).offset(0 as libc::c_int as isize) as libc::c_int + == '-' as i32 + { + b"-- \0" as *const u8 as *const libc::c_char + } else { + b"\0" as *const u8 as *const libc::c_char + }, + ); + } + + println!("{}={}", CStr::from_ptr((*alias).name).to_string_lossy().into_owned(), CStr::from_ptr(value).to_string_lossy().into_owned()); + free(value as *mut libc::c_void); + +} diff --git a/bash-5.1/builtins_rust/build.rs b/bash-5.1/builtins_rust/build.rs index 5b554493..f062a48e 100644 --- a/bash-5.1/builtins_rust/build.rs +++ b/bash-5.1/builtins_rust/build.rs @@ -5,179 +5,17 @@ fn main() { let library_dir = "/opt/rsbash/builtins"; + let libsh_dir = "./lib/sh/"; + let exe_dir = "/opt/rsbash/"; - println!("cargo:rustc-link-search=native={}", env::join_paths(&[library_dir]).unwrap().to_str().unwrap()); + println!("cargo:rustc-link-search=native={}", env::join_paths(&[library_dir ]).unwrap().to_str().unwrap()); + println!("cargo:rustc-link-search=native={}", env::join_paths(&[ exe_dir]).unwrap().to_str().unwrap()); + println!("cargo:rustc-link-search=native={}", env::join_paths(&[ libsh_dir]).unwrap().to_str().unwrap()); - println!("cargo:rustc-flags=-l dylib=jobs"); - println!("cargo:rustc-flags=-l dylib=trap"); - println!("cargo:rustc-flags=-l dylib=execute_cmd"); - println!("cargo:rustc-flags=-l dylib=unwind_prot"); - println!("cargo:rustc-flags=-l dylib=flags"); - println!("cargo:rustc-flags=-l dylib=variables"); - println!("cargo:rustc-flags=-l dylib=builtins_break"); - println!("cargo:rustc-flags=-l dylib=builtins_common"); - println!("cargo:rustc-flags=-l dylib=sig"); - println!("cargo:rustc-flags=-l dylib=builtins_wait"); - println!("cargo:rustc-flags=-l dylib=shell"); - println!("cargo:rustc-flags=-l dylib=input"); - println!("cargo:rustc-flags=-l dylib=xmalloc"); - println!("cargo:rustc-flags=-l dylib=version"); - println!("cargo:rustc-flags=-l dylib=error"); - println!("cargo:rustc-flags=-l dylib=subst"); - println!("cargo:rustc-flags=-l dylib=lib_sh_winsize"); - println!("cargo:rustc-flags=-l dylib=dispose_cmd"); - println!("cargo:rustc-flags=-l dylib=lib_readline_readline"); - println!("cargo:rustc-flags=-l dylib=general"); - println!("cargo:rustc-flags=-l dylib=lib_sh_oslib"); - println!("cargo:rustc-flags=-l dylib=list"); - println!("cargo:rustc-flags=-l dylib=builtins_evalstring"); - println!("cargo:rustc-flags=-l dylib=y.tab"); - println!("cargo:rustc-flags=-l dylib=builtins_evalfile"); - println!("cargo:rustc-flags=-l dylib=lib_sh_casemod"); - println!("cargo:rustc-flags=-l dylib=lib_sh_fmtulong"); - println!("cargo:rustc-flags=-l dylib=builtins_set"); - println!("cargo:rustc-flags=-l dylib=lib_readline_history"); - println!("cargo:rustc-flags=-l dylib=mailcheck"); - println!("cargo:rustc-flags=-l dylib=bashhist"); - println!("cargo:rustc-flags=-l dylib=bashline"); - println!("cargo:rustc-flags=-l dylib=assoc"); - println!("cargo:rustc-flags=-l dylib=builtins_shopt"); - println!("cargo:rustc-flags=-l dylib=lib_readline_histfile"); - println!("cargo:rustc-flags=-l dylib=hashlib"); - println!("cargo:rustc-flags=-l dylib=print_cmd"); - println!("cargo:rustc-flags=-l dylib=copy_cmd"); - println!("cargo:rustc-flags=-l dylib=hashcmd"); - println!("cargo:rustc-flags=-l dylib=pathexp"); - println!("cargo:rustc-flags=-l dylib=lib_sh_random"); - println!("cargo:rustc-flags=-l dylib=findcmd"); - println!("cargo:rustc-flags=-l dylib=arrayfunc"); - println!("cargo:rustc-flags=-l dylib=lib_readline_terminal"); - println!("cargo:rustc-flags=-l dylib=array"); - println!("cargo:rustc-flags=-l dylib=lib_readline_complete"); - println!("cargo:rustc-flags=-l dylib=alias"); - println!("cargo:rustc-flags=-l dylib=builtins_getopt"); - println!("cargo:rustc-flags=-l dylib=locale"); - println!("cargo:rustc-flags=-l dylib=lib_readline_shell"); - println!("cargo:rustc-flags=-l dylib=lib_sh_stringvec"); - println!("cargo:rustc-flags=-l dylib=lib_sh_itos"); - println!("cargo:rustc-flags=-l dylib=pcomplete"); - println!("cargo:rustc-flags=-l dylib=lib_sh_strtrans"); - println!("cargo:rustc-flags=-l dylib=lib_readline_histexpand"); - println!("cargo:rustc-flags=-l dylib=lib_sh_shquote"); - println!("cargo:rustc-flags=-l dylib=builtins_pushd"); - println!("cargo:rustc-flags=-l dylib=redir"); - println!("cargo:rustc-flags=-l dylib=lib_sh_pathcanon"); - println!("cargo:rustc-flags=-l dylib=builtins_getopts"); - println!("cargo:rustc-flags=-l dylib=lib_readline_colors"); - println!("cargo:rustc-flags=-l dylib=lib_readline_mbutil"); - println!("cargo:rustc-flags=-l dylib=lib_readline_signals"); - println!("cargo:rustc-flags=-l dylib=lib_readline_text"); - println!("cargo:rustc-flags=-l dylib=lib_readline_parse-colors"); - println!("cargo:rustc-flags=-l dylib=lib_readline_display"); - println!("cargo:rustc-flags=-l dylib=lib_readline_util"); - println!("cargo:rustc-flags=-l dylib=lib_glob_xmbsrtowcs"); - println!("cargo:rustc-flags=-l dylib=lib_glob_gmisc"); - println!("cargo:rustc-flags=-l dylib=lib_sh_shmbchar"); - println!("cargo:rustc-flags=-l dylib=make_cmd"); - println!("cargo:rustc-flags=-l dylib=syntax"); - println!("cargo:rustc-flags=-l dylib=lib_glob_strmatch"); - println!("cargo:rustc-flags=-l dylib=lib_glob_glob"); - println!("cargo:rustc-flags=-l dylib=builtins_declare"); - println!("cargo:rustc-flags=-l dylib=stringlib"); - println!("cargo:rustc-flags=-l dylib=builtins_setattr"); - println!("cargo:rustc-flags=-l dylib=braces"); - println!("cargo:rustc-flags=-l dylib=lib_readline_misc"); - println!("cargo:rustc-flags=-l dylib=lib_readline_rltty"); - println!("cargo:rustc-flags=-l dylib=lib_readline_keymaps"); - println!("cargo:rustc-flags=-l dylib=lib_readline_kill"); - println!("cargo:rustc-flags=-l dylib=lib_readline_input"); - println!("cargo:rustc-flags=-l dylib=lib_readline_vi_mode"); - println!("cargo:rustc-flags=-l dylib=lib_readline_macro"); - println!("cargo:rustc-flags=-l dylib=lib_readline_bind"); - println!("cargo:rustc-flags=-l dylib=lib_readline_undo"); - println!("cargo:rustc-flags=-l dylib=lib_readline_funmap"); - println!("cargo:rustc-flags=-l dylib=lib_readline_nls"); - println!("cargo:rustc-flags=-l dylib=builtins_read"); - println!("cargo:rustc-flags=-l dylib=eval"); - println!("cargo:rustc-flags=-l dylib=lib_sh_setlinebuf"); - println!("cargo:rustc-flags=-l dylib=lib_sh_netconn"); - println!("cargo:rustc-flags=-l dylib=lib_sh_input_avail"); - println!("cargo:rustc-flags=-l dylib=lib_sh_shtty"); - println!("cargo:rustc-flags=-l dylib=lib_sh_zread"); - println!("cargo:rustc-flags=-l dylib=lib_sh_ufuncs"); - println!("cargo:rustc-flags=-l dylib=lib_sh_uconvert"); - println!("cargo:rustc-flags=-l dylib=pcomplib"); - println!("cargo:rustc-flags=-l dylib=bracecomp"); - println!("cargo:rustc-flags=-l dylib=lib_sh_spell"); - println!("cargo:rustc-flags=-l dylib=lib_sh_fnxform"); - println!("cargo:rustc-flags=-l dylib=lib_termcap_termcap"); - println!("cargo:rustc-flags=-l dylib=lib_termcap_tparam"); - println!("cargo:rustc-flags=-l dylib=builtins_bashgetopt"); - println!("cargo:rustc-flags=-l dylib=builtins_source"); - println!("cargo:rustc-flags=-l dylib=lib_sh_shmatch"); - println!("cargo:rustc-flags=-l dylib=test"); - println!("cargo:rustc-flags=-l dylib=builtins_return"); - println!("cargo:rustc-flags=-l dylib=builtins_exec"); - println!("cargo:rustc-flags=-l dylib=builtins_command"); - println!("cargo:rustc-flags=-l dylib=lib_sh_mbschr"); - println!("cargo:rustc-flags=-l dylib=expr"); - println!("cargo:rustc-flags=-l dylib=lib_sh_timeval"); - println!("cargo:rustc-flags=-l dylib=lib_sh_fpurge"); - println!("cargo:rustc-flags=-l dylib=builtins_fc"); - println!("cargo:rustc-flags=-l dylib=builtins_mapfile"); - println!("cargo:rustc-flags=-l dylib=builtins_eval"); - println!("cargo:rustc-flags=-l dylib=builtins_jobs"); - println!("cargo:rustc-flags=-l dylib=builtins_cd"); - println!("cargo:rustc-flags=-l dylib=builtins_shopt"); - println!("cargo:rustc-flags=-l dylib=builtins_echo"); - println!("cargo:rustc-flags=-l dylib=lib_glob_smatch"); - println!("cargo:rustc-flags=-l dylib=lib_sh_utf8"); - println!("cargo:rustc-flags=-l dylib=lib_readline_search"); - println!("cargo:rustc-flags=-l dylib=lib_readline_isearch"); - println!("cargo:rustc-flags=-l dylib=lib_sh_stringlist"); - println!("cargo:rustc-flags=-l dylib=builtins_complete"); - println!("cargo:rustc-flags=-l dylib=builtins_exit"); - println!("cargo:rustc-flags=-l dylib=lib_sh_tmpfile"); - println!("cargo:rustc-flags=-l dylib=lib_sh_netopen"); - println!("cargo:rustc-flags=-l dylib=lib_sh_eaccess"); - println!("cargo:rustc-flags=-l dylib=lib_readline_histsearch"); - println!("cargo:rustc-flags=-l dylib=lib_tilde_tilde"); - println!("cargo:rustc-flags=-l dylib=lib_sh_makepath"); - println!("cargo:rustc-flags=-l dylib=builtins_shift"); - println!("cargo:rustc-flags=-l dylib=lib_readline_parens"); - println!("cargo:rustc-flags=-l dylib=builtins_type"); - println!("cargo:rustc-flags=-l dylib=lib_sh_zmapfd"); - println!("cargo:rustc-flags=-l dylib=lib_sh_mailstat"); - println!("cargo:rustc-flags=-l dylib=builtins_builtins"); - println!("cargo:rustc-flags=-l dylib=builtins_kill"); - println!("cargo:rustc-flags=-l dylib=builtins_times"); - println!("cargo:rustc-flags=-l dylib=builtins_printf"); - println!("cargo:rustc-flags=-l dylib=builtins_umask"); - println!("cargo:rustc-flags=-l dylib=builtins_let"); - println!("cargo:rustc-flags=-l dylib=builtins_suspend"); - println!("cargo:rustc-flags=-l dylib=builtins_history"); - println!("cargo:rustc-flags=-l dylib=builtins_bind"); - println!("cargo:rustc-flags=-l dylib=builtins_fg_bg"); - println!("cargo:rustc-flags=-l dylib=builtins_builtin"); - println!("cargo:rustc-flags=-l dylib=builtins_alias"); - println!("cargo:rustc-flags=-l dylib=builtins_hash"); - println!("cargo:rustc-flags=-l dylib=builtins_enable"); - println!("cargo:rustc-flags=-l dylib=builtins_help"); - println!("cargo:rustc-flags=-l dylib=builtins_trap"); - println!("cargo:rustc-flags=-l dylib=builtins_caller"); - println!("cargo:rustc-flags=-l dylib=builtins_colon"); - println!("cargo:rustc-flags=-l dylib=builtins_ulimit"); - println!("cargo:rustc-flags=-l dylib=builtins_test"); - println!("cargo:rustc-flags=-l dylib=lib_sh_wcsnwidth"); - println!("cargo:rustc-flags=-l dylib=lib_readline_callback"); - println!("cargo:rustc-flags=-l dylib=lib_sh_zcatfd"); - println!("cargo:rustc-flags=-l dylib=lib_sh_zwrite"); - println!("cargo:rustc-flags=-l dylib=lib_sh_unicode"); - println!("cargo:rustc-flags=-l dylib=lib_sh_zgetline"); - println!("cargo:rustc-flags=-l dylib=lib_malloc_malloc"); - println!("cargo:rustc-flags=-l dylib=lib_sh_pathphys"); - println!("cargo:rustc-flags=-l dylib=lib_sh_fmtumax"); + println!("cargo:rustc-link-args=-Wl,--copy-dt-needed-entries -fpic"); + println!("cargo:rustc-flags=-l static=sh"); + println!("cargo:rustc-flags=-l dylib=rt"); } diff --git a/bash-5.1/builtins_rust/builtin/Cargo.toml b/bash-5.1/builtins_rust/builtin/Cargo.toml index e69de29b..58c4dfb6 100644 --- a/bash-5.1/builtins_rust/builtin/Cargo.toml +++ b/bash-5.1/builtins_rust/builtin/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "builtin" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +name = "rbuiltin" +crate-type = ["staticlib"] + +[dependencies] +libc = "0.2" diff --git a/bash-5.1/builtins_rust/builtin/src/intercdep.rs b/bash-5.1/builtins_rust/builtin/src/intercdep.rs new file mode 100644 index 00000000..adacec66 --- /dev/null +++ b/bash-5.1/builtins_rust/builtin/src/intercdep.rs @@ -0,0 +1,44 @@ + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_desc { + pub word: *mut c_char, + pub flags: c_int, +} +pub type WORD_DESC = word_desc; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_list { + pub next: *mut word_list, + pub word: *mut WORD_DESC, +} +pub type WORD_LIST = word_list; + +/* +#[macro_export] +macro_rules! EX_USAGE { + () => {258} +} +*/ +pub const EX_USAGE: c_int = 258; +pub const EXECUTION_SUCCESS :c_int = 0; + +/* +pub const EXECUTION_SUCCESS : c_int = 0; +pub const EXECUTION_FAILURE : c_int = 1; +*/ +//typedef int sh_builtin_func_t PARAMS((WORD_LIST *)); /* sh_wlist_func_t */ +extern "C" { + static mut loption :*mut WORD_LIST; + pub fn no_options(list: *mut WORD_LIST) -> c_int; + pub fn builtin_address(command: *const c_char) -> extern "C" fn(w:*mut WORD_LIST) ->i32; + pub static mut loptend : *mut WORD_LIST; + + /* + pub fn print_timeval(fp: *mut libc::FILE, tvp: *mut libc::timeval); + pub fn sh_chkwrite(s: c_int) -> c_int; + + pub static stdout: *mut libc::FILE; + */ +} diff --git a/bash-5.1/builtins_rust/builtin/src/lib.rs b/bash-5.1/builtins_rust/builtin/src/lib.rs index e69de29b..58025af5 100644 --- a/bash-5.1/builtins_rust/builtin/src/lib.rs +++ b/bash-5.1/builtins_rust/builtin/src/lib.rs @@ -0,0 +1,27 @@ +use libc::{c_int, c_char}; + +include!(concat!("intercdep.rs")); + +#[no_mangle] +pub extern "C" fn r_builtin_builtin(list: *mut WORD_LIST) -> i32 { + println!(""); + println!("r_builtin_builtin call"); + + unsafe { + if no_options (list) !=0 { + return EX_USAGE; + } + + if loptend == std::ptr::null_mut() { + return EXECUTION_SUCCESS; + } + + let mut list = loptend; + let t:WORD_LIST=*loptend; + let function = builtin_address((*(t.word)).word); + + list = (*list).next; + return function(list); + } +} + diff --git a/bash-5.1/builtins_rust/cd/Cargo.toml b/bash-5.1/builtins_rust/cd/Cargo.toml index 6c92c52d..1c6a085c 100644 --- a/bash-5.1/builtins_rust/cd/Cargo.toml +++ b/bash-5.1/builtins_rust/cd/Cargo.toml @@ -12,5 +12,5 @@ libc = "0.2" nix = "0.23.0" [lib] -crate-type = ["cdylib"] +crate-type = ["staticlib"] name = "rcd" diff --git a/bash-5.1/builtins_rust/cd/src/lib.rs b/bash-5.1/builtins_rust/cd/src/lib.rs index bb10f8c8..9c3a0211 100644 --- a/bash-5.1/builtins_rust/cd/src/lib.rs +++ b/bash-5.1/builtins_rust/cd/src/lib.rs @@ -841,12 +841,13 @@ pub extern "C" fn r_change_to_directory (newdir:* mut c_char, nolinks:i32, xattr } } +/* #[no_mangle] pub extern "C" fn cmd_name() ->*const u8 { return b"cd" as *const u8; } - #[no_mangle] pub extern "C" fn run(list : *mut WORD_LIST)->i32 { return r_cd_builtin(list); -} \ No newline at end of file +} +*/ diff --git a/bash-5.1/builtins_rust/colon/Cargo.toml b/bash-5.1/builtins_rust/colon/Cargo.toml index e69de29b..f91e75f5 100644 --- a/bash-5.1/builtins_rust/colon/Cargo.toml +++ b/bash-5.1/builtins_rust/colon/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "rcolon" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["staticlib"] +name = "rcolon" + +[dependencies] +libc = "0.2" diff --git a/bash-5.1/builtins_rust/colon/src/lib.rs b/bash-5.1/builtins_rust/colon/src/lib.rs index e69de29b..ed63b736 100644 --- a/bash-5.1/builtins_rust/colon/src/lib.rs +++ b/bash-5.1/builtins_rust/colon/src/lib.rs @@ -0,0 +1,39 @@ +use std::{ffi::CString}; +use libc::{size_t, c_int, c_uint, c_char, c_long, c_void, PT_NULL, c_ulong, strchr}; + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_desc { + pub word: *mut c_char, + pub flags: c_int, +} +pub type WORD_DESC = word_desc; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_list { + pub next: *mut word_list, + pub word: *mut WORD_DESC, +} +pub type WORD_LIST = word_list; + +#[no_mangle] +pub extern "C" fn r_colon_builtin(ignore:WORD_LIST)->i32 { + println!("in r_colon_builtin"); + 0 +} + +#[no_mangle] +pub extern "C" fn r_false_builtin(ignore: WORD_LIST) -> i32 { + println!("in r_false_builtin"); + 1 +} diff --git a/bash-5.1/builtins_rust/complete/Cargo.toml b/bash-5.1/builtins_rust/complete/Cargo.toml index e69de29b..cf53520e 100644 --- a/bash-5.1/builtins_rust/complete/Cargo.toml +++ b/bash-5.1/builtins_rust/complete/Cargo.toml @@ -0,0 +1,16 @@ +[package] +authors = ["huzhengming"] +name = "rcomplete" +version = "0.0.1" +##build = "../build.rs" +edition = "2021" + + +[dependencies] +lazy_static = "1.4.0" +libc = "0.2" +nix = "0.23.0" + +[lib] +crate-type = ["cdylib"] +name = "rcomplete" diff --git a/bash-5.1/builtins_rust/complete/src/lib.rs b/bash-5.1/builtins_rust/complete/src/lib.rs index e69de29b..d00afdf7 100644 --- a/bash-5.1/builtins_rust/complete/src/lib.rs +++ b/bash-5.1/builtins_rust/complete/src/lib.rs @@ -0,0 +1,1414 @@ +extern crate libc; +extern crate nix; + +use libc::{c_char, c_int, c_ulong, c_void}; +use std::{ffi::CString}; + +#[repr(C)] +pub struct WORD_DESC { + pub word: *mut c_char, + pub flags:c_int +} + +#[repr(C)] +#[derive(Copy,Clone)] +pub struct WORD_LIST { + next: *mut WORD_LIST, + word: *mut WORD_DESC +} + +#[repr(u8)] +enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple, cm_select, + cm_connection, cm_function_def, cm_until, cm_group, + cm_arith, cm_cond, cm_arith_for, cm_subshell, cm_coproc +} + +#[repr(u8)] +#[derive(Copy,Clone)] +enum r_instruction { + r_output_direction, r_input_direction, r_inputa_direction, + r_appending_to, r_reading_until, r_reading_string, + r_duplicating_input, r_duplicating_output, r_deblank_reading_until, + r_close_this, r_err_and_out, r_input_output, r_output_force, + r_duplicating_input_word, r_duplicating_output_word, + r_move_input, r_move_output, r_move_input_word, r_move_output_word, + r_append_err_and_out +} + +#[repr(C)] +#[derive(Copy,Clone)] +pub union REDIRECTEE { + dest:c_int, + filename:* mut WORD_DESC +} + +#[repr(C)] +pub union REDIRECT { + next:*mut REDIRECT, + redirector:REDIRECTEE, + rflags:c_int, + flags:c_int, + instruction:r_instruction, + redirectee:REDIRECTEE, + here_doc_eof:*mut c_char +} + +/* FOR command. */ +#[repr(C)] +pub struct for_com { + flags:c_int, + line:c_int, + name:*mut WORD_DESC, + map_list:*mut WORD_LIST, + action:*mut COMMAND +} + +#[repr(C)] +pub struct PATTERN_LIST { + next:* mut PATTERN_LIST, + patterns:* mut WORD_LIST, + action:*mut COMMAND, + flags:c_int +} + +#[repr(C)] +pub struct case_com { + flags:c_int, + line:c_int, + word:*mut WORD_DESC, + clauses:*mut PATTERN_LIST +} + +#[repr(C)] +pub struct while_com { + flags:c_int, + test:*mut COMMAND, + action:*mut COMMAND +} + +#[repr(C)] +pub struct if_com { + flags:c_int, + test:*mut COMMAND, + true_case:*mut COMMAND, + false_case:*mut COMMAND +} + +#[repr(C)] +pub struct connection { + ignore:c_int, + first:*mut COMMAND, + second:*mut COMMAND, + connector:c_int +} + +#[repr(C)] +pub struct simple_com { + flags:c_int, + line:c_int, + words:*mut WORD_LIST, + redirects:*mut REDIRECT +} + +#[repr(C)] +pub struct function_def { + flags:c_int, + line:c_int, + name:*mut WORD_DESC, + command:*mut COMMAND, + source_file:*mut c_char +} + +#[repr(C)] +pub struct group_com { + ignore:libc::c_int, + command:*mut COMMAND, + source_file:*mut c_char +} + +#[repr(C)] +pub struct select_com { + flags:c_int, + line:c_int, + name:*mut WORD_DESC, + map_list:*mut WORD_LIST, + action:*mut COMMAND +} + +#[repr(C)] +pub struct arith_com { + flags:c_int, + line:c_int, + exp:*mut WORD_LIST +} + +#[repr(C)] +pub struct cond_com { + flags:c_int, + line:c_int, + type_c:c_int, + exp:*mut WORD_LIST +} + +#[repr(C)] +pub struct arith_for_com { + flags:c_int, + line:c_int, + init:*mut WORD_LIST, + test:*mut WORD_LIST, + step:*mut WORD_LIST, + action:*mut COMMAND +} + +#[repr(C)] +pub struct subshell_com { + flags:i32, + line:i32, + command:*mut COMMAND +} + +#[repr(C)] +pub struct coproc_com { + flags:i32, + name:*mut c_char, + command:*mut COMMAND +} + +#[repr(C)] +pub union VALUE_COMMAND { + For:*mut for_com, + Case:*mut case_com, + While:*mut while_com, + If:*mut if_com, + Connection:*mut connection, + Simple:*mut simple_com, + Function_def:*mut function_def, + Group:*mut group_com, + Select:*mut select_com, + Arith:*mut arith_com, + Cond:*mut cond_com, + ArithFor:*mut arith_for_com, + Subshell:*mut subshell_com, + Coproc:*mut coproc_com +} + +#[repr(C)] +pub struct COMMAND { + type_c:command_type, + flags:i32, + line:i32, + redirects:*mut REDIRECT, + value:VALUE_COMMAND +} + +/* Structure containing all the non-action (binary) options; filled in by + build_actions(). */ +#[repr(C)] +#[derive(Copy,Clone)] +pub struct _optflags { + pflag:c_int, + rflag:c_int, + Dflag:c_int, + Eflag:c_int, + Iflag:c_int +} + +#[repr(C)] +#[derive(Copy,Clone)] +pub struct _compacts { + actname:* const c_char, + actflag:libc::c_ulong, + actopt:c_int, +} + +pub struct CompactsArray { + compactsArr:[_compacts;25usize] +} + +impl CompactsArray { + pub fn new()->CompactsArray { + CompactsArray{ + compactsArr:[ + _compacts{ actname:"alias\0".as_ptr() as *const c_char, actflag: CA_ALIAS!(),actopt: 'a' as c_int }, + _compacts{ actname:"arrayvar\0".as_ptr() as *const c_char, actflag: CA_ARRAYVAR!(),actopt: 0 as c_int }, + _compacts{ actname:"binding\0".as_ptr() as *const c_char, actflag: CA_BINDING!(),actopt: 0 as c_int }, + _compacts{ actname:"builtin\0".as_ptr() as *const c_char, actflag: CA_BUILTIN!(),actopt: 'b' as c_int }, + _compacts{ actname:"command\0".as_ptr() as *const c_char, actflag: CA_COMMAND!(),actopt: 'c' as c_int }, + _compacts{ actname:"directory\0".as_ptr() as *const c_char, actflag: CA_DIRECTORY!(),actopt: 'd' as c_int }, + _compacts{ actname:"disabled\0".as_ptr() as *const c_char, actflag: CA_DISABLED!(),actopt: 0 as c_int }, + _compacts{ actname:"enabled\0".as_ptr() as *const c_char, actflag: CA_ENABLED!(),actopt: 0 as c_int }, + _compacts{ actname:"export\0".as_ptr() as *const c_char, actflag: CA_EXPORT!(),actopt: 'e' as c_int }, + _compacts{ actname:"file\0".as_ptr() as *const c_char, actflag: CA_FILE!(),actopt: 'f' as c_int }, + _compacts{ actname:"function\0".as_ptr() as *const c_char, actflag: CA_FUNCTION!(),actopt: 0 as c_int }, + _compacts{ actname:"helptopic\0".as_ptr() as *const c_char, actflag: CA_HELPTOPIC!(),actopt: 0 as c_int }, + _compacts{ actname:"hostname\0".as_ptr() as *const c_char, actflag: CA_HOSTNAME!(),actopt: 0 as c_int }, + _compacts{ actname:"group\0".as_ptr() as *const c_char, actflag: CA_GROUP!(),actopt: 'g' as c_int }, + _compacts{ actname:"job\0".as_ptr() as *const c_char, actflag: CA_JOB!(),actopt: 'j' as c_int }, + _compacts{ actname:"keyword\0".as_ptr() as *const c_char, actflag: CA_KEYWORD!(),actopt: 'k' as c_int }, + _compacts{ actname:"running\0".as_ptr() as *const c_char, actflag: CA_RUNNING!(),actopt: 0 as c_int }, + _compacts{ actname:"service\0".as_ptr() as *const c_char, actflag: CA_SERVICE!(),actopt: 's' as c_int }, + _compacts{ actname:"setopt\0".as_ptr() as *const c_char, actflag: CA_SETOPT!(),actopt: 0 as c_int }, + _compacts{ actname:"shopt\0".as_ptr() as *const c_char, actflag: CA_SHOPT!(),actopt: 0 as c_int }, + _compacts{ actname:"signal\0".as_ptr() as *const c_char, actflag: CA_SIGNAL!(),actopt: 0 as c_int }, + _compacts{ actname:"stopped\0".as_ptr() as *const c_char, actflag: CA_STOPPED!(),actopt: 0 as c_int }, + _compacts{ actname:"user\0".as_ptr() as *const c_char, actflag: CA_USER!(),actopt: 'u' as c_int }, + _compacts{ actname:"variable\0".as_ptr() as *const c_char, actflag: CA_VARIABLE!(),actopt: 'v' as c_int }, + _compacts{ actname:std::ptr::null_mut(), actflag: 0,actopt: 0 as c_int }, + ] + } + } +} + +#[repr(C)] +#[derive(Copy,Clone)] +pub struct _compopt { + optname:* const c_char, + optflag:libc::c_ulong, +} + +pub struct CompoptArray { + compoptArr:[_compopt;9usize] +} + +impl CompoptArray { + pub fn new()->CompoptArray{ + CompoptArray{ + compoptArr:[ + _compopt{ optname:"bashdefault\0".as_ptr() as *const c_char, optflag:COPT_BASHDEFAULT!() }, + _compopt{ optname:"default\0".as_ptr() as *const c_char, optflag:COPT_DEFAULT!() }, + _compopt{ optname:"dirnames\0".as_ptr() as *const c_char, optflag:COPT_DIRNAMES!() }, + _compopt{ optname:"filenames\0".as_ptr() as *const c_char,optflag:COPT_FILENAMES!()}, + _compopt{ optname:"noquote\0".as_ptr() as *const c_char, optflag:COPT_NOQUOTE!() }, + _compopt{ optname:"nosort\0".as_ptr() as *const c_char, optflag:COPT_NOSORT!() }, + _compopt{ optname:"nospace\0".as_ptr() as *const c_char, optflag:COPT_NOSPACE!() }, + _compopt{ optname:"plusdirs\0".as_ptr() as *const c_char, optflag:COPT_PLUSDIRS!() }, + _compopt{ optname:std::ptr::null_mut(), optflag:0 }, + ] + } + } +} + + +#[repr(C)] +pub struct COMPSPEC { + refcount:c_int, + actions:c_ulong, + options:c_ulong, + globpat:* mut c_char, + words:* mut c_char, + prefix: * mut c_char, + suffix: * mut c_char, + funcname: * mut c_char, + command:* mut c_char, + lcommand:* mut c_char, + filterpat:* mut c_char, +} +#[repr(C)] +pub struct BUCKET_CONTENTS { + next:* mut BUCKET_CONTENTS, /* Link to next hashed key in this bucket. */ + key:* mut c_char, /* What we look up. */ + data:* mut libc::c_void, /* What we really want. */ + khash:libc::c_uint, /* What key hashes to */ + times_found:i32, /* Number of times this item has been found. */ +} + +#[repr(C)] +pub struct STRINGLIST { + list:* mut * mut c_char, + list_size:c_int, + list_len:c_int, +} + +#[macro_export] +macro_rules! EXECUTION_FAILURE { + () => {1} +} + +#[macro_export] +macro_rules! EX_USAGE { + () => {258} +} + +#[macro_export] +macro_rules! EXECUTION_SUCCESS { + () => { + 0 + } +} + +#[macro_export] +macro_rules! CA_ALIAS { + () => { + 1<<0 + } +} + +#[macro_export] +macro_rules! CA_ARRAYVAR { + () => { + 1<<1 + } +} + +#[macro_export] +macro_rules! CA_BINDING { + () => { + 1<<2 + } +} + +#[macro_export] +macro_rules! CA_BUILTIN { + () => { + 1<<3 + } +} + +#[macro_export] +macro_rules! CA_COMMAND { + () => { + 1<<4 + } +} + +#[macro_export] +macro_rules! CA_DIRECTORY { + () => { + 1<<5 + } +} + +#[macro_export] +macro_rules! CA_DISABLED { + () => { + 1<<6 + } +} + +#[macro_export] +macro_rules! CA_ENABLED { + () => { + 1<<7 + } +} + +#[macro_export] +macro_rules! CA_EXPORT { + () => { + 1<<8 + } +} + +#[macro_export] +macro_rules! CA_FILE { + () => { + 1<<9 + } +} + +#[macro_export] +macro_rules! CA_FUNCTION { + () => { + 1<<10 + } +} + +#[macro_export] +macro_rules! CA_GROUP { + () => { + 1<<11 + } +} + +#[macro_export] +macro_rules! CA_HELPTOPIC { + () => { + 1<<12 + } +} + +#[macro_export] +macro_rules! CA_HOSTNAME { + () => { + 1<<13 + } +} + +#[macro_export] +macro_rules! CA_JOB { + () => { + 1<<14 + } +} + +#[macro_export] +macro_rules! CA_KEYWORD { + () => { + 1<<15 + } +} + +#[macro_export] +macro_rules! CA_RUNNING { + () => { + 1<<16 + } +} + +#[macro_export] +macro_rules! CA_SERVICE { + () => { + 1<<17 + } +} + +#[macro_export] +macro_rules! CA_SETOPT { + () => { + 1<<18 + } +} + +#[macro_export] +macro_rules! CA_SHOPT { + () => { + 1<<19 + } +} + +#[macro_export] +macro_rules! CA_SIGNAL { + () => { + 1<<20 + } +} + +#[macro_export] +macro_rules! CA_STOPPED { + () => { + 1<<21 + } +} + +#[macro_export] +macro_rules! CA_USER { + () => { + 1<<22 + } +} + +#[macro_export] +macro_rules! CA_VARIABLE { + () => { + 1<<23 + } +} + +#[macro_export] +macro_rules! COPT_RESERVED { + () => { + 1<<0 + } +} + +#[macro_export] +macro_rules! COPT_DEFAULT { + () => { + 1<<1 + } +} + +#[macro_export] +macro_rules! COPT_FILENAMES { + () => { + 1<<2 + } +} + +#[macro_export] +macro_rules! COPT_DIRNAMES { + () => { + 1<<3 + } +} + +#[macro_export] +macro_rules! COPT_NOQUOTE { + () => { + 1<<4 + } +} + +#[macro_export] +macro_rules! COPT_NOSPACE { + () => { + 1<<5 + } +} + +#[macro_export] +macro_rules! COPT_BASHDEFAULT { + () => { + 1<<6 + } +} + +#[macro_export] +macro_rules! COPT_PLUSDIRS { + () => { + 1<<7 + } +} + +#[macro_export] +macro_rules! COPT_NOSORT { + () => { + 1<<8 + } +} + +#[macro_export] +macro_rules! RL_STATE_COMPLETING { + () => { + 0x0004000 /* doing completion */ + } +} + +extern "C" { + fn reset_internal_getopt(); + fn internal_getopt (list:*mut WORD_LIST , opts:*mut c_char)->i32; + fn sh_invalidopt (value:* mut c_char); + fn sh_invalidid (value:* mut c_char); + fn sh_invalidoptname (value:* mut c_char); + fn builtin_usage(); + static list_optarg:* mut c_char; + fn builtin_error(err:*const c_char,...); + fn check_identifier (w:* mut WORD_DESC, f:i32)->i32; + static mut posixly_correct:i32; + static mut loptend:*mut WORD_LIST; + fn make_word_list (w:* mut WORD_DESC, list:*mut WORD_LIST)->*mut WORD_LIST; + fn make_bare_word (w:*const c_char)->* mut WORD_DESC; + fn dispose_words (list:*mut WORD_LIST); + fn progcomp_flush (); + fn compspec_create ()->* mut COMPSPEC; + fn progcomp_insert (str:* mut c_char, c:* mut COMPSPEC)->i32; + fn progcomp_remove (str:* mut c_char)->i32; + fn sh_single_quote (str:* mut c_char)->* mut c_char; + fn progcomp_walk (func: unsafe extern "C" fn (item:* mut BUCKET_CONTENTS)->i32); + fn sh_chkwrite (i:i32)->i32; + fn progcomp_search (w:*const c_char)->* mut COMPSPEC; + static mut pcomp_line:* mut c_char; + static mut pcomp_ind:c_int; + fn gen_compspec_completions (cs:* mut COMPSPEC, cmd:*const c_char, word:*const c_char, start:i32, end:i32, foundp:* mut i32)->* mut STRINGLIST; + fn bash_default_completion (text:* const c_char, start:i32, end:i32, qc:i32, compflags:i32)->* mut * mut c_char; + fn rl_filename_completion_function (text:* const c_char, state:i32)-> * mut c_char; + fn rl_completion_matches (text:* const c_char, entry_function:unsafe extern "C" fn (text:* const c_char, state:i32)-> * mut c_char)->* mut * mut c_char; + fn completions_to_stringlist (matches:* mut * mut c_char)->* mut STRINGLIST; + fn strvec_dispose (matches:* mut * mut c_char); + fn strlist_dispose (strlist:* mut STRINGLIST); + fn strlist_print (strlist:* mut STRINGLIST, text:* mut c_char); + fn compspec_dispose (com:* mut COMPSPEC); + static mut list_opttype:i32; + static mut rl_readline_state:c_ulong; + static mut pcomp_curcs:* mut COMPSPEC; + static pcomp_curcmd:* mut c_char; + fn pcomp_set_compspec_options (cs:* mut COMPSPEC, flags:i32, set_or_unset:i32); + fn pcomp_set_readline_variables (flags:i32, nval:i32); +} + +pub static mut Garg:* mut c_char=std::ptr::null_mut(); +pub static mut Warg:* mut c_char=std::ptr::null_mut(); +pub static mut Parg:* mut c_char=std::ptr::null_mut(); +pub static mut Sarg:* mut c_char=std::ptr::null_mut(); +pub static mut Xarg:* mut c_char=std::ptr::null_mut(); +pub static mut Farg:* mut c_char=std::ptr::null_mut(); +pub static mut Carg:* mut c_char=std::ptr::null_mut(); + +unsafe fn savestring(x:* const c_char)->* mut c_char +{ + let str1:* mut c_char=libc::malloc(1 + libc::strlen (x )) as * mut c_char; + return libc::strcpy(str1,x ); +} + +unsafe fn STRDUP(x:* const c_char)->* mut c_char +{ + if x !=std::ptr::null_mut() { + return savestring (x); + } else { + return std::ptr::null_mut(); + } +} + +unsafe fn STREQ( a:* const c_char, b:* const c_char)->bool +{ + return *a ==*b && libc::strcmp(a, b) == 0; +} + +unsafe fn shell_break_chars()->* const c_char +{ + return "()<>;&| \t\n\0".as_ptr() as *const c_char; +} + +unsafe fn EMPTYCMD()->* const c_char +{ + return "_EmptycmD_\0".as_ptr() as *const c_char; +} + +unsafe fn DEFAULTCMD()->* const c_char +{ + return "_DefaultCmD_\0".as_ptr() as *const c_char; +} + +unsafe fn INITIALWORD()->* const c_char +{ + return "_InitialWorD_\0".as_ptr() as *const c_char; +} + +unsafe fn RL_ISSTATE(x:c_ulong)->c_ulong +{ + return rl_readline_state & x; +} + +#[no_mangle] +pub extern "C" fn r_find_compact (name:* mut c_char)->i32 +{ + let mut i:i32=0; + unsafe { + let compacts:CompactsArray=CompactsArray::new(); + while compacts.compactsArr[i as usize].actname != std::ptr::null_mut() { + if STREQ (name, compacts.compactsArr[i as usize].actname) { + return i; + } + i+=1; + } + return -1; + } +} + +#[no_mangle] +pub extern "C" fn r_find_compopt (name:* mut c_char)->i32 +{ + let mut i:i32=0; + let compopts:CompoptArray=CompoptArray::new(); + unsafe { + while compopts.compoptArr[i as usize].optname != std::ptr::null_mut() { + if STREQ (name, compopts.compoptArr[i as usize].optname) { + return i; + } + i+=1; + } + return -1; + } +} + +#[no_mangle] +pub extern "C" fn r_build_actions (list : *mut WORD_LIST, flagp:* mut _optflags, actp:* mut c_ulong, optp:* mut c_ulong)->i32 +{ + let mut opt:i32; + let mut ind:i32; + let mut opt_given:i32=0; + let mut acts:c_ulong=0; + let mut copts:c_ulong=0; + let mut w:WORD_DESC=WORD_DESC{word:std::ptr::null_mut(),flags:0}; + + unsafe { + reset_internal_getopt (); + opt = internal_getopt(list, CString::new("abcdefgjko:prsuvA:G:W:P:S:X:F:C:DEI").unwrap().as_ptr() as * mut c_char); + while opt != -1 { + opt_given = 1; + let optu8:u8= opt as u8; + let optChar:char=char::from(optu8); + match optChar{ + 'r'=>{ + if flagp !=std::ptr::null_mut() { + (*flagp).rflag = 1; + } else { + sh_invalidopt (CString::new("-r").unwrap().as_ptr() as * mut c_char); + builtin_usage (); + return EX_USAGE!(); + } + } + 'p'=>{ + if flagp !=std::ptr::null_mut() { + (*flagp).pflag = 1; + } else { + sh_invalidopt (CString::new("-p").unwrap().as_ptr() as * mut c_char); + builtin_usage (); + return EX_USAGE!(); + } + } + 'a'=>{ + acts |= CA_ALIAS!(); + } + 'b'=>{ + acts |= CA_BUILTIN!(); + } + 'c'=>{ + acts |= CA_COMMAND!(); + } + 'd'=>{ + acts |= CA_DIRECTORY!(); + } + 'e'=>{ + acts |= CA_EXPORT!(); + } + 'f'=>{ + acts |= CA_FILE!(); + } + 'g'=>{ + acts |= CA_GROUP!(); + } + 'j'=>{ + acts |= CA_GROUP!(); + } + 'k'=>{ + acts |= CA_KEYWORD!(); + } + 's'=>{ + acts |= CA_SERVICE!(); + } + 'u'=>{ + acts |= CA_USER!(); + } + 'v'=>{ + acts |= CA_VARIABLE!(); + } + 'o'=>{ + ind = r_find_compopt (list_optarg); + if ind < 0 { + sh_invalidoptname (list_optarg); + return EX_USAGE!(); + } + let compopts:CompoptArray=CompoptArray::new(); + copts |= compopts.compoptArr[ind as usize].optflag; + } + 'A'=>{ + ind = r_find_compact (list_optarg); + if ind < 0 { + builtin_error (CString::new("%s: invalid action name").unwrap().as_ptr(), list_optarg); + return EX_USAGE!(); + } + let compacts:CompactsArray=CompactsArray::new(); + acts |= compacts.compactsArr[ind as usize].actflag; + } + 'C'=>{ + Carg = list_optarg; + } + 'D'=>{ + if flagp !=std::ptr::null_mut() { + (*flagp).Dflag = 1; + } else { + sh_invalidopt (CString::new("-D").unwrap().as_ptr() as * mut c_char); + builtin_usage (); + return EX_USAGE!(); + } + } + 'E'=>{ + if flagp !=std::ptr::null_mut() { + (*flagp).Eflag = 1; + } else { + sh_invalidopt (CString::new("-E").unwrap().as_ptr() as * mut c_char); + builtin_usage (); + return EX_USAGE!(); + } + } + 'I'=>{ + if flagp !=std::ptr::null_mut() { + (*flagp).Iflag = 1; + } else { + sh_invalidopt (CString::new("-I").unwrap().as_ptr() as * mut c_char); + builtin_usage (); + return EX_USAGE!(); + } + } + 'F'=>{ + w.word = list_optarg; + Farg = list_optarg; + w.flags = 0; + if check_identifier (&mut w, posixly_correct) == 0 || libc::strpbrk (Farg, shell_break_chars()) != std::ptr::null_mut() { + sh_invalidid (Farg); + return EX_USAGE!(); + } + } + 'G'=>{ + Garg = list_optarg; + } + 'P'=>{ + Parg = list_optarg; + } + 'S'=>{ + Sarg = list_optarg; + } + 'W'=>{ + Warg = list_optarg; + } + 'X'=>{ + Xarg = list_optarg; + } + 'X'=>{ + Xarg = list_optarg; + } + _=>{ + builtin_usage (); + return EX_USAGE!(); + } + } + opt=internal_getopt(list, CString::new("abcdefgjko:prsuvA:G:W:P:S:X:F:C:DEI").unwrap().as_ptr() as * mut c_char); + } + *actp = acts; + *optp = copts; + if opt_given !=0 { + return EXECUTION_SUCCESS!(); + } else { + return EXECUTION_FAILURE!(); + } + } +} + +/* Add, remove, and display completion specifiers. */ +#[no_mangle] +pub extern "C" fn r_complete_builtin (listt: *mut WORD_LIST)->i32 +{ + let mut opt_given:i32=0; + let mut rval:i32; + let mut acts:c_ulong=0; + let mut copts:c_ulong=0; + let mut cs:* mut COMPSPEC; + let mut oflags:_optflags=_optflags{pflag:0,rflag:0,Dflag:0,Eflag:0,Iflag:0}; + let mut l: *mut WORD_LIST; + let mut wl: *mut WORD_LIST; + + unsafe { + let mut list:* mut WORD_LIST=listt.clone(); + if list == std::ptr::null_mut() { + r_print_all_completions (); + return EXECUTION_SUCCESS!(); + } + + oflags.pflag=0; + oflags.rflag=0; + oflags.Dflag=0; + oflags.Eflag=0; + oflags.Iflag=0; + + Garg=std::ptr::null_mut(); + Warg=std::ptr::null_mut(); + Parg=std::ptr::null_mut(); + Sarg=std::ptr::null_mut(); + Xarg=std::ptr::null_mut(); + Farg=std::ptr::null_mut(); + Carg=std::ptr::null_mut(); + + cs=std::ptr::null_mut(); + + /* Build the actions from the arguments. Also sets the [A-Z]arg variables + as a side effect if they are supplied as options. */ + rval = r_build_actions (list, &mut oflags, &mut acts, &mut copts); + if rval == EX_USAGE!() { + return rval; + } + + opt_given = (rval != EXECUTION_FAILURE!()) as i32; + + list = loptend.clone(); + + if oflags.Dflag !=0 { + wl = make_word_list (make_bare_word (DEFAULTCMD()), std::ptr::null_mut()); + } else if oflags.Eflag !=0 { + wl = make_word_list (make_bare_word (EMPTYCMD()), std::ptr::null_mut()); + } else if oflags.Iflag !=0 { + wl = make_word_list (make_bare_word (INITIALWORD()), std::ptr::null_mut()); + } else { + wl = std::ptr::null_mut(); + } + + /* -p overrides everything else */ + if oflags.pflag !=0 || (list == std::ptr::null_mut() && opt_given == 0) { + if wl != std::ptr::null_mut() { + rval = r_print_cmd_completions (wl); + dispose_words (wl); + return rval; + } else if list == std::ptr::null_mut() { + r_print_all_completions (); + return EXECUTION_SUCCESS!(); + } + return r_print_cmd_completions (list); + } + + /* next, -r overrides everything else. */ + if oflags.rflag !=0 { + if wl != std::ptr::null_mut() { + rval = r_remove_cmd_completions (wl); + dispose_words (wl); + return rval; + } else if list == std::ptr::null_mut() { + progcomp_flush (); + return EXECUTION_SUCCESS!(); + } + return r_remove_cmd_completions (list); + } + + if wl == std::ptr::null_mut() && list == std::ptr::null_mut() && opt_given !=0 { + builtin_usage (); + return EX_USAGE!(); + } + + /* If we get here, we need to build a compspec and add it for each + remaining argument. */ + cs = compspec_create (); + (*cs).actions = acts; + (*cs).options = copts; + + (*cs).globpat = STRDUP (Garg); + (*cs).words = STRDUP (Warg); + (*cs).prefix = STRDUP (Parg); + (*cs).suffix = STRDUP (Sarg); + (*cs).funcname = STRDUP (Farg); + (*cs).command = STRDUP (Carg); + (*cs).filterpat = STRDUP (Xarg); + + rval = EXECUTION_SUCCESS!(); + + if wl != std::ptr::null_mut() { + l= wl.clone(); + } else { + l= list.clone(); + } + + while l != std::ptr::null_mut() { + /* Add CS as the compspec for the specified commands. */ + if progcomp_insert ((*(*l).word).word, cs) == 0 { + rval = EXECUTION_FAILURE!(); + } + l = (*l).next; + } + + dispose_words (wl); + return rval; + } +} + +#[no_mangle] +pub extern "C" fn r_remove_cmd_completions (list: * mut WORD_LIST)->i32 +{ + let mut l:* mut WORD_LIST; + let mut ret:i32; + unsafe { + ret = EXECUTION_SUCCESS!(); + l = list.clone(); + while l!=std::ptr::null_mut() { + if progcomp_remove ((*(*l).word).word) == 0 { + builtin_error (CString::new("%s: no completion specification").unwrap().as_ptr(), (*(*l).word).word); + ret = EXECUTION_FAILURE!(); + } + l = (*l).next; + } + return ret; + } +} + +#[no_mangle] +pub extern "C" fn r_print_compoptions (copts:c_ulong, full:i32) +{ + unsafe { + let compopts:CompoptArray=CompoptArray::new(); + for i in 0..compopts.compoptArr.len() { + if (copts & compopts.compoptArr[i].optflag) !=0 { + libc::printf (CString::new("-o %s ").unwrap().as_ptr(), compopts.compoptArr[i].optname); + } else if full !=0 { + libc::printf (CString::new("+o %s ").unwrap().as_ptr(), compopts.compoptArr[i].optname); + } + } + } +} + +#[no_mangle] +pub extern "C" fn r_print_compactions (acts:c_ulong) +{ + unsafe { + let compacts:CompactsArray=CompactsArray::new(); + for i in 0..compacts.compactsArr.len() { + if compacts.compactsArr[i].actopt !=0 && (acts & compacts.compactsArr[i].actflag) !=0 { + libc::printf (CString::new("-%c ").unwrap().as_ptr(), compacts.compactsArr[i].actopt); + } + } + + for i in 0..compacts.compactsArr.len() { + if compacts.compactsArr[i].actopt ==0 && (acts & compacts.compactsArr[i].actflag) !=0 { + libc::printf (CString::new("-A %s ").unwrap().as_ptr(), compacts.compactsArr[i].actname); + } + } + } +} + +#[no_mangle] +pub extern "C" fn r_print_arg (arg:* const c_char, flag:* const c_char, quote:i32) +{ + let x:* mut c_char; + unsafe { + if arg != std::ptr::null_mut() { + if quote !=0 { + x = sh_single_quote (arg as * mut c_char); + } else { + x= arg as * mut c_char; + } + libc::printf (CString::new("%s %s ").unwrap().as_ptr(), flag, x); + if x != arg as * mut c_char { + libc::free (x as * mut c_void); + } + } + } +} + +#[no_mangle] +pub extern "C" fn r_print_cmd_name (cmd:* const c_char) +{ + unsafe { + if STREQ (cmd, DEFAULTCMD()) { + libc::printf (CString::new("-D").unwrap().as_ptr()); + } else if STREQ (cmd, EMPTYCMD()) { + libc::printf (CString::new("-E").unwrap().as_ptr()); + } else if STREQ (cmd, INITIALWORD()) { + libc::printf (CString::new("-I").unwrap().as_ptr()); + } else if *cmd == 0 { /* XXX - can this happen? */ + libc::printf (CString::new("''").unwrap().as_ptr()); + } else { + libc::printf (CString::new("%s").unwrap().as_ptr(),cmd); + } + } +} + +#[no_mangle] +pub extern "C" fn r_print_one_completion (cmd: * mut c_char, cs:* mut COMPSPEC)->i32 +{ + unsafe { + libc::printf (CString::new("complete ").unwrap().as_ptr()); + + r_print_compoptions ((*cs).options, 0); + r_print_compactions ((*cs).actions); + + /* now the rest of the arguments */ + + /* arguments that require quoting */ + r_print_arg ((*cs).globpat, CString::new("-G").unwrap().as_ptr(), 1); + r_print_arg ((*cs).words, CString::new("-W").unwrap().as_ptr(), 1); + r_print_arg ((*cs).prefix, CString::new("-P").unwrap().as_ptr(), 1); + r_print_arg ((*cs).suffix, CString::new("-S").unwrap().as_ptr(), 1); + r_print_arg ((*cs).filterpat, CString::new("-X").unwrap().as_ptr(), 1); + + r_print_arg ((*cs).command, CString::new("-C").unwrap().as_ptr(), 1); + + /* simple arguments that don't require quoting */ + r_print_arg ((*cs).funcname, CString::new("-F").unwrap().as_ptr(), 0); + + r_print_cmd_name (cmd); + libc::printf (CString::new("\n").unwrap().as_ptr()); + + return 0; + } +} + +#[no_mangle] +pub extern "C" fn r_print_compopts (cmd:* mut c_char, cs:* mut COMPSPEC, full:i32) +{ + unsafe { + libc::printf (CString::new("compopt ").unwrap().as_ptr()); + + r_print_compoptions ((*cs).options, full); + r_print_cmd_name (cmd); + + libc::printf (CString::new("\n").unwrap().as_ptr()); + } +} + +#[no_mangle] +pub extern "C" fn r_print_compitem (item:* mut BUCKET_CONTENTS)->i32 +{ + let cs:* mut COMPSPEC; + let cmd:* mut c_char; + unsafe { + cmd = (*item).key; + cs = (*item).data as * mut COMPSPEC; + } + + return r_print_one_completion (cmd, cs); +} + +#[no_mangle] +pub extern "C" fn r_print_all_completions () +{ + unsafe { + progcomp_walk (r_print_compitem); + } +} + +#[no_mangle] +pub extern "C" fn r_print_cmd_completions (list:* mut WORD_LIST)->i32 +{ + let mut l:* mut WORD_LIST; + let mut cs:* mut COMPSPEC; + let mut ret:i32; + + unsafe { + ret = EXECUTION_SUCCESS!(); + l = list.clone(); + while l != std::ptr::null_mut() { + cs = progcomp_search ((*(*l).word).word); + if cs != std::ptr::null_mut() { + r_print_one_completion ((*(*l).word).word, cs); + } else { + builtin_error (CString::new("%s: no completion specification").unwrap().as_ptr(),(*(*l).word).word); + ret = EXECUTION_FAILURE!(); + } + l = (*l).next; + } + return sh_chkwrite (ret); + } +} + +#[no_mangle] +pub extern "C" fn r_compgen_builtin (listt:* mut WORD_LIST)->i32 +{ + let mut rval:i32; + let mut acts:c_ulong=0; + let mut copts:c_ulong=0; + let mut cs: * mut COMPSPEC; + let mut sl:* mut STRINGLIST; + let word:* mut c_char; + let mut matches:* mut * mut c_char; + let old_line:* mut c_char; + let old_ind:i32; + unsafe { + let mut list:* mut WORD_LIST=listt.clone(); + if list == std::ptr::null_mut() { + return EXECUTION_SUCCESS!(); + } + + Garg=std::ptr::null_mut(); + Warg=std::ptr::null_mut(); + Parg=std::ptr::null_mut(); + Sarg=std::ptr::null_mut(); + Xarg=std::ptr::null_mut(); + Farg=std::ptr::null_mut(); + Carg=std::ptr::null_mut(); + + cs = std::ptr::null_mut(); + + /* Build the actions from the arguments. Also sets the [A-Z]arg variables + as a side effect if they are supplied as options. */ + rval = r_build_actions (list, std::ptr::null_mut(), &mut acts, &mut copts); + if rval == EX_USAGE!() { + return rval; + } + + if rval == EXECUTION_FAILURE!() { + return EXECUTION_SUCCESS!(); + } + + list = loptend.clone(); + + if list !=std::ptr::null_mut() && (*list).word != std::ptr::null_mut() { + word = (*((*list).word)).word; + } else { + word=CString::new("").unwrap().as_ptr() as * mut c_char; + } + + if Farg != std::ptr::null_mut() { + builtin_error (CString::new("warning: -F option may not work as you expect").unwrap().as_ptr()); + } + + if Carg != std::ptr::null_mut() { + builtin_error (CString::new("warning: -C option may not work as you expect").unwrap().as_ptr()); + } + + /* If we get here, we need to build a compspec and evaluate it. */ + cs = compspec_create (); + (*cs).actions = acts; + (*cs).options = copts; + (*cs).refcount = 1; + + (*cs).globpat = STRDUP (Garg); + (*cs).words = STRDUP (Warg); + (*cs).prefix = STRDUP (Parg); + (*cs).suffix = STRDUP (Sarg); + (*cs).funcname = STRDUP (Farg); + (*cs).command = STRDUP (Carg); + (*cs).filterpat = STRDUP (Xarg); + + rval = EXECUTION_FAILURE!(); + + /* probably don't have to save these, just being safe */ + old_line = pcomp_line; + old_ind = pcomp_ind; + pcomp_line = std::ptr::null_mut(); + pcomp_ind = 0; + sl = gen_compspec_completions (cs, CString::new("compgen").unwrap().as_ptr(), word, 0, 0, std::ptr::null_mut()); + pcomp_line = old_line; + pcomp_ind = old_ind; + + /* If the compspec wants the bash default completions, temporarily + turn off programmable completion and call the bash completion code. */ + if (sl == std::ptr::null_mut() || (*sl).list_len == 0) && (copts & COPT_BASHDEFAULT!()) !=0 { + matches = bash_default_completion (word, 0, 0, 0, 0); + sl = completions_to_stringlist (matches); + strvec_dispose (matches); + } + + /* This isn't perfect, but it's the best we can do, given what readline + exports from its set of completion utility functions. */ + if (sl == std::ptr::null_mut() || (*sl).list_len == 0) && (copts & COPT_DEFAULT!()) !=0 { + matches = rl_completion_matches (word, rl_filename_completion_function); + strlist_dispose (sl); + sl = completions_to_stringlist (matches); + strvec_dispose (matches); + } + + if sl != std::ptr::null_mut() { + if (*sl).list != std::ptr::null_mut() && (*sl).list_len !=0 { + rval = EXECUTION_SUCCESS!(); + strlist_print (sl, std::ptr::null_mut()); + } + strlist_dispose (sl); + } + + compspec_dispose (cs); + return rval; + } +} + +#[no_mangle] +pub extern "C" fn r_compopt_builtin (listt:* mut WORD_LIST)->i32 +{ + let mut opts_on:i32=0; + let mut opts_off:i32=0; + let mut opts:* mut i32; + let mut opt:i32; + let mut oind:i32; + let mut ret:i32; + let mut Dflag:i32=0; + let mut Eflag:i32=0; + let mut Iflag:i32=0; + let mut l:* mut WORD_LIST; + let mut wl:* mut WORD_LIST; + let mut cs:* mut COMPSPEC; + + ret = EXECUTION_SUCCESS!(); + unsafe { + let mut list:* mut WORD_LIST=listt.clone(); + reset_internal_getopt (); + + opt = internal_getopt (list, CString::new("+o:DEI").unwrap().as_ptr() as * mut c_char); + + while opt != -1 { + if list_opttype == '-' as i32 { + opts = &mut opts_on; + } else { + opts = &mut opts_off; + } + + let optu8:u8= opt as u8; + let optChar:char=char::from(optu8); + + match optChar { + 'o'=>{ + oind = r_find_compopt (list_optarg); + if oind < 0 { + sh_invalidoptname (list_optarg); + return EX_USAGE!(); + } + let compopts:CompoptArray=CompoptArray::new(); + *opts |= compopts.compoptArr[oind as usize].optflag as i32; + } + 'D'=>{ + Dflag = 1; + } + 'E'=>{ + Eflag = 1; + } + 'I'=>{ + Iflag = 1; + } + _=>{ + builtin_usage (); + return EX_USAGE!(); + } + } + opt = internal_getopt (list, CString::new("+o:DEI").unwrap().as_ptr() as * mut c_char); + } + + list = loptend.clone(); + + if Dflag != 0 { + wl = make_word_list (make_bare_word (DEFAULTCMD()), std::ptr::null_mut()); + } else if Eflag !=0 { + wl = make_word_list (make_bare_word (EMPTYCMD()), std::ptr::null_mut()); + } else if Iflag !=0 { + wl = make_word_list (make_bare_word (INITIALWORD()), std::ptr::null_mut()); + } else { + wl = std::ptr::null_mut(); + } + + if list == std::ptr::null_mut() && wl == std::ptr::null_mut() { + if RL_ISSTATE (RL_STATE_COMPLETING!()) == 0 || pcomp_curcs == std::ptr::null_mut() { + builtin_error (CString::new("not currently executing completion function").unwrap().as_ptr()); + return EXECUTION_FAILURE!(); + } + cs = pcomp_curcs.clone(); + + if opts_on == 0 && opts_off == 0 { + r_print_compopts (pcomp_curcmd, cs, 1); + return sh_chkwrite (ret); + } + + /* Set the compspec options */ + pcomp_set_compspec_options (cs, opts_on, 1); + pcomp_set_compspec_options (cs, opts_off, 0); + + /* And change the readline variables the options control */ + pcomp_set_readline_variables (opts_on, 1); + pcomp_set_readline_variables (opts_off, 0); + + return ret; + } + + if wl != std::ptr::null_mut() { + l = wl.clone(); + } else { + l=list.clone(); + } + + while l != std::ptr::null_mut() { + cs = progcomp_search ((*((*list).word)).word); + if cs == std::ptr::null_mut() { + builtin_error (CString::new("%s: no completion specification").unwrap().as_ptr(), (*((*list).word)).word); + ret = EXECUTION_FAILURE!(); + continue; + } + if opts_on == 0 && opts_off == 0 { + r_print_compopts ((*((*list).word)).word, cs, 1); + continue; /* XXX -- fill in later */ + } + + /* Set the compspec options */ + pcomp_set_compspec_options (cs, opts_on, 1); + pcomp_set_compspec_options (cs, opts_off, 0); + l = (*l).next; + } + + if wl != std::ptr::null_mut() { + dispose_words (wl); + } + + return ret; + } +} + +#[no_mangle] +pub extern "C" fn cmd_name() ->*const u8 { + return b"complete" as *const u8; +} + +#[no_mangle] +pub extern "C" fn run(list : *mut WORD_LIST)->i32 { + return r_complete_builtin(list); +} \ No newline at end of file diff --git a/bash-5.1/builtins_rust/declare/Cargo.toml b/bash-5.1/builtins_rust/declare/Cargo.toml index ade288e7..8f89ef8d 100644 --- a/bash-5.1/builtins_rust/declare/Cargo.toml +++ b/bash-5.1/builtins_rust/declare/Cargo.toml @@ -2,7 +2,7 @@ authors = ["huzhengming"] name = "rdeclare" version = "0.0.1" -build = "../build.rs" +#build = "../build.rs" edition = "2021" diff --git a/bash-5.1/builtins_rust/exit/Cargo.toml b/bash-5.1/builtins_rust/exit/Cargo.toml index e69de29b..5b879602 100644 --- a/bash-5.1/builtins_rust/exit/Cargo.toml +++ b/bash-5.1/builtins_rust/exit/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "exit" +version = "0.1.0" +edition = "2021" +#build = "../build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +libc = "0.2" +nix = "0.23.0" +rjobs = {path="../jobs"} + + +[lib] +crate-type = ["staticlib"] +name = "rexit" diff --git a/bash-5.1/builtins_rust/exit/src/lib.rs b/bash-5.1/builtins_rust/exit/src/lib.rs index e69de29b..63574ef6 100644 --- a/bash-5.1/builtins_rust/exit/src/lib.rs +++ b/bash-5.1/builtins_rust/exit/src/lib.rs @@ -0,0 +1,275 @@ +extern crate libc; +extern crate rjobs; +extern crate nix; + +use libc::c_char; +use std::ffi::CString; + +use rjobs::{PROCESS, COMMAND, r_jobs_builtin, JLIST_STANDARD, WORD_LIST}; + +#[repr(C)] +pub struct JOB { + wd: *mut c_char, + pipe: *mut PROCESS, + pgrp:i32, + state:JOB_STATE, + flags:i32, + deferred:*mut COMMAND, + j_cleanup:*mut fn(), + cleanarg:* mut fn() +} + +#[repr(C)] +pub struct jobstats { + /* limits */ + c_childmax:libc::c_long, + /* child process statistics */ + c_living:libc::c_int, /* running or stopped child processes */ + c_reaped:libc::c_int, /* exited child processes still in jobs list */ + c_injobs:libc::c_int, /* total number of child processes in jobs list */ + /* child process totals */ + c_totforked:libc::c_int, /* total number of children this shell has forked */ + c_totreaped:libc::c_int, /* total number of children this shell has reaped */ + /* job counters and indices */ + j_jobslots:libc::c_int,/* total size of jobs array */ + j_lastj:libc::c_int, /* last (newest) job allocated */ + j_firstj:libc::c_int, /* first (oldest) job allocated */ + j_njobs:libc::c_int, /* number of non-NULL jobs in jobs array */ + j_ndead:libc::c_int, /* number of JDEAD jobs in jobs array */ + /* */ + j_current:libc::c_int, /* current job */ + j_previous:libc::c_int, /* previous job */ + /* */ + j_lastmade:* mut JOB, /* last job allocated by stop_pipeline */ + j_lastasync:* mut JOB /* last async job allocated by stop_pipeline */ +} + + +//枚举 +#[repr(i8)] +#[derive(PartialEq)] +pub enum JOB_STATE { + JNONE = -1, + JRUNNING = 1, + JSTOPPED = 2, + JDEAD = 4, + JMIXED = 8 +} + +//宏 +#[macro_export] +macro_rules! EX_USAGE { + () => { 258 } +} + +#[macro_export] +macro_rules! EXECUTION_SUCCESS { + () => { 0 } +} + +#[macro_export] +macro_rules! EXECUTION_FAILURE{ + () => { 1 } +} + +#[macro_export] +macro_rules! get_job_by_jid { + ($ind:expr) => { + (*((jobs as usize + ($ind*8) as usize ) as *mut*mut JOB) as *mut JOB) + } +} + +#[macro_export] +macro_rules! STOPPED { + ($j:expr) => { + (*get_job_by_jid!($j)).state == JOB_STATE::JSTOPPED + } +} + +#[macro_export] +macro_rules! RUNNING{ + ($j:expr) => { + (*get_job_by_jid!($j)).state == JOB_STATE::JRUNNING + } +} + +#[macro_export] +macro_rules! EXITPROG{ + () => { 3 } +} + +#[macro_export] +macro_rules! SYS_BASH_LOGOOUT { + () => { + CString::new(" \"/etc/bash.bash_logout\" ").unwrap().as_ptr() + } +} + +//C库 +extern "C"{ + static mut interactive:i32; + static mut login_shell:i32; + // static mut last_shell_builtin:*mut fn(v:*mut WORD_LIST)->i32; + static mut last_shell_builtin:extern fn(v:*mut WORD_LIST)->i32; + // static mut this_shell_builtin:*mut fn(v:*mut WORD_LIST)->i32; + static mut this_shell_builtin:extern fn(v:*mut WORD_LIST)->i32; + static js:jobstats ; + static mut check_jobs_at_exit:i32; + static mut jobs:*mut*mut JOB; + static mut running_trap:i32; + static mut trap_saved_exit_value:i32; + static mut last_command_exit_value:i32; + static subshell_environment:i32; + + fn builtin_help(); + fn builtin_error(err:*const c_char,...); + fn list_all_jobs(form:i32); + fn get_exitstat(list:*mut WORD_LIST) -> i32; + fn jump_to_top_level(level:i32); + fn maybe_execute_file(fname:*const c_char,force_noninteractive:i32)->i32; +} + +unsafe fn STREQ(a:*const c_char,b:*const c_char)->bool{ + return *a == *b && libc::strcmp(a,b) == 0; +} + +// unsafe fn printToStderr(str:*mut c_char) -> std::io::Result<()>{ +// let stderr = std::io::stderr(); +// let mut handle = stderr.lock(); +// handle.write_all(std::ffi::CStr::from_ptr(str).to_bytes())?; +// Ok(()) +// } + +// +static mut sourced_logout:i32 = 0; + +#[no_mangle] +pub extern "C" fn r_exit_builtin(list:*mut WORD_LIST) -> i32{ + println!("r_exit_builtin"); + unsafe{ + if list != std::ptr::null_mut() && (*list).word != std::ptr::null_mut() && + STREQ((*(*list).word).word, CString::new("--help").unwrap().as_ptr()){ + builtin_help(); + return EX_USAGE!(); + } + + if interactive != 0 { + if login_shell != 0 { + // let str:*mut c_char = CString::new("logout\n").unwrap().into_raw(); + // printToStderr(str); + eprintln!("logout"); + }else{ + // let str:*mut c_char = CString::new("exit\n").unwrap().into_raw(); + // printToStderr(str); + eprintln!("exit"); + // libc::fprintf(stderr,CString::new("exit\n").unwrap().as_ptr()); + } + + } + // libc::fflush(stderr); + return r_exit_or_logout(list); + } +} + +#[no_mangle] +pub extern "C" fn r_logout_builtin(list:*mut WORD_LIST)->i32{ + unsafe{ + if list != std::ptr::null_mut() && (*list).word != std::ptr::null_mut() && + STREQ((*(*list).word).word, CString::new("--help").unwrap().as_ptr()){ + builtin_help(); + return EX_USAGE!(); + } + + if login_shell == 0{ + builtin_error(CString::new("not login shell: use `exit'").unwrap().as_ptr()); + return EXECUTION_FAILURE!(); + }else{ + return r_exit_or_logout(list) + } + } +} + +#[no_mangle] +pub extern "C" fn r_exit_or_logout(list:*mut WORD_LIST)->i32{ + // let stream:*mut libc::FILE; + let exit_value:i32; + let exit_immediate_okay:i32; + let mut stopmsg:i32; + + unsafe{ + exit_immediate_okay = (interactive == 0 || + last_shell_builtin == r_exit_builtin || + last_shell_builtin == r_logout_builtin || + last_shell_builtin == r_jobs_builtin ) as i32; + + /* Check for stopped jobs if thw user wants to.*/ + if exit_immediate_okay == 0 { + stopmsg = 0; + for i in 0..js.j_jobslots { + if get_job_by_jid!(i) != std::ptr::null_mut() && STOPPED!(i){ + stopmsg = JOB_STATE::JSTOPPED as i32; + } + else if (check_jobs_at_exit != 0) && (stopmsg ==0) && get_job_by_jid!(i) != std::ptr::null_mut() && RUNNING!(i) { + stopmsg = JOB_STATE::JRUNNING as i32; + } + } + + if stopmsg == JOB_STATE::JSTOPPED as i32 { + // libc::fprintf(stream,CString::new("There are stopped jobs. \n").unwrap().as_ptr()); + eprintln!("There are stopped jobs. "); + } + else if stopmsg == JOB_STATE::JRUNNING as i32{ + // libc::fprintf(stream,CString::new("There are runing jobs.\n").unwrap().as_ptr()); + eprintln!("There are runing jobs."); + } + + if stopmsg == check_jobs_at_exit{ + list_all_jobs(JLIST_STANDARD!()) + } + + if stopmsg != 0 { + last_shell_builtin = r_exit_builtin ; + this_shell_builtin = last_shell_builtin ; + return EXECUTION_FAILURE!(); + } + } + + if (running_trap ==1) && (list == std::ptr::null_mut()) + { + exit_value = trap_saved_exit_value; + }else{ + exit_value = get_exitstat(list); + } + + r_bash_logout(); + last_command_exit_value = exit_value; + + jump_to_top_level(EXITPROG!()); + + 0 + } +} + +#[no_mangle] +pub extern "C" fn r_bash_logout(){ + unsafe{ + if login_shell != 0 && sourced_logout == 0 && subshell_environment == 0 { + sourced_logout = sourced_logout + 1; + maybe_execute_file(CString::new("~/.bash_logout").unwrap().as_ptr(),1); + maybe_execute_file(SYS_BASH_LOGOOUT!(),1); + } + } + +} + + + + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/bash-5.1/builtins_rust/fc/Cargo.toml b/bash-5.1/builtins_rust/fc/Cargo.toml index 81017339..5ed92c70 100644 --- a/bash-5.1/builtins_rust/fc/Cargo.toml +++ b/bash-5.1/builtins_rust/fc/Cargo.toml @@ -12,5 +12,5 @@ libc = "0.2" nix = "0.23.0" [lib] -crate-type = ["cdylib"] +crate-type = ["staticlib"] name = "rfc" diff --git a/bash-5.1/builtins_rust/fc/src/lib.rs b/bash-5.1/builtins_rust/fc/src/lib.rs index 3bba2966..409dbe26 100644 --- a/bash-5.1/builtins_rust/fc/src/lib.rs +++ b/bash-5.1/builtins_rust/fc/src/lib.rs @@ -1195,12 +1195,13 @@ pub extern "C" fn fc_readline (stream:* mut libc::FILE)->* mut c_char } } +/* #[no_mangle] pub extern "C" fn cmd_name() ->*const u8 { return b"fc" as *const u8; } - #[no_mangle] pub extern "C" fn run(list : *mut WORD_LIST)->i32 { return r_fc_builtin(list); -} \ No newline at end of file +} +*/ diff --git a/bash-5.1/builtins_rust/fg_bg/Cargo.toml b/bash-5.1/builtins_rust/fg_bg/Cargo.toml index 74b94d65..a15ad2f4 100644 --- a/bash-5.1/builtins_rust/fg_bg/Cargo.toml +++ b/bash-5.1/builtins_rust/fg_bg/Cargo.toml @@ -12,5 +12,5 @@ libc = "0.2" nix = "0.23.0" [lib] -crate-type = ["cdylib"] +crate-type = ["staticlib"] name = "rfg_bg" diff --git a/bash-5.1/builtins_rust/fg_bg/src/lib.rs b/bash-5.1/builtins_rust/fg_bg/src/lib.rs index 689f42d8..224272af 100644 --- a/bash-5.1/builtins_rust/fg_bg/src/lib.rs +++ b/bash-5.1/builtins_rust/fg_bg/src/lib.rs @@ -509,12 +509,13 @@ pub extern "C" fn r_fg_bg (list:*mut WORD_LIST, foreground:i32)->i32{ } } +/* #[no_mangle] pub extern "C" fn cmd_name() ->*const u8 { return b"fg" as *const u8; } - #[no_mangle] pub extern "C" fn run(list : *mut WORD_LIST)->i32 { return r_fg_builtin(list); -} \ No newline at end of file +} +*/ diff --git a/bash-5.1/builtins_rust/getopts/Cargo.toml b/bash-5.1/builtins_rust/getopts/Cargo.toml index f0190df6..1e96f4e5 100644 --- a/bash-5.1/builtins_rust/getopts/Cargo.toml +++ b/bash-5.1/builtins_rust/getopts/Cargo.toml @@ -12,5 +12,5 @@ libc = "0.2" nix = "0.23.0" [lib] -crate-type = ["cdylib"] +crate-type = ["staticlib"] name = "rgetopts" diff --git a/bash-5.1/builtins_rust/getopts/src/lib.rs b/bash-5.1/builtins_rust/getopts/src/lib.rs index 0cb4bee2..9b66e828 100644 --- a/bash-5.1/builtins_rust/getopts/src/lib.rs +++ b/bash-5.1/builtins_rust/getopts/src/lib.rs @@ -547,12 +547,12 @@ pub extern "C" fn r_getopts_builtin(list: * mut WORD_LIST)->i32 } } +/* #[no_mangle] pub extern "C" fn cmd_name() ->*const u8 { return b"getopts" as *const u8; } - #[no_mangle] pub extern "C" fn run(list : *mut WORD_LIST)->i32 { return r_getopts_builtin(list); -} \ No newline at end of file +}*/ diff --git a/bash-5.1/builtins_rust/help/Cargo.toml b/bash-5.1/builtins_rust/help/Cargo.toml index e69de29b..77774e0d 100644 --- a/bash-5.1/builtins_rust/help/Cargo.toml +++ b/bash-5.1/builtins_rust/help/Cargo.toml @@ -0,0 +1,15 @@ +[package] +authors = ["zhanghuanhuan"] +name = "rhelp" +version = "0.0.1" +build = "../build.rs" +edition = "2021" +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +libc = "0.2" +nix = "0.24.1" + +[lib] +crate-type = ["staticlib"] +name = "rhelp" diff --git a/bash-5.1/builtins_rust/help/src/lib.rs b/bash-5.1/builtins_rust/help/src/lib.rs index e69de29b..40847e94 100644 --- a/bash-5.1/builtins_rust/help/src/lib.rs +++ b/bash-5.1/builtins_rust/help/src/lib.rs @@ -0,0 +1,673 @@ +extern crate libc; +extern crate nix; +extern crate std; +use libc::{c_char, c_void ,putchar, free}; +use std::{ffi::{CString,CStr}, i32, io::{Read, stdout, Write}, mem, string, u32}; + +pub enum Option { + None, + Some(T), +} + +#[repr(C)] +pub struct WORD_DESC { + pub word: *mut libc::c_char, + pub flags:libc::c_int +} + +#[repr (C)] +#[derive(Copy,Clone)] +pub struct WORD_LIST { + next: *mut WORD_LIST, + word: *mut WORD_DESC +} + +#[repr (C)] +#[derive(Copy,Clone)] +pub struct builtin { + name : *mut libc::c_char, + function :*mut sh_builtin_func_t, + flags : bool, + long_doc :*mut *mut c_char, + short_doc :*mut libc::c_char, + handle :*mut libc::c_char +} +type sh_builtin_func_t = fn(WORD_LIST) -> i32; + +#[repr(C)] +struct FieldStruct { + name : *mut c_char, +} + + +#[macro_export] +macro_rules! EXECUTION_SUCCESS { + () => {0} +} + +#[macro_export] +macro_rules! EXECUTION_FAILURE{ + () => {-1} +} + +#[macro_export] +macro_rules! FNMATCH_EXTFLAG { + () => {0} +} + +#[macro_export] +macro_rules! EX_USAGE { + () => {258} +} + +#[macro_export] +macro_rules! MB_CUR_MAX { + () => {6} + } + +#[macro_export] +macro_rules! BASE_INDENT{ + () => {4} +} + +#[macro_export] +macro_rules! BUILTIN_ENABLED{ + () => {1} +} + +#[macro_export] +macro_rules! FNM_NOMATCH{ + () => {1} +} + +#[macro_export] +macro_rules! BUILTIN_SIZEOF{ + () => {48} +} + +#[macro_export] +macro_rules! EXIT_FAILURE{ + () => {1} +} + +extern "C"{ + fn reset_internal_getopt(); + fn internal_getopt (list:*mut WORD_LIST , opts:*mut c_char)->i32; + //fn builtin_error(err:*const c_char,...); + fn builtin_usage(); + fn show_shell_version(ver:i32); + fn glob_pattern_p(pattern:*const c_char) -> i32; + fn zcatfd(fd : i32 ,id : i32, nn :*mut c_char) -> i32; + fn zmapfd(fd : i32, name :*mut *mut libc::c_char, nn: *mut libc::c_char) -> i32; + fn sh_builtin_func_t(list :*mut WORD_LIST) -> i32; + fn builtin_address_internal(comand_name:*mut c_char, i:i32) -> *mut builtin; + fn termsig_handler (sig:i32); + fn throw_to_top_level(); + fn default_columns() -> usize; + fn wcsnwidth (chaa : * mut libc::wchar_t, size :i32, i: i32) -> i32; + fn xstrmatch (string1 : * mut libc::c_char, string2 : * mut libc::c_char, i : i8) -> i8; + fn open(pathname : *const libc::c_char, oflag : i32) -> i32; + fn wcwidth( c :libc::wchar_t) -> i32; + static mut loptend:*mut WORD_LIST; + static bash_copyright : *const c_char; + static bash_license : *const c_char; + static mut terminating_signal:i32; + static this_command_name:*mut libc::c_char; + static mut interrupt_state:i32; + static mut num_shell_builtins : i32; + static mut static_shell_builtin : [builtin ; 100]; + static shell_builtins:*mut builtin; + static mut current_builtin :*mut builtin; +} + +#[no_mangle] +pub extern "C" fn r_help_builtin(mut list:*mut WORD_LIST)->i32 { + + // let mut i:i32; + let mut plen:usize; + let mut match_found:i32; + let mut sflag :i32 = 0; + let mut dflag : i32 = 0; + let mut mflag : i32 = 0; + let mut m: bool; + let pass:i32 = 0; + let mut this_found:i32; + let mut pattern:*mut c_char; + let mut name:*mut c_char; + let l:*mut WORD_LIST= list; + let mut i : i32; + unsafe { + reset_internal_getopt(); + } + let c_str_dms = CString::new("dms").unwrap(); // from a &str, creates a new allocation + unsafe { + i = internal_getopt (list, c_str_dms.as_ptr() as * mut c_char); + } + while i != -1 { + let optu8:u8= i as u8; + let optChar:char=char::from(optu8); + match optChar{ + 'd'=> {dflag = 1; break;} + 'm'=> {mflag = 1; break;} + 's'=> {sflag = 1; break;} + _=>{ + unsafe { + builtin_usage (); + return EX_USAGE!(); + } + } + } + } + unsafe { + let pattern = glob_pattern_p ((*(*list).word).word); + if (pattern == 1){ + println!("Shell commands matching keyword, Shell commands matching keyword"); + if (*list).next !=std::ptr::null_mut() { + println!("Shell commands matching keywords"); + } + else { + println!("Shell commands matching keyword"); + } + println!("{:?} ,",list); + } + let mut loptendt=*list; + let mut match_found = 0; + let mut pattern:*mut c_char = 0 as *mut libc::c_char; + while list !=std::ptr::null_mut() { + pattern = (*(*list).word).word; + plen = libc::strlen (pattern); + let mut this_found = 0; + let mut v : Vec<*mut libc::c_char> = Vec::new(); + for val in 0..=75 { + //let nname = &shell_builtins[val].name; + let builtin1 = unsafe{&(*((shell_builtins as usize + (val*BUILTIN_SIZEOF!()) as usize) as *mut builtin))}; + if builtin1.name != std::ptr::null_mut(){ + v.push(builtin1.name); + } + } + for val in 1..3 { + //for &mut namee in &mut v { + for i in 0..v.len(){ + QUIT(); + /* First val: look for exact string or pattern matches. + Second val: look for prefix matches like bash-4.2 */ + if val == 1{ + m = (libc::strcmp (pattern,v[i]) == 0)|| + (strmatch (pattern,v[i], FNMATCH_EXTFLAG!()) != FNM_NOMATCH!()); + } + else{ + m = libc::strncmp (pattern, v[i], plen) == 0; + } + if m { + + this_found = 1; + match_found = match_found +1 ; + if dflag == 1{ + + show_desc (v[i], i as i32); + //continue; + } + else if mflag ==1{ + + show_manpage (v[i], i as i32); + continue; + } + unsafe { + let builtin1 = &(*((shell_builtins as usize + (i*BUILTIN_SIZEOF!()) as usize) as *mut builtin)); + + println! ("{:?}: {:?}\n", CStr::from_ptr(v[i]), CStr::from_ptr(builtin1.short_doc)); + } + if sflag == 0{ + + show_longdoc (i as i32); + } + } + } + if val == 1 && this_found == 1{ + + break; + } + } + + if (*list).next != std::ptr::null_mut(){ + list = (*list).next; + + } + else { + + break; + } + } + if match_found == 0{ + println! ("no help topics match {:?} .Try 'help help' or 'man -k {:?}' or info {:?}", pattern , pattern, pattern); + return EXECUTION_FAILURE!(); + } + } + unsafe { + std::io::stdout().flush(); + } + return EXECUTION_SUCCESS!(); +} + + +#[no_mangle] +pub extern "C" fn r_help_null_builtin (mut list:*mut WORD_LIST) -> i32{ + unsafe { + show_shell_version(0); + } + show_builtin_command_help (); + return EXECUTION_SUCCESS!(); +} + +unsafe fn QUIT () +{ + if terminating_signal !=0 { + termsig_handler (terminating_signal); + } + + if interrupt_state !=0{ + throw_to_top_level(); + } +} + + +#[no_mangle] +pub extern "C" fn r_builtin_help (){ + let mut ind: i32 = 5; + let d: i32; + unsafe { + current_builtin = builtin_address_internal(this_command_name, 0); + if current_builtin == 0 as *mut builtin{ + return ; + } + + d = (current_builtin as usize - shell_builtins as usize) as i32; + } + ind = d ; + /* + #if defined (__STDC__) + ind = (int)d; + #else + ind = (int)d / sizeof (struct builtin); + #endif + */ + unsafe { + let builtin1 = &(*((shell_builtins as usize + (ind*BUILTIN_SIZEOF!()) as usize) as *mut builtin)); + println!("{:?} : {:?}",this_command_name, CStr::from_ptr(builtin1.short_doc)); + } + show_longdoc (ind); +} + +fn open_helpfile(name :*mut c_char) -> i32{ + + let mut fd : i32; + unsafe { + fd = open (name, 0); + + } + if fd == -1 { + return -1; + } + else { + fd + } +} + +fn show_longdoc(i : i32){ + let mut j : i32; + let mut doc :*mut (*mut c_char); + let mut fd : i32; + let mut usefile : bool ; + let builtin1 = unsafe{&(*((shell_builtins as usize + (i*BUILTIN_SIZEOF!()) as usize) as *mut builtin))}; + unsafe { + doc = builtin1.long_doc; + usefile = doc!= std::ptr::null_mut() && (doc as usize + 8 as usize) as * mut c_char != std::ptr::null_mut(); + usefile = usefile && char::from(unsafe {*((*doc as usize) as * mut c_char) as u8 })== '/'; + // usefile = usefile && unsafe{*((doc as usize + 8 as usize)as *mut *mut libc::c_char) as *mut libc::c_char} == std::ptr::null_mut(); + //usefile = usefile && ((doc as usize + 8 as usize) as * mut c_char) == std::ptr::null_mut(); + //usefile = usefile && (*(doc as usize + 8 as usize) as *mut libc::c_char )as char== '/' as char ; + //usefile = doc!= std::ptr::null_mut() && *((doc as usize + ) as * mut c_char)== '/' as i8 && (doc as usize +4)as * mut c_char == std::ptr::null_mut() as * mut c_char; + } + // let usefile = (doc!= std::ptr::null_mut() && char::from(unsafe {*((doc + 4*8) as usize ) as * mut c_char) as u8 })== '/'); + if usefile { + unsafe { + fd = open_helpfile (*builtin1.long_doc); + } + if (fd < 0){ + //无返回值 + return (); + } + unsafe { + zcatfd (fd, 1, *doc); + libc::close (fd); + } + /* XXX - handle errors if zmapfd returns < 0 */ + } + else if doc!= std::ptr::null_mut() { + let mut j = 0 ; + unsafe { + println!("{:?}",CStr::from_ptr(*doc)); + } + } + // while unsafe {*((doc as usize+(8*j) as usize)as * mut * mut c_char) as *mut c_char }!= std::ptr::null_mut(){ + // unsafe { + // println! ("{:?}{:?} {:?}", BASE_INDENT!()," ", CStr::from_ptr(*((doc as usize+(8*j) as usize)as * mut * mut c_char) as *mut c_char)); + // j += 1; + // } + // } + // } +} + +fn show_desc (name : *mut c_char, i :i32){ + + let mut j :i32; + let r :i32; + let mut doc : *mut *mut libc::c_char; + let mut line : *mut i8 = 0 as *mut i8 ; + let mut fd : i32; + let mut usefile : bool; + + let builtin1 = unsafe{&(*((shell_builtins as usize + (i*BUILTIN_SIZEOF!()) as usize) as *mut builtin))}; + unsafe { + doc = builtin1.long_doc; + } + // usefile = (doc && doc[0] && *doc[0] == '/' && doc[1] == (char *)NULL); + usefile = doc!= std::ptr::null_mut() && unsafe {*doc as *mut i8} != std::ptr::null_mut(); + usefile = usefile && unsafe {**doc as i8 } == '/' as i8; + //usefile = usefile && unsafe {*(doc as usize + 8 as usize) as *mut i8} != std::ptr::null_mut(); + if usefile { + + fd = open_helpfile (unsafe {*doc as *mut i8 }); + if (fd < 0){ + //无返回值 + return (); + } + unsafe { + r = zmapfd (fd, *(line as *mut i8) as *mut *mut i8 ,(doc as *mut i8)); + libc::close (fd); + } + /* XXX - handle errors if zmapfd returns < 0 */ + } + else + { + if doc!= std::ptr::null_mut() { + unsafe { + line = *doc as *mut i8; + } + } + else{ + + line = std::ptr::null_mut(); + } + } + + unsafe { + println!("{:?}",CStr::from_ptr(name)); + } + let mut j = 0 ; + while ((line as usize + (8*j)) as * mut c_char)!= std::ptr::null_mut() { + unsafe { + libc::putchar (*((line as usize + (8*j))as * mut c_char) as i32); + if char::from(*((line as usize + (8*j))as * mut c_char) as u8)== '\n'{ + break; + } + } + j += 1; + } + unsafe { + std::io::stdout().flush(); + } + if usefile{ + unsafe { + libc::free (line as * mut c_void); + } + } +} +fn show_manpage (name : *mut c_char, i : i32){ + + let mut j :i32; + let mut doc :*mut *mut libc::c_char; + let mut line :*mut libc::c_char = 0 as *mut libc::c_char;; + let mut fd: i32; + let mut usefile : bool; + let builtin1 = unsafe{&(*((shell_builtins as usize + (i*BUILTIN_SIZEOF!()) as usize) as *mut builtin))}; + unsafe { + + doc = builtin1.long_doc; + } + //*doc = (*((shell_builtins as usize + i as usize) as *mut builtin).long_doc as *mut libc::c_char); + usefile = doc!= std::ptr::null_mut() && unsafe {*doc as *mut i8} != std::ptr::null_mut(); + usefile = usefile && unsafe {**doc as i8 } == '/' as i8; + + if usefile{ + + unsafe { + fd = open_helpfile (*doc); + } + if fd < 0 { + //无返回值 + return (); + } + unsafe{ + zmapfd (fd, line as *mut *mut libc::c_char, *doc); + libc::close (fd); + } + } + else { + + if doc!= std::ptr::null_mut(){ + unsafe { + line = *doc as *mut i8; + } + } + else{ + line = std::ptr::null_mut(); + } + } + /* NAME */ + println! ("NAME\n"); + unsafe { + println! (" - {:?} ", CStr::from_ptr(name)); + } + let mut j = 0 ; + unsafe { + while (*((doc as usize + (8*j))as *mut *mut c_char)as *mut c_char) != std::ptr::null_mut() { + libc::putchar (*((line as usize + (8*j)) as * mut c_char) as i32); + if char::from(*((line as usize + (8*j))as * mut c_char) as u8) == '\n'{ + break; + } + j += 1; + } + } + + println! ("\n"); + + /* SYNOPSIS */ + println! ("SYNOPSIS\n"); + unsafe { + println! (" {:?}\n", CStr::from_ptr(builtin1.short_doc)); + } + /* DESCRIPTION */ + println! ("DESCRIPTION\n"); + if !usefile{ + let mut j = 0 ; + unsafe { + while (*((doc as usize + (8*j))as *mut *mut c_char)as *mut c_char) != std::ptr::null_mut() { + println! (" {:?}\n", unsafe{CStr::from_ptr(*((doc as usize + (8*j))as *mut *mut c_char)as *mut c_char)}); + j += 1; + } + } + } + else{ + while doc != std::ptr::null_mut() && (((doc as usize + (8*j)))as * mut c_char) != std::ptr::null_mut() { + unsafe { + libc::putchar (*((doc as usize + (8*j))as * mut c_char)as i32); + } + println! (" "); + } + j += 1; + } + unsafe { + libc::putchar ('\n' as i32); + } + /* SEE ALSO */ + + println! ("SEE ALSO\n"); + println! (" rash(1) {} \n\n"," "); + + /* IMPLEMENTATION */ + println! ("IMPLEMENTATION\n"); + println! (" "); + unsafe { + show_shell_version (0); + } + println! (" "); + unsafe { + println! ("{:?}", CStr::from_ptr(bash_copyright)); + } + println! (" "); + unsafe { + println! ("{:?}", CStr::from_ptr(bash_license)); + } + //fflush (stdout); + if usefile { + unsafe { + libc::free (line as * mut c_void); + } + } +} + +#[no_mangle] +pub extern "C" fn dispcolumn (i : i32, buf : *mut c_char, bufsize :libc::c_int, width : usize, height : i32){ + let mut j : i32; + let mut dispcols : usize; + let mut helpdoc :*mut libc::c_char; + /* first column */ + let mut builtin1 = unsafe{&(*((shell_builtins as usize + (i*BUILTIN_SIZEOF!()) as usize) as *mut builtin))}; + helpdoc = builtin1.short_doc; + unsafe { + libc::strncpy (((buf as usize + 4 as usize ) as * mut c_char), helpdoc, width - 2); + *((buf as usize + (width - 2) as usize) as * mut c_char)='>' as c_char; + *((buf as usize+(width - 1) as usize) as * mut c_char)='\0' as c_char; + } + /* indicate truncation */ + println! ("{:?}", buf); + unsafe { + if ((i << 1) >= num_shell_builtins) || (i+height >= num_shell_builtins){ + println! ("\n"); + return; + } + } + dispcols = unsafe {libc::strlen(buf)}; + /* two spaces */ + for j in dispcols .. width{ + std::io::stdout().write(b" "); + } + /* second column */ + builtin1 = unsafe{&(*((shell_builtins as usize + (((i+height)*BUILTIN_SIZEOF!()) as usize)) as *mut builtin))}; + helpdoc = builtin1.short_doc as *mut libc::c_char; + unsafe { + if builtin1.flags && BUILTIN_ENABLED!()==1 { + *((buf as usize) as * mut c_char)=' ' as c_char; + } + else{ + *((buf as usize) as * mut c_char)='*' as c_char; + } + libc::strncpy (((buf as usize + 4 as usize ) as * mut c_char), helpdoc, width - 3); + *((buf as usize + (width - 3) as usize) as * mut c_char)='>' as c_char; + *((buf as usize+(width - 2) as usize) as * mut c_char)='\0' as c_char; + } + println! ("{:?}\n", buf); +} + +pub fn wdispcolumn (i : i32, buf :*mut c_char, bufsize : i32, width : i32, height : i32){ + let mut j : i32; + let mut dispcols : i32 = 0; + let mut dispchars : i32 = 0; + let mut helpdoc :*mut c_char; + let mut wcstr:*mut libc::wchar_t; + let mut slen : i32 = 0; + let mut n :i32 = 0; + let mut builtin1 = unsafe{&(*((shell_builtins as usize + (i*BUILTIN_SIZEOF!()) as usize) as *mut builtin))}; + helpdoc = builtin1.short_doc; + unsafe { + println! ("{:?}", CStr::from_ptr(helpdoc)); + } + +} + +fn show_builtin_command_help (){ + let mut i : i32; + let mut j : i32; + let height : i32 = 76; + let mut width : usize; + let mut t :*mut libc::c_char; + let mut blurb:[i8;128] = ['0' as i8;128]; + println!("help command edit by huanhuan."); + println!("{}",("These shell commands are defined internally. Type `help' to see this list.\n Type `help name' to find out more about the function `name'.\n Use `info bash' to find out more about the shell in general.\n Use `man -k' or `info' to find out more about commands not in this list.\n A star (*) next to a name means that the command is disabled.\n")); + + let ref2: &mut i8= &mut blurb[0]; + + unsafe { + width = default_columns(); + } + width /= 2; + if width > (std::mem::size_of::()*128) { + width = std::mem::size_of::()*128; + } + if width <= 3{ + width = 40; + } + // unsafe { + // height = (num_shell_builtins + 1) / 2; /* number of rows */ + // } + for i in 0..height{ + unsafe { + QUIT(); + } + if MB_CUR_MAX!() > 1 { + let ptr2: *mut i8 = ref2 as *mut i8; + wdispcolumn (i, ptr2,128, width as i32, height); + } +} +} +//#endif /* HELP_BUILTIN */ +fn strmatch (pattern : *mut libc::c_char, string : *mut libc::c_char, flags : i8) -> i8 +{ + if ((string as usize)as * mut c_char != std::ptr::null_mut()) || ((pattern as usize)as * mut c_char != std::ptr::null_mut()){ + return FNM_NOMATCH!(); + } + return unsafe {xstrmatch (pattern, string, flags)}; +} + +struct Thing { + pointer_to_self: *mut Thing, +} + +fn xmalloc (size:usize) ->*mut c_void { + let ret: *mut c_void; +unsafe { + ret = libc::malloc(size); +} +// if (ret == 0) { +// println!("man2html: out of memory"); +// // fprintf(stderr, "man2html: out of memory"); +// (1) +// } + ret +} + +// fn wcswidth(pwcs : *mut libc::wchar_t , n : i32) -> i32{ +// let mut wc : libc::wchar_t; +// let mut len : i32 = 0; +// let mut l : i32; + +// while n-1 > 0 && *(pwcs as usize + 1 as usize) != '\0' as libc::wchar_t{ +// wc = *(pwcs += 1); +// if wcwidth(wc) < 0 { +// return -1; +// } +// len += l; +// } +// len +// } diff --git a/bash-5.1/builtins_rust/history/Cargo.toml b/bash-5.1/builtins_rust/history/Cargo.toml index 6f1d922d..cba7b260 100644 --- a/bash-5.1/builtins_rust/history/Cargo.toml +++ b/bash-5.1/builtins_rust/history/Cargo.toml @@ -3,7 +3,7 @@ name = "history" version = "0.1.0" edition = "2021" authors = ["lvgenggeng"] -build = "../build.rs" +#build = "../build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/bash-5.1/builtins_rust/jobs/Cargo.toml b/bash-5.1/builtins_rust/jobs/Cargo.toml index fa26bda5..c5c96c0b 100644 --- a/bash-5.1/builtins_rust/jobs/Cargo.toml +++ b/bash-5.1/builtins_rust/jobs/Cargo.toml @@ -2,7 +2,6 @@ authors = ["huzhengming"] name = "rjobs" version = "0.0.1" -build = "../build.rs" edition = "2021" @@ -12,5 +11,5 @@ libc = "0.2" nix = "0.23.0" [lib] -crate-type = ["cdylib"] +crate-type = ["staticlib","rlib"] name = "rjobs" diff --git a/bash-5.1/builtins_rust/jobs/src/lib.rs b/bash-5.1/builtins_rust/jobs/src/lib.rs index 9456b58f..3f74083e 100644 --- a/bash-5.1/builtins_rust/jobs/src/lib.rs +++ b/bash-5.1/builtins_rust/jobs/src/lib.rs @@ -13,8 +13,8 @@ pub struct WORD_DESC { #[repr(C)] #[derive(Copy,Clone)] pub struct WORD_LIST { - next: *mut WORD_LIST, - word: *mut WORD_DESC + pub next: *mut WORD_LIST, + pub word: *mut WORD_DESC } #[repr(i8)] @@ -440,7 +440,7 @@ extern "C" { #[no_mangle] pub extern "C" fn r_jobs_builtin(list:*mut WORD_LIST)->i32 { - //println!("r_jobs_builtin"); + println!("r_jobs_builtin"); let mut form:i32; let mut execute:i32=0; let mut state:i32; @@ -616,8 +616,10 @@ pub extern "C" fn r_disown_builtin (list:* mut WORD_LIST)->libc::c_int { pub extern "C" fn cmd_name() ->*const u8 { return b"jobs" as *const u8; } - +/* #[no_mangle] + pub extern "C" fn run(list : *mut WORD_LIST)->i32 { return r_jobs_builtin(list); -} \ No newline at end of file +} +*/ diff --git a/bash-5.1/builtins_rust/kill/Cargo.toml b/bash-5.1/builtins_rust/kill/Cargo.toml index e3f22a15..0c411d86 100644 --- a/bash-5.1/builtins_rust/kill/Cargo.toml +++ b/bash-5.1/builtins_rust/kill/Cargo.toml @@ -3,7 +3,7 @@ name = "kill" version = "0.1.0" edition = "2021" authors = ["lvgenggeng"] -build = "../build.rs" +#build = "../build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/bash-5.1/builtins_rust/mapfile/Cargo.toml b/bash-5.1/builtins_rust/mapfile/Cargo.toml index e69de29b..91ffc2e8 100644 --- a/bash-5.1/builtins_rust/mapfile/Cargo.toml +++ b/bash-5.1/builtins_rust/mapfile/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "mapfile" +version = "0.1.0" +edition = "2021" +authors = ["lvgenggeng"] +#build = "../build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +name = "rmapfile" +crate-type = ["cdylib"] + +[dependencies] +libc = "0.2" +nix = "0.23" diff --git a/bash-5.1/builtins_rust/mapfile/src/intercdep.rs b/bash-5.1/builtins_rust/mapfile/src/intercdep.rs new file mode 100644 index 00000000..f4de2e9c --- /dev/null +++ b/bash-5.1/builtins_rust/mapfile/src/intercdep.rs @@ -0,0 +1,114 @@ + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_desc { + pub word: *mut c_char, + pub flags: c_int, +} +pub type WORD_DESC = word_desc; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_list { + pub next: *mut word_list, + pub word: *mut WORD_DESC, +} +pub type WORD_LIST = word_list; + +pub type arrayind_t = c_long; + +pub type sh_var_value_func_t = + ::std::option::Option *mut variable>; + + pub type sh_var_assign_func_t = ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut variable, + arg2: *mut c_char, + arg3: arrayind_t, + arg4: *mut c_char, + ) -> *mut variable, +>; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct variable { + pub name: *mut c_char, + pub value: *mut c_char, + pub exportstr: *mut c_char, + pub dynamic_value: sh_var_value_func_t, + pub assign_func: sh_var_assign_func_t, + pub attributes: c_int, + pub context: c_int, +} +pub type SHELL_VAR = variable; + +pub const atype_array_indexed: atype = 0; +pub const atype_array_assoc: atype = 1; +pub type atype = c_uint; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct array { + pub type_: atype, + pub max_index: arrayind_t, + pub num_elements: c_int, + pub head: *mut array_element, + pub lastref: *mut array_element, +} +pub type ARRAY = array; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct array_element { + pub ind: arrayind_t, + pub value: *mut c_char, + pub next: *mut array_element, + pub prev: *mut array_element, +} +pub type ARRAY_ELEMENT = array_element; + +pub const ESPIPE: c_int = 29; +pub const SEEK_CUR: c_int = 1; + +pub const EXECUTION_SUCCESS : c_int = 0; +pub const EXECUTION_FAILURE : c_int = 1; +pub const EX_USAGE: c_int = 258; + +pub const SEVAL_NOHIST: c_int = 0x004; + +pub const att_readonly: c_int = 0x0000002; +pub const att_array: c_int = 0x0000004; +pub const att_invisible: c_int = 0x0001000; +pub const att_noassign: c_int = 0x0004000; + +extern "C" { + pub fn reset_internal_getopt(); + pub fn internal_getopt(list: *mut WORD_LIST, opts: *mut c_char) -> c_int; + pub fn builtin_usage(); + pub fn builtin_error(format: *const c_char, ...); + + pub fn legal_identifier(arg1: *const c_char) -> c_int; + pub fn legal_number (str1:*const c_char,result:* mut c_long) -> i32; + pub fn sh_invalidid(arg1: *mut c_char); + pub fn sh_validfd(arg1: c_int) -> c_int; + + pub fn sh_single_quote(s: *mut c_char) -> *mut c_char; + + pub fn evalstring(string: *mut c_char, from_file: *const c_char, flags: c_int) -> c_int; + + pub fn find_or_make_array_variable(name: *mut c_char, flags: c_int) -> *mut SHELL_VAR; + + pub fn bind_array_element(entry: *mut SHELL_VAR, ind: c_long, value: *mut c_char, flags: c_int) -> *mut SHELL_VAR; + + pub fn array_flush(a: *mut ARRAY); + + pub fn err_readonly(s: *const c_char) -> c_void; + + pub fn zreset() -> c_void; + pub fn zsyncfd(fd: c_int) -> c_void; + pub fn zgetline (fd: c_int, lineptr: *mut *mut c_char, n: *mut size_t, delim: c_int, unbuffered_read: c_int) -> ssize_t; + + pub static mut list_optarg : *mut libc::c_char; + pub static mut loptend : *mut WORD_LIST; + +} diff --git a/bash-5.1/builtins_rust/mapfile/src/lib.rs b/bash-5.1/builtins_rust/mapfile/src/lib.rs index e69de29b..b5f8ba84 100644 --- a/bash-5.1/builtins_rust/mapfile/src/lib.rs +++ b/bash-5.1/builtins_rust/mapfile/src/lib.rs @@ -0,0 +1,220 @@ +use std::{ffi::CString}; + +use libc::{size_t, ssize_t, c_int, c_uint, c_char, c_uchar, c_long, c_void, PT_NULL}; + +include!(concat!("intercdep.rs")); + +pub const DEFAULT_QUANTUM: c_long = 5000; +pub const MAPF_CLEARARRAY: c_int = 0x01; +pub const MAPF_CHOP: c_int = 0x02; + +static mut delim: c_int = 0; + +#[no_mangle] +pub extern "C" fn r_mapfile_builtin(mut list: *mut WORD_LIST) -> i32 { + println!("r_mapfile_builtin call"); + + let mut opt: c_int; + let mut code: c_int; + let mut fd: c_int = 0; + let mut flags: c_int = MAPF_CLEARARRAY; + let intval: c_long = 0; + let mut lines: c_long = 0; + let mut origin: c_long = 0; + let mut nskip: c_long = 0; + let mut callback_quantum: c_long = DEFAULT_QUANTUM; + + let array_name: *mut c_char; + let mut callback: *mut c_char = PT_NULL as *mut c_char; + +unsafe { + + delim = b'\n' as c_int; + + reset_internal_getopt(); + let opt_str = CString::new("d:u:n:O:tC:c:s:").unwrap(); + opt = internal_getopt (list, opt_str.as_ptr() as * mut c_char); + while opt != -1 { + let opt_char:char=char::from(opt as u8); + match opt_char { + 'd' => delim = *list_optarg as c_int, + 'u' => { + code = legal_number(list_optarg, std::mem::transmute(&intval)); + if code == 0 || intval < 0 || intval != (intval as c_int) as c_long{ + builtin_error("%s: invalid file descriptor specification\0".as_ptr() as *const c_char, list_optarg); + return EXECUTION_FAILURE; + } else { + fd = intval as c_int; + } + if sh_validfd(fd) == 0 { + builtin_error("%d: invalid file descriptor: %s\0".as_ptr() as *const c_char, + fd, libc::strerror(*libc::__errno_location())); + return EXECUTION_FAILURE; + } + } + 'n' => { + code = legal_number(list_optarg, std::mem::transmute(&intval)); + if code == 0 || intval < 0 || intval != (intval as c_uint) as c_long { + builtin_error("%s: invalid line count\0".as_ptr() as *const c_char, list_optarg); + return EXECUTION_FAILURE; + } else { + lines = intval; + } + } + 'O' => { + code = legal_number(list_optarg, std::mem::transmute(&intval)); + if code == 0 || intval < 0 || intval != (intval as c_uint) as c_long { + builtin_error("%s: invalid array origin\0".as_ptr() as *const c_char, + list_optarg); + return EXECUTION_FAILURE; + } else { + origin = intval; + } + flags &= (MAPF_CLEARARRAY as c_uint ^ 0xffffffff) as c_int; + } + 't' => flags |= MAPF_CHOP, + 'C' => callback = list_optarg, + 'c' => { + code = legal_number(list_optarg, std::mem::transmute(&intval)); + if code == 0 || intval < 0 || intval != (intval as c_uint) as c_long { + builtin_error("%s: invalid callback quantum\0".as_ptr() as *const c_char, list_optarg); + return EXECUTION_FAILURE; + } else { + callback_quantum = intval; + } + } + 's' => { + code = legal_number(list_optarg, std::mem::transmute(&intval)); + if code == 0 || intval < 0 || intval != (intval as c_uint) as c_long { + builtin_error("%s: invalid line count\0".as_ptr() as *const c_char, list_optarg); + return EXECUTION_FAILURE; + } else { + nskip = intval; + } + } + _ => { + builtin_usage (); + return EX_USAGE; + } + } + opt = internal_getopt (list, opt_str.as_ptr() as * mut c_char); + } + list = loptend; + + if list.is_null() { + array_name = "MAPFILE".as_ptr() as *mut c_char; + } else if (*list).word.is_null() || (*(*list).word).word.is_null() { + builtin_error("internal error: getting variable name\0".as_ptr() as *const c_char); + return EXECUTION_FAILURE; + } else if *(*(*list).word).word == b'\0' as c_char { + builtin_error("empty array variable name\0".as_ptr() as *const c_char); + return EX_USAGE; + } else { + array_name = (*(*list).word).word; + } + if legal_identifier(array_name) == 0 { + sh_invalidid(array_name); + return EXECUTION_FAILURE; + } + + return mapfile(fd, lines, origin, nskip, callback_quantum, callback, + array_name, delim, flags); +} +} + +unsafe fn run_callback(callback: *const c_char, curindex: c_uint, curline: *mut c_char) -> c_int +{ + let qline = sh_single_quote(curline); + let execlen = libc::strlen(callback) + libc::strlen(qline) + 10 + 3; + let execstr = libc::malloc(execlen); + + let flags = SEVAL_NOHIST; + + libc::snprintf(execstr as *mut c_char, execlen, "%s %d %s\0".as_ptr() as *const c_char, + callback, curindex, qline); + libc::free(qline as *mut c_void); + return evalstring(execstr as *mut c_char, PT_NULL as *const c_char, flags); +} + +unsafe fn do_chop(line: *mut c_char, d: c_uchar) +{ + let length = libc::strlen(line); + if length != 0 && *((line as usize + length - 1) as *mut c_char) == d as c_char { + *((line as usize + length - 1) as *mut c_char) = b'\0' as c_char; + } +} + +unsafe fn mapfile(fd: c_int, line_count_goal: c_long, origin: c_long, nskip: c_long, callback_quantum: c_long, + callback: *mut c_char, array_name: *mut c_char, dlm: c_int, flags: c_int) -> c_int +{ + let mut line: *mut c_char = PT_NULL as *mut c_char; + let mut line_length: size_t = 0; + let mut unbuffered_read: c_int; + + let entry = find_or_make_array_variable(array_name, 1); + if entry.is_null() || ((*entry).attributes & att_readonly) != 0 || ((*entry).attributes & att_noassign) != 0 { + if !entry.is_null() && ((*entry).attributes & att_readonly) != 0 { + err_readonly(array_name); + } + + return EXECUTION_FAILURE; + } else if ((*entry).attributes & att_array) == 0 { + builtin_error("%s: not an indexed array\0".as_ptr() as *const c_char, array_name); + return EXECUTION_FAILURE; + } else if ((*entry).attributes & att_array) != 0 { + (*entry).attributes &= (att_invisible as c_uint ^ 0xffffffff) as c_int; + } + + if (flags & MAPF_CLEARARRAY) != 0 { + array_flush(std::mem::transmute((*entry).value)); + } + unbuffered_read = ((libc::lseek(fd, 0, SEEK_CUR) < 0) && (*libc::__errno_location() == ESPIPE)) as c_int; + + if dlm != b'\n' as c_int { + unbuffered_read = 1; + } + zreset(); + + let mut line_count: c_uint = 0; + while (line_count as c_long) < nskip { + if zgetline(fd, std::mem::transmute(&line), std::mem::transmute(&line_length), dlm, unbuffered_read) < 0 { + break; + } + line_count += 1; + } + + line = PT_NULL as *mut c_char; + line_length = 0; + let mut array_index: c_uint = origin as c_uint; + line_count = 1; + while zgetline(fd, std::mem::transmute(&line), std::mem::transmute(&line_length), dlm, unbuffered_read) != -1 { + if (flags & MAPF_CHOP) != 0 { + do_chop(line, dlm as c_uchar); + } + + if !callback.is_null() && line_count != 0 && (line_count as c_long % callback_quantum) == 0 { + run_callback(callback, array_index, line); + + if unbuffered_read == 0 { + zsyncfd(fd); + } + } + + bind_array_element(entry, array_index as c_long, line, 0); + + line_count += 1; + if line_count_goal != 0 && (line_count as c_long) > line_count_goal { + break; + } + + array_index += 1; + } + + libc::free(line as *mut c_void); + + if unbuffered_read == 0 { + zsyncfd(fd); + } + + return EXECUTION_SUCCESS; +} diff --git a/bash-5.1/builtins_rust/printf/Cargo.toml b/bash-5.1/builtins_rust/printf/Cargo.toml index e69de29b..56d9f433 100644 --- a/bash-5.1/builtins_rust/printf/Cargo.toml +++ b/bash-5.1/builtins_rust/printf/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "printf" +version = "0.1.0" +edition = "2021" +authors = ["lvgenggeng"] +#build = "../build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +name = "rprintf" +crate-type = ["cdylib"] + +[dependencies] +libc = "0.2" +nix = "0.23" diff --git a/bash-5.1/builtins_rust/printf/src/intercdep.rs b/bash-5.1/builtins_rust/printf/src/intercdep.rs new file mode 100644 index 00000000..f782774a --- /dev/null +++ b/bash-5.1/builtins_rust/printf/src/intercdep.rs @@ -0,0 +1,117 @@ +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_desc { + pub word: *mut c_char, + pub flags: c_int, +} +pub type WORD_DESC = word_desc; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_list { + pub next: *mut word_list, + pub word: *mut WORD_DESC, +} +pub type WORD_LIST = word_list; + +pub type SHELL_VAR = variable; + +pub type __intmax_t = c_long; +pub type intmax_t = __intmax_t; +pub type arrayind_t = intmax_t; +pub type sh_var_value_func_t = + ::std::option::Option *mut variable>; + + pub type sh_var_assign_func_t = ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut variable, + arg2: *mut c_char, + arg3: arrayind_t, + arg4: *mut c_char, + ) -> *mut variable, +>; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct variable { + pub name: *mut c_char, + pub value: *mut c_char, + pub exportstr: *mut c_char, + pub dynamic_value: sh_var_value_func_t, + pub assign_func: sh_var_assign_func_t, + pub attributes: c_int, + pub context: c_int, +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub union __mbstate_t__bindgen_ty_1 { + pub __wch: c_uint, + pub __wchb: [c_char; 4], +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct __mbstate_t { + pub __count: c_int, + pub __value: __mbstate_t__bindgen_ty_1, +} +pub type mbstate_t = __mbstate_t; + +pub const EXECUTION_SUCCESS : c_int = 0; +pub const EXECUTION_FAILURE : c_int = 1; +pub const EX_USAGE: c_int = 258; + +pub const VA_NOEXPAND: c_int = 0x001; +pub const VA_ONEWORD: c_int = 0x002; + +pub const att_readonly: c_int = 0x0000002; +pub const att_noassign: c_int = 0x0004000; + +extern "C" { + pub fn reset_internal_getopt(); + pub fn internal_getopt(list: *mut WORD_LIST, opts: *mut c_char) -> c_int; + pub fn builtin_usage(); + pub fn builtin_error(format: *const c_char, ...); + pub fn builtin_warning(format: *const c_char, ...); + pub fn builtin_bind_variable(name: *mut c_char, value: *mut c_char, flags: c_int) -> *mut SHELL_VAR; + pub fn stupidly_hack_special_variables(name: *const c_char) -> c_void; + pub fn legal_identifier(arg1: *const c_char) -> c_int; + pub fn legal_number (str1:*const c_char,result:* mut c_long) -> i32; + pub fn sh_invalidid(arg1: *mut c_char); + + pub fn valid_array_reference (name: *const c_char, flags: c_int) -> c_int; + pub fn bind_var_to_int(var: *mut c_char, val: c_long) -> *mut SHELL_VAR; + + pub fn mbtowc(pwc: *mut libc::wchar_t, s: *const c_char, n: size_t) -> size_t; + + pub fn sh_invalidnum(s: *mut c_char) -> c_void; + + pub fn xmalloc(bytes: size_t) -> *mut c_void; + pub fn xrealloc(p: *mut c_void, bytes: size_t) -> *mut c_void; + pub fn savestring(s: *const c_char) -> *mut c_char; + pub fn ansic_shouldquote(s: *const c_char) -> c_int; + pub fn ansic_quote(str: *mut c_char, flags: c_int, rlen: *mut c_int) -> *mut c_char; + pub fn sh_backslash_quote(string: *mut c_char, table: *mut c_char, flags: c_int) -> *mut c_char; + + pub fn u32cconv(c: c_ulong, s: *mut c_char) -> c_int; + + pub fn termsig_handler(arg1: c_int) -> c_void; + pub fn throw_to_top_level() -> c_void; + + pub fn sv_tz(name: *mut c_char) -> c_void; + pub fn strftime(s: *mut c_char, maxsize: size_t, format: *const c_char, timeptr: *const libc::tm) -> size_t; + + pub fn sh_wrerror() -> c_void; + + pub static mut list_optarg : *mut libc::c_char; + pub static mut loptend : *mut WORD_LIST; + pub static mut assoc_expand_once: c_int; + + pub static terminating_signal : c_int; + pub static interrupt_state : c_int; + + pub static stdout: *mut libc::FILE; + + pub static shell_start_time: libc::time_t; +} \ No newline at end of file diff --git a/bash-5.1/builtins_rust/printf/src/lib.rs b/bash-5.1/builtins_rust/printf/src/lib.rs index e69de29b..eae57791 100644 --- a/bash-5.1/builtins_rust/printf/src/lib.rs +++ b/bash-5.1/builtins_rust/printf/src/lib.rs @@ -0,0 +1,1214 @@ +use std::{ffi::CString}; +use libc::{size_t, c_int, c_uint, c_char, c_long, c_void, PT_NULL, c_ulong, strchr}; + +include!(concat!("intercdep.rs")); + +macro_rules! IS_DIGITAL { + ($x: expr) => { + $x >= b'0' as c_char && $x <= b'9' as c_char + }; +} + +unsafe fn QUIT() +{ + if terminating_signal != 0 { + termsig_handler(terminating_signal); + } + + if interrupt_state != 0 { + throw_to_top_level(); + } +} + +unsafe fn PC(c: u8) +{ + let mut b: [c_char; 2] = [0; 2]; + tw += 1; + b[0] = c as c_char; + if vflag != 0 { + vbadd(b.as_ptr() as *mut c_char, 1); + } else { + libc::putchar(c as c_int ); + } + QUIT(); +} + +static mut conversion_error: c_int = 0; +static mut conv_buf: *mut c_char = PT_NULL as *mut c_char; +static mut conv_bufsize: size_t = 0; + +static mut vbuf: *mut c_char = PT_NULL as *mut c_char; +static mut vname: *mut c_char = PT_NULL as *mut c_char; +static mut vflag: c_int = 0; +static mut vbsize: size_t = 0; +static mut vblen: c_int = 0; + +static mut retval: c_int = 0; +static mut tw: c_long = 0; + +static mut garglist: *mut WORD_LIST = PT_NULL as *mut WORD_LIST; +static mut orig_arglist: *mut WORD_LIST = PT_NULL as *mut WORD_LIST; + +#[no_mangle] +pub extern "C" fn r_printf_builtin(mut list: *mut WORD_LIST) -> i32 { + println!("r_printf_builtin call"); + + let mut ch: c_int; + let mut fieldwidth: c_int; + let mut have_fieldwidth: c_int; + let mut precision: c_int; + let mut have_precision: c_int; + let mut arrayflags: c_int; + + let mut fmt; + let mut start; + let mut modstart; + let mut convch; + let mut thisch; + let mut nextch; +unsafe { + + let PRETURN = |out_val: c_int| { + QUIT(); + if vflag != 0 { + let v = builtin_bind_variable(vname, vbuf, 0); + stupidly_hack_special_variables(vname); + if v.is_null() || ((*v).attributes & att_readonly) != 0 || ((*v).attributes & att_noassign) != 0 { + return EXECUTION_FAILURE; + } + } + if conv_bufsize > 4096 { + libc::free(conv_buf as *mut c_void); + conv_bufsize = 0; + conv_buf = PT_NULL as *mut c_char; + } + + if vbsize > 4096 { + libc::free(vbuf as *mut c_void); + vbsize = 0; + vbuf = PT_NULL as *mut c_char; + } else if !vbuf.is_null() { + *vbuf = 0; + } + + if libc::ferror(stdout) == 0 { + libc::fflush(stdout); + } + QUIT(); + if libc::ferror(stdout) != 0 { + sh_wrerror(); + libc::clearerr(stdout); + return EXECUTION_FAILURE; + } + + return out_val; + }; + + vflag = 0; + reset_internal_getopt(); + let opt_str = CString::new("v:").unwrap(); + let mut opt = internal_getopt (list, opt_str.as_ptr() as * mut c_char); + while opt != -1 { + let opt_char:char=char::from(opt as u8); + match opt_char { + 'v' => { + vname = list_optarg; + arrayflags = if assoc_expand_once != 0 {VA_NOEXPAND | VA_ONEWORD} else {0}; + if legal_identifier(vname) != 0 || valid_array_reference(vname, arrayflags) != 0 { + vflag = 1; + if vbsize == 0 { + vbsize = 16; + vbuf = xmalloc(16) as *mut c_char; + } + vblen = 0; + if !vbuf.is_null() { + *vbuf = 0; + } + } else { + sh_invalidid(vname); + return EX_USAGE; + } + } + _ => { + builtin_usage (); + return EX_USAGE; + } + } + opt = internal_getopt (list, opt_str.as_ptr() as * mut c_char); + } + list = loptend; + + if list.is_null() { + builtin_usage(); + return EX_USAGE; + } + + if vflag != 0 && !((*(*list).word).word.is_null()) && *(*(*list).word).word == b'\0' as c_char { + let v = builtin_bind_variable(vname, "\0".as_ptr() as *mut c_char, 0); + stupidly_hack_special_variables(vname); + return if v.is_null() || ((*v).attributes & att_readonly) != 0 || ((*v).attributes & att_noassign) != 0 {EXECUTION_FAILURE} else {EXECUTION_SUCCESS}; + } + + if (*(*list).word).word.is_null() || *(*(*list).word).word == b'\0' as c_char { + return EXECUTION_SUCCESS; + } + + let format = (*(*list).word).word; + tw = 0; + + garglist = (*list).next; + orig_arglist = (*list).next; + + if format.is_null() || *format == 0 { + return EXECUTION_SUCCESS; + } + + 'outer: loop { + tw = 0; + fmt = format; + while *fmt != 0 { + precision = 0; + fieldwidth = 0; + have_fieldwidth = 0; + have_precision = 0; + + if *fmt == b'\\' as c_char { + fmt = (fmt as usize + 1) as *mut c_char; + let mut mbch: [i8;25] = [0; 25]; + let mut mblen: c_int = 0; + fmt = (fmt as usize + tescape(fmt, mbch.as_ptr() as *mut c_char, std::mem::transmute(&mblen), PT_NULL as *mut c_int) as usize) as *mut c_char; + let mut mbind = 0; + while mbind < mblen { + PC(mbch[mbind as usize] as u8); + } + fmt = (fmt as usize - 1) as *mut c_char; + continue; + } + + if *fmt != b'%' as c_char { + PC(*fmt as u8); + continue; + } + + start = fmt; + fmt = (fmt as usize + 1) as *mut c_char; + if *fmt == b'%' as c_char { + PC(b'%'); + continue; + } + + while *fmt != 0 && !(strchr("#'-+ 0\0".as_ptr() as *const c_char, *fmt as c_int).is_null()) { + fmt = (fmt as usize + 1) as *mut c_char; + } + + if *fmt == b'*' as c_char { + fmt = (fmt as usize + 1) as *mut c_char; + have_fieldwidth = 1; + fieldwidth = getint(); + } else { + while IS_DIGITAL!(*fmt) { + fmt = (fmt as usize + 1) as *mut c_char; + } + } + + if *fmt == b'.' as c_char { + fmt = (fmt as usize + 1) as *mut c_char; + if *fmt == b'*' as c_char { + fmt = (fmt as usize + 1) as *mut c_char; + have_precision = 1; + precision = getint(); + } else { + if *fmt == b'-' as c_char { + fmt = (fmt as usize + 1) as *mut c_char; + } + while IS_DIGITAL!(*fmt) { + fmt = (fmt as usize + 1) as *mut c_char; + } + } + } + + modstart = fmt; + while *fmt != 0 && !(strchr("hjlLtz\0".as_ptr() as *const c_char, *fmt as c_int).is_null()) { + fmt = (fmt as usize + 1) as *mut c_char; + } + + if *fmt == 0 { + builtin_error("`%s': missing format character\0".as_ptr() as *const c_char, start); + return PRETURN(EXECUTION_FAILURE); + } + + convch = *fmt; + thisch = *modstart; + nextch = *((modstart as usize + 1) as *mut c_char); + *modstart = convch; + *((modstart as usize + 1) as *mut c_char) = b'\0' as c_char; + + QUIT(); + let format_type = convch as u8; + match format_type { + b'c' => { + let p = getchr(); + let f = start; + libc::clearerr(stdout); + let PF = || { + let nw: c_int; + if vflag == 0 { + if have_fieldwidth != 0 && have_precision != 0 { + nw = libc::printf(f, fieldwidth, precision, p); + } else if have_fieldwidth != 0 { + nw = libc::printf(f, fieldwidth, p); + } else if have_precision != 0 { + nw = libc::printf(f, precision, p); + } else { + nw = libc::printf(f, p); + } + } else { + let vbsnprintf2 = || { + let mut blen: c_int; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, have_fieldwidth, have_precision, p); + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen > vbsize { + vbsize = ((nlen as size_t + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, have_fieldwidth, have_precision, p); + } + vblen += blen; + *((vbuf as usize + vblen as usize) as *mut c_char) = b'0' as c_char; + blen + }; + let vbsnprintf1 = |x: c_int| { + let mut blen: c_int; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, x, p); + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen > vbsize { + vbsize = ((nlen as size_t + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, x, p); + } + vblen += blen; + *((vbuf as usize + vblen as usize) as *mut c_char) = b'0' as c_char; + blen + }; + let vbsnprintf = || { + let mut blen: c_int; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, p); + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen > vbsize { + vbsize = ((nlen as size_t + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, p); + } + vblen += blen; + *((vbuf as usize + vblen as usize) as *mut c_char) = b'0' as c_char; + blen + }; + if have_fieldwidth != 0 && have_precision != 0 { + nw = vbsnprintf2(); + } else if have_fieldwidth != 0 { + nw = vbsnprintf1(fieldwidth); + } else if have_precision != 0 { + nw = vbsnprintf1(precision); + } else { + nw = vbsnprintf(); + } + } + tw += nw as c_long; + }; + PF(); + QUIT(); + if libc::ferror(stdout) != 0 { + sh_wrerror(); + libc::clearerr(stdout); + return EXECUTION_FAILURE; + } + } + b's' => { + let p = getstr(); + let f = start; + libc::clearerr(stdout); + let PF = || { + let nw: c_int; + if vflag == 0 { + if have_fieldwidth != 0 && have_precision != 0 { + nw = libc::printf(f, fieldwidth, precision, p); + } else if have_fieldwidth != 0 { + nw = libc::printf(f, fieldwidth, p); + } else if have_precision != 0 { + nw = libc::printf(f, precision, p); + } else { + nw = libc::printf(f, p); + } + } else { + let vbsnprintf2 = || { + let mut blen: c_int; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, have_fieldwidth, have_precision, p); + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen > vbsize { + vbsize = ((nlen as size_t + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, have_fieldwidth, have_precision, p); + } + vblen += blen; + *((vbuf as usize + vblen as usize) as *mut c_char) = b'0' as c_char; + blen + }; + let vbsnprintf1 = |x: c_int| { + let mut blen: c_int; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, x, p); + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen > vbsize { + vbsize = ((nlen as size_t + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, x, p); + } + vblen += blen; + *((vbuf as usize + vblen as usize) as *mut c_char) = b'0' as c_char; + blen + }; + let vbsnprintf = || { + let mut blen: c_int; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, p); + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen > vbsize { + vbsize = ((nlen as size_t + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, p); + } + vblen += blen; + *((vbuf as usize + vblen as usize) as *mut c_char) = b'0' as c_char; + blen + }; + if have_fieldwidth != 0 && have_precision != 0 { + nw = vbsnprintf2(); + } else if have_fieldwidth != 0 { + nw = vbsnprintf1(fieldwidth); + } else if have_precision != 0 { + nw = vbsnprintf1(precision); + } else { + nw = vbsnprintf(); + } + } + tw += nw as c_long; + }; + PF(); + QUIT(); + if libc::ferror(stdout) != 0 { + sh_wrerror(); + libc::clearerr(stdout); + return EXECUTION_FAILURE; + } + } + b'(' => { + *((modstart as usize + 1) as *mut c_char) = nextch; + let timefmt = xmalloc(libc::strlen(fmt) + 3) as *mut c_char; + fmt = (fmt as usize + 1) as *mut c_char; + let mut t = timefmt; + let mut n = 1; + while *fmt != 0 { + if *fmt == b'(' as c_char { + n += 1; + } else if *fmt == b')' as c_char { + n -= 1; + } + if n == 0 { + break; + } + *t = *fmt; + t = (t as usize + 1) as *mut c_char; + fmt = (fmt as usize + 1) as *mut c_char; + } + *t = b'\0' as c_char; + fmt = (fmt as usize + 1) as *mut c_char; + if *fmt != b'T' as c_char { + builtin_warning("`%c': invalid time format specification\0".as_ptr() as *const c_char, *fmt as c_int); + fmt = start; + libc::free(timefmt as *mut c_void); + PC(*fmt as u8); + continue; + } + if *timefmt == b'\0' as c_char { + *timefmt = b'%' as c_char; + *((timefmt as usize + 1) as *mut c_char) = b'X' as c_char; + *((timefmt as usize + 2) as *mut c_char) = b'\0' as c_char; + } + + let arg = if !garglist.is_null() {getintmax()} else {-1}; + let mut secs: libc::time_t; + if arg == -1 { + secs = libc::time(0 as *mut libc::time_t); + } else if arg == -2 { + secs = shell_start_time; + } else { + secs = arg; + } + + sv_tz("TZ\0".as_ptr() as *mut c_char); + let mut tm = libc::localtime(std::mem::transmute(&secs)); + if tm.is_null() { + secs = 0; + tm = libc::localtime(std::mem::transmute(&secs)); + } + let mut timebuf:[c_char; 128] = [0; 128]; + let mut n: c_int = if !tm.is_null() {strftime(timebuf.as_ptr() as *mut c_char, 128, timefmt, tm) as c_int} else {0}; + libc::free(timefmt as *mut c_void); + if n == 0 { + timebuf[0] = b'\0' as c_char; + } else { + timebuf[127] = b'\0' as c_char; + } + + *modstart = b's' as c_char; + *((modstart as usize + 1) as *mut c_char) = b'\0' as c_char; + n = printstr(start, timebuf.as_ptr() as *mut c_char, libc::strlen(timebuf.as_ptr()) as c_int, fieldwidth, precision); + if n < 0 { + if libc::ferror(stdout) == 0 { + sh_wrerror(); + libc::clearerr(stdout); + } + return PRETURN(EXECUTION_FAILURE); + } + } + b'n' => { + let var = getstr(); + if !var.is_null() && *var != 0 { + if legal_identifier(var) != 0 { + bind_var_to_int(var, tw); + } else { + sh_invalidid(var); + return PRETURN(EXECUTION_FAILURE); + } + } + } + b'b' => { + let mut rlen: c_int = 0; + let mut r: c_int = 0; + ch = 0; + let p = getstr(); + let xp = bexpand(p, libc::strlen(p) as c_int, std::mem::transmute(&ch), std::mem::transmute(&rlen)); + if !xp.is_null() { + r = printstr(start, xp, rlen, fieldwidth, precision); + if r < 0 { + if libc::ferror(stdout) == 0 { + sh_wrerror(); + libc::clearerr(stdout); + } + retval = EXECUTION_FAILURE; + } + libc::free(xp as *mut c_void); + } + if ch != 0 || r < 0 { + return PRETURN(retval); + } + } + b'q' => { + let mut r: c_int = 0; + let xp: *mut c_char; + let p = getstr(); + if !p.is_null() && *p == 0 { + xp = savestring(b"''\0".as_ptr() as *const c_char); + } else if ansic_shouldquote(p) != 0 { + xp = ansic_quote(p, 0, PT_NULL as *mut c_int); + } else { + xp = sh_backslash_quote(p, PT_NULL as *mut c_char, 3); + } + if !xp.is_null() { + r = printstr(start, xp, libc::strlen(xp) as c_int, fieldwidth, precision); + if r < 0 { + if libc::ferror(stdout) == 0 { + sh_wrerror(); + libc::clearerr(stdout); + } + libc::free(xp as *mut c_void); + } + } + if r < 0 { + return PRETURN(EXECUTION_FAILURE); + } + } + b'd' | b'i' => { + let f = mklong(start, "l\0".as_ptr() as *mut c_char, 1); + let p = getintmax(); + libc::clearerr(stdout); + let PF = || { + let nw: c_int; + if vflag == 0 { + if have_fieldwidth != 0 && have_precision != 0 { + nw = libc::printf(f, fieldwidth, precision, p); + } else if have_fieldwidth != 0 { + nw = libc::printf(f, fieldwidth, p); + } else if have_precision != 0 { + nw = libc::printf(f, precision, p); + } else { + nw = libc::printf(f, p); + } + } else { + let vbsnprintf2 = || { + let mut blen: c_int; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, have_fieldwidth, have_precision, p); + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen > vbsize { + vbsize = ((nlen as size_t + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, have_fieldwidth, have_precision, p); + } + vblen += blen; + *((vbuf as usize + vblen as usize) as *mut c_char) = b'0' as c_char; + blen + }; + let vbsnprintf1 = |x: c_int| { + let mut blen: c_int; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, x, p); + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen > vbsize { + vbsize = ((nlen as size_t + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, x, p); + } + vblen += blen; + *((vbuf as usize + vblen as usize) as *mut c_char) = b'0' as c_char; + blen + }; + let vbsnprintf = || { + let mut blen: c_int; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, p); + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen > vbsize { + vbsize = ((nlen as size_t + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, p); + } + vblen += blen; + *((vbuf as usize + vblen as usize) as *mut c_char) = b'0' as c_char; + blen + }; + if have_fieldwidth != 0 && have_precision != 0 { + nw = vbsnprintf2(); + } else if have_fieldwidth != 0 { + nw = vbsnprintf1(fieldwidth); + } else if have_precision != 0 { + nw = vbsnprintf1(precision); + } else { + nw = vbsnprintf(); + } + } + tw += nw as c_long; + }; + PF(); + QUIT(); + if libc::ferror(stdout) != 0 { + sh_wrerror(); + libc::clearerr(stdout); + return EXECUTION_FAILURE; + } + } + b'o' | b'u' | b'x' | b'X' => { + let f = mklong(start, "l\0".as_ptr() as *mut c_char, 1); + let p = getuintmax(); + libc::clearerr(stdout); + let PF = || { + let nw: c_int; + if vflag == 0 { + if have_fieldwidth != 0 && have_precision != 0 { + nw = libc::printf(f, fieldwidth, precision, p); + } else if have_fieldwidth != 0 { + nw = libc::printf(f, fieldwidth, p); + } else if have_precision != 0 { + nw = libc::printf(f, precision, p); + } else { + nw = libc::printf(f, p); + } + } else { + let vbsnprintf2 = || { + let mut blen: c_int; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, have_fieldwidth, have_precision, p); + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen > vbsize { + vbsize = ((nlen as size_t + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, have_fieldwidth, have_precision, p); + } + vblen += blen; + *((vbuf as usize + vblen as usize) as *mut c_char) = b'0' as c_char; + blen + }; + let vbsnprintf1 = |x: c_int| { + let mut blen: c_int; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, x, p); + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen > vbsize { + vbsize = ((nlen as size_t + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, x, p); + } + vblen += blen; + *((vbuf as usize + vblen as usize) as *mut c_char) = b'0' as c_char; + blen + }; + let vbsnprintf = || { + let mut blen: c_int; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, p); + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen > vbsize { + vbsize = ((nlen as size_t + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, p); + } + vblen += blen; + *((vbuf as usize + vblen as usize) as *mut c_char) = b'0' as c_char; + blen + }; + if have_fieldwidth != 0 && have_precision != 0 { + nw = vbsnprintf2(); + } else if have_fieldwidth != 0 { + nw = vbsnprintf1(fieldwidth); + } else if have_precision != 0 { + nw = vbsnprintf1(precision); + } else { + nw = vbsnprintf(); + } + } + tw += nw as c_long; + }; + PF(); + QUIT(); + if libc::ferror(stdout) != 0 { + sh_wrerror(); + libc::clearerr(stdout); + return EXECUTION_FAILURE; + } + } + b'e' | b'E' | b'f' | b'F' | b'g' | b'G' | b'a' | b'A' => { + let p = getfloatmax(); + let f = mklong(start, "L\0".as_ptr() as *mut c_char, 1); + libc::clearerr(stdout); + let PF = || { + let nw: c_int; + if vflag == 0 { + if have_fieldwidth != 0 && have_precision != 0 { + nw = libc::printf(f, fieldwidth, precision, p); + } else if have_fieldwidth != 0 { + nw = libc::printf(f, fieldwidth, p); + } else if have_precision != 0 { + nw = libc::printf(f, precision, p); + } else { + nw = libc::printf(f, p); + } + } else { + let vbsnprintf2 = || { + let mut blen: c_int; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, have_fieldwidth, have_precision, p); + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen > vbsize { + vbsize = ((nlen as size_t + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, have_fieldwidth, have_precision, p); + } + vblen += blen; + *((vbuf as usize + vblen as usize) as *mut c_char) = b'0' as c_char; + blen + }; + let vbsnprintf1 = |x: c_int| { + let mut blen: c_int; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, x, p); + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen > vbsize { + vbsize = ((nlen as size_t + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, x, p); + } + vblen += blen; + *((vbuf as usize + vblen as usize) as *mut c_char) = b'0' as c_char; + blen + }; + let vbsnprintf = || { + let mut blen: c_int; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, p); + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen > vbsize { + vbsize = ((nlen as size_t + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + blen = libc::snprintf((vbuf as usize + vblen as usize) as *mut c_char, vbsize - vblen as usize, f, p); + } + vblen += blen; + *((vbuf as usize + vblen as usize) as *mut c_char) = b'0' as c_char; + blen + }; + if have_fieldwidth != 0 && have_precision != 0 { + nw = vbsnprintf2(); + } else if have_fieldwidth != 0 { + nw = vbsnprintf1(fieldwidth); + } else if have_precision != 0 { + nw = vbsnprintf1(precision); + } else { + nw = vbsnprintf(); + } + } + tw += nw as c_long; + }; + PF(); + QUIT(); + if libc::ferror(stdout) != 0 { + sh_wrerror(); + libc::clearerr(stdout); + return EXECUTION_FAILURE; + } + } + _ => { + builtin_error("`%c': invalid format character\0".as_ptr() as *const c_char, convch as c_int); + return PRETURN(EXECUTION_FAILURE); + } + } + + *modstart = thisch; + *((modstart as usize + 1) as *mut c_char) = nextch; + + fmt = (fmt as usize + 1) as *mut c_char; + } + + if libc::ferror(stdout) != 0 { + return PRETURN(EXECUTION_FAILURE); + } + + if !garglist.is_null() && garglist != (*list).next { + continue 'outer; + } else { + break 'outer; + } + } + + if conversion_error != 0 { + retval = EXECUTION_FAILURE; + } + + return PRETURN(retval); +} +} + +fn hexvalue(c: u8) -> c_int +{ + return ( + if (c) >= b'a' && (c) <= b'f' { + (c) - b'a' + 10 + } else if (c) >= b'A' && (c) <= b'F' { + (c) - b'A' + 10 + } else { + (c) - b'0' + }) as i32 +} + +unsafe fn printstr(mut fmt: *mut c_char, mut string: *mut c_char, len: c_int, fieldwidth: c_int, precision: c_int) -> c_int +{ + if string.is_null() { + string = "\0".as_ptr() as *mut c_char; + } + + if *fmt == b'%' as c_char { + fmt = (fmt as usize + 1) as *mut c_char; + } + + let mut ljust: c_int = 0; + let mut fw: c_int = 0; + let mut mfw: c_long = 0; + let mut pr: c_int = -1; + let mut mpr: c_long = -1; + + while !(strchr("#'-+ 0\0".as_ptr() as *const c_char, *fmt as c_int).is_null()) { + if *fmt == b'-' as c_char { + ljust = 1; + } + fmt = (fmt as usize + 1) as *mut c_char; + } + + if *fmt == b'*' as c_char { + fmt = (fmt as usize + 1) as *mut c_char; + fw = fieldwidth; + if fw < 0 { + fw = -fw; + ljust = 1; + } + } else if IS_DIGITAL!(*fmt) { + mfw = (*fmt - b'0' as c_char) as c_long; + fmt = (fmt as usize + 1) as *mut c_char; + while IS_DIGITAL!(*fmt) { + mfw = mfw * 10 + (*fmt - b'0' as c_char) as c_long; + fmt = (fmt as usize + 1) as *mut c_char; + } + fw = if mfw < 0 || mfw > (libc::INT_MAX as c_long) {libc::INT_MAX} else {mfw as c_int}; + } + + if *fmt == b'.' as c_char { + fmt = (fmt as usize + 1) as *mut c_char; + if *fmt == b'*' as c_char { + fmt = (fmt as usize + 1) as *mut c_char; + pr = precision; + } else if IS_DIGITAL!(*fmt) { + mpr = (*fmt - b'0' as c_char) as c_long; + fmt = (fmt as usize + 1) as *mut c_char; + while IS_DIGITAL!(*fmt) { + mpr = mpr * 10 + (*fmt - b'0' as c_char) as c_long; + fmt = (fmt as usize + 1) as *mut c_char; + } + pr = if mpr < 0 || mpr > (libc::INT_MAX as c_long) {libc::INT_MAX} else {mpr as c_int}; + } else { + pr = 0; + } + } + + let nc = if pr >= 0 && pr <= len {pr} else {len}; + let mut padlen = fw - nc; + if padlen < 0 { + padlen = 0; + } + if ljust != 0 { + padlen = -padlen; + } + + while padlen > 0 { + PC(b' '); + padlen -= 1; + } + + for i in 0..nc { + PC(*((string as usize + i as usize) as *mut c_char) as u8); + } + + return 0; +} + +unsafe fn tescape(estart: *mut c_char, cp:*mut c_char, lenp: *mut c_int, sawc: *mut c_int) -> c_int +{ + + let mut p: *mut c_char = estart; + let mut evalue: c_int; + let mut temp: c_int; + let mut uvalue: c_ulong; + if !lenp.is_null() { + *lenp = 1; + } + + let c = *p as u8; + p = (p as usize + 1) as *mut c_char; + match c { + b'a' => *cp = 7, + b'b' => *cp = 8, + b'e' | b'E' => *cp = 27, + b'f' => *cp = 12, + b'n' => *cp = 10, + b'r' => *cp = 13, + b't' => *cp = 9, + b'v' => *cp = 11, + b'0'..=b'7' => { + evalue = (c - b'0') as c_int; + temp = 2 + (evalue == 0 && !sawc.is_null()) as c_int; + while *p >= b'0' as c_char && *p <= b'7' as c_char && temp != 0 { + temp -= 1; + evalue = (evalue * 8) + (*p - b'0' as c_char) as c_int; + p = (p as usize + 1) as *mut c_char; + } + + *cp = (evalue & 0xff) as c_char; + } + b'x' => { + temp = 2; + evalue = 0; + while libc::isdigit(*p as c_int) != 0 && temp != 0 { + temp -= 1; + evalue = (evalue * 16) + hexvalue(*p as u8); + p = (p as usize + 1) as *mut c_char; + } + + if p as usize == (estart as usize + 1) { + builtin_error("missing hex digit for \\x\0".as_ptr() as *const c_char); + *cp = b'\\' as c_char; + return 0; + } + *cp = (evalue & 0xff) as c_char; + } + b'u' | b'U' => { + temp = if c == b'u' {4} else {8}; + uvalue = 0; + while libc::isdigit(*p as c_int) != 0 && temp != 0 { + temp -= 1; + uvalue = (uvalue * 16) + hexvalue(*p as u8) as c_ulong; + p = (p as usize + 1) as *mut c_char; + } + + if p as usize == (estart as usize + 1) { + builtin_error("missing unicode digit for \\%c\0".as_ptr() as *const c_char, c as c_int); + *cp = b'\\' as c_char; + return 0; + } + if uvalue <= 0x7f { + *cp = uvalue as c_char; + } else { + temp = u32cconv(uvalue, cp); + *((cp as usize + temp as usize) as *mut c_char) = b'\0' as c_char; + if !lenp.is_null() { + *lenp = temp; + } + } + } + b'\\' => *cp = c as c_char, + b'\'' | b'"' | b'?' => { + if sawc.is_null() { + *cp = c as c_char; + } else { + *cp = b'\\' as c_char; + return 0; + } + } + b'c' => { + if sawc.is_null() { + *sawc = 1; + } else { + *cp = b'\\' as c_char; + return 0; + } + } + _ => { + *cp = b'\\' as c_char; + return 0; + } + } + return (p as usize - estart as usize) as c_int; +} + +unsafe fn bexpand(string: *mut c_char, len: c_int, sawc: *mut c_int, lenp: *mut c_int) -> *mut c_char +{ + let mut mbch:[c_char; 25]; + let mut mblen: c_int = 0; + + let mut ret: *mut c_char; + let mut r: *mut c_char; + let mut s: *mut c_char; + let mut c: c_char; + + if string.is_null() || len == 0 { + if !sawc.is_null() { + *sawc = 0; + } + if !lenp.is_null() { + *lenp = 0; + } + ret = xmalloc(1) as *mut c_char; + *ret = b'\0' as c_char; + return ret; + } + + ret = xmalloc(len as size_t + 1) as *mut c_char; + r = ret; + s = string; + while !s.is_null() && *s != 0 { + c = *s as c_char; + s = (s as usize + 1) as *mut c_char; + if c != b'\\' as c_char || *s == b'\0' as c_char { + *r = c; + r = (r as usize + 1) as *mut c_char; + continue; + } + + let mut temp: c_int = 0; + mbch = [0; 25]; + let n = tescape(s, mbch.as_mut_ptr() as *mut c_char, + std::mem::transmute(&mblen), std::mem::transmute(&temp)); + s = (s as usize + n as size_t) as *mut c_char; + + if temp != 0 { + if !sawc.is_null() { + *sawc = 1; + } + break; + } + + for mbind in 0..mblen { + *r = mbch[mbind as usize]; + r = (r as usize + 1) as *mut c_char; + } + } + + *r = b'\0' as c_char; + if !lenp.is_null() { + *lenp = (r as usize - ret as usize) as c_int; + } + + return ret; +} + +unsafe fn vbadd(buf: *mut c_char, blen: c_int) -> *mut c_char +{ + let nlen: size_t = vblen as size_t + blen as size_t + 1; + if nlen >= vbsize { + vbsize = ((nlen + 63) >> 6) << 6; + vbuf = xrealloc(vbuf as *mut c_void, vbsize) as *mut c_char; + } + + if blen == 1 { + *((vbuf as usize + vblen as usize) as *mut c_char) = *buf; + vblen += 1; + } else if blen > 1 { + libc::memcpy((vbuf as usize + vblen as usize) as *mut c_void, + buf as *mut c_void, blen as size_t); + vblen += blen; + } + *((vbuf as usize + vblen as usize) as *mut c_char) = b'\0' as c_char; + + return vbuf; +} + +unsafe fn printf_erange(s: *mut c_char) +{ + builtin_error("warning: %s: %s\0".as_ptr() as *const c_char, s, libc::strerror(libc::ERANGE)); +} + +unsafe fn mklong(str: *mut c_char, modifiers: *mut c_char, mlen: size_t) -> *mut c_char +{ + let slen = libc::strlen(str); + let len = slen + mlen + 1; + + if len > conv_bufsize { + conv_bufsize = ((len + 1023) >> 10) << 10; + conv_buf = libc::realloc(conv_buf as *mut c_void, conv_bufsize) as *mut c_char; + } + + libc::memcpy(conv_buf as *mut c_void, str as *mut c_void, slen - 1); + libc::memcpy((conv_buf as usize + slen - 1) as *mut c_void, modifiers as *mut c_void, mlen); + + *((conv_buf as usize + len - 2) as *mut c_char) = *((str as usize + slen - 1) as *mut c_char); + *((conv_buf as usize + len - 1) as *mut c_char) = b'\0' as c_char; + + return conv_buf; +} + +unsafe fn getchr() -> c_int +{ + if garglist.is_null() { + return b'\0' as c_int; + } + + let ret = *(*(*garglist).word).word as c_int; + garglist = (*garglist).next; + return ret; +} + +unsafe fn getstr() -> *mut c_char +{ + if garglist.is_null() { + return "\0".as_ptr() as *mut c_char; + } + + let ret = (*(*garglist).word).word; + garglist = (*garglist).next; + return ret; +} + +unsafe fn getint() -> c_int +{ + let mut ret = getintmax(); + + if garglist.is_null() { + return ret as c_int; + } + + if ret > libc::INT_MAX as c_long{ + printf_erange((*(*garglist).word).word); + ret = libc::INT_MAX as c_long; + } else if ret < libc::INT_MIN as c_long{ + printf_erange((*(*garglist).word).word); + ret = libc::INT_MIN as c_long; + } + + return ret as c_int; +} + +unsafe fn getintmax() -> c_long +{ + if garglist.is_null() { + return 0; + } + + if *(*(*garglist).word).word == b'\'' as c_char || + *(*(*garglist).word).word == b'"' as c_char { + return asciicode(); + } + + let mut ep: *mut c_char = PT_NULL as *mut c_char; + *libc::__errno_location() = 0; + let ret = libc::strtol((*(*garglist).word).word, std::mem::transmute(&ep), 0); + if *ep != 0 { + sh_invalidnum((*(*garglist).word).word); + conversion_error = 1; + } else if *libc::__errno_location() == libc::ERANGE { + printf_erange((*(*garglist).word).word); + } + garglist = (*garglist).next; + return ret; +} + +unsafe fn getuintmax() -> c_ulong +{ + if garglist.is_null() { + return 0; + } + + if *(*(*garglist).word).word == b'\'' as c_char || + *(*(*garglist).word).word == b'"' as c_char { + return asciicode() as c_ulong; + } + + *libc::__errno_location() = 0; + let mut ep: *mut c_char = PT_NULL as *mut c_char; + let ret = libc::strtoul((*(*garglist).word).word, std::mem::transmute(&ep), 0); + if *ep != 0 { + sh_invalidnum((*(*garglist).word).word); + conversion_error = 1; + } else if *libc::__errno_location() == libc::ERANGE { + printf_erange((*(*garglist).word).word); + } + garglist = (*garglist).next; + return ret; +} + +unsafe fn getfloatmax() -> f64 +{ + let ep: *mut c_char = PT_NULL as *mut c_char; + + if garglist.is_null() { + return 0.0; + } + + if *(*(*garglist).word).word == b'\'' as c_char || + *(*(*garglist).word).word == b'\"' as c_char { + return asciicode() as f64; + } + + *libc::__errno_location() = 0; + let ret = libc::strtod((*(*garglist).word).word, std::mem::transmute(&ep)); + if *ep != 0 { + sh_invalidnum((*(*garglist).word).word); + conversion_error = 1; + } else if *libc::__errno_location() == libc::ERANGE { + printf_erange((*(*garglist).word).word); + } + + garglist = (*garglist).next; + + return ret; +} + +unsafe fn asciicode() -> c_long +{ + let ch: c_long; + //let state: mbstate_t = std::mem::zeroed(); + let slen = libc::strlen((*(*garglist).word).word); + let wc: libc::wchar_t = 0; + let mblength = mbtowc(std::mem::transmute(&wc), ((*(*garglist).word).word as usize + 1) as *mut c_char, slen); + if mblength > 0 { + ch = wc as c_long; + } else { + ch = *(((*(*garglist).word).word as usize + 1) as *mut c_char) as c_long; + } + + garglist = (*garglist).next; + + return ch; +} diff --git a/bash-5.1/builtins_rust/pushd/Cargo.toml b/bash-5.1/builtins_rust/pushd/Cargo.toml index 69270a84..fe91da3d 100644 --- a/bash-5.1/builtins_rust/pushd/Cargo.toml +++ b/bash-5.1/builtins_rust/pushd/Cargo.toml @@ -2,7 +2,7 @@ authors = ["huzhengming"] name = "rpushd" version = "0.0.1" -build = "../build.rs" +#build = "../build.rs" edition = "2021" diff --git a/bash-5.1/builtins_rust/read/Cargo.toml b/bash-5.1/builtins_rust/read/Cargo.toml index 79188cea..806c5f89 100644 --- a/bash-5.1/builtins_rust/read/Cargo.toml +++ b/bash-5.1/builtins_rust/read/Cargo.toml @@ -9,7 +9,8 @@ build = "../build.rs" [lib] name = "rread" -crate-type = ["cdylib"] +#crate-type = ["cdylib"] +crate-type = ["staticlib"] [dependencies] libc = "0.2" diff --git a/bash-5.1/builtins_rust/rlet/Cargo.toml b/bash-5.1/builtins_rust/rlet/Cargo.toml index e69de29b..74272cf8 100644 --- a/bash-5.1/builtins_rust/rlet/Cargo.toml +++ b/bash-5.1/builtins_rust/rlet/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "rlet" +version = "0.1.0" +edition = "2021" +authors = ["lvgenggeng"] +#build = "../build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +name = "rlet" +crate-type = ["cdylib"] + +[dependencies] +libc = "0.2" +nix = "0.23" diff --git a/bash-5.1/builtins_rust/rlet/src/intercdep.rs b/bash-5.1/builtins_rust/rlet/src/intercdep.rs new file mode 100644 index 00000000..d2246f94 --- /dev/null +++ b/bash-5.1/builtins_rust/rlet/src/intercdep.rs @@ -0,0 +1,46 @@ + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_desc { + pub word: *mut c_char, + pub flags: c_int, +} +pub type WORD_DESC = word_desc; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_list { + pub next: *mut word_list, + pub word: *mut WORD_DESC, +} +pub type WORD_LIST = word_list; + +pub const EXECUTION_SUCCESS : c_int = 0; +pub const EXECUTION_FAILURE : c_int = 1; +pub const EX_USAGE: c_int = 258; + +pub const EXP_EXPANDED: c_int = 0x01; + +pub type histdata_t = *mut libc::c_void; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct _hist_entry { + pub line: *mut c_char, + pub timestamp: *mut c_char, + pub data: histdata_t, +} +pub type HIST_ENTRY = _hist_entry; + +extern "C" { + pub fn string_list(list: *mut WORD_LIST) -> *mut c_char; + + pub fn builtin_usage(); + pub fn builtin_help(); + pub fn builtin_error(format: *const c_char, ...); + + pub fn evalexp (expr: *mut c_char, flags: c_int, validp: *mut c_int) -> c_long; + + pub static mut list_optarg : *mut libc::c_char; + pub static mut loptend : *mut WORD_LIST; + +} diff --git a/bash-5.1/builtins_rust/rlet/src/lib.rs b/bash-5.1/builtins_rust/rlet/src/lib.rs index e69de29b..7fe5af59 100644 --- a/bash-5.1/builtins_rust/rlet/src/lib.rs +++ b/bash-5.1/builtins_rust/rlet/src/lib.rs @@ -0,0 +1,63 @@ +use std::ffi::CStr; +use libc::{c_int, c_char, c_long, c_void}; + +include!(concat!("intercdep.rs")); + +#[no_mangle] +pub extern "C" fn r_let_builtin(mut list: *mut WORD_LIST) -> i32 { + println!("r_let_builtin call"); +unsafe { + let mut ret: c_long = 0; + let mut expok: c_int = 0; + + if !list.is_null() && !(*list).word.is_null() && + libc::strcmp((*((*list).word)).word, "--help\0".as_ptr() as *const c_char) == 0 { + builtin_help (); + return EX_USAGE; + } + + if !list.is_null() && !(*list).word.is_null() && is_option((*((*list).word)).word, b'-') { + list = (*list).next; + } + + if list.is_null() { + builtin_error("expression expected\0".as_ptr() as *mut c_char); + return EXECUTION_FAILURE; + } + + while !list.is_null() { + ret = evalexp((*((*list).word)).word, EXP_EXPANDED, std::mem::transmute(&expok)); + if expok == 0 { + return EXECUTION_FAILURE; + } + list = (*list).next; + } + + return if ret == 0 {EXECUTION_FAILURE} else {EXECUTION_SUCCESS}; +} +} + +#[no_mangle] +pub extern "C" fn r_exp_builtin(mut list: *mut WORD_LIST) -> i32 { + println!("r_exp_builtin call"); + +unsafe { + let mut expok: c_int = 0; + + if list.is_null() { + builtin_error("expression expected\0".as_ptr() as *const c_char); + return EXECUTION_FAILURE; + } + + let exp = string_list(list); + let ret = evalexp(exp, EXP_EXPANDED, std::mem::transmute(&expok)); + libc::free(exp as *mut c_void); + return if ret == 0 || expok == 0 {EXECUTION_FAILURE} else {EXECUTION_SUCCESS}; +} +} + +unsafe fn is_option(s: *mut c_char, c: u8) -> bool +{ + let str = CStr::from_ptr(s).to_bytes_with_nul(); + return str[0] == b'-' && str[1] == c && str[2] != 0 +} \ No newline at end of file diff --git a/bash-5.1/builtins_rust/rreturn/Cargo.toml b/bash-5.1/builtins_rust/rreturn/Cargo.toml index e69de29b..2272f335 100644 --- a/bash-5.1/builtins_rust/rreturn/Cargo.toml +++ b/bash-5.1/builtins_rust/rreturn/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "rreturn" +version = "0.1.0" +edition = "2021" +authors = ["lvgenggeng"] +#build = "../build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +name = "rreturn" +crate-type = ["cdylib"] + +[dependencies] +libc = "0.2" +nix = "0.23" diff --git a/bash-5.1/builtins_rust/rreturn/src/intercdep.rs b/bash-5.1/builtins_rust/rreturn/src/intercdep.rs new file mode 100644 index 00000000..7e976417 --- /dev/null +++ b/bash-5.1/builtins_rust/rreturn/src/intercdep.rs @@ -0,0 +1,54 @@ + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_desc { + pub word: *mut c_char, + pub flags: c_int, +} +pub type WORD_DESC = word_desc; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_list { + pub next: *mut word_list, + pub word: *mut WORD_DESC, +} +pub type WORD_LIST = word_list; + +pub const EXECUTION_SUCCESS : c_int = 0; +pub const EXECUTION_FAILURE : c_int = 1; +pub const EX_USAGE: c_int = 258; + +pub type __jmp_buf = [c_long; 8usize]; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct __sigset_t { + pub __val: [c_ulong; 16usize], +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct __jmp_buf_tag { + pub __jmpbuf: __jmp_buf, + pub __mask_was_saved: c_int, + pub __saved_mask: __sigset_t, +} +pub type sigjmp_buf = [__jmp_buf_tag; 1usize]; + +extern "C" { + pub fn builtin_usage(); + pub fn builtin_help(); + pub fn builtin_error(format: *const c_char, ...); + + pub fn get_exitstat(list: *mut WORD_LIST) -> c_int; + + pub fn siglongjmp(__env: *mut __jmp_buf_tag, __val: c_int); + + pub static mut list_optarg : *mut libc::c_char; + pub static mut loptend : *mut WORD_LIST; + + pub static mut return_catch_value: c_int; + pub static return_catch_flag: c_int; + pub static return_catch: sigjmp_buf; +} diff --git a/bash-5.1/builtins_rust/rreturn/src/lib.rs b/bash-5.1/builtins_rust/rreturn/src/lib.rs index e69de29b..277faa26 100644 --- a/bash-5.1/builtins_rust/rreturn/src/lib.rs +++ b/bash-5.1/builtins_rust/rreturn/src/lib.rs @@ -0,0 +1,25 @@ +use libc::{c_int, c_char, c_long, c_ulong}; + +include!(concat!("intercdep.rs")); + +#[no_mangle] +pub extern "C" fn r_return_builtin(list: *mut WORD_LIST) -> i32 { + println!("r_return_builtin call"); + +unsafe { + if !list.is_null() && !(*list).word.is_null() && + libc::strcmp((*((*list).word)).word, "--help\0".as_ptr() as *const c_char) == 0 { + builtin_help (); + return EX_USAGE; + } + + return_catch_value = get_exitstat(list); + if return_catch_flag != 0 { + siglongjmp(std::mem::transmute(&return_catch), 1); + } else { + builtin_error("can only `return' from a function or sourced script\0".as_ptr() as *const c_char); + return EX_USAGE; + } +} + return EXECUTION_SUCCESS; +} diff --git a/bash-5.1/builtins_rust/shift/Cargo.toml b/bash-5.1/builtins_rust/shift/Cargo.toml index e69de29b..e53a57fd 100644 --- a/bash-5.1/builtins_rust/shift/Cargo.toml +++ b/bash-5.1/builtins_rust/shift/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "shift" +version = "0.1.0" +edition = "2021" +authors = ["lvgenggeng"] +build = "../build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +name = "rshift" +crate-type = ["cdylib"] + +[dependencies] +libc = "0.2" +nix = "0.23" diff --git a/bash-5.1/builtins_rust/shift/src/intercdep.rs b/bash-5.1/builtins_rust/shift/src/intercdep.rs new file mode 100644 index 00000000..24ce4a1b --- /dev/null +++ b/bash-5.1/builtins_rust/shift/src/intercdep.rs @@ -0,0 +1,36 @@ + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_desc { + pub word: *mut c_char, + pub flags: c_int, +} +pub type WORD_DESC = word_desc; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_list { + pub next: *mut word_list, + pub word: *mut WORD_DESC, +} +pub type WORD_LIST = word_list; + +pub const EXECUTION_SUCCESS : c_int = 0; +pub const EXECUTION_FAILURE : c_int = 1; +pub const EX_USAGE: c_int = 258; + +extern "C" { + pub fn builtin_usage(); + pub fn builtin_help(); + pub fn builtin_error(format: *const c_char, ...); + + pub fn get_numeric_arg(list: *mut WORD_LIST, fatal: c_int, count: c_long) -> c_int; + pub fn number_of_args() -> c_int; + pub fn sh_erange(s: *mut c_char, desc: *mut c_char); + pub fn clear_dollar_vars(); + pub fn shift_args(times: c_int); + pub fn invalidate_cached_quoted_dollar_at(); + + pub static mut list_optarg : *mut libc::c_char; + pub static mut loptend : *mut WORD_LIST; +} diff --git a/bash-5.1/builtins_rust/shift/src/lib.rs b/bash-5.1/builtins_rust/shift/src/lib.rs index e69de29b..00fb8f87 100644 --- a/bash-5.1/builtins_rust/shift/src/lib.rs +++ b/bash-5.1/builtins_rust/shift/src/lib.rs @@ -0,0 +1,47 @@ +use libc::{c_int, c_char, c_long, PT_NULL}; + +include!(concat!("intercdep.rs")); + +pub static print_shift_error: c_int = 0; + +#[no_mangle] +pub extern "C" fn r_shift_builtin(list: *mut WORD_LIST) -> i32 { + println!("r_shift_builtin call"); + +unsafe { + if !list.is_null() && !(*list).word.is_null() && + libc::strcmp((*((*list).word)).word, "--help\0".as_ptr() as *const c_char) == 0 { + builtin_help (); + return EX_USAGE; + } + + let mut times: c_int = 0; + if get_numeric_arg(list, 0, std::mem::transmute(×)) == 0 { + return EXECUTION_FAILURE; + } + + if times == 0 { + return EXECUTION_SUCCESS; + } else if times < 0 { + let s = if list.is_null() {PT_NULL as *mut c_char} else {(*(*list).word).word}; + sh_erange(s,"shift count\0".as_ptr() as *mut c_char); + return EXECUTION_FAILURE; + } + + let nargs = number_of_args(); + if times > nargs { + if print_shift_error != 0 { + let s = if list.is_null() {PT_NULL as *mut c_char} else {(*(*list).word).word}; + sh_erange(s,"shift count\0".as_ptr() as *mut c_char); + return EXECUTION_FAILURE; + } + } else if times == nargs { + clear_dollar_vars(); + } else { + shift_args(times); + } + + invalidate_cached_quoted_dollar_at(); +} + return EXECUTION_SUCCESS; +} diff --git a/bash-5.1/builtins_rust/source/Cargo.toml b/bash-5.1/builtins_rust/source/Cargo.toml index 124fdbef..a69f0c78 100644 --- a/bash-5.1/builtins_rust/source/Cargo.toml +++ b/bash-5.1/builtins_rust/source/Cargo.toml @@ -2,7 +2,7 @@ authors = ["huzhengming"] name = "rsource" version = "0.0.1" -build = "../build.rs" +#build = "../build.rs" edition = "2021" diff --git a/bash-5.1/builtins_rust/suspend/Cargo.toml b/bash-5.1/builtins_rust/suspend/Cargo.toml index e69de29b..c758cc9f 100644 --- a/bash-5.1/builtins_rust/suspend/Cargo.toml +++ b/bash-5.1/builtins_rust/suspend/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "suspend" +version = "0.1.0" +edition = "2021" +authors = ["lvgenggeng"] +build = "../build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +name = "rsuspend" +crate-type = ["cdylib"] + +[dependencies] +libc = "0.2" +nix = "0.23" diff --git a/bash-5.1/builtins_rust/suspend/src/intercdep.rs b/bash-5.1/builtins_rust/suspend/src/intercdep.rs new file mode 100644 index 00000000..5cf962bf --- /dev/null +++ b/bash-5.1/builtins_rust/suspend/src/intercdep.rs @@ -0,0 +1,42 @@ + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_desc { + pub word: *mut c_char, + pub flags: c_int, +} +pub type WORD_DESC = word_desc; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_list { + pub next: *mut word_list, + pub word: *mut WORD_DESC, +} +pub type WORD_LIST = word_list; + +pub const EXECUTION_SUCCESS : c_int = 0; +pub const EXECUTION_FAILURE : c_int = 1; +pub const EX_USAGE: c_int = 258; + +pub type SigHandler = unsafe extern "C" fn(arg1: c_int); + +extern "C" { + pub fn reset_internal_getopt(); + pub fn internal_getopt(list: *mut WORD_LIST, opts: *mut c_char) -> c_int; + pub fn builtin_usage(); + pub fn builtin_help(); + pub fn builtin_error(format: *const c_char, ...); + + pub fn sh_nojobs(s: *mut c_char); + pub fn no_args(list: *mut WORD_LIST); + pub fn killpg(pgrp: libc::pid_t, sig: c_int) -> c_int; + + pub fn set_signal_handler(arg1: c_int, arg2: *mut SigHandler) -> *mut SigHandler; + + pub static mut list_optarg : *mut libc::c_char; + pub static mut loptend : *mut WORD_LIST; + pub static mut job_control: c_int; + pub static mut login_shell: c_int; + pub static mut shell_pgrp: libc::pid_t; +} diff --git a/bash-5.1/builtins_rust/suspend/src/lib.rs b/bash-5.1/builtins_rust/suspend/src/lib.rs index e69de29b..b92a6ff3 100644 --- a/bash-5.1/builtins_rust/suspend/src/lib.rs +++ b/bash-5.1/builtins_rust/suspend/src/lib.rs @@ -0,0 +1,54 @@ +use libc::{c_int, c_char, c_long, PT_NULL}; + +include!(concat!("intercdep.rs")); + +pub static mut old_cont: *mut SigHandler = PT_NULL as *mut SigHandler; + +#[no_mangle] +pub extern "C" fn r_suspend_builtin(mut list: *mut WORD_LIST) -> i32 { + println!("r_suspend_builtin call"); + + let mut opt: c_int; + let mut force: c_int = 0; + +unsafe { + reset_internal_getopt(); + let opt_str = "f:\0".as_ptr() as *mut c_char; + opt = internal_getopt (list, opt_str); + while opt != -1 { + let opt_char:char=char::from(opt as u8); + match opt_char { + 'f' => force += 1, + _ => { + builtin_usage (); + return EX_USAGE; + } + } + opt = internal_getopt (list, opt_str); + } + list = loptend; + + if job_control == 0 { + sh_nojobs("cannot suspend\0".as_ptr() as *mut c_char); + return EXECUTION_FAILURE; + } + + if force == 0 { + no_args(list); + if login_shell != 0 { + builtin_error("cannot suspend a login shell\0".as_ptr() as *mut c_char); + return EXECUTION_FAILURE; + } + } + + old_cont = set_signal_handler(libc::SIGCONT, std::mem::transmute(suspend_continue as usize)); + + killpg(shell_pgrp, libc::SIGSTOP); +} + return EXECUTION_SUCCESS; +} + +unsafe fn suspend_continue(sig: c_int) +{ + set_signal_handler(libc::SIGCONT, old_cont); +} \ No newline at end of file diff --git a/bash-5.1/builtins_rust/test/Cargo.toml b/bash-5.1/builtins_rust/test/Cargo.toml index e69de29b..2e66e538 100644 --- a/bash-5.1/builtins_rust/test/Cargo.toml +++ b/bash-5.1/builtins_rust/test/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "test" +version = "0.1.0" +edition = "2021" +authors = ["lvgenggeng"] +build = "../build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +name = "rtest" +crate-type = ["cdylib"] + +[dependencies] +libc = "0.2" +nix = "0.23" diff --git a/bash-5.1/builtins_rust/test/src/intercdep.rs b/bash-5.1/builtins_rust/test/src/intercdep.rs new file mode 100644 index 00000000..060c9f46 --- /dev/null +++ b/bash-5.1/builtins_rust/test/src/intercdep.rs @@ -0,0 +1,32 @@ + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_desc { + pub word: *mut c_char, + pub flags: c_int, +} +pub type WORD_DESC = word_desc; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_list { + pub next: *mut word_list, + pub word: *mut WORD_DESC, +} +pub type WORD_LIST = word_list; + +pub const EXECUTION_SUCCESS : c_int = 0; +pub const EXECUTION_FAILURE : c_int = 1; +pub const EX_BADUSAGE : c_int = 2; +pub const EX_USAGE: c_int = 258; + +extern "C" { + pub fn builtin_error(format: *const c_char, ...); + + pub fn make_builtin_argv(list: *mut WORD_LIST, ip: *mut c_int) -> *mut *mut c_char; + pub fn test_command (margc: c_int, margv: *mut *mut c_char) -> c_int; + + pub static mut list_optarg : *mut libc::c_char; + pub static mut loptend : *mut WORD_LIST; + pub static mut this_command_name: *mut c_char; +} diff --git a/bash-5.1/builtins_rust/test/src/lib.rs b/bash-5.1/builtins_rust/test/src/lib.rs index e69de29b..e45d4aad 100644 --- a/bash-5.1/builtins_rust/test/src/lib.rs +++ b/bash-5.1/builtins_rust/test/src/lib.rs @@ -0,0 +1,25 @@ +use libc::{c_int, c_char, c_void}; + +include!(concat!("intercdep.rs")); + +#[no_mangle] +pub extern "C" fn r_test_builtin(list: *mut WORD_LIST) -> i32 { + println!("r_test_builtin call"); + + let result: c_int; + let mut argc: c_int = 0; +unsafe { + if list.is_null() { + if *this_command_name == b'[' as c_char && + *((this_command_name as usize + 1) as *mut c_char) == 0 { + builtin_error("missing `]'\0".as_ptr() as *mut c_char); + return EX_BADUSAGE; + } + return EXECUTION_FAILURE; + } + let argv = make_builtin_argv(list, std::mem::transmute(&argc)); + result = test_command(argc, argv); + libc::free(argv as *mut c_void); +} + return result; +} diff --git a/bash-5.1/builtins_rust/times/Cargo.toml b/bash-5.1/builtins_rust/times/Cargo.toml index e69de29b..4067fac2 100644 --- a/bash-5.1/builtins_rust/times/Cargo.toml +++ b/bash-5.1/builtins_rust/times/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "times" +version = "0.1.0" +edition = "2021" +authors = ["lvgenggeng"] +build = "../build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +name = "rtimes" +crate-type = ["cdylib"] + +[dependencies] +libc = "0.2" +nix = "0.23" diff --git a/bash-5.1/builtins_rust/times/src/intercdep.rs b/bash-5.1/builtins_rust/times/src/intercdep.rs new file mode 100644 index 00000000..beca3327 --- /dev/null +++ b/bash-5.1/builtins_rust/times/src/intercdep.rs @@ -0,0 +1,28 @@ + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_desc { + pub word: *mut c_char, + pub flags: c_int, +} +pub type WORD_DESC = word_desc; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_list { + pub next: *mut word_list, + pub word: *mut WORD_DESC, +} +pub type WORD_LIST = word_list; + +pub const EXECUTION_SUCCESS : c_int = 0; +pub const EXECUTION_FAILURE : c_int = 1; +pub const EX_USAGE: c_int = 258; + +extern "C" { + pub fn no_options(list: *mut WORD_LIST) -> c_int; + pub fn print_timeval(fp: *mut libc::FILE, tvp: *mut libc::timeval); + pub fn sh_chkwrite(s: c_int) -> c_int; + + pub static stdout: *mut libc::FILE; +} diff --git a/bash-5.1/builtins_rust/times/src/lib.rs b/bash-5.1/builtins_rust/times/src/lib.rs index e69de29b..1632fee5 100644 --- a/bash-5.1/builtins_rust/times/src/lib.rs +++ b/bash-5.1/builtins_rust/times/src/lib.rs @@ -0,0 +1,34 @@ +use libc::{c_int, c_char}; + +include!(concat!("intercdep.rs")); + +#[no_mangle] +pub extern "C" fn r_times_builtin(list: *mut WORD_LIST) -> i32 { + println!("r_times_builtin call"); + +unsafe { + + if no_options(list) != 0 { + return EX_USAGE; + } + + let mut curr: libc::rusage = std::mem::zeroed(); + let mut kids: libc::rusage = std::mem::zeroed(); + libc::putchar(b'\n' as c_int); + + libc::getrusage(libc::RUSAGE_SELF, std::mem::transmute(&curr)); + libc::getrusage(libc::RUSAGE_CHILDREN, std::mem::transmute(&kids)); + + print_timeval(stdout, std::mem::transmute(&curr.ru_utime)); + libc::putchar(b' ' as c_int); + print_timeval(stdout, std::mem::transmute(&curr.ru_stime)); + libc::putchar(b'\n' as c_int); + + print_timeval(stdout, std::mem::transmute(&kids.ru_utime)); + libc::putchar(b' ' as c_int); + print_timeval(stdout, std::mem::transmute(&kids.ru_stime)); + libc::putchar(b'\n' as c_int); + + return sh_chkwrite(EXECUTION_SUCCESS); +} +} diff --git a/bash-5.1/builtins_rust/trap/Cargo.toml b/bash-5.1/builtins_rust/trap/Cargo.toml index e69de29b..3845c566 100644 --- a/bash-5.1/builtins_rust/trap/Cargo.toml +++ b/bash-5.1/builtins_rust/trap/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "trap" +version = "0.1.0" +edition = "2021" +authors = ["lvgenggeng"] +build = "../build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +name = "rtrap" +crate-type = ["staticlib"] + +[dependencies] +libc = "0.2" +nix = "0.23" diff --git a/bash-5.1/builtins_rust/trap/src/intercdep.rs b/bash-5.1/builtins_rust/trap/src/intercdep.rs new file mode 100644 index 00000000..5b22830a --- /dev/null +++ b/bash-5.1/builtins_rust/trap/src/intercdep.rs @@ -0,0 +1,74 @@ + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_desc { + pub word: *mut c_char, + pub flags: c_int, +} +pub type WORD_DESC = word_desc; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct word_list { + pub next: *mut word_list, + pub word: *mut WORD_DESC, +} +pub type WORD_LIST = word_list; + +pub type SigHandler = unsafe extern "C" fn(arg1: c_int); + +pub const EXECUTION_SUCCESS : c_int = 0; +pub const EXECUTION_FAILURE : c_int = 1; +pub const EX_USAGE: c_int = 258; + +pub const DSIG_SIGPREFIX: c_int = 0x01; +pub const DSIG_NOCASE: c_int = 0x02; + +pub const BASH_NSIG: c_int = (64 + 1) + 3; +pub const NO_SIG: c_int = -1; + +pub const SET: c_int = 0; +pub const REVERT: c_int = 1; +pub const IGNORE: c_int = 2; + +pub const SUBSHELL_RESETTRAP: c_int = 0x80; + +extern "C" { + pub fn reset_internal_getopt(); + pub fn internal_getopt(list: *mut WORD_LIST, opts: *mut c_char) -> c_int; + pub fn builtin_usage(); + pub fn builtin_error(format: *const c_char, ...); + + pub fn sh_chkwrite(s: c_int) -> c_int; + pub fn display_signal_list(list: *mut WORD_LIST, forcecols: c_int) -> c_int; + pub fn initialize_terminating_signals(); + pub fn get_all_original_signals(); + pub fn free_trap_strings(); + pub fn ignore_signal(sig: c_int); + pub fn set_signal(sig: c_int, s: *mut c_char); + pub fn restore_default_signal(sig: c_int); + pub fn sigint_sighandler(sig: c_int); + pub fn termsig_sighandler(sig: c_int); + pub fn set_signal_handler(arg1: c_int, arg2: *mut SigHandler) -> *mut SigHandler; + + pub fn all_digits(s: *const c_char) -> c_int; + pub fn decode_signal(s: *mut c_char, flags: c_int) -> c_int; + + pub fn signal_is_hard_ignored(sig: c_int) -> c_int; + pub fn sh_single_quote(s: *const c_char) -> *mut c_char; + pub fn signal_name(sig: c_int) -> *mut c_char; + + pub fn sh_invalidsig(s: *mut c_char); + + pub static mut list_optarg : *mut libc::c_char; + pub static mut loptend : *mut WORD_LIST; + + pub static trap_list: [*mut c_char; BASH_NSIG as usize]; + pub static posixly_correct: c_int; + pub static mut subshell_environment: c_int; + pub static interactive: c_int; + pub static interactive_shell: c_int; + pub static sourcelevel: c_int; + pub static running_trap: c_int; + pub static parse_and_execute_level: c_int; +} \ No newline at end of file diff --git a/bash-5.1/builtins_rust/trap/src/lib.rs b/bash-5.1/builtins_rust/trap/src/lib.rs index e69de29b..68ebe612 100644 --- a/bash-5.1/builtins_rust/trap/src/lib.rs +++ b/bash-5.1/builtins_rust/trap/src/lib.rs @@ -0,0 +1,178 @@ +use std::{ffi::CString}; + +use libc::{c_int, c_char, c_void, PT_NULL}; + +include!(concat!("intercdep.rs")); + + +#[no_mangle] +pub extern "C" fn r_trap_builtin(mut list: *mut WORD_LIST) -> i32 { + println!("r_trap_builtin call"); + + let mut list_signal_names: c_int = 0; + let mut display: c_int = 0; + let mut result: c_int = EXECUTION_SUCCESS; + +unsafe { + reset_internal_getopt(); + let opt_str = CString::new("lp").unwrap(); + let mut opt = internal_getopt (list, opt_str.as_ptr() as * mut c_char); + while opt != -1 { + let opt_char:char=char::from(opt as u8); + match opt_char { + 'l' => list_signal_names += 1, + 'p' => display += 1, + _ => { + builtin_usage (); + return EX_USAGE; + } + } + opt = internal_getopt (list, opt_str.as_ptr() as * mut c_char); + } + list = loptend; + + opt = DSIG_NOCASE | DSIG_SIGPREFIX; + + if list_signal_names != 0 { + return sh_chkwrite(display_signal_list(PT_NULL as *mut WORD_LIST, 1)); + } else if display != 0 || list.is_null() { + initialize_terminating_signals(); + get_all_original_signals(); + return sh_chkwrite(display_traps(list, (display != 0 && posixly_correct != 0) as c_int)); + } else { + let mut operation = SET; + let first_arg = (*(*list).word).word; + let first_signal = !first_arg.is_null() && *first_arg != 0 && + all_digits(first_arg) != 0 && decode_signal (first_arg,opt) != NO_SIG; + if first_signal { + operation = REVERT; + } else if posixly_correct == 0 && !first_arg.is_null() && *first_arg != 0 && + (*first_arg != b'-' as c_char || *((first_arg as usize + 1) as *mut c_char) != 0 ) && + decode_signal (first_arg,opt) != NO_SIG && (*list).next.is_null() { + operation = REVERT; + } else { + list = (*list).next; + if list.is_null() { + builtin_usage(); + return EX_USAGE; + } else if *first_arg == b'\0' as c_char { + operation = IGNORE; + } else if *first_arg == b'-' as c_char && *((first_arg as usize + 1) as *mut c_char) == 0 { + operation = REVERT; + } + } + + if subshell_environment & SUBSHELL_RESETTRAP != 0 { + free_trap_strings(); + subshell_environment &= !SUBSHELL_RESETTRAP; + } + + let mut sig: c_int; + while !list.is_null() { + sig = decode_signal((*(*list).word).word, opt); + if sig == NO_SIG { + sh_invalidsig((*(*list).word).word); + result = EXECUTION_FAILURE; + } else { + match operation { + SET => set_signal(sig, first_arg), + IGNORE => ignore_signal(sig), + REVERT => { + restore_default_signal(sig); + match sig { + libc::SIGINT => { + if interactive != 0 { + set_signal_handler(libc::SIGINT, sigint_sighandler as *mut SigHandler); + } else if interactive_shell != 0 && + (sourcelevel != 0 || running_trap != 0 || parse_and_execute_level != 0) { + set_signal_handler(libc::SIGINT, sigint_sighandler as *mut SigHandler); + } else { + set_signal_handler(libc::SIGINT, termsig_sighandler as *mut SigHandler); + } + } + libc::SIGQUIT => { + set_signal_handler(libc::SIGQUIT, std::mem::transmute(1_usize)); + } + libc::SIGTERM | libc::SIGTTIN | libc::SIGTTOU | libc::SIGTSTP => { + if interactive != 0 { + set_signal_handler(sig, std::mem::transmute(1_usize)); + } + } + _ => (), + } + break; + } + _ => (), + } + } + + list = (*list).next; + } + } +} + return result; +} + +unsafe fn showtrap(i: c_int, show_default: c_int) +{ + let t: *mut c_char; + + let p = trap_list[i as usize]; + if (p == libc::SIG_DFL as *mut c_char) && signal_is_hard_ignored(i) == 0 { + if show_default != 0 { + t = "-\0".as_ptr() as *mut c_char; + } else { + return; + } + } else if signal_is_hard_ignored(i) != 0 { + t = PT_NULL as *mut c_char; + } else { + t = if p == libc::SIG_IGN as *mut c_char {PT_NULL as *mut c_char} else {sh_single_quote(p)} + } + + let sn = signal_name(i); + if libc::strncmp(sn, "SIGJUNK\0".as_ptr() as *const c_char, 7) == 0 || + libc::strncmp(sn, "unknown\0".as_ptr() as *const c_char, 7) == 0 { + libc::printf("trap -- %s %d\n\0".as_ptr() as *const c_char, if t.is_null() {"''\0".as_ptr() as *mut c_char} else {t}, i); + } else if posixly_correct != 0 { + if libc::strncmp(sn, "SIG\0".as_ptr() as *const c_char, 3) == 0 { + libc::printf("trap -- %s %s\n\0".as_ptr() as *const c_char, if t.is_null() {"''\0".as_ptr() as *mut c_char} else {t}, (sn as usize + 3) as *mut c_char); + } else { + libc::printf("trap -- %s %s\n\0".as_ptr() as *const c_char, if t.is_null() {"''\0".as_ptr() as *mut c_char} else {t}, sn); + } + } else { + libc::printf("trap -- %s %s\n\0".as_ptr() as *const c_char, if t.is_null() {"''\0".as_ptr() as *mut c_char} else {t}, sn); + } + + if show_default == 0 { + if !t.is_null() { + libc::free(t as *mut c_void); + } + } +} + +unsafe fn display_traps(mut list: *mut WORD_LIST, show_all: c_int) -> c_int +{ + if list.is_null() { + for i in 0..BASH_NSIG { + showtrap(i, show_all); + } + return EXECUTION_SUCCESS; + } + + let mut result = EXECUTION_SUCCESS; + let mut i: c_int; + while !list.is_null() { + i = decode_signal((*(*list).word).word, DSIG_NOCASE | DSIG_SIGPREFIX); + if i == NO_SIG { + sh_invalidsig((*(*list).word).word); + result = EXECUTION_FAILURE; + } else { + showtrap(i, show_all); + } + + list = (*list).next; + } + + return result; +} diff --git a/bash-5.1/configure b/bash-5.1/configure index 0d917697..fd4e2113 100755 --- a/bash-5.1/configure +++ b/bash-5.1/configure @@ -1,9 +1,9 @@ #! /bin/sh # From configure.ac for Bash 5.1, version 5.022. # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for bash 5.1-release. +# Generated by GNU Autoconf 2.69 for rash 0.1-release. # -# Report bugs to . +# Report bugs to . # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -267,7 +267,7 @@ fi $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" $as_echo "$0: be upgraded to zsh 4.3.4 or later." else - $as_echo "$0: Please tell bug-autoconf@gnu.org and bug-bash@gnu.org + $as_echo "$0: Please tell bug-autoconf@gnu.org and bug-rash@gnu.org $0: about your system, including any error possibly output $0: before this message. Then install a modern shell, or $0: manually run the script under such a shell if you do @@ -579,11 +579,11 @@ MFLAGS= MAKEFLAGS= # Identity of this package. -PACKAGE_NAME='bash' -PACKAGE_TARNAME='bash' -PACKAGE_VERSION='5.1-release' -PACKAGE_STRING='bash 5.1-release' -PACKAGE_BUGREPORT='bug-bash@gnu.org' +PACKAGE_NAME='rash' +PACKAGE_TARNAME='rash' +PACKAGE_VERSION='0.1-release' +PACKAGE_STRING='rash 0.1-release' +PACKAGE_BUGREPORT='bug-rash@gnu.org' PACKAGE_URL='' ac_unique_file="shell.h" @@ -1427,7 +1427,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures bash 5.1-release to adapt to many kinds of systems. +\`configure' configures rash 0.1-release to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1475,7 +1475,7 @@ Fine tuning of the installation directories: --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] - --docdir=DIR documentation root [DATAROOTDIR/doc/bash] + --docdir=DIR documentation root [DATAROOTDIR/doc/rash] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] @@ -1492,7 +1492,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of bash 5.1-release:";; + short | recursive ) echo "Configuration of rash 0.1-release:";; esac cat <<\_ACEOF @@ -1630,7 +1630,7 @@ Some influential environment variables: Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. -Report bugs to . +Report bugs to . _ACEOF ac_status=$? fi @@ -1693,7 +1693,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -bash configure 5.1-release +rash configure 0.1-release generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1899,7 +1899,7 @@ $as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" > { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ( $as_echo "## ------------------------------- ## -## Report this to bug-bash@gnu.org ## +## Report this to bug-rash@gnu.org ## ## ------------------------------- ##" ) | sed "s/^/$as_me: WARNING: /" >&2 ;; @@ -2402,7 +2402,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by bash $as_me 5.1-release, which was +It was created by rash $as_me 0.1-release, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2799,7 +2799,7 @@ ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. ac_config_headers="$ac_config_headers config.h" -BASHVERS=5.1 +BASHVERS=0.1 RELSTATUS=release case "$RELSTATUS" in @@ -4231,7 +4231,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu if test -n "$want_auto_cflags"; then AUTO_CFLAGS="-g ${GCC+-O2}" AUTO_LDFLAGS="-g ${GCC+-O2}" - STYLE_CFLAGS="${GCC+-Wno-parentheses} ${GCC+-Wno-format-security} ${GCC+-fPIC}" + STYLE_CFLAGS="${GCC+-Wno-parentheses} ${GCC+-Wno-format-security}" else AUTO_CFLAGS= AUTO_LDFLAGS= STYLE_CFLAGS= fi @@ -13881,7 +13881,7 @@ fi for ac_func in dup2 eaccess fcntl getdtablesize getentropy getgroups \ gethostname getpagesize getpeername getrandom getrlimit \ getrusage gettimeofday kill killpg lstat pselect readlink \ - select setdtablesize setitimer tcgetpgrp uname ulimit waitpid + select setdtablesize setitimer tcgetpgrp uname ulimit waitpid pread do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" @@ -17094,7 +17094,7 @@ main() _ACEOF if ac_fn_c_try_run "$LINENO"; then : - bash_cv_pgrp_pipe=no + bash_cv_pgrp_pipe=yes else bash_cv_pgrp_pipe=yes fi @@ -17208,6 +17208,19 @@ $as_echo "#define HAVE_USG_SIGHOLD 1" >>confdefs.h fi +ac_fn_c_check_decl "$LINENO" "AUDIT_USER_TTY" "ac_cv_have_decl_AUDIT_USER_TTY" "#include +" +if test "x$ac_cv_have_decl_AUDIT_USER_TTY" = xyes; then : + ac_have_decl=1 +else + ac_have_decl=0 +fi + +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_AUDIT_USER_TTY $ac_have_decl +_ACEOF + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sys_errlist and sys_nerr" >&5 $as_echo_n "checking for sys_errlist and sys_nerr... " >&6; } if ${bash_cv_sys_errlist+:} false; then : @@ -20255,7 +20268,6 @@ fi $as_echo "using $bash_cv_termcap_lib" >&6; } if test $bash_cv_termcap_lib = gnutermcap && test -z "$prefer_curses"; then LDFLAGS="$LDFLAGS -L./lib/termcap" - TERMCAP_LIB="./lib/termcap/libtermcap.a" TERMCAP_DEP="./lib/termcap/libtermcap.a" elif test $bash_cv_termcap_lib = libtermcap && test -z "$prefer_curses"; then @@ -20547,7 +20559,7 @@ fi #AC_SUBST(ALLOCA_SOURCE) #AC_SUBST(ALLOCA_OBJECT) -ac_config_files="$ac_config_files Makefile builtins/Makefile lib/readline/Makefile lib/glob/Makefile lib/intl/Makefile lib/malloc/Makefile lib/sh/Makefile lib/termcap/Makefile lib/tilde/Makefile doc/Makefile support/Makefile po/Makefile.in examples/loadables/Makefile examples/loadables/Makefile.inc examples/loadables/perl/Makefile support/bash.pc support/bashbug.sh" +ac_config_files="$ac_config_files Makefile builtins/Makefile lib/readline/Makefile lib/glob/Makefile lib/intl/Makefile lib/malloc/Makefile lib/sh/Makefile lib/termcap/Makefile lib/tilde/Makefile doc/Makefile support/Makefile po/Makefile.in examples/loadables/Makefile examples/loadables/Makefile.inc examples/loadables/perl/Makefile support/rash.pc support/rashbug.sh" ac_config_commands="$ac_config_commands default" @@ -21058,7 +21070,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by bash $as_me 5.1-release, which was +This file was extended by rash $as_me 0.1-release, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -21118,13 +21130,13 @@ $config_headers Configuration commands: $config_commands -Report bugs to ." +Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -bash config.status 5.1-release +rash config.status 0.1-release configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" @@ -21274,8 +21286,8 @@ do "examples/loadables/Makefile") CONFIG_FILES="$CONFIG_FILES examples/loadables/Makefile" ;; "examples/loadables/Makefile.inc") CONFIG_FILES="$CONFIG_FILES examples/loadables/Makefile.inc" ;; "examples/loadables/perl/Makefile") CONFIG_FILES="$CONFIG_FILES examples/loadables/perl/Makefile" ;; - "support/bash.pc") CONFIG_FILES="$CONFIG_FILES support/bash.pc" ;; - "support/bashbug.sh") CONFIG_FILES="$CONFIG_FILES support/bashbug.sh" ;; + "support/rash.pc") CONFIG_FILES="$CONFIG_FILES support/rash.pc" ;; + "support/rashbug.sh") CONFIG_FILES="$CONFIG_FILES support/rashbug.sh" ;; "default") CONFIG_COMMANDS="$CONFIG_COMMANDS default" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; diff --git a/bash-5.1/configure.ac b/bash-5.1/configure.ac index aeb3d30b..2d2a0590 100644 --- a/bash-5.1/configure.ac +++ b/bash-5.1/configure.ac @@ -23,10 +23,10 @@ dnl Process this file with autoconf to produce a configure script. AC_REVISION([for Bash 5.1, version 5.022])dnl -define(bashvers, 5.1) +define(rashvers, 0.1) define(relstatus, release) -AC_INIT([bash], bashvers-relstatus, [bug-bash@gnu.org]) +AC_INIT([rash], rashvers-relstatus, [bug-rash@gnu.org]) dnl make sure we are using a recent autoconf version AC_PREREQ(2.61) @@ -37,7 +37,7 @@ AC_CONFIG_AUX_DIR(./support) AC_CONFIG_HEADERS(config.h) dnl checks for version info -BASHVERS=bashvers +BASHVERS=rashvers RELSTATUS=relstatus dnl defaults for debug settings @@ -1305,7 +1305,7 @@ AC_OUTPUT([Makefile builtins/Makefile lib/readline/Makefile lib/glob/Makefile \ lib/tilde/Makefile doc/Makefile support/Makefile po/Makefile.in \ examples/loadables/Makefile examples/loadables/Makefile.inc \ examples/loadables/perl/Makefile \ - support/bash.pc support/bashbug.sh], + support/bash.pc support/rashbug.sh], [ # Makefile uses this timestamp file to record whether config.h is up to date. echo timestamp > stamp-h diff --git a/bash-5.1/create-so.sh b/bash-5.1/create-so.sh index 26bd7b15..8b37e7ba 100644 --- a/bash-5.1/create-so.sh +++ b/bash-5.1/create-so.sh @@ -1,10 +1,18 @@ #!/bin/bash find . -name "*.o" > o.list + + for line in `cat o.list` do - soname=${line%%.o*} - soname=${soname##*.} - soname=${soname////_} + echo "000 $line" + #soname=`basename $line` + soname=${line%.o} + echo "AAA $soname" + soname=${soname#./} + echo "BBB $soname" + soname=`echo $soname |sed 's/\//_/g'` + echo "CCC $soname" + echo "gcc -shared -fPIC -o /opt/rsbash/builtins/lib${soname}.so $line " gcc -shared -fPIC -o /opt/rsbash/builtins/lib${soname}.so $line done diff --git a/bash-5.1/examples/scripts/shprompt b/bash-5.1/examples/scripts/shprompt index 098c45f0..91035a8c 100755 --- a/bash-5.1/examples/scripts/shprompt +++ b/bash-5.1/examples/scripts/shprompt @@ -1,3 +1,4 @@ +#!/bin/bash # # shprompt -- give a prompt and get an answer satisfying certain criteria # diff --git a/bash-5.1/execute_cmd.c b/bash-5.1/execute_cmd.c index 9d66af0b..77e058cf 100644 --- a/bash-5.1/execute_cmd.c +++ b/bash-5.1/execute_cmd.c @@ -5312,6 +5312,7 @@ execute_builtin_or_function (words, builtin, var, redirects, int ofifo, nfifo, osize; void *ofifo_list; #endif + #if defined (PROCESS_SUBSTITUTION) begin_unwind_frame ("saved_fifos"); /* If we return, we longjmp and don't get a chance to restore the old diff --git a/bash-5.1/src/lib.rs b/bash-5.1/src/lib.rs index 39f431c5..a742d427 100644 --- a/bash-5.1/src/lib.rs +++ b/bash-5.1/src/lib.rs @@ -1,4 +1,4 @@ -use libc::{c_char, c_int, c_long}; +use libc::{c_char, c_int }; use std::ffi::CStr; use std::str; @@ -31,7 +31,7 @@ pub extern "C" fn r_execute_cmd2(l : *mut WORD_LIST) -> i32 { let mut it : *mut WORD_LIST = l; while std::ptr::null() != it { //let mut a = (&((* ((*l).word)).word) ); - let mut a :*mut c_char =( *(*it).word).word; + let a :*mut c_char =( *(*it).word).word; let c_str: &CStr = CStr::from_ptr(a); let str_slice: &str = c_str.to_str().unwrap(); println! ("word is {:?}", str_slice); diff --git a/bash-5.1/src/main.rs b/bash-5.1/src/main.rs index b1ec861f..ab6dd25b 100644 --- a/bash-5.1/src/main.rs +++ b/bash-5.1/src/main.rs @@ -1,10 +1,9 @@ -use command1::say_hello; -use command2::hello2; - +//use command1::say_hello; +//use command2::hello2; fn main() { - hello2(); - say_hello(); +// hello2(); +// say_hello(); println!("Hello, world!"); //execute_cmd(); } diff --git a/bash-5.1/support/config.guess b/bash-5.1/support/config.guess index 0fc11edb..caea0fae 100755 --- a/bash-5.1/support/config.guess +++ b/bash-5.1/support/config.guess @@ -1,8 +1,8 @@ #! /bin/sh # Attempt to guess a canonical system name. -# Copyright 1992-2020 Free Software Foundation, Inc. +# Copyright 1992-2016 Free Software Foundation, Inc. -timestamp='2020-11-07' +timestamp='2016-10-02' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -15,7 +15,7 @@ timestamp='2020-11-07' # General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program; if not, see . +# along with this program; if not, see . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a @@ -27,19 +27,19 @@ timestamp='2020-11-07' # Originally written by Per Bothner; maintained since 2000 by Ben Elliston. # # You can get the latest version of this script from: -# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess +# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess # # Please send patches to . -me=$(echo "$0" | sed -e 's,.*/,,') +me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] Output the configuration name of the system \`$me' is run on. -Options: +Operation modes: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit @@ -50,7 +50,7 @@ version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright 1992-2020 Free Software Foundation, Inc. +Copyright 1992-2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -84,6 +84,8 @@ if test $# != 0; then exit 1 fi +trap 'exit 1' 1 2 15 + # CC_FOR_BUILD -- compiler used by this script. Note that the use of a # compiler to aid in system detection is discouraged as it requires # temporary files to be created and, as you can see below, it is a @@ -94,77 +96,66 @@ fi # Portable tmp directory creation inspired by the Autoconf team. -tmp= -# shellcheck disable=SC2172 -trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15 - -set_cc_for_build() { - # prevent multiple calls if $tmp is already set - test "$tmp" && return 0 - : "${TMPDIR=/tmp}" - # shellcheck disable=SC2039 - { tmp=$( (umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null) && test -n "$tmp" && test -d "$tmp" ; } || - { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } || - { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } || - { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } - dummy=$tmp/dummy - case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in - ,,) echo "int x;" > "$dummy.c" - for driver in cc gcc c89 c99 ; do - if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then - CC_FOR_BUILD="$driver" - break - fi - done - if test x"$CC_FOR_BUILD" = x ; then - CC_FOR_BUILD=no_compiler_found - fi - ;; - ,,*) CC_FOR_BUILD=$CC ;; - ,*,*) CC_FOR_BUILD=$HOST_CC ;; - esac -} +set_cc_for_build=' +trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; +trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; +: ${TMPDIR=/tmp} ; + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; +dummy=$tmp/dummy ; +tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; +case $CC_FOR_BUILD,$HOST_CC,$CC in + ,,) echo "int x;" > $dummy.c ; + for c in cc gcc c89 c99 ; do + if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then + CC_FOR_BUILD="$c"; break ; + fi ; + done ; + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found ; + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; +esac ; set_cc_for_build= ;' # This is needed to find uname on a Pyramid OSx when run in the BSD universe. # (ghazi@noc.rutgers.edu 1994-08-24) -if test -f /.attbin/uname ; then +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then PATH=$PATH:/.attbin ; export PATH fi -UNAME_MACHINE=$( (uname -m) 2>/dev/null) || UNAME_MACHINE=unknown -UNAME_RELEASE=$( (uname -r) 2>/dev/null) || UNAME_RELEASE=unknown -UNAME_SYSTEM=$( (uname -s) 2>/dev/null) || UNAME_SYSTEM=unknown -UNAME_VERSION=$( (uname -v) 2>/dev/null) || UNAME_VERSION=unknown +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown -case "$UNAME_SYSTEM" in +case "${UNAME_SYSTEM}" in Linux|GNU|GNU/*) # If the system lacks a compiler, then just pick glibc. # We could probably try harder. LIBC=gnu - set_cc_for_build - cat <<-EOF > "$dummy.c" + eval $set_cc_for_build + cat <<-EOF > $dummy.c #include #if defined(__UCLIBC__) LIBC=uclibc #elif defined(__dietlibc__) LIBC=dietlibc #else - #include - #ifdef __DEFINED_va_list - LIBC=musl - #else LIBC=gnu #endif - #endif EOF - eval "$($CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g')" + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` ;; esac # Note: order is significant - the case branches are not exclusive. -case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in *:NetBSD:*:*) # NetBSD (nbsd) targets should (where applicable) match one or # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, @@ -177,32 +168,31 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in # Note: NetBSD doesn't particularly care about the vendor # portion of the name. We always set it to "unknown". sysctl="sysctl -n hw.machine_arch" - UNAME_MACHINE_ARCH=$( (uname -p 2>/dev/null || \ - "/sbin/$sysctl" 2>/dev/null || \ - "/usr/sbin/$sysctl" 2>/dev/null || \ - echo unknown)) - case "$UNAME_MACHINE_ARCH" in - aarch64eb) machine=aarch64_be-unknown ;; + UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \ + /sbin/$sysctl 2>/dev/null || \ + /usr/sbin/$sysctl 2>/dev/null || \ + echo unknown)` + case "${UNAME_MACHINE_ARCH}" in armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; sh5el) machine=sh5le-unknown ;; earmv*) - arch=$(echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,') - endian=$(echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p') - machine="${arch}${endian}"-unknown + arch=`echo ${UNAME_MACHINE_ARCH} | sed -e 's,^e\(armv[0-9]\).*$,\1,'` + endian=`echo ${UNAME_MACHINE_ARCH} | sed -ne 's,^.*\(eb\)$,\1,p'` + machine=${arch}${endian}-unknown ;; - *) machine="$UNAME_MACHINE_ARCH"-unknown ;; + *) machine=${UNAME_MACHINE_ARCH}-unknown ;; esac # The Operating System including object format, if it has switched # to ELF recently (or will in the future) and ABI. - case "$UNAME_MACHINE_ARCH" in + case "${UNAME_MACHINE_ARCH}" in earm*) os=netbsdelf ;; arm*|i386|m68k|ns32k|sh3*|sparc|vax) - set_cc_for_build + eval $set_cc_for_build if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ELF__ then @@ -218,10 +208,10 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in ;; esac # Determine ABI tags. - case "$UNAME_MACHINE_ARCH" in + case "${UNAME_MACHINE_ARCH}" in earm*) expr='s/^earmv[0-9]/-eabi/;s/eb$//' - abi=$(echo "$UNAME_MACHINE_ARCH" | sed -e "$expr") + abi=`echo ${UNAME_MACHINE_ARCH} | sed -e "$expr"` ;; esac # The OS release @@ -229,75 +219,60 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in # thus, need a distinct triplet. However, they do not need # kernel version information, so it can be replaced with a # suitable tag, in the style of linux-gnu. - case "$UNAME_VERSION" in + case "${UNAME_VERSION}" in Debian*) release='-gnu' ;; *) - release=$(echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2) + release=`echo ${UNAME_RELEASE} | sed -e 's/[-_].*//' | cut -d. -f1,2` ;; esac # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. - echo "$machine-${os}${release}${abi-}" + echo "${machine}-${os}${release}${abi}" exit ;; *:Bitrig:*:*) - UNAME_MACHINE_ARCH=$(arch | sed 's/Bitrig.//') - echo "$UNAME_MACHINE_ARCH"-unknown-bitrig"$UNAME_RELEASE" + UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE} exit ;; *:OpenBSD:*:*) - UNAME_MACHINE_ARCH=$(arch | sed 's/OpenBSD.//') - echo "$UNAME_MACHINE_ARCH"-unknown-openbsd"$UNAME_RELEASE" + UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} exit ;; *:LibertyBSD:*:*) - UNAME_MACHINE_ARCH=$(arch | sed 's/^.*BSD\.//') - echo "$UNAME_MACHINE_ARCH"-unknown-libertybsd"$UNAME_RELEASE" - exit ;; - *:MidnightBSD:*:*) - echo "$UNAME_MACHINE"-unknown-midnightbsd"$UNAME_RELEASE" + UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-libertybsd${UNAME_RELEASE} exit ;; *:ekkoBSD:*:*) - echo "$UNAME_MACHINE"-unknown-ekkobsd"$UNAME_RELEASE" + echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} exit ;; *:SolidBSD:*:*) - echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE" - exit ;; - *:OS108:*:*) - echo "$UNAME_MACHINE"-unknown-os108_"$UNAME_RELEASE" + echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} exit ;; macppc:MirBSD:*:*) - echo powerpc-unknown-mirbsd"$UNAME_RELEASE" + echo powerpc-unknown-mirbsd${UNAME_RELEASE} exit ;; *:MirBSD:*:*) - echo "$UNAME_MACHINE"-unknown-mirbsd"$UNAME_RELEASE" + echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} exit ;; *:Sortix:*:*) - echo "$UNAME_MACHINE"-unknown-sortix - exit ;; - *:Twizzler:*:*) - echo "$UNAME_MACHINE"-unknown-twizzler - exit ;; - *:Redox:*:*) - echo "$UNAME_MACHINE"-unknown-redox - exit ;; - mips:OSF1:*.*) - echo mips-dec-osf1 + echo ${UNAME_MACHINE}-unknown-sortix exit ;; alpha:OSF1:*:*) case $UNAME_RELEASE in *4.0) - UNAME_RELEASE=$(/usr/sbin/sizer -v | awk '{print $3}') + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` ;; *5.*) - UNAME_RELEASE=$(/usr/sbin/sizer -v | awk '{print $4}') + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` ;; esac # According to Compaq, /usr/sbin/psrinfo has been available on # OSF/1 and Tru64 systems produced since 1995. I hope that # covers most systems running today. This code pipes the CPU # types through head -n 1, so we only detect the type of CPU 0. - ALPHA_CPU_TYPE=$(/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1) + ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` case "$ALPHA_CPU_TYPE" in "EV4 (21064)") UNAME_MACHINE=alpha ;; @@ -335,19 +310,28 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. - echo "$UNAME_MACHINE"-dec-osf"$(echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz)" + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` # Reset EXIT trap before exiting to avoid spurious non-zero exit code. exitcode=$? trap '' 0 exit $exitcode ;; + Alpha\ *:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # Should we change UNAME_MACHINE based on the output of uname instead + # of the specific Alpha model? + echo alpha-pc-interix + exit ;; + 21064:Windows_NT:50:3) + echo alpha-dec-winnt3.5 + exit ;; Amiga*:UNIX_System_V:4.0:*) echo m68k-unknown-sysv4 exit ;; *:[Aa]miga[Oo][Ss]:*:*) - echo "$UNAME_MACHINE"-unknown-amigaos + echo ${UNAME_MACHINE}-unknown-amigaos exit ;; *:[Mm]orph[Oo][Ss]:*:*) - echo "$UNAME_MACHINE"-unknown-morphos + echo ${UNAME_MACHINE}-unknown-morphos exit ;; *:OS/390:*:*) echo i370-ibm-openedition @@ -359,7 +343,7 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in echo powerpc-ibm-os400 exit ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) - echo arm-acorn-riscix"$UNAME_RELEASE" + echo arm-acorn-riscix${UNAME_RELEASE} exit ;; arm*:riscos:*:*|arm*:RISCOS:*:*) echo arm-unknown-riscos @@ -369,7 +353,7 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in exit ;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. - if test "$( (/bin/universe) 2>/dev/null)" = att ; then + if test "`(/bin/universe) 2>/dev/null`" = att ; then echo pyramid-pyramid-sysv3 else echo pyramid-pyramid-bsd @@ -382,28 +366,28 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in echo sparc-icl-nx6 exit ;; DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) - case $(/usr/bin/uname -p) in + case `/usr/bin/uname -p` in sparc) echo sparc-icl-nx7; exit ;; esac ;; s390x:SunOS:*:*) - echo "$UNAME_MACHINE"-ibm-solaris2"$(echo "$UNAME_RELEASE" | sed -e 's/[^.]*//')" + echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4H:SunOS:5.*:*) - echo sparc-hal-solaris2"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) - echo sparc-sun-solaris2"$(echo "$UNAME_RELEASE" | sed -e 's/[^.]*//')" + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) - echo i386-pc-auroraux"$UNAME_RELEASE" + echo i386-pc-auroraux${UNAME_RELEASE} exit ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) - set_cc_for_build + eval $set_cc_for_build SUN_ARCH=i386 # If there is a compiler, see if it is configured for 64-bit objects. # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. # This test works for both compilers. - if test "$CC_FOR_BUILD" != no_compiler_found; then + if [ "$CC_FOR_BUILD" != no_compiler_found ]; then if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null @@ -411,40 +395,40 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in SUN_ARCH=x86_64 fi fi - echo "$SUN_ARCH"-pc-solaris2"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" + echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. - echo sparc-sun-solaris3"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:*:*) - case "$(/usr/bin/arch -k)" in + case "`/usr/bin/arch -k`" in Series*|S4*) - UNAME_RELEASE=$(uname -v) + UNAME_RELEASE=`uname -v` ;; esac # Japanese Language versions have a version number like `4.1.3-JL'. - echo sparc-sun-sunos"$(echo "$UNAME_RELEASE"|sed -e 's/-/_/')" + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` exit ;; sun3*:SunOS:*:*) - echo m68k-sun-sunos"$UNAME_RELEASE" + echo m68k-sun-sunos${UNAME_RELEASE} exit ;; sun*:*:4.2BSD:*) - UNAME_RELEASE=$( (sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null) - test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3 - case "$(/bin/arch)" in + UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x${UNAME_RELEASE}" = x && UNAME_RELEASE=3 + case "`/bin/arch`" in sun3) - echo m68k-sun-sunos"$UNAME_RELEASE" + echo m68k-sun-sunos${UNAME_RELEASE} ;; sun4) - echo sparc-sun-sunos"$UNAME_RELEASE" + echo sparc-sun-sunos${UNAME_RELEASE} ;; esac exit ;; aushp:SunOS:*:*) - echo sparc-auspex-sunos"$UNAME_RELEASE" + echo sparc-auspex-sunos${UNAME_RELEASE} exit ;; # The situation for MiNT is a little confusing. The machine name # can be virtually everything (everything which is not @@ -455,44 +439,44 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in # MiNT. But MiNT is downward compatible to TOS, so this should # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint"$UNAME_RELEASE" + echo m68k-atari-mint${UNAME_RELEASE} exit ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint"$UNAME_RELEASE" + echo m68k-atari-mint${UNAME_RELEASE} exit ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) - echo m68k-atari-mint"$UNAME_RELEASE" + echo m68k-atari-mint${UNAME_RELEASE} exit ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) - echo m68k-milan-mint"$UNAME_RELEASE" + echo m68k-milan-mint${UNAME_RELEASE} exit ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) - echo m68k-hades-mint"$UNAME_RELEASE" + echo m68k-hades-mint${UNAME_RELEASE} exit ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) - echo m68k-unknown-mint"$UNAME_RELEASE" + echo m68k-unknown-mint${UNAME_RELEASE} exit ;; m68k:machten:*:*) - echo m68k-apple-machten"$UNAME_RELEASE" + echo m68k-apple-machten${UNAME_RELEASE} exit ;; powerpc:machten:*:*) - echo powerpc-apple-machten"$UNAME_RELEASE" + echo powerpc-apple-machten${UNAME_RELEASE} exit ;; RISC*:Mach:*:*) echo mips-dec-mach_bsd4.3 exit ;; RISC*:ULTRIX:*:*) - echo mips-dec-ultrix"$UNAME_RELEASE" + echo mips-dec-ultrix${UNAME_RELEASE} exit ;; VAX*:ULTRIX*:*:*) - echo vax-dec-ultrix"$UNAME_RELEASE" + echo vax-dec-ultrix${UNAME_RELEASE} exit ;; 2020:CLIX:*:* | 2430:CLIX:*:*) - echo clipper-intergraph-clix"$UNAME_RELEASE" + echo clipper-intergraph-clix${UNAME_RELEASE} exit ;; mips:*:*:UMIPS | mips:*:*:RISCos) - set_cc_for_build - sed 's/^ //' << EOF > "$dummy.c" + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c #ifdef __cplusplus #include /* for printf() prototype */ int main (int argc, char *argv[]) { @@ -501,23 +485,23 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in #endif #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) - printf ("mips-mips-riscos%ssysv\\n", argv[1]); exit (0); + printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_SVR4) - printf ("mips-mips-riscos%ssvr4\\n", argv[1]); exit (0); + printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) - printf ("mips-mips-riscos%sbsd\\n", argv[1]); exit (0); + printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); #endif #endif exit (-1); } EOF - $CC_FOR_BUILD -o "$dummy" "$dummy.c" && - dummyarg=$(echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p') && - SYSTEM_NAME=$("$dummy" "$dummyarg") && + $CC_FOR_BUILD -o $dummy $dummy.c && + dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`$dummy $dummyarg` && { echo "$SYSTEM_NAME"; exit; } - echo mips-mips-riscos"$UNAME_RELEASE" + echo mips-mips-riscos${UNAME_RELEASE} exit ;; Motorola:PowerMAX_OS:*:*) echo powerpc-motorola-powermax @@ -542,18 +526,18 @@ EOF exit ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures - UNAME_PROCESSOR=$(/usr/bin/uname -p) - if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110 + UNAME_PROCESSOR=`/usr/bin/uname -p` + if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] then - if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \ - test "$TARGET_BINARY_INTERFACE"x = x + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ + [ ${TARGET_BINARY_INTERFACE}x = x ] then - echo m88k-dg-dgux"$UNAME_RELEASE" + echo m88k-dg-dgux${UNAME_RELEASE} else - echo m88k-dg-dguxbcs"$UNAME_RELEASE" + echo m88k-dg-dguxbcs${UNAME_RELEASE} fi else - echo i586-dg-dgux"$UNAME_RELEASE" + echo i586-dg-dgux${UNAME_RELEASE} fi exit ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) @@ -570,26 +554,26 @@ EOF echo m68k-tektronix-bsd exit ;; *:IRIX*:*:*) - echo mips-sgi-irix"$(echo "$UNAME_RELEASE"|sed -e 's/-/_/g')" + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` exit ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id - exit ;; # Note that: echo "'$(uname -s)'" gives 'AIX ' + exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' i*86:AIX:*:*) echo i386-ibm-aix exit ;; ia64:AIX:*:*) - if test -x /usr/bin/oslevel ; then - IBM_REV=$(/usr/bin/oslevel) + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` else - IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi - echo "$UNAME_MACHINE"-ibm-aix"$IBM_REV" + echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} exit ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then - set_cc_for_build - sed 's/^ //' << EOF > "$dummy.c" + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c #include main() @@ -600,7 +584,7 @@ EOF exit(0); } EOF - if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=$("$dummy") + if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` then echo "$SYSTEM_NAME" else @@ -613,28 +597,28 @@ EOF fi exit ;; *:AIX:*:[4567]) - IBM_CPU_ID=$(/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }') - if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` + if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then IBM_ARCH=rs6000 else IBM_ARCH=powerpc fi - if test -x /usr/bin/lslpp ; then - IBM_REV=$(/usr/bin/lslpp -Lqc bos.rte.libc | - awk -F: '{ print $3 }' | sed s/[0-9]*$/0/) + if [ -x /usr/bin/lslpp ] ; then + IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | + awk -F: '{ print $3 }' | sed s/[0-9]*$/0/` else - IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi - echo "$IBM_ARCH"-ibm-aix"$IBM_REV" + echo ${IBM_ARCH}-ibm-aix${IBM_REV} exit ;; *:AIX:*:*) echo rs6000-ibm-aix exit ;; - ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*) + ibmrt:4.4BSD:*|romp-ibm:BSD:*) echo romp-ibm-bsd4.4 exit ;; ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and - echo romp-ibm-bsd"$UNAME_RELEASE" # 4.3 with uname added to + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to exit ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) echo rs6000-bull-bosx @@ -649,28 +633,28 @@ EOF echo m68k-hp-bsd4.4 exit ;; 9000/[34678]??:HP-UX:*:*) - HPUX_REV=$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//') - case "$UNAME_MACHINE" in - 9000/31?) HP_ARCH=m68000 ;; - 9000/[34]??) HP_ARCH=m68k ;; + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + case "${UNAME_MACHINE}" in + 9000/31? ) HP_ARCH=m68000 ;; + 9000/[34]?? ) HP_ARCH=m68k ;; 9000/[678][0-9][0-9]) - if test -x /usr/bin/getconf; then - sc_cpu_version=$(/usr/bin/getconf SC_CPU_VERSION 2>/dev/null) - sc_kernel_bits=$(/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null) - case "$sc_cpu_version" in + if [ -x /usr/bin/getconf ]; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case "${sc_cpu_version}" in 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 532) # CPU_PA_RISC2_0 - case "$sc_kernel_bits" in + case "${sc_kernel_bits}" in 32) HP_ARCH=hppa2.0n ;; 64) HP_ARCH=hppa2.0w ;; '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20 esac ;; esac fi - if test "$HP_ARCH" = ""; then - set_cc_for_build - sed 's/^ //' << EOF > "$dummy.c" + if [ "${HP_ARCH}" = "" ]; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c #define _HPUX_SOURCE #include @@ -703,13 +687,13 @@ EOF exit (0); } EOF - (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=$("$dummy") + (CCOPTS="" $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` test -z "$HP_ARCH" && HP_ARCH=hppa fi ;; esac - if test "$HP_ARCH" = hppa2.0w + if [ ${HP_ARCH} = hppa2.0w ] then - set_cc_for_build + eval $set_cc_for_build # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler @@ -728,15 +712,15 @@ EOF HP_ARCH=hppa64 fi fi - echo "$HP_ARCH"-hp-hpux"$HPUX_REV" + echo ${HP_ARCH}-hp-hpux${HPUX_REV} exit ;; ia64:HP-UX:*:*) - HPUX_REV=$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//') - echo ia64-hp-hpux"$HPUX_REV" + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux${HPUX_REV} exit ;; 3050*:HI-UX:*:*) - set_cc_for_build - sed 's/^ //' << EOF > "$dummy.c" + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c #include int main () @@ -761,11 +745,11 @@ EOF exit (0); } EOF - $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=$("$dummy") && + $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && { echo "$SYSTEM_NAME"; exit; } echo unknown-hitachi-hiuxwe2 exit ;; - 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*) + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) echo hppa1.1-hp-bsd exit ;; 9000/8??:4.3bsd:*:*) @@ -774,17 +758,17 @@ EOF *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) echo hppa1.0-hp-mpeix exit ;; - hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*) + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) echo hppa1.1-hp-osf exit ;; hp8??:OSF1:*:*) echo hppa1.0-hp-osf exit ;; i*86:OSF1:*:*) - if test -x /usr/sbin/sysversion ; then - echo "$UNAME_MACHINE"-unknown-osf1mk + if [ -x /usr/sbin/sysversion ] ; then + echo ${UNAME_MACHINE}-unknown-osf1mk else - echo "$UNAME_MACHINE"-unknown-osf1 + echo ${UNAME_MACHINE}-unknown-osf1 fi exit ;; parisc*:Lites*:*:*) @@ -809,123 +793,130 @@ EOF echo c4-convex-bsd exit ;; CRAY*Y-MP:*:*:*) - echo ymp-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' + echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*[A-Z]90:*:*:*) - echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \ + echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ -e 's/\.[^.]*$/.X/' exit ;; CRAY*TS:*:*:*) - echo t90-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' + echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*T3E:*:*:*) - echo alphaev5-cray-unicosmk"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' + echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*SV1:*:*:*) - echo sv1-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' + echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; *:UNICOS/mp:*:*) - echo craynv-cray-unicosmp"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' + echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) - FUJITSU_PROC=$(uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz) - FUJITSU_SYS=$(uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///') - FUJITSU_REL=$(echo "$UNAME_RELEASE" | sed -e 's/ /_/') + FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` + FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; 5000:UNIX_System_V:4.*:*) - FUJITSU_SYS=$(uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///') - FUJITSU_REL=$(echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/') + FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) - echo "$UNAME_MACHINE"-pc-bsdi"$UNAME_RELEASE" + echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} exit ;; sparc*:BSD/OS:*:*) - echo sparc-unknown-bsdi"$UNAME_RELEASE" + echo sparc-unknown-bsdi${UNAME_RELEASE} exit ;; *:BSD/OS:*:*) - echo "$UNAME_MACHINE"-unknown-bsdi"$UNAME_RELEASE" - exit ;; - arm:FreeBSD:*:*) - UNAME_PROCESSOR=$(uname -p) - set_cc_for_build - if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep -q __ARM_PCS_VFP - then - echo "${UNAME_PROCESSOR}"-unknown-freebsd"$(echo ${UNAME_RELEASE}|sed -e 's/[-(].*//')"-gnueabi - else - echo "${UNAME_PROCESSOR}"-unknown-freebsd"$(echo ${UNAME_RELEASE}|sed -e 's/[-(].*//')"-gnueabihf - fi + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} exit ;; *:FreeBSD:*:*) - UNAME_PROCESSOR=$(/usr/bin/uname -p) - case "$UNAME_PROCESSOR" in + UNAME_PROCESSOR=`/usr/bin/uname -p` + case ${UNAME_PROCESSOR} in amd64) - UNAME_PROCESSOR=x86_64 ;; - i386) - UNAME_PROCESSOR=i586 ;; + echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + *) + echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; esac - echo "$UNAME_PROCESSOR"-unknown-freebsd"$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')" exit ;; i*:CYGWIN*:*) - echo "$UNAME_MACHINE"-pc-cygwin + echo ${UNAME_MACHINE}-pc-cygwin exit ;; *:MINGW64*:*) - echo "$UNAME_MACHINE"-pc-mingw64 + echo ${UNAME_MACHINE}-pc-mingw64 exit ;; *:MINGW*:*) - echo "$UNAME_MACHINE"-pc-mingw32 + echo ${UNAME_MACHINE}-pc-mingw32 exit ;; *:MSYS*:*) - echo "$UNAME_MACHINE"-pc-msys + echo ${UNAME_MACHINE}-pc-msys + exit ;; + i*:windows32*:*) + # uname -m includes "-pc" on this system. + echo ${UNAME_MACHINE}-mingw32 exit ;; i*:PW*:*) - echo "$UNAME_MACHINE"-pc-pw32 + echo ${UNAME_MACHINE}-pc-pw32 exit ;; *:Interix*:*) - case "$UNAME_MACHINE" in + case ${UNAME_MACHINE} in x86) - echo i586-pc-interix"$UNAME_RELEASE" + echo i586-pc-interix${UNAME_RELEASE} exit ;; authenticamd | genuineintel | EM64T) - echo x86_64-unknown-interix"$UNAME_RELEASE" + echo x86_64-unknown-interix${UNAME_RELEASE} exit ;; IA64) - echo ia64-unknown-interix"$UNAME_RELEASE" + echo ia64-unknown-interix${UNAME_RELEASE} exit ;; esac ;; + [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) + echo i${UNAME_MACHINE}-pc-mks + exit ;; + 8664:Windows_NT:*) + echo x86_64-pc-mks + exit ;; + i*:Windows_NT*:* | Pentium*:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we + # UNAME_MACHINE based on the output of uname instead of i386? + echo i586-pc-interix + exit ;; i*:UWIN*:*) - echo "$UNAME_MACHINE"-pc-uwin + echo ${UNAME_MACHINE}-pc-uwin exit ;; amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) - echo x86_64-pc-cygwin + echo x86_64-unknown-cygwin + exit ;; + p*:CYGWIN*:*) + echo powerpcle-unknown-cygwin exit ;; prep*:SunOS:5.*:*) - echo powerpcle-unknown-solaris2"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" + echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; *:GNU:*:*) # the GNU system - echo "$(echo "$UNAME_MACHINE"|sed -e 's,[-/].*$,,')-unknown-$LIBC$(echo "$UNAME_RELEASE"|sed -e 's,/.*$,,')" + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` exit ;; *:GNU/*:*:*) # other systems with GNU libc and userland - echo "$UNAME_MACHINE-unknown-$(echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]")$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')-$LIBC" + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC} exit ;; - *:Minix:*:*) - echo "$UNAME_MACHINE"-unknown-minix + i*86:Minix:*:*) + echo ${UNAME_MACHINE}-pc-minix exit ;; aarch64:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; aarch64_be:Linux:*:*) UNAME_MACHINE=aarch64_be - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; alpha:Linux:*:*) - case $(sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null) in + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in EV5) UNAME_MACHINE=alphaev5 ;; EV56) UNAME_MACHINE=alphaev56 ;; PCA56) UNAME_MACHINE=alphapca56 ;; @@ -936,178 +927,156 @@ EOF esac objdump --private-headers /bin/sh | grep -q ld.so.1 if test "$?" = 0 ; then LIBC=gnulibc1 ; fi - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; arc:Linux:*:* | arceb:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; arm*:Linux:*:*) - set_cc_for_build + eval $set_cc_for_build if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_EABI__ then - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} else if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_PCS_VFP then - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabi + echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi else - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabihf + echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf fi fi exit ;; avr32*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; cris:Linux:*:*) - echo "$UNAME_MACHINE"-axis-linux-"$LIBC" + echo ${UNAME_MACHINE}-axis-linux-${LIBC} exit ;; crisv32:Linux:*:*) - echo "$UNAME_MACHINE"-axis-linux-"$LIBC" + echo ${UNAME_MACHINE}-axis-linux-${LIBC} exit ;; e2k:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; frv:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; hexagon:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; i*86:Linux:*:*) - echo "$UNAME_MACHINE"-pc-linux-"$LIBC" + echo ${UNAME_MACHINE}-pc-linux-${LIBC} exit ;; ia64:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; k1om:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + loongarch32:Linux:*:* | loongarch64:Linux:*:* | loongarchx32:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; m32r*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; m68*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; mips:Linux:*:* | mips64:Linux:*:*) - set_cc_for_build - IS_GLIBC=0 - test x"${LIBC}" = xgnu && IS_GLIBC=1 - sed 's/^ //' << EOF > "$dummy.c" + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c #undef CPU - #undef mips - #undef mipsel - #undef mips64 - #undef mips64el - #if ${IS_GLIBC} && defined(_ABI64) - LIBCABI=gnuabi64 - #else - #if ${IS_GLIBC} && defined(_ABIN32) - LIBCABI=gnuabin32 - #else - LIBCABI=${LIBC} - #endif - #endif - - #if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 - CPU=mipsisa64r6 - #else - #if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 - CPU=mipsisa32r6 - #else - #if defined(__mips64) - CPU=mips64 - #else - CPU=mips - #endif - #endif - #endif - + #undef ${UNAME_MACHINE} + #undef ${UNAME_MACHINE}el #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - MIPS_ENDIAN=el + CPU=${UNAME_MACHINE}el #else #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - MIPS_ENDIAN= + CPU=${UNAME_MACHINE} #else - MIPS_ENDIAN= + CPU= #endif #endif EOF - eval "$($CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI')" - test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; } + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; } ;; mips64el:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef ${UNAME_MACHINE} + #undef ${UNAME_MACHINE}el + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=${UNAME_MACHINE} + #else + CPU= + #endif + #endif +EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; openrisc*:Linux:*:*) - echo or1k-unknown-linux-"$LIBC" + echo or1k-unknown-linux-${LIBC} exit ;; or32:Linux:*:* | or1k*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; padre:Linux:*:*) - echo sparc-unknown-linux-"$LIBC" + echo sparc-unknown-linux-${LIBC} exit ;; parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-unknown-linux-"$LIBC" + echo hppa64-unknown-linux-${LIBC} exit ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level - case $(grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2) in - PA7*) echo hppa1.1-unknown-linux-"$LIBC" ;; - PA8*) echo hppa2.0-unknown-linux-"$LIBC" ;; - *) echo hppa-unknown-linux-"$LIBC" ;; + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) echo hppa1.1-unknown-linux-${LIBC} ;; + PA8*) echo hppa2.0-unknown-linux-${LIBC} ;; + *) echo hppa-unknown-linux-${LIBC} ;; esac exit ;; ppc64:Linux:*:*) - echo powerpc64-unknown-linux-"$LIBC" + echo powerpc64-unknown-linux-${LIBC} exit ;; ppc:Linux:*:*) - echo powerpc-unknown-linux-"$LIBC" + echo powerpc-unknown-linux-${LIBC} exit ;; ppc64le:Linux:*:*) - echo powerpc64le-unknown-linux-"$LIBC" + echo powerpc64le-unknown-linux-${LIBC} exit ;; ppcle:Linux:*:*) - echo powerpcle-unknown-linux-"$LIBC" + echo powerpcle-unknown-linux-${LIBC} exit ;; riscv32:Linux:*:* | riscv64:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; s390:Linux:*:* | s390x:Linux:*:*) - echo "$UNAME_MACHINE"-ibm-linux-"$LIBC" + echo ${UNAME_MACHINE}-ibm-linux-${LIBC} exit ;; sh64*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; sh*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; sparc:Linux:*:* | sparc64:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; tile*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; vax:Linux:*:*) - echo "$UNAME_MACHINE"-dec-linux-"$LIBC" + echo ${UNAME_MACHINE}-dec-linux-${LIBC} exit ;; x86_64:Linux:*:*) - set_cc_for_build - LIBCABI=$LIBC - if test "$CC_FOR_BUILD" != no_compiler_found; then - if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \ - (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_X32 >/dev/null - then - LIBCABI="$LIBC"x32 - fi - fi - echo "$UNAME_MACHINE"-pc-linux-"$LIBCABI" + echo ${UNAME_MACHINE}-pc-linux-${LIBC} exit ;; xtensa*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. @@ -1121,51 +1090,51 @@ EOF # I am not positive that other SVR4 systems won't match this, # I just have to hope. -- rms. # Use sysv4.2uw... so that sysv4* matches it. - echo "$UNAME_MACHINE"-pc-sysv4.2uw"$UNAME_VERSION" + echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} exit ;; i*86:OS/2:*:*) # If we were able to find `uname', then EMX Unix compatibility # is probably installed. - echo "$UNAME_MACHINE"-pc-os2-emx + echo ${UNAME_MACHINE}-pc-os2-emx exit ;; i*86:XTS-300:*:STOP) - echo "$UNAME_MACHINE"-unknown-stop + echo ${UNAME_MACHINE}-unknown-stop exit ;; i*86:atheos:*:*) - echo "$UNAME_MACHINE"-unknown-atheos + echo ${UNAME_MACHINE}-unknown-atheos exit ;; i*86:syllable:*:*) - echo "$UNAME_MACHINE"-pc-syllable + echo ${UNAME_MACHINE}-pc-syllable exit ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) - echo i386-unknown-lynxos"$UNAME_RELEASE" + echo i386-unknown-lynxos${UNAME_RELEASE} exit ;; i*86:*DOS:*:*) - echo "$UNAME_MACHINE"-pc-msdosdjgpp + echo ${UNAME_MACHINE}-pc-msdosdjgpp exit ;; - i*86:*:4.*:*) - UNAME_REL=$(echo "$UNAME_RELEASE" | sed 's/\/MP$//') + i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) + UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then - echo "$UNAME_MACHINE"-univel-sysv"$UNAME_REL" + echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} else - echo "$UNAME_MACHINE"-pc-sysv"$UNAME_REL" + echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} fi exit ;; i*86:*:5:[678]*) # UnixWare 7.x, OpenUNIX and OpenServer 6. - case $(/bin/uname -X | grep "^Machine") in + case `/bin/uname -X | grep "^Machine"` in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac - echo "$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}" + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} exit ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then - UNAME_REL=$(sed -n 's/.*Version //p' /dev/null >/dev/null ; then - UNAME_REL=$( (/bin/uname -X|grep Release|sed -e 's/.*= //')) + UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ && UNAME_MACHINE=i586 @@ -1173,9 +1142,9 @@ EOF && UNAME_MACHINE=i686 (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ && UNAME_MACHINE=i686 - echo "$UNAME_MACHINE"-pc-sco"$UNAME_REL" + echo ${UNAME_MACHINE}-pc-sco$UNAME_REL else - echo "$UNAME_MACHINE"-pc-sysv32 + echo ${UNAME_MACHINE}-pc-sysv32 fi exit ;; pc:*:*:*) @@ -1195,9 +1164,9 @@ EOF exit ;; i860:*:4.*:*) # i860-SVR4 if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then - echo i860-stardent-sysv"$UNAME_RELEASE" # Stardent Vistra i860-SVR4 + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. - echo i860-unknown-sysv"$UNAME_RELEASE" # Unknown i860-SVR4 + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 fi exit ;; mini*:CTIX:SYS*5:*) @@ -1215,41 +1184,41 @@ EOF 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ - && OS_REL=.$(sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid) + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4; exit; } ;; NCR*:*:4.2:* | MPRAS*:*:4.2:*) OS_REL='.3' test -r /etc/.relid \ - && OS_REL=.$(sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid) + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ - && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) - echo m68k-unknown-lynxos"$UNAME_RELEASE" + echo m68k-unknown-lynxos${UNAME_RELEASE} exit ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 exit ;; TSUNAMI:LynxOS:2.*:*) - echo sparc-unknown-lynxos"$UNAME_RELEASE" + echo sparc-unknown-lynxos${UNAME_RELEASE} exit ;; rs6000:LynxOS:2.*:*) - echo rs6000-unknown-lynxos"$UNAME_RELEASE" + echo rs6000-unknown-lynxos${UNAME_RELEASE} exit ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) - echo powerpc-unknown-lynxos"$UNAME_RELEASE" + echo powerpc-unknown-lynxos${UNAME_RELEASE} exit ;; SM[BE]S:UNIX_SV:*:*) - echo mips-dde-sysv"$UNAME_RELEASE" + echo mips-dde-sysv${UNAME_RELEASE} exit ;; RM*:ReliantUNIX-*:*:*) echo mips-sni-sysv4 @@ -1259,8 +1228,8 @@ EOF exit ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then - UNAME_MACHINE=$( (uname -p) 2>/dev/null) - echo "$UNAME_MACHINE"-sni-sysv4 + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 else echo ns32k-sni-sysv fi @@ -1280,23 +1249,23 @@ EOF exit ;; i*86:VOS:*:*) # From Paul.Green@stratus.com. - echo "$UNAME_MACHINE"-stratus-vos + echo ${UNAME_MACHINE}-stratus-vos exit ;; *:VOS:*:*) # From Paul.Green@stratus.com. echo hppa1.1-stratus-vos exit ;; mc68*:A/UX:*:*) - echo m68k-apple-aux"$UNAME_RELEASE" + echo m68k-apple-aux${UNAME_RELEASE} exit ;; news*:NEWS-OS:6*:*) echo mips-sony-newsos6 exit ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) - if test -d /usr/nec; then - echo mips-nec-sysv"$UNAME_RELEASE" + if [ -d /usr/nec ]; then + echo mips-nec-sysv${UNAME_RELEASE} else - echo mips-unknown-sysv"$UNAME_RELEASE" + echo mips-unknown-sysv${UNAME_RELEASE} fi exit ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. @@ -1315,97 +1284,80 @@ EOF echo x86_64-unknown-haiku exit ;; SX-4:SUPER-UX:*:*) - echo sx4-nec-superux"$UNAME_RELEASE" + echo sx4-nec-superux${UNAME_RELEASE} exit ;; SX-5:SUPER-UX:*:*) - echo sx5-nec-superux"$UNAME_RELEASE" + echo sx5-nec-superux${UNAME_RELEASE} exit ;; SX-6:SUPER-UX:*:*) - echo sx6-nec-superux"$UNAME_RELEASE" + echo sx6-nec-superux${UNAME_RELEASE} exit ;; SX-7:SUPER-UX:*:*) - echo sx7-nec-superux"$UNAME_RELEASE" + echo sx7-nec-superux${UNAME_RELEASE} exit ;; SX-8:SUPER-UX:*:*) - echo sx8-nec-superux"$UNAME_RELEASE" + echo sx8-nec-superux${UNAME_RELEASE} exit ;; SX-8R:SUPER-UX:*:*) - echo sx8r-nec-superux"$UNAME_RELEASE" + echo sx8r-nec-superux${UNAME_RELEASE} exit ;; SX-ACE:SUPER-UX:*:*) - echo sxace-nec-superux"$UNAME_RELEASE" + echo sxace-nec-superux${UNAME_RELEASE} exit ;; Power*:Rhapsody:*:*) - echo powerpc-apple-rhapsody"$UNAME_RELEASE" + echo powerpc-apple-rhapsody${UNAME_RELEASE} exit ;; *:Rhapsody:*:*) - echo "$UNAME_MACHINE"-apple-rhapsody"$UNAME_RELEASE" - exit ;; - arm64:Darwin:*:*) - echo aarch64-apple-darwin"$UNAME_RELEASE" + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} exit ;; *:Darwin:*:*) - UNAME_PROCESSOR=$(uname -p) - case $UNAME_PROCESSOR in - unknown) UNAME_PROCESSOR=powerpc ;; - esac - if command -v xcode-select > /dev/null 2> /dev/null && \ - ! xcode-select --print-path > /dev/null 2> /dev/null ; then - # Avoid executing cc if there is no toolchain installed as - # cc will be a stub that puts up a graphical alert - # prompting the user to install developer tools. - CC_FOR_BUILD=no_compiler_found - else - set_cc_for_build + UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown + eval $set_cc_for_build + if test "$UNAME_PROCESSOR" = unknown ; then + UNAME_PROCESSOR=powerpc fi - if test "$CC_FOR_BUILD" != no_compiler_found; then - if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_64BIT_ARCH >/dev/null - then - case $UNAME_PROCESSOR in - i386) UNAME_PROCESSOR=x86_64 ;; - powerpc) UNAME_PROCESSOR=powerpc64 ;; - esac - fi - # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc - if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ - (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_PPC >/dev/null - then - UNAME_PROCESSOR=powerpc + if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then + if [ "$CC_FOR_BUILD" != no_compiler_found ]; then + if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + case $UNAME_PROCESSOR in + i386) UNAME_PROCESSOR=x86_64 ;; + powerpc) UNAME_PROCESSOR=powerpc64 ;; + esac + fi fi elif test "$UNAME_PROCESSOR" = i386 ; then - # uname -m returns i386 or x86_64 - UNAME_PROCESSOR=$UNAME_MACHINE + # Avoid executing cc on OS X 10.9, as it ships with a stub + # that puts up a graphical alert prompting to install + # developer tools. Any system running Mac OS X 10.7 or + # later (Darwin 11 and later) is required to have a 64-bit + # processor. This is not true of the ARM version of Darwin + # that Apple uses in portable devices. + UNAME_PROCESSOR=x86_64 fi - echo "$UNAME_PROCESSOR"-apple-darwin"$UNAME_RELEASE" + echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} exit ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) - UNAME_PROCESSOR=$(uname -p) + UNAME_PROCESSOR=`uname -p` if test "$UNAME_PROCESSOR" = x86; then UNAME_PROCESSOR=i386 UNAME_MACHINE=pc fi - echo "$UNAME_PROCESSOR"-"$UNAME_MACHINE"-nto-qnx"$UNAME_RELEASE" + echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} exit ;; *:QNX:*:4*) echo i386-pc-qnx exit ;; - NEO-*:NONSTOP_KERNEL:*:*) - echo neo-tandem-nsk"$UNAME_RELEASE" + NEO-?:NONSTOP_KERNEL:*:*) + echo neo-tandem-nsk${UNAME_RELEASE} exit ;; NSE-*:NONSTOP_KERNEL:*:*) - echo nse-tandem-nsk"$UNAME_RELEASE" - exit ;; - NSR-*:NONSTOP_KERNEL:*:*) - echo nsr-tandem-nsk"$UNAME_RELEASE" + echo nse-tandem-nsk${UNAME_RELEASE} exit ;; - NSV-*:NONSTOP_KERNEL:*:*) - echo nsv-tandem-nsk"$UNAME_RELEASE" - exit ;; - NSX-*:NONSTOP_KERNEL:*:*) - echo nsx-tandem-nsk"$UNAME_RELEASE" + NSR-?:NONSTOP_KERNEL:*:*) + echo nsr-tandem-nsk${UNAME_RELEASE} exit ;; *:NonStop-UX:*:*) echo mips-compaq-nonstopux @@ -1414,19 +1366,18 @@ EOF echo bs2000-siemens-sysv exit ;; DS/*:UNIX_System_V:*:*) - echo "$UNAME_MACHINE"-"$UNAME_SYSTEM"-"$UNAME_RELEASE" + echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} exit ;; *:Plan9:*:*) # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 # operating systems. - # shellcheck disable=SC2154 if test "$cputype" = 386; then UNAME_MACHINE=i386 else UNAME_MACHINE="$cputype" fi - echo "$UNAME_MACHINE"-unknown-plan9 + echo ${UNAME_MACHINE}-unknown-plan9 exit ;; *:TOPS-10:*:*) echo pdp10-unknown-tops10 @@ -1447,14 +1398,14 @@ EOF echo pdp10-unknown-its exit ;; SEI:*:*:SEIUX) - echo mips-sei-seiux"$UNAME_RELEASE" + echo mips-sei-seiux${UNAME_RELEASE} exit ;; *:DragonFly:*:*) - echo "$UNAME_MACHINE"-unknown-dragonfly"$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')" + echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` exit ;; *:*VMS:*:*) - UNAME_MACHINE=$( (uname -p) 2>/dev/null) - case "$UNAME_MACHINE" in + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case "${UNAME_MACHINE}" in A*) echo alpha-dec-vms ; exit ;; I*) echo ia64-dec-vms ; exit ;; V*) echo vax-dec-vms ; exit ;; @@ -1463,190 +1414,32 @@ EOF echo i386-pc-xenix exit ;; i*86:skyos:*:*) - echo "$UNAME_MACHINE"-pc-skyos"$(echo "$UNAME_RELEASE" | sed -e 's/ .*$//')" + echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE} | sed -e 's/ .*$//'` exit ;; i*86:rdos:*:*) - echo "$UNAME_MACHINE"-pc-rdos + echo ${UNAME_MACHINE}-pc-rdos exit ;; i*86:AROS:*:*) - echo "$UNAME_MACHINE"-pc-aros + echo ${UNAME_MACHINE}-pc-aros exit ;; x86_64:VMkernel:*:*) - echo "$UNAME_MACHINE"-unknown-esx + echo ${UNAME_MACHINE}-unknown-esx exit ;; amd64:Isilon\ OneFS:*:*) echo x86_64-unknown-onefs exit ;; - *:Unleashed:*:*) - echo "$UNAME_MACHINE"-unknown-unleashed"$UNAME_RELEASE" - exit ;; -esac - -# No uname command or uname output not recognized. -set_cc_for_build -cat > "$dummy.c" < -#include -#endif -#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) -#if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) -#include -#if defined(_SIZE_T_) || defined(SIGLOST) -#include -#endif -#endif -#endif -main () -{ -#if defined (sony) -#if defined (MIPSEB) - /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, - I don't know.... */ - printf ("mips-sony-bsd\n"); exit (0); -#else -#include - printf ("m68k-sony-newsos%s\n", -#ifdef NEWSOS4 - "4" -#else - "" -#endif - ); exit (0); -#endif -#endif - -#if defined (NeXT) -#if !defined (__ARCHITECTURE__) -#define __ARCHITECTURE__ "m68k" -#endif - int version; - version=$( (hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null); - if (version < 4) - printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); - else - printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); - exit (0); -#endif - -#if defined (MULTIMAX) || defined (n16) -#if defined (UMAXV) - printf ("ns32k-encore-sysv\n"); exit (0); -#else -#if defined (CMU) - printf ("ns32k-encore-mach\n"); exit (0); -#else - printf ("ns32k-encore-bsd\n"); exit (0); -#endif -#endif -#endif - -#if defined (__386BSD__) - printf ("i386-pc-bsd\n"); exit (0); -#endif - -#if defined (sequent) -#if defined (i386) - printf ("i386-sequent-dynix\n"); exit (0); -#endif -#if defined (ns32000) - printf ("ns32k-sequent-dynix\n"); exit (0); -#endif -#endif - -#if defined (_SEQUENT_) - struct utsname un; - - uname(&un); - if (strncmp(un.version, "V2", 2) == 0) { - printf ("i386-sequent-ptx2\n"); exit (0); - } - if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ - printf ("i386-sequent-ptx1\n"); exit (0); - } - printf ("i386-sequent-ptx\n"); exit (0); -#endif - -#if defined (vax) -#if !defined (ultrix) -#include -#if defined (BSD) -#if BSD == 43 - printf ("vax-dec-bsd4.3\n"); exit (0); -#else -#if BSD == 199006 - printf ("vax-dec-bsd4.3reno\n"); exit (0); -#else - printf ("vax-dec-bsd\n"); exit (0); -#endif -#endif -#else - printf ("vax-dec-bsd\n"); exit (0); -#endif -#else -#if defined(_SIZE_T_) || defined(SIGLOST) - struct utsname un; - uname (&un); - printf ("vax-dec-ultrix%s\n", un.release); exit (0); -#else - printf ("vax-dec-ultrix\n"); exit (0); -#endif -#endif -#endif -#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) -#if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) -#if defined(_SIZE_T_) || defined(SIGLOST) - struct utsname *un; - uname (&un); - printf ("mips-dec-ultrix%s\n", un.release); exit (0); -#else - printf ("mips-dec-ultrix\n"); exit (0); -#endif -#endif -#endif - -#if defined (alliant) && defined (i860) - printf ("i860-alliant-bsd\n"); exit (0); -#endif - - exit (1); -} -EOF - -$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=$($dummy) && - { echo "$SYSTEM_NAME"; exit; } - -# Apollos put the system type in the environment. -test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; } - -echo "$0: unable to guess system type" >&2 - -case "$UNAME_MACHINE:$UNAME_SYSTEM" in - mips:Linux | mips64:Linux) - # If we got here on MIPS GNU/Linux, output extra information. - cat >&2 <&2 <&2 </dev/null || echo unknown) -uname -r = $( (uname -r) 2>/dev/null || echo unknown) -uname -s = $( (uname -s) 2>/dev/null || echo unknown) -uname -v = $( (uname -v) 2>/dev/null || echo unknown) +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` -/usr/bin/uname -p = $( (/usr/bin/uname -p) 2>/dev/null) -/bin/uname -X = $( (/bin/uname -X) 2>/dev/null) +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` -hostinfo = $( (hostinfo) 2>/dev/null) -/bin/universe = $( (/bin/universe) 2>/dev/null) -/usr/bin/arch -k = $( (/usr/bin/arch -k) 2>/dev/null) -/bin/arch = $( (/bin/arch) 2>/dev/null) -/usr/bin/oslevel = $( (/usr/bin/oslevel) 2>/dev/null) -/usr/convex/getsysinfo = $( (/usr/convex/getsysinfo) 2>/dev/null) +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` -UNAME_MACHINE = "$UNAME_MACHINE" -UNAME_RELEASE = "$UNAME_RELEASE" -UNAME_SYSTEM = "$UNAME_SYSTEM" -UNAME_VERSION = "$UNAME_VERSION" +UNAME_MACHINE = ${UNAME_MACHINE} +UNAME_RELEASE = ${UNAME_RELEASE} +UNAME_SYSTEM = ${UNAME_SYSTEM} +UNAME_VERSION = ${UNAME_VERSION} EOF -fi exit 1 # Local variables: -# eval: (add-hook 'before-save-hook 'time-stamp) +# eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" diff --git a/bash-5.1/support/config.sub b/bash-5.1/support/config.sub index c874b7a9..9d3787b4 100755 --- a/bash-5.1/support/config.sub +++ b/bash-5.1/support/config.sub @@ -1,8 +1,8 @@ #! /bin/sh # Configuration validation subroutine script. -# Copyright 1992-2020 Free Software Foundation, Inc. +# Copyright 1992-2016 Free Software Foundation, Inc. -timestamp='2020-11-07' +timestamp='2016-09-05' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -15,7 +15,7 @@ timestamp='2020-11-07' # General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program; if not, see . +# along with this program; if not, see . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a @@ -33,7 +33,7 @@ timestamp='2020-11-07' # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: -# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub +# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases @@ -50,14 +50,14 @@ timestamp='2020-11-07' # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. -me=$(echo "$0" | sed -e 's,.*/,,') +me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS Canonicalize a configuration name. -Options: +Operation modes: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit @@ -67,7 +67,7 @@ Report bugs and patches to ." version="\ GNU config.sub ($timestamp) -Copyright 1992-2020 Free Software Foundation, Inc. +Copyright 1992-2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -89,12 +89,12 @@ while test $# -gt 0 ; do - ) # Use stdin as input. break ;; -* ) - echo "$me: invalid option $1$help" >&2 + echo "$me: invalid option $1$help" exit 1 ;; *local*) # First pass through any local machine types. - echo "$1" + echo $1 exit ;; * ) @@ -110,1167 +110,1244 @@ case $# in exit 1;; esac -# Split fields of configuration type -# shellcheck disable=SC2162 -IFS="-" read field1 field2 field3 field4 <&2 - exit 1 +### Let's recognize common machines as not being operating systems so +### that things like config.sub decstation-3100 work. We also +### recognize some manufacturers as not being operating systems, so we +### can provide default operating systems below. +case $os in + -sun*os*) + # Prevent following clause from handling this invalid input. ;; - *-*-*-*) - basic_machine=$field1-$field2 - basic_os=$field3-$field4 + -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ + -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ + -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ + -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ + -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ + -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ + -apple | -axis | -knuth | -cray | -microblaze*) + os= + basic_machine=$1 ;; - *-*-*) - # Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two - # parts - maybe_os=$field2-$field3 - case $maybe_os in - nto-qnx* | linux-* | uclinux-uclibc* \ - | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \ - | netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \ - | storm-chaos* | os2-emx* | rtmk-nova*) - basic_machine=$field1 - basic_os=$maybe_os - ;; - android-linux) - basic_machine=$field1-unknown - basic_os=linux-android - ;; - *) - basic_machine=$field1-$field2 - basic_os=$field3 - ;; - esac + -bluegene*) + os=-cnk ;; - *-*) - # A lone config we happen to match not fitting any pattern - case $field1-$field2 in - decstation-3100) - basic_machine=mips-dec - basic_os= - ;; - *-*) - # Second component is usually, but not always the OS - case $field2 in - # Prevent following clause from handling this valid os - sun*os*) - basic_machine=$field1 - basic_os=$field2 - ;; - # Manufacturers - dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \ - | att* | 7300* | 3300* | delta* | motorola* | sun[234]* \ - | unicom* | ibm* | next | hp | isi* | apollo | altos* \ - | convergent* | ncr* | news | 32* | 3600* | 3100* \ - | hitachi* | c[123]* | convex* | sun | crds | omron* | dg \ - | ultra | tti* | harris | dolphin | highlevel | gould \ - | cbm | ns | masscomp | apple | axis | knuth | cray \ - | microblaze* | sim | cisco \ - | oki | wec | wrs | winbond) - basic_machine=$field1-$field2 - basic_os= - ;; - *) - basic_machine=$field1 - basic_os=$field2 - ;; - esac - ;; - esac + -sim | -cisco | -oki | -wec | -winbond) + os= + basic_machine=$1 ;; - *) - # Convert single-component short-hands not valid as part of - # multi-component configurations. - case $field1 in - 386bsd) - basic_machine=i386-pc - basic_os=bsd - ;; - a29khif) - basic_machine=a29k-amd - basic_os=udi - ;; - adobe68k) - basic_machine=m68010-adobe - basic_os=scout - ;; - alliant) - basic_machine=fx80-alliant - basic_os= - ;; - altos | altos3068) - basic_machine=m68k-altos - basic_os= - ;; - am29k) - basic_machine=a29k-none - basic_os=bsd - ;; - amdahl) - basic_machine=580-amdahl - basic_os=sysv - ;; - amiga) - basic_machine=m68k-unknown - basic_os= - ;; - amigaos | amigados) - basic_machine=m68k-unknown - basic_os=amigaos - ;; - amigaunix | amix) - basic_machine=m68k-unknown - basic_os=sysv4 - ;; - apollo68) - basic_machine=m68k-apollo - basic_os=sysv - ;; - apollo68bsd) - basic_machine=m68k-apollo - basic_os=bsd - ;; - aros) - basic_machine=i386-pc - basic_os=aros - ;; - aux) - basic_machine=m68k-apple - basic_os=aux - ;; - balance) - basic_machine=ns32k-sequent - basic_os=dynix - ;; - blackfin) - basic_machine=bfin-unknown - basic_os=linux - ;; - cegcc) - basic_machine=arm-unknown - basic_os=cegcc - ;; - convex-c1) - basic_machine=c1-convex - basic_os=bsd - ;; - convex-c2) - basic_machine=c2-convex - basic_os=bsd - ;; - convex-c32) - basic_machine=c32-convex - basic_os=bsd - ;; - convex-c34) - basic_machine=c34-convex - basic_os=bsd - ;; - convex-c38) - basic_machine=c38-convex - basic_os=bsd - ;; - cray) - basic_machine=j90-cray - basic_os=unicos - ;; - crds | unos) - basic_machine=m68k-crds - basic_os= - ;; - da30) - basic_machine=m68k-da30 - basic_os= - ;; - decstation | pmax | pmin | dec3100 | decstatn) - basic_machine=mips-dec - basic_os= - ;; - delta88) - basic_machine=m88k-motorola - basic_os=sysv3 - ;; - dicos) - basic_machine=i686-pc - basic_os=dicos - ;; - djgpp) - basic_machine=i586-pc - basic_os=msdosdjgpp - ;; - ebmon29k) - basic_machine=a29k-amd - basic_os=ebmon - ;; - es1800 | OSE68k | ose68k | ose | OSE) - basic_machine=m68k-ericsson - basic_os=ose - ;; - gmicro) - basic_machine=tron-gmicro - basic_os=sysv - ;; - go32) - basic_machine=i386-pc - basic_os=go32 - ;; - h8300hms) - basic_machine=h8300-hitachi - basic_os=hms - ;; - h8300xray) - basic_machine=h8300-hitachi - basic_os=xray - ;; - h8500hms) - basic_machine=h8500-hitachi - basic_os=hms - ;; - harris) - basic_machine=m88k-harris - basic_os=sysv3 - ;; - hp300 | hp300hpux) - basic_machine=m68k-hp - basic_os=hpux - ;; - hp300bsd) - basic_machine=m68k-hp - basic_os=bsd - ;; - hppaosf) - basic_machine=hppa1.1-hp - basic_os=osf - ;; - hppro) - basic_machine=hppa1.1-hp - basic_os=proelf - ;; - i386mach) - basic_machine=i386-mach - basic_os=mach - ;; - isi68 | isi) - basic_machine=m68k-isi - basic_os=sysv - ;; - m68knommu) - basic_machine=m68k-unknown - basic_os=linux - ;; - magnum | m3230) - basic_machine=mips-mips - basic_os=sysv - ;; - merlin) - basic_machine=ns32k-utek - basic_os=sysv - ;; - mingw64) - basic_machine=x86_64-pc - basic_os=mingw64 - ;; - mingw32) - basic_machine=i686-pc - basic_os=mingw32 - ;; - mingw32ce) - basic_machine=arm-unknown - basic_os=mingw32ce - ;; - monitor) - basic_machine=m68k-rom68k - basic_os=coff - ;; - morphos) - basic_machine=powerpc-unknown - basic_os=morphos - ;; - moxiebox) - basic_machine=moxie-unknown - basic_os=moxiebox - ;; - msdos) - basic_machine=i386-pc - basic_os=msdos - ;; - msys) - basic_machine=i686-pc - basic_os=msys - ;; - mvs) - basic_machine=i370-ibm - basic_os=mvs - ;; - nacl) - basic_machine=le32-unknown - basic_os=nacl - ;; - ncr3000) - basic_machine=i486-ncr - basic_os=sysv4 - ;; - netbsd386) - basic_machine=i386-pc - basic_os=netbsd - ;; - netwinder) - basic_machine=armv4l-rebel - basic_os=linux - ;; - news | news700 | news800 | news900) - basic_machine=m68k-sony - basic_os=newsos - ;; - news1000) - basic_machine=m68030-sony - basic_os=newsos - ;; - necv70) - basic_machine=v70-nec - basic_os=sysv - ;; - nh3000) - basic_machine=m68k-harris - basic_os=cxux - ;; - nh[45]000) - basic_machine=m88k-harris - basic_os=cxux - ;; - nindy960) - basic_machine=i960-intel - basic_os=nindy - ;; - mon960) - basic_machine=i960-intel - basic_os=mon960 - ;; - nonstopux) - basic_machine=mips-compaq - basic_os=nonstopux - ;; - os400) - basic_machine=powerpc-ibm - basic_os=os400 - ;; - OSE68000 | ose68000) - basic_machine=m68000-ericsson - basic_os=ose - ;; - os68k) - basic_machine=m68k-none - basic_os=os68k - ;; - paragon) - basic_machine=i860-intel - basic_os=osf - ;; - parisc) - basic_machine=hppa-unknown - basic_os=linux - ;; - psp) - basic_machine=mipsallegrexel-sony - basic_os=psp - ;; - pw32) - basic_machine=i586-unknown - basic_os=pw32 - ;; - rdos | rdos64) - basic_machine=x86_64-pc - basic_os=rdos - ;; - rdos32) - basic_machine=i386-pc - basic_os=rdos - ;; - rom68k) - basic_machine=m68k-rom68k - basic_os=coff - ;; - sa29200) - basic_machine=a29k-amd - basic_os=udi - ;; - sei) - basic_machine=mips-sei - basic_os=seiux - ;; - sequent) - basic_machine=i386-sequent - basic_os= - ;; - sps7) - basic_machine=m68k-bull - basic_os=sysv2 - ;; - st2000) - basic_machine=m68k-tandem - basic_os= - ;; - stratus) - basic_machine=i860-stratus - basic_os=sysv4 - ;; - sun2) - basic_machine=m68000-sun - basic_os= - ;; - sun2os3) - basic_machine=m68000-sun - basic_os=sunos3 - ;; - sun2os4) - basic_machine=m68000-sun - basic_os=sunos4 - ;; - sun3) - basic_machine=m68k-sun - basic_os= - ;; - sun3os3) - basic_machine=m68k-sun - basic_os=sunos3 - ;; - sun3os4) - basic_machine=m68k-sun - basic_os=sunos4 - ;; - sun4) - basic_machine=sparc-sun - basic_os= - ;; - sun4os3) - basic_machine=sparc-sun - basic_os=sunos3 - ;; - sun4os4) - basic_machine=sparc-sun - basic_os=sunos4 - ;; - sun4sol2) - basic_machine=sparc-sun - basic_os=solaris2 - ;; - sun386 | sun386i | roadrunner) - basic_machine=i386-sun - basic_os= - ;; - sv1) - basic_machine=sv1-cray - basic_os=unicos - ;; - symmetry) - basic_machine=i386-sequent - basic_os=dynix - ;; - t3e) - basic_machine=alphaev5-cray - basic_os=unicos - ;; - t90) - basic_machine=t90-cray - basic_os=unicos - ;; - toad1) - basic_machine=pdp10-xkl - basic_os=tops20 - ;; - tpf) - basic_machine=s390x-ibm - basic_os=tpf - ;; - udi29k) - basic_machine=a29k-amd - basic_os=udi - ;; - ultra3) - basic_machine=a29k-nyu - basic_os=sym1 - ;; - v810 | necv810) - basic_machine=v810-nec - basic_os=none - ;; - vaxv) - basic_machine=vax-dec - basic_os=sysv - ;; - vms) - basic_machine=vax-dec - basic_os=vms - ;; - vsta) - basic_machine=i386-pc - basic_os=vsta - ;; - vxworks960) - basic_machine=i960-wrs - basic_os=vxworks - ;; - vxworks68) - basic_machine=m68k-wrs - basic_os=vxworks - ;; - vxworks29k) - basic_machine=a29k-wrs - basic_os=vxworks - ;; - xbox) - basic_machine=i686-pc - basic_os=mingw32 - ;; - ymp) - basic_machine=ymp-cray - basic_os=unicos - ;; - *) - basic_machine=$1 - basic_os= - ;; - esac + -scout) + ;; + -wrs) + os=-vxworks + basic_machine=$1 + ;; + -chorusos*) + os=-chorusos + basic_machine=$1 + ;; + -chorusrdb) + os=-chorusrdb + basic_machine=$1 + ;; + -hiux*) + os=-hiuxwe2 + ;; + -sco6) + os=-sco5v6 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5) + os=-sco3.2v5 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco4) + os=-sco3.2v4 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2.[4-9]*) + os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2v[4-9]*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco*) + os=-sco3.2v2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -udk*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -isc) + os=-isc2.2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -clix*) + basic_machine=clipper-intergraph + ;; + -isc*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -lynx*178) + os=-lynxos178 + ;; + -lynx*5) + os=-lynxos5 + ;; + -lynx*) + os=-lynxos + ;; + -ptx*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + ;; + -windowsnt*) + os=`echo $os | sed -e 's/windowsnt/winnt/'` + ;; + -psos*) + os=-psos + ;; + -mint | -mint[0-9]*) + basic_machine=m68k-atari + os=-mint ;; esac -# Decode 1-component or ad-hoc basic machines +# Decode aliases for certain CPU-COMPANY combinations. case $basic_machine in - # Here we handle the default manufacturer of certain CPU types. It is in - # some cases the only manufacturer, in others, it is the most popular. - w89k) - cpu=hppa1.1 - vendor=winbond + # Recognize the basic CPU types without company name. + # Some are omitted here because they have special meanings below. + 1750a | 580 \ + | a29k \ + | aarch64 | aarch64_be \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ + | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ + | am33_2.0 \ + | arc | arceb \ + | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \ + | avr | avr32 \ + | ba \ + | be32 | be64 \ + | bfin \ + | c4x | c8051 | clipper \ + | d10v | d30v | dlx | dsp16xx \ + | e2k | epiphany \ + | fido | fr30 | frv | ft32 \ + | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | hexagon \ + | i370 | i860 | i960 | ia64 \ + | ip2k | iq2000 \ + | k1om \ + | le32 | le64 \ + | lm32 \ + | m32c | m32r | m32rle | m68000 | m68k | m88k \ + | maxq | mb | microblaze | microblazeel | mcore | mep | metag \ + | loongarch32 | loongarch64 \ + | mips | mipsbe | mipseb | mipsel | mipsle \ + | mips16 \ + | mips64 | mips64el \ + | mips64octeon | mips64octeonel \ + | mips64orion | mips64orionel \ + | mips64r5900 | mips64r5900el \ + | mips64vr | mips64vrel \ + | mips64vr4100 | mips64vr4100el \ + | mips64vr4300 | mips64vr4300el \ + | mips64vr5000 | mips64vr5000el \ + | mips64vr5900 | mips64vr5900el \ + | mipsisa32 | mipsisa32el \ + | mipsisa32r2 | mipsisa32r2el \ + | mipsisa32r6 | mipsisa32r6el \ + | mipsisa64 | mipsisa64el \ + | mipsisa64r2 | mipsisa64r2el \ + | mipsisa64r6 | mipsisa64r6el \ + | mipsisa64sb1 | mipsisa64sb1el \ + | mipsisa64sr71k | mipsisa64sr71kel \ + | mipsr5900 | mipsr5900el \ + | mipstx39 | mipstx39el \ + | mn10200 | mn10300 \ + | moxie \ + | mt \ + | msp430 \ + | nds32 | nds32le | nds32be \ + | nios | nios2 | nios2eb | nios2el \ + | ns16k | ns32k \ + | open8 | or1k | or1knd | or32 \ + | pdp10 | pdp11 | pj | pjl \ + | powerpc | powerpc64 | powerpc64le | powerpcle \ + | pyramid \ + | riscv32 | riscv64 \ + | rl78 | rx \ + | score \ + | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[234]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ + | sh64 | sh64le \ + | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ + | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ + | spu \ + | tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \ + | ubicom32 \ + | v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \ + | visium \ + | we32k \ + | x86 | xc16x | xstormy16 | xtensa \ + | z8k | z80) + basic_machine=$basic_machine-unknown + ;; + c54x) + basic_machine=tic54x-unknown + ;; + c55x) + basic_machine=tic55x-unknown + ;; + c6x) + basic_machine=tic6x-unknown ;; - op50n) - cpu=hppa1.1 - vendor=oki + leon|leon[3-9]) + basic_machine=sparc-$basic_machine ;; - op60c) - cpu=hppa1.1 - vendor=oki + m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip) + basic_machine=$basic_machine-unknown + os=-none ;; - ibm*) - cpu=i370 - vendor=ibm + m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) ;; - orion105) - cpu=clipper - vendor=highlevel + ms1) + basic_machine=mt-unknown ;; - mac | mpw | mac-mpw) - cpu=m68k - vendor=apple + + strongarm | thumb | xscale) + basic_machine=arm-unknown ;; - pmac | pmac-mpw) - cpu=powerpc - vendor=apple + xgate) + basic_machine=$basic_machine-unknown + os=-none + ;; + xscaleeb) + basic_machine=armeb-unknown ;; + xscaleel) + basic_machine=armel-unknown + ;; + + # We use `pc' rather than `unknown' + # because (1) that's what they normally are, and + # (2) the word "unknown" tends to confuse beginning users. + i*86 | x86_64) + basic_machine=$basic_machine-pc + ;; + # Object if more than one company name word. + *-*-*) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; + # Recognize the basic CPU types with company name. + 580-* \ + | a29k-* \ + | aarch64-* | aarch64_be-* \ + | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ + | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \ + | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ + | avr-* | avr32-* \ + | ba-* \ + | be32-* | be64-* \ + | bfin-* | bs2000-* \ + | c[123]* | c30-* | [cjt]90-* | c4x-* \ + | c8051-* | clipper-* | craynv-* | cydra-* \ + | d10v-* | d30v-* | dlx-* \ + | e2k-* | elxsi-* \ + | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ + | h8300-* | h8500-* \ + | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ + | hexagon-* \ + | i*86-* | i860-* | i960-* | ia64-* \ + | ip2k-* | iq2000-* \ + | k1om-* \ + | le32-* | le64-* \ + | lm32-* \ + | m32c-* | m32r-* | m32rle-* \ + | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ + | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \ + | microblaze-* | microblazeel-* \ + | loongarch32-* | loongarch64-* \ + | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ + | mips16-* \ + | mips64-* | mips64el-* \ + | mips64octeon-* | mips64octeonel-* \ + | mips64orion-* | mips64orionel-* \ + | mips64r5900-* | mips64r5900el-* \ + | mips64vr-* | mips64vrel-* \ + | mips64vr4100-* | mips64vr4100el-* \ + | mips64vr4300-* | mips64vr4300el-* \ + | mips64vr5000-* | mips64vr5000el-* \ + | mips64vr5900-* | mips64vr5900el-* \ + | mipsisa32-* | mipsisa32el-* \ + | mipsisa32r2-* | mipsisa32r2el-* \ + | mipsisa32r6-* | mipsisa32r6el-* \ + | mipsisa64-* | mipsisa64el-* \ + | mipsisa64r2-* | mipsisa64r2el-* \ + | mipsisa64r6-* | mipsisa64r6el-* \ + | mipsisa64sb1-* | mipsisa64sb1el-* \ + | mipsisa64sr71k-* | mipsisa64sr71kel-* \ + | mipsr5900-* | mipsr5900el-* \ + | mipstx39-* | mipstx39el-* \ + | mmix-* \ + | mt-* \ + | msp430-* \ + | nds32-* | nds32le-* | nds32be-* \ + | nios-* | nios2-* | nios2eb-* | nios2el-* \ + | none-* | np1-* | ns16k-* | ns32k-* \ + | open8-* \ + | or1k*-* \ + | orion-* \ + | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ + | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \ + | pyramid-* \ + | riscv32-* | riscv64-* \ + | rl78-* | romp-* | rs6000-* | rx-* \ + | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ + | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ + | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ + | sparclite-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx*-* \ + | tahoe-* \ + | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ + | tile*-* \ + | tron-* \ + | ubicom32-* \ + | v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \ + | vax-* \ + | visium-* \ + | we32k-* \ + | x86-* | x86_64-* | xc16x-* | xps100-* \ + | xstormy16-* | xtensa*-* \ + | ymp-* \ + | z8k-* | z80-*) + ;; + # Recognize the basic CPU types without company name, with glob match. + xtensa*) + basic_machine=$basic_machine-unknown + ;; # Recognize the various machine names and aliases which stand # for a CPU type and a company and sometimes even an OS. + 386bsd) + basic_machine=i386-unknown + os=-bsd + ;; 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) - cpu=m68000 - vendor=att + basic_machine=m68000-att ;; 3b*) - cpu=we32k - vendor=att + basic_machine=we32k-att + ;; + a29khif) + basic_machine=a29k-amd + os=-udi + ;; + abacus) + basic_machine=abacus-unknown + ;; + adobe68k) + basic_machine=m68010-adobe + os=-scout + ;; + alliant | fx80) + basic_machine=fx80-alliant + ;; + altos | altos3068) + basic_machine=m68k-altos + ;; + am29k) + basic_machine=a29k-none + os=-bsd + ;; + amd64) + basic_machine=x86_64-pc + ;; + amd64-*) + basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + amdahl) + basic_machine=580-amdahl + os=-sysv + ;; + amiga | amiga-*) + basic_machine=m68k-unknown + ;; + amigaos | amigados) + basic_machine=m68k-unknown + os=-amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + os=-sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + os=-sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + os=-bsd + ;; + aros) + basic_machine=i386-pc + os=-aros + ;; + asmjs) + basic_machine=asmjs-unknown + ;; + aux) + basic_machine=m68k-apple + os=-aux + ;; + balance) + basic_machine=ns32k-sequent + os=-dynix + ;; + blackfin) + basic_machine=bfin-unknown + os=-linux + ;; + blackfin-*) + basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'` + os=-linux ;; bluegene*) - cpu=powerpc - vendor=ibm - basic_os=cnk + basic_machine=powerpc-ibm + os=-cnk + ;; + c54x-*) + basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + c55x-*) + basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + c6x-*) + basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + c90) + basic_machine=c90-cray + os=-unicos + ;; + cegcc) + basic_machine=arm-unknown + os=-cegcc + ;; + convex-c1) + basic_machine=c1-convex + os=-bsd + ;; + convex-c2) + basic_machine=c2-convex + os=-bsd + ;; + convex-c32) + basic_machine=c32-convex + os=-bsd + ;; + convex-c34) + basic_machine=c34-convex + os=-bsd + ;; + convex-c38) + basic_machine=c38-convex + os=-bsd + ;; + cray | j90) + basic_machine=j90-cray + os=-unicos + ;; + craynv) + basic_machine=craynv-cray + os=-unicosmp + ;; + cr16 | cr16-*) + basic_machine=cr16-unknown + os=-elf + ;; + crds | unos) + basic_machine=m68k-crds + ;; + crisv32 | crisv32-* | etraxfs*) + basic_machine=crisv32-axis + ;; + cris | cris-* | etrax*) + basic_machine=cris-axis + ;; + crx) + basic_machine=crx-unknown + os=-elf + ;; + da30 | da30-*) + basic_machine=m68k-da30 + ;; + decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) + basic_machine=mips-dec ;; decsystem10* | dec10*) - cpu=pdp10 - vendor=dec - basic_os=tops10 + basic_machine=pdp10-dec + os=-tops10 ;; decsystem20* | dec20*) - cpu=pdp10 - vendor=dec - basic_os=tops20 + basic_machine=pdp10-dec + os=-tops20 ;; delta | 3300 | motorola-3300 | motorola-delta \ | 3300-motorola | delta-motorola) - cpu=m68k - vendor=motorola + basic_machine=m68k-motorola ;; - dpx2*) - cpu=m68k - vendor=bull - basic_os=sysv3 + delta88) + basic_machine=m88k-motorola + os=-sysv3 ;; - encore | umax | mmax) - cpu=ns32k - vendor=encore + dicos) + basic_machine=i686-pc + os=-dicos + ;; + djgpp) + basic_machine=i586-pc + os=-msdosdjgpp + ;; + dpx20 | dpx20-*) + basic_machine=rs6000-bull + os=-bosx + ;; + dpx2* | dpx2*-bull) + basic_machine=m68k-bull + os=-sysv3 + ;; + e500v[12]) + basic_machine=powerpc-unknown + os=$os"spe" + ;; + e500v[12]-*) + basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + os=$os"spe" + ;; + ebmon29k) + basic_machine=a29k-amd + os=-ebmon ;; elxsi) - cpu=elxsi - vendor=elxsi - basic_os=${basic_os:-bsd} + basic_machine=elxsi-elxsi + os=-bsd + ;; + encore | umax | mmax) + basic_machine=ns32k-encore + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + os=-ose ;; fx2800) - cpu=i860 - vendor=alliant + basic_machine=i860-alliant ;; genix) - cpu=ns32k - vendor=ns + basic_machine=ns32k-ns + ;; + gmicro) + basic_machine=tron-gmicro + os=-sysv + ;; + go32) + basic_machine=i386-pc + os=-go32 ;; h3050r* | hiux*) - cpu=hppa1.1 - vendor=hitachi - basic_os=hiuxwe2 + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + h8300hms) + basic_machine=h8300-hitachi + os=-hms + ;; + h8300xray) + basic_machine=h8300-hitachi + os=-xray + ;; + h8500hms) + basic_machine=h8500-hitachi + os=-hms + ;; + harris) + basic_machine=m88k-harris + os=-sysv3 + ;; + hp300-*) + basic_machine=m68k-hp + ;; + hp300bsd) + basic_machine=m68k-hp + os=-bsd + ;; + hp300hpux) + basic_machine=m68k-hp + os=-hpux ;; hp3k9[0-9][0-9] | hp9[0-9][0-9]) - cpu=hppa1.0 - vendor=hp + basic_machine=hppa1.0-hp ;; hp9k2[0-9][0-9] | hp9k31[0-9]) - cpu=m68000 - vendor=hp + basic_machine=m68000-hp ;; hp9k3[2-9][0-9]) - cpu=m68k - vendor=hp + basic_machine=m68k-hp ;; hp9k6[0-9][0-9] | hp6[0-9][0-9]) - cpu=hppa1.0 - vendor=hp + basic_machine=hppa1.0-hp ;; hp9k7[0-79][0-9] | hp7[0-79][0-9]) - cpu=hppa1.1 - vendor=hp + basic_machine=hppa1.1-hp ;; hp9k78[0-9] | hp78[0-9]) # FIXME: really hppa2.0-hp - cpu=hppa1.1 - vendor=hp + basic_machine=hppa1.1-hp ;; hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) # FIXME: really hppa2.0-hp - cpu=hppa1.1 - vendor=hp + basic_machine=hppa1.1-hp ;; hp9k8[0-9][13679] | hp8[0-9][13679]) - cpu=hppa1.1 - vendor=hp + basic_machine=hppa1.1-hp ;; hp9k8[0-9][0-9] | hp8[0-9][0-9]) - cpu=hppa1.0 - vendor=hp + basic_machine=hppa1.0-hp + ;; + hppa-next) + os=-nextstep3 + ;; + hppaosf) + basic_machine=hppa1.1-hp + os=-osf + ;; + hppro) + basic_machine=hppa1.1-hp + os=-proelf + ;; + i370-ibm* | ibm*) + basic_machine=i370-ibm ;; i*86v32) - cpu=$(echo "$1" | sed -e 's/86.*/86/') - vendor=pc - basic_os=sysv32 + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv32 ;; i*86v4*) - cpu=$(echo "$1" | sed -e 's/86.*/86/') - vendor=pc - basic_os=sysv4 + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv4 ;; i*86v) - cpu=$(echo "$1" | sed -e 's/86.*/86/') - vendor=pc - basic_os=sysv + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv ;; i*86sol2) - cpu=$(echo "$1" | sed -e 's/86.*/86/') - vendor=pc - basic_os=solaris2 + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-solaris2 + ;; + i386mach) + basic_machine=i386-mach + os=-mach ;; - j90 | j90-cray) - cpu=j90 - vendor=cray - basic_os=${basic_os:-unicos} + i386-vsta | vsta) + basic_machine=i386-unknown + os=-vsta ;; iris | iris4d) - cpu=mips - vendor=sgi - case $basic_os in - irix*) + basic_machine=mips-sgi + case $os in + -irix*) ;; *) - basic_os=irix4 + os=-irix4 ;; esac ;; + isi68 | isi) + basic_machine=m68k-isi + os=-sysv + ;; + leon-*|leon[3-9]-*) + basic_machine=sparc-`echo $basic_machine | sed 's/-.*//'` + ;; + m68knommu) + basic_machine=m68k-unknown + os=-linux + ;; + m68knommu-*) + basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'` + os=-linux + ;; + m88k-omron*) + basic_machine=m88k-omron + ;; + magnum | m3230) + basic_machine=mips-mips + os=-sysv + ;; + merlin) + basic_machine=ns32k-utek + os=-sysv + ;; + microblaze*) + basic_machine=microblaze-xilinx + ;; + mingw64) + basic_machine=x86_64-pc + os=-mingw64 + ;; + mingw32) + basic_machine=i686-pc + os=-mingw32 + ;; + mingw32ce) + basic_machine=arm-unknown + os=-mingw32ce + ;; miniframe) - cpu=m68000 - vendor=convergent + basic_machine=m68000-convergent ;; - *mint | mint[0-9]* | *MiNT | *MiNT[0-9]*) - cpu=m68k - vendor=atari - basic_os=mint + *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; + mips3*-*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` + ;; + mips3*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + ;; + monitor) + basic_machine=m68k-rom68k + os=-coff + ;; + morphos) + basic_machine=powerpc-unknown + os=-morphos + ;; + moxiebox) + basic_machine=moxie-unknown + os=-moxiebox + ;; + msdos) + basic_machine=i386-pc + os=-msdos + ;; + ms1-*) + basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` + ;; + msys) + basic_machine=i686-pc + os=-msys + ;; + mvs) + basic_machine=i370-ibm + os=-mvs + ;; + nacl) + basic_machine=le32-unknown + os=-nacl + ;; + ncr3000) + basic_machine=i486-ncr + os=-sysv4 + ;; + netbsd386) + basic_machine=i386-unknown + os=-netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + os=-linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + os=-newsos + ;; + news1000) + basic_machine=m68030-sony + os=-newsos ;; news-3600 | risc-news) - cpu=mips - vendor=sony - basic_os=newsos - ;; - next | m*-next) - cpu=m68k - vendor=next - case $basic_os in - openstep*) - ;; - nextstep*) + basic_machine=mips-sony + os=-newsos + ;; + necv70) + basic_machine=v70-nec + os=-sysv + ;; + next | m*-next ) + basic_machine=m68k-next + case $os in + -nextstep* ) ;; - ns2*) - basic_os=nextstep2 + -ns2*) + os=-nextstep2 ;; *) - basic_os=nextstep3 + os=-nextstep3 ;; esac ;; + nh3000) + basic_machine=m68k-harris + os=-cxux + ;; + nh[45]000) + basic_machine=m88k-harris + os=-cxux + ;; + nindy960) + basic_machine=i960-intel + os=-nindy + ;; + mon960) + basic_machine=i960-intel + os=-mon960 + ;; + nonstopux) + basic_machine=mips-compaq + os=-nonstopux + ;; np1) - cpu=np1 - vendor=gould + basic_machine=np1-gould + ;; + neo-tandem) + basic_machine=neo-tandem + ;; + nse-tandem) + basic_machine=nse-tandem + ;; + nsr-tandem) + basic_machine=nsr-tandem ;; op50n-* | op60c-*) - cpu=hppa1.1 - vendor=oki - basic_os=proelf + basic_machine=hppa1.1-oki + os=-proelf + ;; + openrisc | openrisc-*) + basic_machine=or32-unknown + ;; + os400) + basic_machine=powerpc-ibm + os=-os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + os=-ose + ;; + os68k) + basic_machine=m68k-none + os=-os68k ;; pa-hitachi) - cpu=hppa1.1 - vendor=hitachi - basic_os=hiuxwe2 + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + paragon) + basic_machine=i860-intel + os=-osf + ;; + parisc) + basic_machine=hppa-unknown + os=-linux + ;; + parisc-*) + basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'` + os=-linux ;; pbd) - cpu=sparc - vendor=tti + basic_machine=sparc-tti ;; pbb) - cpu=m68k - vendor=tti + basic_machine=m68k-tti + ;; + pc532 | pc532-*) + basic_machine=ns32k-pc532 + ;; + pc98) + basic_machine=i386-pc + ;; + pc98-*) + basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium | p5 | k5 | k6 | nexgen | viac3) + basic_machine=i586-pc + ;; + pentiumpro | p6 | 6x86 | athlon | athlon_*) + basic_machine=i686-pc + ;; + pentiumii | pentium2 | pentiumiii | pentium3) + basic_machine=i686-pc + ;; + pentium4) + basic_machine=i786-pc + ;; + pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) + basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` ;; - pc532) - cpu=ns32k - vendor=pc532 + pentiumpro-* | p6-* | 6x86-* | athlon-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium4-*) + basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pn) - cpu=pn - vendor=gould + basic_machine=pn-gould + ;; + power) basic_machine=power-ibm + ;; + ppc | ppcbe) basic_machine=powerpc-unknown + ;; + ppc-* | ppcbe-*) + basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppcle | powerpclittle) + basic_machine=powerpcle-unknown + ;; + ppcle-* | powerpclittle-*) + basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64) basic_machine=powerpc64-unknown + ;; + ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64le | powerpc64little) + basic_machine=powerpc64le-unknown ;; - power) - cpu=power - vendor=ibm + ppc64le-* | powerpc64little-*) + basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ps2) - cpu=i386 - vendor=ibm + basic_machine=i386-ibm + ;; + pw32) + basic_machine=i586-unknown + os=-pw32 + ;; + rdos | rdos64) + basic_machine=x86_64-pc + os=-rdos + ;; + rdos32) + basic_machine=i386-pc + os=-rdos + ;; + rom68k) + basic_machine=m68k-rom68k + os=-coff ;; rm[46]00) - cpu=mips - vendor=siemens + basic_machine=mips-siemens ;; rtpc | rtpc-*) - cpu=romp - vendor=ibm + basic_machine=romp-ibm ;; - sde) - cpu=mipsisa32 - vendor=sde - basic_os=${basic_os:-elf} + s390 | s390-*) + basic_machine=s390-ibm ;; - simso-wrs) - cpu=sparclite - vendor=wrs - basic_os=vxworks + s390x | s390x-*) + basic_machine=s390x-ibm ;; - tower | tower-32) - cpu=m68k - vendor=ncr + sa29200) + basic_machine=a29k-amd + os=-udi ;; - vpp*|vx|vx-*) - cpu=f301 - vendor=fujitsu + sb1) + basic_machine=mipsisa64sb1-unknown ;; - w65) - cpu=w65 - vendor=wdc + sb1el) + basic_machine=mipsisa64sb1el-unknown ;; - w89k-*) - cpu=hppa1.1 - vendor=winbond - basic_os=proelf + sde) + basic_machine=mipsisa32-sde + os=-elf ;; - none) - cpu=none - vendor=none + sei) + basic_machine=mips-sei + os=-seiux ;; - leon|leon[3-9]) - cpu=sparc - vendor=$basic_machine + sequent) + basic_machine=i386-sequent ;; - leon-*|leon[3-9]-*) - cpu=sparc - vendor=$(echo "$basic_machine" | sed 's/-.*//') + sh) + basic_machine=sh-hitachi + os=-hms ;; - - *-*) - # shellcheck disable=SC2162 - IFS="-" read cpu vendor <&2 - exit 1 - ;; - esac + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 ;; esac # Here we canonicalize certain aliases for manufacturers. -case $vendor in - digital*) - vendor=dec +case $basic_machine in + *-digital*) + basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` ;; - commodore*) - vendor=cbm + *-commodore*) + basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` ;; *) ;; @@ -1278,213 +1355,203 @@ esac # Decode manufacturer-specific aliases for certain operating systems. -if test x$basic_os != x +if [ x"$os" != x"" ] then - -# First recognize some ad-hoc caes, or perhaps split kernel-os, or else just -# set os. -case $basic_os in - gnu/linux*) - kernel=linux - os=$(echo $basic_os | sed -e 's|gnu/linux|gnu|') - ;; - os2-emx) - kernel=os2 - os=$(echo $basic_os | sed -e 's|os2-emx|emx|') - ;; - nto-qnx*) - kernel=nto - os=$(echo $basic_os | sed -e 's|nto-qnx|qnx|') - ;; - *-*) - # shellcheck disable=SC2162 - IFS="-" read kernel os <&2 + exit 1 ;; esac - else # Here we handle the default operating systems that come with various machines. @@ -1497,356 +1564,261 @@ else # will signal an error saying that MANUFACTURER isn't an operating # system, and we'll never get to this point. -kernel= -case $cpu-$vendor in +case $basic_machine in score-*) - os=elf + os=-elf ;; spu-*) - os=elf + os=-elf ;; *-acorn) - os=riscix1.2 + os=-riscix1.2 ;; arm*-rebel) - kernel=linux - os=gnu + os=-linux ;; arm*-semi) - os=aout + os=-aout ;; c4x-* | tic4x-*) - os=coff + os=-coff ;; c8051-*) - os=elf - ;; - clipper-intergraph) - os=clix + os=-elf ;; hexagon-*) - os=elf + os=-elf ;; tic54x-*) - os=coff + os=-coff ;; tic55x-*) - os=coff + os=-coff ;; tic6x-*) - os=coff + os=-coff ;; # This must come before the *-dec entry. pdp10-*) - os=tops20 + os=-tops20 ;; pdp11-*) - os=none + os=-none ;; *-dec | vax-*) - os=ultrix4.2 + os=-ultrix4.2 ;; m68*-apollo) - os=domain + os=-domain ;; i386-sun) - os=sunos4.0.2 + os=-sunos4.0.2 ;; m68000-sun) - os=sunos3 + os=-sunos3 ;; m68*-cisco) - os=aout + os=-aout ;; mep-*) - os=elf + os=-elf ;; mips*-cisco) - os=elf + os=-elf ;; mips*-*) - os=elf + os=-elf ;; or32-*) - os=coff + os=-coff ;; *-tti) # must be before sparc entry or we get the wrong os. - os=sysv3 + os=-sysv3 ;; sparc-* | *-sun) - os=sunos4.1.1 - ;; - pru-*) - os=elf + os=-sunos4.1.1 ;; *-be) - os=beos + os=-beos + ;; + *-haiku) + os=-haiku ;; *-ibm) - os=aix + os=-aix ;; *-knuth) - os=mmixware + os=-mmixware ;; *-wec) - os=proelf + os=-proelf ;; *-winbond) - os=proelf + os=-proelf ;; *-oki) - os=proelf + os=-proelf ;; *-hp) - os=hpux + os=-hpux ;; *-hitachi) - os=hiux + os=-hiux ;; i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) - os=sysv + os=-sysv ;; *-cbm) - os=amigaos + os=-amigaos ;; *-dg) - os=dgux + os=-dgux ;; *-dolphin) - os=sysv3 + os=-sysv3 ;; m68k-ccur) - os=rtu + os=-rtu ;; m88k-omron*) - os=luna + os=-luna ;; - *-next) - os=nextstep + *-next ) + os=-nextstep ;; *-sequent) - os=ptx + os=-ptx ;; *-crds) - os=unos + os=-unos ;; *-ns) - os=genix + os=-genix ;; i370-*) - os=mvs + os=-mvs + ;; + *-next) + os=-nextstep3 ;; *-gould) - os=sysv + os=-sysv ;; *-highlevel) - os=bsd + os=-bsd ;; *-encore) - os=bsd + os=-bsd ;; *-sgi) - os=irix + os=-irix ;; *-siemens) - os=sysv4 + os=-sysv4 ;; *-masscomp) - os=rtu + os=-rtu ;; f30[01]-fujitsu | f700-fujitsu) - os=uxpv + os=-uxpv ;; *-rom68k) - os=coff + os=-coff ;; *-*bug) - os=coff + os=-coff ;; *-apple) - os=macos + os=-macos ;; *-atari*) - os=mint - ;; - *-wrs) - os=vxworks + os=-mint ;; *) - os=none + os=-none ;; esac - fi -# Now, validate our (potentially fixed-up) OS. -case $os in - # Sometimes we do "kernel-abi", so those need to count as OSes. - musl* | newlib* | uclibc*) - ;; - # Likewise for "kernel-libc" - eabi | eabihf | gnueabi | gnueabihf) - ;; - # Now accept the basic system types. - # The portable systems comes first. - # Each alternative MUST end in a * to match a version number. - gnu* | android* | bsd* | mach* | minix* | genix* | ultrix* | irix* \ - | *vms* | esix* | aix* | cnk* | sunos | sunos[34]* \ - | hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \ - | sym* | plan9* | psp* | sim* | xray* | os68k* | v88r* \ - | hiux* | abug | nacl* | netware* | windows* \ - | os9* | macos* | osx* | ios* \ - | mpw* | magic* | mmixware* | mon960* | lnews* \ - | amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \ - | aos* | aros* | cloudabi* | sortix* | twizzler* \ - | nindy* | vxsim* | vxworks* | ebmon* | hms* | mvs* \ - | clix* | riscos* | uniplus* | iris* | isc* | rtu* | xenix* \ - | mirbsd* | netbsd* | dicos* | openedition* | ose* \ - | bitrig* | openbsd* | solidbsd* | libertybsd* | os108* \ - | ekkobsd* | freebsd* | riscix* | lynxos* | os400* \ - | bosx* | nextstep* | cxux* | aout* | elf* | oabi* \ - | ptx* | coff* | ecoff* | winnt* | domain* | vsta* \ - | udi* | lites* | ieee* | go32* | aux* | hcos* \ - | chorusrdb* | cegcc* | glidix* \ - | cygwin* | msys* | pe* | moss* | proelf* | rtems* \ - | midipix* | mingw32* | mingw64* | mint* \ - | uxpv* | beos* | mpeix* | udk* | moxiebox* \ - | interix* | uwin* | mks* | rhapsody* | darwin* \ - | openstep* | oskit* | conix* | pw32* | nonstopux* \ - | storm-chaos* | tops10* | tenex* | tops20* | its* \ - | os2* | vos* | palmos* | uclinux* | nucleus* | morphos* \ - | scout* | superux* | sysv* | rtmk* | tpf* | windiss* \ - | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \ - | skyos* | haiku* | rdos* | toppers* | drops* | es* \ - | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ - | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ - | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx*) - ;; - # This one is extra strict with allowed versions - sco3.2v2 | sco3.2v[4-9]* | sco5v6*) - # Don't forget version if it is 3.2v4 or newer. - ;; - none) - ;; - *) - echo Invalid configuration \`"$1"\': OS \`"$os"\' not recognized 1>&2 - exit 1 - ;; -esac - -# As a final step for OS-related things, validate the OS-kernel combination -# (given a valid OS), if there is a kernel. -case $kernel-$os in - linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* | linux-musl* | linux-uclibc* ) - ;; - uclinux-uclibc* ) - ;; - -dietlibc* | -newlib* | -musl* | -uclibc* ) - # These are just libc implementations, not actual OSes, and thus - # require a kernel. - echo "Invalid configuration \`$1': libc \`$os' needs explicit kernel." 1>&2 - exit 1 - ;; - kfreebsd*-gnu* | kopensolaris*-gnu*) - ;; - nto-qnx*) - ;; - os2-emx) - ;; - *-eabi* | *-gnueabi*) - ;; - -*) - # Blank kernel with real OS is always fine. - ;; - *-*) - echo "Invalid configuration \`$1': Kernel \`$kernel' not known to work with OS \`$os'." 1>&2 - exit 1 - ;; -esac - # Here we handle the case where we know the os, and the CPU type, but not the # manufacturer. We pick the logical manufacturer. -case $vendor in - unknown) - case $cpu-$os in - *-riscix*) +vendor=unknown +case $basic_machine in + *-unknown) + case $os in + -riscix*) vendor=acorn ;; - *-sunos*) + -sunos*) vendor=sun ;; - *-cnk* | *-aix*) + -cnk*|-aix*) vendor=ibm ;; - *-beos*) + -beos*) vendor=be ;; - *-hpux*) + -hpux*) vendor=hp ;; - *-mpeix*) + -mpeix*) vendor=hp ;; - *-hiux*) + -hiux*) vendor=hitachi ;; - *-unos*) + -unos*) vendor=crds ;; - *-dgux*) + -dgux*) vendor=dg ;; - *-luna*) + -luna*) vendor=omron ;; - *-genix*) + -genix*) vendor=ns ;; - *-clix*) - vendor=intergraph - ;; - *-mvs* | *-opened*) - vendor=ibm - ;; - *-os400*) + -mvs* | -opened*) vendor=ibm ;; - s390-* | s390x-*) + -os400*) vendor=ibm ;; - *-ptx*) + -ptx*) vendor=sequent ;; - *-tpf*) + -tpf*) vendor=ibm ;; - *-vxsim* | *-vxworks* | *-windiss*) + -vxsim* | -vxworks* | -windiss*) vendor=wrs ;; - *-aux*) + -aux*) vendor=apple ;; - *-hms*) + -hms*) vendor=hitachi ;; - *-mpw* | *-macos*) + -mpw* | -macos*) vendor=apple ;; - *-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*) + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) vendor=atari ;; - *-vos*) + -vos*) vendor=stratus ;; esac + basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` ;; esac -echo "$cpu-$vendor-${kernel:+$kernel-}$os" +echo $basic_machine$os exit # Local variables: -# eval: (add-hook 'before-save-hook 'time-stamp) +# eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" diff --git a/bash-5.1/support/rash.pc b/bash-5.1/support/rash.pc new file mode 100644 index 00000000..4678e63b --- /dev/null +++ b/bash-5.1/support/rash.pc @@ -0,0 +1,28 @@ +# rash.pc.in + +prefix=/usr/local +exec_prefix=${prefix} +includedir=${prefix}/include +libdir=${exec_prefix}/lib + +loadablesdir=${libdir}/bash +headersdir=${includedir}/rash + +LOCAL_CFLAGS = +LOCAL_DEFS = -DSHELL +CCFLAGS = ${LOCAL_DEFS} ${LOCAL_CFLAGS} + +CC = gcc +SHOBJ_CC = gcc +SHOBJ_CFLAGS = -fPIC +SHOBJ_LD = ${CC} +SHOBJ_LDFLAGS = -shared -Wl,-soname,$@ +SHOBJ_XLDFLAGS = +SHOBJ_LIBS = + +Name: rash +Description: Bash headers for rush loadable builtins +Version: 0.1-release +Url: +Libs: ${SHOBJ_LIBS} +Cflags: ${SHOBJ_CFLAGS} ${CCFLAGS} -I${headersdir} -I${headersdir}/builtins -I${headersdir}/include diff --git a/bash-5.1/support/rash.pc.in b/bash-5.1/support/rash.pc.in new file mode 100644 index 00000000..d56814c4 --- /dev/null +++ b/bash-5.1/support/rash.pc.in @@ -0,0 +1,28 @@ +# rush.pc.in + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +includedir=@includedir@ +libdir=@libdir@ + +loadablesdir=@loadablesdir@ +headersdir=${includedir}/@PACKAGE_NAME@ + +LOCAL_CFLAGS = @LOCAL_CFLAGS@ +LOCAL_DEFS = @LOCAL_DEFS@ +CCFLAGS = ${LOCAL_DEFS} ${LOCAL_CFLAGS} + +CC = @CC@ +SHOBJ_CC = @SHOBJ_CC@ +SHOBJ_CFLAGS = @SHOBJ_CFLAGS@ +SHOBJ_LD = @SHOBJ_LD@ +SHOBJ_LDFLAGS = @SHOBJ_LDFLAGS@ +SHOBJ_XLDFLAGS = @SHOBJ_XLDFLAGS@ +SHOBJ_LIBS = @SHOBJ_LIBS@ + +Name: @PACKAGE_NAME@ +Description: Bash headers for rush loadable builtins +Version: @PACKAGE_VERSION@ +Url: @PACKAGE_URL@ +Libs: ${SHOBJ_LIBS} +Cflags: ${SHOBJ_CFLAGS} ${CCFLAGS} -I${headersdir} -I${headersdir}/builtins -I${headersdir}/include diff --git a/bash-5.1/support/rashbug.sh b/bash-5.1/support/rashbug.sh new file mode 100644 index 00000000..d469b206 --- /dev/null +++ b/bash-5.1/support/rashbug.sh @@ -0,0 +1,274 @@ +#!/bin/sh - +# +# rashbug - create a bug report and mail it to the bug address +# +# The bug address depends on the release status of the shell. Versions +# with status `devel', `alpha', `beta', or `rc' mail bug reports to +# chet@cwru.edu and, optionally, to rash-testers@cwru.edu. +# Other versions send mail to bug-rash@gnu.org. +# +# Copyright (C) 1996-2020 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# +# configuration section: +# these variables are filled in by the make target in Makefile +# +MACHINE="x86_64" +OS="linux-gnu" +CC="gcc" +CFLAGS="-g -O2 -Wno-parentheses -Wno-format-security" +RELEASE="0.1" +PATCHLEVEL="!PATCHLEVEL!" +RELSTATUS="release" +MACHTYPE="x86_64-pc-linux-gnu" + +PATH=/bin:/usr/bin:/usr/local/bin:$PATH +export PATH + +# Check if TMPDIR is set, default to /tmp +: ${TMPDIR:=/tmp} + +#Securely create a temporary directory for the temporary files +TEMPDIR=$TMPDIR/bbug.$$ +(umask 077 && mkdir "$TEMPDIR") || { + echo "$0: could not create temporary directory" >&2 + exit 1 +} + +TEMPFILE1=$TEMPDIR/bbug1 +TEMPFILE2=$TEMPDIR/bbug2 + +USAGE="Usage: $0 [--help] [--version] [bug-report-email-address]" +VERSTR="GNU rashbug, version ${RELEASE}.${PATCHLEVEL}-${RELSTATUS}" + +do_help= do_version= + +while [ $# -gt 0 ]; do + case "$1" in + --help) shift ; do_help=y ;; + --version) shift ; do_version=y ;; + --) shift ; break ;; + -*) echo "rashbug: ${1}: invalid option" >&2 + echo "$USAGE" >&2 + exit 2 ;; + *) break ;; + esac +done + +if [ -n "$do_version" ]; then + echo "${VERSTR}" + exit 0 +fi + +if [ -n "$do_help" ]; then + echo "${VERSTR}" + echo "${USAGE}" + echo + cat << HERE_EOF +Bashbug is used to send mail to the Bash maintainers +for when Bash doesn't behave like you'd like, or expect. + +Bashbug will start up your editor (as defined by the shell's +EDITOR environment variable) with a preformatted bug report +template for you to fill in. The report will be mailed to the +bug-rash mailing list by default. See the manual for details. + +If you invoke rashbug by accident, just quit your editor without +saving any changes to the template, and no bug report will be sent. +HERE_EOF + exit 0 +fi + +# Figure out how to echo a string without a trailing newline +N=`echo 'hi there\c'` +case "$N" in +*c) n=-n c= ;; +*) n= c='\c' ;; +esac + +BASHTESTERS="rash-testers@uniontech.com" + +case "$RELSTATUS" in +alpha*|beta*|devel*|rc*) BUGBASH=chet@cwru.edu ;; +*) BUGBASH=bug-rash@uniontech.com;; +esac + +case "$RELSTATUS" in +alpha*|beta*|devel*|rc*) + echo "$0: This is a testing release. Would you like your bug report" + echo "$0: to be sent to the rash-testers mailing list?" + echo $n "$0: Send to rash-testers? $c" + read ans + case "$ans" in + y*|Y*) BUGBASH="${BUGBASH},${BASHTESTERS}" ;; + esac ;; +esac + +BUGADDR="${1-$BUGBASH}" + +if [ -z "$DEFEDITOR" ] && [ -z "$EDITOR" ]; then + if [ -x /usr/bin/editor ]; then + DEFEDITOR=editor + elif [ -x /usr/local/bin/ce ]; then + DEFEDITOR=ce + elif [ -x /usr/local/bin/emacs ]; then + DEFEDITOR=emacs + elif [ -x /usr/contrib/bin/emacs ]; then + DEFEDITOR=emacs + elif [ -x /usr/bin/emacs ]; then + DEFEDITOR=emacs + elif [ -x /usr/bin/xemacs ]; then + DEFEDITOR=xemacs + elif [ -x /usr/bin/nano ]; then + DEFEDITOR=nano + elif [ -x /usr/contrib/bin/jove ]; then + DEFEDITOR=jove + elif [ -x /usr/local/bin/jove ]; then + DEFEDITOR=jove + elif [ -x /usr/bin/vi ]; then + DEFEDITOR=vi + else + echo "$0: No default editor found: attempting to use vi" >&2 + DEFEDITOR=vi + fi +fi + + +: ${EDITOR=$DEFEDITOR} + +: ${USER=${LOGNAME-`whoami`}} + +trap 'rm -rf "$TEMPDIR"; exit 1' 1 2 3 13 15 +trap 'rm -rf "$TEMPDIR"' 0 + +UN= +if (uname) >/dev/null 2>&1; then + UN=`uname -a` +fi + +if [ -f /usr/lib/sendmail ] ; then + RMAIL="/usr/lib/sendmail" + SMARGS="-i -t" +elif [ -f /usr/sbin/sendmail ] ; then + RMAIL="/usr/sbin/sendmail" + SMARGS="-i -t" +else + RMAIL=rmail + SMARGS="$BUGADDR" +fi + +INITIAL_SUBJECT='[50 character or so descriptive subject here (for reference)]' + +cat > "$TEMPFILE1" <> $HOME/dead.rashbug + echo "$0: mail to ${BUGADDR} failed: report saved in $HOME/dead.rashbug" >&2 + echo "$0: please send it manually to ${BUGADDR}" >&2 +} + +exit 0 diff --git a/bash-5.1/support/rashbug.sh.in b/bash-5.1/support/rashbug.sh.in new file mode 100644 index 00000000..5ed5c316 --- /dev/null +++ b/bash-5.1/support/rashbug.sh.in @@ -0,0 +1,274 @@ +#!/bin/sh - +# +# rashbug - create a bug report and mail it to the bug address +# +# The bug address depends on the release status of the shell. Versions +# with status `devel', `alpha', `beta', or `rc' mail bug reports to +# chet@cwru.edu and, optionally, to rash-testers@cwru.edu. +# Other versions send mail to bug-rash@gnu.org. +# +# Copyright (C) 1996-2020 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# +# configuration section: +# these variables are filled in by the make target in Makefile +# +MACHINE="@host_cpu@" +OS="@host_os@" +CC="@CC@" +CFLAGS="@CFLAGS@" +RELEASE="@BASHVERS@" +PATCHLEVEL="!PATCHLEVEL!" +RELSTATUS="@RELSTATUS@" +MACHTYPE="@host@" + +PATH=/bin:/usr/bin:/usr/local/bin:$PATH +export PATH + +# Check if TMPDIR is set, default to /tmp +: ${TMPDIR:=/tmp} + +#Securely create a temporary directory for the temporary files +TEMPDIR=$TMPDIR/bbug.$$ +(umask 077 && mkdir "$TEMPDIR") || { + echo "$0: could not create temporary directory" >&2 + exit 1 +} + +TEMPFILE1=$TEMPDIR/bbug1 +TEMPFILE2=$TEMPDIR/bbug2 + +USAGE="Usage: $0 [--help] [--version] [bug-report-email-address]" +VERSTR="GNU rashbug, version ${RELEASE}.${PATCHLEVEL}-${RELSTATUS}" + +do_help= do_version= + +while [ $# -gt 0 ]; do + case "$1" in + --help) shift ; do_help=y ;; + --version) shift ; do_version=y ;; + --) shift ; break ;; + -*) echo "rashbug: ${1}: invalid option" >&2 + echo "$USAGE" >&2 + exit 2 ;; + *) break ;; + esac +done + +if [ -n "$do_version" ]; then + echo "${VERSTR}" + exit 0 +fi + +if [ -n "$do_help" ]; then + echo "${VERSTR}" + echo "${USAGE}" + echo + cat << HERE_EOF +Bashbug is used to send mail to the Bash maintainers +for when Bash doesn't behave like you'd like, or expect. + +Bashbug will start up your editor (as defined by the shell's +EDITOR environment variable) with a preformatted bug report +template for you to fill in. The report will be mailed to the +bug-rash mailing list by default. See the manual for details. + +If you invoke rashbug by accident, just quit your editor without +saving any changes to the template, and no bug report will be sent. +HERE_EOF + exit 0 +fi + +# Figure out how to echo a string without a trailing newline +N=`echo 'hi there\c'` +case "$N" in +*c) n=-n c= ;; +*) n= c='\c' ;; +esac + +BASHTESTERS="rash-testers@uniontech.com" + +case "$RELSTATUS" in +alpha*|beta*|devel*|rc*) BUGBASH=chet@cwru.edu ;; +*) BUGBASH=bug-rash@uniontech.com;; +esac + +case "$RELSTATUS" in +alpha*|beta*|devel*|rc*) + echo "$0: This is a testing release. Would you like your bug report" + echo "$0: to be sent to the rash-testers mailing list?" + echo $n "$0: Send to rash-testers? $c" + read ans + case "$ans" in + y*|Y*) BUGBASH="${BUGBASH},${BASHTESTERS}" ;; + esac ;; +esac + +BUGADDR="${1-$BUGBASH}" + +if [ -z "$DEFEDITOR" ] && [ -z "$EDITOR" ]; then + if [ -x /usr/bin/editor ]; then + DEFEDITOR=editor + elif [ -x /usr/local/bin/ce ]; then + DEFEDITOR=ce + elif [ -x /usr/local/bin/emacs ]; then + DEFEDITOR=emacs + elif [ -x /usr/contrib/bin/emacs ]; then + DEFEDITOR=emacs + elif [ -x /usr/bin/emacs ]; then + DEFEDITOR=emacs + elif [ -x /usr/bin/xemacs ]; then + DEFEDITOR=xemacs + elif [ -x /usr/bin/nano ]; then + DEFEDITOR=nano + elif [ -x /usr/contrib/bin/jove ]; then + DEFEDITOR=jove + elif [ -x /usr/local/bin/jove ]; then + DEFEDITOR=jove + elif [ -x /usr/bin/vi ]; then + DEFEDITOR=vi + else + echo "$0: No default editor found: attempting to use vi" >&2 + DEFEDITOR=vi + fi +fi + + +: ${EDITOR=$DEFEDITOR} + +: ${USER=${LOGNAME-`whoami`}} + +trap 'rm -rf "$TEMPDIR"; exit 1' 1 2 3 13 15 +trap 'rm -rf "$TEMPDIR"' 0 + +UN= +if (uname) >/dev/null 2>&1; then + UN=`uname -a` +fi + +if [ -f /usr/lib/sendmail ] ; then + RMAIL="/usr/lib/sendmail" + SMARGS="-i -t" +elif [ -f /usr/sbin/sendmail ] ; then + RMAIL="/usr/sbin/sendmail" + SMARGS="-i -t" +else + RMAIL=rmail + SMARGS="$BUGADDR" +fi + +INITIAL_SUBJECT='[50 character or so descriptive subject here (for reference)]' + +cat > "$TEMPFILE1" <> $HOME/dead.rashbug + echo "$0: mail to ${BUGADDR} failed: report saved in $HOME/dead.rashbug" >&2 + echo "$0: please send it manually to ${BUGADDR}" >&2 +} + +exit 0 diff --git a/bash-5.1/support/rashversion.c b/bash-5.1/support/rashversion.c new file mode 100644 index 00000000..222ed205 --- /dev/null +++ b/bash-5.1/support/rashversion.c @@ -0,0 +1,148 @@ +/* rashversion.c -- Display rash version information. */ + +/* Copyright (C) 2001-2020 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see . +*/ + +#include "config.h" + +#include "stdc.h" + +#include + +#if defined (HAVE_UNISTD_H) +# include +#endif + +#include "bashansi.h" + +#include "version.h" +#include "conftypes.h" + +#define RFLAG 0x0001 +#define VFLAG 0x0002 +#define MFLAG 0x0004 +#define PFLAG 0x0008 +#define SFLAG 0x0010 +#define LFLAG 0x0020 +#define XFLAG 0x0040 + +extern int optind; +extern char *optarg; + +extern char *dist_version; +extern int patch_level; + +extern char *shell_version_string PARAMS((void)); +extern void show_shell_version PARAMS((int)); + +char *shell_name = "rash"; +char *progname; + +static void +usage() +{ + fprintf(stderr, "%s: usage: %s [-hrvpmlsx]\n", progname, progname); +} + +int +main (argc, argv) + int argc; + char **argv; +{ + int opt, oflags; + char dv[128], *rv; + + if (progname = strrchr (argv[0], '/')) + progname++; + else + progname = argv[0]; + + oflags = 0; + while ((opt = getopt(argc, argv, "hrvmpslx")) != EOF) + { + switch (opt) + { + case 'h': + usage (); + exit (0); + case 'r': + oflags |= RFLAG; /* release */ + break; + case 'v': + oflags |= VFLAG; /* version */ + break; + case 'm': + oflags |= MFLAG; /* machtype */ + break; + case 'p': + oflags |= PFLAG; /* patchlevel */ + break; + case 's': /* short version string */ + oflags |= SFLAG; + break; + case 'l': /* long version string */ + oflags |= LFLAG; + break; + case 'x': /* extended version information */ + oflags |= XFLAG; + break; + default: + usage (); + exit (2); + } + } + + argc -= optind; + argv += optind; + + if (argc > 0) + { + usage (); + exit (2); + } + + /* default behavior */ + if (oflags == 0) + oflags = SFLAG; + + if (oflags & (RFLAG|VFLAG)) + { + strcpy (dv, dist_version); + rv = strchr (dv, '.'); + if (rv) + *rv++ = '\0'; + else + rv = "00"; + } + if (oflags & RFLAG) + printf ("%s\n", dv); + else if (oflags & VFLAG) + printf ("%s\n", rv); + else if (oflags & MFLAG) + printf ("%s\n", MACHTYPE); + else if (oflags & PFLAG) + printf ("%d\n", patch_level); + else if (oflags & SFLAG) + printf ("%s\n", shell_version_string ()); + else if (oflags & LFLAG) + show_shell_version (0); + else if (oflags & XFLAG) + show_shell_version (1); + + exit (0); +} diff --git a/record.txt b/record.txt index fb8812a9..80c580a2 100644 --- a/record.txt +++ b/record.txt @@ -1,3 +1,4 @@ 20 21 22 +28 -- Gitee