From 11ed818147717b2d2b7f00261244c1e386d3c7c2 Mon Sep 17 00:00:00 2001 From: wangmengc Date: Wed, 25 Oct 2023 10:47:43 +0800 Subject: [PATCH] add execute if command function --- bash-5.1/r_execute_cmd/src/lib.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/bash-5.1/r_execute_cmd/src/lib.rs b/bash-5.1/r_execute_cmd/src/lib.rs index 69d7d32..c729637 100644 --- a/bash-5.1/r_execute_cmd/src/lib.rs +++ b/bash-5.1/r_execute_cmd/src/lib.rs @@ -3624,6 +3624,35 @@ unsafe extern "C" fn execute_while_or_until( return body_status; } +unsafe extern "C" fn execute_if_command(mut if_command: *mut IF_COM) -> libc::c_int { + let mut return_value: libc::c_int = 0; + let mut save_line_number: libc::c_int = 0; + + save_line_number = line_number; + (*(*if_command).test).flags |= CMD_IGNORE_RETURN as libc::c_int; + return_value = execute_command((*if_command).test); + line_number = save_line_number; + if return_value == EXECUTION_SUCCESS as libc::c_int { + QUIT!(); + + if !((*if_command).true_case).is_null() + && (*if_command).flags & CMD_IGNORE_RETURN as libc::c_int != 0 + { + (*(*if_command).true_case).flags |= CMD_IGNORE_RETURN as libc::c_int; + } + return execute_command((*if_command).true_case); + } else { + QUIT!(); + + if !((*if_command).false_case).is_null() + && (*if_command).flags & CMD_IGNORE_RETURN as libc::c_int != 0 + { + (*(*if_command).false_case).flags |= CMD_IGNORE_RETURN as libc::c_int; + } + + return execute_command((*if_command).false_case); + }; +} -- Gitee