summaryrefslogtreecommitdiff
path: root/core/src/xmake/process
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-10 21:00:21 +0800
committerruki <[email protected]>2025-11-10 21:00:21 +0800
commit2c387895657ae13cd717d7f42f5baed5eb028a8e (patch)
tree8f005a8dfc3272e9f027560e5e1b5881a7a8bc70 /core/src/xmake/process
parent831447a51da0b094e08bb047247bf269a6e6cf71 (diff)
format more if-else codes in core
Diffstat (limited to 'core/src/xmake/process')
-rw-r--r--core/src/xmake/process/close.c3
-rw-r--r--core/src/xmake/process/kill.c3
-rw-r--r--core/src/xmake/process/open.c15
-rw-r--r--core/src/xmake/process/openv.c27
4 files changed, 30 insertions, 18 deletions
diff --git a/core/src/xmake/process/close.c b/core/src/xmake/process/close.c
index fc57453e6..bd39d49ee 100644
--- a/core/src/xmake/process/close.c
+++ b/core/src/xmake/process/close.c
@@ -39,8 +39,9 @@ tb_int_t xm_process_close(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
// is pointer?
- if (!xm_lua_ispointer(lua, 1))
+ if (!xm_lua_ispointer(lua, 1)) {
return 0;
+ }
// get the process
tb_process_ref_t process = (tb_process_ref_t)xm_lua_topointer(lua, 1);
diff --git a/core/src/xmake/process/kill.c b/core/src/xmake/process/kill.c
index 4859027b4..21cc68149 100644
--- a/core/src/xmake/process/kill.c
+++ b/core/src/xmake/process/kill.c
@@ -39,8 +39,9 @@ tb_int_t xm_process_kill(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
// is pointer?
- if (!xm_lua_ispointer(lua, 1))
+ if (!xm_lua_ispointer(lua, 1)) {
return 0;
+ }
// get the process
tb_process_ref_t process = (tb_process_ref_t)xm_lua_topointer(lua, 1);
diff --git a/core/src/xmake/process/open.c b/core/src/xmake/process/open.c
index f0885719a..669e90ff1 100644
--- a/core/src/xmake/process/open.c
+++ b/core/src/xmake/process/open.c
@@ -68,8 +68,9 @@ tb_int_t xm_process_open(lua_State *lua) {
// is detached?
lua_pushstring(lua, "detach");
lua_gettable(lua, 2);
- if (lua_toboolean(lua, -1))
+ if (lua_toboolean(lua, -1)) {
attr.flags |= TB_PROCESS_FLAG_DETACH;
+ }
lua_pop(lua, 1);
// get curdir
@@ -161,9 +162,9 @@ tb_int_t xm_process_open(lua_State *lua) {
// is string?
if (lua_isstring(lua, -1)) {
// add this environment value
- if (envn + 1 < tb_arrayn(envs))
+ if (envn + 1 < tb_arrayn(envs)) {
envs[envn++] = lua_tostring(lua, -1);
- else {
+ } else {
// error
lua_pushfstring(lua,
"envs is too large(%d > %d) for process.openv",
@@ -239,14 +240,16 @@ tb_int_t xm_process_open(lua_State *lua) {
}
// set the new environments
- if (envn > 0)
+ if (envn > 0) {
attr.envp = envs;
+ }
// init process
tb_process_ref_t process = (tb_process_ref_t)tb_process_init_cmd(command, &attr);
- if (process)
+ if (process) {
xm_lua_pushpointer(lua, (tb_pointer_t)process);
- else
+ } else {
lua_pushnil(lua);
+ }
return 1;
}
diff --git a/core/src/xmake/process/openv.c b/core/src/xmake/process/openv.c
index 99a6133d0..1b95c45fe 100644
--- a/core/src/xmake/process/openv.c
+++ b/core/src/xmake/process/openv.c
@@ -117,15 +117,17 @@ tb_int_t xm_process_openv(lua_State *lua) {
// is detached?
lua_pushstring(lua, "detach");
lua_gettable(lua, 3);
- if (lua_toboolean(lua, -1))
+ if (lua_toboolean(lua, -1)) {
attr.flags |= TB_PROCESS_FLAG_DETACH;
+ }
lua_pop(lua, 1);
// is exclusive?
lua_pushstring(lua, "exclusive");
lua_gettable(lua, 3);
- if (lua_toboolean(lua, -1))
+ if (lua_toboolean(lua, -1)) {
exclusive = tb_true;
+ }
lua_pop(lua, 1);
// get curdir
@@ -217,9 +219,9 @@ tb_int_t xm_process_openv(lua_State *lua) {
// is string?
if (lua_isstring(lua, -1)) {
// add this environment value
- if (envn + 1 < tb_arrayn(envs))
+ if (envn + 1 < tb_arrayn(envs)) {
envs[envn++] = lua_tostring(lua, -1);
- else {
+ } else {
// error
lua_pushfstring(lua,
"envs is too large(%d > %d) for process.openv",
@@ -295,31 +297,36 @@ tb_int_t xm_process_openv(lua_State *lua) {
}
// set the new environments
- if (envn > 0)
+ if (envn > 0) {
attr.envp = envs;
+ }
/* we need to ignore SIGINT and SIGQUIT if we enter exclusive mode
* @see https://github.com/xmake-io/xmake/discussions/2893
*/
#if defined(SIGINT)
- if (exclusive)
+ if (exclusive) {
signal(SIGINT, SIG_IGN);
+ }
#endif
#if defined(SIGQUIT)
- if (exclusive)
+ if (exclusive) {
signal(SIGQUIT, SIG_IGN);
+ }
#endif
// init process
tb_process_ref_t process = (tb_process_ref_t)tb_process_init(shellname, argv, &attr);
- if (process)
+ if (process) {
xm_lua_pushpointer(lua, (tb_pointer_t)process);
- else
+ } else {
lua_pushnil(lua);
+ }
// exit argv
- if (argv)
+ if (argv) {
tb_free(argv);
+ }
argv = tb_null;
return 1;