aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lush.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/lush.c b/src/lush.c
index 9b43324..1cdb50d 100644
--- a/src/lush.c
+++ b/src/lush.c
@@ -1153,28 +1153,52 @@ int lush_execute_chain(lua_State *L, char ***commands, int num_commands) {
}
int num_actions = (num_commands + 1) / 2;
-
int last_result = 0;
+
for (int i = 0; i < num_actions; i++) {
// Determine the operator type between commands
if (i < num_actions - 1) {
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) {
+ char ***pipe_commands =
+ malloc(sizeof(char **) * (num_actions - i));
+ int pipe_count = 0;
+
+ while (i < num_actions - 1 && op_type == OP_PIPE) {
+ pipe_commands[pipe_count++] = commands[0];
+ commands += 2;
+ i++;
+ if (i < num_actions - 1) {
+ op_type = is_operator(commands[1][0]);
+ } else {
+ break;
+ }
+ }
+
+ pipe_commands[pipe_count++] = commands[0];
+ last_result = lush_execute_pipeline(pipe_commands, pipe_count);
+
+ free(pipe_commands);
+ commands += 2;
continue;
}
}
- // Execute the current command if it's not an operator
if (!is_operator(commands[0][0])) {
last_result = run_command(L, commands);
commands += 2;
}
}
- commands -= num_actions * 2;
- printf("sanity check, commands[0]: %s", commands[0][0]);
-
- return 1;
+ return last_result;
}
int lush_execute_pipeline(char ***commands, int num_commands) {
@@ -1355,10 +1379,6 @@ int main(int argc, char *argv[]) {
exit(1);
}
- for (int i = 0; commands[i] != NULL; i++) {
- printf("Command %d: '%s'\n", i, commands[i]);
- }
-
for (int i = 0; args[i]; i++) {
free(args[i]);
}
f/commit/surf.c?id=9333d5d72740b97d66df9bc4e3777d24c884c033&follow=1'>My CMD was too short. :OGravatar Christoph Lohmann 1-1/+1 2015-01-17Add the manpage changes for the disk cache support.Gravatar Christoph Lohmann 1-1/+7 2015-01-17Adding disk cache support for soup.Gravatar Christoph Lohmann 2-9/+40 2015-01-17Fix extra newline, and add -g where other switches are forwarded.Gravatar Ben Woolley 1-1/+3 2015-01-17Newer libc want _DEFAULT_SOURCE.Gravatar Christoph Lohmann 1-1/+1 2015-01-17Major styles update.Gravatar Christoph Lohmann 3-11/+84 2015-01-02Fix a typo in surf manual.Gravatar Jakukyo Friel 1-1/+1 2014-09-28Minor style change.Gravatar Christoph Lohmann 1-1/+1 2014-09-28Make »Copy image address« work.Gravatar Christoph Lohmann 1-3/+10 2014-08-07Mention xdotool in SEE ALSO too.Gravatar Christoph Lohmann 1-1/+2 2014-08-07Fix the manpage about xid.Gravatar Christoph Lohmann 1-1/+3