From cc9ed05a5287c109e527d3ca5eb3c943aa9aa3ce Mon Sep 17 00:00:00 2001 From: wangmengc Date: Wed, 25 Oct 2023 10:46:47 +0800 Subject: [PATCH] CMD_WHILE macro,execute while command function,CMD_UNTIL macro,execute until command function,execute while or until function --- bash-5.1/r_execute_cmd/src/lib.rs | 81 +++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/bash-5.1/r_execute_cmd/src/lib.rs b/bash-5.1/r_execute_cmd/src/lib.rs index ba0e15e..69d7d32 100644 --- a/bash-5.1/r_execute_cmd/src/lib.rs +++ b/bash-5.1/r_execute_cmd/src/lib.rs @@ -3541,8 +3541,89 @@ unsafe extern "C" fn execute_case_command( return retval; } +#[macro_export] +macro_rules! CMD_WHILE { + () => { + 0 + }; +} + +unsafe extern "C" fn execute_while_command( + mut while_command: *mut WHILE_COM, +) -> libc::c_int { + return execute_while_or_until(while_command, CMD_WHILE!()); +} + +#[macro_export] +macro_rules! CMD_UNTIL { + () => { + 1 + }; +} + +unsafe extern "C" fn execute_until_command( + mut while_command: *mut WHILE_COM, +) -> libc::c_int { + return execute_while_or_until(while_command, CMD_UNTIL!()); +} + +unsafe extern "C" fn execute_while_or_until( + mut while_command: *mut WHILE_COM, + mut type_0: libc::c_int, +) -> libc::c_int { + let mut return_value: libc::c_int = 0; + let mut body_status: libc::c_int = 0; + + body_status = EXECUTION_SUCCESS as libc::c_int; + loop_level += 1; + (*(*while_command).test).flags |= CMD_IGNORE_RETURN as libc::c_int; + if (*while_command).flags & CMD_IGNORE_RETURN as libc::c_int != 0 { + (*(*while_command).action).flags |= CMD_IGNORE_RETURN as libc::c_int; + } + + loop { + return_value = execute_command((*while_command).test); + REAP!(); + + if type_0 == CMD_WHILE!() && return_value != EXECUTION_SUCCESS as libc::c_int { + if breaking != 0 { + breaking -= 1; + } + if continuing != 0 { + continuing -= 1; + } + break; + } else if type_0 == CMD_UNTIL!() && return_value == EXECUTION_SUCCESS as libc::c_int { + if breaking != 0 { + breaking -= 1; + } + if continuing != 0 { + continuing -= 1; + } + break; + } else { + QUIT!(); + body_status = execute_command((*while_command).action); + QUIT!(); + if breaking != 0 { + breaking -= 1; + break; + } else { + if !(continuing != 0) { + continue; + } + continuing -= 1; + if continuing != 0 { + break; + } + } + } + } + loop_level -= 1; + return body_status; +} -- Gitee