From c22edb862c68d915778743f91910557ebf0ba8ef Mon Sep 17 00:00:00 2001 From: liutong Date: Thu, 10 Aug 2023 23:44:39 +0800 Subject: [PATCH] fixed some command segmentation fault --- bash-5.1/builtins_rust/break_1/src/lib.rs | 3 +- bash-5.1/builtins_rust/builtin/src/lib.rs | 5 +- bash-5.1/builtins_rust/echo/src/lib.rs | 2 +- bash-5.1/builtins_rust/eval/src/lib.rs | 9 - bash-5.1/builtins_rust/exec_cmd/src/lib.rs | 279 +++++++++++++++++---- bash-5.1/builtins_rust/help/src/lib.rs | 28 ++- bash-5.1/builtins_rust/read/src/lib.rs | 40 +-- bash-5.1/builtins_rust/type/src/lib.rs | 11 +- record.txt | 1 + 9 files changed, 294 insertions(+), 84 deletions(-) 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 a2f0a63..54df7d5 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/builtin/src/lib.rs b/bash-5.1/builtins_rust/builtin/src/lib.rs index 017a2a2..3965d5b 100644 --- a/bash-5.1/builtins_rust/builtin/src/lib.rs +++ b/bash-5.1/builtins_rust/builtin/src/lib.rs @@ -6,15 +6,14 @@ include!(concat!("intercdep.rs")); pub extern "C" fn r_builtin_builtin(mut list: *mut WordList) -> i32 { unsafe{ let mut function: Option:: = None; - let mut command: &CStr = CStr::from_ptr((*(*list).word).word as *mut c_char); if no_options(list) != 0 { return EX_USAGE; } list = loptend; - if list.is_null() { + if list == std::ptr::null_mut() { return EXECUTION_SUCCESS!(); } - + let mut command: &CStr = CStr::from_ptr((*(*list).word).word as *mut c_char); function = find_shell_builtin(command.as_ptr() as *mut c_char); if function.is_none() { sh_notbuiltin(command.as_ptr() as *mut c_char); diff --git a/bash-5.1/builtins_rust/echo/src/lib.rs b/bash-5.1/builtins_rust/echo/src/lib.rs index 79a74fe..5905670 100644 --- a/bash-5.1/builtins_rust/echo/src/lib.rs +++ b/bash-5.1/builtins_rust/echo/src/lib.rs @@ -91,7 +91,7 @@ pub extern "C" fn r_echo_builtin(mut list:*mut WordList)->i32{ // if posixly_correct!=0 && xpg_echo!=0{ //xpg_echo=0,所以这个可能不用翻译 // } - if (*(*list).word).word != std::ptr::null_mut(){ + if !list.is_null() && (*list).word != std::ptr::null_mut() && (*(*list).word).word != std::ptr::null_mut(){ temp = (*(*list).word).word; } while !list.is_null() && *temp=='-' as c_char{ diff --git a/bash-5.1/builtins_rust/eval/src/lib.rs b/bash-5.1/builtins_rust/eval/src/lib.rs index 33fcbb9..a882f3c 100644 --- a/bash-5.1/builtins_rust/eval/src/lib.rs +++ b/bash-5.1/builtins_rust/eval/src/lib.rs @@ -43,15 +43,6 @@ pub extern "C" fn r_eval_builtin(mut list:*mut WordList)->i32{ } - - - - - - - - - #[cfg(test)] mod tests { #[test] 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 0779d99..0a31ece 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 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; @@ -49,23 +49,32 @@ 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, @@ -76,11 +85,16 @@ enum CMDType { MapfileCmd, PrintfCmd, PushdCmd, + DirsCmd, + PopdCmd, ReadCmd, ReservedCmd, ReturnCmd, SetattrCmd, + ExportCmd, + ReadonlyCmd, SetCmd, + UnSetCmd, ShiftCmd, ShoptCmd, SourceCmd, @@ -102,6 +116,15 @@ enum CMDType { } } } + 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)-> i32{ @@ -113,6 +136,12 @@ enum CMDType { 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{ @@ -132,12 +161,26 @@ enum CMDType { 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)-> 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{ @@ -151,9 +194,7 @@ enum CMDType { struct CommonComand; impl CommandExec for CommonComand{ fn excute(&self,list : *mut WordList)-> i32{ - unsafe { - r_alias_builtin(list) - } + 0 } } struct CompleteComand; @@ -162,12 +203,34 @@ enum CMDType { 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)-> 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)-> i32{ @@ -178,7 +241,6 @@ enum CMDType { impl CommandExec for EnableComand{ fn excute(&self,list : *mut WordList)-> i32{ unsafe { - println!("=======================d============="); r_enable_builtin(list) } } @@ -186,8 +248,7 @@ enum CMDType { struct EvalComand; impl CommandExec for EvalComand{ fn excute(&self,list : *mut WordList)-> i32{ - // r_eval_builtin(list) - 0 + r_eval_builtin(list) } } struct ExecComand; @@ -202,17 +263,30 @@ enum CMDType { 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)-> i32{ r_fc_builtin(list) } } - struct FgbgComand; - impl CommandExec for FgbgComand{ + 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{ @@ -229,7 +303,6 @@ enum CMDType { struct HelpComand; impl CommandExec for HelpComand{ fn excute(&self,list : *mut WordList)-> i32{ - println!("==============help========"); r_help_builtin(list) } } @@ -269,12 +342,25 @@ enum CMDType { r_printf_builtin(list) } } - struct PushdComand; - impl CommandExec for PushdComand{ + 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)-> i32{ @@ -284,8 +370,8 @@ enum CMDType { struct ReservedComand; impl CommandExec for ReservedComand{ fn excute(&self,list : *mut WordList)-> i32{ - //r_reserve_builtin(list); - 0 + // r_reserve_builtin(list) + 0 } } struct ReturnComand; @@ -303,12 +389,36 @@ enum CMDType { } } +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)-> 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{ @@ -319,10 +429,9 @@ enum CMDType { struct ShoptComand; impl CommandExec for ShoptComand{ fn excute(&self,list : *mut WordList)-> i32{ - // unsafe { - // r_shopt_builtin(list) - // } - 0 + unsafe { + r_shopt_builtin(list) + } } } struct SourceComand; @@ -411,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{} ), @@ -426,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{} ), @@ -456,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{} @@ -490,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{} @@ -504,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{} ), @@ -549,12 +700,18 @@ unsafe fn get_cmd_type (command : *mut i8) -> CMDType{ if libc::strcmp(command, b"alias\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::AliasCmd; } + 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 libc::strcmp(command, b"break\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::BreakCmd; } + 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; } @@ -564,9 +721,16 @@ unsafe fn get_cmd_type (command : *mut i8) -> CMDType{ else if libc::strcmp(command, b"cd\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::CdCmd; } - else if libc::strcmp(command, b"colon\0" as *const u8 as *const i8 as *mut i8) == 0{ + 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 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; } @@ -576,8 +740,17 @@ unsafe fn get_cmd_type (command : *mut i8) -> CMDType{ else if libc::strcmp(command, b"complete\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::CompleteCmd; } + 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::CompleteCmd; + types = CMDType::DeclareCmd; + } + 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; @@ -597,13 +770,18 @@ unsafe fn get_cmd_type (command : *mut i8) -> CMDType{ else if libc::strcmp(command,b"exit\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::ExitCmd; } - + 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 libc::strcmp(command,b"fg\0" as *const u8 as *const i8 as *mut i8) == 0{ - types = CMDType::FgbgCmd; + 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 libc::strcmp(command,b"getopts\0" as *const u8 as *const i8 as *mut i8) == 0 { @@ -613,8 +791,7 @@ unsafe fn get_cmd_type (command : *mut i8) -> CMDType{ else if libc::strcmp(command, b"hash\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::HashCmd; } - else if libc::strcmp(command,CString::new("help").unwrap().as_ptr() as * mut i8) == 0 { - println!("222222222========222222"); + else if libc::strcmp(command,b"help\0" as *const u8 as *const i8 as * mut i8) == 0 { types = CMDType::HelpCmd; } else if libc::strcmp(command,b"history\0" as *const u8 as *const i8 as *mut i8) == 0 { @@ -626,7 +803,8 @@ unsafe fn get_cmd_type (command : *mut i8) -> CMDType{ else if libc::strcmp(command, b"kill\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::KillCmd; } - else if libc::strcmp(command, b"mapfile\0" as *const u8 as *const i8 as *mut i8) == 0{ + 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{ @@ -635,6 +813,12 @@ unsafe fn get_cmd_type (command : *mut i8) -> CMDType{ else if libc::strcmp(command,b"pushd\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::PushdCmd; } + 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; } @@ -646,14 +830,23 @@ unsafe fn get_cmd_type (command : *mut i8) -> CMDType{ else if libc::strcmp(command,b"return\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::ReturnCmd; } - else if libc::strcmp(command,b"set\0" as *const u8 as *const i8 as *mut i8) == 0 { + 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 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 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; } diff --git a/bash-5.1/builtins_rust/help/src/lib.rs b/bash-5.1/builtins_rust/help/src/lib.rs index 16bedff..390f3a9 100644 --- a/bash-5.1/builtins_rust/help/src/lib.rs +++ b/bash-5.1/builtins_rust/help/src/lib.rs @@ -100,7 +100,7 @@ extern "C"{ #[no_mangle] pub extern "C" fn r_help_builtin(mut list:*mut WordList)->i32 { - + // let mut i:i32; let mut plen:usize; let mut match_found:i32; @@ -125,9 +125,9 @@ pub extern "C" fn r_help_builtin(mut list:*mut WordList)->i32 { let optu8:u8= i as u8; let optChar:char=char::from(optu8); match optChar{ - 'd'=> {dflag = 1; break;} - 'm'=> {mflag = 1; break;} - 's'=> {sflag = 1; break;} + 'd'=> {dflag = 1; } + 'm'=> {mflag = 1; } + 's'=> {sflag = 1; } _=>{ unsafe { if i == -99 { @@ -139,12 +139,23 @@ pub extern "C" fn r_help_builtin(mut list:*mut WordList)->i32 { } } } + unsafe{ + i = internal_getopt (list, c_str_dms.as_ptr() as * mut c_char); + } + } + if list == std::ptr::null_mut(){ + unsafe { + show_shell_version (0); + } + show_builtin_command_help (); + return EXECUTION_SUCCESS!(); } unsafe { - let pattern = glob_pattern_p ((*(*list).word).word); - if (pattern == 1){ + let mut pattern = 0; + pattern = glob_pattern_p ((*(*list).word).word); + if pattern == 1 { println!("Shell commands matching keyword, Shell commands matching keyword"); - if (*list).next !=std::ptr::null_mut() { + if list != std::ptr::null_mut() && (*list).next !=std::ptr::null_mut() { println!("Shell commands matching keywords"); } else { @@ -152,7 +163,8 @@ pub extern "C" fn r_help_builtin(mut list:*mut WordList)->i32 { } println!("{:?} ,",list); } - let mut loptendt=*list; + // let mut loptendt=*list; + let mut match_found = 0; let mut pattern:*mut c_char = 0 as *mut libc::c_char; while list !=std::ptr::null_mut() { diff --git a/bash-5.1/builtins_rust/read/src/lib.rs b/bash-5.1/builtins_rust/read/src/lib.rs index 946f8f9..da68f6e 100644 --- a/bash-5.1/builtins_rust/read/src/lib.rs +++ b/bash-5.1/builtins_rust/read/src/lib.rs @@ -159,20 +159,7 @@ unsafe { tmusec = uval as c_uint; } } - 'N' => { - ignore_delim = 1; - delim = -1; - } - 'n' => { - nflag = 1; - code = legal_number(list_optarg, &mut intval); - if code == 0 || intval < 0 || intval != (intval as c_int) as c_long { - sh_invalidnum(list_optarg); - return EXECUTION_FAILURE; - } else { - nchars = intval as c_int; - } - } + 'u' => { code = legal_number(list_optarg, &mut intval); if code == 0 || intval < 0 || intval != (intval as c_int) as c_long { @@ -193,6 +180,31 @@ unsafe { } _ => { + if (opt_char == 'N'){ + ignore_delim = 1; + delim = -1; + nflag = 1; + code = legal_number(list_optarg, &mut intval); + if code == 0 || intval < 0 || intval != (intval as c_int) as c_long { + sh_invalidnum(list_optarg); + return EXECUTION_FAILURE; + } else { + nchars = intval as c_int; + } + break; + } + if (opt_char == 'n') + { + nflag = 1; + code = legal_number(list_optarg, &mut intval); + if code == 0 || intval < 0 || intval != (intval as c_int) as c_long { + sh_invalidnum(list_optarg); + return EXECUTION_FAILURE; + } else { + nchars = intval as c_int; + } + break; + } // builtin_usage(); r_builtin_usage (); return EX_USAGE; diff --git a/bash-5.1/builtins_rust/type/src/lib.rs b/bash-5.1/builtins_rust/type/src/lib.rs index c2318bf..ddf85bf 100644 --- a/bash-5.1/builtins_rust/type/src/lib.rs +++ b/bash-5.1/builtins_rust/type/src/lib.rs @@ -362,7 +362,7 @@ extern "C" { fn sh_single_quote(quote: *const i8) -> *mut i8; fn find_reserved_word(word: *mut i8)->i32; fn find_function (name:* const i8)-> *mut SHELL_VAR; - fn named_function_string (name: *mut i8, cmd:* mut i8, i:i32)->* mut i8; + fn named_function_string (name: *mut i8, cmd:* mut COMMAND, i:i32)->* mut i8; fn find_shell_builtin(builtin: *mut i8) -> *mut i8; fn find_special_builtin(builtins: *mut i8) -> *mut sh_builtin_func_t; fn absolute_program(program:*const i8) -> i32; @@ -566,15 +566,16 @@ fn describe_command (command : *mut i8, dflags : i32) -> i32 { } } else if dflags & CDESC_SHORTDESC!() != 0 { - let result : *mut i8; + let mut result : *mut i8; unsafe { println!("{:?} is a function",CStr::from_ptr(command)); - result = named_function_string (command, unsafe{function_cell(func) as *mut i8}, FUNC_MULTILINE!()|FUNC_EXTERNAL!()); - println!("{:?}",CStr::from_ptr(result)); + result = named_function_string (command, function_cell(find_function (command)), FUNC_MULTILINE!()|FUNC_EXTERNAL!()); + println!("{:?}",CStr::from_ptr(result)); } } - else if dflags & CDESC_REUSABLE!() != 0{ + else if dflags & CDESC_REUSABLE!() != 0{ + unsafe { println!("{:?}",CStr::from_ptr(command)); } diff --git a/record.txt b/record.txt index 4a2b69c..4567e56 100644 --- a/record.txt +++ b/record.txt @@ -54,3 +54,4 @@ 53 54 55 +56 -- Gitee