diff --git a/dev/TODO b/dev/TODO index 1ae3568..d5619bb 100644 --- a/dev/TODO +++ b/dev/TODO @@ -1,9 +1,6 @@ - finding commands - built-in commands -- signals - - ^C, ^D, ^\ - variables - - $? - uses $PATH in env.variables instead of envp - builtins: - echo (with option -n) @@ -17,6 +14,7 @@ - empty variables aren't freed - need to free value returned by readline - the builtins should get all arguments and check if they're good + - command `echo "hello` with unclosed quotes (unnecessary part) - working history (rl_* functions?) diff --git a/src/exec_command.c b/src/exec_command.c index b6b4f8a..92a2205 100644 --- a/src/exec_command.c +++ b/src/exec_command.c @@ -6,7 +6,7 @@ /* By: jschaft +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/24 13:48:00 by jschaft #+# #+# */ -/* Updated: 2024/06/13 13:56:21 by mcolonna ### ########.fr */ +/* Updated: 2024/06/21 15:57:28 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -118,6 +118,7 @@ int execute_command(t_env *env, t_command command) t_exec_command_global global; int r; + r = 0; global.mc = env->mc_command; global.nb_calls = 0; while (command.calls[global.nb_calls].program != NULL) @@ -127,11 +128,11 @@ int execute_command(t_env *env, t_command command) r = create_pipes(&global, command); if (r) return (r); - exec_each_call(&global, command, env->envp); + r = exec_each_call(&global, command, env->envp); close_all_pipes(&global); while (wait(NULL) != -1) ; if (errno != ECHILD) return (minishell_error("errno"), errno); - return (0); + return (r); } diff --git a/src/main.c b/src/main.c index b11222c..4040605 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: jschaft +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/23 14:33:45 by mcolonna #+# #+# */ -/* Updated: 2024/06/21 14:44:16 by mcolonna ### ########.fr */ +/* Updated: 2024/06/21 15:48:48 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,7 +66,7 @@ static void prompt_command(t_env *env) else { add_history(command_str); - do_command(env, command_str); + env->errorstatus = do_command(env, command_str); } mem_freeall(env->mc_command); env->mc_command = NULL; diff --git a/src/parse_command.c b/src/parse_command.c index 99710fa..d552ca3 100644 --- a/src/parse_command.c +++ b/src/parse_command.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/24 13:47:40 by mcolonna #+# #+# */ -/* Updated: 2024/06/18 13:41:04 by mcolonna ### ########.fr */ +/* Updated: 2024/06/21 15:44:51 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -99,6 +99,7 @@ typedef struct s_parsing_args bool got_first_call; // already got at least the first program call? const char *heredoc; // EOF line for heredoc. NULL if no heredoc t_list *variables; // list of current variables + t_env *env; } t_parsing_args; // Skip blank characters @@ -150,17 +151,27 @@ static void read_variable_value(t_parsing_args *args, const char **dest) const char *value; const char *tmp; - name = str_dup(fatal_error, args->mc, ""); - read_only(args, &name, SYMBOL_CHARS); - if (str_eq(name, "")) + name = NULL; + tmp = NULL; + if (stream_read(&args->stream) == '?') { - args->r.error = parse_error("variable name expected"); - return ; + stream_pop(&args->stream); + value = str_inttostr(fatal_error, args->mc, args->env->errorstatus); + } + else + { + name = str_dup(fatal_error, args->mc, ""); + read_only(args, &name, SYMBOL_CHARS); + if (str_eq(name, "")) + { + args->r.error = parse_error("variable name expected"); + return ; + } + value = variables_get(args->variables, name); } - value = variables_get(args->variables, name); - mem_free((char *)name); tmp = *dest; *dest = str_join(fatal_error, args->mc, *dest, value); + mem_free((char *)name); mem_free((char *)tmp); } @@ -443,7 +454,7 @@ static void read_command(t_parsing_args *args) // Create a t_parsing_args shared between all the parse_command subfunctions. // Define every fields but .stream -static t_parsing_args init_parsing_args(const t_memclass mc, +static t_parsing_args init_parsing_args(t_env *env, const t_memclass mc, t_list *variables) { const t_parsing_args r = { @@ -458,6 +469,7 @@ static t_parsing_args init_parsing_args(const t_memclass mc, .got_first_call = false, .heredoc = NULL, .variables = variables, + .env = env, }; return (r); @@ -473,7 +485,7 @@ t_command parse_command(t_env *env, const char *command) { t_parsing_args args; - args = init_parsing_args(env->mc_command, env->variables); + args = init_parsing_args(env, env->mc_command, env->variables); if (parse_variable_set_command(&args, command, env->variables)) { args.r.empty = true;