aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar BanceDev 2024-09-25 18:37:06 -0400
committerGravatar BanceDev 2024-09-25 18:37:06 -0400
commiteda09a981f0dd3a1fb56dfe7a6ac62bd062a491f (patch)
treef5e3a83f9de0fdb6d16b6fffd5ba590e765dae5e /src
parentv0.2.0 (diff)
fixed semicolon chaining functionality
Diffstat (limited to '')
-rw-r--r--src/lush.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/lush.c b/src/lush.c
index 6a3892f..c3bd831 100644
--- a/src/lush.c
+++ b/src/lush.c
@@ -867,27 +867,20 @@ static int is_operator(const char *str) {
}
static int operator_length(const char *str) {
- const char *operators[] = {"||", "&&", ">>", ">", "<", "&", ";", "|"};
+ const char *operators[] = {"||", "&&", ">>", ">", "&", ";", "|"};
int num_operators = sizeof(operators) / sizeof(operators[0]);
for (int i = 0; i < num_operators; i++) {
if (strncmp(str, operators[i], strlen(operators[i])) == 0) {
switch (i) {
case 0:
- return 2;
case 1:
- return 2;
case 2:
return 2;
case 3:
- return 1;
case 4:
- return 1;
case 5:
- return 1;
case 6:
return 1;
- case 7:
- return 1;
default:
return 0;
}
@@ -1133,19 +1126,21 @@ int lush_execute_chain(lua_State *L, char ***commands, int num_commands) {
int last_result = 0;
for (int i = 0; i < num_actions; i++) {
+ // Handle ; operator
+ if (is_operator(commands[0][0]) == OP_SEMICOLON) {
+ commands++;
+ }
- // Handle &&, ||, and ; operators
+ // Handle && and || operators
if (i > 0) {
commands--;
if (last_result != 0) {
- if (is_operator(commands[0][0]) == OP_AND ||
- is_operator(commands[0][0]) == OP_SEMICOLON) {
+ if (is_operator(commands[0][0]) == OP_AND) {
commands += 3;
continue;
}
- } else if (last_result == 0) {
- if (is_operator(commands[0][0]) == OP_OR ||
- is_operator(commands[0][0]) == OP_SEMICOLON) {
+ } else {
+ if (is_operator(commands[0][0]) == OP_OR) {
commands += 3;
continue;
}