From 930c2b1e96df6e34d05b95d79be5d2450e742779 Mon Sep 17 00:00:00 2001 From: wangmengc Date: Wed, 18 Oct 2023 13:37:45 +0800 Subject: [PATCH] add eval arith for expr --- bash-5.1/r_execute_cmd/src/lib.rs | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/bash-5.1/r_execute_cmd/src/lib.rs b/bash-5.1/r_execute_cmd/src/lib.rs index 30a066b..400ffb3 100644 --- a/bash-5.1/r_execute_cmd/src/lib.rs +++ b/bash-5.1/r_execute_cmd/src/lib.rs @@ -2857,4 +2857,46 @@ unsafe extern "C" fn execute_for_command(mut for_command: *mut FOR_COM) -> libc: return retval; } +unsafe extern "C" fn eval_arith_for_expr( + mut l: *mut WordList, + mut okp: *mut libc::c_int, +) -> intmax_t { + let mut new: *mut WordList = 0 as *mut WordList; + let mut expresult: intmax_t = 0; + let mut r: libc::c_int = 0; + + new = expand_words_no_vars(l); + if !new.is_null() { + if echo_command_at_execute != 0 { + xtrace_print_arith_cmd(new); + } + + this_command_name = b"((\0" as *const u8 as *mut libc::c_char; + + command_string_index = 0 ; + print_arith_command(new); + if signal_in_progress(DEBUG_TRAP as libc::c_int) == 0 && running_trap == 0 + { + FREE!(the_printed_command_except_trap); + the_printed_command_except_trap = savestring!(the_printed_command); + } + r = run_debug_trap(); + if debugging_mode == 0 || r == EXECUTION_SUCCESS as libc::c_int { + expresult = evalexp((*(*new).word).word, EXP_EXPANDED as libc::c_int, okp); + } else { + expresult = 0 as intmax_t; + if !okp.is_null() { + *okp = 1 ; + } + } + + dispose_words(new); + } else { + expresult = 0 as intmax_t; + if !okp.is_null() { + *okp = 1 ; + } + } + return expresult; +} -- Gitee