aboutsummaryrefslogtreecommitdiffstats
path: root/src/lush.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lush.c')
-rw-r--r--src/lush.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/src/lush.c b/src/lush.c
index f851b2f..629c4b5 100644
--- a/src/lush.c
+++ b/src/lush.c
@@ -1084,21 +1084,28 @@ static int run_command_background(lua_State *L, char ***commands) {
int lush_execute_chain(lua_State *L, char ***commands, int num_commands) {
if (commands[0][0][0] == '\0') {
- return 1;
+ return 0;
}
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 && commands[1] != NULL) {
- int op_type = is_operator(commands[1][0]);
- if (op_type == OP_AND && last_result != 0) {
- commands += 2;
+ // Handle && operator
+ if (last_result != 0 && i > 0) {
+ commands--;
+ if (is_operator(commands[0][0]) == OP_AND) {
+ commands += 3;
continue;
- } else if (op_type == OP_PIPE) {
+ }
+ commands++;
+ }
+
+ // Handle other operations
+ if (commands[1] != NULL) {
+ int op_type = is_operator(commands[1][0]);
+ if (op_type == OP_PIPE) {
char ***pipe_commands =
malloc(sizeof(char **) * (num_actions - i));
int pipe_count = 0;
@@ -1131,13 +1138,13 @@ int lush_execute_chain(lua_State *L, char ***commands, int num_commands) {
commands += 2;
}
- return 1;
+ return 0;
}
int lush_execute_pipeline(char ***commands, int num_commands) {
// no command given
if (commands[0][0][0] == '\0') {
- return 1;
+ return 0;
}
// create pipes for each command
@@ -1173,7 +1180,7 @@ int lush_execute_pipeline(char ***commands, int num_commands) {
free(pipes[i]);
}
free(pipes);
- return 1;
+ return 0;
}
int lush_execute_command(char **args, int input_fd, int output_fd) {
@@ -1206,7 +1213,7 @@ int lush_execute_command(char **args, int input_fd, int output_fd) {
// execute the command
if (execvp(args[0], args) == -1) {
perror("execvp");
- printf("%s\n", args[0]);
+ printf("the file: %s\n", args[0]);
exit(EXIT_FAILURE);
}
} else if (pid < 0) {
@@ -1229,7 +1236,7 @@ int lush_execute_command(char **args, int input_fd, int output_fd) {
int lush_run(lua_State *L, char ***commands, int num_commands) {
if (commands[0][0] == NULL) {
// no command given
- return 1;
+ return 0;
}
return lush_execute_chain(L, commands, num_commands);
@@ -1268,7 +1275,7 @@ int main(int argc, char *argv[]) {
if (status == -1) {
fprintf(stderr, "lush: Expected end of quoted string\n");
- } else if (lush_run(L, args, status) == 0) {
+ } else if (lush_run(L, args, status) != 0) {
exit(1);
}
@@ -1317,10 +1324,13 @@ int main(int argc, char *argv[]) {
}
char *expanded_line = lush_resolve_aliases(line);
char **commands = lush_split_commands(expanded_line);
+ for (int i = 0; commands[i] != NULL; i++) {
+ printf("Command %d: '%s'\n", i, commands[i]);
+ }
char ***args = lush_split_args(commands, &status);
if (status == -1) {
fprintf(stderr, "lush: Expected end of quoted string\n");
- } else if (lush_run(L, args, status) == 0) {
+ } else if (lush_run(L, args, status) != 0) {
exit(1);
}
13' height='13' alt='Gravatar' /> Christoph Lohmann 1-0/+3 2015-01-19Add plumbing functionality.Gravatar Christoph Lohmann 2-2/+28 2015-01-18Add a comment about how the styles are iterated.Gravatar Christoph Lohmann 1-0/+4 Thanks quing for noticing. 2015-01-18My CMD was too short. :OGravatar Christoph Lohmann 1-1/+1 Thanks Carlos Torres for mentioning this. 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 This is a merge of the patch of Ben Woolley <tautolog@gmail.com> 2015-01-17Fix extra newline, and add -g where other switches are forwarded.Gravatar Ben Woolley 1-1/+3 Signed-off-by: Christoph Lohmann <20h@r-36.net> 2015-01-17Newer libc want _DEFAULT_SOURCE.Gravatar Christoph Lohmann 1-1/+1 2015-01-17Major styles update.Gravatar Christoph Lohmann 3-11/+84 In config.h there is now some styles array to apply site-specific styles. This can be toggled using the -mM flags. If a stylefile is manually specified, then this will overwrite everything. 2015-01-02Fix a typo in surf manual.Gravatar Jakukyo Friel 1-1/+1 `Ctrl-/` displays incorrectly in `man surf` on my machine. A patch is attached. (You also access it here: https://github.com/weakish/surf/commit/07e97eccedd96eabf14b2fbf77de75ec1b594d97) ---- surf.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Signed-off-by: Christoph Lohmann <20h@r-36.net> 2014-09-28Minor style change.Gravatar Christoph Lohmann 1-1/+1 2014-09-28Make »Copy image address« work.Gravatar Christoph Lohmann 1-3/+10 Thanks yui@blekksprut.net for the patch! 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 Something was missing from this one sentence. Now it is complete.