From 403201e163a70f1c3aafb2de21f71fd9a36580c6 Mon Sep 17 00:00:00 2001 From: wangmengc Date: Wed, 16 Aug 2023 09:20:35 +0800 Subject: [PATCH] fix mapfile -d --- bash-5.1/Cargo.toml | 8 - bash-5.1/Makefile.in | 4 +- bash-5.1/builtins_rust/alias/src/lib.rs | 91 ++--------- bash-5.1/builtins_rust/declare/src/lib.rs | 52 +++--- bash-5.1/builtins_rust/hash/src/lib.rs | 121 ++++++-------- bash-5.1/builtins_rust/help/src/lib.rs | 2 +- bash-5.1/builtins_rust/setattr/Cargo.toml | 3 +- .../builtins_rust/setattr/src/intercdep.rs | 20 +-- bash-5.1/builtins_rust/setattr/src/lib.rs | 151 +++++------------- bash-5.1/cargo/config.toml | 3 - bash-5.1/resources/en-US/message.ftl | 34 ++-- bash-5.1/resources/zh-CN/message.ftl | 17 +- bash-5.1/resources/zh-HK/message.ftl | 19 ++- record.txt | 1 + 14 files changed, 167 insertions(+), 359 deletions(-) diff --git a/bash-5.1/Cargo.toml b/bash-5.1/Cargo.toml index 68e7298..87ccd3a 100644 --- a/bash-5.1/Cargo.toml +++ b/bash-5.1/Cargo.toml @@ -2,10 +2,6 @@ name = "rsbash" version = "0.1.0" edition = "2018" -build = "build.rs" - -[build-dependencies] -bindgen = "0.20.0" [lib] name = "rsbash" @@ -66,12 +62,10 @@ members=[ "builtins_rust/setattr", "builtins_rust/source", "builtins_rust/exec_cmd", - "u_src", ] [dependencies] libc = "*" - bindgen = "*" rread = {path = "./builtins_rust/read"} rhistory = {path = "./builtins_rust/history"} rkill = {path = "./builtins_rust/kill"} @@ -108,5 +102,3 @@ members=[ rwait = {path = "./builtins_rust/wait"} rdeclare = {path = "./builtins_rust/declare"} rexec_cmd = {path = "./builtins_rust/exec_cmd"} - - r_main = {path = "./u_src"} diff --git a/bash-5.1/Makefile.in b/bash-5.1/Makefile.in index d94c718..dd1c8a4 100644 --- a/bash-5.1/Makefile.in +++ b/bash-5.1/Makefile.in @@ -139,7 +139,7 @@ LOCALE_DEFS = -DLOCALEDIR='"$(localedir)"' -DPACKAGE='"$(PACKAGE)"' LOCAL_LIBS = @LOCAL_LIBS@ -LIBS = $(BUILTINS_LIB) $(LIBRARIES) @LIBS@ -lrt -lpthread -L./target/debug -lralias -lrbind -lrbreak -lrbuiltin -lrcaller -lrcd -lrcolon -lrcommon -lcommand -lrcomplete -lrdeclare -lrecho -lrenable -lreval -lrexec -lrexit -lrfc -lrfg_bg -lrgetopts -lrhash -lrexit -lrhelp -lrhistory -lrjobs -lrkill -lrmapfile -lrpushd -lrread -lrlet -lrreturn -lrset -lrsetattr -lrshift -lrshopt -lrsource -lrsuspend -lrtest -lrtimes -lrtrap -lrtype -lrulimit -lrumask -lrwait -lrprintf -lrexec_cmd -lr_main +LIBS = $(BUILTINS_LIB) $(LIBRARIES) @LIBS@ -lrt -lpthread -L./target/debug -lralias -lrbind -lrbreak -lrbuiltin -lrcaller -lrcd -lrcolon -lrcommon -lcommand -lrcomplete -lrdeclare -lrecho -lrenable -lreval -lrexec -lrexit -lrfc -lrfg_bg -lrgetopts -lrhash -lrexit -lrhelp -lrhistory -lrjobs -lrkill -lrmapfile -lrpushd -lrread -lrlet -lrreturn -lrset -lrsetattr -lrshift -lrshopt -lrsource -lrsuspend -lrtest -lrtimes -lrtrap -lrtype -lrulimit -lrumask -lrwait -lrprintf -lrexec_cmd LIBS_FOR_BUILD = STATIC_LD = @STATIC_LD@ @@ -571,7 +571,7 @@ LANGSRC = $(srcdir)/$(LANGSUBDIR) RUST_DIR = $(top_builddir)/builtins_rust #RUST_TARGET_LIB = $(top_builddir)/target/debug/librjobs.a $(top_builddir)/target/debug/librread.a -RUST_BUILTINS_DIRS = $(RUST_DIR)/alias $(RUST_DIR)/bind $(RUST_DIR)/break_1 $(RUST_DIR)/builtin $(RUST_DIR)/caller $(RUST_DIR)/cd $(RUST_DIR)/colon $(RUST_DIR)/command $(RUST_DIR)/common $(RUST_DIR)/complete $(RUST_DIR)/declare $(RUST_DIR)/echo $(RUST_DIR)/enable $(RUST_DIR)/eval $(RUST_DIR)/exit $(RUST_DIR)/fc $(RUST_DIR)/fg_bg $(RUST_DIR)/getopts $(RUST_DIR)/hash $(RUST_DIR)/help $(RUST_DIR)/history $(RUST_DIR)/jobs $(RUST_DIR)/kill $(RUST_DIR)/mapfile $(RUST_DIR)/printf $(RUST_DIR)/pushd $(RUST_DIR)/read $(RUST_DIR)/rlet $(RUST_DIR)/rreturn $(RUST_DIR)/set $(RUST_DIR)/setattr $(RUST_DIR)/shift $(RUST_DIR)/shopt $(RUST_DIR)/source $(RUST_DIR)/suspend $(RUST_DIR)/test $(RUST_DIR)/times $(RUST_DIR)/trap $(RUST_DIR)/type $(RUST_DIR)/ulimit $(RUST_DIR)/umask $(RUST_DIR)/wait $(RUST_DIR)/exec $(RUST_DIR)/exec_cmd $(RUST_DIR)/u_src +RUST_BUILTINS_DIRS = $(RUST_DIR)/alias $(RUST_DIR)/bind $(RUST_DIR)/break_1 $(RUST_DIR)/builtin $(RUST_DIR)/caller $(RUST_DIR)/cd $(RUST_DIR)/colon $(RUST_DIR)/command $(RUST_DIR)/common $(RUST_DIR)/complete $(RUST_DIR)/declare $(RUST_DIR)/echo $(RUST_DIR)/enable $(RUST_DIR)/eval $(RUST_DIR)/exit $(RUST_DIR)/fc $(RUST_DIR)/fg_bg $(RUST_DIR)/getopts $(RUST_DIR)/hash $(RUST_DIR)/help $(RUST_DIR)/history $(RUST_DIR)/jobs $(RUST_DIR)/kill $(RUST_DIR)/mapfile $(RUST_DIR)/printf $(RUST_DIR)/pushd $(RUST_DIR)/read $(RUST_DIR)/rlet $(RUST_DIR)/rreturn $(RUST_DIR)/set $(RUST_DIR)/setattr $(RUST_DIR)/shift $(RUST_DIR)/shopt $(RUST_DIR)/source $(RUST_DIR)/suspend $(RUST_DIR)/test $(RUST_DIR)/times $(RUST_DIR)/trap $(RUST_DIR)/type $(RUST_DIR)/ulimit $(RUST_DIR)/umask $(RUST_DIR)/wait $(RUST_DIR)/exec $(RUST_DIR)/exec_cmd # Keep GNU Make from exporting the entire environment for small machines. diff --git a/bash-5.1/builtins_rust/alias/src/lib.rs b/bash-5.1/builtins_rust/alias/src/lib.rs index 9f0edba..8cdfc22 100644 --- a/bash-5.1/builtins_rust/alias/src/lib.rs +++ b/bash-5.1/builtins_rust/alias/src/lib.rs @@ -1,10 +1,10 @@ - use std::ffi::CStr; + //extern crate rcommon; use rcommon::r_sh_notfound; -use rcommon::{WordList, WordDesc, EX_USAGE, EXECUTION_SUCCESS, EXECUTION_FAILURE,r_builtin_usage,SHELL_VAR}; +use rcommon::{WordList, WordDesc, EX_USAGE, EXECUTION_SUCCESS, EXECUTION_FAILURE,r_builtin_usage}; use rhelp::r_builtin_help; -use std::ffi::CString; + extern "C" { fn free(__ptr: *mut libc::c_void); fn dcgettext( @@ -28,12 +28,10 @@ extern "C" { fn sh_chkwrite(_: libc::c_int) -> libc::c_int; static mut loptend: *mut WordList; fn internal_getopt(_: *mut WordList, _: *mut libc::c_char) -> libc::c_int; - fn find_user_command(name:*const libc::c_char)->*mut libc::c_char; - fn find_shell_builtin(builtin: *mut libc::c_char) -> *mut libc::c_char; - fn find_function (name:* const libc::c_char)-> *mut SHELL_VAR; fn reset_internal_getopt(); } pub type SizeT = libc::c_ulong; + #[derive(Copy, Clone)] #[repr(C)] pub struct bucket_contents { @@ -60,7 +58,11 @@ pub struct alias { pub flags: libc::c_char, } pub type AliasT = alias; + pub static AL_REUSABLE:i32 = 0x01; + + + #[no_mangle] pub unsafe extern "C" fn r_alias_builtin(mut list: *mut WordList) -> libc::c_int { let mut any_failed; @@ -140,12 +142,7 @@ pub unsafe extern "C" fn r_alias_builtin(mut list: *mut WordList) -> libc::c_int ); any_failed += 1; } else { - let slice= CStr::from_ptr(value); - let mut r_str=slice.to_str().unwrap().to_owned(); - let new_str = CString::new(r_str).unwrap(); - if legal_alias_rust(name,new_str.as_ptr() as *mut libc::c_char) == 0 { - add_alias(name, value); - } + add_alias(name, value); } } else { t = find_alias(name); @@ -230,75 +227,7 @@ unsafe extern "C" fn print_alias( alias: *mut AliasT, flags: libc::c_int) { } //); } + println!("{}={}", CStr::from_ptr((*alias).name).to_string_lossy().into_owned(), CStr::from_ptr(value).to_string_lossy().into_owned()); free(value as *mut libc::c_void); } -unsafe fn legal_alias_rust(name :*mut libc::c_char,value :*mut libc::c_char ) -> libc::c_int { - - let mut name_w:*mut libc::c_char; - let mut value_w:*mut libc::c_char; - let mut new_value:*mut libc::c_char; - let mut new_value_2:*mut libc::c_char; - let mut shell_bui : *mut libc::c_char; - let mut t: *mut AliasT; - let mut dflags ; - dflags = if posixly_correct != 0 { 0 as libc::c_int } else { 0x1 as libc::c_int }; - - if libc::strstr(value,CString::new(";").unwrap().as_ptr() as *mut libc::c_char) != std::ptr::null_mut() { - println!("; is not allow in alias"); - return 1; - } - t = find_alias(name); - if !t.is_null() { - println!("{} is already in alias", CStr::from_ptr(name).to_string_lossy().into_owned()); - print_alias(t, dflags); - return 1; - } - name_w = find_user_command(name); - new_value = sh_single_quote(value); - // 按照空格区分 - new_value_2 = libc::strtok(value, CString::new(" ").unwrap().as_ptr() as *mut libc::c_char) ; - t = find_alias(new_value_2); - while t != std::ptr::null_mut() { - new_value_2 = libc::strtok((*t).value, CString::new(" ").unwrap().as_ptr() as *mut libc::c_char) ; - if libc::strcmp((*t).name,new_value_2) == 0 { - break; - } - t = find_alias(new_value_2); - } - let arr:[ *mut libc::c_char;7] = [CString::new("exec").unwrap().into_raw() as *mut libc::c_char, - CString::new("eval").unwrap().into_raw() as *mut libc::c_char, - CString::new("builtin").unwrap().into_raw() as *mut libc::c_char, - CString::new("command").unwrap().into_raw() as *mut libc::c_char, - CString::new("function").unwrap().into_raw() as *mut libc::c_char, - CString::new("source").unwrap().into_raw() as *mut libc::c_char, - CString::new(".").unwrap().into_raw() as *mut libc::c_char ]; - - for index in 0..7 { - if libc::strcmp(new_value_2, arr[index]) == 0 { - println!("command {} will raise an unsafe operation",CStr::from_ptr(arr[index]).to_string_lossy().into_owned()); - return 1; - } - } - value_w = find_user_command(new_value_2); - if name_w != std::ptr::null_mut(){ - if value_w != std::ptr::null_mut() && libc::strcmp(name_w, value_w) == 0 { - return 0; - } - else { - println!("The name and value point to different executable files"); - return 1 ; - } - } - else { - if find_shell_builtin(name) != std::ptr::null_mut() { - println!("name {} is shell builtin",CStr::from_ptr(name).to_string_lossy().into_owned()); - return 1; - } - else if find_function(name) != std::ptr::null_mut() { - println!("name {} is function",CStr::from_ptr(name).to_string_lossy().into_owned()); - return 1; - } - } - return 0; -} diff --git a/bash-5.1/builtins_rust/declare/src/lib.rs b/bash-5.1/builtins_rust/declare/src/lib.rs index dcc5beb..8f171df 100644 --- a/bash-5.1/builtins_rust/declare/src/lib.rs +++ b/bash-5.1/builtins_rust/declare/src/lib.rs @@ -5,7 +5,7 @@ use libc::{c_char, c_long, c_void}; use std::{ffi::CString}; use rcommon::{WordList, WordDesc, EX_USAGE, EXECUTION_SUCCESS, EXECUTION_FAILURE, r_savestring}; use rhelp::r_builtin_help; -use rsetattr::{show_name_attributes,set_or_show_attributes,show_all_var_attributes}; +use rsetattr::{show_name_attributes,set_or_show_attributes}; use std::ffi::CStr; #[repr(u8)] enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple, cm_select, @@ -463,7 +463,7 @@ extern "C" { fn builtin_usage(); static mut loptend:*mut WordList; fn show_local_var_attributes (v:i32, nodefs:i32)->i32; - // fn show_all_var_attributes (v:i32, nodefs:i32)->i32; + fn show_all_var_attributes (v:i32, nodefs:i32)->i32; fn set_builtin (list:*mut WordList)->i32; fn sh_chkwrite (ret:i32)->i32; fn show_func_attributes (name:* mut c_char, nodefs:i32)->i32; @@ -651,6 +651,7 @@ pub extern "C" fn r_declare_internal (mut list:* mut WordList, local_var:i32)->i let mut shell_fn:*mut function_def; refvar = std::ptr::null_mut(); + unsafe { reset_internal_getopt (); let tmp = DECLARE_OPTS(); @@ -776,7 +777,7 @@ pub extern "C" fn r_declare_internal (mut list:* mut WordList, local_var:i32)->i let wflags:i32; let mut created_var:i32; let mut namelen:i32; - let assoc_noexpand:bool; + let assoc_noexpand:i32; let mut making_array_special:i32; let mut compound_array_assign:i32; @@ -784,14 +785,14 @@ pub extern "C" fn r_declare_internal (mut list:* mut WordList, local_var:i32)->i let mut var_exists:i32; let mut array_exists:i32; let mut creating_array:i32; - let mut array_subscript_assignment:bool; + let mut array_subscript_assignment:i32; name = r_savestring ((*(*list).word).word); wflags = (*(*list).word).flags; - assoc_noexpand = (assoc_expand_once !=0 && (wflags & (1 << 2)) !=0); + assoc_noexpand = (assoc_expand_once !=0 && (wflags & (1 << 2)) !=0) as i32; // 分出= - if assoc_noexpand { + if assoc_noexpand !=0 { offset = assignment (name, 2); } else { offset = assignment (name, 0); @@ -815,14 +816,15 @@ pub extern "C" fn r_declare_internal (mut list:* mut WordList, local_var:i32)->i if offset !=0 { /* declare [-aAfFirx] name=value */ *name.offset(offset as isize) = '\0' as c_char; - value = name.offset((offset + 1) as isize) ; - if *(name.offset((offset - 1) as isize)) == '+' as c_char { + value = (name as usize + (offset + 1) as usize) as * mut c_char; + if *((name as usize + (offset - 1) as usize) as * mut c_char) == '+' as c_char { aflags |= ASS_APPEND!(); - *(name.offset((offset - 1) as isize))= '\0' as c_char; + *((name as usize + (offset - 1) as usize) as * mut c_char) = '\0' as c_char; } } else { value = tmpValue.as_ptr() as * mut c_char; } + /* Do some lexical error checking on the LHS and RHS of the assignment that is specific to nameref variables. */ if (flags_on & att_nameref!()) !=0 { @@ -859,7 +861,7 @@ pub extern "C" fn r_declare_internal (mut list:* mut WordList, local_var:i32)->i creating_array = 0; compound_array_assign = 0; simple_array_assign = 0; - array_subscript_assignment = false; + array_subscript_assignment = 0; subscript_start = std::ptr::null_mut(); t = libc::strchr (name, '[' as libc::c_int); if t !=std::ptr::null_mut() && (flags_on & att_function!()) == 0 {/* ] */ @@ -876,7 +878,7 @@ pub extern "C" fn r_declare_internal (mut list:* mut WordList, local_var:i32)->i subscript_start = t; *t = '\0' as c_char; making_array_special = 1; /* XXX - should this check offset? */ - array_subscript_assignment = offset != 0; + array_subscript_assignment = (offset != 0) as i32; } else { making_array_special = 0; } @@ -1101,7 +1103,7 @@ pub extern "C" fn r_declare_internal (mut list:* mut WordList, local_var:i32)->i var =find_variable (nameref_cell (refvar)); } } - } else if var == std::ptr::null_mut() && offset !=0 && array_subscript_assignment { + } else if var == std::ptr::null_mut() && offset !=0 && array_subscript_assignment !=0 { /* If we have an array assignment to a nameref, remove the nameref attribute and go on. */ if mkglobal !=0 { @@ -1158,25 +1160,24 @@ pub extern "C" fn r_declare_internal (mut list:* mut WordList, local_var:i32)->i libc::strcpy (name, nameref_cell (refvar)); if subscript_start != std::ptr::null_mut() { - libc::strcpy (name.offset(libc::strlen (nameref_cell (refvar)) as isize), subscript_start); + libc::strcpy ((name as usize + (libc::strlen (nameref_cell (refvar))) as usize) as * mut c_char, subscript_start); } /* We are committed to using the new name, so reset */ if offset !=0 { /* Rebuild assignment and restore offset and value */ if (aflags & ASS_APPEND!()) !=0 { - *(name.offset( namelen as isize) as * mut c_char) = '+' as c_char; - + *((name as usize + namelen as usize) as * mut c_char) = '+' as c_char; namelen+=1; } - *(name.offset( namelen as isize) as * mut c_char) = '=' as c_char; - // *((name as usize + namelen as usize) as * mut c_char) = '=' as c_char; + + *((name as usize + namelen as usize) as * mut c_char) = '=' as c_char; namelen+=1; if value != std::ptr::null_mut() && (*value) !=0 { - libc::strcpy (name.offset(namelen as isize), value); + libc::strcpy ((name as usize + namelen as usize) as * mut c_char, value); } else { - *(name.offset( namelen as isize) as * mut c_char) = '\0' as c_char; + *((name as usize + namelen as usize) as * mut c_char) = '\0' as c_char; } offset = assignment (name, 0); @@ -1191,9 +1192,8 @@ pub extern "C" fn r_declare_internal (mut list:* mut WordList, local_var:i32)->i list = (*list).next; continue 'outter; } - *(name.offset(offset as isize)) = '\0' as c_char; - - value = name.offset(namelen as isize) ; + *((name as usize + offset as usize) as * mut c_char) = '\0' as c_char; + value = (name as usize + namelen as usize) as * mut c_char; } libc::free (oldname as * mut c_void); @@ -1303,13 +1303,13 @@ pub extern "C" fn r_declare_internal (mut list:* mut WordList, local_var:i32)->i /* make declare a[2]=foo as similar to a[2]=foo as possible if a is already an array or assoc variable. */ - if array_subscript_assignment && array_exists !=0 && creating_array == 0 { + if array_subscript_assignment !=0 && array_exists !=0 && creating_array == 0 { simple_array_assign = 1; } else if (making_array_special !=0 || creating_array !=0 || array_exists !=0) && offset!=0 { let mut vlen:i32; vlen = libc::strlen (value) as i32; /*itrace("declare_builtin: name = %s value = %s flags = %d", name, value, wflags);*/ - if shell_compatibility_level > 43 && (wflags & W_COMPASSIGN!()) == 0 && *value == '(' as c_char && *(value.offset((vlen-1) as isize) as * mut c_char) == ')' as c_char { + if shell_compatibility_level > 43 && (wflags & W_COMPASSIGN!()) == 0 && *value == '(' as c_char && *((value as usize + (vlen-1) as usize) as * mut c_char) == ')' as c_char { /* The warning is only printed when using compound assignment to an array variable that doesn't already exist. We use creating_array to allow things like @@ -1319,7 +1319,7 @@ pub extern "C" fn r_declare_internal (mut list:* mut WordList, local_var:i32)->i } compound_array_assign = (array_exists !=0 || creating_array !=0) as i32; simple_array_assign = making_array_special; - } else if *value == '(' as c_char && *(value.offset((vlen-1) as isize) as * mut c_char) == ')' as c_char && (shell_compatibility_level < 44 || (wflags & W_COMPASSIGN!()) !=0 ) { + } else if *value == '(' as c_char && *((value as usize + (vlen-1) as usize) as * mut c_char) == ')' as c_char && (shell_compatibility_level < 44 || (wflags & W_COMPASSIGN!()) !=0 ) { compound_array_assign = 1; } else { simple_array_assign = 1; @@ -1390,7 +1390,7 @@ pub extern "C" fn r_declare_internal (mut list:* mut WordList, local_var:i32)->i *subscript_start = '[' as c_char; /* ] */ /* XXX - problem here with appending */ local_aflags = aflags&ASS_APPEND!(); - if assoc_noexpand { + if assoc_noexpand !=0 { local_aflags |= ASS_NOEXPAND!(); } else { local_aflags |= 0; diff --git a/bash-5.1/builtins_rust/hash/src/lib.rs b/bash-5.1/builtins_rust/hash/src/lib.rs index 4918236..20c6b72 100644 --- a/bash-5.1/builtins_rust/hash/src/lib.rs +++ b/bash-5.1/builtins_rust/hash/src/lib.rs @@ -1,6 +1,7 @@ - extern crate libc; extern crate rread; + + use libc::{c_char,c_int, strchr,free,c_void,strerror,EISDIR}; use std::ffi::{CStr,CString}; use std::io::{stdout, Write}; @@ -8,8 +9,7 @@ use rread::{SHELL_VAR}; use rcommon::{r_find_shell_builtin,r_builtin_usage}; use rcommon::{WordList, WordDesc, EX_USAGE, EXECUTION_SUCCESS, EXECUTION_FAILURE}; use rhelp::r_builtin_help; -use std::fs; -use std::os::linux::fs::MetadataExt; + type PTR_T=c_void; #[repr (C)] pub struct bucket_contents{ @@ -20,6 +20,7 @@ pub struct bucket_contents{ pub times_found:i32, } type BUCKET_CONTENTS=bucket_contents; + #[repr (C)] pub struct hash_table{ pub bucket_array:*mut *mut BUCKET_CONTENTS, @@ -27,6 +28,7 @@ pub struct hash_table{ pub nentries:i32, } type HASH_TABLE = hash_table; + #[repr (C)] pub struct _pathdata{ pub path:*mut c_char, @@ -34,6 +36,9 @@ pub struct _pathdata{ } type PATH_DATA = _pathdata; //enum + + + #[macro_export] macro_rules! PARAMS { ($protos:expr) => { @@ -47,6 +52,7 @@ pub unsafe fn hash_entries(ht: *mut HASH_TABLE) -> i32 { return 0; } } + #[macro_export] macro_rules! HASH_ENTRIES { ($ht:expr) => { @@ -58,6 +64,7 @@ macro_rules! HASH_ENTRIES { } }; } + fn HASH_ENTRIES(ht:*mut HASH_TABLE)->i32{ unsafe{ if ht != std::ptr::null_mut(){ @@ -67,13 +74,17 @@ fn HASH_ENTRIES(ht:*mut HASH_TABLE)->i32{ return 0; } } + + } + #[macro_export] macro_rules! pathdata { ($x:expr) => { (*$x).data as *mut PATH_DATA }; } + #[macro_export] macro_rules! FREE { ($s:expr) => { @@ -82,17 +93,11 @@ macro_rules! FREE { } }; } -#[derive(Copy, Clone)] -#[repr(C)] -pub struct alias { - pub name: *mut libc::c_char, - pub value: *mut libc::c_char, - pub flags: libc::c_char, -} -pub type AliasT = alias; + // type i32 hash_efunc PARAMS(*mut BUCKET_CONTENTS); type hash_wfunc = extern fn(*mut BUCKET_CONTENTS)->i32; type sh_builtin_func_t = extern fn (*mut WordList)->i32; + //extern c extern "C"{ static loptend:*mut WordList; @@ -104,10 +109,11 @@ extern "C"{ static shell_compatibility_level:i32; static hashed_filenames:*mut HASH_TABLE; static dot_found_in_search:i32; + fn builtin_error(format:*const c_char,...); fn reset_internal_getopt(); fn internal_getopt(list:*mut WordList,opts:*mut c_char)->i32; - fn all_aliases() -> *mut *mut AliasT; + fn sh_needarg(s:*mut c_char); fn phash_flush(); fn sh_restricted(s:*mut c_char); @@ -125,7 +131,6 @@ extern "C"{ fn printable_filename(f:*mut c_char,flage:i32)->*mut c_char; } -static mut common_inode: c_int = 0; //rust /* Print statistics on the current state of hashed commands. If LIST is not empty, then rehash (or hash in the first place) the specified @@ -139,10 +144,12 @@ pub extern "C" fn r_hash_builtin(mut list:*mut WordList)->i32{ let mut opt:i32; let mut w:*mut c_char; let mut pathname:*mut c_char; + unsafe{ if hashing_enabled == 0{ let c_str = CString::new("hashing disabled").unwrap(); let c_str_ptr = c_str.as_ptr(); + builtin_error(c_str_ptr); return EXECUTION_FAILURE!(); } @@ -151,6 +158,7 @@ pub extern "C" fn r_hash_builtin(mut list:*mut WordList)->i32{ list_portably = 0; delete = 0; pathname = std::ptr::null_mut(); + reset_internal_getopt(); let opts = CString::new("dlp:rt").unwrap(); opt = internal_getopt(list,opts.as_ptr() as *mut c_char); @@ -171,10 +179,13 @@ pub extern "C" fn r_hash_builtin(mut list:*mut WordList)->i32{ r_builtin_usage(); return EX_USAGE; } + } opt = internal_getopt(list,opts.as_ptr() as *mut c_char); } + list = loptend; + /* hash -t requires at least one argument. */ if list == std::ptr::null_mut() && (delete != 0 || list_targets != 0) { let temp:CString; @@ -204,18 +215,22 @@ pub extern "C" fn r_hash_builtin(mut list:*mut WordList)->i32{ } return EXECUTION_SUCCESS!(); } + if expunge_hash_table != 0{ phash_flush(); } + /* If someone runs `hash -r -t xyz' he will be disappointed. */ if list_targets != 0{ return r_list_hashed_filename_targets(list,list_portably); } + if restricted != 0 && pathname != std::ptr::null_mut(){ if strchr(pathname,'/' as c_int) != std::ptr::null_mut(){ sh_restricted(pathname); return EXECUTION_FAILURE!(); } + /* If we are changing the hash table in a restricted shell, make sure the target pathname can be found using a $PATH search. */ w = find_user_command(pathname); @@ -226,6 +241,7 @@ pub extern "C" fn r_hash_builtin(mut list:*mut WordList)->i32{ } free(w as *mut c_void); } + opt = EXECUTION_SUCCESS!(); while list != std::ptr::null_mut(){ /* Add, remove or rehash the specified commands. */ @@ -235,16 +251,15 @@ pub extern "C" fn r_hash_builtin(mut list:*mut WordList)->i32{ } else if pathname != std::ptr::null_mut(){ if is_directory(pathname) != 0{ + let c_err = CString::new("%s:%s").unwrap(); let c_err_ptr = c_err.as_ptr(); builtin_error(c_err_ptr,pathname,strerror(EISDIR)); opt = EXECUTION_SUCCESS!(); + } else{ - if legal_hash_rust(w,pathname) == 0{ - phash_insert(w,pathname,0,0); - } - + phash_insert(w,pathname,0,0); } } else if delete != 0{ @@ -258,17 +273,22 @@ pub extern "C" fn r_hash_builtin(mut list:*mut WordList)->i32{ } list = (*list).next; } + stdout().flush(); return opt; }//unsafe } + extern "C" fn r_add_hashed_command(w:*mut c_char,quiet:i32)->i32{ let mut rv:i32; let full_path:*mut c_char; + rv = 0; + unsafe{ if find_function(w).is_null() && find_shell_builtin(w).is_null(){ // if find_function(w).is_null() && r_find_shell_builtin(w).is_null(){ + // println!("1111"); phash_remove(w); full_path = find_user_command(w); if full_path != std::ptr::null_mut() && executable_file(full_path) != 0{ @@ -282,9 +302,12 @@ extern "C" fn r_add_hashed_command(w:*mut c_char,quiet:i32)->i32{ } FREE!(full_path); } + return rv; + }//unsafe } + extern "C" fn r_print_hash_info(item:*mut BUCKET_CONTENTS)->i32{ unsafe{ @@ -294,16 +317,19 @@ extern "C" fn r_print_hash_info(item:*mut BUCKET_CONTENTS)->i32{ }//unsafe 0 } + #[no_mangle] extern "C" fn r_print_portable_hash_info(item:*mut BUCKET_CONTENTS)->i32{ let fp:*mut c_char; let f:*mut c_char; + unsafe{ fp = printable_filename((*pathdata!(item)).path,1); f = printable_filename((*item).key,1); let fp_string = CStr::from_ptr(fp).to_str().unwrap();//.to_owned() let f_string = CStr::from_ptr(f).to_str().unwrap();//.to_owned() println!("builtin hash -p {} {}",fp_string,f_string); + if fp != (*pathdata!(item)).path{ free(fp as *mut c_void); } @@ -313,10 +339,13 @@ extern "C" fn r_print_portable_hash_info(item:*mut BUCKET_CONTENTS)->i32{ return 0; }//unsafe } + #[no_mangle] extern "C" fn r_print_hashed_commands(fmt:i32)->i32{ unsafe{ + if hashed_filenames.is_null() || hash_entries(hashed_filenames) == 0 { + return 0; } if fmt == 0{ @@ -333,12 +362,14 @@ extern "C" fn r_print_hashed_commands(fmt:i32)->i32{ return 1; } } + #[no_mangle] extern "C" fn r_list_hashed_filename_targets(list:*mut WordList,fmt:i32)->i32{ let mut all_found:i32; let multiple:i32; let mut target:*mut c_char; let mut l:*mut WordList; + all_found = 1; unsafe{ @@ -348,6 +379,7 @@ extern "C" fn r_list_hashed_filename_targets(list:*mut WordList,fmt:i32)->i32{ else{ multiple = 0; } + l = list; while !l.is_null(){ target = phash_search((*(*l).word).word); @@ -380,58 +412,5 @@ extern "C" fn r_list_hashed_filename_targets(list:*mut WordList,fmt:i32)->i32{ return EXECUTION_FAILURE!(); } } -} -unsafe fn legal_hash_rust(name :*mut libc::c_char,value :*mut libc::c_char ) -> libc::c_int { - let alias_list: *mut *mut AliasT = all_aliases(); - let mut t: *mut AliasT; - let mut offset; - let mut name_w:*mut libc::c_char; - let mut target:*mut c_char; - offset = 0; - if !alias_list.is_null() { - t = *alias_list.offset(offset as isize); - while !t.is_null() { - if !(*t).name.is_null() { - if libc::strcmp(name,(*t).name) == 0 { - println!("Prohibit setting existing variables that is already in alias"); - println!("{} = {}" ,CStr::from_ptr((*t).name).to_string_lossy().into_owned(),CStr::from_ptr((*t).value).to_string_lossy().into_owned()); - return 1; - } - } - offset += 1; - t = *alias_list.offset(offset as isize); - } - } - if find_shell_builtin(name) != std::ptr::null_mut() { - println!("Prohibit setting existing variables {} is a shell builtin",CStr::from_ptr(name).to_string_lossy().into_owned()); - return 1; - } - else if find_function(name) != std::ptr::null_mut() { - println!("Prohibit setting existing variables {} is a function",CStr::from_ptr(name).to_string_lossy().into_owned()); - return 1; - } - name_w = find_user_command(name) ; - if name_w != std::ptr::null_mut() { - file_inode(CStr::from_ptr(name_w).to_str().unwrap(),CStr::from_ptr(value).to_str().unwrap()); - if common_inode == 1 { - return 1; - } - } - target = phash_search(name); - if target != std::ptr::null_mut() { - println!("{} is already in hash", CStr::from_ptr(name).to_string_lossy().into_owned()); - return 1; - } - return 0; -} -unsafe fn file_inode(pathname : &str,pathname2 : &str) -> std::io::Result<()> { - let meta = fs::metadata( pathname )?; - let meta2 = fs::metadata( pathname2 )?; - common_inode = 0; - if (meta.st_ino() != meta2.st_ino()) { - println!("The name and value point to different executable files"); - common_inode = 1; - } - Ok(()) -} \ No newline at end of file +} diff --git a/bash-5.1/builtins_rust/help/src/lib.rs b/bash-5.1/builtins_rust/help/src/lib.rs index 9647bbc..99e69f8 100644 --- a/bash-5.1/builtins_rust/help/src/lib.rs +++ b/bash-5.1/builtins_rust/help/src/lib.rs @@ -353,7 +353,7 @@ fn show_helpsynopsis( i : i32) let mut pattern = value.value().expect("partern err"); let mut errors = vec![]; let mut msg1 = bundle.format_pattern(&pattern, Some(&args), &mut errors); - println!(" {}", msg1); + println!(" {}", msg1); } fn show_desc (i :i32){ diff --git a/bash-5.1/builtins_rust/setattr/Cargo.toml b/bash-5.1/builtins_rust/setattr/Cargo.toml index 29dd143..3eb0712 100644 --- a/bash-5.1/builtins_rust/setattr/Cargo.toml +++ b/bash-5.1/builtins_rust/setattr/Cargo.toml @@ -15,5 +15,4 @@ crate-type = ["staticlib","rlib"] libc = "*" nix = "*" rcommon = {path = "../common"} -rhelp = {path ="../help"} -rread = {path="../read"} \ No newline at end of file +rhelp = {path ="../help"} \ No newline at end of file diff --git a/bash-5.1/builtins_rust/setattr/src/intercdep.rs b/bash-5.1/builtins_rust/setattr/src/intercdep.rs index b5322b5..8c46559 100644 --- a/bash-5.1/builtins_rust/setattr/src/intercdep.rs +++ b/bash-5.1/builtins_rust/setattr/src/intercdep.rs @@ -1,5 +1,4 @@ use rcommon::{WordList}; -use rread::{ARRAY}; #[repr(C)] #[derive(Copy, Clone)] pub struct word_desc { @@ -300,22 +299,6 @@ pub struct jobstats { pub j_lastasync: *mut JOB, } -#[repr(C)] -pub struct BUCKET_CONTENTS { - next:* mut BUCKET_CONTENTS, /* Link to next hashed key in this bucket. */ - key:* mut c_char, /* What we look up. */ - data:* mut c_void, /* What we really want. */ - khash:u32, /* What key hashes to */ - times_found:i32 /* Number of times this item has been found. */ -} - -#[repr(C)] -pub struct HASH_TABLE { - bucket_array:*mut * mut BUCKET_CONTENTS, /* Where the data is kept. */ - nbuckets:i32, /* How many buckets does this table have. */ - nentries:i32 /* How many entries does this table have. */ -} - pub type sh_builtin_func_t = unsafe extern "C" fn(arg1: *mut WordList) -> c_int; @@ -395,6 +378,5 @@ extern "C" { pub fn bind_variable(name: *const c_char, value: *mut c_char, flags: c_int) -> *mut SHELL_VAR; pub fn stupidly_hack_special_variables(name: *mut c_char); - pub fn array_to_assign(a:*mut ARRAY,quote : c_int) -> *mut c_char; - pub fn assoc_to_assign(a:*mut HASH_TABLE,quote : c_int) -> *mut c_char; + } diff --git a/bash-5.1/builtins_rust/setattr/src/lib.rs b/bash-5.1/builtins_rust/setattr/src/lib.rs index a6de56a..fb491d1 100644 --- a/bash-5.1/builtins_rust/setattr/src/lib.rs +++ b/bash-5.1/builtins_rust/setattr/src/lib.rs @@ -4,7 +4,6 @@ use libc::{c_int, c_uint, c_char, c_long, PT_NULL, c_void}; use rhelp::r_builtin_help; include!(concat!("intercdep.rs")); use std::ffi::CStr; - #[no_mangle] pub extern "C" fn r_export_builtin(list: *mut WordList) -> c_int { return set_or_show_attributes(list, att_exported, 0); @@ -84,6 +83,7 @@ unsafe { list = (*list).next; continue; } + assign = assignment(name, 0); aflags = 0; if assign != 0 { @@ -157,7 +157,7 @@ unsafe { set_var_attribute(name, attribute, undo); if assign != 0 { *(name.offset(assign as isize)) = b'=' as c_char; - // *((name as usize + assign as usize) as *mut c_char) = b'=' as c_char; + *((name as usize + assign as usize) as *mut c_char) = b'=' as c_char; if (aflags & ASS_APPEND) != 0 { *(name.offset((assign-1) as isize)) = b'+' as c_char; } @@ -190,15 +190,15 @@ unsafe { if !variable_list.is_null() { let mut i = 0; loop { - var = *(variable_list.offset(i)) as *mut SHELL_VAR; + var = *(variable_list.offset(i)) as *mut SHELL_VAR; if var.is_null() { break; } - if arrays_only != 0 && (((*var).attributes & att_array) == 0) { + if arrays_only != 0 && ((*var).attributes & att_array) == 0 { i += 1; continue; - } else if assoc_only != 0 && (((*var).attributes & att_assoc) == 0) { + } else if assoc_only != 0 && ((*var).attributes & assoc_only) == 0 { i += 1; continue; } @@ -211,12 +211,7 @@ unsafe { if ((*var).attributes & attribute) != 0 { let pattr = (this_shell_builtin as usize == r_readonly_builtin as usize) || (this_shell_builtin as usize == r_export_builtin as usize); - if pattr { - show_var_attributes(var, 1, nodefs); - } - else { - show_var_attributes(var, 0, nodefs); - } + show_var_attributes(var, pattr as c_int, nodefs); any_failed = sh_chkwrite(any_failed); if any_failed != 0 { break; @@ -232,34 +227,31 @@ unsafe { } #[no_mangle] -pub extern "C" fn show_all_var_attributes(v: c_int, nodefs: c_int) -> c_int { +pub extern "C" fn show_all_var_attributes(list: *mut WordList, v: c_int, nodefs: c_int) -> c_int { let mut i = 0; let mut any_failed = 0; let mut var: *mut SHELL_VAR; let mut variable_list: *mut *mut SHELL_VAR; unsafe { - variable_list = if v != 0 {all_shell_variables() } else {all_shell_functions()}; + variable_list = if v != 0 {all_shell_variables()} else {all_shell_functions()}; if variable_list.is_null() { return EXECUTION_SUCCESS; } loop { - var = *(variable_list.offset(i)); + var = variable_list.offset(i) as *mut SHELL_VAR; if var.is_null() { break; } + let pattr = (this_shell_builtin as usize == r_readonly_builtin as usize) || (this_shell_builtin as usize == r_export_builtin as usize); - if pattr { - show_var_attributes(var, 1, nodefs); - } - else { - show_var_attributes(var, 0, nodefs); - } + show_var_attributes(var, pattr as c_int, nodefs); any_failed = sh_chkwrite(any_failed); if any_failed != 0 { break; } + i += 1; } @@ -288,12 +280,7 @@ unsafe { let pattr = (this_shell_builtin as usize == r_readonly_builtin as usize) || (this_shell_builtin as usize == r_export_builtin as usize); - if pattr { - show_var_attributes(var, 1, nodefs); - } - else { - show_var_attributes(var, 0, nodefs); - } + show_var_attributes(var, pattr as c_int, nodefs); any_failed = sh_chkwrite(any_failed); if any_failed != 0 { break; @@ -308,57 +295,56 @@ unsafe { } #[no_mangle] -pub unsafe extern "C" fn show_var_attributes(var: *mut SHELL_VAR, pattr: c_int, mut nodefs: c_int) -> c_int { +pub extern "C" fn show_var_attributes(var: *mut SHELL_VAR, pattr: c_int, mut nodefs: c_int) -> c_int { + let mut flags = [0;16]; +unsafe { let i = var_attribute_string(var, pattr, flags.as_mut_ptr()); - if ((*var).attributes & att_function) != 0 && nodefs == 0 && (pattr == 0 || posixly_correct == 0) { - println!("{}",CStr::from_ptr(named_function_string((*var).name, (*var).value as *mut COMMAND, FUNC_MULTILINE | FUNC_EXTERNAL)).to_str().unwrap()); + if ((*var).attributes & att_function) != 0 && nodefs == 0 && + (pattr == 0 || posixly_correct == 0) { + println!("{}",CStr::from_ptr(named_function_string((*var).name, (*var).value as *mut COMMAND, FUNC_MULTILINE | FUNC_EXTERNAL)).to_str().unwrap()); nodefs += 1; if pattr == 0 && i == 1 && flags[0] == b'f' as c_char { return 0; } } if pattr == 0 || posixly_correct == 0 { - if i != 0 { - print!("declare -{} ",CStr::from_ptr(flags.as_ptr()).to_str().unwrap()); + if i !=0 { + print!("declare -{} ", CStr::from_ptr(flags.as_ptr()).to_str().unwrap()); } else { print!("declare -- "); } } else if i != 0 { - print!("{} -{} ",CStr::from_ptr(this_command_name).to_str().unwrap(),CStr::from_ptr(flags.as_ptr()).to_str().unwrap()); + print!("{} {}", CStr::from_ptr(this_command_name).to_str().unwrap(),CStr::from_ptr(flags.as_ptr()).to_str().unwrap()); } - else { - print!("{} ",CStr::from_ptr(this_command_name).to_str().unwrap()); + else { + print!("{}", CStr::from_ptr(this_command_name).to_str().unwrap()); } if ((*var).attributes & att_invisible) != 0 && - (((*var).attributes & att_array) != 0 || - ((*var).attributes & att_assoc) != 0 ){ + ((*var).attributes & att_array) != 0 && + ((*var).attributes & att_assoc) != 0 { println!("{}",CStr::from_ptr((*var).name).to_str().unwrap()); } - else if ((*var).attributes & att_array) != 0 { - r_print_array_assignment(var, 0); + else if ((*var).attributes & att_array) != 0 { + print_array_assignment(var, 0); } else if ((*var).attributes & att_assoc) != 0 { - r_print_assoc_assignment(var, 0); + print_assoc_assignment(var, 0); } - else if nodefs != 0 || ((((*var).attributes & att_function) != 0 && pattr != 0 && posixly_correct != 0)) { + else if nodefs != 0 || (((*var).attributes & att_function) != 0 && pattr != 0 && posixly_correct != 0) { println!("{}",CStr::from_ptr((*var).name).to_str().unwrap()); } else if ((*var).attributes & att_function) != 0 { println!("{}",CStr::from_ptr(named_function_string((*var).name, (*var).value as *mut COMMAND, FUNC_MULTILINE | FUNC_EXTERNAL)).to_str().unwrap()); - } - else if ((*var).attributes & att_invisible) != 0 || (*var).value == std::ptr::null_mut() { + } else if ((*var).attributes & att_invisible) != 0 || (*var).value.is_null() { println!("{}",CStr::from_ptr((*var).name).to_str().unwrap()); + } else { + println!("{} = {}",CStr::from_ptr((*var).name).to_str().unwrap(),CStr::from_ptr(sh_double_quote(value_cell(var))).to_str().unwrap()); } - else { - let x = sh_double_quote (value_cell(var)); - println!("{}={}",CStr::from_ptr((*var).name).to_str().unwrap(),CStr::from_ptr(x).to_str().unwrap()); - libc::free(x as *mut c_void); - } - +} return 0; } @@ -367,16 +353,6 @@ unsafe fn value_cell(var:*mut SHELL_VAR)->* mut c_char return (*var).value; } -unsafe fn array_cell(var:*mut SHELL_VAR)->* mut ARRAY -{ - return (*var).value as *mut ARRAY; -} - -unsafe fn assoc_cell(var:*mut SHELL_VAR)->* mut HASH_TABLE -{ - return (*var).value as *mut HASH_TABLE; -} - #[no_mangle] pub extern "C" fn show_name_attributes(name: *mut c_char, nodefs: c_int) -> c_int { unsafe { @@ -384,12 +360,7 @@ unsafe { if !var.is_null() { let pattr = (this_shell_builtin as usize == r_readonly_builtin as usize) || (this_shell_builtin as usize == r_export_builtin as usize); - if pattr { - show_var_attributes(var, 1, nodefs); - } - else { - show_var_attributes(var, 0, nodefs); - } + show_var_attributes(var, pattr as c_int, nodefs); return 0; } else { return 1; @@ -405,12 +376,7 @@ unsafe { if cond { let pattr = (this_shell_builtin as usize == r_readonly_builtin as usize) || (this_shell_builtin as usize == r_export_builtin as usize); - if pattr { - show_var_attributes(var, 1, nodefs); - } - else { - show_var_attributes(var, 0, nodefs); - } + show_var_attributes(var, pattr as c_int, nodefs); return 0; } else { return 1; @@ -425,12 +391,7 @@ pub extern "C" fn show_func_attributes(name: *mut c_char, nodefs: c_int) -> c_in if !var.is_null() { let pattr = (this_shell_builtin as usize == r_readonly_builtin as usize) || (this_shell_builtin as usize == r_export_builtin as usize); - if pattr { - show_var_attributes(var, 1, nodefs); - } - else { - show_var_attributes(var, 0, nodefs); - } + show_var_attributes(var, pattr as c_int, nodefs); return 0; } else { return 1; @@ -579,45 +540,9 @@ unsafe { *(flags.offset(i as isize)) = b'\0' as c_char; } - return i ; + return i as c_int; } unsafe fn cmp_two(a: usize, b: usize) -> bool { return a == b; } - -#[no_mangle] -pub unsafe extern "C" fn r_print_array_assignment(var: *mut SHELL_VAR, quote: c_int) { - let mut vstr = array_to_assign(array_cell(var) as *mut ARRAY ,quote); - - if vstr == std::ptr::null_mut() { - if quote != 0 { - println!("{}=\"\'()\'\"",CStr::from_ptr((*var).name).to_str().unwrap()); - } - else { - println!("{}=\"()\"",CStr::from_ptr((*var).name).to_str().unwrap()); - } - } - else { - println!("{}={}",CStr::from_ptr((*var).name).to_str().unwrap(),CStr::from_ptr(vstr).to_str().unwrap()); - libc::free(vstr as *mut c_void); - } -} - -#[no_mangle] -pub unsafe extern "C" fn r_print_assoc_assignment(var: *mut SHELL_VAR, quote: c_int) { - let mut vstr = assoc_to_assign(assoc_cell(var) as *mut HASH_TABLE ,quote); - - if vstr == std::ptr::null_mut() { - if quote != 0 { - println!("{}=\"\'()\'\"",CStr::from_ptr((*var).name).to_str().unwrap()); - } - else { - println!("{}=\"()\"",CStr::from_ptr((*var).name).to_str().unwrap()); - } - } - else { - println!("{}={}",CStr::from_ptr((*var).name).to_str().unwrap(),CStr::from_ptr(vstr).to_str().unwrap()); - libc::free(vstr as *mut c_void); - } -} diff --git a/bash-5.1/cargo/config.toml b/bash-5.1/cargo/config.toml index 40bd2d4..b00244a 100644 --- a/bash-5.1/cargo/config.toml +++ b/bash-5.1/cargo/config.toml @@ -8,6 +8,3 @@ replace-with = "vendored-sources" [source.vendored-sources] directory = "vendor" - -[dependencies] -clap = "4" diff --git a/bash-5.1/resources/en-US/message.ftl b/bash-5.1/resources/en-US/message.ftl index 8e6800c..6f1a201 100644 --- a/bash-5.1/resources/en-US/message.ftl +++ b/bash-5.1/resources/en-US/message.ftl @@ -976,16 +976,6 @@ $cmdName -> Returns success unless MODE is invalid or an invalid option is given. [return] - Return from a shell function. - - Causes a function or sourced script to exit with the return value - specified by N. If N is omitted, the return status is that of the - last command executed within the function or script. - - Exit Status: - Returns N, or failure if the shell is not executing a function or script. - -[wait] Wait for job completion and return exit status. Waits for each process identified by an ID, which may be a process ID or @@ -994,14 +984,17 @@ $cmdName -> status is zero. If ID is a job specification, waits for all processes in that job's pipeline. - If the -n option is supplied, waits for a single job from the list of IDs, - or, if no IDs are supplied, for the next job to complete and returns its + If the -n option is supplied, waits for a single job from the list of + IDs, + or, if no IDs are supplied, for the next job to complete and returns + its exit status. If the -p option is supplied, the process or job identifier of the job for which the exit status is returned is assigned to the variable VAR named by the option argument. The variable will be unset initially, - before any assignment. This is useful only when the -n option is supplied. + before + any assignment. This is useful only when the -n option is supplied. If the -f option is supplied, and job control is enabled, waits for the specified ID to terminate, instead of waiting for it to change status. @@ -1011,6 +1004,19 @@ $cmdName -> option is given, or if -n is supplied and the shell has no unwaited-for children. +[wait] + Wait for process completion and return exit status. + + Waits for each process specified by a PID and reports its termination + status. + If PID is not given, waits for all currently active child processes, + and the return status is zero. PID must be a process ID. + + Exit Status: + Returns the status of the last PID; fails if PID is invalid or an + invalid + option is given. + [for] Execute commands for each member in a list. @@ -1799,4 +1805,4 @@ invaildmap = {$str1} : invalid keymap name logout = logout nologinsh = not login shell: use 'exit' stoppedjobs = There are stopped jobs. -runjobs = There are running jobs. +runjobs = There are running jobs. \ No newline at end of file diff --git a/bash-5.1/resources/zh-CN/message.ftl b/bash-5.1/resources/zh-CN/message.ftl index 4cb92a5..90668d4 100644 --- a/bash-5.1/resources/zh-CN/message.ftl +++ b/bash-5.1/resources/zh-CN/message.ftl @@ -913,7 +913,7 @@ $cmdName -> 退出状态: 返回成功,除非使用了无效的 MODE 模式或者选项。 -[wait] +[return] 等待任务完成并返回退出状态。 等待以 ID 编号识别的进程,其中 ID 可以是进程编号或者任务声明, @@ -928,15 +928,14 @@ $cmdName -> 退出状态: 返回最后一个 ID 进程的状态;如果使用了无效的 ID 或者选项则失败。 -[return] - 从一个 shell 函数返回。 - - 使一个函数或者被引用的脚本以指定的返回值 N 退出。 - 如果 N 被省略,则返回状态就是 - 函数或脚本中的最后一个执行的命令的状态。 - +[wait] + 等待进程完成并且返回退出状态。 + + 等待指定进程并报告它的终止状态。如果没有提供 PID,则当前所有的活跃 + 子进程都会被等待,并且返回码为零。PID 必须为进程号。 + 退出状态: - 返回 N,或者如果 shell 不在执行一个函数或引用脚本时,失败。 + 返回进程 ID 的状态;如果 PID 是无效的进程号或者指定了无效的选项则失败。 [for] 为列表中的每个成员执行命令。 diff --git a/bash-5.1/resources/zh-HK/message.ftl b/bash-5.1/resources/zh-HK/message.ftl index b668058..15b71de 100644 --- a/bash-5.1/resources/zh-HK/message.ftl +++ b/bash-5.1/resources/zh-HK/message.ftl @@ -913,7 +913,7 @@ $cmdName -> 退出状态: 返回成功,除非使用了无效的 MODE 模式或者选项。 -[wait] +[return] 等待任务完成并返回退出状态。 等待以 ID 编号识别的进程,其中 ID 可以是进程编号或者任务声明, @@ -928,15 +928,14 @@ $cmdName -> 退出状态: 返回最后一个 ID 进程的状态;如果使用了无效的 ID 或者选项则失败。 -[return] - 从一个 shell 函数返回。 - - 使一个函数或者被引用的脚本以指定的返回值 N 退出。 - 如果 N 被省略,则返回状态就是 - 函数或脚本中的最后一个执行的命令的状态。 - +[wait] + 等待进程完成并且返回退出状态。 + + 等待指定进程并报告它的终止状态。如果没有提供 PID,则当前所有的活跃 + 子进程都会被等待,并且返回码为零。PID 必须为进程号。 + 退出状态: - 返回 N,或者如果 shell 不在执行一个函数或引用脚本时,失败。 + 返回进程 ID 的状态;如果 PID 是无效的进程号或者指定了无效的选项则失败。 [for] 为列表中的每个成员执行命令。 @@ -1634,4 +1633,4 @@ unbindfaild = {$str1} : 无法解除绑定 invaildmap = {$str1} : 无效的键映射名 logout = 注销 stoppedjobs = 有停止的任务 -runjobs = 有运行中的任务 +runjobs = 有运行中的任务 \ No newline at end of file diff --git a/record.txt b/record.txt index 4568309..d05e2cd 100644 --- a/record.txt +++ b/record.txt @@ -119,3 +119,4 @@ 118 119 120 +121 -- Gitee