From 832f2812e5c66125ce801dd9de1a0714f80d1d84 Mon Sep 17 00:00:00 2001 From: wangmengc Date: Mon, 30 Oct 2023 17:48:10 +0800 Subject: [PATCH] add GET_ARRAY_FROM_VAR macro array_cell macro array_pop macro maybe restore getopt state function --- bash-5.1/r_execute_cmd/src/lib.rs | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/bash-5.1/r_execute_cmd/src/lib.rs b/bash-5.1/r_execute_cmd/src/lib.rs index 572d096..8e2aa19 100644 --- a/bash-5.1/r_execute_cmd/src/lib.rs +++ b/bash-5.1/r_execute_cmd/src/lib.rs @@ -5054,8 +5054,41 @@ unsafe extern "C" fn execute_builtin( return result; } +unsafe extern "C" fn maybe_restore_getopt_state(mut gs: *mut sh_getopt_state_t) { + if (*gs).gs_flags & 1 != 0 { + sh_getopt_restore_istate(gs); + } else { + free(gs as *mut c_void); + }; +} +#[macro_export] +macro_rules! array_pop { + ($a:expr) => { + array_dispose_element( + array_shift(($a), 1 , 0 ), + ); + }; +} +#[macro_export] +macro_rules! array_cell { + ($var:expr) => { + (*$var).value as *mut ARRAY + }; +} + +#[macro_export] +macro_rules! GET_ARRAY_FROM_VAR { + ($n:expr, $v:expr, $a:expr) => { + $v = find_variable($n); + $a = if !$v.is_null() && array_p!($v) != 0 { + array_cell!($v) + } else { + 0 as *mut ARRAY + } + }; +} -- Gitee