diff --git a/bash-5.1/Cargo.toml b/bash-5.1/Cargo.toml index 595ff04a526f3c51f01f20ab870596e1678de811..0c967670afade1c367ba5e87fb5f37d845513d73 100644 --- a/bash-5.1/Cargo.toml +++ b/bash-5.1/Cargo.toml @@ -61,6 +61,7 @@ members=[ "builtins_rust/trap", "builtins_rust/setattr", "builtins_rust/source", + "builtins_rust/exec_cmd", ] [dependencies] @@ -100,3 +101,4 @@ members=[ rumask = {path = "./builtins_rust/umask"} rwait = {path = "./builtins_rust/wait"} rdeclare = {path = "./builtins_rust/declare"} + rexec_cmd = {path = "./builtins_rust/exec_cmd"} diff --git a/bash-5.1/Makefile.in b/bash-5.1/Makefile.in index 019ead7c23d64a18534266d8c550e98f9ad9e30d..30ddc175d57f4d239b2a20ebc0b3a59a6a075872 100644 --- a/bash-5.1/Makefile.in +++ b/bash-5.1/Makefile.in @@ -139,7 +139,7 @@ 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 -lralias -lrbind -lrbreak -lrbuiltin -lrcaller -lrcd -lrcolon -lrcommon -lrcommand -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 -lrexec_cmd LIBS_FOR_BUILD = STATIC_LD = @STATIC_LD@ @@ -575,7 +575,7 @@ LOADABLES_DIR = ${top_builddir}/examples/loadables RUST_DIR = $(top_builddir)/builtins_rust #RUST_TARGET_LIB = $(top_builddir)/target/debug/librjobs.a $(top_builddir)/target/debug/librread.a -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)/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_DIR)/exec_cmd # Keep GNU Make from exporting the entire environment for small machines. diff --git a/bash-5.1/builtins/command.def b/bash-5.1/builtins/command.def index acd46cc1be0062d1ca15777821e1b309645bdb3e..f538122dabbb1c70c075b8c6d0644c0c6aaddd1d 100644 --- a/bash-5.1/builtins/command.def +++ b/bash-5.1/builtins/command.def @@ -60,12 +60,14 @@ $END extern size_t confstr PARAMS((int, char *, size_t)); #endif +int r_command_builtin ( WORD_LIST *list); /* Run the commands mentioned in LIST without paying attention to shell functions. */ int command_builtin (list) WORD_LIST *list; { +return r_command_builtin ( list); int result, verbose, use_standard_path, opt; COMMAND *command; diff --git a/bash-5.1/builtins/complete.def b/bash-5.1/builtins/complete.def index 28a9ec2f9a5ee9869056016a3a1543fed025f293..973341975268e40afc0c211c6e9f33635861708d 100644 --- a/bash-5.1/builtins/complete.def +++ b/bash-5.1/builtins/complete.def @@ -365,11 +365,13 @@ build_actions (list, flagp, actp, optp) return (opt_given ? EXECUTION_SUCCESS : EXECUTION_FAILURE); } +int r_complete_builtin ( WORD_LIST *list); /* Add, remove, and display completion specifiers. */ int complete_builtin (list) WORD_LIST *list; { +return r_complete_builtin (list); int opt_given, rval; unsigned long acts, copts; COMPSPEC *cs; diff --git a/bash-5.1/builtins/declare.def b/bash-5.1/builtins/declare.def index 21e4516d194abbc5eb4b0abdd01c4f3858b300e1..aee4afb1be2a76a68d24da5835bbdc5e48802ae8 100644 --- a/bash-5.1/builtins/declare.def +++ b/bash-5.1/builtins/declare.def @@ -92,13 +92,14 @@ $END static SHELL_VAR *declare_find_variable PARAMS((const char *, int, int)); static int declare_internal PARAMS((register WORD_LIST *, int)); +int r_declare_internal PARAMS((register WORD_LIST *, int)); /* Declare or change variable attributes. */ int declare_builtin (list) register WORD_LIST *list; { - return (declare_internal (list, 0)); + return (r_declare_internal (list, 0)); } $BUILTIN local @@ -128,7 +129,7 @@ local_builtin (list) } if (variable_context) - return (declare_internal (list, 1)); + return (r_declare_internal (list, 1)); else { builtin_error (_("can only be used in a function")); diff --git a/bash-5.1/builtins/pushd.def b/bash-5.1/builtins/pushd.def index 829f827d5dc7c3d2e2cd7852e6e0b5224b9f6d49..de1bb2df1809c71e1e0636837fedfe554c52e358 100644 --- a/bash-5.1/builtins/pushd.def +++ b/bash-5.1/builtins/pushd.def @@ -169,10 +169,13 @@ static int get_dirstack_index PARAMS((intmax_t, int, int *)); #define LONGFORM 0x04 #define CLEARSTAK 0x08 +int r_pushd_builtin ( WORD_LIST *list); + int pushd_builtin (list) WORD_LIST *list; { +return r_pushd_builtin(list); WORD_LIST *orig_list; char *temp, *current_directory, *top; int j, flags, skipopt; @@ -312,13 +315,15 @@ pushd_builtin (list) } } +int +r_popd_builtin ( + WORD_LIST *list); /* Pop the directory stack, and then change to the new top of the stack. If LIST is non-null it should consist of a word +N or -N, which says what element to delete from the stack. The default is the top one. */ -int -popd_builtin (list) - WORD_LIST *list; +int popd_builtin ( WORD_LIST *list) { +return r_popd_builtin(list); register int i; intmax_t which; int flags; diff --git a/bash-5.1/builtins/source.def b/bash-5.1/builtins/source.def index 5b2f994db414d08a87cc64e5e0f706f4ee9e3d48..930d1a882a6216b1ef0f94af1e5fb68c162e5c64 100644 --- a/bash-5.1/builtins/source.def +++ b/bash-5.1/builtins/source.def @@ -108,14 +108,14 @@ maybe_pop_dollar_vars () invalidate_cached_quoted_dollar_at (); /* just invalidate to be safe */ } +int r_source_builtin ( WORD_LIST *list); /* Read and execute commands from the file passed as argument. Guess what. This cannot be done in a subshell, since things like variable assignments take place in there. So, I open the file, place it into a large string, close the file, and then execute the string. */ -int -source_builtin (list) - WORD_LIST *list; +int source_builtin ( WORD_LIST *list) { +return r_source_builtin (list); int result; char *filename, *debug_trap, *x; diff --git a/bash-5.1/builtins_rust/command/src/lib.rs b/bash-5.1/builtins_rust/command/src/lib.rs index c5d6d2b833b0b816447e2e1550e76ad921281c44..b7f593deeadd6d95c9875232fbc8a00b5c1b3500 100644 --- a/bash-5.1/builtins_rust/command/src/lib.rs +++ b/bash-5.1/builtins_rust/command/src/lib.rs @@ -284,7 +284,7 @@ pub const CMD_STDPATH :i32 = 0x4000; pub const CMD_TRY_OPTIMIZING :i32 = 0x8000; #[no_mangle] -pub unsafe extern "C" fn command_builtin(mut list: *mut WordList) -> libc::c_int { +pub unsafe extern "C" fn r_command_builtin(mut list: *mut WordList) -> libc::c_int { let mut result: libc::c_int = 0; let mut verbose: libc::c_int = 0; let mut use_standard_path: libc::c_int = 0; diff --git a/bash-5.1/builtins_rust/complete/src/lib.rs b/bash-5.1/builtins_rust/complete/src/lib.rs index cc1f283697f8dfdc6025c25244d61a686cfe1b3c..9dd58df4447e7ed94457e37ea33b672002f9442f 100644 --- a/bash-5.1/builtins_rust/complete/src/lib.rs +++ b/bash-5.1/builtins_rust/complete/src/lib.rs @@ -1376,12 +1376,3 @@ pub extern "C" fn r_compopt_builtin (listt:* mut WordList)->i32 } } -#[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 WordList)->i32 { - return r_complete_builtin(list); -} diff --git a/bash-5.1/builtins_rust/declare/src/lib.rs b/bash-5.1/builtins_rust/declare/src/lib.rs index 225e7aa749f6665dc27b448c512264b97b62018c..eede3a82011608e5b881dbe1b6343bb3b3550b8d 100644 --- a/bash-5.1/builtins_rust/declare/src/lib.rs +++ b/bash-5.1/builtins_rust/declare/src/lib.rs @@ -3,7 +3,6 @@ extern crate nix; use libc::{c_char, c_long, c_void}; use std::{ffi::CString}; -// use rcommon::{r_sh_notfound,r_sh_invalidopt,r_sh_invalidid,r_sh_readonly,r_sh_chkwrite,}; use rcommon::{WordList, WordDesc, EX_USAGE, EXECUTION_SUCCESS, EXECUTION_FAILURE}; @@ -1516,12 +1515,3 @@ pub extern "C" fn r_declare_internal (list:* mut WordList, local_var:i32)->i32 } } -#[no_mangle] -pub extern "C" fn cmd_name() ->*const u8 { - return b"declare" as *const u8; -} - -#[no_mangle] -pub extern "C" fn run(list : *mut WordList)->i32 { - return r_declare_builtin(list); -} diff --git a/bash-5.1/builtins_rust/exec_cmd/Cargo.toml b/bash-5.1/builtins_rust/exec_cmd/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..9a416d5bf8341a7cda20084a15915772ec2f0928 --- /dev/null +++ b/bash-5.1/builtins_rust/exec_cmd/Cargo.toml @@ -0,0 +1,57 @@ +[package] +authors = ["zhanghuanhuan"] +name = "rexec_cmd" +version = "0.0.1" +edition = "2021" +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ralias = {path="../alias"} +rbind = {path="../bind"} +rbreak= {path="../break_1"} +rbuiltin = {path="../builtin"} +rcaller = {path="../caller"} +rcd = {path="../cd"} +rcmd = {path="../cmd"} +rcolon = {path="../colon"} +command = {path="../command"} +rcommon = {path="../common"} +rcomplete = {path="../complete"} +rdeclare = {path="../declare"} +recho = {path="../echo"} +renable = {path="../enable"} +reval = {path="../eval"} +rexec = {path="../exec"} +rexit = {path="../exit"} +rfc = {path="../fc"} +rfg_bg = {path="../fg_bg"} +rgetopts = {path="../getopts"} +rhash = {path="../hash"} +rhelp = {path="../help"} +rhistory = {path="../history"} +rjobs = {path="../jobs"} +rkill = {path="../kill"} +rmapfile = {path="../mapfile"} +rprintf = {path="../printf"} +rpushd = {path="../pushd"} +rread = {path="../read"} +rlet = {path="../rlet"} +rreturn = {path="../rreturn"} +rset = {path="../set"} +rsetattr = {path="../setattr"} +rshift = {path="../shift"} +rshopt = {path="../shopt"} +rsource = {path="../source"} +rsuspend = {path="../suspend"} +rtest = {path="../test"} +rtimes = {path="../times"} +rtrap = {path="../trap"} +rtype = {path="../type"} +rulimit = {path="../ulimit"} +rumask = {path="../umask"} +rwait = {path="../wait"} + +[lib] +crate-type = ["staticlib","rlib"] +name = "rexec_cmd" + diff --git a/bash-5.1/builtins_rust/exec_cmd/src/lib.rs b/bash-5.1/builtins_rust/exec_cmd/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..80f93ef6663c1426f197c2817779e7c525756ffd --- /dev/null +++ b/bash-5.1/builtins_rust/exec_cmd/src/lib.rs @@ -0,0 +1,676 @@ +use rcommon::{WordList, WordDesc}; +use ralias::r_alias_builtin; +use rbind::r_bind_builtin; +use rbreak::r_break_builtin; +use rbuiltin::r_builtin_builtin; +use rcaller::r_caller_builtin; +use rcd::r_cd_builtin; +//use rcmd::r_cmd_builtin; +use rcolon::r_colon_builtin; +//use command::command_builtin; +//use rcommon ::r__builtin; +use rcomplete::r_complete_builtin; +use rdeclare::r_declare_builtin; +use recho::r_echo_builtin; +use renable::r_enable_builtin; +use reval::r_eval_builtin; +use rexec::r_exec_builtin; +use rexit::r_exit_builtin; +use rfc::r_fc_builtin; +use rfg_bg::r_fg_builtin; +use rgetopts::r_getopts_builtin; +use rhash::r_hash_builtin; +use rhelp::r_help_builtin; +use rhistory::r_history_builtin; +use rjobs::r_jobs_builtin; +use rkill::r_kill_builtin; +use rmapfile::r_mapfile_builtin; +use rprintf::r_printf_builtin; +use rpushd::r_pushd_builtin; +use rread::r_read_builtin; +use rlet::r_let_builtin; +use rreturn::r_return_builtin; +use rset::r_set_builtin; +//use rsetattr::r_setattr_builtin; +use rshift::r_shift_builtin; +use rshopt::r_shopt_builtin; +use rsource::r_source_builtin; +use rsuspend::r_suspend_builtin; +use rtest::r_test_builtin; +use rtimes::r_times_builtin; +use rtrap::r_trap_builtin; +use rtype::r_type_builtin; +use rulimit::r_ulimit_builtin; +use rumask::r_umask_builtin; +use rwait::r_wait_builtin; + +enum CMDType { + AliasCmd, + BindCmd, + BreakCmd, + BuiltinCmd, + CallerCmd, + CdCmd, + ColonCmd, + CommandCmd, + CommonCmd, + CompleteCmd, + DeclareCmd, + EchoCmd, + EnableCmd, + EvalCmd, + ExecCmd, + ExitCmd, + FcCmd, + FgbgCmd, + GetoptsCmd, + HashCmd, + HelpCmd, + HistoryCmd, + JobsCmd, + KillCmd, + LetCmd, + MapfileCmd, + PrintfCmd, + PushdCmd, + ReadCmd, + ReservedCmd, + ReturnCmd, + SetattrCmd, + SetCmd, + ShiftCmd, + ShoptCmd, + SourceCmd, + SuspendCmd, + TestCmd, + TimesCmd, + TrapCmd, + TypeCmd, + UlimitCmd, + UmaskCmd, + WaitCmd +} + + struct AliasComand ; + impl CommandExec for AliasComand{ + fn excute(&self,list : *mut WordList){ + unsafe { + r_alias_builtin(list); + } + } + } + struct BindComand; + impl CommandExec for BindComand{ + fn excute(&self,list : *mut WordList){ + r_bind_builtin(list); + } +} + struct BreakComand; + impl CommandExec for BreakComand{ + fn excute(&self,list : *mut WordList){ + r_break_builtin(list); + } +} + struct BuiltinComand; + impl CommandExec for BuiltinComand{ + fn excute(&self,list : *mut WordList){ + r_builtin_builtin(list); + } +} + struct CallerComand; + impl CommandExec for CallerComand{ + fn excute(&self,list : *mut WordList){ + r_caller_builtin(list); + } +} + struct CdComand; + impl CommandExec for CdComand{ + fn excute(&self,list : *mut WordList){ + r_cd_builtin(list); + } +} + struct ColonComand; + impl CommandExec for ColonComand{ + fn excute(&self,list :*mut WordList){ + // r_colon_builtin(list); + } +} + struct CommandComand; + impl CommandExec for CommandComand{ + fn excute(&self,list : *mut WordList){ + //command_builtin(list); + } +} + struct CommonComand; + impl CommandExec for CommonComand{ + fn excute(&self,list : *mut WordList){ + unsafe { + r_alias_builtin(list); + } + } +} + struct CompleteComand; + impl CommandExec for CompleteComand{ + fn excute(&self,list : *mut WordList){ + r_complete_builtin(list); + } +} + struct DeclareComand; + impl CommandExec for DeclareComand{ + fn excute(&self,list : *mut WordList){ + r_declare_builtin(list); + } +} + struct EchoComand; + impl CommandExec for EchoComand{ + fn excute(&self,list : *mut WordList){ + r_echo_builtin(list); + } +} + struct EnableComand; + impl CommandExec for EnableComand{ + fn excute(&self,list : *mut WordList){ + unsafe { + r_enable_builtin(list); + } + } +} + struct EvalComand; + impl CommandExec for EvalComand{ + fn excute(&self,list : *mut WordList){ + r_eval_builtin(list); + } +} + struct ExecComand; + impl CommandExec for ExecComand{ + fn excute(&self,list : *mut WordList){ + r_exec_builtin(list); + } +} + struct ExitComand; + impl CommandExec for ExitComand{ + fn excute(&self,list : *mut WordList){ + r_exit_builtin(list); + } +} + struct FcComand; + impl CommandExec for FcComand{ + fn excute(&self,list : *mut WordList){ + r_fc_builtin(list); + } +} + struct FgbgComand; + impl CommandExec for FgbgComand{ + fn excute(&self,list : *mut WordList){ + r_fg_builtin(list); + } +} + struct GetoptsComand; + impl CommandExec for GetoptsComand{ + fn excute(&self,list : *mut WordList){ + r_getopts_builtin(list); + } +} + struct HashComand; + impl CommandExec for HashComand{ + fn excute(&self,list : *mut WordList){ + r_hash_builtin(list); + } +} + struct HelpComand; + impl CommandExec for HelpComand{ + fn excute(&self,list : *mut WordList){ + r_help_builtin(list); + } +} + struct HistoryComand; + impl CommandExec for HistoryComand{ + fn excute(&self,list : *mut WordList){ + r_history_builtin(list); + } +} + struct JobsComand; + impl CommandExec for JobsComand{ + fn excute(&self,list : *mut WordList){ + r_jobs_builtin(list); + } +} + struct KillComand; + impl CommandExec for KillComand{ + fn excute(&self,list : *mut WordList){ + r_kill_builtin(list); + } +} + struct LetComand; + impl CommandExec for LetComand{ + fn excute(&self,list : *mut WordList){ + r_let_builtin(list); + } +} + struct MapfileComand; + impl CommandExec for MapfileComand{ + fn excute(&self,list : *mut WordList){ + r_mapfile_builtin(list); + } +} + struct PrintfComand; + impl CommandExec for PrintfComand{ + fn excute(&self,list : *mut WordList){ + r_printf_builtin(list); + } +} + struct PushdComand; + impl CommandExec for PushdComand{ + fn excute(&self,list : *mut WordList){ + r_pushd_builtin(list); + } +} + struct ReadComand; + impl CommandExec for ReadComand{ + fn excute(&self,list : *mut WordList){ + r_read_builtin(list); + } +} + struct ReservedComand; + impl CommandExec for ReservedComand{ + fn excute(&self,list : *mut WordList){ + //r_reserve_builtin(list); + } +} + struct ReturnComand; + impl CommandExec for ReturnComand{ + fn excute(&self,list : *mut WordList){ + r_return_builtin(list); + } +} + struct SetattrComand; + impl CommandExec for SetattrComand{ + fn excute(&self,list : *mut WordList){ + //r_setattr_builtin(list); + /*unkown enter which func */ + } + +} + struct SetComand; + impl CommandExec for SetComand{ + fn excute(&self,list : *mut WordList){ + r_set_builtin(list); + } + +} + struct ShiftComand; + impl CommandExec for ShiftComand{ + fn excute(&self,list : *mut WordList){ + r_shift_builtin(list); + } +} + struct ShoptComand; + impl CommandExec for ShoptComand{ + fn excute(&self,list : *mut WordList){ + unsafe { + r_shopt_builtin(list); + } + } +} + struct SourceComand; + impl CommandExec for SourceComand{ + fn excute(&self,list : *mut WordList){ + r_source_builtin(list); + } +} + struct SuspendComand; + impl CommandExec for SuspendComand{ + fn excute(&self,list : *mut WordList){ + r_suspend_builtin(list); + } +} + struct TestComand; + impl CommandExec for TestComand{ + fn excute(&self,list : *mut WordList){ + r_test_builtin(list); + } +} + struct TimesComand; + impl CommandExec for TimesComand{ + fn excute(&self,list : *mut WordList){ + r_times_builtin(list); + } +} + struct TrapComand; + impl CommandExec for TrapComand{ + fn excute(&self,list : *mut WordList){ + r_trap_builtin(list); + } +} + struct TypeComand; + impl CommandExec for TypeComand{ + fn excute(&self,list : *mut WordList){ + unsafe { + r_type_builtin(list); + } + + } + +} + struct UlimitComand; + impl CommandExec for UlimitComand{ + fn excute(&self,list : *mut WordList){ + unsafe { + r_ulimit_builtin(list); + } + } + +} + struct UmaskComand; + impl CommandExec for UmaskComand{ + fn excute(&self,list : *mut WordList){ + r_umask_builtin(list); + } +} + struct WaitComand; + impl CommandExec for WaitComand{ + fn excute(&self,list : *mut WordList){ + r_wait_builtin(list); + } +} + +// 定义接口 +pub trait CommandExec { + fn excute(&self,list : *mut WordList); +} + + +// 工厂模式 +trait Factory { + fn make_product(&self, product_type : CMDType) ->Box; +} + +struct SimpleFactory; +impl SimpleFactory { + fn new() -> Self { + Self + } +} + +impl Factory for SimpleFactory { + fn make_product(&self, cmd_type : CMDType) -> Box { + match cmd_type { + CMDType::AliasCmd => Box::new( + AliasComand{} + ) , + CMDType::BindCmd => Box::new( + BindComand{} + ), + CMDType::BreakCmd => Box::new( + BreakComand{} + ) , + CMDType::BuiltinCmd => Box::new( + BuiltinComand{} + ), + CMDType::CallerCmd => Box::new( + CallerComand{} + ), + CMDType::CdCmd => Box::new( + CdComand{} + ), + CMDType::ColonCmd => Box::new( + ColonComand{} + ), + CMDType::CommandCmd => Box::new( + CommandComand{} + ), + CMDType::CommonCmd => Box::new( + CommandComand{} + ), + CMDType::CompleteCmd => Box::new( + CompleteComand{} + ), + CMDType::DeclareCmd => Box::new( + DeclareComand{} + ), + CMDType::EchoCmd => Box::new( + EchoComand{} + ), + CMDType::EnableCmd => Box::new( + EnableComand{} + ), + CMDType::EvalCmd => Box::new( + EvalComand{} + ), + CMDType::ExecCmd => Box::new( + ExecComand{} + ), + CMDType::ExitCmd => Box::new( + ExitComand{} + ), + CMDType::FcCmd => Box::new( + FcComand{} + ), + CMDType::FgbgCmd => Box::new( + FgbgComand{} + ), + CMDType::GetoptsCmd => Box::new( + GetoptsComand{} + ), + CMDType::HashCmd => Box::new( + HashComand{} + ), + CMDType::HelpCmd => Box::new( + HelpComand{} + ), + CMDType::HistoryCmd => Box::new( + HistoryComand{} + ), + CMDType::JobsCmd => Box::new( + JobsComand{} + ), + CMDType::KillCmd => Box::new( + KillComand{} + ), + CMDType::LetCmd => Box::new( + LetComand{} + ), + CMDType::MapfileCmd => Box::new( + MapfileComand{} + ), + CMDType::PrintfCmd => Box::new( + PrintfComand{} + ), + CMDType::PushdCmd => Box::new( + PushdComand{} + ), + CMDType::ReadCmd => Box::new( + ReadComand{} + ), + CMDType::ReservedCmd => Box::new( + ReservedComand{} + ), + CMDType::ReturnCmd => Box::new( + ReadComand{} + ), + CMDType::SetattrCmd => Box::new( + SetattrComand{} + ), + CMDType::SetCmd => Box::new( + SetComand{} + ), + CMDType::ShiftCmd => Box::new( + ShiftComand{} + ), + CMDType::ShoptCmd => Box::new( + ShoptComand{} + ), + CMDType::SourceCmd => Box::new( + SourceComand{} + ), + CMDType::SuspendCmd => Box::new( + SuspendComand{} + ), + CMDType::TestCmd => Box::new( + TestComand{} + ), + CMDType::TimesCmd => Box::new( + TimesComand{} + ), + CMDType::TrapCmd => Box::new( + TrapComand{} + ), + CMDType::TypeCmd => Box::new( + TypeComand{} + ), + CMDType::UlimitCmd => Box::new( + UlimitComand{} + ), + CMDType::UmaskCmd => Box::new( + UmaskComand{} + ), + CMDType::WaitCmd => Box::new( + WaitComand{} + ) + } + } +} + +fn get_cmd_type (command : *mut i8) -> CMDType{ + let mut types = CMDType::HelpCmd; + if command == b"alias\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::AliasCmd; + } + else if command == b"bind\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::BindCmd; + } + else if command == b"break\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::BreakCmd; + } + else if command == b"builtin\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::BuiltinCmd; + } + else if command == b"caller\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::CallerCmd; + } + else if command == b"cd\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::CdCmd; + } + else if command == b"colon\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::ColonCmd; + } + else if command == b"command\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::CommandCmd; + } + else if command == b"common\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::CommonCmd; + } + else if command == b"complete\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::CompleteCmd; + } + else if command == b"declare\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::DeclareCmd; + } + else if command == b"echo\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::EchoCmd; + } + else if command == b"enable\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::EnableCmd; + } + else if command == b"eval\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::EvalCmd; + } + else if command == b"exec\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::ExecCmd; + } + else if command == b"exit\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::ExitCmd; + } + else if command == b"fc\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::FcCmd; + } + else if command == b"fg_bg\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::FgbgCmd; + } + else if command == b"getopts\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::GetoptsCmd; + } + else if command == b"hash\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::HashCmd; + } + else if command == b"help\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::HelpCmd; + } + else if command == b"history\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::HistoryCmd; + } + else if command == b"jobs\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::JobsCmd; + } + else if command == b"kill\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::KillCmd; + } + else if command == b"mapfile\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::MapfileCmd; + } + else if command == b"printf\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::PrintfCmd; + } + else if command == b"pushd\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::PushdCmd; + } + else if command == b"read\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::ReadCmd; + } + else if command == b"let\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::LetCmd; + } + else if command == b"return\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::ReturnCmd; + + } + else if command == b"set\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::SetCmd; + } + else if command == b"setattr\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::SetattrCmd; + } + else if command == b"shift\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::ShiftCmd; + } + else if command == b"shopt\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::ShoptCmd; + } + else if command == b"source\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::SourceCmd; + } + else if command == b"suspend\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::SuspendCmd; + } + else if command == b"test\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::TestCmd; + } + else if command == b"times\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::TimesCmd; + } + else if command == b"trap\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::TrapCmd; + } + else if command == b"type\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::TypeCmd; + } + else if command == b"ulimit\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::UlimitCmd; + } + else if command == b"umask\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::UmaskCmd; + } + else if command == b"wait\0" as *const u8 as *const i8 as *mut i8{ + types = CMDType::WaitCmd; + } + return types +} + +#[no_mangle] +pub extern "C" fn r_exec_cmd(command : *mut i8, mut list :*mut WordList) { + + let commandType = get_cmd_type(command); + let factory = SimpleFactory::new(); + let cmdCall = factory.make_product(commandType); + cmdCall.excute(list); +} \ No newline at end of file diff --git a/bash-5.1/builtins_rust/fc/src/lib.rs b/bash-5.1/builtins_rust/fc/src/lib.rs index 47d9e0be09f818de163bc4337f35352012206e81..5d0eb3fcd91a5f7c48574b5291f41da800035aed 100644 --- a/bash-5.1/builtins_rust/fc/src/lib.rs +++ b/bash-5.1/builtins_rust/fc/src/lib.rs @@ -1,10 +1,8 @@ extern crate libc; extern crate nix; -//use rcommon::{ EX_USAGE,EXECUTION_FAILURE, EXECUTION_SUCCESS }; use libc::{c_char, c_long, c_void}; use std::{ffi::CString, i32, io::{Write, stdout}, ops::Add, string, u32}; - use rcommon::{WordList, WordDesc, EX_USAGE, EXECUTION_SUCCESS, EXECUTION_FAILURE,r_builtin_usage}; #[repr(i8)] diff --git a/bash-5.1/builtins_rust/hash/src/lib.rs b/bash-5.1/builtins_rust/hash/src/lib.rs index 88cc8f5ee83a2fa45bfd3be46b7b95d0959c188c..698a3f95897fdc18c2804461078a77a2c518f6c3 100644 --- a/bash-5.1/builtins_rust/hash/src/lib.rs +++ b/bash-5.1/builtins_rust/hash/src/lib.rs @@ -197,7 +197,6 @@ pub extern "C" fn r_hash_builtin(mut list:*mut WordList)->i32{ } } - opt = internal_getopt(list,opts.as_ptr() as *mut c_char); } @@ -210,12 +209,13 @@ pub extern "C" fn r_hash_builtin(mut list:*mut WordList)->i32{ if delete != 0{ temp = CString::new("-d").unwrap(); temp_ptr = temp.as_ptr() as *mut c_char; + sh_needarg(temp_ptr); } else{ temp = CString::new("-t").unwrap(); temp_ptr = temp.as_ptr() as *mut c_char; + sh_needarg(temp_ptr); } - sh_needarg(temp_ptr); return EXECUTION_FAILURE!(); } diff --git a/bash-5.1/builtins_rust/help/src/lib.rs b/bash-5.1/builtins_rust/help/src/lib.rs index 28321371f37d974cc1e4e65aecd2fc870da94d31..16bedff4edda98f7805d28e1811873f7391a20df 100644 --- a/bash-5.1/builtins_rust/help/src/lib.rs +++ b/bash-5.1/builtins_rust/help/src/lib.rs @@ -95,6 +95,7 @@ extern "C"{ static mut static_shell_builtin : [builtin ; 100]; static shell_builtins:*mut builtin; static mut current_builtin :*mut builtin; + fn builtin_help(); } #[no_mangle] @@ -129,9 +130,12 @@ pub extern "C" fn r_help_builtin(mut list:*mut WordList)->i32 { 's'=> {sflag = 1; break;} _=>{ unsafe { - - builtin_usage (); - return EX_USAGE; + if i == -99 { + builtin_help(); + return EX_USAGE; + } + builtin_usage (); + return EX_USAGE; } } } diff --git a/bash-5.1/builtins_rust/history/src/intercdep.rs b/bash-5.1/builtins_rust/history/src/intercdep.rs index 5ea73daf22ae470ee472a5fb7cd5bce400eef592..a1c6d3d18cb77159890474cd36359a3d467de6ad 100644 --- a/bash-5.1/builtins_rust/history/src/intercdep.rs +++ b/bash-5.1/builtins_rust/history/src/intercdep.rs @@ -31,6 +31,7 @@ pub struct _hist_entry { pub type HIST_ENTRY = _hist_entry; extern "C" { + pub fn printf(_: *const libc::c_char, _: ...) -> libc::c_int; pub fn reset_internal_getopt(); pub fn internal_getopt(list: *mut WordList, opts: *mut c_char) -> c_int; pub fn builtin_usage(); @@ -67,7 +68,7 @@ extern "C" { pub fn sh_erange(s: *mut c_char, desc: *mut c_char); pub fn sh_restricted(s: *mut c_char) -> c_void; - + fn builtin_help(); pub static mut list_optarg : *mut libc::c_char; pub static mut loptend : *mut WordList; diff --git a/bash-5.1/builtins_rust/history/src/lib.rs b/bash-5.1/builtins_rust/history/src/lib.rs index 520f0cfc91dc61513107d225ca3785c7c22a20ee..37caa34665bfa1594beba574e9bab53759899ece 100644 --- a/bash-5.1/builtins_rust/history/src/lib.rs +++ b/bash-5.1/builtins_rust/history/src/lib.rs @@ -47,6 +47,10 @@ unsafe { } 'p' => flags |= PFLAG, _ => { + if opt == -99 { + builtin_help(); + return EX_USAGE; + } r_builtin_usage (); return EX_USAGE; } @@ -55,7 +59,6 @@ unsafe { } list = loptend; - opt = flags & (AFLAG | RFLAG | WFLAG | NFLAG); if opt != 0 && opt != AFLAG && opt != RFLAG && opt != WFLAG && opt != NFLAG { let c_err = CString::new("cannot use more than one of -anrw").unwrap(); @@ -81,11 +84,15 @@ unsafe { } return r_sh_chkwrite(EXECUTION_SUCCESS); } else if (flags & DFLAG) != 0 { - let c_tmp = if *delete_arg == b'-' as c_char {(delete_arg as usize + 1) as *mut c_char} else {delete_arg}; + let c_tmp = if *delete_arg == b'-' as c_char {delete_arg.offset(1 as isize ) as *mut c_char} else {delete_arg}; range = libc::strchr(c_tmp, b'-' as c_int); + + printf(b"AAAAAAArange=%u, c_tmp=%s\n" as *const u8 as *const i8, range, c_tmp); if !range.is_null() { - let mut delete_start: c_long = 0; - let mut delete_end: c_long = 0; + printf(b"AAAAAAArange=%s\n" as *const u8 as *const i8, range); + + let mut delete_start: c_long = 0; + let mut delete_end: c_long = 0; *range = b'\0' as c_char; range = (range as usize + 1) as *mut c_char; @@ -129,8 +136,8 @@ unsafe { return if result != 0 {EXECUTION_SUCCESS} else {EXECUTION_FAILURE}; } - } else if (flags & DFLAG) != 0 { - if legal_number(delete_arg, std::mem::transmute(&delete_offset)) == 0 { + else if (flags & DFLAG) != 0 { + if legal_number(delete_arg, &mut delete_offset) == 0 { r_sh_erange(delete_arg, "history position\0".as_ptr() as *mut c_char); return EXECUTION_FAILURE; } @@ -149,13 +156,13 @@ unsafe { } else { opt = delete_offset as c_int; } - result = bash_delete_histent(opt - history_base); if where_history() > history_length { history_set_pos(history_length); } return if result != 0 {EXECUTION_FAILURE} else {EXECUTION_SUCCESS}; - } else if (flags & (AFLAG | RFLAG | NFLAG | WFLAG | CFLAG)) == 0 { + } +} else if (flags & (AFLAG | RFLAG | NFLAG | WFLAG | CFLAG)) == 0 { result = display_history(list); return r_sh_chkwrite(result); } @@ -167,7 +174,6 @@ unsafe { r_sh_restricted(filename); return EXECUTION_FAILURE; } - if (flags & AFLAG) != 0 { result = maybe_append_history(filename); } else if (flags & WFLAG) != 0 { @@ -245,37 +251,45 @@ unsafe fn display_history(list: *mut WordList) -> c_int } else { limit = -1; } - let hlist = history_list(); if !hlist.is_null() { let mut i: c_long = 0; - while !((hlist as usize + (i * 8) as usize) as *mut HIST_ENTRY).is_null() { + while !(*hlist.offset(i as isize)).is_null() { i += 1; } i = if 0 <= limit && limit < i {i - limit} else {0}; - histtimefmt = get_string_value("HISTTIMEFORMAT\0".as_ptr() as *const c_char); - - while !((hlist as usize + (i * 8) as usize) as *mut HIST_ENTRY).is_null(){ - quit(); + histtimefmt = get_string_value(b"HISTTIMEFORMAT\0" as *const u8 as *const c_char); - if !histtimefmt.is_null() && *histtimefmt != 0 { - timestr = histtime((hlist as usize + (i * 8) as usize) as *mut HIST_ENTRY, histtimefmt); - } else { - timestr = PT_NULL as *mut c_char; + while !(*hlist.offset(i as isize)).is_null() { + if terminating_signal != 0 { + termsig_handler(terminating_signal); } - - let data = (*((hlist as usize + (i * 8) as usize) as *mut HIST_ENTRY)).data; - let line = (*((hlist as usize + (i * 8) as usize) as *mut HIST_ENTRY)).line; - let s_timestr = CString::from_raw(timestr).into_string().unwrap(); - println!("{:>5}{} {}{}", - i as c_int + history_base, - if !data.is_null() {"*"} else {" "}, - if !timestr.is_null() && *timestr != 0 {s_timestr} else {"".to_owned()}, - CString::from_raw(line).into_string().unwrap() - ); + if interrupt_state != 0 { + throw_to_top_level(); + } + timestr = if !histtimefmt.is_null() && *histtimefmt as libc::c_int != 0 { + histtime(*hlist.offset(i as isize), histtimefmt) + } else { + 0 as *mut libc::c_void as *mut libc::c_char + }; + printf( + b"%5d%c %s%s\n\0" as *const u8 as *const libc::c_char, + i + history_base as c_long, + if !((**hlist.offset(i as isize)).data).is_null() { + '*' as i32 + } else { + ' ' as i32 + }, + if !timestr.is_null() && *timestr as libc::c_int != 0 { + timestr + } else { + b"\0" as *const u8 as *const libc::c_char + }, + (**hlist.offset(i as isize)).line, + ); i += 1; } } @@ -284,10 +298,12 @@ unsafe fn display_history(list: *mut WordList) -> c_int } fn push_history(list: *mut WordList) { + println!("push_history!!!!"); unsafe { if remember_on_history != 0 && hist_last_line_pushed == 0 && (hist_last_line_added != 0 || (current_command_line_count > 0 && current_command_first_line_saved != 0 && command_oriented_history != 0)) && bash_delete_last_history() == 0 { + return; } diff --git a/bash-5.1/builtins_rust/jobs/src/lib.rs b/bash-5.1/builtins_rust/jobs/src/lib.rs index ce7f97b6e41dde849a0d17a4fdb22d1fb925e85b..8f70ce26c2303b630ec61f22d3379a430c5e5365 100644 --- a/bash-5.1/builtins_rust/jobs/src/lib.rs +++ b/bash-5.1/builtins_rust/jobs/src/lib.rs @@ -601,10 +601,3 @@ pub extern "C" fn r_disown_builtin (list:* mut WordList)->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 WordList)->i32 { - return r_jobs_builtin(list); -} -*/ diff --git a/bash-5.1/builtins_rust/mapfile/src/intercdep.rs b/bash-5.1/builtins_rust/mapfile/src/intercdep.rs index f439e7b614012377dc7a66a361769ef3eae1f4bd..8450248d09589efc52448bfe539382c28fadf17c 100644 --- a/bash-5.1/builtins_rust/mapfile/src/intercdep.rs +++ b/bash-5.1/builtins_rust/mapfile/src/intercdep.rs @@ -1,19 +1,4 @@ - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct word_desc { - pub word: *mut c_char, - pub flags: c_int, -} -pub type WordDesc = word_desc; - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct word_list { - pub next: *mut word_list, - pub word: *mut WordDesc, -} -pub type WordList = word_list; +use rcommon::{WordList}; pub type arrayind_t = c_long; diff --git a/bash-5.1/builtins_rust/printf/src/intercdep.rs b/bash-5.1/builtins_rust/printf/src/intercdep.rs index e5ab6fa7ea92f0cc6bd5601478823627879ec1c9..db66567dcfc63e9081874bfb07771a0f07a70f80 100644 --- a/bash-5.1/builtins_rust/printf/src/intercdep.rs +++ b/bash-5.1/builtins_rust/printf/src/intercdep.rs @@ -1,20 +1,4 @@ -#[repr(C)] -#[derive(Copy, Clone)] -pub struct word_desc { - pub word: *mut c_char, - pub flags: c_int, -} -pub type WordDesc = word_desc; - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct word_list { - pub next: *mut word_list, - pub word: *mut WordDesc, -} -pub type WordList = word_list; - -// pub type SHELL_VAR = variable; +use rcommon::{WordList}; pub type __intmax_t = c_long; pub type intmax_t = __intmax_t; diff --git a/bash-5.1/builtins_rust/pushd/src/lib.rs b/bash-5.1/builtins_rust/pushd/src/lib.rs index b8bfcb04aedec608023a1f5030694ea206fbce32..08d04fa57d45a72c4b5baf5e3e48a06057567460 100644 --- a/bash-5.1/builtins_rust/pushd/src/lib.rs +++ b/bash-5.1/builtins_rust/pushd/src/lib.rs @@ -935,12 +935,3 @@ pub extern "C" fn r_get_directory_stack (flags:i32)->* mut WordList } } -#[no_mangle] -pub extern "C" fn cmd_name() ->*const u8 { - return b"pushd" as *const u8; -} - -#[no_mangle] -pub extern "C" fn run(list : *mut WordList)->i32 { - return r_pushd_builtin(list); -} diff --git a/bash-5.1/builtins_rust/read/src/intercdep.rs b/bash-5.1/builtins_rust/read/src/intercdep.rs index 2fed8da36bfd5e48de34d8e1da7784d4fb2c10be..60570c20b4d02c2662ee319ee1301ab1a9fe10e5 100644 --- a/bash-5.1/builtins_rust/read/src/intercdep.rs +++ b/bash-5.1/builtins_rust/read/src/intercdep.rs @@ -1,19 +1,4 @@ - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct word_desc { - pub word: *mut c_char, - pub flags: c_int, -} -pub type WordDesc = word_desc; - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct word_list { - pub next: *mut word_list, - pub word: *mut WordDesc, -} -pub type WordList = word_list; +use rcommon::{WordList}; use rcommon::{r_builtin_usage,r_sh_invalidid,r_builtin_bind_variable}; //use rcommon::{r_builtin_usage,r_sh_invalidid,r_builtin_bind_variable,SHELL_VAR}; diff --git a/bash-5.1/builtins_rust/rlet/Cargo.toml b/bash-5.1/builtins_rust/rlet/Cargo.toml index c468265b2b38f149a4e8785644550422903d91c1..b52101cab52d92ce7b9ddb1a90791237124ba2a3 100644 --- a/bash-5.1/builtins_rust/rlet/Cargo.toml +++ b/bash-5.1/builtins_rust/rlet/Cargo.toml @@ -14,3 +14,4 @@ crate-type = ["staticlib","rlib"] [dependencies] libc = "0.2" nix = "0.23" +rcommon = {path = "../common"} \ No newline at end of file diff --git a/bash-5.1/builtins_rust/rlet/src/intercdep.rs b/bash-5.1/builtins_rust/rlet/src/intercdep.rs index fda0e61a078cc0911365079533cfa55b133a2388..d37ae34bc367b7e15245baa881c25ee85051fd34 100644 --- a/bash-5.1/builtins_rust/rlet/src/intercdep.rs +++ b/bash-5.1/builtins_rust/rlet/src/intercdep.rs @@ -1,19 +1,4 @@ - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct word_desc { - pub word: *mut c_char, - pub flags: c_int, -} -pub type WordDesc = word_desc; - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct word_list { - pub next: *mut word_list, - pub word: *mut WordDesc, -} -pub type WordList = word_list; +use rcommon::{WordList}; pub const EXECUTION_SUCCESS : c_int = 0; pub const EXECUTION_FAILURE : c_int = 1; diff --git a/bash-5.1/builtins_rust/setattr/Cargo.toml b/bash-5.1/builtins_rust/setattr/Cargo.toml index 1e1d381ea1ba1ef04b23a0b4682d27406fe492b4..90004e4d728755daf4f9b44e5dc3c405edc7d9ad 100644 --- a/bash-5.1/builtins_rust/setattr/Cargo.toml +++ b/bash-5.1/builtins_rust/setattr/Cargo.toml @@ -18,3 +18,4 @@ rdeclare = {path = "../declare"} libc = "0.2" nix = "0.23" rdeclare = {path = "../declare"} +rcommon = {path = "../common"} \ No newline at end of file diff --git a/bash-5.1/builtins_rust/setattr/src/intercdep.rs b/bash-5.1/builtins_rust/setattr/src/intercdep.rs index 98a323e01fa0ac0541ba0565a6a877e1f7ec74bb..8c4655937ba5aea202fd59998c0c25838c719c1a 100644 --- a/bash-5.1/builtins_rust/setattr/src/intercdep.rs +++ b/bash-5.1/builtins_rust/setattr/src/intercdep.rs @@ -1,4 +1,4 @@ - +use rcommon::{WordList}; #[repr(C)] #[derive(Copy, Clone)] pub struct word_desc { @@ -7,14 +7,6 @@ pub struct word_desc { } pub type WordDesc = word_desc; -#[repr(C)] -#[derive(Copy, Clone)] -pub struct word_list { - pub next: *mut word_list, - pub word: *mut WordDesc, -} -pub type WordList = word_list; - pub type __intmax_t = c_long; pub type intmax_t = __intmax_t; pub type arrayind_t = intmax_t; diff --git a/bash-5.1/builtins_rust/shift/src/intercdep.rs b/bash-5.1/builtins_rust/shift/src/intercdep.rs index 5e0851b52a14bf6b751662c63ad45ea28cc2edf9..7130cc619efba5d49b95ee4ed3c8249d1cf9329f 100644 --- a/bash-5.1/builtins_rust/shift/src/intercdep.rs +++ b/bash-5.1/builtins_rust/shift/src/intercdep.rs @@ -1,19 +1,4 @@ - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct word_desc { - pub word: *mut c_char, - pub flags: c_int, -} -pub type WordDesc = word_desc; - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct word_list { - pub next: *mut word_list, - pub word: *mut WordDesc, -} -pub type WordList = word_list; +use rcommon::{WordList}; pub const EXECUTION_SUCCESS : c_int = 0; pub const EXECUTION_FAILURE : c_int = 1; diff --git a/bash-5.1/builtins_rust/source/src/lib.rs b/bash-5.1/builtins_rust/source/src/lib.rs index fcbbf1e040211a924dd7352f74851788585eb01e..a33457a46170f4c26f503b8e1cc0c348c6fab99e 100644 --- a/bash-5.1/builtins_rust/source/src/lib.rs +++ b/bash-5.1/builtins_rust/source/src/lib.rs @@ -386,12 +386,3 @@ pub extern "C" fn r_source_builtin (list:* mut WordList)->i32 } } -#[no_mangle] -pub extern "C" fn cmd_name() ->*const u8 { - return b"source" as *const u8; -} - -#[no_mangle] -pub extern "C" fn run(list : *mut WordList)->i32 { - return r_source_builtin(list); -} diff --git a/bash-5.1/builtins_rust/times/src/intercdep.rs b/bash-5.1/builtins_rust/times/src/intercdep.rs index eb18f3826b723b0d47faca93f06f27d7b6a9b55d..c2f5d3213ba44c8fff14c155c067b46939b25667 100644 --- a/bash-5.1/builtins_rust/times/src/intercdep.rs +++ b/bash-5.1/builtins_rust/times/src/intercdep.rs @@ -1,19 +1,4 @@ - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct word_desc { - pub word: *mut c_char, - pub flags: c_int, -} -pub type WordDesc = word_desc; - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct word_list { - pub next: *mut word_list, - pub word: *mut WordDesc, -} -pub type WordList = word_list; +use rcommon::WordList; pub const EXECUTION_SUCCESS : c_int = 0; pub const EXECUTION_FAILURE : c_int = 1; diff --git a/record.txt b/record.txt index 3f298cc810ed4b609a07beb2620c40ee25af2f00..6f00cd385bee978d7a8e485e1e34e7ea4e80b3c4 100644 --- a/record.txt +++ b/record.txt @@ -23,3 +23,4 @@ 45 46 47 +48