From abb6efb3c5835ec0b497cb2d4a7d2b1b8302e485 Mon Sep 17 00:00:00 2001 From: mengfansheng Date: Wed, 22 May 2024 09:55:32 +0800 Subject: [PATCH] add print_assoc_assignment --- utshell-0.5/r_arrayfunc/src/lib.rs | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/utshell-0.5/r_arrayfunc/src/lib.rs b/utshell-0.5/r_arrayfunc/src/lib.rs index 415341d7..af10d003 100644 --- a/utshell-0.5/r_arrayfunc/src/lib.rs +++ b/utshell-0.5/r_arrayfunc/src/lib.rs @@ -1851,4 +1851,60 @@ pub unsafe extern "C" fn unbind_array_element( } return 0 as libc::c_int; +} + +/* Format and output an array assignment in compound form VAR=(VALUES), +suitable for re-use as input. */ +#[no_mangle] +pub unsafe extern "C" fn print_array_assignment(mut var: *mut SHELL_VAR, mut quoted: libc::c_int) { + let mut vstr: *mut libc::c_char = 0 as *mut libc::c_char; + + vstr = array_to_assign(array_cell!(var), quoted); + + if vstr.is_null() { + printf( + b"%s=%s\n\0" as *const u8 as *const libc::c_char, + (*var).name, + if quoted != 0 { + b"'()'\0" as *const u8 as *const libc::c_char + } else { + b"()\0" as *const u8 as *const libc::c_char + }, + ); + } else { + printf( + b"%s=%s\n\0" as *const u8 as *const libc::c_char, + (*var).name, + vstr, + ); + libc::free(vstr as *mut libc::c_void); + }; +} + +/* Format and output an associative array assignment in compound form +VAR=(VALUES), suitable for re-use as input. */ +#[no_mangle] +pub unsafe extern "C" fn print_assoc_assignment(mut var: *mut SHELL_VAR, mut quoted: libc::c_int) { + let mut vstr: *mut libc::c_char = 0 as *mut libc::c_char; + + vstr = assoc_to_assign(assoc_cell!(var), quoted); + + if vstr.is_null() { + printf( + b"%s=%s\n\0" as *const u8 as *const libc::c_char, + (*var).name, + if quoted != 0 { + b"'()'\0" as *const u8 as *const libc::c_char + } else { + b"()\0" as *const u8 as *const libc::c_char + }, + ); + } else { + printf( + b"%s=%s\n\0" as *const u8 as *const libc::c_char, + (*var).name, + vstr, + ); + libc::free(vstr as *mut libc::c_void); + }; } \ No newline at end of file -- Gitee