diff --git a/bash-5.1/Makefile.in b/bash-5.1/Makefile.in index 30ddc175d57f4d239b2a20ebc0b3a59a6a075872..3ea296c012dfd886dc9eb74e134086374264f86c 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_rust/break_1/src/lib.rs b/bash-5.1/builtins_rust/break_1/src/lib.rs index a2f0a636195761e535f6bbd335f1db5866c418b7..54df7d5e0a0bdf5f4b96adb7b4192ce667b8a193 100644 --- a/bash-5.1/builtins_rust/break_1/src/lib.rs +++ b/bash-5.1/builtins_rust/break_1/src/lib.rs @@ -73,7 +73,8 @@ pub extern "C" fn r_break_builtin(mut list :*mut WordList) -> i32 { return (EXECUTION_SUCCESS!()); } -fn continue_builtin (list :*mut WordList) -> i32 { +#[no_mangle] +pub extern "C" fn r_continue_builtin (list :*mut WordList) -> i32 { let mut newcont : intmax_t = 0 as intmax_t; unsafe { CHECK_HELPOPT! (list); diff --git a/bash-5.1/builtins_rust/colon/src/lib.rs b/bash-5.1/builtins_rust/colon/src/lib.rs index 6ead6461c2f484e233e15ed3b90540856713826e..393088e96ede79e78474687505fc41faf77c5683 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 0b76f4f54dc01b4010897183c68822997eda95b0..d390905eefa11437e94991f8a574483cf2baefc3 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 9a416d5bf8341a7cda20084a15915772ec2f0928..b120c60bef89f7e2a2ad135af17b0870ea11ac3e 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 80f93ef6663c1426f197c2817779e7c525756ffd..0a31ecedb72eb7bb98da2f14c1aff868e7999efa 100644 --- a/bash-5.1/builtins_rust/exec_cmd/src/lib.rs +++ b/bash-5.1/builtins_rust/exec_cmd/src/lib.rs @@ -1,23 +1,23 @@ -use rcommon::{WordList, WordDesc}; -use ralias::r_alias_builtin; +use rcommon::WordList; +use ralias::{r_alias_builtin,r_unalias_builtin}; use rbind::r_bind_builtin; -use rbreak::r_break_builtin; +use rbreak::{r_break_builtin,r_continue_builtin}; use rbuiltin::r_builtin_builtin; use rcaller::r_caller_builtin; -use rcd::r_cd_builtin; +use rcd::{r_cd_builtin,r_pwd_builtin}; //use rcmd::r_cmd_builtin; -use rcolon::r_colon_builtin; -//use command::command_builtin; +use rcolon::{r_colon_builtin,r_false_builtin}; +use command::r_command_builtin; //use rcommon ::r__builtin; -use rcomplete::r_complete_builtin; -use rdeclare::r_declare_builtin; +use rcomplete::{r_complete_builtin,r_compgen_builtin,r_compopt_builtin}; +use rdeclare::{r_declare_builtin,r_local_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 rexit::{r_exit_builtin,r_logout_builtin}; use rfc::r_fc_builtin; -use rfg_bg::r_fg_builtin; +use rfg_bg::{r_fg_builtin,r_bg_builtin}; use rgetopts::r_getopts_builtin; use rhash::r_hash_builtin; use rhelp::r_help_builtin; @@ -26,12 +26,12 @@ 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 rpushd::{r_pushd_builtin,r_dirs_builtin,r_popd_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 rset::{r_set_builtin,r_unset_builtin}; +use rsetattr::{r_export_builtin,r_readonly_builtin}; use rshift::r_shift_builtin; use rshopt::r_shopt_builtin; use rsource::r_source_builtin; @@ -43,26 +43,38 @@ 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, + UnAliasCmd, BindCmd, BreakCmd, + ContinueCmd, BuiltinCmd, CallerCmd, CdCmd, + PwdCmd, ColonCmd, + FalseCmd, CommandCmd, CommonCmd, CompleteCmd, + CompoptCmd, + CompgenCmd, DeclareCmd, + LocalCmd, EchoCmd, EnableCmd, EvalCmd, ExecCmd, ExitCmd, + LogoutCmd, FcCmd, - FgbgCmd, + FgCmd, + BgCmd, GetoptsCmd, HashCmd, HelpCmd, @@ -73,11 +85,16 @@ enum CMDType { MapfileCmd, PrintfCmd, PushdCmd, + DirsCmd, + PopdCmd, ReadCmd, ReservedCmd, ReturnCmd, SetattrCmd, + ExportCmd, + ReadonlyCmd, SetCmd, + UnSetCmd, ShiftCmd, ShoptCmd, SourceCmd, @@ -93,260 +110,365 @@ 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 UnAliasComand ; + impl CommandExec for UnAliasComand{ + fn excute(&self,list : *mut WordList)-> i32{ + unsafe { + r_unalias_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 ContinueComand; + impl CommandExec for ContinueComand{ + fn excute(&self,list : *mut WordList)-> i32{ + r_continue_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 PwdComand; +impl CommandExec for PwdComand{ + fn excute(&self,list : *mut WordList)-> i32{ + r_pwd_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 FalseComand; +impl CommandExec for FalseComand{ + fn excute(&self,list :*mut WordList)-> i32{ + r_false_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){ - unsafe { - r_alias_builtin(list); - } + fn excute(&self,list : *mut WordList)-> i32{ + 0 } } 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 CompgenCommand; +impl CommandExec for CompgenCommand{ + fn excute(&self,list : *mut WordList)-> i32{ + r_compgen_builtin(list) + } +} + +struct CompoptCommand; +impl CommandExec for CompoptCommand{ + fn excute(&self,list : *mut WordList)-> i32{ + r_compopt_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 LocalComand; + impl CommandExec for LocalComand{ + fn excute(&self,list : *mut WordList)-> i32{ + r_local_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); + 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) } } 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 LogoutCommand; +impl CommandExec for LogoutCommand{ + fn excute(&self,list : *mut WordList)-> i32{ + r_logout_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); + struct FgComand; + impl CommandExec for FgComand{ + fn excute(&self,list : *mut WordList)-> i32{ + r_fg_builtin(list) } +} +struct BgComand; +impl CommandExec for BgComand{ + fn excute(&self,list : *mut WordList)-> i32{ + r_bg_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{ + 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); + struct PushdCommand; + impl CommandExec for PushdCommand{ + fn excute(&self,list : *mut WordList)-> i32{ + r_pushd_builtin(list) } } + +struct PopdComand; +impl CommandExec for PopdComand{ + fn excute(&self,list : *mut WordList)-> i32{ + r_popd_builtin(list) + } +} +struct DirsCommand; +impl CommandExec for DirsCommand{ + fn excute(&self,list : *mut WordList)-> i32{ + r_dirs_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){ - //r_reserve_builtin(list); + 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 ExportComand; +impl CommandExec for ExportComand{ + fn excute(&self,list : *mut WordList)-> i32{ + r_export_builtin(list) + } + +} + +struct ReadonlyComand; +impl CommandExec for ReadonlyComand{ + fn excute(&self,list : *mut WordList)-> i32{ + r_readonly_builtin(list) + } + +} + 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 UnSetComand; +impl CommandExec for UnSetComand{ + fn excute(&self,list : *mut WordList)-> i32{ + r_unset_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) + } + } } 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 +476,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; } @@ -398,12 +520,18 @@ impl Factory for SimpleFactory { CMDType::AliasCmd => Box::new( AliasComand{} ) , + CMDType::UnAliasCmd => Box::new( + UnAliasComand{} + ) , CMDType::BindCmd => Box::new( BindComand{} ), CMDType::BreakCmd => Box::new( BreakComand{} ) , + CMDType::ContinueCmd => Box::new( + ContinueComand{} + ) , CMDType::BuiltinCmd => Box::new( BuiltinComand{} ), @@ -413,21 +541,36 @@ impl Factory for SimpleFactory { CMDType::CdCmd => Box::new( CdComand{} ), + CMDType::PwdCmd => Box::new( + PwdComand{} + ), CMDType::ColonCmd => Box::new( ColonComand{} ), + CMDType::FalseCmd => Box::new( + FalseComand{} + ), CMDType::CommandCmd => Box::new( CommandComand{} ), CMDType::CommonCmd => Box::new( - CommandComand{} + CommonComand{} ), CMDType::CompleteCmd => Box::new( CompleteComand{} ), + CMDType::CompoptCmd => Box::new( + CompoptCommand{} + ), + CMDType::CompgenCmd => Box::new( + CompgenCommand{} + ), CMDType::DeclareCmd => Box::new( DeclareComand{} ), + CMDType::LocalCmd => Box::new( + LocalComand{} + ), CMDType::EchoCmd => Box::new( EchoComand{} ), @@ -443,11 +586,17 @@ impl Factory for SimpleFactory { CMDType::ExitCmd => Box::new( ExitComand{} ), + CMDType::LogoutCmd => Box::new( + LogoutCommand{} + ), CMDType::FcCmd => Box::new( FcComand{} ), - CMDType::FgbgCmd => Box::new( - FgbgComand{} + CMDType::FgCmd => Box::new( + FgComand{} + ), + CMDType::BgCmd => Box::new( + BgComand{} ), CMDType::GetoptsCmd => Box::new( GetoptsComand{} @@ -477,7 +626,13 @@ impl Factory for SimpleFactory { PrintfComand{} ), CMDType::PushdCmd => Box::new( - PushdComand{} + PushdCommand{} + ), + CMDType::DirsCmd => Box::new( + DirsCommand{} + ), + CMDType::PopdCmd => Box::new( + PopdComand{} ), CMDType::ReadCmd => Box::new( ReadComand{} @@ -491,9 +646,18 @@ impl Factory for SimpleFactory { CMDType::SetattrCmd => Box::new( SetattrComand{} ), + CMDType::ExportCmd => Box::new( + ExportComand{} + ), + CMDType::ReadonlyCmd => Box::new( + ReadonlyComand{} + ), CMDType::SetCmd => Box::new( SetComand{} ), + CMDType::UnSetCmd => Box::new( + UnSetComand{} + ), CMDType::ShiftCmd => Box::new( ShiftComand{} ), @@ -531,146 +695,215 @@ 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{ + if libc::strcmp(command, b"unalias\0" as *const u8 as *const i8 as *mut i8) == 0{ + types = CMDType::UnAliasCmd; + } + 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"continue\0" as *const u8 as *const i8 as *mut i8) == 0 { + types = CMDType::ContinueCmd; + } + 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"pwd\0" as *const u8 as *const i8 as *mut i8) == 0{ + types = CMDType::PwdCmd; + } + else if libc::strcmp(command, b":\0" as *const u8 as *const i8 as *mut i8) == 0 + || libc::strcmp(command, b"true\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"false\0" as *const u8 as *const i8 as *mut i8) == 0{ + types = CMDType::FalseCmd; + } + 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{ + else if libc::strcmp(command, b"compopt\0" as *const u8 as *const i8 as *mut i8) == 0{ + types = CMDType::CompoptCmd; + } + else if libc::strcmp(command, b"compgen\0" as *const u8 as *const i8 as *mut i8) == 0{ + types = CMDType::CompgenCmd; + } + else if libc::strcmp(command,b"declare\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::DeclareCmd; } - else if command == b"echo\0" as *const u8 as *const i8 as *mut i8{ + else if libc::strcmp(command,b"local\0" as *const u8 as *const i8 as *mut i8) == 0{ + types = CMDType::LocalCmd; + } + 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"logout\0" as *const u8 as *const i8 as *mut i8) == 0{ + types = CMDType::LogoutCmd; + } + 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{ - types = CMDType::FgbgCmd; + + else if libc::strcmp(command,b"fg\0" as *const u8 as *const i8 as *mut i8) == 0{ + types = CMDType::FgCmd; + } + else if libc::strcmp(command,b"bg\0" as *const u8 as *const i8 as *mut i8) == 0{ + types = CMDType::BgCmd; } - 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,b"help\0" as *const u8 as *const i8 as * mut i8) == 0 { 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 || + libc::strcmp(command, b"readarray\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"dirs\0" as *const u8 as *const i8 as *mut i8) == 0{ + types = CMDType::DirsCmd; + } + else if libc::strcmp(command,b"popd\0" as *const u8 as *const i8 as *mut i8) == 0{ + types = CMDType::PopdCmd; + } + 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 + || libc::strcmp(command,b"typeset\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"unset\0" as *const u8 as *const i8 as *mut i8) == 0 { + types = CMDType::UnSetCmd; + } + 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"readonly\0" as *const u8 as *const i8 as *mut i8) == 0{ + types = CMDType::ReadonlyCmd; + } + else if libc::strcmp(command,b"export\0" as *const u8 as *const i8 as *mut i8) == 0{ + types = CMDType::ExportCmd; + } + 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 8f70ce26c2303b630ec61f22d3379a430c5e5365..6354a9e5769782a5533015e54413e3c0f73d4657 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 77e058cf7890670c26f37492facfa6944814edea..8fae15e6f29cffd6f85fe49edd2598be8982fe48 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 5192ebbc89f9d10daaabd4afd8b24bf77e106080..dcb84cb08cc7cc1f3e9f1c3e08a06856b9368919 100644 --- a/record.txt +++ b/record.txt @@ -25,3 +25,9 @@ 47 48 49 +50 +51 +52 +53 +54 +55