t_cmd => t_token (parce que c'est plus logique aussi)
This commit is contained in:
@ -6,13 +6,13 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/16 21:02:54 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/03/27 14:49:28 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/27 16:21:48 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int cd(t_cmd *args)
|
||||
int cd(t_token *args)
|
||||
{
|
||||
char *new_wd;
|
||||
|
||||
|
@ -6,16 +6,16 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/05 18:22:15 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/03/27 14:59:43 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/27 16:20:06 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int get_cmd_count(t_cmd *cmds)
|
||||
int get_cmd_count(t_token *cmds)
|
||||
{
|
||||
int count;
|
||||
t_cmd *cur_cmd;
|
||||
t_token *cur_cmd;
|
||||
|
||||
count = 0;
|
||||
cur_cmd = cmds;
|
||||
@ -31,10 +31,10 @@ int get_cmd_count(t_cmd *cmds)
|
||||
return (count);
|
||||
}
|
||||
|
||||
int get_args_count(t_cmd *cmds)
|
||||
int get_args_count(t_token *cmds)
|
||||
{
|
||||
int count;
|
||||
t_cmd *cur_cmd;
|
||||
t_token *cur_cmd;
|
||||
|
||||
count = 0;
|
||||
cur_cmd = cmds;
|
||||
@ -56,7 +56,7 @@ int get_args_count(t_cmd *cmds)
|
||||
char **get_cmd_args(t_msh *msh)
|
||||
{
|
||||
char **cmd_args;
|
||||
t_cmd *cur_cmd;
|
||||
t_token *cur_cmd;
|
||||
int args_count;
|
||||
int i;
|
||||
|
||||
@ -85,8 +85,8 @@ char **get_cmd_args(t_msh *msh)
|
||||
|
||||
void remove_command_from_msh(t_msh *msh)
|
||||
{
|
||||
t_cmd *cur_cmd;
|
||||
t_cmd *cmd_tmp;
|
||||
t_token *cur_cmd;
|
||||
t_token *cmd_tmp;
|
||||
|
||||
cur_cmd = msh->cmds;
|
||||
while (cur_cmd && cur_cmd->next)
|
||||
|
@ -6,13 +6,13 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/18 15:46:50 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/27 14:56:35 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/27 16:21:24 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void print_parsed_cmd(t_cmd *cmd)
|
||||
void print_parsed_cmd(t_token *cmd)
|
||||
{
|
||||
while (cmd)
|
||||
{
|
||||
|
@ -6,14 +6,14 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/27 14:55:08 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/27 16:21:14 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
#include <unistd.h>
|
||||
|
||||
void put_args(t_cmd *args)
|
||||
void put_args(t_token *args)
|
||||
{
|
||||
int first;
|
||||
|
||||
@ -33,7 +33,7 @@ void put_args(t_cmd *args)
|
||||
}
|
||||
}
|
||||
|
||||
int echo(t_cmd *args)
|
||||
int echo(t_token *args)
|
||||
{
|
||||
int put_nl;
|
||||
int i;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/27 14:51:02 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/27 15:35:57 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -22,7 +22,7 @@ void numeric_arg_err(char *arg, int *exit_code)
|
||||
|
||||
void get_exit_bt_return_code(t_msh *msh, int *exit_code)
|
||||
{
|
||||
t_cmd *cur_cmd;
|
||||
t_token *cur_cmd;
|
||||
|
||||
cur_cmd = msh->cmds->next;
|
||||
if (cur_cmd && cur_cmd->type == ARG && !ft_strisnbr(cur_cmd->value))
|
||||
@ -35,7 +35,7 @@ void get_exit_bt_return_code(t_msh *msh, int *exit_code)
|
||||
|
||||
void exit_bt(t_msh *msh)
|
||||
{
|
||||
t_cmd *cur_cmd;
|
||||
t_token *cur_cmd;
|
||||
int exit_code;
|
||||
int cmd_count;
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/03/27 14:58:15 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/27 16:20:41 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -27,7 +27,7 @@ void redirect_input(t_msh *msh, int i)
|
||||
}
|
||||
}
|
||||
|
||||
void open_input_file(t_msh *msh, t_cmd **cur_cmd)
|
||||
void open_input_file(t_msh *msh, t_token **cur_cmd)
|
||||
{
|
||||
if ((*cur_cmd)->type == HERE_DOC)
|
||||
handle_here_doc(msh, (*cur_cmd)->next->value);
|
||||
@ -45,9 +45,9 @@ void open_input_file(t_msh *msh, t_cmd **cur_cmd)
|
||||
}
|
||||
}
|
||||
|
||||
void get_in_type(t_msh *msh, t_cmd *cmds)
|
||||
void get_in_type(t_msh *msh, t_token *cmds)
|
||||
{
|
||||
t_cmd *cur_cmd;
|
||||
t_token *cur_cmd;
|
||||
|
||||
cur_cmd = cmds;
|
||||
while (cur_cmd && cur_cmd->next && cur_cmd->type == ARG)
|
||||
@ -67,7 +67,7 @@ void get_in_type(t_msh *msh, t_cmd *cmds)
|
||||
|
||||
int first_is_in_type(t_msh *msh)
|
||||
{
|
||||
t_cmd *cur_cmd;
|
||||
t_token *cur_cmd;
|
||||
|
||||
cur_cmd = msh->cmds;
|
||||
while (cur_cmd && cur_cmd->type == ARG && cur_cmd->next)
|
||||
|
@ -6,18 +6,18 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/27 14:48:50 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/27 15:56:11 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
t_cmd *cmd_add_back(t_cmd *cmd, char *value, t_token_type type)
|
||||
t_cmd *cmd_add_back(t_token *cmd, char *value, t_token_type type)
|
||||
{
|
||||
t_cmd *res;
|
||||
t_cmd *current;
|
||||
|
||||
res = ft_calloc(1, sizeof(t_cmd));
|
||||
res = ft_calloc(1, sizeof(t_token));
|
||||
if (!res)
|
||||
return (cmd);
|
||||
res->value = value;
|
||||
@ -31,7 +31,7 @@ t_cmd *cmd_add_back(t_cmd *cmd, char *value, t_token_type type)
|
||||
return (cmd);
|
||||
}
|
||||
|
||||
void free_cmd(t_cmd *cmd)
|
||||
void free_cmd(t_token *cmd)
|
||||
{
|
||||
if (cmd)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/26 17:25:20 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/27 15:05:42 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/27 14:46:04 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/27 15:24:41 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -35,12 +35,12 @@ typedef enum e_token_type
|
||||
HERE_DOC,
|
||||
} t_token_type;
|
||||
|
||||
typedef struct s_cmd
|
||||
typedef struct s_token
|
||||
{
|
||||
t_token_type type;
|
||||
char *value;
|
||||
struct s_cmd *next;
|
||||
} t_cmd;
|
||||
struct s_token *next;
|
||||
} t_token;
|
||||
|
||||
typedef struct s_env
|
||||
{
|
||||
@ -65,26 +65,26 @@ typedef struct s_msh
|
||||
|
||||
extern int g_return_code;
|
||||
|
||||
t_cmd *cmd_add_back(t_cmd *res, char *token, t_token_type type);
|
||||
void free_cmd(t_cmd *cmd);
|
||||
t_token *cmd_add_back(t_token *res, char *token, t_token_type type);
|
||||
void free_cmd(t_token *cmd);
|
||||
void exec_commands(t_msh *msh);
|
||||
int echo(t_cmd *args);
|
||||
int echo(t_token *args);
|
||||
void exit_bt(t_msh *msh);
|
||||
t_env *env_add_back(t_env *env, char *name, char *value);
|
||||
void free_env(t_env *env);
|
||||
int print_env(t_env *env);
|
||||
t_cmd *parse_command(char *command, t_env *env);
|
||||
t_token *parse_command(char *command, t_env *env);
|
||||
int get_token_len(char *cmd, t_env *env);
|
||||
int add_var_to_str(char *res, char **command, t_env *env);
|
||||
int get_var_name_len(char *command);
|
||||
char *ft_get_env(t_env *env, char *var_name);
|
||||
int pwd(void);
|
||||
int is_cmd_char(char c);
|
||||
void print_parsed_cmd(t_cmd *cmd);//debug
|
||||
void print_parsed_cmd(t_token *cmd);//debug
|
||||
void ft_exit(t_msh *msh, int error_code);
|
||||
char **env_to_char_tab(t_env *env);
|
||||
void handle_minishellrc(t_msh *msh);
|
||||
int cd(t_cmd *args);
|
||||
int cd(t_token *args);
|
||||
int ft_export(t_msh *msh);
|
||||
void free_msh(t_msh *msh);
|
||||
char **split_paths_from_env(t_env *env);
|
||||
@ -92,8 +92,8 @@ void find_cmd_path(t_msh *msh, char **paths, int *found);
|
||||
void get_cmd_path(t_msh *msh);
|
||||
void handle_here_doc(t_msh *msh, char *eof);
|
||||
int ft_unset(t_msh *msh);
|
||||
void get_in_type(t_msh *msh, t_cmd *cmds);
|
||||
void get_out_type(t_msh *msh, t_cmd *cmds);
|
||||
void get_in_type(t_msh *msh, t_token *cmds);
|
||||
void get_out_type(t_msh *msh, t_token *cmds);
|
||||
int first_is_in_type(t_msh *msh);
|
||||
void redirect_input(t_msh *msh, int i);
|
||||
void redirect_output(t_msh *msh, int i);
|
||||
@ -103,8 +103,8 @@ void free_msh(t_msh *msh);
|
||||
void ft_exit(t_msh *msh, int exit_code);
|
||||
int cmd_is_builtin(t_msh *msh, char *cmd_token);
|
||||
int exec_builtin(t_msh *msh);
|
||||
int get_cmd_count(t_cmd *cmds);
|
||||
int get_args_count(t_cmd *cmds);
|
||||
int get_cmd_count(t_token *cmds);
|
||||
int get_args_count(t_token *cmds);
|
||||
char **get_cmd_args(t_msh *msh);
|
||||
void remove_command_from_msh(t_msh *msh);
|
||||
int file_access(t_msh *msh, int *found);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/03/27 14:58:29 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/27 16:21:56 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -26,7 +26,7 @@ void redirect_output(t_msh *msh, int i)
|
||||
}
|
||||
}
|
||||
|
||||
void open_out_file(t_msh *msh, t_cmd **cur_cmd)
|
||||
void open_out_file(t_msh *msh, t_token **cur_cmd)
|
||||
{
|
||||
msh->out_type = (*cur_cmd)->type;
|
||||
if (msh->out_type == RED_O)
|
||||
@ -51,9 +51,9 @@ void open_out_file(t_msh *msh, t_cmd **cur_cmd)
|
||||
}
|
||||
}
|
||||
|
||||
void get_out_type(t_msh *msh, t_cmd *cmds)
|
||||
void get_out_type(t_msh *msh, t_token *cmds)
|
||||
{
|
||||
t_cmd *cur_cmd;
|
||||
t_token *cur_cmd;
|
||||
|
||||
msh->out_type = ARG;
|
||||
msh->out_fd = 0;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/26 17:59:37 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/27 16:22:39 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -53,27 +53,28 @@ void signal_handler_here_doc(int signum)
|
||||
ft_exit(msh, 1);
|
||||
}
|
||||
}
|
||||
|
||||
int set_echoctl(int value)
|
||||
{
|
||||
struct termios t_p;
|
||||
|
||||
if(tcgetattr(1, &t_p))
|
||||
if (tcgetattr(1, &t_p))
|
||||
{
|
||||
ft_printf_fd(2, "minishell: an error occured while setting the local fl\
|
||||
ags");
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
if(value)
|
||||
if (value)
|
||||
t_p.c_lflag = t_p.c_lflag | ECHOCTL;
|
||||
else
|
||||
t_p.c_lflag = t_p.c_lflag & (~ECHOCTL);
|
||||
if(tcsetattr(1, TCSANOW, &t_p))
|
||||
if (tcsetattr(1, TCSANOW, &t_p))
|
||||
{
|
||||
ft_printf_fd(2, "minishell: an error occured while setting the local fl\
|
||||
ags");
|
||||
return(1);
|
||||
ags");
|
||||
return (1);
|
||||
}
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
void signal_handler_command(int signum)
|
||||
{
|
||||
|
Reference in New Issue
Block a user