diff --git a/src/commands.c b/src/commands.c index 37b3c5c824919fecbb6c8f399750173439fd7c17..db5cc984351aaa6e5d038a84691e8809e357de56 100644 --- a/src/commands.c +++ b/src/commands.c @@ -45,17 +45,16 @@ static int is_built_in_command(const char* command_name) */ int evaluate_command(int n_commands, struct single_command (*commands)[512], struct pidStorage *ps) { - int ti, status, i, j, n; + int ti, status, i, j, n, re_i; pid_t p_id; char tmp_path[PATH_MAX]; struct aliased_command** aliased_commands; ti = 0; - + while (n_commands > ti) { struct single_command* com = (*commands) + ti++; - assert(com->argc != 0); - + n = get_no_alias(); aliased_commands = get_aliased_commands(); @@ -89,7 +88,9 @@ int evaluate_command(int n_commands, struct single_command (*commands)[512], str ps->pid_arr[ps->arr_i][ps->arr_n++] = p_id; } } else { - return exute_command(com, tmp_path, ps); + re_i = exute_command(com, tmp_path, ps); + if(re_i) + return re_i; } } return 0; diff --git a/src/utils.c b/src/utils.c index 0d1d66f0656246e6c1c4431d2368ff929b781326..8e9443dfd5142c3f0a308eeb217d846c0c6aff0c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -19,10 +19,11 @@ void mysh_parse_command(const char* command, while (tok != NULL) { struct single_command* com = *commands + ti; parse_single_command(tok, &com->argc, &com->argv); - + ++ti; - + tok = strtok_r(NULL, "|", &saveptr); + } *n_commands = ti; @@ -46,7 +47,13 @@ void parse_single_command(const char* command, flag = 0; point = command[command_i++]; - while(point != '\n'){ + while(1){ + if(point == '\n' || point == '\0') + break; + else if(buf_i == 0 && point == ' '){ + point = command[command_i++]; + continue; + } buf[buf_i++] = point; if(!flag && point == ' '){