From f604673f3036e235840d8173e8be18e1e22301f6 Mon Sep 17 00:00:00 2001 From: liutong Date: Thu, 10 Aug 2023 23:44:26 +0800 Subject: [PATCH] succeed called factory --- bash-5.1/Makefile.in | 2 +- bash-5.1/builtins/break.def | 25 +- bash-5.1/builtins_rust/break_1/src/lib.rs | 38 ++- bash-5.1/builtins_rust/colon/src/lib.rs | 4 +- bash-5.1/builtins_rust/command/Cargo.toml | 2 +- bash-5.1/builtins_rust/exec_cmd/Cargo.toml | 2 +- bash-5.1/builtins_rust/exec_cmd/src/lib.rs | 338 ++++++++++++--------- bash-5.1/builtins_rust/jobs/src/lib.rs | 3 +- bash-5.1/execute_cmd.c | 26 +- record.txt | 1 + 10 files changed, 234 insertions(+), 207 deletions(-) diff --git a/bash-5.1/Makefile.in b/bash-5.1/Makefile.in index 30ddc17..3ea296c 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 -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 = $(BUILTINS_LIB) $(LIBRARIES) @LIBS@ -lrt -lpthread -L./target/debug -lralias -lrbind -lrbreak -lrbuiltin -lrcaller -lrcd -lrcolon -lrcommon -lcommand -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@ diff --git a/bash-5.1/builtins/break.def b/bash-5.1/builtins/break.def index 346b632..f71bc0d 100644 --- a/bash-5.1/builtins/break.def +++ b/bash-5.1/builtins/break.def @@ -144,27 +144,4 @@ 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_rust/break_1/src/lib.rs b/bash-5.1/builtins_rust/break_1/src/lib.rs index f458c5a..a2f0a63 100644 --- a/bash-5.1/builtins_rust/break_1/src/lib.rs +++ b/bash-5.1/builtins_rust/break_1/src/lib.rs @@ -33,13 +33,16 @@ macro_rules! CHECK_HELPOPT { extern "C" { fn get_numeric_arg(list :*mut WordList, i: i32 , intmax :*mut intmax_t) -> i32; fn builtin_help (); - fn get_loop_level() -> i32; - fn set_continuing(cont : i32); - fn set_breaking(breaking : i32); + // fn get_loop_level() -> i32; + //fn set_continuing(cont : i32); + //fn set_breaking(breaking : i32); fn sh_erange (s:* mut libc::c_char, desc:* mut libc::c_char); //pub static fn check_loop_level () -> i64; /* Non-zero when a "break" instruction is encountered. */ pub static posixly_correct :i32; + static mut breaking : i32; + static mut continuing : i32; + static mut loop_level : i32; } #[no_mangle] @@ -49,22 +52,23 @@ pub extern "C" fn r_break_builtin(mut list :*mut WordList) -> i32 { unsafe { CHECK_HELPOPT! (list); if check_loop_level() == 0 { - return (EXECUTION_SUCCESS!()); + return EXECUTION_SUCCESS!(); } get_numeric_arg(list, 1, &mut newbreak as *mut intmax_t); if newbreak <= 0{ #[warn(temporary_cstring_as_ptr)] sh_erange ((*(*list).word).word, CString::new("loop count").unwrap().as_ptr() as * mut libc::c_char); - set_breaking (get_loop_level()); - return (EXECUTION_FAILURE!()); + //set_breaking (get_loop_level()); + breaking = loop_level; + return EXECUTION_FAILURE!(); } - if newbreak > get_loop_level() as libc::c_long{ - newbreak = get_loop_level() as i64; + if newbreak > loop_level as libc::c_long{ + newbreak = loop_level as i64; } - - set_breaking(newbreak as i32); + breaking = newbreak as i32; + // set_breaking(newbreak as i32); } return (EXECUTION_SUCCESS!()); } @@ -84,13 +88,15 @@ fn continue_builtin (list :*mut WordList) -> i32 { if newcont <= 0{ #[warn(temporary_cstring_as_ptr)] sh_erange ((*(*list).word).word, CString::new("loop count ").unwrap().as_ptr() as * mut libc::c_char); - set_breaking(get_loop_level()); + //set_breaking(get_loop_level()); + breaking = loop_level; return (EXECUTION_FAILURE!()); } - if newcont > get_loop_level().into(){ - newcont = get_loop_level() as i64; + if newcont > loop_level.into(){ + newcont = loop_level as i64; } - set_continuing(newcont as i32); + continuing = newcont as i32; + //set_continuing(newcont as i32); } return (EXECUTION_SUCCESS!()); @@ -99,11 +105,11 @@ fn continue_builtin (list :*mut WordList) -> i32 { #[no_mangle] pub extern "C" fn check_loop_level () -> i32 { unsafe { - if get_loop_level()== 0 && posixly_correct == 0 { + if loop_level == 0 && posixly_correct == 0 { println! ("only meaningful in a `for`, `while`, or until `loop` "); return 0; } - return (get_loop_level()); + loop_level } } diff --git a/bash-5.1/builtins_rust/colon/src/lib.rs b/bash-5.1/builtins_rust/colon/src/lib.rs index 6ead646..393088e 100644 --- a/bash-5.1/builtins_rust/colon/src/lib.rs +++ b/bash-5.1/builtins_rust/colon/src/lib.rs @@ -13,13 +13,13 @@ mod tests { #[no_mangle] -pub extern "C" fn r_colon_builtin(ignore:WordList)->i32 { +pub extern "C" fn r_colon_builtin(ignore: *mut WordList )->i32 { println!("in r_colon_builtin"); 0 } #[no_mangle] -pub extern "C" fn r_false_builtin(ignore: WordList) -> i32 { +pub extern "C" fn r_false_builtin(ignore: *mut WordList) -> i32 { println!("in r_false_builtin"); 1 } diff --git a/bash-5.1/builtins_rust/command/Cargo.toml b/bash-5.1/builtins_rust/command/Cargo.toml index 0b76f4f..d390905 100644 --- a/bash-5.1/builtins_rust/command/Cargo.toml +++ b/bash-5.1/builtins_rust/command/Cargo.toml @@ -11,4 +11,4 @@ rcommon = {path="../common"} [lib] crate-type = ["staticlib", "rlib"] -name = "rcommand" +name = "command" diff --git a/bash-5.1/builtins_rust/exec_cmd/Cargo.toml b/bash-5.1/builtins_rust/exec_cmd/Cargo.toml index 9a416d5..b120c60 100644 --- a/bash-5.1/builtins_rust/exec_cmd/Cargo.toml +++ b/bash-5.1/builtins_rust/exec_cmd/Cargo.toml @@ -50,7 +50,7 @@ rtype = {path="../type"} rulimit = {path="../ulimit"} rumask = {path="../umask"} rwait = {path="../wait"} - +libc = "0.2" [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 index 80f93ef..0779d99 100644 --- a/bash-5.1/builtins_rust/exec_cmd/src/lib.rs +++ b/bash-5.1/builtins_rust/exec_cmd/src/lib.rs @@ -1,4 +1,4 @@ -use rcommon::{WordList, WordDesc}; +use rcommon::{WordList, WordDesc,}; use ralias::r_alias_builtin; use rbind::r_bind_builtin; use rbreak::r_break_builtin; @@ -7,7 +7,7 @@ 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 command::r_command_builtin; //use rcommon ::r__builtin; use rcomplete::r_complete_builtin; use rdeclare::r_declare_builtin; @@ -43,6 +43,9 @@ use rtype::r_type_builtin; use rulimit::r_ulimit_builtin; use rumask::r_umask_builtin; use rwait::r_wait_builtin; +use std::ffi::CStr; +use std::ffi::CString; +use libc::{strcmp}; enum CMDType { AliasCmd, @@ -93,260 +96,270 @@ enum CMDType { struct AliasComand ; impl CommandExec for AliasComand{ - fn excute(&self,list : *mut WordList){ + fn excute(&self,list : *mut WordList)-> i32{ unsafe { - r_alias_builtin(list); + r_alias_builtin(list) } } } struct BindComand; impl CommandExec for BindComand{ - fn excute(&self,list : *mut WordList){ - r_bind_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_bind_builtin(list) } } struct BreakComand; impl CommandExec for BreakComand{ - fn excute(&self,list : *mut WordList){ - r_break_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_break_builtin(list) } } struct BuiltinComand; impl CommandExec for BuiltinComand{ - fn excute(&self,list : *mut WordList){ - r_builtin_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_builtin_builtin(list) } } struct CallerComand; impl CommandExec for CallerComand{ - fn excute(&self,list : *mut WordList){ - r_caller_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_caller_builtin(list) } } struct CdComand; impl CommandExec for CdComand{ - fn excute(&self,list : *mut WordList){ - r_cd_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_cd_builtin(list) } } struct ColonComand; impl CommandExec for ColonComand{ - fn excute(&self,list :*mut WordList){ - // r_colon_builtin(list); + fn excute(&self,list :*mut WordList)-> i32{ + r_colon_builtin(list) + // 0 } } struct CommandComand; impl CommandExec for CommandComand{ - fn excute(&self,list : *mut WordList){ - //command_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + unsafe { + r_command_builtin(list) + } + } } struct CommonComand; impl CommandExec for CommonComand{ - fn excute(&self,list : *mut WordList){ + fn excute(&self,list : *mut WordList)-> i32{ unsafe { - r_alias_builtin(list); + r_alias_builtin(list) } } } struct CompleteComand; impl CommandExec for CompleteComand{ - fn excute(&self,list : *mut WordList){ - r_complete_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_complete_builtin(list) } } struct DeclareComand; impl CommandExec for DeclareComand{ - fn excute(&self,list : *mut WordList){ - r_declare_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_declare_builtin(list) } } struct EchoComand; impl CommandExec for EchoComand{ - fn excute(&self,list : *mut WordList){ - r_echo_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_echo_builtin(list) } } struct EnableComand; impl CommandExec for EnableComand{ - fn excute(&self,list : *mut WordList){ + fn excute(&self,list : *mut WordList)-> i32{ unsafe { - r_enable_builtin(list); + println!("=======================d============="); + r_enable_builtin(list) } } } struct EvalComand; impl CommandExec for EvalComand{ - fn excute(&self,list : *mut WordList){ - r_eval_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + // r_eval_builtin(list) + 0 } } struct ExecComand; impl CommandExec for ExecComand{ - fn excute(&self,list : *mut WordList){ - r_exec_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_exec_builtin(list) } } struct ExitComand; impl CommandExec for ExitComand{ - fn excute(&self,list : *mut WordList){ - r_exit_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_exit_builtin(list) } } struct FcComand; impl CommandExec for FcComand{ - fn excute(&self,list : *mut WordList){ - r_fc_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_fc_builtin(list) } } struct FgbgComand; impl CommandExec for FgbgComand{ - fn excute(&self,list : *mut WordList){ - r_fg_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_fg_builtin(list) } } struct GetoptsComand; impl CommandExec for GetoptsComand{ - fn excute(&self,list : *mut WordList){ - r_getopts_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_getopts_builtin(list) } } struct HashComand; impl CommandExec for HashComand{ - fn excute(&self,list : *mut WordList){ - r_hash_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_hash_builtin(list) } } struct HelpComand; impl CommandExec for HelpComand{ - fn excute(&self,list : *mut WordList){ - r_help_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + println!("==============help========"); + r_help_builtin(list) } } struct HistoryComand; impl CommandExec for HistoryComand{ - fn excute(&self,list : *mut WordList){ - r_history_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_history_builtin(list) } } struct JobsComand; impl CommandExec for JobsComand{ - fn excute(&self,list : *mut WordList){ - r_jobs_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_jobs_builtin(list) } } struct KillComand; impl CommandExec for KillComand{ - fn excute(&self,list : *mut WordList){ - r_kill_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_kill_builtin(list) } } struct LetComand; impl CommandExec for LetComand{ - fn excute(&self,list : *mut WordList){ - r_let_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_let_builtin(list) } } struct MapfileComand; impl CommandExec for MapfileComand{ - fn excute(&self,list : *mut WordList){ - r_mapfile_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_mapfile_builtin(list) } } struct PrintfComand; impl CommandExec for PrintfComand{ - fn excute(&self,list : *mut WordList){ - r_printf_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_printf_builtin(list) } } struct PushdComand; impl CommandExec for PushdComand{ - fn excute(&self,list : *mut WordList){ - r_pushd_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_pushd_builtin(list) } } struct ReadComand; impl CommandExec for ReadComand{ - fn excute(&self,list : *mut WordList){ - r_read_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_read_builtin(list) } } struct ReservedComand; impl CommandExec for ReservedComand{ - fn excute(&self,list : *mut WordList){ + fn excute(&self,list : *mut WordList)-> i32{ //r_reserve_builtin(list); + 0 } } struct ReturnComand; impl CommandExec for ReturnComand{ - fn excute(&self,list : *mut WordList){ - r_return_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_return_builtin(list) } } struct SetattrComand; impl CommandExec for SetattrComand{ - fn excute(&self,list : *mut WordList){ + fn excute(&self,list : *mut WordList)-> i32{ //r_setattr_builtin(list); /*unkown enter which func */ + 0 } } struct SetComand; impl CommandExec for SetComand{ - fn excute(&self,list : *mut WordList){ - r_set_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_set_builtin(list) } } struct ShiftComand; impl CommandExec for ShiftComand{ - fn excute(&self,list : *mut WordList){ - r_shift_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_shift_builtin(list) } } struct ShoptComand; impl CommandExec for ShoptComand{ - fn excute(&self,list : *mut WordList){ - unsafe { - r_shopt_builtin(list); - } - } + fn excute(&self,list : *mut WordList)-> i32{ + // unsafe { + // r_shopt_builtin(list) + // } + 0 + } } struct SourceComand; impl CommandExec for SourceComand{ - fn excute(&self,list : *mut WordList){ - r_source_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_source_builtin(list) } } struct SuspendComand; impl CommandExec for SuspendComand{ - fn excute(&self,list : *mut WordList){ - r_suspend_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_suspend_builtin(list) } } struct TestComand; impl CommandExec for TestComand{ - fn excute(&self,list : *mut WordList){ - r_test_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_test_builtin(list) } } struct TimesComand; impl CommandExec for TimesComand{ - fn excute(&self,list : *mut WordList){ - r_times_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_times_builtin(list) } } struct TrapComand; impl CommandExec for TrapComand{ - fn excute(&self,list : *mut WordList){ - r_trap_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_trap_builtin(list) } } struct TypeComand; impl CommandExec for TypeComand{ - fn excute(&self,list : *mut WordList){ + fn excute(&self,list : *mut WordList)-> i32{ unsafe { - r_type_builtin(list); + r_type_builtin(list) } } @@ -354,29 +367,29 @@ enum CMDType { } struct UlimitComand; impl CommandExec for UlimitComand{ - fn excute(&self,list : *mut WordList){ + fn excute(&self,list : *mut WordList)-> i32{ unsafe { - r_ulimit_builtin(list); + r_ulimit_builtin(list) } } } struct UmaskComand; impl CommandExec for UmaskComand{ - fn excute(&self,list : *mut WordList){ - r_umask_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_umask_builtin(list) } } struct WaitComand; impl CommandExec for WaitComand{ - fn excute(&self,list : *mut WordList){ - r_wait_builtin(list); + fn excute(&self,list : *mut WordList)-> i32{ + r_wait_builtin(list) } } // 定义接口 pub trait CommandExec { - fn excute(&self,list : *mut WordList); + fn excute(&self,list : *mut WordList) -> i32; } @@ -531,146 +544,173 @@ impl Factory for SimpleFactory { } } -fn get_cmd_type (command : *mut i8) -> CMDType{ +unsafe 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{ + if libc::strcmp(command, b"alias\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::AliasCmd; } - else if command == b"bind\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command, b"bind\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::BindCmd; } - else if command == b"break\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command, b"break\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::BreakCmd; } - else if command == b"builtin\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command, b"builtin\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::BuiltinCmd; } - else if command == b"caller\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command, b"caller\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::CallerCmd; } - else if command == b"cd\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command, b"cd\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::CdCmd; } - else if command == b"colon\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command, b"colon\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::ColonCmd; } - else if command == b"command\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command, b"command\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::CommandCmd; } - else if command == b"common\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command, b"common\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::CommonCmd; } - else if command == b"complete\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command, b"complete\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::CompleteCmd; } - else if command == b"declare\0" as *const u8 as *const i8 as *mut i8{ - types = CMDType::DeclareCmd; + else if libc::strcmp(command,b"declare\0" as *const u8 as *const i8 as *mut i8) == 0{ + types = CMDType::CompleteCmd; } - else if command == b"echo\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command,b"echo\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::EchoCmd; } - else if command == b"enable\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command,b"enable\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::EnableCmd; } - else if command == b"eval\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command,b"eval\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::EvalCmd; } - else if command == b"exec\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command,b"exec\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::ExecCmd; } - else if command == b"exit\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command,b"exit\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::ExitCmd; } - else if command == b"fc\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command,b"fc\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::FcCmd; } - else if command == b"fg_bg\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command,b"fg\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::FgbgCmd; } - else if command == b"getopts\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command,b"getopts\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::GetoptsCmd; } - else if command == b"hash\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command, b"hash\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::HashCmd; } - else if command == b"help\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command,CString::new("help").unwrap().as_ptr() as * mut i8) == 0 { + println!("222222222========222222"); types = CMDType::HelpCmd; } - else if command == b"history\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command,b"history\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::HistoryCmd; } - else if command == b"jobs\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command,b"jobs\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::JobsCmd; } - else if command == b"kill\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command, b"kill\0" as *const u8 as *const i8 as *mut i8) == 0{ 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{ + else if libc::strcmp(command, b"mapfile\0" as *const u8 as *const i8 as *mut i8) == 0{ + types = CMDType::MapfileCmd;; + } + else if libc::strcmp(command,b"printf\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::PrintfCmd; } - else if command == b"pushd\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command,b"pushd\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::PushdCmd; } - else if command == b"read\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command, b"read\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::ReadCmd; - } - else if command == b"let\0" as *const u8 as *const i8 as *mut i8{ + } + + else if libc::strcmp(command, b"let\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::LetCmd; } - else if command == b"return\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command,b"return\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::ReturnCmd; - - } - else if command == b"set\0" as *const u8 as *const i8 as *mut i8{ + } + else if libc::strcmp(command,b"set\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::SetCmd; } - else if command == b"setattr\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command,b"setattr\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::SetattrCmd; - } - else if command == b"shift\0" as *const u8 as *const i8 as *mut i8{ + } + + else if libc::strcmp(command,b"shift\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::ShiftCmd; } - else if command == b"shopt\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command,b"shopt\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::ShoptCmd; } - else if command == b"source\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command,b"source\0" as *const u8 as *const i8 as *mut i8) == 0 + || libc::strcmp(command,b".\0" as *const u8 as *const i8 as *mut i8)== 0 { types = CMDType::SourceCmd; } - else if command == b"suspend\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command, b"suspend\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::SuspendCmd; } - else if command == b"test\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command,b"test\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::TestCmd; } - else if command == b"times\0" as *const u8 as *const i8 as *mut i8{ + + + else if libc::strcmp(command ,b"times\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::TimesCmd; } - else if command == b"trap\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command ,b"trap\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::TrapCmd; } - else if command == b"type\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command ,b"type\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::TypeCmd; } - else if command == b"ulimit\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command ,b"ulimit\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::UlimitCmd; } - else if command == b"umask\0" as *const u8 as *const i8 as *mut i8{ + + else if libc::strcmp(command ,b"umask\0" as *const u8 as *const i8 as *mut i8 ) == 0{ types = CMDType::UmaskCmd; - } - else if command == b"wait\0" as *const u8 as *const i8 as *mut i8{ + } + + else if libc::strcmp(command , b"wait\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::WaitCmd; - } - return types + } + + types } #[no_mangle] -pub extern "C" fn r_exec_cmd(command : *mut i8, mut list :*mut WordList) { +pub extern "C" fn r_exec_cmd(command : *mut i8, mut list :*mut WordList) -> i32 { - let commandType = get_cmd_type(command); + println!("enter r_exec_cmd"); + unsafe { + println!("command is {:?}",CStr::from_ptr(command)); + } + let commandType = unsafe {get_cmd_type(command)}; let factory = SimpleFactory::new(); let cmdCall = factory.make_product(commandType); - cmdCall.excute(list); + cmdCall.excute(list) } \ No newline at end of file diff --git a/bash-5.1/builtins_rust/jobs/src/lib.rs b/bash-5.1/builtins_rust/jobs/src/lib.rs index 8f70ce2..6354a9e 100644 --- a/bash-5.1/builtins_rust/jobs/src/lib.rs +++ b/bash-5.1/builtins_rust/jobs/src/lib.rs @@ -597,7 +597,6 @@ pub extern "C" fn r_disown_builtin (list:* mut WordList)->libc::c_int { } } -#[no_mangle] -pub extern "C" fn cmd_name() ->*const u8 { +fn cmd_name() ->*const u8 { return b"jobs" as *const u8; } diff --git a/bash-5.1/execute_cmd.c b/bash-5.1/execute_cmd.c index 77e058c..8fae15e 100644 --- a/bash-5.1/execute_cmd.c +++ b/bash-5.1/execute_cmd.c @@ -199,6 +199,7 @@ static int execute_pipeline PARAMS((COMMAND *, int, int, int, struct fd_bitmap * static int execute_connection PARAMS((COMMAND *, int, int, int, struct fd_bitmap *)); static int execute_intern_function PARAMS((WORD_DESC *, FUNCTION_DEF *)); +extern int r_exec_cmd PARAMS((char *, WORD_LIST *)); /* Set to 1 if fd 0 was the subject of redirection to a subshell. Global so that reader_loop can set it to zero before executing a command. */ @@ -4395,7 +4396,6 @@ execute_simple_command (simple_command, pipe_in, pipe_out, async, fds_to_close) } else words = copy_word_list (simple_command->words); - /* It is possible for WORDS not to have anything left in it. Perhaps all the words consisted of `$foo', and there was no variable `$foo'. */ @@ -4733,10 +4733,9 @@ execute_builtin (builtin, words, flags, subshell) int result, eval_unwind, ignexit_flag; int isbltinenv, should_keep; char *error_trap; - error_trap = 0; should_keep = 0; - + //r_execute_cmd(); /* The eval builtin calls parse_and_execute, which does not know about the setting of flags, and always calls the execution functions with @@ -4840,8 +4839,9 @@ execute_builtin (builtin, words, flags, subshell) executing_builtin++; executing_command_builtin |= builtin == command_builtin; - result = ((*builtin) (words->next)); - // r_execute_cmd2(words->next); + //result = ((*builtin) (words->next)); + result = r_exec_cmd(this_command_name,words->next); + //r_execute_cmd2(words->next); /* This shouldn't happen, but in case `return' comes back instead of longjmp'ing, we need to unwind. */ @@ -5354,7 +5354,9 @@ execute_builtin_or_function (words, builtin, var, redirects, redirection_undo_list = (REDIRECT *)NULL; if (builtin) + { result = execute_builtin (builtin, words, flags, 0); + } else result = execute_function (var, words, flags, fds_to_close, 0, 0); @@ -5376,15 +5378,15 @@ execute_builtin_or_function (words, builtin, var, redirects, discard = 0; if (saved_undo_list) - { - dispose_redirects (saved_undo_list); - discard = 1; - } + { + dispose_redirects (saved_undo_list); + discard = 1; + } redirection_undo_list = exec_redirection_undo_list; saved_undo_list = exec_redirection_undo_list = (REDIRECT *)NULL; if (discard) - discard_unwind_frame ("saved-redirects"); - } + discard_unwind_frame ("saved-redirects"); + } if (saved_undo_list) { @@ -5498,6 +5500,7 @@ execute_disk_command (words, redirects, command_line, pipe_in, pipe_out, if (command) { + printf("command is %s ========== ======= \n",command); /* If we're optimizing out the fork (implicit `exec'), decrement the shell level like `exec' would do. */ #if 0 /* TAG: bash-5.2 psmith 10/11/2020 */ @@ -5811,6 +5814,7 @@ shell_execve (command, args, env) char *command; char **args, **env; { + printf("wwwwwwwwwwwwwwwwwwwwwwwwww===========\n"); int larray, i, fd; char sample[HASH_BANG_BUFSIZ]; int sample_len; diff --git a/record.txt b/record.txt index abac465..4a2b69c 100644 --- a/record.txt +++ b/record.txt @@ -53,3 +53,4 @@ 52 53 54 +55 -- Gitee