diff --git a/README.md b/README.md index 6d9379d..fd777c7 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Work is still in porgress, buf when you will see a "finished" topic assigned to * History of commands and navigation or search through it with `up/down` keys * Username, ip address and current path in prompt before each command input * Show previous command return status in prompt and invert it with `!`, separated with space, specified before it -* Running multiple commands separated by `;` +* Running multiple commands separated by `;`, `&&` or `||` # Builtin commands * `cd`: changes current working directory to the one specified by user. If no arguments provided, shows error. @@ -24,5 +24,4 @@ Work is still in porgress, buf when you will see a "finished" topic assigned to * Replace linux `echo` command with builtin one with support of environmental variables * Environmental variables * `Ctrl+Z` running programm with `fd` -* ~~Getting commands path from system `PATH` environment variable~~ -* Running multiple commands separated by `&&` and `||` with appropriate logic \ No newline at end of file +* ~~Getting commands path from system `PATH` environment variable~~ \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index f66be26..7e57d4a 100644 --- a/src/shell.c +++ b/src/shell.c @@ -47,6 +47,17 @@ void process_command() curr->stat.s = status; term.last_status = curr->stat.s; + if (curr->sep_next == AND_SEP) + { + if (term.last_status != 0) + break; + } + else if (curr->sep_next == OR_SEP) + { + if (term.last_status == 0) + break; + } + curr = curr->next; } @@ -110,14 +121,8 @@ int process_line(char *line, cmds_p **coms) append_to_str_arr(&(curr_cmd->args), &args_am, trim_string(tmp, false)); tmp += strlen(curr_cmd->args[args_am - 1]) + 1; } - else { + else tmp++; - } - if (tmp[0] == ' ') - { - tmp++; - i++; - } curr_cmd->args = realloc(curr_cmd->args, sizeof(char *) * (args_am + 1)); curr_cmd->args[args_am] = NULL; @@ -141,6 +146,12 @@ int process_line(char *line, cmds_p **coms) break; } + if (tmp[0] == ' ') + { + tmp++; + i++; + } + cmds_p *next = new_cmd(); curr_cmd->next = next;