parsing redirection au millieu d'une commande
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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))
|
||||
tmp = tmp->next;
|
||||
if (tmp)
|
||||
msh->tokens = parse_command(tmp->value, msh->env);
|
||||
msh->tokens = parse_cmds_to_token(tmp, msh->env);
|
||||
else
|
||||
msh->tokens = 0;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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))
|
||||
cmds = cmds->next;
|
||||
msh->tokens = parse_command(cmds->value, msh->env);
|
||||
msh->tokens = parse_cmds_to_token(cmds, msh->env);
|
||||
msh->cmds = cmds;
|
||||
//print_msh_struct(msh); // debug
|
||||
//print_parsed_token(msh->tokens); // debug
|
||||
print_parsed_token(msh->tokens); // debug
|
||||
exec_commands(msh);
|
||||
msh->in_fd = 0;
|
||||
msh->out_fd = 0;
|
||||
@ -118,6 +118,9 @@ int get_cmd_count(t_cmd *cmds)
|
||||
{
|
||||
if (is_cmd_type(cmds))
|
||||
nb++;
|
||||
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);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
close(msh->in_fd);
|
||||
filename = parse_command((*cur_token)->value, msh->env);
|
||||
filename = parse_tokens((*cur_token)->value, msh->env);
|
||||
if (!filename)
|
||||
ft_exit(msh, 1);
|
||||
msh->in_fd = open(filename->value, O_RDONLY);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
int cmd_is_builtin(t_msh *msh, char *cmd_token);
|
||||
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);
|
||||
char *ft_get_env(t_env *env, char *var_name);
|
||||
int is_fd_open(int fd);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
{
|
||||
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)
|
||||
ft_exit(msh, 1);
|
||||
open_out_file(msh, &cur_cmd, filename->value);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
@ -58,7 +58,7 @@ char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env)
|
||||
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_dquote;
|
||||
@ -81,3 +81,21 @@ t_token *parse_command(char *command, t_env *env)
|
||||
return (parsing_syntax_error(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> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
return (0);
|
||||
}
|
||||
token = parse_command(cmd->value, 0);
|
||||
token = parse_cmds_to_token(cmd, 0);
|
||||
if (!token)
|
||||
return (0);
|
||||
free_token(token);
|
||||
@ -172,7 +172,7 @@ t_cmd *check_cmds_syntax(t_cmd *cmds)
|
||||
&& cmds->value == 0)
|
||||
return (cmds);
|
||||
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);
|
||||
if (is_cmd_type(cmds))
|
||||
if (!check_tokens_syntax(cmds, last))
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
@ -49,14 +49,17 @@ t_token *get_all_files(DIR *dir, char *wildcard)
|
||||
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)
|
||||
return (next);
|
||||
start = res;
|
||||
while (res->next)
|
||||
res = res->next;
|
||||
res->next = next;
|
||||
return (res);
|
||||
return (start);
|
||||
}
|
||||
|
||||
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));
|
||||
free(value);
|
||||
sort_wildcards_token(new);
|
||||
res = wildcards_add_back(res, new);
|
||||
res = add_token_back(res, new);
|
||||
return (res);
|
||||
}
|
||||
|
Reference in New Issue
Block a user