This commit is contained in:
mcolonna 2024-07-04 12:02:56 +02:00
commit 01722c4e21
16 changed files with 211 additions and 142 deletions

View file

@ -6,7 +6,7 @@
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */
/* Updated: 2024/07/04 11:48:47 by mcolonna ### ########.fr */
/* Updated: 2024/07/04 12:02:43 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,25 +15,29 @@
# include "include.h"
// for the 'std' parameter in all these functions:
// - std[0] is stdin
// - std[1] is stdout
// Check if the command is a builtin.
bool is_builtin(const char *str);
// Execute the builtin command
int exec_builtin(t_env *env, t_call call);
int exec_builtin(t_env *env, t_call call, int std[2]);
// Execute echo builtin
int echo_builtin(t_env *env, t_call call);
int echo_builtin(t_env *env, t_call call, int std[2]);
// Execute cd builtin
int cd_builtin(t_env *env, t_call call);
int cd_builtin(t_env *env, t_call call, int std[2]);
// Execute export builtin with no arguments
int export_print_builtin(t_env *env, t_call call);
int export_print_builtin(t_env *env, t_call call, int std[2]);
// Execute export builtin
int export_builtin(t_env *env, t_call call);
int export_builtin(t_env *env, t_call call, int std[2]);
// Execute exit builtin
int exit_builtin(t_env *env, t_call call);
int exit_builtin(t_env *env, t_call call, int std[2]);
#endif

View file

@ -6,7 +6,7 @@
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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
{
t_memclass mc_global; // open during all the runtime
t_memclass mc_command; // open during the execution of a command
int errorstatus; // Error status of the last executed command
t_list *variables; // Shell variables
bool exit; // Set to true to exit minishell
t_memclass mc_global;
t_memclass mc_command;
int errorstatus;
t_list *variables;
bool exit;
} t_env;
#endif

View file

@ -6,7 +6,7 @@
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)
typedef struct s_call
{
const char *program; // path of the program to call.
int argc; // number of arguments given
char *const *argv; // arguments given (ended by NULL)
// (argc and argv must include the program name)
const char *program;
int argc;
char *const *argv;
} t_call;
// Represents a command given by the user.
typedef struct s_command
{
int error; // 0 if parse_command() succeded, error status if not
bool empty; // true if there isn't anything to do
const t_call *calls; // all calls to programs (ended by .program == NULL)
int input_fd; // fd to use with '<' redirection (0 by default)
int output_fd; // fd to use with '>' redirection (1 by default)
int error;
bool empty;
const t_call *calls;
int input_fd;
int output_fd;
} t_command;
// An element of a list of 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;
// Return the t_command representing the command given by the user.

View file

@ -6,13 +6,16 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/27 13:43:21 by mcolonna #+# #+# */
/* Updated: 2024/06/28 14:22:50 by mcolonna ### ########.fr */
/* Updated: 2024/07/03 14:09:27 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef VARIABLES_H
# define VARIABLES_H
# define SYMBOL_CHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
_0123456789"
typedef struct s_variable
{
const char *name;
@ -36,4 +39,7 @@ void variables_unset(t_list *variables, const char *name);
// Get a envp of all exported variables.
char *const *variables_envp(t_list *variables, t_memclass mc);
// Return true if 'name' is a valid variable name.
bool variables_nameisvalid(const char *name);
#endif