[ADD] $?
This commit is contained in:
parent
92759513e8
commit
1091ddf32f
4 changed files with 29 additions and 18 deletions
4
dev/TODO
4
dev/TODO
|
@ -1,9 +1,6 @@
|
||||||
- finding commands
|
- finding commands
|
||||||
- built-in commands
|
- built-in commands
|
||||||
- signals
|
|
||||||
- ^C, ^D, ^\
|
|
||||||
- variables
|
- variables
|
||||||
- $?
|
|
||||||
- uses $PATH in env.variables instead of envp
|
- uses $PATH in env.variables instead of envp
|
||||||
- builtins:
|
- builtins:
|
||||||
- echo (with option -n)
|
- echo (with option -n)
|
||||||
|
@ -17,6 +14,7 @@
|
||||||
- empty variables aren't freed
|
- empty variables aren't freed
|
||||||
- need to free value returned by readline
|
- need to free value returned by readline
|
||||||
- the builtins should get all arguments and check if they're good
|
- the builtins should get all arguments and check if they're good
|
||||||
|
- command `echo "hello` with unclosed quotes
|
||||||
|
|
||||||
(unnecessary part)
|
(unnecessary part)
|
||||||
- working history (rl_* functions?)
|
- working history (rl_* functions?)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/24 13:48:00 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;
|
t_exec_command_global global;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
r = 0;
|
||||||
global.mc = env->mc_command;
|
global.mc = env->mc_command;
|
||||||
global.nb_calls = 0;
|
global.nb_calls = 0;
|
||||||
while (command.calls[global.nb_calls].program != NULL)
|
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);
|
r = create_pipes(&global, command);
|
||||||
if (r)
|
if (r)
|
||||||
return (r);
|
return (r);
|
||||||
exec_each_call(&global, command, env->envp);
|
r = exec_each_call(&global, command, env->envp);
|
||||||
close_all_pipes(&global);
|
close_all_pipes(&global);
|
||||||
while (wait(NULL) != -1)
|
while (wait(NULL) != -1)
|
||||||
;
|
;
|
||||||
if (errno != ECHILD)
|
if (errno != ECHILD)
|
||||||
return (minishell_error("errno"), errno);
|
return (minishell_error("errno"), errno);
|
||||||
return (0);
|
return (r);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/23 14:33:45 by mcolonna #+# #+# */
|
/* 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
|
else
|
||||||
{
|
{
|
||||||
add_history(command_str);
|
add_history(command_str);
|
||||||
do_command(env, command_str);
|
env->errorstatus = do_command(env, command_str);
|
||||||
}
|
}
|
||||||
mem_freeall(env->mc_command);
|
mem_freeall(env->mc_command);
|
||||||
env->mc_command = NULL;
|
env->mc_command = NULL;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/24 13:47:40 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?
|
bool got_first_call; // already got at least the first program call?
|
||||||
const char *heredoc; // EOF line for heredoc. NULL if no heredoc
|
const char *heredoc; // EOF line for heredoc. NULL if no heredoc
|
||||||
t_list *variables; // list of current variables
|
t_list *variables; // list of current variables
|
||||||
|
t_env *env;
|
||||||
} t_parsing_args;
|
} t_parsing_args;
|
||||||
|
|
||||||
// Skip blank characters
|
// Skip blank characters
|
||||||
|
@ -150,17 +151,27 @@ static void read_variable_value(t_parsing_args *args, const char **dest)
|
||||||
const char *value;
|
const char *value;
|
||||||
const char *tmp;
|
const char *tmp;
|
||||||
|
|
||||||
name = str_dup(fatal_error, args->mc, "");
|
name = NULL;
|
||||||
read_only(args, &name, SYMBOL_CHARS);
|
tmp = NULL;
|
||||||
if (str_eq(name, ""))
|
if (stream_read(&args->stream) == '?')
|
||||||
{
|
{
|
||||||
args->r.error = parse_error("variable name expected");
|
stream_pop(&args->stream);
|
||||||
return ;
|
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;
|
tmp = *dest;
|
||||||
*dest = str_join(fatal_error, args->mc, *dest, value);
|
*dest = str_join(fatal_error, args->mc, *dest, value);
|
||||||
|
mem_free((char *)name);
|
||||||
mem_free((char *)tmp);
|
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.
|
// Create a t_parsing_args shared between all the parse_command subfunctions.
|
||||||
// Define every fields but .stream
|
// 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)
|
t_list *variables)
|
||||||
{
|
{
|
||||||
const t_parsing_args r = {
|
const t_parsing_args r = {
|
||||||
|
@ -458,6 +469,7 @@ static t_parsing_args init_parsing_args(const t_memclass mc,
|
||||||
.got_first_call = false,
|
.got_first_call = false,
|
||||||
.heredoc = NULL,
|
.heredoc = NULL,
|
||||||
.variables = variables,
|
.variables = variables,
|
||||||
|
.env = env,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (r);
|
return (r);
|
||||||
|
@ -473,7 +485,7 @@ t_command parse_command(t_env *env, const char *command)
|
||||||
{
|
{
|
||||||
t_parsing_args args;
|
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))
|
if (parse_variable_set_command(&args, command, env->variables))
|
||||||
{
|
{
|
||||||
args.r.empty = true;
|
args.r.empty = true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue