This commit is contained in:
mcolonna 2024-07-01 11:23:31 +02:00
parent 0bcb738496
commit 147743058d
4 changed files with 29 additions and 28 deletions

View file

@ -6,7 +6,7 @@
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */ /* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */ /* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */
/* Updated: 2024/06/28 14:01:25 by mcolonna ### ########.fr */ /* Updated: 2024/07/01 11:12:51 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,11 +17,11 @@
typedef struct s_env typedef struct s_env
{ {
t_memclass mc_global; // open during all the runtime t_memclass mc_global;
t_memclass mc_command; // open during the execution of a command t_memclass mc_command;
int errorstatus; // Error status of the last executed command int errorstatus;
t_list *variables; // Shell variables t_list *variables;
bool exit; // Set to true to exit minishell bool exit;
} t_env; } t_env;
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */ /* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */ /* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */
/* Updated: 2024/06/27 13:47:56 by mcolonna ### ########.fr */ /* Updated: 2024/07/01 11:16:02 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,26 +18,25 @@
// Represents a call to a program (the program name and its arguments) // Represents a call to a program (the program name and its arguments)
typedef struct s_call typedef struct s_call
{ {
const char *program; // path of the program to call. const char *program;
int argc; // number of arguments given int argc;
char *const *argv; // arguments given (ended by NULL) char *const *argv;
// (argc and argv must include the program name)
} t_call; } t_call;
// Represents a command given by the user. // Represents a command given by the user.
typedef struct s_command typedef struct s_command
{ {
int error; // 0 if parse_command() succeded, error status if not int error;
bool empty; // true if there isn't anything to do bool empty;
const t_call *calls; // all calls to programs (ended by .program == NULL) const t_call *calls;
int input_fd; // fd to use with '<' redirection (0 by default) int input_fd;
int output_fd; // fd to use with '>' redirection (1 by default) int output_fd;
} t_command; } t_command;
// An element of a list of pipes // An element of a list of pipes
typedef struct s_pipes typedef struct s_pipes
{ {
int pipe[2]; // Simple pipe, we write on pipe[1] and we read on pipe[0] int pipe[2];
} t_pipes; } t_pipes;
// Return the t_command representing the command given by the user. // Return the t_command representing the command given by the user.

View file

@ -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/27 14:47:14 by mcolonna ### ########.fr */ /* Updated: 2024/07/01 11:15:33 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,13 +20,13 @@
// Global variables for all the parsing functions // Global variables for all the parsing functions
typedef struct s_parsing_args typedef struct s_parsing_args
{ {
t_memclass mc; // mc freed given to parse_command t_memclass mc;
t_command r; // t_command that parse_command will return t_command r;
t_stream stream; // stream reading the command string t_stream stream;
t_list calls; // list of calls t_list calls;
bool got_first_call; // already got at least the first program call? bool got_first_call;
const char *heredoc; // EOF line for heredoc. NULL if no heredoc const char *heredoc;
t_list *variables; // list of current variables t_list *variables;
t_env *env; t_env *env;
} t_parsing_args; } t_parsing_args;

View file

@ -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/28 14:33:14 by mcolonna ### ########.fr */ /* Updated: 2024/07/01 13:38:03 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,8 +15,10 @@
void variables_set(t_list *variables, const char *name, const char *value) void variables_set(t_list *variables, const char *name, const char *value)
{ {
variables_find(variables, name)->value = ( t_variable *var;
str_dup(fatal_error, variables->mc, value));
var = variables_find(variables, name);
var->value = str_dup(fatal_error, variables->mc, value);
} }
const char *variables_get(t_list *variables, const char *name) const char *variables_get(t_list *variables, const char *name)