parsing redirection au millieu d'une commande
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 18:22:15 by marde-vr #+# #+# */
|
/* Created: 2024/03/05 18:22:15 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/04/18 20:48:51 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/19 10:40:13 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ void remove_command_from_msh(t_msh *msh)
|
|||||||
while (tmp && !is_cmd_type(tmp))
|
while (tmp && !is_cmd_type(tmp))
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
if (tmp)
|
if (tmp)
|
||||||
msh->tokens = parse_command(tmp->value, msh->env);
|
msh->tokens = parse_cmds_to_token(tmp, msh->env);
|
||||||
else
|
else
|
||||||
msh->tokens = 0;
|
msh->tokens = 0;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
|
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/04/18 21:06:26 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/19 10:44:36 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -52,10 +52,10 @@ void exec_command_bonus(t_msh *msh, char *cmd_str)
|
|||||||
{
|
{
|
||||||
if (is_operand_type(cmds))
|
if (is_operand_type(cmds))
|
||||||
cmds = cmds->next;
|
cmds = cmds->next;
|
||||||
msh->tokens = parse_command(cmds->value, msh->env);
|
msh->tokens = parse_cmds_to_token(cmds, msh->env);
|
||||||
msh->cmds = cmds;
|
msh->cmds = cmds;
|
||||||
//print_msh_struct(msh); // debug
|
//print_msh_struct(msh); // debug
|
||||||
//print_parsed_token(msh->tokens); // debug
|
print_parsed_token(msh->tokens); // debug
|
||||||
exec_commands(msh);
|
exec_commands(msh);
|
||||||
msh->in_fd = 0;
|
msh->in_fd = 0;
|
||||||
msh->out_fd = 0;
|
msh->out_fd = 0;
|
||||||
@ -118,7 +118,10 @@ int get_cmd_count(t_cmd *cmds)
|
|||||||
{
|
{
|
||||||
if (is_cmd_type(cmds))
|
if (is_cmd_type(cmds))
|
||||||
nb++;
|
nb++;
|
||||||
cmds = cmds->next;
|
while(cmds && (is_output_type(cmds) || is_input_type(cmds) || is_cmd_type(cmds)))
|
||||||
|
cmds=cmds->next;
|
||||||
|
if(cmds && cmds->cmd_type == PIPE)
|
||||||
|
cmds = cmds->next;
|
||||||
}
|
}
|
||||||
return (nb);
|
return (nb);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */
|
/* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/04/18 20:48:54 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/19 09:43:39 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ void open_input_file(t_msh *msh, t_cmd **cur_token)
|
|||||||
{
|
{
|
||||||
if (msh->in_fd != 0)
|
if (msh->in_fd != 0)
|
||||||
close(msh->in_fd);
|
close(msh->in_fd);
|
||||||
filename = parse_command((*cur_token)->value, msh->env);
|
filename = parse_tokens((*cur_token)->value, msh->env);
|
||||||
if (!filename)
|
if (!filename)
|
||||||
ft_exit(msh, 1);
|
ft_exit(msh, 1);
|
||||||
msh->in_fd = open(filename->value, O_RDONLY);
|
msh->in_fd = open(filename->value, O_RDONLY);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/04/17 10:13:08 by tomoron ### ########.fr */
|
/* Updated: 2024/04/19 10:39:52 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -86,7 +86,9 @@ t_env *env_add_back(t_env *env, char *name, char *value);
|
|||||||
void exec_command_bonus(t_msh *msh, char *cmd_str);
|
void exec_command_bonus(t_msh *msh, char *cmd_str);
|
||||||
int cmd_is_builtin(t_msh *msh, char *cmd_token);
|
int cmd_is_builtin(t_msh *msh, char *cmd_token);
|
||||||
void child(t_msh *msh, char **cmd_args, int i);
|
void child(t_msh *msh, char **cmd_args, int i);
|
||||||
t_token *parse_command(char *command, t_env *env);
|
t_token *parse_tokens(char *command, t_env *env);
|
||||||
|
t_token *add_token_back(t_token *res, t_token *next);
|
||||||
|
t_token *parse_cmds_to_token(t_cmd *command, t_env *env);
|
||||||
void parent(t_msh *msh, int i, int cmd_count);
|
void parent(t_msh *msh, int i, int cmd_count);
|
||||||
char *ft_get_env(t_env *env, char *var_name);
|
char *ft_get_env(t_env *env, char *var_name);
|
||||||
int is_fd_open(int fd);
|
int is_fd_open(int fd);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */
|
/* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/04/18 20:48:57 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/19 09:45:21 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ void get_out_type(t_msh *msh, t_cmd *cmds)
|
|||||||
&& cur_cmd->cmd_type != PIPE)
|
&& cur_cmd->cmd_type != PIPE)
|
||||||
{
|
{
|
||||||
msh->out_type = cur_cmd->cmd_type;
|
msh->out_type = cur_cmd->cmd_type;
|
||||||
filename = parse_command(cur_cmd->value, msh->env);
|
filename = parse_tokens(cur_cmd->value, msh->env);
|
||||||
if (!filename)
|
if (!filename)
|
||||||
ft_exit(msh, 1);
|
ft_exit(msh, 1);
|
||||||
open_out_file(msh, &cur_cmd, filename->value);
|
open_out_file(msh, &cur_cmd, filename->value);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
|
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/04/18 20:48:57 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/19 10:43:47 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
@ -58,7 +58,7 @@ char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env)
|
|||||||
return (res);
|
return (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_token *parse_command(char *command, t_env *env)
|
t_token *parse_tokens(char *command, t_env *env)
|
||||||
{
|
{
|
||||||
int in_quote;
|
int in_quote;
|
||||||
int in_dquote;
|
int in_dquote;
|
||||||
@ -81,3 +81,21 @@ t_token *parse_command(char *command, t_env *env)
|
|||||||
return (parsing_syntax_error(res));
|
return (parsing_syntax_error(res));
|
||||||
return (res);
|
return (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t_token *parse_cmds_to_token(t_cmd *command, t_env *env)
|
||||||
|
{
|
||||||
|
t_token *res;
|
||||||
|
t_token *new;
|
||||||
|
|
||||||
|
res = 0;
|
||||||
|
while(command && (is_cmd_type(command) || is_output_type(command) || is_input_type(command)))
|
||||||
|
{
|
||||||
|
if(is_cmd_type(command))
|
||||||
|
{
|
||||||
|
new = parse_tokens(command->value, env);
|
||||||
|
res = add_token_back(res, new);
|
||||||
|
}
|
||||||
|
command = command->next;
|
||||||
|
}
|
||||||
|
return(res);
|
||||||
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/27 14:40:44 by tomoron #+# #+# */
|
/* Created: 2024/03/27 14:40:44 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/04/18 20:48:57 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/19 10:40:51 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ int check_tokens_syntax(t_cmd *cmd, t_cmd *last)
|
|||||||
ft_putstr_fd("minishell : syntax error\n", 2);
|
ft_putstr_fd("minishell : syntax error\n", 2);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
token = parse_command(cmd->value, 0);
|
token = parse_cmds_to_token(cmd, 0);
|
||||||
if (!token)
|
if (!token)
|
||||||
return (0);
|
return (0);
|
||||||
free_token(token);
|
free_token(token);
|
||||||
@ -172,7 +172,7 @@ t_cmd *check_cmds_syntax(t_cmd *cmds)
|
|||||||
&& cmds->value == 0)
|
&& cmds->value == 0)
|
||||||
return (cmds);
|
return (cmds);
|
||||||
if (is_operand_type(cmds) || cmds->cmd_type == PIPE)
|
if (is_operand_type(cmds) || cmds->cmd_type == PIPE)
|
||||||
if (!is_cmd_type(last) || !cmds->next || !is_cmd_type(cmds->next))
|
if ((!is_cmd_type(last) && !is_output_type(last) && !is_input_type(last)) || !cmds->next || (!is_cmd_type(cmds->next) && !is_output_type(cmds->next) && !is_input_type(cmds->next)))
|
||||||
return (cmds);
|
return (cmds);
|
||||||
if (is_cmd_type(cmds))
|
if (is_cmd_type(cmds))
|
||||||
if (!check_tokens_syntax(cmds, last))
|
if (!check_tokens_syntax(cmds, last))
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/15 12:53:29 by tomoron #+# #+# */
|
/* Created: 2024/04/15 12:53:29 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/04/18 20:48:39 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/19 10:55:20 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
@ -49,14 +49,17 @@ t_token *get_all_files(DIR *dir, char *wildcard)
|
|||||||
return (res);
|
return (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_token *wildcards_add_back(t_token *res, t_token *next)
|
t_token *add_token_back(t_token *res, t_token *next)
|
||||||
{
|
{
|
||||||
|
t_token *start;
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
return (next);
|
return (next);
|
||||||
|
start = res;
|
||||||
while (res->next)
|
while (res->next)
|
||||||
res = res->next;
|
res = res->next;
|
||||||
res->next = next;
|
res->next = next;
|
||||||
return (res);
|
return (start);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_token *expand_wildcards(t_token *res, char *value)
|
t_token *expand_wildcards(t_token *res, char *value)
|
||||||
@ -80,6 +83,6 @@ t_token *expand_wildcards(t_token *res, char *value)
|
|||||||
return (token_add_back(res, value));
|
return (token_add_back(res, value));
|
||||||
free(value);
|
free(value);
|
||||||
sort_wildcards_token(new);
|
sort_wildcards_token(new);
|
||||||
res = wildcards_add_back(res, new);
|
res = add_token_back(res, new);
|
||||||
return (res);
|
return (res);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
redirection au millieu d'une commande
|
|
||||||
print message quand segfault et "(core dumped)" si WCOREDUMP
|
print message quand segfault et "(core dumped)" si WCOREDUMP
|
||||||
|
|
||||||
export +=
|
export +=
|
||||||
export sort
|
export sort
|
||||||
fix exit | exit
|
fix exit | exit
|
||||||
exec export in fork when piped
|
exec export in fork when piped
|
||||||
here doc in fork
|
here doc in fork
|
||||||
|
|
||||||
|
|
||||||
LEAKS
|
LEAKS
|
||||||
|
add cmds_head in msh_struct to free in runtime
|
||||||
|
Reference in New Issue
Block a user