From 6d0ff4d8db9700ca98675fb3816144801bc2b687 Mon Sep 17 00:00:00 2001 From: BanceDev Date: Mon, 23 Sep 2024 15:56:03 -0400 Subject: fixed operator chaining to handle commands terminating with an operator --- src/lush.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/lush.c b/src/lush.c index 3318807..f851b2f 100644 --- a/src/lush.c +++ b/src/lush.c @@ -1092,17 +1092,13 @@ int lush_execute_chain(lua_State *L, char ***commands, int num_commands) { for (int i = 0; i < num_actions; i++) { // Determine the operator type between commands - if (i < num_actions - 1) { + if (i < num_actions && commands[1] != NULL) { int op_type = is_operator(commands[1][0]); - // Handle '&&' operator if (op_type == OP_AND && last_result != 0) { commands += 2; continue; - } - - // Handle '|', build pipe array - if (op_type == OP_PIPE) { + } else if (op_type == OP_PIPE) { char ***pipe_commands = malloc(sizeof(char **) * (num_actions - i)); int pipe_count = 0; @@ -1124,20 +1120,15 @@ int lush_execute_chain(lua_State *L, char ***commands, int num_commands) { free(pipe_commands); commands += 2; continue; - } - // Handle '&' operator for background execution - if (op_type == OP_BACKGROUND) { - + } else if (op_type == OP_BACKGROUND) { run_command_background(L, commands); commands += 2; continue; } } - if (!is_operator(commands[0][0])) { - last_result = run_command(L, commands); - commands += 2; - } + last_result = run_command(L, commands); + commands += 2; } return 1; -- cgit v1.2.3-59-g8ed1b