diff --git a/bash-5.1/builtins_rust/cd/src/lib.rs b/bash-5.1/builtins_rust/cd/src/lib.rs index a44fe505c56cdcc65c3295ef85164238d969beef..1025580eb7aa141b5a54f4579699791ecc423550 100644 --- a/bash-5.1/builtins_rust/cd/src/lib.rs +++ b/bash-5.1/builtins_rust/cd/src/lib.rs @@ -344,9 +344,7 @@ extern "C" { fn same_file (path1:*const c_char, path2:*const c_char, stp1:*mut libc::stat, stp2:*mut libc::stat)->i32; fn make_absolute (str1:*const c_char, dot_path:*const c_char)->* mut c_char; fn sh_canonpath (path:* mut c_char, flags:i32)->* mut c_char; - fn set_working_directory (path:* mut c_char); - fn builtin_help(); - + fn set_working_directory (path:* mut c_char); } pub static mut xattrfd:i32=-1; @@ -501,10 +499,6 @@ pub extern "C" fn r_cd_builtin (mut list:*mut WordList)->i32 { 'L'=>{no_symlinks = 0;} 'e'=>{eflag = 1;} _=>{ - if opt == -99 { - builtin_help(); - return EX_USAGE; - } builtin_usage (); return EX_USAGE; } @@ -666,12 +660,7 @@ pub extern "C" fn r_pwd_builtin (list:* mut WordList)->i32 { 'P'=>{verbatim_pwd =1; pflag = 1;} 'L'=>{verbatim_pwd = 0;} - _=>{ - if opt == -99 { - builtin_help(); - return EX_USAGE; - } - builtin_usage (); + _=>{builtin_usage (); return EX_USAGE; } } diff --git a/bash-5.1/builtins_rust/command/src/lib.rs b/bash-5.1/builtins_rust/command/src/lib.rs index 3c2347ac3283c0acf1ee9d669985b7dcd892eecf..b7f593deeadd6d95c9875232fbc8a00b5c1b3500 100644 --- a/bash-5.1/builtins_rust/command/src/lib.rs +++ b/bash-5.1/builtins_rust/command/src/lib.rs @@ -247,7 +247,7 @@ pub const CDESC_STDPATH: i32 = 0x100; //#define CDESC_STDPATH 0x100 /* command -p */ -pub const const_command_builtin:*mut libc::c_char = b"command_builtin\0" as *const u8 as *const libc::c_char as *mut libc::c_char;//.unwrap(); +pub const const_command_builtin:&CStr =unsafe{ CStr::from_bytes_with_nul_unchecked(b"command_builtin\0")};//.unwrap(); //#define COMMAND_BUILTIN_FLAGS (CMD_NO_FUNCTIONS | CMD_INHIBIT_EXPANSION | CMD_COMMAND_BUILTIN | (use_standard_path ? CMD_STDPATH : 0)) //#define CMD_WANT_SUBSHELL 0x01 /* User wants a subshell: ( command ) */ //#define CMD_FORCE_SUBSHELL 0x02 /* Shell needs to force a subshell. */ @@ -345,7 +345,7 @@ pub unsafe extern "C" fn r_command_builtin(mut list: *mut WordList) -> libc::c_i return if any_found != 0 { EXECUTION_SUCCESS!() } else { EXECUTION_FAILURE!() }; } begin_unwind_frame( - const_command_builtin + const_command_builtin.as_ptr() as *mut libc::c_char ); command = make_bare_simple_command(); // let ref mut fresh0 = (*(*command).value.Simple).words; diff --git a/bash-5.1/builtins_rust/common/Cargo.toml b/bash-5.1/builtins_rust/common/Cargo.toml index 374f067fa7a3dbe1753af1cb1e9385a325fa611b..a180848df16c907213f174d8b8b639b659d44cc3 100644 --- a/bash-5.1/builtins_rust/common/Cargo.toml +++ b/bash-5.1/builtins_rust/common/Cargo.toml @@ -8,7 +8,8 @@ edition = "2021" [dependencies] libc = "0.2" nix = "0.24" -unic-langid = "0.9.0" + + [lib] crate-type = ["staticlib","rlib"] name = "rcommon" diff --git a/bash-5.1/builtins_rust/common/src/lib.rs b/bash-5.1/builtins_rust/common/src/lib.rs index 1e48063864edccc01012cb39dad7d68d6d0b07e6..fa1361f8f56d1d108639e1dc065001ed3519ae37 100644 --- a/bash-5.1/builtins_rust/common/src/lib.rs +++ b/bash-5.1/builtins_rust/common/src/lib.rs @@ -6,8 +6,7 @@ use std::ffi::{CStr, CString}; use std::mem::size_of; use std::ptr::read_volatile; use nix::errno::errno; -use std::env::var; -use unic_langid::LanguageIdentifier; + include!(concat!("lib_readline_keymaps.rs")); include!(concat!("command.rs")); @@ -520,14 +519,14 @@ macro_rules! VUNSETATTR { #[macro_export] macro_rules! ISOCTAL { ($c:expr) => { - ($c) >= b'0' as libc::c_char && ($c) <= b'7' as libc::c_char + ($c) >= b'0' as i8 && ($c) <= b'7' as i8 }; } #[macro_export] macro_rules! DIGIT { ($c:expr) => { - ($c) >= b'0' as libc::c_char && ($c) <= b'9' as libc::c_char + ($c) >= b'0' as i8 && ($c) <= b'9' as i8 }; } @@ -663,7 +662,6 @@ extern "C"{ fn builtin_help(); fn builtin_error(format:*const c_char,...); - } unsafe fn ISOPTION(s:* const c_char, c:c_char)->bool @@ -748,7 +746,7 @@ pub extern "C" fn r_no_options(list:*mut WordList)->i32{ reset_internal_getopt(); let c_str = CString::new("").unwrap(); let c_ptr = c_str.as_ptr(); - opt = internal_getopt(list,c_ptr as *mut libc::c_char); + opt = internal_getopt(list,c_ptr as *mut i8); if opt != -1{ if opt == GETOPT_HELP!(){ builtin_help(); @@ -826,11 +824,11 @@ pub extern "C" fn r_sh_invalidnum(s:*mut c_char){ let mut msg = String::new(); let mut mag_ptr:*const c_char = std::ptr::null_mut(); - if *s == b'0' as libc::c_char && isdigit(*s.offset(1) as c_int) != 0{ + if *s == b'0' as i8 && isdigit(*s.offset(1) as c_int) != 0{ msg.push_str("invalid octal number"); mag_ptr = msg.as_ptr() as *mut c_char; } - else if *s == b'0' as libc::c_char && *s.offset(1) == b'x' as libc::c_char{ + else if *s == b'0' as i8 && *s.offset(1) == b'x' as i8{ msg.push_str("invalid hex number"); mag_ptr = msg.as_ptr() as *mut c_char; } @@ -1150,7 +1148,7 @@ pub extern "C" fn r_get_numeric_arg(mut list:*mut WordList,fatal:i32,count:*mut *count = 1; } - if !list.is_null() && !(*list).word.is_null() && ISOPTION((*(*list).word).word,b'-' as libc::c_char){ + if !list.is_null() && !(*list).word.is_null() && ISOPTION((*(*list).word).word,b'-' as i8){ list = (*list).next; } @@ -1161,7 +1159,7 @@ pub extern "C" fn r_get_numeric_arg(mut list:*mut WordList,fatal:i32,count:*mut r_sh_neednumarg((*(*list).word).word); } else { - r_sh_neednumarg(String::from("`'").as_ptr() as *mut libc::c_char); + r_sh_neednumarg(String::from("`'").as_ptr() as *mut i8); } if fatal == 0{ @@ -1190,7 +1188,7 @@ pub extern "C" fn r_get_exitstat(mut list:*mut WordList)->i32{ let arg:*mut c_char; unsafe{ - if !list.is_null() && !(*list).word.is_null() && ISOPTION((*(*list).word).word,b'-' as libc::c_char){ + if !list.is_null() && !(*list).word.is_null() && ISOPTION((*(*list).word).word,b'-' as i8){ list = (*list).next; } @@ -1213,7 +1211,7 @@ pub extern "C" fn r_get_exitstat(mut list:*mut WordList)->i32{ r_sh_neednumarg((*(*list).word).word); } else { - r_sh_neednumarg(String::from("`'").as_ptr() as *mut libc::c_char); + r_sh_neednumarg(String::from("`'").as_ptr() as *mut i8); } return EX_BADUSAGE!(); @@ -1236,7 +1234,7 @@ pub extern "C" fn r_read_octal(mut string:*mut c_char)->i32{ unsafe{ while *string!=0 && ISOCTAL!(*string){ digits += 1; - result = (result * 8) + (*string - b'0' as libc::c_char) as i32; + result = (result * 8) + (*string - b'0' as i8) as i32; string = (string as usize + 1 ) as *mut c_char; if result > 0o7777{ return -1; @@ -1392,11 +1390,11 @@ pub extern "C" fn r_get_job_spec(list:*mut WordList)->i32{ word = (*(*list).word).word; - if *word.offset(0) == '\0' as libc::c_char { + if *word.offset(0) == '\0' as i8 { return NO_JOB!(); } - if *word.offset(0) == '%' as libc::c_char { + if *word.offset(0) == '%' as i8 { word = word.offset(1); } @@ -1732,7 +1730,7 @@ pub extern "C" fn r_builtin_bind_variable(name:*mut c_char,value:*mut c_char,fla /* Like check_unbind_variable, but for use by builtins (only matters for error messages). */ - pub extern "C" fn r_builtin_unbind_variable(vname:*const c_char)->i32{ +pub extern "C" fn r_builtin_unbind_variable(vname:*const c_char)->i32{ let v:*mut SHELL_VAR; unsafe{ @@ -1755,20 +1753,3 @@ pub extern "C" fn r_builtin_bind_variable(name:*mut c_char,value:*mut c_char,fla } } -pub extern "C" fn get_local_str()-> Vec{ - - let lang : String; - match var("LANGUAGE") { - Ok(v) => lang = v , - Err(e) => - { - lang = String::from("en-US"); - println!("err is {e:?}") - }, - } - println!("now language is {:?}",lang); - //parse() 用于类型转换 - let langid : LanguageIdentifier = lang.parse().expect("wrong language"); - let locales = vec![langid.into()]; - return locales; - } \ No newline at end of file diff --git a/bash-5.1/builtins_rust/complete/src/lib.rs b/bash-5.1/builtins_rust/complete/src/lib.rs index a3254b4f6bad2f00882c3120d479f3678ae4b4ff..9dd58df4447e7ed94457e37ea33b672002f9442f 100644 --- a/bash-5.1/builtins_rust/complete/src/lib.rs +++ b/bash-5.1/builtins_rust/complete/src/lib.rs @@ -554,7 +554,6 @@ extern "C" { fn sh_invalidid (value:* mut c_char); fn sh_invalidoptname (value:* mut c_char); fn builtin_usage(); - fn builtin_help(); static list_optarg:* mut c_char; fn builtin_error(err:*const c_char,...); fn check_identifier (w:* mut WordDesc, f:i32)->i32; @@ -823,10 +822,6 @@ pub extern "C" fn r_build_actions (list : *mut WordList, flagp:* mut _optflags, Xarg = list_optarg; } _=>{ - if opt == -99 { - builtin_help(); - return EX_USAGE; - } builtin_usage (); return EX_USAGE; } diff --git a/bash-5.1/builtins_rust/declare/src/lib.rs b/bash-5.1/builtins_rust/declare/src/lib.rs index 6da37b1294d8f4cb9fb874e1cf31ed8a5db2012a..eede3a82011608e5b881dbe1b6343bb3b3550b8d 100644 --- a/bash-5.1/builtins_rust/declare/src/lib.rs +++ b/bash-5.1/builtins_rust/declare/src/lib.rs @@ -716,12 +716,7 @@ pub extern "C" fn r_declare_internal (list:* mut WordList, local_var:i32)->i32 } } 'I'=>{ inherit_flag = MKLOC_INHERIT!();} - _=>{ - if opt == -99 { - builtin_help(); - return EX_USAGE; - } - builtin_usage (); + _=>{ builtin_usage (); return EX_USAGE; } } diff --git a/bash-5.1/builtins_rust/exec/src/lib.rs b/bash-5.1/builtins_rust/exec/src/lib.rs index d2a4aff49b5ed5354d66b194da49f168e4bac058..ca8399dbda1e308c7226d6e410baf7fc3fdf4957 100644 --- a/bash-5.1/builtins_rust/exec/src/lib.rs +++ b/bash-5.1/builtins_rust/exec/src/lib.rs @@ -135,7 +135,7 @@ extern "C" fn r_mkdashname(name:*mut c_char)->*mut c_char{ unsafe{ ret = xmalloc(2 + strlen(name)) as *mut c_char; - *ret.offset(0) = '-' as libc::c_char; + *ret.offset(0) = '-' as i8; strcpy(ret.offset(1), name); return ret; } 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 3aad47b4d0810cbc7b5e09a9df490131931c5bf0..0a31ecedb72eb7bb98da2f14c1aff868e7999efa 100644 --- a/bash-5.1/builtins_rust/exec_cmd/src/lib.rs +++ b/bash-5.1/builtins_rust/exec_cmd/src/lib.rs @@ -695,201 +695,200 @@ impl Factory for SimpleFactory { } } -unsafe fn get_cmd_type (command : *mut libc::c_char) -> CMDType{ +unsafe fn get_cmd_type (command : *mut i8) -> CMDType{ let mut types = CMDType::HelpCmd; - if libc::strcmp(command, b"alias\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0 { + 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 libc::c_char as *mut libc::c_char) == 0 { + 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 libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command, b"builtin\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::BuiltinCmd; } - else if libc::strcmp(command, b"caller\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command, b"caller\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::CallerCmd; } - else if libc::strcmp(command, b"cd\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + 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"pwd\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 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 libc::c_char as *mut libc::c_char) == 0 - || libc::strcmp(command, b"true\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command, b"command\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::CommandCmd; } - else if libc::strcmp(command, b"common\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command, b"common\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::CommonCmd; } - else if libc::strcmp(command, b"complete\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command,b"declare\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::DeclareCmd; } - else if libc::strcmp(command,b"local\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command,b"echo\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::EchoCmd; } - else if libc::strcmp(command,b"enable\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command,b"enable\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::EnableCmd; } - else if libc::strcmp(command,b"eval\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command,b"eval\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::EvalCmd; } - else if libc::strcmp(command,b"exec\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command,b"exec\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::ExecCmd; } - else if libc::strcmp(command,b"exit\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0 { + 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 libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0 { + else if libc::strcmp(command,b"getopts\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::GetoptsCmd; } - else if libc::strcmp(command, b"hash\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + 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,b"help\0" as *const u8 as *const libc::c_char as * mut libc::c_char) == 0 { + 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 libc::c_char as *mut libc::c_char) == 0 { + else if libc::strcmp(command,b"history\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::HistoryCmd; } - else if libc::strcmp(command,b"jobs\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command,b"jobs\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::JobsCmd; } - else if libc::strcmp(command, b"kill\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0 || - libc::strcmp(command, b"readarray\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 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 libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command,b"printf\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::PrintfCmd; } - else if libc::strcmp(command,b"pushd\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command, b"read\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::ReadCmd; } - else if libc::strcmp(command, b"let\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command, b"let\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::LetCmd; } - else if libc::strcmp(command,b"return\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0 { + 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 libc::c_char as *mut libc::c_char) == 0 - || libc::strcmp(command,b"typeset\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 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 libc::c_char as *mut libc::c_char) == 0 { + 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 libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + 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 libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command,b"shift\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::ShiftCmd; } - else if libc::strcmp(command,b"shopt\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command,b"shopt\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::ShoptCmd; } - else if libc::strcmp(command,b"source\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0 - || libc::strcmp(command,b".\0" as *const u8 as *const libc::c_char as *mut libc::c_char)== 0 { + 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 libc::strcmp(command, b"suspend\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command, b"suspend\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::SuspendCmd; } - else if libc::strcmp(command,b"test\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0 - || libc::strcmp(command,b"[\0" as *const u8 as *const libc::c_char as *mut libc::c_char)== 0 { + else if libc::strcmp(command,b"test\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::TestCmd; } - else if libc::strcmp(command ,b"times\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0 { + else if libc::strcmp(command ,b"times\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::TimesCmd; } - else if libc::strcmp(command ,b"trap\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0 { + else if libc::strcmp(command ,b"trap\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::TrapCmd; } - else if libc::strcmp(command ,b"type\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0 { + else if libc::strcmp(command ,b"type\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::TypeCmd; } - else if libc::strcmp(command ,b"ulimit\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0{ + else if libc::strcmp(command ,b"ulimit\0" as *const u8 as *const i8 as *mut i8) == 0{ types = CMDType::UlimitCmd; } - else if libc::strcmp(command ,b"umask\0" as *const u8 as *const libc::c_char as *mut libc::c_char ) == 0{ + else if libc::strcmp(command ,b"umask\0" as *const u8 as *const i8 as *mut i8 ) == 0{ types = CMDType::UmaskCmd; } - else if libc::strcmp(command , b"wait\0" as *const u8 as *const libc::c_char as *mut libc::c_char) == 0 { + else if libc::strcmp(command , b"wait\0" as *const u8 as *const i8 as *mut i8) == 0 { types = CMDType::WaitCmd; } @@ -897,7 +896,7 @@ unsafe fn get_cmd_type (command : *mut libc::c_char) -> CMDType{ } #[no_mangle] -pub extern "C" fn r_exec_cmd(command : *mut libc::c_char, mut list :*mut WordList) -> i32 { +pub extern "C" fn r_exec_cmd(command : *mut i8, mut list :*mut WordList) -> i32 { println!("enter r_exec_cmd"); unsafe { @@ -907,4 +906,4 @@ pub extern "C" fn r_exec_cmd(command : *mut libc::c_char, mut list :*mut WordLis 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 f57283863e7d99e2abe56c88583321c3882fc728..5d0eb3fcd91a5f7c48574b5291f41da800035aed 100644 --- a/bash-5.1/builtins_rust/fc/src/lib.rs +++ b/bash-5.1/builtins_rust/fc/src/lib.rs @@ -400,19 +400,17 @@ pub extern "C" fn r_set_verbose_flag (){ #[no_mangle] pub extern "C" fn r_fc_number (list:* mut WordList)->i32 { - let mut s:*mut c_char = 0 as *mut libc::c_char; + let mut s:*mut c_char; if list == std::ptr::null_mut(){ return 0; } unsafe { - if (*list).word != std::ptr::null_mut() { - s = (*(*list).word).word; - if char::from(*s as u8 ) == '-' { - s= s.offset(1) ; + s = (*(*list).word).word; + if char::from(*s as u8 ) == '-' { + s=(s as u8 +1) as *mut c_char; } - } return legal_number (s, std::ptr::null_mut()); } } @@ -538,6 +536,7 @@ pub extern "C" fn r_fc_builtin (list:* mut WordList)->i32 opt = internal_getopt (list, CString::new(":e:lnrs").unwrap().as_ptr() as * mut c_char); ret= ret && (opt !=-1); } + let mut llist:* mut WordList = loptend.clone(); if ename != std::ptr::null_mut() && char::from(*ename as u8 ) == '-' && char::from(*((ename as usize +4) as * mut c_char) as u8 )== '\0'{ diff --git a/bash-5.1/builtins_rust/help/Cargo.toml b/bash-5.1/builtins_rust/help/Cargo.toml index 1228246909ca100596ed04a5dc39014978b8690a..993d13e0d1533cd1e18757cb8589fb5f3952316e 100644 --- a/bash-5.1/builtins_rust/help/Cargo.toml +++ b/bash-5.1/builtins_rust/help/Cargo.toml @@ -9,9 +9,6 @@ edition = "2018" libc = "0.2" nix = "0.24.1" rcommon = {path ="../common"} -fluent = "0.16.0" -fluent-bundle = "0.15.2" -fluent-resmgr = "0.0.5" [lib] crate-type = ["staticlib","rlib"] diff --git a/bash-5.1/builtins_rust/help/src/lib.rs b/bash-5.1/builtins_rust/help/src/lib.rs index 281fe0bc3d227cabebc447030810306bb9c810d9..390f3a90c4dbb124380bd3b67af193397d6b851d 100644 --- a/bash-5.1/builtins_rust/help/src/lib.rs +++ b/bash-5.1/builtins_rust/help/src/lib.rs @@ -3,12 +3,8 @@ extern crate nix; extern crate std; use libc::{c_char, c_void ,putchar, free}; use std::{ffi::{CString,CStr}, i32, io::{Read, stdout, Write}, mem, string, u32}; -use rcommon::{WordList, WordDesc, EX_USAGE, EXECUTION_SUCCESS, - EXECUTION_FAILURE, EX_NOTFOUND, EX_NOEXEC, SUBSHELL_PAREN, - r_builtin_usage,get_local_str}; +use rcommon::{WordList, WordDesc, EX_USAGE, EXECUTION_SUCCESS, EXECUTION_FAILURE, EX_NOTFOUND, EX_NOEXEC, SUBSHELL_PAREN,r_builtin_usage}; -use fluent_bundle::{FluentBundle, FluentResource, FluentValue, FluentArgs}; -use fluent_resmgr::resource_manager::ResourceManager; pub enum Option { None, Some(T), @@ -86,7 +82,7 @@ extern "C"{ fn throw_to_top_level(); fn default_columns() -> usize; fn wcsnwidth (chaa : * mut libc::wchar_t, size :i32, i: i32) -> i32; - fn xstrmatch (string1 : * mut libc::c_char, string2 : * mut libc::c_char, i : libc::c_char) -> libc::c_char; + fn xstrmatch (string1 : * mut libc::c_char, string2 : * mut libc::c_char, i : i8) -> i8; fn open(pathname : *const libc::c_char, oflag : i32) -> i32; fn wcwidth( c :libc::wchar_t) -> i32; static mut loptend:*mut WordList; @@ -324,7 +320,7 @@ fn show_longdoc(i : i32){ // usefile = usefile && unsafe{*((doc as usize + 8 as usize)as *mut *mut libc::c_char) as *mut libc::c_char} == std::ptr::null_mut(); //usefile = usefile && ((doc as usize + 8 as usize) as * mut c_char) == std::ptr::null_mut(); //usefile = usefile && (*(doc as usize + 8 as usize) as *mut libc::c_char )as char== '/' as char ; - //usefile = doc!= std::ptr::null_mut() && *((doc as usize + ) as * mut c_char)== '/' as libc::c_char && (doc as usize +4)as * mut c_char == std::ptr::null_mut() as * mut c_char; + //usefile = doc!= std::ptr::null_mut() && *((doc as usize + ) as * mut c_char)== '/' as i8 && (doc as usize +4)as * mut c_char == std::ptr::null_mut() as * mut c_char; } // let usefile = (doc!= std::ptr::null_mut() && char::from(unsafe {*((doc + 4*8) as usize ) as * mut c_char) as u8 })== '/'); if usefile { @@ -361,7 +357,7 @@ fn show_desc (name : *mut c_char, i :i32){ let mut j :i32; let r :i32; let mut doc : *mut *mut libc::c_char; - let mut line : *mut libc::c_char = 0 as *mut libc::c_char ; + let mut line : *mut i8 = 0 as *mut i8 ; let mut fd : i32; let mut usefile : bool; @@ -370,18 +366,18 @@ fn show_desc (name : *mut c_char, i :i32){ doc = builtin1.long_doc; } // usefile = (doc && doc[0] && *doc[0] == '/' && doc[1] == (char *)NULL); - usefile = doc!= std::ptr::null_mut() && unsafe {*doc as *mut libc::c_char} != std::ptr::null_mut(); - usefile = usefile && unsafe {**doc as libc::c_char } == '/' as libc::c_char; - //usefile = usefile && unsafe {*(doc as usize + 8 as usize) as *mut libc::c_char} != std::ptr::null_mut(); + usefile = doc!= std::ptr::null_mut() && unsafe {*doc as *mut i8} != std::ptr::null_mut(); + usefile = usefile && unsafe {**doc as i8 } == '/' as i8; + //usefile = usefile && unsafe {*(doc as usize + 8 as usize) as *mut i8} != std::ptr::null_mut(); if usefile { - fd = open_helpfile (unsafe {*doc as *mut libc::c_char }); + fd = open_helpfile (unsafe {*doc as *mut i8 }); if (fd < 0){ //无返回值 return (); } unsafe { - r = zmapfd (fd, *(line as *mut libc::c_char) as *mut *mut libc::c_char ,(doc as *mut libc::c_char)); + r = zmapfd (fd, *(line as *mut i8) as *mut *mut i8 ,(doc as *mut i8)); libc::close (fd); } /* XXX - handle errors if zmapfd returns < 0 */ @@ -390,7 +386,7 @@ fn show_desc (name : *mut c_char, i :i32){ { if doc!= std::ptr::null_mut() { unsafe { - line = *doc as *mut libc::c_char; + line = *doc as *mut i8; } } else{ @@ -425,19 +421,17 @@ fn show_manpage (name : *mut c_char, i : i32){ let mut j :i32; let mut doc :*mut *mut libc::c_char; - let mut line :*mut libc::c_char = 0 as *mut libc::c_char; + let mut line :*mut libc::c_char = 0 as *mut libc::c_char;; let mut fd: i32; let mut usefile : bool; let builtin1 = unsafe{&(*((shell_builtins as usize + (i*BUILTIN_SIZEOF!()) as usize) as *mut builtin))}; - let mgr = ResourceManager::new("./resources/{locale}/{res_id}".into()); - let resources = vec![ "message.ftl".into()]; unsafe { doc = builtin1.long_doc; } //*doc = (*((shell_builtins as usize + i as usize) as *mut builtin).long_doc as *mut libc::c_char); - usefile = doc!= std::ptr::null_mut() && unsafe {*doc as *mut libc::c_char} != std::ptr::null_mut(); - usefile = usefile && unsafe {**doc as libc::c_char } == '/' as libc::c_char; + usefile = doc!= std::ptr::null_mut() && unsafe {*doc as *mut i8} != std::ptr::null_mut(); + usefile = usefile && unsafe {**doc as i8 } == '/' as i8; if usefile{ @@ -457,7 +451,7 @@ fn show_manpage (name : *mut c_char, i : i32){ if doc!= std::ptr::null_mut(){ unsafe { - line = *doc as *mut libc::c_char; + line = *doc as *mut i8; } } else{ @@ -490,16 +484,13 @@ fn show_manpage (name : *mut c_char, i : i32){ /* DESCRIPTION */ println! ("DESCRIPTION\n"); if !usefile{ - let mut args = FluentArgs::new(); - let c_str: &CStr = unsafe { CStr::from_ptr(builtin1.name) }; - let msg: &str = c_str.to_str().unwrap(); - args.set("cmdName",msg); - let bundle = mgr.get_bundle(get_local_str(), resources); - let value = bundle.get_message("helplongdoc").unwrap(); - let pattern = value.value().expect("partern err"); - let mut errors = vec![]; - let msg1 = bundle.format_pattern(&pattern, Some(&args), &mut errors); - println!("{}", msg1); + let mut j = 0 ; + unsafe { + while (*((doc as usize + (8*j))as *mut *mut c_char)as *mut c_char) != std::ptr::null_mut() { + println! (" {:?}\n", unsafe{CStr::from_ptr(*((doc as usize + (8*j))as *mut *mut c_char)as *mut c_char)}); + j += 1; + } + } } else{ while doc != std::ptr::null_mut() && (((doc as usize + (8*j)))as * mut c_char) != std::ptr::null_mut() { @@ -605,18 +596,18 @@ fn show_builtin_command_help (){ let height : i32 = 76; let mut width : usize; let mut t :*mut libc::c_char; - let mut blurb:[libc::c_char;128] = ['0' as libc::c_char;128]; + let mut blurb:[i8;128] = ['0' as i8;128]; println!("help command edit by huanhuan."); println!("{}",("These shell commands are defined internally. Type `help' to see this list.\n Type `help name' to find out more about the function `name'.\n Use `info bash' to find out more about the shell in general.\n Use `man -k' or `info' to find out more about commands not in this list.\n A star (*) next to a name means that the command is disabled.\n")); - let ref2: &mut libc::c_char= &mut blurb[0]; + let ref2: &mut i8= &mut blurb[0]; unsafe { width = default_columns(); } width /= 2; - if width > (std::mem::size_of::()*128) { - width = std::mem::size_of::()*128; + if width > (std::mem::size_of::()*128) { + width = std::mem::size_of::()*128; } if width <= 3{ width = 40; @@ -629,13 +620,13 @@ fn show_builtin_command_help (){ QUIT(); } if MB_CUR_MAX!() > 1 { - let ptr2: *mut libc::c_char = ref2 as *mut libc::c_char; + let ptr2: *mut i8 = ref2 as *mut i8; wdispcolumn (i, ptr2,128, width as i32, height); } } } //#endif /* HELP_BUILTIN */ -fn strmatch (pattern : *mut libc::c_char, string : *mut libc::c_char, flags : libc::c_char) -> libc::c_char +fn strmatch (pattern : *mut libc::c_char, string : *mut libc::c_char, flags : i8) -> i8 { if ((string as usize)as * mut c_char != std::ptr::null_mut()) || ((pattern as usize)as * mut c_char != std::ptr::null_mut()){ return FNM_NOMATCH!(); @@ -674,4 +665,3 @@ unsafe { // } // len // } - diff --git a/bash-5.1/builtins_rust/history/src/lib.rs b/bash-5.1/builtins_rust/history/src/lib.rs index 54fd1b46adedc712294e329464062b2659b1b49d..37caa34665bfa1594beba574e9bab53759899ece 100644 --- a/bash-5.1/builtins_rust/history/src/lib.rs +++ b/bash-5.1/builtins_rust/history/src/lib.rs @@ -87,9 +87,9 @@ unsafe { 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 libc::c_char, range, c_tmp); + printf(b"AAAAAAArange=%u, c_tmp=%s\n" as *const u8 as *const i8, range, c_tmp); if !range.is_null() { - printf(b"AAAAAAArange=%s\n" as *const u8 as *const libc::c_char, range); + 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; diff --git a/bash-5.1/builtins_rust/jobs/src/lib.rs b/bash-5.1/builtins_rust/jobs/src/lib.rs index 17b62c73aee9d3a22e43fc7f1ace215475da39bd..6354a9e5769782a5533015e54413e3c0f73d4657 100644 --- a/bash-5.1/builtins_rust/jobs/src/lib.rs +++ b/bash-5.1/builtins_rust/jobs/src/lib.rs @@ -391,7 +391,7 @@ extern "C" { } libc::free((*(*l).word).word as * mut libc::c_void); - (*(*(*l).word).word) = (*get_job_by_jid! (job)).pgrp as libc::c_char; + (*(*(*l).word).word) = (*get_job_by_jid! (job)).pgrp as i8; } l=(*l).next; } diff --git a/bash-5.1/builtins_rust/mapfile/src/intercdep.rs b/bash-5.1/builtins_rust/mapfile/src/intercdep.rs index a3ebfc37ae3ec81899b92b0c93b5625ba52c6ac8..8450248d09589efc52448bfe539382c28fadf17c 100644 --- a/bash-5.1/builtins_rust/mapfile/src/intercdep.rs +++ b/bash-5.1/builtins_rust/mapfile/src/intercdep.rs @@ -71,7 +71,6 @@ extern "C" { pub fn reset_internal_getopt(); pub fn internal_getopt(list: *mut WordList, opts: *mut c_char) -> c_int; pub fn builtin_usage(); - fn builtin_help(); pub fn builtin_error(format: *const c_char, ...); pub fn legal_identifier(arg1: *const c_char) -> c_int; diff --git a/bash-5.1/builtins_rust/mapfile/src/lib.rs b/bash-5.1/builtins_rust/mapfile/src/lib.rs index c4d9530da0d9baefddb20b468ebeb5cfbfdc6220..4fa35f5b1b343e7ebedf6b75ee10128a879898ad 100644 --- a/bash-5.1/builtins_rust/mapfile/src/lib.rs +++ b/bash-5.1/builtins_rust/mapfile/src/lib.rs @@ -94,10 +94,6 @@ unsafe { } } _ => { - if opt == -99 { - builtin_help(); - return EX_USAGE; - } r_builtin_usage (); return EX_USAGE; } diff --git a/bash-5.1/builtins_rust/printf/src/intercdep.rs b/bash-5.1/builtins_rust/printf/src/intercdep.rs index 1f133a6f845b11073302e36c686a7e59f7103879..db66567dcfc63e9081874bfb07771a0f07a70f80 100644 --- a/bash-5.1/builtins_rust/printf/src/intercdep.rs +++ b/bash-5.1/builtins_rust/printf/src/intercdep.rs @@ -56,7 +56,6 @@ extern "C" { pub fn reset_internal_getopt(); pub fn internal_getopt(list: *mut WordList, opts: *mut c_char) -> c_int; pub fn builtin_usage(); - fn builtin_help(); pub fn builtin_error(format: *const c_char, ...); pub fn builtin_warning(format: *const c_char, ...); pub fn builtin_bind_variable(name: *mut c_char, value: *mut c_char, flags: c_int) -> *mut SHELL_VAR; diff --git a/bash-5.1/builtins_rust/printf/src/lib.rs b/bash-5.1/builtins_rust/printf/src/lib.rs index 429860b0e01ccd8bb1a06a37d014a5edb5692fde..1a29c02d29c0eb4862f96d059430b2625f18370e 100644 --- a/bash-5.1/builtins_rust/printf/src/lib.rs +++ b/bash-5.1/builtins_rust/printf/src/lib.rs @@ -140,10 +140,6 @@ unsafe { } } _ => { - if opt == -99 { - builtin_help(); - return EX_USAGE; - } r_builtin_usage (); return EX_USAGE; } @@ -190,7 +186,7 @@ unsafe { if *fmt == b'\\' as c_char { fmt = (fmt as usize + 1) as *mut c_char; - let mut mbch: [libc::c_char;25] = [0; 25]; + let mut mbch: [i8;25] = [0; 25]; let mut mblen: c_int = 0; fmt = (fmt as usize + tescape(fmt, mbch.as_ptr() as *mut c_char, std::mem::transmute(&mblen), PT_NULL as *mut c_int) as usize) as *mut c_char; let mut mbind = 0; diff --git a/bash-5.1/builtins_rust/read/src/intercdep.rs b/bash-5.1/builtins_rust/read/src/intercdep.rs index 5c9570a0da3cfd9e93506df7ac46c1cc20b3b647..4ea450bce04cb2bc6cd064d7d8b1e1368724f725 100644 --- a/bash-5.1/builtins_rust/read/src/intercdep.rs +++ b/bash-5.1/builtins_rust/read/src/intercdep.rs @@ -271,7 +271,7 @@ extern "C" { pub fn rl_get_keymap() -> Keymap; pub fn rl_insert(count: c_int, key: c_int) -> c_int; pub fn rl_newline(count: c_int, key: c_int) -> c_int; - fn builtin_help(); + } extern "C" { diff --git a/bash-5.1/builtins_rust/read/src/lib.rs b/bash-5.1/builtins_rust/read/src/lib.rs index d5ae2945b277f78c3f0664ea7641839442a10672..da68f6e4874fecd0ddd9d7dd076312e567db2af6 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' | 'n' => { - if opt_char == 'N' { - ignore_delim = 1; - delim = 255 as u8 as libc::c_char; - } - 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,10 +180,32 @@ unsafe { } _ => { - if opt == -99 { - builtin_help(); - return EX_USAGE; + 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; } @@ -222,7 +231,7 @@ unsafe { //忽略界定符 if ignore_delim != 0{ //-N ignore_delim = 1 - delim = 255 as u8 as libc::c_char; + delim = -1; } ifs_chars = getifs(); //ifs_chars is "\n" diff --git a/bash-5.1/builtins_rust/set/src/lib.rs b/bash-5.1/builtins_rust/set/src/lib.rs index 8caab34f4097120add311ed960f3e45b3a48be39..32066f4e08f081832c20ce9a18c86a0d6feffd97 100644 --- a/bash-5.1/builtins_rust/set/src/lib.rs +++ b/bash-5.1/builtins_rust/set/src/lib.rs @@ -207,7 +207,7 @@ macro_rules! att_array{ #[macro_export] macro_rules! savestring { ($x:expr) => { - libc::strcpy(xmalloc ((1+ strlen ($x)) as u64) as *mut libc::c_char, $x) + libc::strcpy(xmalloc ((1+ strlen ($x)) as u64) as *mut i8, $x) } } @@ -221,9 +221,9 @@ macro_rules! value_cell { #[derive(Copy, Clone)] #[repr(C)] pub struct variable { - pub name: *mut libc::c_char, - pub value: *mut libc::c_char, - pub exportstr: *mut libc::c_char, + pub name: *mut i8, + pub value: *mut i8, + pub exportstr: *mut i8, pub dynamic_value: sh_var_value_func_t, pub assign_func: sh_var_assign_func_t, pub attributes: i32, @@ -233,7 +233,7 @@ pub struct variable { #[derive(Copy, Clone)] #[repr(C)] pub struct opp{ - name : *mut libc::c_char, + name : *mut i8, letter : i32, variable : *mut i32, set_func : Option::, @@ -268,7 +268,7 @@ macro_rules! VA_ONEWORD { pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"allexport\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"allexport\0" as *const u8 as *const i8 as *mut i8, letter : b'a' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -289,7 +289,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"braceexpand\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"braceexpand\0" as *const u8 as *const i8 as *mut i8, letter : b'B' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -308,7 +308,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"emacs\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"emacs\0" as *const u8 as *const i8 as *mut i8, letter : b'\0' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -320,7 +320,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"errexit\0" as *const u8 as *const libc::c_char as *mut libc::c_char , + name : b"errexit\0" as *const u8 as *const i8 as *mut i8 , letter : b'e' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -339,7 +339,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp { - name : b"errtrace\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"errtrace\0" as *const u8 as *const i8 as *mut i8, letter : b'E' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -358,7 +358,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp { - name : b"functrace\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"functrace\0" as *const u8 as *const i8 as *mut i8, letter : b'T' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -377,7 +377,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp { - name : b"hashall\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"hashall\0" as *const u8 as *const i8 as *mut i8, letter : b'h' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -396,7 +396,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"histexpand\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"histexpand\0" as *const u8 as *const i8 as *mut i8, letter : b'H' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -415,7 +415,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"history\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"history\0" as *const u8 as *const i8 as *mut i8, letter : b'\0' as i32, // variable : 0 as *const libc::c_void // as *mut libc::c_void @@ -432,7 +432,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"ignoreeof\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"ignoreeof\0" as *const u8 as *const i8 as *mut i8, letter : b'\0' as i32, /*variable : 0 as *const libc::c_void as *mut libc::c_void @@ -449,7 +449,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"interactive-comments\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"interactive-comments\0" as *const u8 as *const i8 as *mut i8, letter : b'\0' as i32, /*variable : 0 as *const libc::c_void as *mut libc::c_void @@ -469,7 +469,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"keyword\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"keyword\0" as *const u8 as *const i8 as *mut i8, letter : b'k' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -488,7 +488,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"monitor\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"monitor\0" as *const u8 as *const i8 as *mut i8, letter : b'm' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -507,7 +507,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"noclobber\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"noclobber\0" as *const u8 as *const i8 as *mut i8, letter : b'C' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -526,7 +526,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"noexec\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"noexec\0" as *const u8 as *const i8 as *mut i8, letter : b'n' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -545,7 +545,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"noglob\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"noglob\0" as *const u8 as *const i8 as *mut i8, letter : b'f' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -564,7 +564,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"nolog\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"nolog\0" as *const u8 as *const i8 as *mut i8, letter : b'\0' as i32, /*variable : 0 as *const libc::c_void as *mut libc::c_void @@ -584,7 +584,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"notify\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"notify\0" as *const u8 as *const i8 as *mut i8, letter : b'b' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -603,7 +603,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"nounset\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"nounset\0" as *const u8 as *const i8 as *mut i8, letter : b'u' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -622,7 +622,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"onecmd\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"onecmd\0" as *const u8 as *const i8 as *mut i8, letter : b't' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -641,7 +641,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"physical\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"physical\0" as *const u8 as *const i8 as *mut i8, letter : b'P' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -660,7 +660,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"pipefail\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"pipefail\0" as *const u8 as *const i8 as *mut i8, letter : b'\0' as i32, /*variable : 0 as *const libc::c_void as *mut libc::c_void @@ -680,7 +680,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"posix\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"posix\0" as *const u8 as *const i8 as *mut i8, letter : b'\0' as i32, /*variable : 0 as *const libc::c_void as *mut libc::c_void @@ -697,7 +697,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"privileged\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"privileged\0" as *const u8 as *const i8 as *mut i8, letter : b'p' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -716,7 +716,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"verbose\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"verbose\0" as *const u8 as *const i8 as *mut i8, letter : b'v' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -735,7 +735,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"vi\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"vi\0" as *const u8 as *const i8 as *mut i8, letter : b'\0' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -747,7 +747,7 @@ pub static mut o_options : [opp ; 28] = unsafe {[ { opp{ - name : b"xtrace\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + name : b"xtrace\0" as *const u8 as *const i8 as *mut i8, letter : b'x' as i32, variable : 0 as *const libc::c_void as *mut libc::c_void @@ -786,73 +786,72 @@ pub static mut o_options : [opp ; 28] = unsafe {[ ]}; extern "C" { - fn setopt_set_func_t (i :i32 , name : *mut libc::c_char) -> i32; - fn setopt_get_func_t (name : *mut libc::c_char)-> i32; + fn setopt_set_func_t (i :i32 , name : *mut i8) -> i32; + fn setopt_get_func_t (name : *mut i8)-> i32; fn xmalloc(_: u64) -> *mut libc::c_void; - fn unbind_variable_noref(_: *const libc::c_char) -> i32; - fn unbind_nameref(_: *const libc::c_char) -> i32; - fn unbind_func(_: *const libc::c_char) -> i32; - fn strvec_create(_: i32) -> *mut *mut libc::c_char; + fn unbind_variable_noref(_: *const i8) -> i32; + fn unbind_nameref(_: *const i8) -> i32; + fn unbind_func(_: *const i8) -> i32; + fn strvec_create(_: i32) -> *mut *mut i8; fn all_shell_variables() -> *mut *mut SHELL_VAR; fn print_var_list(_: *mut *mut SHELL_VAR); fn print_func_list(_: *mut *mut SHELL_VAR); fn change_flag(_: i32, _: i32) -> i32; - fn strlen(_: *const libc::c_char) -> u64; + fn strlen(_: *const i8) -> u64; fn builtin_usage(); - fn find_function (name:* const libc::c_char)->* mut SHELL_VAR; + fn find_function (name:* const i8)->* mut SHELL_VAR; fn bind_variable( - _: *const libc::c_char, - _: *mut libc::c_char, + _: *const i8, + _: *mut i8, _: i32, ) -> *mut SHELL_VAR; - fn find_variable(_: *const libc::c_char) -> *mut SHELL_VAR; - fn rl_variable_bind (_: *const libc::c_char, _: *const libc::c_char) -> i32; + fn find_variable(_: *const i8) -> *mut SHELL_VAR; + fn rl_variable_bind (_: *const i8, _: *const i8) -> i32; fn find_variable_last_nameref( - _: *const libc::c_char, + _: *const i8, _: i32, ) -> *mut SHELL_VAR; fn extract_colon_unit( - _: *mut libc::c_char, + _: *mut i8, _: *mut i32, - ) -> *mut libc::c_char; + ) -> *mut i8; fn valid_array_reference ( - _ : *const libc::c_char , + _ : *const i8 , _ : i32 )-> i32; fn array_variable_part ( - _: *const libc::c_char, + _: *const i8, _: i32, - _:*mut *mut libc::c_char, + _:*mut *mut i8, _:*mut i32 ) -> *mut SHELL_VAR; fn all_shell_functions () -> *mut *mut SHELL_VAR; fn num_posix_options() -> i32; fn find_flag(_: i32) -> *mut i32; - fn internal_getopt (list:*mut WordList , opts:*mut libc::c_char)->i32; - fn get_posix_options(_: *mut libc::c_char) -> *mut libc::c_char; + fn internal_getopt (list:*mut WordList , opts:*mut i8)->i32; + fn get_posix_options(_: *mut i8) -> *mut i8; fn sh_chkwrite (_:i32)->i32; fn reset_internal_getopt(); - fn sh_invalidopt (value:* mut libc::c_char); - fn sv_ignoreeof (_ : *mut libc::c_char); - fn sv_strict_posix (_: *mut libc::c_char); + fn sh_invalidopt (value:* mut i8); + fn sv_ignoreeof (_ : *mut i8); + fn sv_strict_posix (_: *mut i8); fn with_input_from_stdin(); - fn sh_invalidoptname (value:* mut libc::c_char); + fn sh_invalidoptname (value:* mut i8); fn bash_history_enable(); fn load_history(); fn bash_history_disable(); fn remember_args (list:* mut WordList, argc:i32); - fn sh_invalidid (value:* mut libc::c_char); - fn legal_identifier (_:*const libc::c_char) -> i32; - fn unbind_array_element(_: *mut SHELL_VAR, _:*mut libc::c_char,_: i32) -> i32; - fn unbind_variable (_: *const libc::c_char) -> i32; - fn with_input_from_stream (_:libc::FILE , _: *const libc::c_char); - fn stupidly_hack_special_variables (_ : *mut libc::c_char); - fn builtin_error(_: *const libc::c_char, _: ...); - fn builtin_help(); + fn sh_invalidid (value:* mut i8); + fn legal_identifier (_:*const i8) -> i32; + fn unbind_array_element(_: *mut SHELL_VAR, _:*mut i8,_: i32) -> i32; + fn unbind_variable (_: *const i8) -> i32; + fn with_input_from_stream (_:libc::FILE , _: *const i8); + fn stupidly_hack_special_variables (_ : *mut i8); + fn builtin_error(_: *const i8, _: ...); static mut posixly_correct : i32; static mut enable_history_list : i32; static mut ignoreeof : i32 ; @@ -861,7 +860,7 @@ extern "C" { static mut pipefail_opt : i32; static mut mark_modified_vars: i32; static mut remember_on_history: i32; - static mut optflags: [libc::c_char; 0]; + static mut optflags: [i8; 0]; static mut list_opttype:i32; static mut no_line_editing :i32; static mut interactive : i32; @@ -876,11 +875,11 @@ extern "C" { type setopt_set_func_t = unsafe extern "C" fn ( i :i32 , - name : *mut libc::c_char + name : *mut i8 ) -> i32; type setopt_get_func_t = unsafe extern "C" fn ( - name : *mut libc::c_char + name : *mut i8 ) -> i32; type sh_var_value_func_t = unsafe extern "C" fn ( @@ -889,25 +888,25 @@ type sh_var_value_func_t = unsafe extern "C" fn ( type sh_var_assign_func_t = unsafe extern "C" fn ( _ : *mut SHELL_VAR , - _ : *mut libc::c_char, + _ : *mut i8, _ : arrayind_t, - _ : *mut libc::c_char + _ : *mut i8 ) -> *mut SHELL_VAR; //type check = String::from_utf8(cc::Build::new().file("../builtins/set.def").expand()).unwrap(); -static mut on: *const libc::c_char = b"on\0" as *const u8 as *const libc::c_char; -static mut off: *const libc::c_char = b"off\0" as *const u8 as *const libc::c_char; +static mut on: *const i8 = b"on\0" as *const u8 as *const i8; +static mut off: *const i8 = b"off\0" as *const u8 as *const i8; static mut previous_option_value: i32 = 0; pub type SHELL_VAR = variable; pub type arrayind_t = i64; -unsafe fn STREQ( a:* const libc::c_char, b:* const libc::c_char)->bool { +unsafe fn STREQ( a:* const i8, b:* const i8)->bool { //println!("hahhahahhahahah"); //println!("a is {:?}, b is {:?}",CStr::from_ptr(a),CStr::from_ptr(b)); return (*a ==*b) && (libc::strcmp(a, b) == 0); } -unsafe fn find_minus_o_option (mut name : *mut libc::c_char) -> i32 { +unsafe fn find_minus_o_option (mut name : *mut i8) -> i32 { //println! ("enter find_minus_o_option"); let mut i : i32 = 0; for j in 0..N_O_OPTIONS!()-1 { @@ -923,7 +922,7 @@ unsafe fn find_minus_o_option (mut name : *mut libc::c_char) -> i32 { -1 } -unsafe fn minus_o_option_value (name : *mut libc::c_char) -> i32{ +unsafe fn minus_o_option_value (name : *mut i8) -> i32{ let mut i : i32 = 0; let mut on_or_off : *mut i32 = 0 as *mut i32; @@ -943,7 +942,7 @@ unsafe fn minus_o_option_value (name : *mut libc::c_char) -> i32{ } } -unsafe fn print_minus_o_option (name : *mut libc::c_char, value : i32, pflag : i32){ +unsafe fn print_minus_o_option (name : *mut i8, value : i32, pflag : i32){ if pflag == 0 { if value > 0 { println!("{:?} {:?}", CStr::from_ptr(name), CStr::from_ptr(on)); @@ -999,9 +998,9 @@ unsafe fn list_minus_o_opts (mode : i32 , reusable :i32){ } } -unsafe fn get_minus_o_opts () -> *mut *mut libc::c_char{ +unsafe fn get_minus_o_opts () -> *mut *mut i8{ - let mut ret = 0 as *mut *mut libc::c_char; + let mut ret = 0 as *mut *mut i8; let mut i : i32 = 0; ret = strvec_create(N_O_OPTIONS!() as i32 + 1); for j in 0..N_O_OPTIONS!(){ @@ -1019,26 +1018,26 @@ unsafe fn get_minus_o_opts () -> *mut *mut libc::c_char{ ret } -unsafe fn get_current_options () -> *mut libc::c_char{ +unsafe fn get_current_options () -> *mut i8{ - let mut temp : *mut libc::c_char = 0 as *mut libc::c_char; + let mut temp : *mut i8 = 0 as *mut i8; let mut i : i32 =0 ; let mut posixopts: i32 = 0; posixopts = unsafe {num_posix_options ()}; /* shopts modified by posix mode */ /* Make the buffer big enough to hold the set -o options and the shopt options modified by posix mode. */ - temp = unsafe {xmalloc((1 + N_O_OPTIONS!() as i32 + posixopts) as u64) as *mut libc::c_char}; + temp = unsafe {xmalloc((1 + N_O_OPTIONS!() as i32 + posixopts) as u64) as *mut i8}; for t in 0..N_O_OPTIONS!() { i = t as i32; if o_options[t as usize].letter != 0 { unsafe { *(temp.offset(t as isize)) = - *(find_flag (o_options[t as usize].letter)) as libc::c_char + *(find_flag (o_options[t as usize].letter)) as i8 }; } else { unsafe { - *(temp.offset(t as isize)) = GET_BINARY_O_OPTION_VALUE!(t,o_options[i as usize].name) as libc::c_char; + *(temp.offset(t as isize)) = GET_BINARY_O_OPTION_VALUE!(t,o_options[i as usize].name) as i8; } } } @@ -1046,12 +1045,12 @@ unsafe fn get_current_options () -> *mut libc::c_char{ bitmap. They will be handled in set_current_options() */ unsafe { get_posix_options (temp.offset(i as isize)); - *(temp.offset((i+posixopts) as isize) )= b'\0' as libc::c_char; + *(temp.offset((i+posixopts) as isize) )= b'\0' as i8; } return (temp); } -unsafe fn set_current_options (bitmap : *const libc::c_char) { +unsafe fn set_current_options (bitmap : *const i8) { let mut i : i32 ; let mut v : i32 ; @@ -1099,22 +1098,22 @@ unsafe fn set_current_options (bitmap : *const libc::c_char) { } } -unsafe extern "C" fn set_ignoreeof (on_or_off : i32 , option_name : *mut libc::c_char) -> i32 { +unsafe extern "C" fn set_ignoreeof (on_or_off : i32 , option_name : *mut i8) -> i32 { on_or_off == FLAG_ON!(); ignoreeof = on_or_off; - unbind_variable_noref (b"ignoreeof\0" as *const u8 as *const libc::c_char); + unbind_variable_noref (b"ignoreeof\0" as *const u8 as *const i8); if ignoreeof != 0 { - bind_variable (b"IGNOREEOF\0" as *const u8 as *const libc::c_char, - b"10\0" as *const u8 as *mut libc::c_char, 0); + bind_variable (b"IGNOREEOF\0" as *const u8 as *const i8, + b"10\0" as *const u8 as *mut i8, 0); } else { - unbind_variable_noref (b"IGNOREEOF\0" as *const u8 as *const libc::c_char); + unbind_variable_noref (b"IGNOREEOF\0" as *const u8 as *const i8); } - sv_ignoreeof (b"IGNOREEOF\0" as *const u8 as *const libc::c_char as *mut libc::c_char); + sv_ignoreeof (b"IGNOREEOF\0" as *const u8 as *const i8 as *mut i8); return 0; } -unsafe extern "C" fn set_posix_mode (on_or_off : i32 , option_name : *mut libc::c_char) -> i32 { +unsafe extern "C" fn set_posix_mode (on_or_off : i32 , option_name : *mut i8) -> i32 { if (on_or_off == FLAG_ON!() && posixly_correct != 0 ) || (on_or_off == FLAG_OFF!() && posixly_correct == 0){ return 0; @@ -1123,24 +1122,24 @@ unsafe extern "C" fn set_posix_mode (on_or_off : i32 , option_name : *mut libc:: posixly_correct = on_or_off ; if posixly_correct != 0 { - unbind_variable_noref(b"POSIXLY_CORRECT\0" as *const u8 as *const libc::c_char); + unbind_variable_noref(b"POSIXLY_CORRECT\0" as *const u8 as *const i8); } else { - bind_variable (b"POSIXLY_CORRECT\0" as *const u8 as *const libc::c_char, - b"y\0" as *const u8 as *mut libc::c_char, 0); + bind_variable (b"POSIXLY_CORRECT\0" as *const u8 as *const i8, + b"y\0" as *const u8 as *mut i8, 0); } - sv_strict_posix (b"POSIXLY_CORRECT\0" as *const u8 as *mut libc::c_char); + sv_strict_posix (b"POSIXLY_CORRECT\0" as *const u8 as *mut i8); return 0; } -unsafe extern "C" fn set_edit_mode (on_or_off : i32 , option_name : *mut libc::c_char) -> i32{ +unsafe extern "C" fn set_edit_mode (on_or_off : i32 , option_name : *mut i8) -> i32{ //println!("set edit mode by huanhuan"); let mut isemacs : i32; if on_or_off == FLAG_ON!() { - rl_variable_bind (b"editing-mode\0" as *const u8 as *const libc::c_char, + rl_variable_bind (b"editing-mode\0" as *const u8 as *const i8, option_name); if interactive > 0 { with_input_from_stdin () @@ -1156,10 +1155,10 @@ unsafe extern "C" fn set_edit_mode (on_or_off : i32 , option_name : *mut libc::c else { isemacs = 0; } - if isemacs != 0 && *option_name == b'e' as libc::c_char - || (isemacs == 0 && *option_name == b'v' as libc::c_char) { + if isemacs != 0 && *option_name == b'e' as i8 + || (isemacs == 0 && *option_name == b'v' as i8) { if interactive > 0 { - with_input_from_stream (stdin, b"stdin\0" as *const u8 as *const libc::c_char); + with_input_from_stream (stdin, b"stdin\0" as *const u8 as *const i8); } } @@ -1168,9 +1167,9 @@ unsafe extern "C" fn set_edit_mode (on_or_off : i32 , option_name : *mut libc::c {no_line_editing}; } -unsafe extern "C" fn get_edit_mode (name : *mut libc::c_char) -> i32 { +unsafe extern "C" fn get_edit_mode (name : *mut i8) -> i32 { - if *name == b'e' as libc::c_char { + if *name == b'e' as i8 { if no_line_editing== 0 && rl_editing_mode == 1 { return 1; } @@ -1188,7 +1187,7 @@ unsafe extern "C" fn get_edit_mode (name : *mut libc::c_char) -> i32 { } } -unsafe extern "C" fn bash_set_history (on_or_off : i32 , option_name : *mut libc::c_char) -> i32 { +unsafe extern "C" fn bash_set_history (on_or_off : i32 , option_name : *mut i8) -> i32 { if on_or_off == FLAG_ON!() { enable_history_list = 1; @@ -1206,7 +1205,7 @@ unsafe extern "C" fn bash_set_history (on_or_off : i32 , option_name : *mut lib return 1 - enable_history_list; } -unsafe fn set_minus_o_option (on_or_off : i32, option_name : *mut libc::c_char) -> i32 { +unsafe fn set_minus_o_option (on_or_off : i32, option_name : *mut i8) -> i32 { //println!("enter set_minus_o_option"); let mut i : i32 ; @@ -1257,8 +1256,8 @@ unsafe fn print_all_shell_variables (){ pub unsafe fn r_set_shellopts () { //println!("set shellopts by huanhuan"); - let mut value : *mut libc::c_char; - let mut tflag : [libc::c_char;N_O_OPTIONS!()] = [0 as libc::c_char ;N_O_OPTIONS!()]; + let mut value : *mut i8; + let mut tflag : [i8;N_O_OPTIONS!()] = [0 as i8 ;N_O_OPTIONS!()]; let mut vsize : i32 = 0; let mut i: i32 = 0; let mut vptr : i32 ; @@ -1283,18 +1282,18 @@ pub unsafe fn r_set_shellopts () { } } } - value = unsafe {xmalloc((vsize + 1) as u32 as u64) as *mut libc::c_char}; + value = unsafe {xmalloc((vsize + 1) as u32 as u64) as *mut i8}; vptr = 0; for j in 0..N_O_OPTIONS!(){ i = j as i32; if o_options[i as usize].name != std::ptr::null_mut(){ - if tflag[i as usize] != 0 as libc::c_char { + if tflag[i as usize] != 0 as i8 { unsafe { libc::strcpy (value.offset(vptr as isize), o_options[i as usize].name); vptr = vptr + strlen (o_options[i as usize].name) as u64 as i64 as i32; } - *value.offset(vptr as isize) = b':' as libc::c_char; + *value.offset(vptr as isize) = b':' as i8; vptr = vptr+1; } } @@ -1303,9 +1302,9 @@ pub unsafe fn r_set_shellopts () { if vptr > 0 { vptr = vptr-1; } - *value.offset(vptr as isize) = b'\0' as libc::c_char; + *value.offset(vptr as isize) = b'\0' as i8; - v = find_variable (b"SHELLOPTS\0" as *const u8 as *mut libc::c_char); + v = find_variable (b"SHELLOPTS\0" as *const u8 as *mut i8); /* Turn off the read-only attribute so we can bind the new value, and note whether or not the variable was exported. */ @@ -1316,7 +1315,7 @@ pub unsafe fn r_set_shellopts () { else { exported = 0; } - v = bind_variable (b"SHELLOPTS\0" as *const u8 as *mut libc::c_char, value, 0); + v = bind_variable (b"SHELLOPTS\0" as *const u8 as *mut i8, value, 0); /* Turn the read-only attribute back on, and turn off the export attribute if it was set implicitly by mark_modified_vars and SHELLOPTS was not exported before we bound the new value. */ @@ -1331,8 +1330,8 @@ pub unsafe fn r_set_shellopts () { } -unsafe fn parse_shellopts (value : *mut libc::c_char) { - let mut vname : *mut libc::c_char; +unsafe fn parse_shellopts (value : *mut i8) { + let mut vname : *mut i8; let mut vptr : i32 = 0; loop { vname = extract_colon_unit(value, &mut vptr); @@ -1345,11 +1344,11 @@ unsafe fn parse_shellopts (value : *mut libc::c_char) { } unsafe fn initialize_shell_options (no_shellopts : i32) { - let mut temp: *mut libc::c_char; + let mut temp: *mut i8; let mut var : *mut SHELL_VAR = 0 as *mut SHELL_VAR; if no_shellopts == 0 { - var = find_variable (b"SHELLOPTS\0" as *const u8 as *const libc::c_char); + var = find_variable (b"SHELLOPTS\0" as *const u8 as *const i8); /* set up any shell options we may have inherited. */ if !var.is_null() && imported_p!(var) != 0 { if assoc_p! (var) != 0 || array_p !(var) != 0{ @@ -1388,8 +1387,8 @@ unsafe fn reset_shell_options () { let mut opts_changed : i32; let mut rv : i32; let mut r : i32 ; - let mut arg : *mut libc::c_char = 0 as *mut libc::c_char; - let mut s: [libc::c_char;3] = [0 as libc::c_char;3]; + let mut arg : *mut i8 = 0 as *mut i8; + let mut s: [i8;3] = [0 as i8;3]; let mut opt : i32; let mut flag : bool = false; if list.is_null() { @@ -1413,12 +1412,12 @@ unsafe fn reset_shell_options () { match optChar { 'i' => { s[0] = unsafe { - list_opttype as libc::c_char + list_opttype as i8 }; - s[1] = b'i' as u8 as libc::c_char; - s[2] = b'\0' as u8 as libc::c_char; + s[1] = b'i' as u8 as i8; + s[2] = b'\0' as u8 as i8; unsafe { - sh_invalidopt (s.as_ptr() as *mut libc::c_char); + sh_invalidopt (s.as_ptr() as *mut i8); builtin_usage(); } return EX_USAGE;} @@ -1426,7 +1425,7 @@ unsafe fn reset_shell_options () { unsafe { builtin_usage (); } - if unsafe {list_optopt} == b'?' as libc::c_char as i32 { + if unsafe {list_optopt} == b'?' as i8 as i32 { return EXECUTION_SUCCESS!(); } else { @@ -1435,18 +1434,14 @@ unsafe fn reset_shell_options () { } _ => { if opt == -99 { - unsafe { - builtin_help(); - } - return EX_USAGE; - } - unsafe { + unsafe { builtin_usage (); - } return EX_USAGE; + } } } - // opt = unsafe {internal_getopt(list, optflags.as_ptr() as *mut libc::c_char)}; + } + // opt = unsafe {internal_getopt(list, optflags.as_ptr() as *mut i8)}; opt = unsafe {internal_getopt (list, optflags.as_mut_ptr())}; } opts_changed = 0; @@ -1457,16 +1452,16 @@ unsafe fn reset_shell_options () { arg = unsafe {(*(*list).word).word}; //if (arg[0] == '-' && (!arg[1] || (arg[1] == '-' && !arg[2]))) if unsafe { - (*arg == b'-' as u8 as libc::c_char) + (*arg == b'-' as u8 as i8) && ( arg.offset(1 as isize) == std::ptr::null_mut() - || (*(arg.offset(1 as isize)) == b'-' as u8 as libc::c_char + || (*(arg.offset(1 as isize)) == b'-' as u8 as i8 && arg.offset(2 as isize) != std::ptr::null_mut())) } { //println!("*arg == b'-' && arg[1] && arg[1]== b'-'"); unsafe { list = (*list).next; /* `set --' unsets the positional parameters. */ - if *arg.offset(1 as isize) == b'-' as u8 as libc::c_char { + if *arg.offset(1 as isize) == b'-' as u8 as i8 { //println!("arg[1]== b'-'"); force_assignment = 1; } @@ -1506,7 +1501,7 @@ unsafe fn reset_shell_options () { else if optChar == 'o' { /* -+o option-name */ //println!("optChar == 'o'"); - let mut option_name : *mut libc::c_char = 0 as *mut libc::c_char ; + let mut option_name : *mut i8 = 0 as *mut i8 ; let mut opt : *mut WordList = 0 as *mut WordList; unsafe {opt = (*list).next;} if opt == std::ptr::null_mut(){ @@ -1539,9 +1534,9 @@ unsafe fn reset_shell_options () { if (option_name == std::ptr::null_mut() || unsafe { - *option_name == '\u{0}' as libc::c_char - ||*option_name == '-' as libc::c_char - || *option_name == '+' as libc::c_char + *option_name == '\u{0}' as i8 + ||*option_name == '-' as i8 + || *option_name == '+' as i8 }){ //on_or_off == '+' as i32; unsafe { @@ -1577,11 +1572,11 @@ unsafe fn reset_shell_options () { } else if unsafe{change_flag (flag_name, on_or_off) == FLAG_ERROR!()}{ //println!("change_flag ...."); - s[0] = on_or_off as libc::c_char; - s[1] = flag_name as libc::c_char ; - s[2] = '\0' as i32 as libc::c_char ; + s[0] = on_or_off as i8; + s[1] = flag_name as i8 ; + s[2] = '\0' as i32 as i8 ; unsafe { - sh_invalidopt (s.as_ptr() as *mut libc::c_char); + sh_invalidopt (s.as_ptr() as *mut i8); builtin_usage (); r_set_shellopts (); } @@ -1634,14 +1629,14 @@ pub extern "C" fn r_unset_builtin(mut list: *mut WordList) -> i32 { let mut global_unset_var: i32 = 0; let mut vflags: i32 = 0; let mut valid_id: i32 = 0; - let mut name: *mut libc::c_char = 0 as *mut libc::c_char; - let mut tname: *mut libc::c_char = 0 as *mut libc::c_char; + let mut name: *mut i8 = 0 as *mut i8; + let mut tname: *mut i8 = 0 as *mut i8; println!("enter r_unset by huanhuan"); let mut c_str_fnv = CString::new("fnv").unwrap(); unsafe { reset_internal_getopt(); - opt= internal_getopt (list, c_str_fnv.as_ptr() as * mut libc::c_char); + opt= internal_getopt (list, c_str_fnv.as_ptr() as * mut i8); while opt != -1 { let optu8:u8= opt as u8; @@ -1651,15 +1646,11 @@ pub extern "C" fn r_unset_builtin(mut list: *mut WordList) -> i32 { 'v'=>{global_unset_var = 0;} 'n'=>{nameref = 1;} _=>{ - if opt == -99 { - builtin_help(); - return EX_USAGE; - } builtin_usage (); return EX_USAGE; } } - opt =internal_getopt (list, c_str_fnv.as_ptr() as * mut libc::c_char); + opt =internal_getopt (list, c_str_fnv.as_ptr() as * mut i8); } //println!("unset func={}, unset val=%{}", global_unset_func, global_unset_var); @@ -1667,7 +1658,7 @@ pub extern "C" fn r_unset_builtin(mut list: *mut WordList) -> i32 { if global_unset_func != 0 && global_unset_var != 0 { builtin_error (b"cannot simultaneously unset a function and a variable \0" as *const u8 - as *const libc::c_char); + as *const i8); return EXECUTION_FAILURE!(); } else if unset_function != 0 && nameref != 0 { @@ -1684,7 +1675,7 @@ pub extern "C" fn r_unset_builtin(mut list: *mut WordList) -> i32 { let mut var : *mut SHELL_VAR; let mut tem : i32 = 0; - let mut t : *mut libc::c_char = 0 as *mut libc::c_char; + let mut t : *mut i8 = 0 as *mut i8; name = (*(*list).word).word; unset_function = global_unset_func; @@ -1693,7 +1684,7 @@ pub extern "C" fn r_unset_builtin(mut list: *mut WordList) -> i32 { if !unset_function == 0 && nameref == 0 && valid_array_reference (name, vflags) != 0 { t = libc::strchr (name, '[' as i32); - *t.offset(1 as isize) = b'\0' as i32 as libc::c_char; + *t.offset(1 as isize) = b'\0' as i32 as i8; unset_array = unset_array + 1; } @@ -1726,7 +1717,7 @@ pub extern "C" fn r_unset_builtin(mut list: *mut WordList) -> i32 { if var != std::ptr::null_mut() && unset_function == 0 && non_unsettable_p!(var) != 0 { builtin_error (b"%s: cannot unset \0" as *const u8 - as *const libc::c_char, name); + as *const i8, name); any_failed = any_failed + 1; list = (*list).next; } @@ -1744,12 +1735,12 @@ pub extern "C" fn r_unset_builtin(mut list: *mut WordList) -> i32 { if var!= std::ptr::null_mut() && readonly_p! (var)!= 0 { if unset_function != 0 { - builtin_error (b"%s: cannot unset: readonly %s \0 " as *const u8 as *mut libc::c_char, - (*var).name, b"function\0" as *const u8 as *mut libc::c_char); + builtin_error (b"%s: cannot unset: readonly %s \0 " as *const u8 as *mut i8, + (*var).name, b"function\0" as *const u8 as *mut i8); } else { - builtin_error (b"%s: cannot unset: readonly %s \0" as *const u8 as *mut libc::c_char, - (*var).name, b"variable\0" as *const u8 as *mut libc::c_char); + builtin_error (b"%s: cannot unset: readonly %s \0" as *const u8 as *mut i8, + (*var).name, b"variable\0" as *const u8 as *mut i8); } any_failed = any_failed + 1; list = (*list).next; @@ -1760,7 +1751,7 @@ pub extern "C" fn r_unset_builtin(mut list: *mut WordList) -> i32 { tem = unbind_array_element (var, t, vflags); /* XXX new third arg */ if tem == -2 && array_p!(var) == 0 && assoc_p! (var) == 0 { builtin_error (b"%s: not an array variable\0" as *const u8 - as *const libc::c_char, (*var).name); + as *const i8, (*var).name); any_failed = any_failed + 1; list = (*list).next; } diff --git a/bash-5.1/builtins_rust/setattr/src/intercdep.rs b/bash-5.1/builtins_rust/setattr/src/intercdep.rs index a6bf5817a4b7835cb12e85c25484f9f11429201e..8c4655937ba5aea202fd59998c0c25838c719c1a 100644 --- a/bash-5.1/builtins_rust/setattr/src/intercdep.rs +++ b/bash-5.1/builtins_rust/setattr/src/intercdep.rs @@ -345,7 +345,6 @@ extern "C" { pub fn reset_internal_getopt(); pub fn internal_getopt(list: *mut WordList, opts: *mut c_char) -> c_int; pub fn builtin_usage(); - fn builtin_help(); pub fn builtin_error(arg1: *const c_char, ...); pub fn find_function(name: *const c_char) -> *mut SHELL_VAR; pub fn exportable_function_name(string: *const c_char) -> c_int; diff --git a/bash-5.1/builtins_rust/setattr/src/lib.rs b/bash-5.1/builtins_rust/setattr/src/lib.rs index 3fa36f7366ffec942e4f115ff276ab5ec8a79176..3237cbeb07092e4f8d3607b34a6591c1b09a4e90 100644 --- a/bash-5.1/builtins_rust/setattr/src/lib.rs +++ b/bash-5.1/builtins_rust/setattr/src/lib.rs @@ -1,5 +1,3 @@ -use std::mem::size_of_val; - use libc::{c_int, c_uint, c_char, c_long, PT_NULL, c_void}; include!(concat!("intercdep.rs")); @@ -43,10 +41,6 @@ unsafe { 'a' => arrays_only = 1, 'A' => assoc_only = 1, _ => { - if opt == -99 { - builtin_help(); - return EX_USAGE; - } builtin_usage (); return EX_USAGE; } @@ -191,8 +185,7 @@ unsafe { if !variable_list.is_null() { let mut i = 0; loop { - var = *((variable_list as usize + (8*i))as *mut *mut SHELL_VAR) as *mut SHELL_VAR; - + var = (variable_list as usize + 8 * i) as *mut SHELL_VAR; if var.is_null() { break; } @@ -200,12 +193,10 @@ unsafe { if arrays_only != 0 && ((*var).attributes & att_array) != 0 { continue; } else if assoc_only != 0 && ((*var).attributes & assoc_only) != 0 { - i += 1; continue; } if ((*var).attributes & (att_invisible | att_exported)) == (att_invisible | att_exported) { - i += 1; continue; } diff --git a/bash-5.1/builtins_rust/shift/src/lib.rs b/bash-5.1/builtins_rust/shift/src/lib.rs index ae2d00a0963ce1343b590cad8daf96972709ab9f..746196e15cb6feae566ebada7d11f4d4c4e0d021 100644 --- a/bash-5.1/builtins_rust/shift/src/lib.rs +++ b/bash-5.1/builtins_rust/shift/src/lib.rs @@ -33,9 +33,9 @@ unsafe { if times > nargs { if print_shift_error != 0 { let s = if list.is_null() {PT_NULL as *mut c_char} else {(*(*list).word).word}; - r_sh_erange(s,"shift count\0".as_ptr() as *mut c_char); + r_sh_erange(s,"shift count\0".as_ptr() as *mut c_char); + return EXECUTION_FAILURE; } - return EXECUTION_FAILURE; } else if times == nargs { clear_dollar_vars(); } else { diff --git a/bash-5.1/builtins_rust/shopt/src/lib.rs b/bash-5.1/builtins_rust/shopt/src/lib.rs index 2f4ed512036dfc83e2dd57a9c22ddb4a36e25334..c557ab770e664b3cc19575d38c2ecfc052ed6002 100644 --- a/bash-5.1/builtins_rust/shopt/src/lib.rs +++ b/bash-5.1/builtins_rust/shopt/src/lib.rs @@ -926,7 +926,7 @@ pub unsafe extern "C" fn r_shopt_builtin(mut list: *mut WordList) -> i32 { reset_internal_getopt(); let psuoq = CString::new("psuoq").expect("CString::new failed"); loop { - opt = internal_getopt( list, psuoq.as_ptr() as *mut libc::c_char); + opt = internal_getopt( list, psuoq.as_ptr() as *mut c_char); if !(opt != -(1 as i32)) { break; } diff --git a/bash-5.1/builtins_rust/source/src/lib.rs b/bash-5.1/builtins_rust/source/src/lib.rs index 7ce136b069fd18065de359f21bd65938e39b20aa..a33457a46170f4c26f503b8e1cc0c348c6fab99e 100644 --- a/bash-5.1/builtins_rust/source/src/lib.rs +++ b/bash-5.1/builtins_rust/source/src/lib.rs @@ -294,7 +294,6 @@ unsafe fn DEBUG_TRAP()->i32 #[no_mangle] pub extern "C" fn r_source_builtin (list:* mut WordList)->i32 { - let mut result:i32; let mut filename:*mut c_char; let mut debug_trap:* mut c_char; @@ -307,7 +306,7 @@ pub extern "C" fn r_source_builtin (list:* mut WordList)->i32 let mut llist:* mut WordList = loptend.clone(); if list == std::ptr::null_mut() { - builtin_error (b"filename argument required\0" as *const u8 as *const libc::c_char as *mut libc::c_char ); + builtin_error (CString::new("filename argument required").unwrap().as_ptr()); builtin_usage (); return EX_USAGE; } @@ -345,7 +344,7 @@ pub extern "C" fn r_source_builtin (list:* mut WordList)->i32 } } - begin_unwind_frame (b"source\0" as *const u8 as *const libc::c_char as *mut libc::c_char); + begin_unwind_frame (CString::new("source").unwrap().as_ptr() as * mut c_char); let xf:Functions=Functions{f_xfree :xfree}; add_unwind_protect (xf, filename); @@ -381,7 +380,7 @@ pub extern "C" fn r_source_builtin (list:* mut WordList)->i32 result = source_file (filename, (list !=std::ptr::null_mut() && (*list).next !=std::ptr::null_mut()) as i32); - run_unwind_frame (b"source\0" as *const u8 as *const libc::c_char as *mut libc::c_char); + run_unwind_frame (CString::new("source").unwrap().as_ptr() as * mut c_char); return result; } diff --git a/bash-5.1/builtins_rust/suspend/src/lib.rs b/bash-5.1/builtins_rust/suspend/src/lib.rs index bce087870ee66ce76d885efac6811c1d25ef35c3..3798740cfc9feacefa875018a9628bf627ca0e94 100644 --- a/bash-5.1/builtins_rust/suspend/src/lib.rs +++ b/bash-5.1/builtins_rust/suspend/src/lib.rs @@ -14,29 +14,26 @@ pub extern "C" fn r_suspend_builtin(mut list: *mut WordList) -> i32 { unsafe { reset_internal_getopt(); - let opt_str = "f\0".as_ptr() as *mut c_char; + let opt_str = "f:\0".as_ptr() as *mut c_char; opt = internal_getopt (list, opt_str); while opt != -1 { let opt_char:char=char::from(opt as u8); match opt_char { 'f' => force += 1, _ => { - if opt == -99 { - builtin_help(); - return EX_USAGE; - } r_builtin_usage (); return EX_USAGE; } } - opt = internal_getopt (list, opt_str); } list = loptend; + if job_control == 0 { sh_nojobs("cannot suspend\0".as_ptr() as *mut c_char); return EXECUTION_FAILURE; } + if force == 0 { r_no_args(list); if login_shell != 0 { @@ -46,6 +43,7 @@ unsafe { } old_cont = set_signal_handler(libc::SIGCONT, std::mem::transmute(suspend_continue as usize)); + killpg(shell_pgrp, libc::SIGSTOP); } return EXECUTION_SUCCESS; diff --git a/bash-5.1/builtins_rust/trap/src/intercdep.rs b/bash-5.1/builtins_rust/trap/src/intercdep.rs index fba354db2a4f39776fd1c7b60be33f19333262e5..93e2d8a223feb297a4e278da59047ffc6a3aaf4d 100644 --- a/bash-5.1/builtins_rust/trap/src/intercdep.rs +++ b/bash-5.1/builtins_rust/trap/src/intercdep.rs @@ -37,7 +37,6 @@ extern "C" { pub fn reset_internal_getopt(); pub fn internal_getopt(list: *mut WordList, opts: *mut c_char) -> c_int; pub fn builtin_usage(); - fn builtin_help(); pub fn builtin_error(format: *const c_char, ...); pub fn sh_chkwrite(s: c_int) -> c_int; diff --git a/bash-5.1/builtins_rust/trap/src/lib.rs b/bash-5.1/builtins_rust/trap/src/lib.rs index f5dddb3b34ec679414adb93a8647694f9349a8e6..7e1016513bdf23aa71e006978c02cbd061b5d547 100644 --- a/bash-5.1/builtins_rust/trap/src/lib.rs +++ b/bash-5.1/builtins_rust/trap/src/lib.rs @@ -24,10 +24,6 @@ unsafe { 'l' => list_signal_names += 1, 'p' => display += 1, _ => { - if opt == -99 { - builtin_help(); - return EX_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 fc4c26ddac2352826b4bf992387ba876f2db0bba..ddf85bf648d8cd2d884cf04de88e066a50714d29 100644 --- a/bash-5.1/builtins_rust/type/src/lib.rs +++ b/bash-5.1/builtins_rust/type/src/lib.rs @@ -100,7 +100,7 @@ macro_rules! MP_RMDOT{ #[macro_export] macro_rules! STREQ{ ($a:expr,$b:expr) =>{ - *$a as libc::c_char == *$b as libc::c_char && libc::strcmp($a,$b)==0 + *$a as i8 == *$b as i8 && libc::strcmp($a,$b)==0 } } @@ -114,11 +114,11 @@ macro_rules! SIZEOFWORD{ #[repr(C)] pub struct SHELL_VAR { - name:*mut libc::c_char, - value:*mut libc::c_char, - exportstr:*mut libc::c_char, + name:*mut i8, + value:*mut i8, + exportstr:*mut i8, dynamic_value:*mut fn(v:* mut SHELL_VAR)->*mut SHELL_VAR, - assign_func:* mut fn(v:* mut SHELL_VAR,str1:* mut libc::c_char,t:i64,str2:* mut libc::c_char)->*mut SHELL_VAR, + assign_func:* mut fn(v:* mut SHELL_VAR,str1:* mut i8,t:i64,str2:* mut i8)->*mut SHELL_VAR, attributes:i32, context:i32 } @@ -126,9 +126,9 @@ pub struct SHELL_VAR { #[repr (C)] #[derive(Copy,Clone)] pub struct alias { - name :*mut libc::c_char, - value :*mut libc::c_char , - flags:libc::c_char + name :*mut i8, + value :*mut i8 , + flags:i8 } type sh_builtin_func_t = fn(WordList) -> i32; @@ -192,7 +192,7 @@ pub union REDIRECT { flags: i32 , instruction:r_instruction, redirectee:REDIRECTEE, - here_doc_eof:*mut libc::c_char + here_doc_eof:*mut i8 } #[repr(C)] @@ -262,14 +262,14 @@ pub struct function_def { line: i32 , name:*mut WordDesc, command:*mut COMMAND, - source_file:*mut libc::c_char + source_file:*mut i8 } #[repr(C)] pub struct group_com { ignore: i32 , command:*mut COMMAND, - source_file:*mut libc::c_char + source_file:*mut i8 } #[repr(C)] @@ -316,7 +316,7 @@ pub struct subshell_com { #[repr(C)] pub struct coproc_com { flags:i32, - name:*mut libc::c_char, + name:*mut i8, command:*mut COMMAND } @@ -345,7 +345,7 @@ macro_rules! FS_EXEC_ONLY { macro_rules! ABSPATH { ($s :expr) => { unsafe { - char::from(*($s as *mut libc::c_char) as u8) }== '/'; + char::from(*($s as *mut i8) as u8) }== '/'; // $x == '/'; } @@ -354,27 +354,26 @@ macro_rules! ABSPATH { extern "C" { fn reset_internal_getopt(); - fn internal_getopt (list:*mut WordList , opts:*mut libc::c_char)->i32; + fn internal_getopt (list:*mut WordList , opts:*mut i8)->i32; fn builtin_usage(); - fn builtin_help(); - fn sh_notfound (name:* mut libc::c_char); + fn sh_notfound (name:* mut i8); fn sh_chkwrite (ret:i32)->i32; - fn find_alias(alia :*mut libc::c_char) ->alias_t; - fn sh_single_quote(quote: *const libc::c_char) -> *mut libc::c_char; - fn find_reserved_word(word: *mut libc::c_char)->i32; - fn find_function (name:* const libc::c_char)-> *mut SHELL_VAR; - fn named_function_string (name: *mut libc::c_char, cmd:* mut COMMAND, i:i32)->* mut libc::c_char; - fn find_shell_builtin(builtin: *mut libc::c_char) -> *mut libc::c_char; - fn find_special_builtin(builtins: *mut libc::c_char) -> *mut sh_builtin_func_t; - fn absolute_program(program:*const libc::c_char) -> i32; - fn file_status(status :*const libc::c_char) -> i32 ; - fn phash_search(search:*const libc::c_char) -> *mut libc::c_char; - fn conf_standard_path() -> *mut libc::c_char; - fn find_in_path(path1:*const libc::c_char, path2:*mut libc::c_char, num: i32) -> *mut libc::c_char; - fn find_user_command(cmd:*mut libc::c_char) -> *mut libc::c_char; - fn user_command_matches(cmd:*const libc::c_char, num1:i32, num2:i32) -> *mut libc::c_char; - fn sh_makepath(path:*const libc::c_char, path1:*const libc::c_char, i: i32) -> *mut libc::c_char; - //fn find_alias(alia : *mut libc::c_char) -> *mut alias_t; + fn find_alias(alia :*mut i8) ->alias_t; + 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 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; + fn file_status(status :*const i8) -> i32 ; + fn phash_search(search:*const i8) -> *mut i8; + fn conf_standard_path() -> *mut i8; + fn find_in_path(path1:*const i8, path2:*mut i8, num: i32) -> *mut i8; + fn find_user_command(cmd:*mut i8) -> *mut i8; + fn user_command_matches(cmd:*const i8, num1:i32, num2:i32) -> *mut i8; + fn sh_makepath(path:*const i8, path1:*const i8, i: i32) -> *mut i8; + //fn find_alias(alia : *mut i8) -> *mut alias_t; static expand_aliases : i32; static mut loptend:*mut WordList; static posixly_correct:i32; @@ -396,41 +395,38 @@ pub unsafe extern "C" fn r_type_builtin (mut list :*mut WordList) -> i32 { unsafe{ this = list; while this != std::ptr::null_mut() && char::from((*(*(*this).word).word) as u8) == '-' { - let mut flag = (((*(*this).word).word) as usize + 1) as *mut libc::c_char; + let mut flag = (((*(*this).word).word) as usize + 1) as *mut i8; let mut c_str_type = CString::new("type").unwrap(); let c_str_type1 = CString::new("-type").unwrap(); let c_str_path = CString::new("path").unwrap(); let c_str_path1 = CString::new("-path").unwrap(); let c_str_all = CString::new("all").unwrap(); let c_str_all1 = CString::new("-all").unwrap(); - if STREQ!(flag, c_str_type.as_ptr() as *mut libc::c_char ) || STREQ!(flag, c_str_type1.as_ptr() as *mut libc::c_char) { + if STREQ!(flag, c_str_type.as_ptr() as *mut i8 ) || STREQ!(flag, c_str_type1.as_ptr() as *mut i8) { unsafe { - *((((*(*this).word).word) as usize + 1) as *mut libc::c_char) = 't' as libc::c_char ; - *((((*(*this).word).word) as usize + 2) as *mut libc::c_char) = '\0' as libc::c_char ; + *((((*(*this).word).word) as usize + 1) as *mut i8) = 't' as i8 ; + *((((*(*this).word).word) as usize + 2) as *mut i8) = '\0' as i8 ; } } - else if STREQ!(flag, c_str_path.as_ptr() as *mut libc::c_char) || STREQ!(flag, c_str_path1.as_ptr() as *mut libc::c_char){ - *((((*(*this).word).word) as usize + 1) as *mut libc::c_char) = 'p' as libc::c_char ; - *((((*(*this).word).word) as usize + 2) as *mut libc::c_char) = '\0' as libc::c_char ; + else if STREQ!(flag, c_str_path.as_ptr() as *mut i8) || STREQ!(flag, c_str_path1.as_ptr() as *mut i8){ + *((((*(*this).word).word) as usize + 1) as *mut i8) = 'p' as i8 ; + *((((*(*this).word).word) as usize + 2) as *mut i8) = '\0' as i8 ; } - else if STREQ!(flag, c_str_all.as_ptr() as *mut libc::c_char) || STREQ!(flag, c_str_all1.as_ptr() as *mut libc::c_char) { - *((((*(*this).word).word) as usize + 1) as *mut libc::c_char) = 'a' as libc::c_char ; - *((((*(*this).word).word) as usize + 2) as *mut libc::c_char) = '\0' as libc::c_char ; + else if STREQ!(flag, c_str_all.as_ptr() as *mut i8) || STREQ!(flag, c_str_all1.as_ptr() as *mut i8) { + *((((*(*this).word).word) as usize + 1) as *mut i8) = 'a' as i8 ; + *((((*(*this).word).word) as usize + 2) as *mut i8) = '\0' as i8 ; } if (*this).next != std::ptr::null_mut(){ this = (*this).next; } - else { - break; - } } } reset_internal_getopt(); let c_str_afptP = CString::new("afptP").unwrap(); - let mut opt = unsafe {internal_getopt(list,c_str_afptP.as_ptr() as *mut libc::c_char) } ; + let mut opt = unsafe {internal_getopt(list,c_str_afptP.as_ptr() as *mut i8) } ; while opt != -1{ let optu8:u8= opt as u8; let optChar:char=char::from(optu8); @@ -445,17 +441,17 @@ pub unsafe extern "C" fn r_type_builtin (mut list :*mut WordList) -> i32 { dflags = dflags& !(CDESC_TYPE!()|CDESC_SHORTDESC!()); } _ =>{ - if opt == -99 { - builtin_help(); - return EX_USAGE; - } + if opt == -99 { + builtin_usage(); + return EX_USAGE; + } unsafe { builtin_usage (); return EX_USAGE; } } } - opt = internal_getopt (list, c_str_afptP.as_ptr() as * mut libc::c_char); + opt = internal_getopt (list, c_str_afptP.as_ptr() as * mut i8); } list = loptend; while list != std::ptr::null_mut() { @@ -486,15 +482,15 @@ pub unsafe extern "C" fn r_type_builtin (mut list :*mut WordList) -> i32 { } -fn describe_command (command : *mut libc::c_char, dflags : i32) -> i32 { +fn describe_command (command : *mut i8, dflags : i32) -> i32 { let mut found : i32 = 0; let mut i : i32; let mut found_file : i32 = 0; let mut f : i32; let mut all : i32; - let mut full_path : *mut libc::c_char; - let mut x : *mut libc::c_char; - let mut pathlist : *mut libc::c_char; + let mut full_path : *mut i8; + let mut x : *mut i8; + let mut pathlist : *mut i8; let mut func : *mut SHELL_VAR = 0 as *mut SHELL_VAR; // let mut alias : *mut alias_t; @@ -514,7 +510,7 @@ fn describe_command (command : *mut libc::c_char, dflags : i32) -> i32 { { if (dflags & CDESC_TYPE!()) != 0{ unsafe { - libc::puts("alias" as *const libc::c_char ); + libc::puts("alias" as *const i8 ); } } else if (dflags & CDESC_SHORTDESC!()) != 0 { @@ -570,7 +566,7 @@ fn describe_command (command : *mut libc::c_char, dflags : i32) -> i32 { } } else if dflags & CDESC_SHORTDESC!() != 0 { - let mut result : *mut libc::c_char; + let mut result : *mut i8; unsafe { println!("{:?} is a function",CStr::from_ptr(command)); result = named_function_string (command, function_cell(find_function (command)), FUNC_MULTILINE!()|FUNC_EXTERNAL!()); diff --git a/bash-5.1/builtins_rust/ulimit/src/lib.rs b/bash-5.1/builtins_rust/ulimit/src/lib.rs index 283ed16cd3dbcb9c6e1220aa0f14d336662e0913..2ed26a2227a7f2d15db6dd1db44009b07ad84bcf 100644 --- a/bash-5.1/builtins_rust/ulimit/src/lib.rs +++ b/bash-5.1/builtins_rust/ulimit/src/lib.rs @@ -22,15 +22,15 @@ pub struct RESOURCE_LIMITS{ option : i32, /* The ulimit option for this limit. */ parameter : i32, /* Parameter to pass to get_limit (). */ block_factor : i32, /* Blocking factor for specific limit. */ - description : *const libc::c_char, /* Descriptive string to output. */ - units : *const libc::c_char /* scale */ + description : *const i8, /* Descriptive string to output. */ + units : *const i8 /* scale */ } #[repr (C)] #[derive(Copy,Clone)] pub struct _cmd { cmd : i32, - arg : *mut libc::c_char + arg : *mut i8 } #[repr (C)] @@ -41,9 +41,9 @@ pub struct user_info { euid : uid_t, gid : gid_t, egid : gid_t, - user_name : *mut libc::c_char, - shell :*mut libc::c_char, - home_dir : *mut libc::c_char + user_name : *mut i8, + shell :*mut i8, + home_dir : *mut i8 } #[macro_export] @@ -233,40 +233,40 @@ const limits: [ RESOURCE_LIMITS_T;18] =[ parameter: __RLIMIT_RTTIME as i32, block_factor: 1 as i32, description: b"real-time non-blocking time\0" as *const u8 - as *const libc::c_char, - units: b"microseconds\0" as *const u8 as *const libc::c_char, + as *const i8, + units: b"microseconds\0" as *const u8 as *const i8, }}, { RESOURCE_LIMITS { option: 'c' as i32, parameter: RLIMIT_CORE as i32, block_factor: -(2 as i32), - description: b"core file size\0" as *const u8 as *const libc::c_char, - units: b"blocks\0" as *const u8 as *const libc::c_char, + description: b"core file size\0" as *const u8 as *const i8, + units: b"blocks\0" as *const u8 as *const i8, }}, { RESOURCE_LIMITS { option: 'd' as i32, parameter: RLIMIT_DATA as i32, block_factor: 1024 as i32, - description: b"data seg size\0" as *const u8 as *const libc::c_char, - units: b"kbytes\0" as *const u8 as *const libc::c_char, + description: b"data seg size\0" as *const u8 as *const i8, + units: b"kbytes\0" as *const u8 as *const i8, }}, { RESOURCE_LIMITS { option: 'e' as i32, parameter: __RLIMIT_NICE as i32, block_factor: 1 as i32, - description: b"scheduling priority\0" as *const u8 as *const libc::c_char, - units: 0 as *const libc::c_void as *mut libc::c_void as *mut libc::c_char, + description: b"scheduling priority\0" as *const u8 as *const i8, + units: 0 as *const libc::c_void as *mut libc::c_void as *mut i8, }}, { RESOURCE_LIMITS { option: 'f' as i32, parameter: RLIMIT_FSIZE as i32, block_factor: -(2 as i32), - description: b"file size\0" as *const u8 as *const libc::c_char, - units: b"blocks\0" as *const u8 as *const libc::c_char, + description: b"file size\0" as *const u8 as *const i8, + units: b"blocks\0" as *const u8 as *const i8, }}, { @@ -274,8 +274,8 @@ const limits: [ RESOURCE_LIMITS_T;18] =[ option: 'i' as i32, parameter: __RLIMIT_SIGPENDING as i32, block_factor: 1 as i32, - description: b"pending signals\0" as *const u8 as *const libc::c_char, - units: 0 as *const libc::c_void as *mut libc::c_void as *mut libc::c_char, + description: b"pending signals\0" as *const u8 as *const i8, + units: 0 as *const libc::c_void as *mut libc::c_void as *mut i8, } }, @@ -283,88 +283,88 @@ const limits: [ RESOURCE_LIMITS_T;18] =[ option: 'l' as i32, parameter: __RLIMIT_MEMLOCK as i32, block_factor: 1024 as i32, - description: b"max locked memory\0" as *const u8 as *const libc::c_char, - units: b"kbytes\0" as *const u8 as *const libc::c_char, + description: b"max locked memory\0" as *const u8 as *const i8, + units: b"kbytes\0" as *const u8 as *const i8, }}, { RESOURCE_LIMITS { option: 'm' as i32, parameter: __RLIMIT_RSS as i32, block_factor: 1024 as i32, - description: b"max memory size\0" as *const u8 as *const libc::c_char, - units: b"kbytes\0" as *const u8 as *const libc::c_char, + description: b"max memory size\0" as *const u8 as *const i8, + units: b"kbytes\0" as *const u8 as *const i8, }}, { RESOURCE_LIMITS { option: 'n' as i32, parameter: RLIMIT_NOFILE as i32, block_factor: 1 as i32, - description: b"open files\0" as *const u8 as *const libc::c_char, - units: 0 as *const libc::c_void as *mut libc::c_void as *mut libc::c_char, + description: b"open files\0" as *const u8 as *const i8, + units: 0 as *const libc::c_void as *mut libc::c_void as *mut i8, }}, { RESOURCE_LIMITS { option: 'p' as i32, parameter: 257 as i32, block_factor: 512 as i32, - description: b"pipe size\0" as *const u8 as *const libc::c_char, - units: b"512 bytes\0" as *const u8 as *const libc::c_char, + description: b"pipe size\0" as *const u8 as *const i8, + units: b"512 bytes\0" as *const u8 as *const i8, }}, { RESOURCE_LIMITS { option: 'q' as i32, parameter: __RLIMIT_MSGQUEUE as i32, block_factor: 1 as i32, - description: b"POSIX message queues\0" as *const u8 as *const libc::c_char, - units: b"bytes\0" as *const u8 as *const libc::c_char, + description: b"POSIX message queues\0" as *const u8 as *const i8, + units: b"bytes\0" as *const u8 as *const i8, }}, { RESOURCE_LIMITS { option: 'r' as i32, parameter: __RLIMIT_RTPRIO as i32, block_factor: 1 as i32, - description: b"real-time priority\0" as *const u8 as *const libc::c_char, - units: 0 as *const libc::c_void as *mut libc::c_void as *mut libc::c_char, + description: b"real-time priority\0" as *const u8 as *const i8, + units: 0 as *const libc::c_void as *mut libc::c_void as *mut i8, }}, { RESOURCE_LIMITS { option: 's' as i32, parameter: RLIMIT_STACK as i32, block_factor: 1024 as i32, - description: b"stack size\0" as *const u8 as *const libc::c_char, - units: b"kbytes\0" as *const u8 as *const libc::c_char, + description: b"stack size\0" as *const u8 as *const i8, + units: b"kbytes\0" as *const u8 as *const i8, }}, { RESOURCE_LIMITS { option: 't' as i32, parameter: RLIMIT_CPU as i32, block_factor: 1 as i32, - description: b"cpu time\0" as *const u8 as *const libc::c_char, - units: b"seconds\0" as *const u8 as *const libc::c_char, + description: b"cpu time\0" as *const u8 as *const i8, + units: b"seconds\0" as *const u8 as *const i8, }}, { RESOURCE_LIMITS { option: 'u' as i32, parameter: __RLIMIT_NPROC as i32, block_factor: 1 as i32, - description: b"max user processes\0" as *const u8 as *const libc::c_char, - units: 0 as *const libc::c_void as *mut libc::c_void as *mut libc::c_char, + description: b"max user processes\0" as *const u8 as *const i8, + units: 0 as *const libc::c_void as *mut libc::c_void as *mut i8, }}, { RESOURCE_LIMITS { option: 'v' as i32, parameter: RLIMIT_AS as i32, block_factor: 1024 as i32, - description: b"virtual memory\0" as *const u8 as *const libc::c_char, - units: b"kbytes\0" as *const u8 as *const libc::c_char, + description: b"virtual memory\0" as *const u8 as *const i8, + units: b"kbytes\0" as *const u8 as *const i8, }}, { RESOURCE_LIMITS { option: 'x' as i32, parameter: __RLIMIT_LOCKS as i32, block_factor: 1 as i32, - description: b"file locks\0" as *const u8 as *const libc::c_char, - units: 0 as *const libc::c_void as *mut libc::c_void as *mut libc::c_char, + description: b"file locks\0" as *const u8 as *const i8, + units: 0 as *const libc::c_void as *mut libc::c_void as *mut i8, }}, { RESOURCE_LIMITS { @@ -372,8 +372,8 @@ const limits: [ RESOURCE_LIMITS_T;18] =[ parameter: -1, block_factor:-1, description: 0 as *const libc::c_void as *mut libc::c_void - as *mut libc::c_char, - units: 0 as *const libc::c_void as *mut libc::c_void as *mut libc::c_char, + as *mut i8, + units: 0 as *const libc::c_void as *mut libc::c_void as *mut i8, }} ]; @@ -381,17 +381,17 @@ extern "C" { fn reset_internal_getopt(); fn xmalloc(_: u64) -> *mut libc::c_void; fn xrealloc(_: *mut libc::c_void, _: u64) -> *mut libc::c_void; - fn all_digits(_: *const libc::c_char) -> i32; + fn all_digits(_: *const i8) -> i32; fn sh_chkwrite(_: i32) -> i32; - fn internal_getopt(_: *mut WordList, _: *mut libc::c_char) -> i32; - fn strerror(_: i32) -> *mut libc::c_char; - fn sprintf(_: *mut libc::c_char, _: *const libc::c_char, _: ...) -> i32; - fn string_to_rlimtype(_: *mut libc::c_char ) -> rlim_t; + fn internal_getopt(_: *mut WordList, _: *mut i8) -> i32; + fn strerror(_: i32) -> *mut i8; + fn sprintf(_: *mut i8, _: *const i8, _: ...) -> i32; + fn string_to_rlimtype(_: *mut i8 ) -> rlim_t; fn getdtablesize() -> i32; fn builtin_help (); fn builtin_usage(); - fn sh_erange (s:* mut libc::c_char, desc:* mut libc::c_char); - fn sh_invalidnum(arg1: *mut libc::c_char); + fn sh_erange (s:* mut i8, desc:* mut i8); + fn sh_invalidnum(arg1: *mut i8); fn __errno_location() -> *mut i32; fn getrlimit(__resource: __rlimit_resource_t, __rlimits: *mut rlimit) -> i32; fn setrlimit( @@ -399,17 +399,17 @@ extern "C" { __rlimits: *const rlimit, ) -> i32; - fn builtin_error(_: *const libc::c_char, _: ...); + fn builtin_error(_: *const i8, _: ...); fn getmaxchild() -> i64; fn print_rlimtype(_: rlim_t, _: i32); static mut loptend: *mut WordList; - static mut list_optarg: *mut libc::c_char; + static mut list_optarg: *mut i8; static mut posixly_correct:i32 ; static mut current_user: user_info; } -static mut optstring:[ libc::c_char;4 + 2 * NCMDS!() as usize] = [0;4 + 2 * NCMDS!() as usize]; +static mut optstring:[ i8;4 + 2 * NCMDS!() as usize] = [0;4 + 2 * NCMDS!() as usize]; static mut cmdlist : *mut ULCMD = 0 as *const ULCMD as *mut ULCMD; static mut ncmd : i32 = 0; @@ -432,7 +432,7 @@ fn _findlim (opt:i32) -> i32{ pub unsafe extern "C" fn r_ulimit_builtin(mut list: *mut WordList) -> i32{ //println!("enter ulimit set by huanhuan"); - let mut s : *mut libc::c_char; + let mut s : *mut i8; let mut c : i32 ; let mut limind : i32 ; let mut mode : i32 = 0 ; @@ -441,23 +441,23 @@ pub unsafe extern "C" fn r_ulimit_builtin(mut list: *mut WordList) -> i32{ if optstring[0] == 0 { //println!(" optstring[0] == 0"); s = optstring.as_mut_ptr(); - s = (s as usize ) as *mut libc::c_char; - *s = 'a' as libc::c_char; - s = (s as usize + 1) as *mut libc::c_char; - *s = 'S' as libc::c_char; - s = (s as usize + 1) as *mut libc::c_char; - *s = 'H' as libc::c_char; + s = (s as usize ) as *mut i8; + *s = 'a' as i8; + s = (s as usize + 1) as *mut i8; + *s = 'S' as i8; + s = (s as usize + 1) as *mut i8; + *s = 'H' as i8; c = 0 ; for i in 0..17 { if limits[i].option > 0{ //println!("limits[i].option > 0 is {}",limits[i].option); - s = (s as usize + 1) as *mut libc::c_char; - *s = limits[i].option as libc::c_char; - s = (s as usize + 1) as *mut libc::c_char; - *s = ';' as libc::c_char; + s = (s as usize + 1) as *mut i8; + *s = limits[i].option as i8; + s = (s as usize + 1) as *mut i8; + *s = ';' as i8; } } - *s = '\0' as libc::c_char; + *s = '\0' as i8; } //println! ("cmdlistsz is {}",cmdlistsz); @@ -472,7 +472,7 @@ pub unsafe extern "C" fn r_ulimit_builtin(mut list: *mut WordList) -> i32{ } ncmd = 0; reset_internal_getopt (); - opt = internal_getopt(list, optstring.as_ptr() as *mut libc::c_char); + opt = internal_getopt(list, optstring.as_ptr() as *mut i8); //println! ("get opt 2 is {}",opt); while opt != -1 { //println!("opt is {}", opt); @@ -483,13 +483,17 @@ pub unsafe extern "C" fn r_ulimit_builtin(mut list: *mut WordList) -> i32{ 'S' => { mode = mode | LIMIT_SOFT!() ; } 'H' => { mode = mode | LIMIT_HARD!();} '?'=> { - builtin_usage(); + builtin_help(); return EX_USAGE; } + // => { + // builtin_usage(); + // return EX_USAGE; + // } _ => { //println!("enter switch default,opt is {}",opt); if opt == -99 { - builtin_help(); + builtin_usage(); return EX_USAGE; } if ncmd >= cmdlistsz { @@ -517,7 +521,7 @@ pub unsafe extern "C" fn r_ulimit_builtin(mut list: *mut WordList) -> i32{ } } - opt = internal_getopt (list, optstring.as_ptr() as * mut libc::c_char); + opt = internal_getopt (list, optstring.as_ptr() as * mut i8); } // println! ("now cmd1 opt is {:?}",(*((cmdlist as usize + (ncmd as usize)*std::mem::size_of::()) @@ -582,9 +586,9 @@ pub unsafe extern "C" fn r_ulimit_builtin(mut list: *mut WordList) -> i32{ //println!("now get limind is {}",limind); if limind == -1 { unsafe { - builtin_error(b"%s: bad command : %s\0" as *const u8 as *const libc::c_char, + builtin_error(b"%s: bad command : %s\0" as *const u8 as *const i8, (*cmdlist.offset(d as isize)).cmd, - strerror(*__errno_location()) as *const libc::c_char); + strerror(*__errno_location()) as *const i8); } return EX_USAGE; } @@ -607,7 +611,7 @@ pub unsafe extern "C" fn r_ulimit_builtin(mut list: *mut WordList) -> i32{ } -unsafe fn ulimit_internal (cmd : i32 , cmdarg :*mut libc::c_char,mut mode : i32, multiple : i32) -> i32 { +unsafe fn ulimit_internal (cmd : i32 , cmdarg :*mut i8,mut mode : i32, multiple : i32) -> i32 { let mut opt : i32 ; let mut limind : i32 ; @@ -642,8 +646,8 @@ unsafe fn ulimit_internal (cmd : i32 , cmdarg :*mut libc::c_char,mut mode : i32 if opt < 0 { unsafe { - builtin_error(b"%s: cannot get limit : %s\0" as *const u8 as *const libc::c_char, limits[limind as usize].description, - strerror(*__errno_location()) as *const libc::c_char); + builtin_error(b"%s: cannot get limit : %s\0" as *const u8 as *const i8, limits[limind as usize].description, + strerror(*__errno_location()) as *const i8); } return EXECUTION_FAILURE!(); @@ -664,14 +668,14 @@ unsafe fn ulimit_internal (cmd : i32 , cmdarg :*mut libc::c_char,mut mode : i32 let mut c_str_hard = CString::new("hard").unwrap(); let mut c_str_soft = CString::new("soft").unwrap(); let mut c_str_unlimited = CString::new("unlimited").unwrap(); - if unsafe{STREQ!(cmdarg,c_str_hard.as_ptr() as *mut libc::c_char )}{ + if unsafe{STREQ!(cmdarg,c_str_hard.as_ptr() as *mut i8 )}{ real_limit = hard_limit; } - else if unsafe{STREQ!(cmdarg, c_str_soft.as_ptr() as *mut libc::c_char)}{ + else if unsafe{STREQ!(cmdarg, c_str_soft.as_ptr() as *mut i8)}{ real_limit = soft_limit; } - else if unsafe{STREQ!(cmdarg, c_str_unlimited.as_ptr() as *mut libc::c_char)}{ + else if unsafe{STREQ!(cmdarg, c_str_unlimited.as_ptr() as *mut i8)}{ real_limit = RLIM_INFINITY!(); } @@ -683,7 +687,7 @@ unsafe fn ulimit_internal (cmd : i32 , cmdarg :*mut libc::c_char,mut mode : i32 if (real_limit / block_factor as i64) != limit { // println!("real_limit / block_factor as i64) != limit"); let c_str_limit =CString::new("limit").unwrap(); - unsafe {sh_erange (cmdarg,c_str_limit.as_ptr() as *mut libc::c_char)}; + unsafe {sh_erange (cmdarg,c_str_limit.as_ptr() as *mut i8)}; return EXECUTION_FAILURE!(); } //println!("real_limit / block_factor as i64) == limit"); @@ -694,8 +698,8 @@ unsafe fn ulimit_internal (cmd : i32 , cmdarg :*mut libc::c_char,mut mode : i32 return EXECUTION_FAILURE!(); } if set_limit (limind, real_limit, mode) < 0 { - builtin_error(b"%s: cannot modify limit : %s\0" as *const u8 as *const libc::c_char, limits[limind as usize].description, - strerror(*__errno_location()) as *const libc::c_char); + builtin_error(b"%s: cannot modify limit : %s\0" as *const u8 as *const i8, limits[limind as usize].description, + strerror(*__errno_location()) as *const i8); return EXECUTION_FAILURE!(); } return EXECUTION_SUCCESS!(); @@ -728,7 +732,7 @@ fn get_limit (mut ind : i32, softlim : *mut RLIMTYPE, hardlim : *mut RLIMTYPE ) } RLIMIT_VIRTMEM!() => { - return unsafe {getmaxvm(softlim, hardlim as *mut libc::c_char) }; + return unsafe {getmaxvm(softlim, hardlim as *mut i8) }; } RLIMIT_MAXUPROC!() => { if getmaxuprc ((value as usize) as *mut u64) < 0 { @@ -819,7 +823,7 @@ fn set_limit (ind : i32, newlim : RLIMTYPE, mode : i32) -> i32{ } } -unsafe fn getmaxvm(softlim : *mut RLIMTYPE , hardlim : *mut libc::c_char) -> i32 { +unsafe fn getmaxvm(softlim : *mut RLIMTYPE , hardlim : *mut i8) -> i32 { let mut datalim : rlimit = rlimit { rlim_cur: 0, rlim_max: 0 }; let mut stacklim : rlimit = rlimit { rlim_cur: 0, rlim_max: 0 }; @@ -831,7 +835,7 @@ unsafe fn getmaxvm(softlim : *mut RLIMTYPE , hardlim : *mut libc::c_char) -> i32 return -1; } *softlim = (datalim.rlim_cur as i64 / 1024 as i64) + (stacklim.rlim_cur as i64/1024 as i64); - *hardlim = ((datalim.rlim_max as i64) /1024 as i64) as libc::c_char + (stacklim.rlim_max as i64/1024 as i64) as libc::c_char; + *hardlim = ((datalim.rlim_max as i64) /1024 as i64) as i8 + (stacklim.rlim_max as i64/1024 as i64) as i8; return 0; } @@ -888,8 +892,8 @@ fn print_all_limits (mut mode : i32) { else if unsafe { *__errno_location() != libc::EINVAL } { unsafe { - builtin_error(b"%s: cannot get limit : %s\0" as *const u8 as *const libc::c_char, limits[i as usize].description, - strerror(*__errno_location()) as *const libc::c_char); + builtin_error(b"%s: cannot get limit : %s\0" as *const u8 as *const i8, limits[i as usize].description, + strerror(*__errno_location()) as *const i8); } } i = i+1; @@ -899,7 +903,7 @@ fn print_all_limits (mut mode : i32) { fn printone (limind : i32, curlim :RLIMTYPE , pdesc : i32){ // println!("enter printone"); //println!("now get curlim is {}",curlim); - let mut unitstr :[ libc::c_char; 64] = [0 ; 64]; + let mut unitstr :[ i8; 64] = [0 ; 64]; let mut factor : i32 ; // println!("limind1 is {} ",limind); @@ -908,7 +912,7 @@ fn printone (limind : i32, curlim :RLIMTYPE , pdesc : i32){ if !limits[limind as usize].units.is_null(){ unsafe { //println!("ffffffffff11"); - sprintf (unitstr.as_mut_ptr(), b"(%s, -%c) \0" as *const u8 as *const libc::c_char, + sprintf (unitstr.as_mut_ptr(), b"(%s, -%c) \0" as *const u8 as *const i8, limits[limind as usize].units, limits[limind as usize].option); } @@ -916,7 +920,7 @@ fn printone (limind : i32, curlim :RLIMTYPE , pdesc : i32){ } else { unsafe { - sprintf (unitstr.as_mut_ptr(),b"(-%c) \0" as *const u8 as *const libc::c_char, + sprintf (unitstr.as_mut_ptr(),b"(-%c) \0" as *const u8 as *const i8, limits[limind as usize].option); } @@ -986,8 +990,8 @@ fn set_all_limits (mut mode : i32 , newlim : RLIMTYPE) -> i32 { while limits[i as usize].option > 0 { if set_limit (i, newlim, mode) < 0 { unsafe { - builtin_error(b"%s: cannot modify limit : %s\0" as *const u8 as *const libc::c_char, limits[i as usize].description, - strerror(*__errno_location()) as *const libc::c_char); + builtin_error(b"%s: cannot modify limit : %s\0" as *const u8 as *const i8, limits[i as usize].description, + strerror(*__errno_location()) as *const i8); } retval = 1; i = i +1; diff --git a/bash-5.1/builtins_rust/umask/src/lib.rs b/bash-5.1/builtins_rust/umask/src/lib.rs index e45a50f7a9c1cecf322cb4838836803e1623de51..6e153736fdd426f78175e57aab61996ac18c7e3c 100644 --- a/bash-5.1/builtins_rust/umask/src/lib.rs +++ b/bash-5.1/builtins_rust/umask/src/lib.rs @@ -160,7 +160,6 @@ extern "C" { fn reset_internal_getopt(); fn internal_getopt (list:*mut WordList, opts:*mut c_char)->i32; fn builtin_usage(); - fn builtin_help(); // fn read_octal(string:*mut c_char)->i32; fn sh_erange(s:*mut c_char,desc:*mut c_char); fn sh_chkwrite(s:i32)->i32; @@ -213,12 +212,7 @@ pub extern "C" fn r_umask_builtin(mut list:*mut WordList) ->i32{ match opt_char { 'S' => {print_symbolically = print_symbolically +1;} 'p' => {pflag = pflag + 1;} - _ => { - if opt == -99 { - builtin_help(); - return EX_USAGE; - } - builtin_usage(); + _ => { builtin_usage(); return EX_USAGE; } } @@ -402,7 +396,7 @@ extern "C" fn r_parse_symbolic_mode(mode:*mut c_char,initial_bits:i32)->i32{ /* Now perform the operation or return an error for a bad permission string. */ - if *s != 0 || *s == ',' as libc::c_char{ + if *s != 0 || *s == ',' as i8{ if who != 0{ perm &= who; } @@ -420,7 +414,7 @@ extern "C" fn r_parse_symbolic_mode(mode:*mut c_char,initial_bits:i32)->i32{ /* No other values are possible. */ _ => { } } - if *s == '\0' as libc::c_char{ + if *s == '\0' as i8{ break; } else { diff --git a/bash-5.1/builtins_rust/wait/src/lib.rs b/bash-5.1/builtins_rust/wait/src/lib.rs index 6cf0626b7657b72ecaa7e6c093ecd93427ac3186..79362038aef94d30cdd07e50d9aa2f554ca2bf97 100644 --- a/bash-5.1/builtins_rust/wait/src/lib.rs +++ b/bash-5.1/builtins_rust/wait/src/lib.rs @@ -212,7 +212,6 @@ extern "C" { fn wait_for_background_pids(ps:*mut procstat); fn wait_for_single_pid(pid:pid_t,flags:i32)->i32; fn wait_for_job(job:i32,flags:i32,ps:*mut procstat)->i32; - fn builtin_help(); } unsafe fn DIGIT(c:c_char)->bool{ @@ -275,10 +274,6 @@ pub extern "C" fn r_wait_builtin(mut list:*mut WordList)->i32{ 'f' => wflags |= JWAIT_FORCE!(), 'p' => vname = list_optarg, _ => { - if opt == -99 { - builtin_help(); - return EX_USAGE; - } r_builtin_usage(); return EX_USAGE; } @@ -407,7 +402,7 @@ pub extern "C" fn r_wait_builtin(mut list:*mut WordList)->i32{ //if defined (JOB_CONTROL) //else if w != std::ptr::null_mut() && (w as u8)as char == '%' { - else if *w != 0 && *w == '%' as libc::c_char { + else if *w != 0 && *w == '%' as i8 { /* Must be a job spec. Check it out. */ let job:i32; let mut set:SigSet = SigSet::empty(); diff --git a/record.txt b/record.txt index 6929b166db5841b5ce97066d56a44defe5d3656e..250ff63e5d34d2167122796b7d7f3c28744b9d7b 100644 --- a/record.txt +++ b/record.txt @@ -59,3 +59,4 @@ 58 59 60 +61