From b910d7a165022a2c3831b0aa7e7b91092c6f8091 Mon Sep 17 00:00:00 2001 From: mengfansheng Date: Tue, 14 May 2024 10:12:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0convert=5Fvar=5Fto=5Farray?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utshell-0.5/r_arrayfunc/src/lib.rs | 43 +++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/utshell-0.5/r_arrayfunc/src/lib.rs b/utshell-0.5/r_arrayfunc/src/lib.rs index bf7de1eb..2e72b4de 100644 --- a/utshell-0.5/r_arrayfunc/src/lib.rs +++ b/utshell-0.5/r_arrayfunc/src/lib.rs @@ -478,4 +478,45 @@ pub static mut bash_badsub_errmsg: *const libc::c_char = /* **************************************************************** */ /* Convert a shell variable to an array variable. The original value is -saved as array[0]. */ \ No newline at end of file +saved as array[0]. */ +#[no_mangle] +pub unsafe extern "C" fn convert_var_to_array(mut var: *mut SHELL_VAR) -> *mut SHELL_VAR { + let mut oldval: *mut libc::c_char = 0 as *mut libc::c_char; + let mut array: *mut ARRAY = 0 as *mut ARRAY; + + oldval = value_cell!(var); + array = array_create(); + if !oldval.is_null() { + array_insert(array, 0 as libc::c_int as arrayind_t, oldval); + } + FREE!(value_cell!(var)); + var_setarray!(var, array); + + /* these aren't valid anymore */ + (*var).dynamic_value = ::core::mem::transmute::<*mut libc::c_void, Option>( + 0 as *mut libc::c_void, + ); + (*var).assign_func = ::core::mem::transmute::<*mut libc::c_void, Option>( + 0 as *mut libc::c_void, + ); + + INVALIDATE_EXPORTSTR!(var); + + if exported_p!(var) != 0 { + array_needs_making += 1; + array_needs_making; + } + + VSETATTR!(var, att_array); + if !oldval.is_null() { + VUNSETATTR!(var, att_invisible); + } + + /* Make sure it's not marked as an associative array any more */ + VUNSETATTR!(var, att_assoc); + + /* Since namerefs can't be array variables, turn off nameref attribute */ + VUNSETATTR!(var, att_nameref); + + return var; +} \ No newline at end of file -- Gitee