From 3dbfc5ab13bc1ce4bc894a49578ee393d1d2fb7d Mon Sep 17 00:00:00 2001 From: zhanghuanhuan Date: Thu, 10 Aug 2023 15:40:34 +0800 Subject: [PATCH] rust: add colon and builtin --- bash-5.1/Cargo.toml | 85 ++---- bash-5.1/Makefile.in | 6 +- bash-5.1/builtins/alias.def | 12 +- bash-5.1/builtins/break.def | 27 -- bash-5.1/builtins/builtin.c | 2 +- bash-5.1/builtins/caller.def | 62 ++++- bash-5.1/builtins/enable.def | 3 - bash-5.1/builtins/eval.def | 7 +- bash-5.1/builtins/exec.def | 182 ++++++++++++- bash-5.1/builtins/exit.def | 6 - bash-5.1/builtins/hash.def | 2 - bash-5.1/builtins/help.def | 10 - bash-5.1/builtins/setattr.def | 20 +- bash-5.1/builtins/shopt.def | 23 -- bash-5.1/builtins/type.def | 3 +- bash-5.1/builtins/ulimit.def | 2 - bash-5.1/builtins_rust/builtin/Cargo.toml | 8 +- .../builtins_rust/builtin/src/intercdep.rs | 28 +- bash-5.1/builtins_rust/builtin/src/lib.rs | 42 ++- bash-5.1/builtins_rust/cd/Cargo.toml | 5 +- bash-5.1/builtins_rust/cd/src/lib.rs | 255 +++++++++--------- bash-5.1/builtins_rust/colon/Cargo.toml | 4 +- bash-5.1/builtins_rust/complete/Cargo.toml | 6 +- bash-5.1/builtins_rust/declare/Cargo.toml | 5 +- bash-5.1/builtins_rust/fc/Cargo.toml | 5 +- bash-5.1/builtins_rust/fg_bg/Cargo.toml | 5 +- bash-5.1/builtins_rust/getopts/Cargo.toml | 5 +- bash-5.1/builtins_rust/getopts/src/lib.rs | 10 + bash-5.1/builtins_rust/history/Cargo.toml | 8 +- bash-5.1/builtins_rust/jobs/Cargo.toml | 6 +- bash-5.1/builtins_rust/jobs/src/lib.rs | 4 +- bash-5.1/builtins_rust/kill/Cargo.toml | 8 +- bash-5.1/builtins_rust/kill/src/lib.rs | 4 +- bash-5.1/builtins_rust/mapfile/Cargo.toml | 8 +- bash-5.1/builtins_rust/printf/Cargo.toml | 7 +- bash-5.1/builtins_rust/pushd/Cargo.toml | 5 +- bash-5.1/builtins_rust/read/Cargo.toml | 6 +- bash-5.1/builtins_rust/rlet/Cargo.toml | 6 +- bash-5.1/builtins_rust/rreturn/Cargo.toml | 4 +- bash-5.1/builtins_rust/shift/Cargo.toml | 8 +- bash-5.1/builtins_rust/source/Cargo.toml | 5 +- bash-5.1/builtins_rust/suspend/Cargo.toml | 8 +- bash-5.1/builtins_rust/test/Cargo.toml | 8 +- bash-5.1/builtins_rust/times/Cargo.toml | 8 +- record.txt | 1 + 45 files changed, 525 insertions(+), 409 deletions(-) diff --git a/bash-5.1/Cargo.toml b/bash-5.1/Cargo.toml index 52fb0ce..dc99ad7 100644 --- a/bash-5.1/Cargo.toml +++ b/bash-5.1/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rsbash" version = "0.1.0" -edition = "2018" +edition = "2021" [lib] @@ -13,82 +13,27 @@ crate-type = ["cdylib"] members=[ "builtins_rust/jobs", + "builtins_rust/cd", "builtins_rust/fg_bg", + "builtins_rust/read", "builtins_rust/fc", "builtins_rust/getopts", - "builtins_rust/read", - "builtins_rust/cd", - "builtins_rust/pushd", - "builtins_rust/rlet", - "builtins_rust/mapfile", - "builtins_rust/help", - "builtins_rust/exit", - "builtins_rust/history", - "builtins_rust/kill", - "builtins_rust/builtin", "builtins_rust/colon", - "builtins_rust/echo", - "builtins_rust/complete", - - "builtins_rust/set", - "builtins_rust/shopt", - "builtins_rust/alias", - "builtins_rust/caller", - "builtins_rust/eval", - "builtins_rust/exec", - "builtins_rust/common", - "builtins_rust/cmd", - "builtins_rust/enable", - "builtins_rust/declare", - "builtins_rust/setattr", - "builtins_rust/command", - "builtins_rust/hash", - "builtins_rust/break_1", - "builtins_rust/type", - "builtins_rust/ulimit", - "builtins_rust/source", - "builtins_rust/suspend", - "builtins_rust/test", - "builtins_rust/times", - "builtins_rust/trap", - "builtins_rust/umask", - "builtins_rust/wait", - "builtins_rust/printf", - "builtins_rust/bind", + "builtins_rust/builtin", ] [dependencies] libc = "0.2" read = {path = "./builtins_rust/read"} -rhash = {path = "./builtins_rust/hash"} -rhistory = {path = "./builtins_rust/history"} -rkill = {path = "./builtins_rust/kill"} -rlet = {path = "./builtins_rust/rlet"} -rmapfile = {path = "./builtins_rust/mapfile"} -rreturn = {path = "./builtins_rust/rreturn"} -rshift = {path = "./builtins_rust/shift"} -rtimes = {path = "./builtins_rust/times"} -rsuspend = {path = "./builtins_rust/suspend"} -rtest = {path = "./builtins_rust/test"} -rtrap = {path = "./builtins_rust/trap"} -rsetattr = {path = "./builtins_rust/setattr"} -rumask = {path = "./builtins_rust/umask"} +#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"} rcolon = {path = "./builtins_rust/colon"} -rbuiltin = {path = "./builtins_rust/builtin"} -ralias= {path = "./builtins_rust/alias"} -rexit = {path = "./builtins_rust/exit"} -rhelp = {path = "./builtins_rust/help"} -rcaller = {path = "./builtins_rust/caller"} -rsource = {path = "./builtins_rust/source"} -reval = {path = "./builtins_rust/eval"} -rexec = {path = "./builtins_rust/exec"} -rcommon = {path = "./builtins_rust/common"} -rcmd = {path = "builtins_rust/cmd"} -renable = {path = "builtins_rust/enable"} -rbreak = {path = "builtins_rust/break_1"} -rulimit = {path = "builtins_rust/ulimit"} -rtype = {path = "builtins_rust/type"} -rshopt = {path = "builtins_rust/shopt"} -rwait = {path = "builtins_rust/wait"} -rprintf= {path = "builtins_rust/printf"} -rbind = {path = "builtins_rust/bind"} + builtin = {path = "./builtins_rust/builtin"} diff --git a/bash-5.1/Makefile.in b/bash-5.1/Makefile.in index 10e61f7..565abd3 100644 --- a/bash-5.1/Makefile.in +++ b/bash-5.1/Makefile.in @@ -138,7 +138,8 @@ LOCAL_DEFS = @LOCAL_DEFS@ LOCALE_DEFS = -DLOCALEDIR='"$(localedir)"' -DPACKAGE='"$(PACKAGE)"' LOCAL_LIBS = @LOCAL_LIBS@ -LIBS = $(BUILTINS_LIB) $(LIBRARIES) @LIBS@ -lrt -lpthread -L./target/debug -lralias -lrbind -lrbreak -lrbuiltin -lrcaller -lrcd -lrcolon -lrcommon -lrcomplete -lrdeclare -lrecho -lrenable -lreval -lrexec -lrexit -lrfc -lrfg_bg -lrgetopts -lrhash -lrexit -lrhelp -lrhistory -lrjobs -lrkill -lrmapfile -lrpushd -lrread -lrlet -lrreturn -lrset -lrsetattr -lrshift -lrshopt -lrsource -lrsuspend -lrtest -lrtimes -lrtrap -lrtype -lrulimit -lrumask -lrwait -lrprintf +LIBS = $(BUILTINS_LIB) $(LIBRARIES) @LIBS@ -lrt -lpthread -L./target/debug -lrjobs -lrread -lrcd -lrfg_bg -lrfc -lrgetopts -lrcolon -lrbuiltin + LIBS_FOR_BUILD = STATIC_LD = @STATIC_LD@ @@ -573,7 +574,8 @@ 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)/alias $(RUST_DIR)/bind $(RUST_DIR)/break_1 $(RUST_DIR)/builtin $(RUST_DIR)/caller $(RUST_DIR)/cd $(RUST_DIR)/colon $(RUST_DIR)/command $(RUST_DIR)/common $(RUST_DIR)/complete $(RUST_DIR)/declare $(RUST_DIR)/echo $(RUST_DIR)/enable $(RUST_DIR)/eval $(RUST_DIR)/exit $(RUST_DIR)/fc $(RUST_DIR)/fg_bg $(RUST_DIR)/getopts $(RUST_DIR)/hash $(RUST_DIR)/help $(RUST_DIR)/history $(RUST_DIR)/jobs $(RUST_DIR)/kill $(RUST_DIR)/mapfile $(RUST_DIR)/printf $(RUST_DIR)/pushd $(RUST_DIR)/read $(RUST_DIR)/rlet $(RUST_DIR)/rreturn $(RUST_DIR)/set $(RUST_DIR)/setattr $(RUST_DIR)/shift $(RUST_DIR)/shopt $(RUST_DIR)/source $(RUST_DIR)/suspend $(RUST_DIR)/test $(RUST_DIR)/times $(RUST_DIR)/trap $(RUST_DIR)/type $(RUST_DIR)/ulimit $(RUST_DIR)/umask $(RUST_DIR)/wait $(RUST_DIR)/exec +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_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. diff --git a/bash-5.1/builtins/alias.def b/bash-5.1/builtins/alias.def index 2d12e80..0ab9069 100644 --- a/bash-5.1/builtins/alias.def +++ b/bash-5.1/builtins/alias.def @@ -64,21 +64,19 @@ $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; dflags = posixly_correct ? 0 : AL_REUSABLE; pflag = 0; - reset_internal_getopt (); /*lhead = lcurrent = loptend = (WORD_LIST *)NULL; sp = 1;*/ + reset_internal_getopt (); while ((offset = internal_getopt (list, "p")) != -1) { switch (offset) @@ -112,7 +110,7 @@ alias_builtin (list) free (alias_list); /* XXX - Do not free the strings. */ if (list == 0) - return (sh_chkwrite (EXECUTION_SUCCESS));//flush + return (sh_chkwrite (EXECUTION_SUCCESS)); } any_failed = 0; @@ -125,8 +123,8 @@ alias_builtin (list) if (offset && name[offset] == '=') { - name[offset] = '\0';//need cp to transfrom rust - value = name + offset + 1;//need cp to transfrom rust + name[offset] = '\0'; + value = name + offset + 1; if (legal_alias_name (name, 0) == 0) { @@ -168,12 +166,10 @@ $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/break.def b/bash-5.1/builtins/break.def index 346b632..b73ed5e 100644 --- a/bash-5.1/builtins/break.def +++ b/bash-5.1/builtins/break.def @@ -47,7 +47,6 @@ $END #include "common.h" static int check_loop_level PARAMS((void)); -extern int r_break_builtin PARAMS((WORD_LIST *)); /* The depth of while's and until's. */ int loop_level = 0; @@ -64,7 +63,6 @@ int break_builtin (list) WORD_LIST *list; { - return r_break_builtin(list); intmax_t newbreak; CHECK_HELPOPT (list); @@ -143,28 +141,3 @@ check_loop_level () return (loop_level); } - -extern void set_loop_level(int i) -{ - loop_level = i; -} -extern int get_loop_level(void ) -{ - return loop_level; -} -extern void set_continuing(int i) -{ - continuing = i; -} -extern int get_continuing() -{ - return continuing; -} -extern void set_breaking(int i) -{ - breaking = i ; -} -extern int get_breaking() -{ - return breaking; -} diff --git a/bash-5.1/builtins/builtin.c b/bash-5.1/builtins/builtin.c index eff88dc..dee9ef5 100644 --- a/bash-5.1/builtins/builtin.c +++ b/bash-5.1/builtins/builtin.c @@ -16,7 +16,7 @@ #include "common.h" #include "bashgetopt.h" -extern int r_builtin_builtin ( WORD_LIST *list); +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. */ diff --git a/bash-5.1/builtins/caller.def b/bash-5.1/builtins/caller.def index 31a3d58..1000979 100644 --- a/bash-5.1/builtins/caller.def +++ b/bash-5.1/builtins/caller.def @@ -39,7 +39,7 @@ Returns 0 unless the shell is not executing a shell function or EXPR is invalid. $END -#include +#include #include #include "chartypes.h" #include "bashtypes.h" @@ -68,13 +68,67 @@ $END extern int errno; #endif /* !errno */ -extern int r_caller_builtin(WORD_LIST *); - int caller_builtin (list) WORD_LIST *list; { - r_caller_builtin(list); +#if !defined (ARRAY_VARS) + printf ("1 NULL\n"); + return (EXECUTION_FAILURE); +#else + SHELL_VAR *funcname_v, *bash_source_v, *bash_lineno_v; + ARRAY *funcname_a, *bash_source_a, *bash_lineno_a; + char *funcname_s, *source_s, *lineno_s; + intmax_t num; + + CHECK_HELPOPT (list); + + GET_ARRAY_FROM_VAR ("FUNCNAME", funcname_v, funcname_a); + GET_ARRAY_FROM_VAR ("BASH_SOURCE", bash_source_v, bash_source_a); + GET_ARRAY_FROM_VAR ("BASH_LINENO", bash_lineno_v, bash_lineno_a); + + if (bash_lineno_a == 0 || array_empty (bash_lineno_a)) + return (EXECUTION_FAILURE); + + if (bash_source_a == 0 || array_empty (bash_source_a)) + return (EXECUTION_FAILURE); + + if (no_options (list)) + return (EX_USAGE); + list = loptend; /* skip over possible `--' */ + + /* If there is no argument list, then give short form: line filename. */ + if (list == 0) + { + lineno_s = array_reference (bash_lineno_a, 0); + source_s = array_reference (bash_source_a, 1); + printf("%s %s\n", lineno_s ? lineno_s : "NULL", source_s ? source_s : "NULL"); + return (EXECUTION_SUCCESS); + } + + if (funcname_a == 0 || array_empty (funcname_a)) + return (EXECUTION_FAILURE); + + if (legal_number (list->word->word, &num)) + { + lineno_s = array_reference (bash_lineno_a, num); + source_s = array_reference (bash_source_a, num+1); + funcname_s = array_reference (funcname_a, num+1); + + if (lineno_s == NULL|| source_s == NULL || funcname_s == NULL) + return (EXECUTION_FAILURE); + + printf("%s %s %s\n", lineno_s, funcname_s, source_s); + } + else + { + sh_invalidnum (list->word->word); + builtin_usage (); + return (EX_USAGE); + } + + return (EXECUTION_SUCCESS); +#endif } #ifdef LOADABLE_BUILTIN diff --git a/bash-5.1/builtins/enable.def b/bash-5.1/builtins/enable.def index 9767c35..9d9010b 100644 --- a/bash-5.1/builtins/enable.def +++ b/bash-5.1/builtins/enable.def @@ -104,12 +104,10 @@ static int enable_shell_command PARAMS((char *, int)); /* Enable/disable shell commands present in LIST. If list is not specified, then print out a list of shell commands showing which are enabled and which are disabled. */ -extern int r_enable_builtin ( WORD_LIST *list); int enable_builtin (list) WORD_LIST *list; { -return r_enable_builtin(list); int result, flags; int opt, filter; #if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM) @@ -313,7 +311,6 @@ dyn_load_builtin (list, flags, filename) #endif handle = 0; - //没找到 if (absolute_program (filename) == 0) { loadables_path = get_string_value ("BASH_LOADABLES_PATH"); diff --git a/bash-5.1/builtins/eval.def b/bash-5.1/builtins/eval.def index 71b3b8f..a92b538 100644 --- a/bash-5.1/builtins/eval.def +++ b/bash-5.1/builtins/eval.def @@ -45,12 +45,13 @@ $END #include "common.h" /* Parse the string that these words make, and execute the command found. */ -extern int r_eval_builtin(WORD_LIST *); - int eval_builtin (list) WORD_LIST *list; { - r_eval_builtin(list); + if (no_options (list)) + return (EX_USAGE); + list = loptend; /* skip over possible `--' */ + return (list ? evalstring (string_list (list), "eval", SEVAL_NOHIST) : EXECUTION_SUCCESS); } diff --git a/bash-5.1/builtins/exec.def b/bash-5.1/builtins/exec.def index 3713c99..cbcb641 100644 --- a/bash-5.1/builtins/exec.def +++ b/bash-5.1/builtins/exec.def @@ -84,12 +84,190 @@ int no_exit_on_failed_exec; /* If the user wants this to look like a login shell, then prepend a `-' onto NAME and return the new name. */ +static char * +mkdashname (name) + char *name; +{ + char *ret; -extern int r_exec_builtin(WORD_LIST *); + ret = (char *)xmalloc (2 + strlen (name)); + ret[0] = '-'; + strcpy (ret + 1, name); + return ret; +} int exec_builtin (list) WORD_LIST *list; { - r_exec_builtin(list); + int exit_value = EXECUTION_FAILURE; + int cleanenv, login, opt, orig_job_control; + char *argv0, *command, **args, **env, *newname, *com2; + + cleanenv = login = 0; + exec_argv0 = argv0 = (char *)NULL; + + reset_internal_getopt (); + while ((opt = internal_getopt (list, "cla:")) != -1) + { + switch (opt) + { + case 'c': + cleanenv = 1; + break; + case 'l': + login = 1; + break; + case 'a': + argv0 = list_optarg; + break; + CASE_HELPOPT; + default: + builtin_usage (); + return (EX_USAGE); + } + } + list = loptend; + + /* First, let the redirections remain. */ + dispose_redirects (redirection_undo_list); + redirection_undo_list = (REDIRECT *)NULL; + + if (list == 0) + return (EXECUTION_SUCCESS); + +#if defined (RESTRICTED_SHELL) + if (restricted) + { + sh_restricted ((char *)NULL); + return (EXECUTION_FAILURE); + } +#endif /* RESTRICTED_SHELL */ + + args = strvec_from_word_list (list, 1, 0, (int *)NULL); + env = (char **)0; + + /* A command with a slash anywhere in its name is not looked up in $PATH. */ + command = absolute_program (args[0]) ? args[0] : search_for_command (args[0], 1); + + if (command == 0) + { + if (file_isdir (args[0])) + { +#if defined (EISDIR) + builtin_error (_("%s: cannot execute: %s"), args[0], strerror (EISDIR)); +#else + builtin_error (_("%s: cannot execute: %s"), args[0], strerror (errno)); +#endif + exit_value = EX_NOEXEC; + } + else + { + sh_notfound (args[0]); + exit_value = EX_NOTFOUND; /* As per Posix.2, 3.14.6 */ + } + goto failed_exec; + } + + com2 = full_pathname (command); + if (com2) + { + if (command != args[0]) + free (command); + command = com2; + } + + if (argv0) + { + free (args[0]); + args[0] = login ? mkdashname (argv0) : savestring (argv0); + exec_argv0 = savestring (args[0]); + } + else if (login) + { + newname = mkdashname (args[0]); + free (args[0]); + args[0] = newname; + } + + /* Decrement SHLVL by 1 so a new shell started here has the same value, + preserving the appearance. After we do that, we need to change the + exported environment to include the new value. If we've already forked + and are in a subshell, we don't want to decrement the shell level, + since we are `increasing' the level */ + + if (cleanenv == 0 && (subshell_environment & SUBSHELL_PAREN) == 0) + adjust_shell_level (-1); + + if (cleanenv) + { + env = strvec_create (1); + env[0] = (char *)0; + } + else + { + maybe_make_export_env (); + env = export_env; + } + +#if defined (HISTORY) + if (interactive_shell && subshell_environment == 0) + maybe_save_shell_history (); +#endif /* HISTORY */ + + restore_original_signals (); + +#if defined (JOB_CONTROL) + orig_job_control = job_control; /* XXX - was also interactive_shell */ + if (subshell_environment == 0) + end_job_control (); + if (interactive || job_control) + default_tty_job_signals (); /* undo initialize_job_signals */ +#endif /* JOB_CONTROL */ + +#if defined (BUFFERED_INPUT) + if (default_buffered_input >= 0) + sync_buffered_stream (default_buffered_input); +#endif + + exit_value = shell_execve (command, args, env); + + /* We have to set this to NULL because shell_execve has called realloc() + to stuff more items at the front of the array, which may have caused + the memory to be freed by realloc(). We don't want to free it twice. */ + args = (char **)NULL; + if (cleanenv == 0) + adjust_shell_level (1); + + if (exit_value == EX_NOTFOUND) /* no duplicate error message */ + goto failed_exec; + else if (executable_file (command) == 0) + { + builtin_error (_("%s: cannot execute: %s"), command, strerror (errno)); + exit_value = EX_NOEXEC; /* As per Posix.2, 3.14.6 */ + } + else + file_error (command); + +failed_exec: + FREE (command); + + if (subshell_environment || (interactive == 0 && no_exit_on_failed_exec == 0)) + exit_shell (exit_value); + + if (args) + strvec_dispose (args); + + if (env && env != export_env) + strvec_dispose (env); + + initialize_traps (); + initialize_signals (1); + +#if defined (JOB_CONTROL) + if (orig_job_control) + restart_job_control (); +#endif /* JOB_CONTROL */ + + return (exit_value); } diff --git a/bash-5.1/builtins/exit.def b/bash-5.1/builtins/exit.def index d79bcd6..dc6f3d5 100644 --- a/bash-5.1/builtins/exit.def +++ b/bash-5.1/builtins/exit.def @@ -53,13 +53,10 @@ 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) @@ -80,14 +77,11 @@ 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/hash.def b/bash-5.1/builtins/hash.def index 4291ac7..c58e91c 100644 --- a/bash-5.1/builtins/hash.def +++ b/bash-5.1/builtins/hash.def @@ -79,12 +79,10 @@ static int list_hashed_filename_targets PARAMS((WORD_LIST *, int)); /* Print statistics on the current state of hashed commands. If LIST is not empty, then rehash (or hash in the first place) the specified commands. */ -int r_hash_builtin (WORD_LIST *list); int hash_builtin (list) WORD_LIST *list; { -return r_hash_builtin(list); int expunge_hash_table, list_targets, list_portably, delete, opt; char *w, *pathname; diff --git a/bash-5.1/builtins/help.def b/bash-5.1/builtins/help.def index 6246919..f33b2b9 100644 --- a/bash-5.1/builtins/help.def +++ b/bash-5.1/builtins/help.def @@ -88,20 +88,10 @@ 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/setattr.def b/bash-5.1/builtins/setattr.def index f83dbee..33bef4c 100644 --- a/bash-5.1/builtins/setattr.def +++ b/bash-5.1/builtins/setattr.def @@ -76,7 +76,6 @@ int export_builtin (list) register WORD_LIST *list; { - return r_export_builtin(list); return (set_or_show_attributes (list, att_exported, 0)); } @@ -108,7 +107,6 @@ int readonly_builtin (list) register WORD_LIST *list; { - return r_readonly_builtin(list); return (set_or_show_attributes (list, att_readonly, 0)); } @@ -122,7 +120,7 @@ readonly_builtin (list) ATTRIBUTE. An arg of `-n' says to remove the attribute from the the remaining names in LIST (doesn't work for readonly). */ int -__set_or_show_attributes (list, attribute, nodefs) +set_or_show_attributes (list, attribute, nodefs) register WORD_LIST *list; int attribute, nodefs; { @@ -352,7 +350,7 @@ __set_or_show_attributes (list, attribute, nodefs) /* Show all variable variables (v == 1) or functions (v == 0) with attributes. */ int -__show_all_var_attributes (v, nodefs) +show_all_var_attributes (v, nodefs) int v, nodefs; { SHELL_VAR **variable_list, *var; @@ -376,7 +374,7 @@ __show_all_var_attributes (v, nodefs) /* Show all local variable variables with their attributes. This shows unset local variables (all_local_variables called with 0 argment). */ int -__show_local_var_attributes (v, nodefs) +show_local_var_attributes (v, nodefs) int v, nodefs; { SHELL_VAR **variable_list, *var; @@ -398,7 +396,7 @@ __show_local_var_attributes (v, nodefs) } int -__var_attribute_string (var, pattr, flags) +var_attribute_string (var, pattr, flags) SHELL_VAR *var; int pattr; char *flags; /* filled in with attributes */ @@ -470,7 +468,7 @@ __var_attribute_string (var, pattr, flags) or `readonly') instead of `declare', and doesn't print function defs when called by `export' or `readonly'. */ int -__show_var_attributes (var, pattr, nodefs) +show_var_attributes (var, pattr, nodefs) SHELL_VAR *var; int pattr, nodefs; { @@ -524,7 +522,7 @@ __show_var_attributes (var, pattr, nodefs) } int -__show_name_attributes (name, nodefs) +show_name_attributes (name, nodefs) char *name; int nodefs; { @@ -542,7 +540,7 @@ __show_name_attributes (name, nodefs) } int -__show_localname_attributes (name, nodefs) +show_localname_attributes (name, nodefs) char *name; int nodefs; { @@ -560,7 +558,7 @@ __show_localname_attributes (name, nodefs) } int -__show_func_attributes (name, nodefs) +show_func_attributes (name, nodefs) char *name; int nodefs; { @@ -578,7 +576,7 @@ __show_func_attributes (name, nodefs) } void -__set_var_attribute (name, attribute, undo) +set_var_attribute (name, attribute, undo) char *name; int attribute, undo; { diff --git a/bash-5.1/builtins/shopt.def b/bash-5.1/builtins/shopt.def index ecceed3..6dca224 100644 --- a/bash-5.1/builtins/shopt.def +++ b/bash-5.1/builtins/shopt.def @@ -94,17 +94,6 @@ extern int inherit_errexit; extern int localvar_inherit; extern int localvar_unset; -void r_reset_shopt_options (); -void r_set_bashopts (); -void r_set_compatibility_opts (); -int r_set_login_shell ( char *option_name, int mode); -char** r_get_shopt_options(); -void r_initialize_bashopts ( int no_bashopts); -void parse_bashopts ( char *value); - -int r_shopt_listopt ( char *name, int reusable); -int r_shopt_setopt (char *name, int mode); - #if defined (EXTENDED_GLOB) extern int extended_glob; #endif @@ -281,12 +270,10 @@ static int set_shopt_o_options PARAMS((int, WORD_LIST *, int)); #define OFLAG 0x08 #define PFLAG 0x10 -extern int r_shopt_builtin ( WORD_LIST *list); int shopt_builtin (list) WORD_LIST *list; { -return r_shopt_builtin(list); int opt, flags, rval; flags = 0; @@ -345,7 +332,6 @@ return r_shopt_builtin(list); void reset_shopt_options () { -return r_reset_shopt_options(); autocd = cdable_vars = cdspelling = 0; check_hashed_filenames = CHECKHASH_DEFAULT; check_window_size = CHECKWINSIZE_DEFAULT; @@ -690,7 +676,6 @@ set_compatibility_level (option_name, mode) void set_compatibility_opts () { -r_set_compatibility_opts (); shopt_compat31 = shopt_compat32 = 0; shopt_compat40 = shopt_compat41 = shopt_compat42 = shopt_compat43 = 0; shopt_compat44 = 0; @@ -750,7 +735,6 @@ set_login_shell (option_name, mode) char *option_name; int mode; { -return r_set_login_shell(option_name, mode); shopt_login_shell = login_shell != 0; return (0); } @@ -758,7 +742,6 @@ return r_set_login_shell(option_name, mode); char ** get_shopt_options () { -return r_get_shopt_options(); char **ret; int n, i; @@ -780,7 +763,6 @@ shopt_setopt (name, mode) char *name; int mode; { -return r_shopt_setopt(name, mode); WORD_LIST *wl; int r; @@ -795,7 +777,6 @@ shopt_listopt (name, reusable) char *name; int reusable; { -return r_shopt_listopt(name, reusable); int i; if (name == 0) @@ -815,7 +796,6 @@ return r_shopt_listopt(name, reusable); void set_bashopts () { -return r_set_bashopts(); char *value; char tflag[N_SHOPT_OPTIONS]; int vsize, i, vptr, *ip, exported; @@ -875,8 +855,6 @@ void parse_bashopts (value) char *value; { - -return r_parse_bashopts (value); char *vname; int vptr, ind; @@ -898,7 +876,6 @@ void initialize_bashopts (no_bashopts) int no_bashopts; { -return r_initialize_bashopts (no_bashopts); char *temp; SHELL_VAR *var; diff --git a/bash-5.1/builtins/type.def b/bash-5.1/builtins/type.def index d26801f..a8e47c0 100644 --- a/bash-5.1/builtins/type.def +++ b/bash-5.1/builtins/type.def @@ -77,7 +77,7 @@ $END #include "bashgetopt.h" extern int find_reserved_word PARAMS((char *)); -extern int r_type_builtin PARAMS((WORD_LIST *)); + /* For each word in LIST, find out what the shell is going to do with it as a simple command. i.e., which file would this shell use to execve, or if it is a builtin command, or an alias. Possible flag @@ -110,7 +110,6 @@ int type_builtin (list) WORD_LIST *list; { - return r_type_builtin(list); int dflags, any_failed, opt; WORD_LIST *this; diff --git a/bash-5.1/builtins/ulimit.def b/bash-5.1/builtins/ulimit.def index 6029913..a895c5e 100644 --- a/bash-5.1/builtins/ulimit.def +++ b/bash-5.1/builtins/ulimit.def @@ -220,7 +220,6 @@ static int filesize PARAMS((RLIMTYPE *)); static int pipesize PARAMS((RLIMTYPE *)); static int getmaxuprc PARAMS((RLIMTYPE *)); static int getmaxvm PARAMS((RLIMTYPE *, RLIMTYPE *)); -extern int r_ulimit_builtin PARAMS((WORD_LIST *)); typedef struct { int option; /* The ulimit option for this limit. */ @@ -333,7 +332,6 @@ int ulimit_builtin (list) register WORD_LIST *list; { - return r_ulimit_builtin(list); register char *s; int c, limind, mode, opt, all_limits; diff --git a/bash-5.1/builtins_rust/builtin/Cargo.toml b/bash-5.1/builtins_rust/builtin/Cargo.toml index c09d949..58c4dfb 100644 --- a/bash-5.1/builtins_rust/builtin/Cargo.toml +++ b/bash-5.1/builtins_rust/builtin/Cargo.toml @@ -1,14 +1,12 @@ [package] -name = "rbuiltin" +name = "builtin" version = "0.1.0" -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] name = "rbuiltin" -crate-type = ["staticlib","rlib"] +crate-type = ["staticlib"] [dependencies] libc = "0.2" -rcmd = {path="../cmd"} - diff --git a/bash-5.1/builtins_rust/builtin/src/intercdep.rs b/bash-5.1/builtins_rust/builtin/src/intercdep.rs index d07f2e3..adacec6 100644 --- a/bash-5.1/builtins_rust/builtin/src/intercdep.rs +++ b/bash-5.1/builtins_rust/builtin/src/intercdep.rs @@ -13,24 +13,32 @@ 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_FAILURE :c_int = 1; - +/* +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; - static mut this_command_name: *mut libc::c_char; + /* + pub fn print_timeval(fp: *mut libc::FILE, tvp: *mut libc::timeval); + pub fn sh_chkwrite(s: c_int) -> c_int; - fn sh_notbuiltin(_: *mut libc::c_char); - fn find_shell_builtin(_: *mut libc::c_char) -> Option::; - static mut this_shell_builtin: Option::; - static mut loptend: *mut WORD_LIST; + pub static stdout: *mut libc::FILE; + */ } - -pub type sh_builtin_func_t = unsafe extern "C" fn(*mut WORD_LIST) -> i32; diff --git a/bash-5.1/builtins_rust/builtin/src/lib.rs b/bash-5.1/builtins_rust/builtin/src/lib.rs index 00b9709..58025af 100644 --- a/bash-5.1/builtins_rust/builtin/src/lib.rs +++ b/bash-5.1/builtins_rust/builtin/src/lib.rs @@ -1,31 +1,27 @@ use libc::{c_int, c_char}; -use std::ffi::CStr; + include!(concat!("intercdep.rs")); #[no_mangle] -pub extern "C" fn r_builtin_builtin(mut list: *mut WORD_LIST) -> i32 { - unsafe{ - let mut function: Option:: = None; - let mut command: &CStr = CStr::from_ptr((*(*list).word).word as *mut c_char); - if no_options(list) != 0 { - return EX_USAGE; - } - list = loptend; - if list.is_null() { - return EXECUTION_SUCCESS; - } +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; + } - function = find_shell_builtin(command.as_ptr() as *mut c_char); - if function.is_none() { - sh_notbuiltin(command.as_ptr() as *mut c_char); - return EXECUTION_FAILURE; - } else { - this_command_name = command.as_ptr() as *mut c_char; - this_shell_builtin = function; - list = (*list).next; - return (Some(function.expect("non-null function pointer"))) - .expect("non-null function pointer")(list); - }; + 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 2212855..1c6a085 100644 --- a/bash-5.1/builtins_rust/cd/Cargo.toml +++ b/bash-5.1/builtins_rust/cd/Cargo.toml @@ -2,7 +2,8 @@ authors = ["huzhengming"] name = "rcd" version = "0.0.1" -edition = "2018" +build = "../build.rs" +edition = "2021" [dependencies] @@ -11,5 +12,5 @@ libc = "0.2" nix = "0.23.0" [lib] -crate-type = ["staticlib","rlib"] +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 adde5fa..9c3a021 100644 --- a/bash-5.1/builtins_rust/cd/src/lib.rs +++ b/bash-5.1/builtins_rust/cd/src/lib.rs @@ -2,7 +2,7 @@ extern crate libc; extern crate nix; use libc::{c_char, c_long, c_void}; -use std::{ffi::{CString, CStr}}; +use std::{ffi::CString}; #[repr(C)] pub struct WORD_DESC { @@ -492,7 +492,7 @@ pub extern "C" fn r_resetxattr () { } #[no_mangle] -pub extern "C" fn r_cd_builtin (mut list:*mut WORD_LIST)->i32 { +pub extern "C" fn r_cd_builtin (list:*mut WORD_LIST)->i32 { let mut dirname:*mut c_char=std::ptr::null_mut(); let cdpath:*mut c_char; let mut path:*mut c_char; @@ -502,168 +502,159 @@ pub extern "C" fn r_cd_builtin (mut list:*mut WORD_LIST)->i32 { let mut opt:i32; let mut lflag:i32; let e:i32; - unsafe { - if restricted !=0 { - sh_restricted (0 as * mut c_char); - return EXECUTION_FAILURE!(); - } - - eflag = 0; - no_symlinks = no_symbolic_links; - xattrflag = 0; - reset_internal_getopt (); - - let c_str_elp = CString::new("eLP").unwrap(); // from a &str, creates a new allocation - opt = internal_getopt (list, c_str_elp.as_ptr() as * mut c_char); - while opt != -1 { - let optu8:u8= opt as u8; - let optChar:char=char::from(optu8); - match optChar { - 'P'=>{no_symlinks = 1;} - 'L'=>{no_symlinks = 0;} - 'e'=>{eflag = 1;} - _=>{ - builtin_usage (); - return EX_USAGE!(); - } - } - opt =internal_getopt (list, c_str_elp.as_ptr() as * mut c_char); - } + if restricted !=0 { + sh_restricted (0 as * mut c_char); + return EXECUTION_FAILURE!(); + } - // list = loptend; //后加的 + eflag = 0; + no_symlinks = no_symbolic_links; + xattrflag = 0; + reset_internal_getopt (); + let c_str_elp = CString::new("eLP").unwrap(); // from a &str, creates a new allocation + opt = internal_getopt (list, c_str_elp.as_ptr() as * mut c_char); + while opt != -1 { + let optu8:u8= opt as u8; + let optChar:char=char::from(optu8); + match optChar { + 'P'=>{no_symlinks = 1;} + 'L'=>{no_symlinks = 0;} + 'e'=>{eflag = 1;} + _=>{ + builtin_usage (); + return EX_USAGE!(); + } + } + opt =internal_getopt (list, c_str_elp.as_ptr() as * mut c_char); + } - if cdable_vars != 0 { - lflag=LCD_DOVARS!(); - } else { - lflag=0; - } + if cdable_vars != 0 { + lflag=LCD_DOVARS!(); + } else { + lflag=0; + } - if interactive !=0 && cdspelling !=0 { - lflag=lflag | LCD_DOSPELL!(); - } else { - lflag=lflag | 0; - } + if interactive !=0 && cdspelling !=0 { + lflag=lflag | LCD_DOSPELL!(); + } else { + lflag=lflag | 0; + } - if eflag !=0 && no_symlinks == 0{ - eflag = 0; - } + if eflag !=0 && no_symlinks == 0{ + eflag = 0; + } - if loptend == std::ptr::null_mut() { + if loptend == std::ptr::null_mut() { /* `cd' without arguments is equivalent to `cd $HOME' */ dirname = get_string_value (CString::new("HOME").unwrap().as_ptr()); if dirname == std::ptr::null_mut() { builtin_error (CString::new("HOME not set").unwrap().as_ptr()); return EXECUTION_FAILURE!(); - } + } lflag = 0; - } - else if (*loptend).next != std::ptr::null_mut() { - builtin_error (CString::new("too many arguments").unwrap().as_ptr()); - return EXECUTION_FAILURE!(); - } - else if char::from((*(*(*loptend).word).word) as u8) == '-' && char::from(*((((*(*loptend).word).word) as usize +4) as *mut c_char) as u8) == '\0' { - /* This is `cd -', equivalent to `cd $OLDPWD' */ - dirname = get_string_value (CString::new("OLDPWD").unwrap().as_ptr()); - if dirname == std::ptr::null_mut() { - builtin_error (CString::new("OLDPWD not set").unwrap().as_ptr()); - return EXECUTION_FAILURE!(); - } - lflag = LCD_PRINTPATH!(); /* According to SUSv3 */ - } - else if absolute_pathname ((*(*loptend).word).word) !=0 { - dirname = (*(*loptend).word).word; - } - else if privileged_mode == 0 && get_string_value (CString::new("CDPATH").unwrap().as_ptr() ) != std::ptr::null_mut(){ - cdpath = get_string_value (CString::new("CDPATH").unwrap().as_ptr() ); - dirname = (*(*loptend).word).word; - - /* Find directory in $CDPATH. */ - path_index = 0; - path = extract_colon_unit (cdpath, & mut path_index); - - while path != std::ptr::null_mut() { + }else if (*loptend).next != std::ptr::null_mut() { + builtin_error (CString::new("too many arguments").unwrap().as_ptr()); + return EXECUTION_FAILURE!(); + }else if char::from((*(*(*loptend).word).word) as u8) == '-' && char::from(*((((*(*loptend).word).word) as usize +4) as *mut c_char) as u8) == '\0' { + /* This is `cd -', equivalent to `cd $OLDPWD' */ + dirname = get_string_value (CString::new("OLDPWD").unwrap().as_ptr()); + + if dirname == std::ptr::null_mut() { + builtin_error (CString::new("OLDPWD not set").unwrap().as_ptr()); + return EXECUTION_FAILURE!(); + } + lflag = LCD_PRINTPATH!(); /* According to SUSv3 */ + } else if absolute_pathname ((*(*loptend).word).word) !=0 { + dirname = (*(*loptend).word).word; + } else if privileged_mode == 0 { + cdpath = get_string_value (CString::new("CDPATH").unwrap().as_ptr() ); + if cdpath !=std::ptr::null_mut() { + dirname = (*(*loptend).word).word; + /* Find directory in $CDPATH. */ + path_index = 0; + path = extract_colon_unit (cdpath, & mut path_index); + while path != std::ptr::null_mut() { /* OPT is 1 if the path element is non-empty */ opt = (char::from(*path as u8 )!= '\0') as i32 ; temp = sh_makepath (path, dirname, MP_DOTILDE!()); libc::free (path as * mut c_void); - if r_change_to_directory (temp, no_symlinks, xattrflag) !=0 { - /* POSIX.2 says that if a nonempty directory from CDPATH - is used to find the directory to change to, the new - directory name is echoed to stdout, whether or not - the shell is interactive. */ - if opt !=0 { - if no_symlinks !=0 { - path=temp; - } - else { - path=the_current_working_directory; - } - - if path !=std::ptr::null_mut() { - libc::printf(CString::new("%s\n").unwrap().as_ptr() as * const c_char,path); - } - } - - libc::free (temp as * mut c_void); - return r_bindpwd (no_symlinks); - } - else { - libc::free (temp as * mut c_void); - } - - path = extract_colon_unit (cdpath, &mut path_index); + if r_change_to_directory (temp, no_symlinks, xattrflag) !=0 { + /* POSIX.2 says that if a nonempty directory from CDPATH + is used to find the directory to change to, the new + directory name is echoed to stdout, whether or not + the shell is interactive. */ + if opt !=0 { + if no_symlinks !=0 { + path=temp; + } else { + path=the_current_working_directory; + } + + if path !=std::ptr::null_mut() { + libc::printf(CString::new("%s\n").unwrap().as_ptr() as * const c_char,path); + } + } + + libc::free (temp as * mut c_void); + return r_bindpwd (no_symlinks); + + } else { + libc::free (temp as * mut c_void); } - } - else{ - dirname = (*(*loptend).word).word; + + path = extract_colon_unit (cdpath, &mut path_index); + } } + } else{ + dirname = (*(*loptend).word).word; + } - /* When we get here, DIRNAME is the directory to change to. If we - chdir successfully, just return. */ - if 0 != r_change_to_directory (dirname, no_symlinks, xattrflag) { - if (lflag & LCD_PRINTPATH!()) !=0 { - libc::printf(CString::new("%s\n").unwrap().as_ptr() as * const c_char,dirname); - } - return r_bindpwd (no_symlinks); + /* When we get here, DIRNAME is the directory to change to. If we + chdir successfully, just return. */ + if 0 != r_change_to_directory (dirname, no_symlinks, xattrflag) { + if (lflag & LCD_PRINTPATH!()) !=0 { + libc::printf(CString::new("%s\n").unwrap().as_ptr() as * const c_char,dirname); } + return r_bindpwd (no_symlinks); + } - /* If the user requests it, then perhaps this is the name of - a shell variable, whose value contains the directory to - change to. */ - if (lflag & LCD_DOVARS!()) !=0 { + /* If the user requests it, then perhaps this is the name of + a shell variable, whose value contains the directory to + change to. */ + if (lflag & LCD_DOVARS!()) !=0 { temp = get_string_value (dirname); if temp != std::ptr::null_mut() && r_change_to_directory (temp, no_symlinks, xattrflag) !=0 { libc::printf(CString::new("%s\n").unwrap().as_ptr() as * const c_char,temp); return r_bindpwd (no_symlinks); } - } + } - /* If the user requests it, try to find a directory name similar in - spelling to the one requested, in case the user made a simple - typo. This is similar to the UNIX 8th and 9th Edition shells. */ - if (lflag & LCD_DOSPELL!()) !=0 { - temp = dirspell (dirname); - if temp !=std::ptr::null_mut() && r_change_to_directory (temp, no_symlinks, xattrflag) !=0 { - println!("{:?}", temp); - libc::free (temp as * mut c_void); - return r_bindpwd (no_symlinks); - } else { - libc::free (temp as * mut c_void); - } - } + /* If the user requests it, try to find a directory name similar in + spelling to the one requested, in case the user made a simple + typo. This is similar to the UNIX 8th and 9th Edition shells. */ + if (lflag & LCD_DOSPELL!()) !=0 { + temp = dirspell (dirname); + if temp !=std::ptr::null_mut() && r_change_to_directory (temp, no_symlinks, xattrflag) !=0 { + println!("{:?}", temp); + libc::free (temp as * mut c_void); + return r_bindpwd (no_symlinks); + } else { + libc::free (temp as * mut c_void); + } + } - e =errno!(); - temp = printable_filename (dirname, 0); - builtin_error (CString::new("%s: %s").unwrap().as_ptr(), temp, libc::strerror (e)); + e =errno!(); + temp = printable_filename (dirname, 0); + builtin_error (CString::new("%s: %s").unwrap().as_ptr(), temp, libc::strerror (e)); - if temp != dirname { - libc::free (temp as * mut c_void); - } - return EXECUTION_FAILURE!(); + if temp != dirname { + libc::free (temp as * mut c_void); + } + return EXECUTION_FAILURE!(); } } diff --git a/bash-5.1/builtins_rust/colon/Cargo.toml b/bash-5.1/builtins_rust/colon/Cargo.toml index 3df1f22..f91e75f 100644 --- a/bash-5.1/builtins_rust/colon/Cargo.toml +++ b/bash-5.1/builtins_rust/colon/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "rcolon" version = "0.1.0" -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] -crate-type = ["staticlib","rlib"] +crate-type = ["staticlib"] name = "rcolon" [dependencies] diff --git a/bash-5.1/builtins_rust/complete/Cargo.toml b/bash-5.1/builtins_rust/complete/Cargo.toml index e18cffe..cf53520 100644 --- a/bash-5.1/builtins_rust/complete/Cargo.toml +++ b/bash-5.1/builtins_rust/complete/Cargo.toml @@ -2,8 +2,8 @@ authors = ["huzhengming"] name = "rcomplete" version = "0.0.1" - -edition = "2018" +##build = "../build.rs" +edition = "2021" [dependencies] @@ -12,5 +12,5 @@ libc = "0.2" nix = "0.23.0" [lib] -crate-type = ["staticlib","rlib"] +crate-type = ["cdylib"] name = "rcomplete" diff --git a/bash-5.1/builtins_rust/declare/Cargo.toml b/bash-5.1/builtins_rust/declare/Cargo.toml index 18e85d0..8f89ef8 100644 --- a/bash-5.1/builtins_rust/declare/Cargo.toml +++ b/bash-5.1/builtins_rust/declare/Cargo.toml @@ -2,7 +2,8 @@ authors = ["huzhengming"] name = "rdeclare" version = "0.0.1" -edition = "2018" +#build = "../build.rs" +edition = "2021" [dependencies] @@ -11,5 +12,5 @@ libc = "0.2" nix = "0.23.0" [lib] -crate-type = ["staticlib","rlib"] +crate-type = ["cdylib"] name = "rdeclare" diff --git a/bash-5.1/builtins_rust/fc/Cargo.toml b/bash-5.1/builtins_rust/fc/Cargo.toml index 499532a..5ed92c7 100644 --- a/bash-5.1/builtins_rust/fc/Cargo.toml +++ b/bash-5.1/builtins_rust/fc/Cargo.toml @@ -2,7 +2,8 @@ authors = ["huzhengming"] name = "rfc" version = "0.0.1" -edition = "2018" +build = "../build.rs" +edition = "2021" [dependencies] @@ -11,5 +12,5 @@ libc = "0.2" nix = "0.23.0" [lib] -crate-type = ["staticlib","rlib"] +crate-type = ["staticlib"] name = "rfc" diff --git a/bash-5.1/builtins_rust/fg_bg/Cargo.toml b/bash-5.1/builtins_rust/fg_bg/Cargo.toml index 26f78f3..a15ad2f 100644 --- a/bash-5.1/builtins_rust/fg_bg/Cargo.toml +++ b/bash-5.1/builtins_rust/fg_bg/Cargo.toml @@ -2,7 +2,8 @@ authors = ["huzhengming"] name = "rfg_bg" version = "0.0.1" -edition = "2018" +build = "../build.rs" +edition = "2021" [dependencies] @@ -11,5 +12,5 @@ libc = "0.2" nix = "0.23.0" [lib] -crate-type = ["staticlib","rlib"] +crate-type = ["staticlib"] name = "rfg_bg" diff --git a/bash-5.1/builtins_rust/getopts/Cargo.toml b/bash-5.1/builtins_rust/getopts/Cargo.toml index ca691a1..1e96f4e 100644 --- a/bash-5.1/builtins_rust/getopts/Cargo.toml +++ b/bash-5.1/builtins_rust/getopts/Cargo.toml @@ -2,7 +2,8 @@ authors = ["huzhengming"] name = "rgetopts" version = "0.0.1" -edition = "2018" +build = "../build.rs" +edition = "2021" [dependencies] @@ -11,5 +12,5 @@ libc = "0.2" nix = "0.23.0" [lib] -crate-type = ["staticlib","rlib"] +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 90b0793..9b66e82 100644 --- a/bash-5.1/builtins_rust/getopts/src/lib.rs +++ b/bash-5.1/builtins_rust/getopts/src/lib.rs @@ -546,3 +546,13 @@ pub extern "C" fn r_getopts_builtin(list: * mut WORD_LIST)->i32 return ret; } } + +/* +#[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); +}*/ diff --git a/bash-5.1/builtins_rust/history/Cargo.toml b/bash-5.1/builtins_rust/history/Cargo.toml index 4835035..cba7b26 100644 --- a/bash-5.1/builtins_rust/history/Cargo.toml +++ b/bash-5.1/builtins_rust/history/Cargo.toml @@ -1,15 +1,15 @@ [package] -name = "rhistory" +name = "history" version = "0.1.0" -edition = "2018" +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 = "rhistory" -crate-type = ["staticlib","rlib"] +crate-type = ["cdylib"] [dependencies] libc = "0.2" diff --git a/bash-5.1/builtins_rust/jobs/Cargo.toml b/bash-5.1/builtins_rust/jobs/Cargo.toml index d2db00b..820ebeb 100644 --- a/bash-5.1/builtins_rust/jobs/Cargo.toml +++ b/bash-5.1/builtins_rust/jobs/Cargo.toml @@ -2,7 +2,8 @@ authors = ["huzhengming"] name = "rjobs" version = "0.0.1" -edition = "2018" +build = "../build.rs" +edition = "2021" [dependencies] @@ -11,5 +12,6 @@ libc = "0.2" nix = "0.23.0" [lib] -crate-type = ["staticlib","rlib"] +crate-type = ["staticlib"] +#crate-type = ["cdylib"] 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 3f74083..2f97485 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 { - pub next: *mut WORD_LIST, - pub word: *mut WORD_DESC + next: *mut WORD_LIST, + word: *mut WORD_DESC } #[repr(i8)] diff --git a/bash-5.1/builtins_rust/kill/Cargo.toml b/bash-5.1/builtins_rust/kill/Cargo.toml index 0f2128e..0c411d8 100644 --- a/bash-5.1/builtins_rust/kill/Cargo.toml +++ b/bash-5.1/builtins_rust/kill/Cargo.toml @@ -1,15 +1,15 @@ [package] -name = "rkill" +name = "kill" version = "0.1.0" -edition = "2018" +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 = "rkill" -crate-type = ["staticlib","rlib"] +crate-type = ["cdylib"] [dependencies] libc = "0.2" diff --git a/bash-5.1/builtins_rust/kill/src/lib.rs b/bash-5.1/builtins_rust/kill/src/lib.rs index 435e8ef..5f294f1 100644 --- a/bash-5.1/builtins_rust/kill/src/lib.rs +++ b/bash-5.1/builtins_rust/kill/src/lib.rs @@ -192,7 +192,7 @@ unsafe { 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 + return str[0] == b'-' && str[1] == c && str[2] != 0 } unsafe fn kill_error(pid: libc::pid_t, e: c_int) @@ -203,4 +203,4 @@ unsafe fn kill_error(pid: libc::pid_t, e: c_int) } builtin_error("(%ld) - %s".as_ptr() as *const c_char, pid, x); -} +} \ No newline at end of file diff --git a/bash-5.1/builtins_rust/mapfile/Cargo.toml b/bash-5.1/builtins_rust/mapfile/Cargo.toml index 003233b..91ffc2e 100644 --- a/bash-5.1/builtins_rust/mapfile/Cargo.toml +++ b/bash-5.1/builtins_rust/mapfile/Cargo.toml @@ -1,15 +1,15 @@ [package] -name = "rmapfile" +name = "mapfile" version = "0.1.0" -edition = "2018" +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 = ["staticlib","rlib"] +crate-type = ["cdylib"] [dependencies] libc = "0.2" diff --git a/bash-5.1/builtins_rust/printf/Cargo.toml b/bash-5.1/builtins_rust/printf/Cargo.toml index cde8443..56d9f43 100644 --- a/bash-5.1/builtins_rust/printf/Cargo.toml +++ b/bash-5.1/builtins_rust/printf/Cargo.toml @@ -1,14 +1,15 @@ [package] -name = "rprintf" +name = "printf" version = "0.1.0" -edition = "2018" +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 = ["staticlib","rlib"] +crate-type = ["cdylib"] [dependencies] libc = "0.2" diff --git a/bash-5.1/builtins_rust/pushd/Cargo.toml b/bash-5.1/builtins_rust/pushd/Cargo.toml index cfd6cdc..fe91da3 100644 --- a/bash-5.1/builtins_rust/pushd/Cargo.toml +++ b/bash-5.1/builtins_rust/pushd/Cargo.toml @@ -2,7 +2,8 @@ authors = ["huzhengming"] name = "rpushd" version = "0.0.1" -edition = "2018" +#build = "../build.rs" +edition = "2021" [dependencies] @@ -11,5 +12,5 @@ libc = "0.2" nix = "0.23.0" [lib] -crate-type = ["staticlib","rlib"] +crate-type = ["cdylib"] name = "rpushd" diff --git a/bash-5.1/builtins_rust/read/Cargo.toml b/bash-5.1/builtins_rust/read/Cargo.toml index 72f08ad..806c5f8 100644 --- a/bash-5.1/builtins_rust/read/Cargo.toml +++ b/bash-5.1/builtins_rust/read/Cargo.toml @@ -1,14 +1,16 @@ [package] name = "read" version = "0.1.0" -edition = "2018" +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 = "rread" -crate-type = ["staticlib", "rlib"] +#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 c468265..74272cf 100644 --- a/bash-5.1/builtins_rust/rlet/Cargo.toml +++ b/bash-5.1/builtins_rust/rlet/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "rlet" version = "0.1.0" -edition = "2018" +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 = ["staticlib","rlib"] +crate-type = ["cdylib"] [dependencies] libc = "0.2" diff --git a/bash-5.1/builtins_rust/rreturn/Cargo.toml b/bash-5.1/builtins_rust/rreturn/Cargo.toml index 6645b22..2272f33 100644 --- a/bash-5.1/builtins_rust/rreturn/Cargo.toml +++ b/bash-5.1/builtins_rust/rreturn/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rreturn" version = "0.1.0" -edition = "2018" +edition = "2021" authors = ["lvgenggeng"] #build = "../build.rs" @@ -9,7 +9,7 @@ authors = ["lvgenggeng"] [lib] name = "rreturn" -crate-type = ["staticlib","rlib"] +crate-type = ["cdylib"] [dependencies] libc = "0.2" diff --git a/bash-5.1/builtins_rust/shift/Cargo.toml b/bash-5.1/builtins_rust/shift/Cargo.toml index 350421e..e53a57f 100644 --- a/bash-5.1/builtins_rust/shift/Cargo.toml +++ b/bash-5.1/builtins_rust/shift/Cargo.toml @@ -1,15 +1,15 @@ [package] -name = "rshift" +name = "shift" version = "0.1.0" -edition = "2018" +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 = ["staticlib","rlib"] +crate-type = ["cdylib"] [dependencies] libc = "0.2" diff --git a/bash-5.1/builtins_rust/source/Cargo.toml b/bash-5.1/builtins_rust/source/Cargo.toml index 91e3163..a69f0c7 100644 --- a/bash-5.1/builtins_rust/source/Cargo.toml +++ b/bash-5.1/builtins_rust/source/Cargo.toml @@ -2,7 +2,8 @@ authors = ["huzhengming"] name = "rsource" version = "0.0.1" -edition = "2018" +#build = "../build.rs" +edition = "2021" [dependencies] @@ -11,5 +12,5 @@ libc = "0.2" nix = "0.23.0" [lib] -crate-type = ["staticlib","rlib"] +crate-type = ["cdylib"] name = "rsource" diff --git a/bash-5.1/builtins_rust/suspend/Cargo.toml b/bash-5.1/builtins_rust/suspend/Cargo.toml index fb50d5d..c758cc9 100644 --- a/bash-5.1/builtins_rust/suspend/Cargo.toml +++ b/bash-5.1/builtins_rust/suspend/Cargo.toml @@ -1,15 +1,15 @@ [package] -name = "rsuspend" +name = "suspend" version = "0.1.0" -edition = "2018" +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 = ["staticlib","rlib"] +crate-type = ["cdylib"] [dependencies] libc = "0.2" diff --git a/bash-5.1/builtins_rust/test/Cargo.toml b/bash-5.1/builtins_rust/test/Cargo.toml index ed8f9dd..2e66e53 100644 --- a/bash-5.1/builtins_rust/test/Cargo.toml +++ b/bash-5.1/builtins_rust/test/Cargo.toml @@ -1,15 +1,15 @@ [package] -name = "rtest" +name = "test" version = "0.1.0" -edition = "2018" +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 = ["staticlib","rlib"] +crate-type = ["cdylib"] [dependencies] libc = "0.2" diff --git a/bash-5.1/builtins_rust/times/Cargo.toml b/bash-5.1/builtins_rust/times/Cargo.toml index 109108f..4067fac 100644 --- a/bash-5.1/builtins_rust/times/Cargo.toml +++ b/bash-5.1/builtins_rust/times/Cargo.toml @@ -1,15 +1,15 @@ [package] -name = "rtimes" +name = "times" version = "0.1.0" -edition = "2018" +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 = ["staticlib","rlib"] +crate-type = ["cdylib"] [dependencies] libc = "0.2" diff --git a/record.txt b/record.txt index 2d5477d..e2fdd0a 100644 --- a/record.txt +++ b/record.txt @@ -29,3 +29,4 @@ 28 29 30 +31 -- Gitee