i think i never speedran the norm like this before

This commit is contained in:
mdev9
2024-04-18 21:50:23 +02:00
parent 5da5968deb
commit fb62d4ceed
32 changed files with 169 additions and 158 deletions

View File

@ -6,7 +6,7 @@
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ # # By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# # # Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
# Updated: 2024/04/17 10:13:40 by tomoron ### ########.fr # # Updated: 2024/04/18 20:36:38 by marde-vr ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:20:21 by marde-vr #+# #+# */ /* Created: 2024/03/05 18:20:21 by marde-vr #+# #+# */
/* Updated: 2024/04/07 17:14:57 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:48 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/16 21:02:54 by marde-vr #+# #+# */ /* Created: 2024/02/16 21:02:54 by marde-vr #+# #+# */
/* Updated: 2024/04/18 17:56:04 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:50 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -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/17 18:29:07 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:51 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -60,17 +60,17 @@ char **get_cmd_args(t_msh *msh)
void remove_command_from_msh(t_msh *msh) void remove_command_from_msh(t_msh *msh)
{ {
t_cmd *tmp; t_cmd *tmp;
free_token(msh->tokens); free_token(msh->tokens);
while(msh->cmds && !is_cmd_type(msh->cmds)) while (msh->cmds && !is_cmd_type(msh->cmds))
msh->cmds = msh->cmds->next; msh->cmds = msh->cmds->next;
while(msh->cmds && is_cmd_type(msh->cmds)) while (msh->cmds && is_cmd_type(msh->cmds))
msh->cmds = msh->cmds->next; msh->cmds = msh->cmds->next;
tmp = msh->cmds; tmp = msh->cmds;
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_command(tmp->value, msh->env);
else else
msh->tokens = 0; msh->tokens = 0;

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/18 15:46:50 by tomoron #+# #+# */ /* Created: 2024/02/18 15:46:50 by tomoron #+# #+# */
/* Updated: 2024/04/07 17:27:45 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:51 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,29 +24,29 @@ void print_parsed_token(t_token *token)
void print_cmd_type(t_cmd_type type, char *value) void print_cmd_type(t_cmd_type type, char *value)
{ {
if(type == CMD) if (type == CMD)
printf("[CMD : %s] ", value); printf("[CMD : %s] ", value);
if(type == PAREN) if (type == PAREN)
printf("[PAREN : %s] ", value); printf("[PAREN : %s] ", value);
if(type == AND) if (type == AND)
printf("[AND] "); printf("[AND] ");
if(type == OR) if (type == OR)
printf("[OR] "); printf("[OR] ");
if(type == PIPE) if (type == PIPE)
printf("[PIPE] "); printf("[PIPE] ");
if(type == RED_O_APP) if (type == RED_O_APP)
printf("[RED_O_APP : %s] ", value); printf("[RED_O_APP : %s] ", value);
if(type == RED_O) if (type == RED_O)
printf("[RED_O : %s] ", value); printf("[RED_O : %s] ", value);
if(type == RED_I) if (type == RED_I)
printf("[RED_I : %s] ", value); printf("[RED_I : %s] ", value);
if(type == HERE_DOC) if (type == HERE_DOC)
printf("[HERE_DOC : %s] ", value); printf("[HERE_DOC : %s] ", value);
} }
void print_parsed_cmd(t_cmd *cmd) void print_parsed_cmd(t_cmd *cmd)
{ {
while(cmd) while (cmd)
{ {
print_cmd_type(cmd->cmd_type, cmd->value); print_cmd_type(cmd->cmd_type, cmd->value);
cmd = cmd->next; cmd = cmd->next;

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */ /* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */
/* Updated: 2024/04/02 00:44:56 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:52 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/16 13:30:18 by tomoron #+# #+# */ /* Created: 2024/02/16 13:30:18 by tomoron #+# #+# */
/* Updated: 2024/03/26 08:49:12 by marde-vr ### ########.fr */ /* Updated: 2024/04/18 20:48:52 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */ /* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
/* Updated: 2024/04/03 17:21:57 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:52 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -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 18:29:10 by marde-vr ### ########.fr */ /* Updated: 2024/04/18 21:06:26 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -36,12 +36,12 @@ void exec_command_bonus(t_msh *msh, char *cmd_str)
t_cmd *tmp; t_cmd *tmp;
cmds = parsing_bonus(cmd_str); cmds = parsing_bonus(cmd_str);
print_parsed_cmd(cmds); // debug //print_parsed_cmd(cmds); // debug
tmp = check_cmds_syntax(cmds); tmp = check_cmds_syntax(cmds);
if (tmp) if (tmp)
{ {
print_syntax_error_bonus(tmp); print_syntax_error_bonus(tmp);
printf("error\n"); // debug //printf("error\n"); // debug
free_cmd(cmds); free_cmd(cmds);
return ; return ;
} }
@ -72,13 +72,13 @@ int exec(t_msh *msh, char **cmd_args, int i, int cmd_count)
if (i != cmd_count - 1) if (i != cmd_count - 1)
{ {
fprintf(stderr, "piping %d", i); //fprintf(stderr, "piping %d", i);
if (pipe(msh->fds[i]) == -1) if (pipe(msh->fds[i]) == -1)
{ {
perror("minishell: pipe"); perror("minishell: pipe");
ft_exit(msh, 1); ft_exit(msh, 1);
} }
fprintf(stderr, "pipe: msh->fds[%d][0]: %d, msh->fds[%d][1]: %d\n", i, msh->fds[i][0], i, msh->fds[i][1]); //fprintf(stderr, "pipe: msh->fds[%d][0]: %d, msh->fds[%d][1]: %d\n", i, msh->fds[i][0], i, msh->fds[i][1]);
} }
pid = fork(); pid = fork();
if (pid == -1) if (pid == -1)
@ -99,7 +99,7 @@ int exec(t_msh *msh, char **cmd_args, int i, int cmd_count)
void exec_command(t_msh *msh, int i, int cmd_count) void exec_command(t_msh *msh, int i, int cmd_count)
{ {
g_return_code = 0; //g_return_code = 0;
msh->fds[i] = ft_calloc(2, sizeof(int *)); msh->fds[i] = ft_calloc(2, sizeof(int *));
if (!msh->fds[i]) if (!msh->fds[i])
ft_exit(msh, 1); ft_exit(msh, 1);
@ -153,7 +153,7 @@ void exec_commands(t_msh *msh)
if (!msh->tokens) if (!msh->tokens)
return ; return ;
cmd_count = get_cmd_count(msh->cmds); cmd_count = get_cmd_count(msh->cmds);
printf("cmd_count : %d\n", cmd_count); //printf("cmd_count : %d\n", cmd_count);
msh->fds = ft_calloc(cmd_count, sizeof(int **)); msh->fds = ft_calloc(cmd_count, sizeof(int **));
msh->pids = ft_calloc(cmd_count, sizeof(int *)); msh->pids = ft_calloc(cmd_count, sizeof(int *));
if (!msh->pids || !msh->fds) if (!msh->pids || !msh->fds)
@ -162,7 +162,7 @@ void exec_commands(t_msh *msh)
while (i < cmd_count) while (i < cmd_count)
{ {
get_redirections(msh, msh->cmds); get_redirections(msh, msh->cmds);
fprintf(stderr, "command: %s, in_type: %d, out_type: %d\n", msh->cmds->value, msh->in_type, msh->out_type); //fprintf(stderr, "command: %s, in_type: %d, out_type: %d\n", msh->cmds->value, msh->in_type, msh->out_type);
exec_command(msh, i, cmd_count); exec_command(msh, i, cmd_count);
//free(msh->fds[i]); //free(msh->fds[i]);
i++; i++;

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */ /* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */
/* Updated: 2024/04/03 15:44:06 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:53 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */ /* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
/* Updated: 2024/04/03 15:45:32 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:53 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -61,8 +61,8 @@ int ft_export(t_msh *msh)
value = ft_strdup(arg + len); value = ft_strdup(arg + len);
msh->env = env_add_back(msh->env, name, value); msh->env = env_add_back(msh->env, name, value);
} }
//export += //export +=
//replacer si ça existe deja sauf si il y a pas de = //replacer si ça existe deja sauf si il y a pas de =
return (0); return (0);
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */ /* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */
/* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:53 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -50,7 +50,7 @@ void here_doc_child(t_msh *msh, char *eof, char *here_doc_file)
void here_doc_signal(t_msh *msh, int child_pid, char *here_doc_file) void here_doc_signal(t_msh *msh, int child_pid, char *here_doc_file)
{ {
int status; int status;
//signal(SIGINT, signal_handler_command); //signal(SIGINT, signal_handler_command);
signal(SIGQUIT, signal_handler_here_doc); signal(SIGQUIT, signal_handler_here_doc);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/26 09:06:51 by marde-vr #+# #+# */ /* Created: 2024/03/26 09:06:51 by marde-vr #+# #+# */
/* Updated: 2024/03/26 09:07:42 by marde-vr ### ########.fr */ /* Updated: 2024/04/18 20:48:54 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -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 18:25:20 by marde-vr ### ########.fr */ /* Updated: 2024/04/18 20:48:54 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,15 +16,15 @@ void redirect_input(t_msh *msh, int i)
{ {
if (msh->in_type != PIPE) if (msh->in_type != PIPE)
{ {
fprintf(stderr, "redirecting input\n"); //fprintf(stderr, "redirecting input\n");
if (dup2(msh->in_fd, 0) < 0) if (dup2(msh->in_fd, 0) < 0)
ft_exit(msh, 1); ft_exit(msh, 1);
close(msh->in_fd); close(msh->in_fd);
} }
else else
{ {
fprintf(stderr, "redirecting pipe input\n"); //fprintf(stderr, "redirecting pipe input\n");
fprintf(stderr, "input of cmd %d: %d -> 0\n", i, msh->fds[i - 1][0]); //fprintf(stderr, "input of cmd %d: %d -> 0\n", i, msh->fds[i - 1][0]);
if (dup2(msh->fds[i - 1][0], 0) < 0) if (dup2(msh->fds[i - 1][0], 0) < 0)
{ {
perror("dup2"); //debug perror("dup2"); //debug
@ -35,7 +35,7 @@ void redirect_input(t_msh *msh, int i)
void open_input_file(t_msh *msh, t_cmd **cur_token) void open_input_file(t_msh *msh, t_cmd **cur_token)
{ {
t_token *filename; t_token *filename;
if ((*cur_token)->cmd_type == HERE_DOC) if ((*cur_token)->cmd_type == HERE_DOC)
handle_here_doc(msh, (*cur_token)->value); handle_here_doc(msh, (*cur_token)->value);
@ -44,7 +44,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_command((*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);
free_token(filename); free_token(filename);
@ -67,14 +67,15 @@ void get_in_type(t_msh *msh, t_cmd *tokens)
msh->in_type = PIPE; msh->in_type = PIPE;
return ; return ;
} }
while (cur_token && (cur_token->cmd_type == CMD || cur_token->cmd_type == PAREN)) while (cur_token && (cur_token->cmd_type == CMD
|| cur_token->cmd_type == PAREN))
cur_token = cur_token->next; cur_token = cur_token->next;
if (cur_token && is_input_type(cur_token)) if (cur_token && is_input_type(cur_token))
{ {
msh->in_type = cur_token->cmd_type; msh->in_type = cur_token->cmd_type;
open_input_file(msh, &cur_token); open_input_file(msh, &cur_token);
} }
if(cur_token && cur_token->next && !is_operand_type(cur_token->next)) if (cur_token && cur_token->next && !is_operand_type(cur_token->next))
get_in_type(msh, cur_token->next); get_in_type(msh, cur_token->next);
} }
@ -85,7 +86,7 @@ int first_is_in_type(t_cmd *cmd)
cur_token = cmd; cur_token = cmd;
while (cur_token && cur_token->cmd_type == CMD && cur_token->next) while (cur_token && cur_token->cmd_type == CMD && cur_token->next)
cur_token = cur_token->next; cur_token = cur_token->next;
if ( is_input_type(cur_token) || cur_token->cmd_type == PIPE) if (is_input_type(cur_token) || cur_token->cmd_type == PIPE)
return (1); return (1);
return (0); return (0);
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 17:31:53 by marde-vr #+# #+# */ /* Created: 2024/03/05 17:31:53 by marde-vr #+# #+# */
/* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:54 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */ /* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */
/* Updated: 2024/03/29 14:30:00 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:55 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */ /* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */
/* Updated: 2024/02/17 04:33:17 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:55 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */ /* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */
/* Updated: 2024/04/02 00:44:16 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:56 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */ /* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
/* Updated: 2024/04/17 14:24:31 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:57:00 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -83,7 +83,7 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
(*msh)->env = get_env(envp); (*msh)->env = get_env(envp);
tcgetattr(1, &t_p); tcgetattr(1, &t_p);
(*msh)->echoctl = t_p.c_lflag & ECHOCTL; (*msh)->echoctl = t_p.c_lflag & ECHOCTL;
// signal(SIGINT, signal_handler_interactive); //enables ctrl-C // signal(SIGINT, signal_handler_interactive); //enables ctrl-C
signal(SIGQUIT, signal_handler_interactive); signal(SIGQUIT, signal_handler_interactive);
if (set_echoctl(0)) if (set_echoctl(0))
ft_exit(*msh, 1); ft_exit(*msh, 1);
@ -96,6 +96,9 @@ int main(int argc, char **argv, char **envp)
char *commands; char *commands;
char *prompt; char *prompt;
t_msh *msh; t_msh *msh;
char *commands;
char *prompt;
t_msh *msh;
commands = (char *)1; commands = (char *)1;
init_minishell(&msh, argc, argv, envp); init_minishell(&msh, argc, argv, envp);
@ -121,7 +124,7 @@ int main(int argc, char **argv, char **envp)
return (g_return_code); return (g_return_code);
}*/ }*/
int main(int argc, char **argv, char **envp) int main(int argc, char **argv, char **envp)
{ {
char *commands; char *commands;
char *prompt; char *prompt;
@ -139,5 +142,5 @@ int main(int argc, char **argv, char **envp)
add_history(commands); add_history(commands);
exec_command_bonus(msh, commands); exec_command_bonus(msh, commands);
free(commands); free(commands);
} }
} }

View File

@ -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 17:56:05 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:57 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,18 +17,18 @@ void redirect_output(t_msh *msh, int i)
{ {
if (msh->out_type != PIPE) if (msh->out_type != PIPE)
{ {
fprintf(stderr, "redirecting output\n"); //fprintf(stderr, "redirecting output\n");
if (dup2(msh->out_fd, 1) < 0) if (dup2(msh->out_fd, 1) < 0)
ft_exit(msh, 1); ft_exit(msh, 1);
} }
else else
{ {
fprintf(stderr, "redirecting pipe output\n"); //fprintf(stderr, "redirecting pipe output\n");
//sleep(1); //sleep(1);
if (dup2(msh->fds[i][1], 1) < 0) if (dup2(msh->fds[i][1], 1) < 0)
{ {
perror("dup2"); perror("dup2");
fprintf(stderr, "exiting\n"); //fprintf(stderr, "exiting\n");
//ft_exit(msh, 1); //ft_exit(msh, 1);
} }
} }
@ -59,31 +59,33 @@ void open_out_file(t_msh *msh, t_cmd **cur_cmd, char *filename)
void get_out_type(t_msh *msh, t_cmd *cmds) void get_out_type(t_msh *msh, t_cmd *cmds)
{ {
t_cmd *cur_cmd; t_cmd *cur_cmd;
t_token *filename; t_token *filename;
msh->out_type = CMD; msh->out_type = CMD;
msh->out_fd = 0; msh->out_fd = 0;
cur_cmd = cmds; cur_cmd = cmds;
while(cur_cmd && !is_cmd_type(cur_cmd)) while (cur_cmd && !is_cmd_type(cur_cmd))
cur_cmd = cur_cmd->next; cur_cmd = cur_cmd->next;
while (cur_cmd && cur_cmd->next && !is_output_type(cur_cmd) && !is_operand_type(cur_cmd) && cur_cmd->cmd_type != PIPE) while (cur_cmd && cur_cmd->next && !is_output_type(cur_cmd)
&& !is_operand_type(cur_cmd) && cur_cmd->cmd_type != PIPE)
{ {
fprintf(stderr, "%s: %d\n", cur_cmd->value, cur_cmd->cmd_type); //fprintf(stderr, "%s: %d\n", cur_cmd->value, cur_cmd->cmd_type);
cur_cmd = cur_cmd->next; cur_cmd = cur_cmd->next;
} }
if (cur_cmd) //if (cur_cmd)
fprintf(stderr, "%s: %d\n", cur_cmd->value, cur_cmd->cmd_type); //fprintf(stderr, "%s: %d\n", cur_cmd->value, cur_cmd->cmd_type);
if (cur_cmd->cmd_type == CMD || cur_cmd->cmd_type == PAREN) if (cur_cmd->cmd_type == CMD || cur_cmd->cmd_type == PAREN)
msh->out_type = 0; msh->out_type = 0;
else if(cur_cmd && is_output_type(cur_cmd) && !is_operand_type(cur_cmd) && cur_cmd->cmd_type != PIPE) else if (cur_cmd && is_output_type(cur_cmd) && !is_operand_type(cur_cmd)
&& 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_command(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);
free_token(filename); free_token(filename);
} }
else if(cur_cmd && cur_cmd->cmd_type == PIPE) else if (cur_cmd && cur_cmd->cmd_type == PIPE)
msh->out_type = PIPE; msh->out_type = PIPE;
} }

View File

@ -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/15 15:56:17 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:57 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
@ -51,7 +51,7 @@ char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env)
else if (**cmd == '~' && !*in_quote && !*in_dquote) else if (**cmd == '~' && !*in_quote && !*in_dquote)
i += add_home_to_str(res + i); i += add_home_to_str(res + i);
else if (((**cmd == '\'' && *in_dquote) || (**cmd == '"' && *in_quote)) else if (((**cmd == '\'' && *in_dquote) || (**cmd == '"' && *in_quote))
|| (**cmd != '\'' && **cmd != '"')) || (**cmd != '\'' && **cmd != '"'))
res[i++] = **cmd; res[i++] = **cmd;
(*cmd)++; (*cmd)++;
} }
@ -60,10 +60,10 @@ char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env)
t_token *parse_command(char *command, t_env *env) t_token *parse_command(char *command, t_env *env)
{ {
int in_quote; int in_quote;
int in_dquote; int in_dquote;
t_token *res; t_token *res;
char *value; char *value;
in_quote = 0; in_quote = 0;
in_dquote = 0; in_dquote = 0;

View File

@ -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 17:56:05 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:57 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -236,7 +236,7 @@ t_cmd *parsing_bonus(char *cmd)
if (type == CMD || type == PAREN) if (type == CMD || type == PAREN)
value = get_cmd_value(&cmd, type); value = get_cmd_value(&cmd, type);
else if (type == RED_O || type == RED_O_APP || type == RED_I else if (type == RED_O || type == RED_O_APP || type == RED_I
|| type == HERE_DOC) || type == HERE_DOC)
value = get_next_arg(&cmd); value = get_next_arg(&cmd);
else else
value = 0; value = 0;

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */ /* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */
/* Updated: 2024/03/28 14:10:02 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:58 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -65,7 +65,7 @@ int get_token_len(char *command, t_env *env)
else if (*command != '\'' && *command != '"') else if (*command != '\'' && *command != '"')
res++; res++;
else if ((*command == '\'' && in_dquote) || (*command == '"' else if ((*command == '\'' && in_dquote) || (*command == '"'
&& in_quote)) && in_quote))
res++; res++;
command++; command++;
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/21 21:47:15 by marde-vr #+# #+# */ /* Created: 2024/02/21 21:47:15 by marde-vr #+# #+# */
/* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:58 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */ /* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */
/* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:58 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,23 +18,23 @@ void close_pipe_fds(t_msh *msh, int i)
{ {
if (msh->fds[i - 1][0] > 2) if (msh->fds[i - 1][0] > 2)
{ {
fprintf(stderr, "closing fd %d in child\n", msh->fds[i-1][0]); //fprintf(stderr, "closing fd %d in child\n", msh->fds[i-1][0]);
close(msh->fds[i - 1][0]); close(msh->fds[i - 1][0]);
} }
if (msh->fds[i - 1][1] > 2) if (msh->fds[i - 1][1] > 2)
{ {
fprintf(stderr, "closing fd %d in child\n", msh->fds[i-1][1]); //fprintf(stderr, "closing fd %d in child\n", msh->fds[i-1][1]);
close(msh->fds[i - 1][1]); close(msh->fds[i - 1][1]);
} }
} }
if (msh->fds[i][0] > 2) if (msh->fds[i][0] > 2)
{ {
fprintf(stderr, "closing fd %d in child\n", msh->fds[i][0]); //fprintf(stderr, "closing fd %d in child\n", msh->fds[i][0]);
close(msh->fds[i][0]); close(msh->fds[i][0]);
} }
if (msh->fds[i][1] > 2) if (msh->fds[i][1] > 2)
{ {
fprintf(stderr, "closing fd %d in child\n", msh->fds[i][1]); //fprintf(stderr, "closing fd %d in child\n", msh->fds[i][1]);
close(msh->fds[i][1]); close(msh->fds[i][1]);
} }
} }
@ -53,9 +53,9 @@ void execute_command(t_msh *msh, char **cmd_args)
{ {
set_echoctl(msh->echoctl); set_echoctl(msh->echoctl);
env = env_to_char_tab(msh->env); env = env_to_char_tab(msh->env);
if(env) if (env)
{ {
fprintf(stderr, "execveing %s\n", msh->tokens->value); //fprintf(stderr, "execveing %s\n", msh->tokens->value);
execve(msh->tokens->value, cmd_args, env); execve(msh->tokens->value, cmd_args, env);
} }
ft_free_str_arr(env); ft_free_str_arr(env);
@ -65,13 +65,13 @@ void execute_command(t_msh *msh, char **cmd_args)
void child(t_msh *msh, char **cmd_args, int i) void child(t_msh *msh, char **cmd_args, int i)
{ {
if ((msh->in_type != CMD && msh->in_type != PAREN && msh->in_type != AND if ((msh->in_type != CMD && msh->in_type != PAREN && msh->in_type != AND
&& msh->in_type != OR && msh->in_type != PIPE) && msh->in_type != OR && msh->in_type != PIPE)
|| (msh->in_type == PIPE && i > 0)) || (msh->in_type == PIPE && i > 0))
redirect_input(msh, i); redirect_input(msh, i);
if (msh->out_type == PIPE || msh->out_type == RED_O if (msh->out_type == PIPE || msh->out_type == RED_O
|| msh->out_type == RED_O_APP) || msh->out_type == RED_O_APP)
redirect_output(msh, i); redirect_output(msh, i);
fprintf(stderr, "closing fds\n"); //fprintf(stderr, "closing fds\n");
close_pipe_fds(msh, i); close_pipe_fds(msh, i);
execute_command(msh, cmd_args); execute_command(msh, cmd_args);
close(0); close(0);
@ -89,12 +89,12 @@ void parent(t_msh *msh, int i, int cmd_count)
{ {
if (msh->fds[i - 1][0] > 2) if (msh->fds[i - 1][0] > 2)
{ {
fprintf(stderr, "closing fd %d in parent\n", msh->fds[i - 1][0]); //fprintf(stderr, "closing fd %d in parent\n", msh->fds[i - 1][0]);
close(msh->fds[i - 1][0]); close(msh->fds[i - 1][0]);
} }
if (msh->fds[i - 1][1] > 2) if (msh->fds[i - 1][1] > 2)
{ {
fprintf(stderr, "closing fd %d in parent\n", msh->fds[i - 1][1]); //fprintf(stderr, "closing fd %d in parent\n", msh->fds[i - 1][1]);
close(msh->fds[i - 1][1]); close(msh->fds[i - 1][1]);
} }
} }
@ -102,23 +102,23 @@ void parent(t_msh *msh, int i, int cmd_count)
{ {
if (msh->fds[i][0] > 2) if (msh->fds[i][0] > 2)
{ {
fprintf(stderr, "closing fd %d in parent\n", msh->fds[i][0]); //fprintf(stderr, "closing fd %d in parent\n", msh->fds[i][0]);
close(msh->fds[i][0]); close(msh->fds[i][0]);
} }
if (msh->fds[i][1] > 2) if (msh->fds[i][1] > 2)
{ {
fprintf(stderr, "closing fd %d in parent\n", msh->fds[i][1]); //fprintf(stderr, "closing fd %d in parent\n", msh->fds[i][1]);
close(msh->fds[i][1]); close(msh->fds[i][1]);
} }
} }
if (msh->in_fd > 2) if (msh->in_fd > 2)
{ {
fprintf(stderr, "closing in_fd %d in parent\n", msh->in_fd); //fprintf(stderr, "closing in_fd %d in parent\n", msh->in_fd);
close(msh->in_fd); close(msh->in_fd);
} }
if (msh->out_fd > 2) if (msh->out_fd > 2)
{ {
fprintf(stderr, "closing in_fd %d in parent\n", msh->out_fd); //fprintf(stderr, "closing in_fd %d in parent\n", msh->out_fd);
close(msh->out_fd); close(msh->out_fd);
} }
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/09 18:31:21 by tomoron #+# #+# */ /* Created: 2024/02/09 18:31:21 by tomoron #+# #+# */
/* Updated: 2024/02/21 12:47:39 by marde-vr ### ########.fr */ /* Updated: 2024/04/18 20:48:59 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */ /* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
/* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:57:35 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -60,21 +60,21 @@ int set_echoctl(int value)
//ft_printf("echoctl value : %d\n",value); //ft_printf("echoctl value : %d\n",value);
if (tcgetattr(1, &t_p)) if (tcgetattr(1, &t_p))
{ {
fprintf(stderr, "minishell: an error occured while getting the local fl\ //fprintf(stderr, "minishell: an error occured while getting the local fl\
ags\n"); //ags\n");
return (1); return (1);
} }
if (((t_p.c_lflag & ECHOCTL) != 0) == value) if (((t_p.c_lflag & ECHOCTL) != 0) == value)
return (0); return (0);
ft_printf("change\n"); //ft_printf("change\n");
if (value) if (value)
t_p.c_lflag = t_p.c_lflag | ECHOCTL; t_p.c_lflag = t_p.c_lflag | ECHOCTL;
else else
t_p.c_lflag = t_p.c_lflag & (~ECHOCTL); t_p.c_lflag = t_p.c_lflag & (~ECHOCTL);
if (tcsetattr(1, TCSANOW, &t_p)) if (tcsetattr(1, TCSANOW, &t_p))
{ {
fprintf(stderr, "minishell: an error occured while setting the local fl\ //fprintf(stderr, "minishell: an error occured while setting the local fl\
ags\n"); //ags\n");
return (1); return (1);
} }
return (0); return (0);

View File

@ -6,22 +6,22 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */ /* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/17 09:12:33 by tomoron #+# #+# */ /* Created: 2024/04/17 09:12:33 by tomoron #+# #+# */
/* Updated: 2024/04/17 10:42:39 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:49:00 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int wildcard_cmp(char *s1, char *s2, char *order) int wildcard_cmp(char *s1, char *s2, char *order)
{ {
while(*s1 && *s2) while (*s1 && *s2)
{ {
while(*s1 && !ft_isalnum(*s1)) while (*s1 && !ft_isalnum(*s1))
s1++; s1++;
while(*s2 && !ft_isalnum(*s2)) while (*s2 && !ft_isalnum(*s2))
s2++; s2++;
if(*s1 != *s2) if (*s1 != *s2)
return ((ft_strchr(order, *s2) - order) - (ft_strchr(order, *s1)\ return ((ft_strchr(order, *s2) - order) - (ft_strchr(order, *s1)
- order)); - order));
s1++; s1++;
s2++; s2++;
@ -31,18 +31,19 @@ int wildcard_cmp(char *s1, char *s2, char *order)
void sort_wildcards_token(t_token *list) void sort_wildcards_token(t_token *list)
{ {
t_token *tmp; t_token *tmp;
t_token *start; t_token *start;
char *swap; char *swap;
tmp = list; tmp = list;
start = list; start = list;
while(tmp) while (tmp)
{ {
list = start; list = start;
while(list->next) while (list->next)
{ {
if(wildcard_cmp(list->value, list->next->value, "zZyYxXwWvVuUtTsSrRqQpPoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA9876543210") > 0) if (wildcard_cmp(list->value, list->next->value,
"zZyYxXwWvVuUtTsSrRqQpPoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA9876543210") > 0)
{ {
swap = list->value; swap = list->value;
list->value = list->next->value; list->value = list->next->value;

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */ /* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */
/* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:49:01 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,7 +26,7 @@ void free_msh(t_msh *msh)
void ft_exit(t_msh *msh, int exit_code) void ft_exit(t_msh *msh, int exit_code)
{ {
ft_printf("exiting"); //ft_printf("exiting");
free_msh(msh); free_msh(msh);
exit(exit_code); exit(exit_code);
} }

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 17:19:27 by tomoron #+# #+# */ /* Created: 2024/03/27 17:19:27 by tomoron #+# #+# */
/* Updated: 2024/04/02 17:16:06 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:49:00 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,22 +19,22 @@ t_token *parsing_syntax_error(t_token *res)
return (0); return (0);
} }
int is_input_type(t_cmd *cmd) int is_input_type(t_cmd *cmd)
{ {
return(cmd->cmd_type == HERE_DOC || cmd->cmd_type == RED_I); return (cmd->cmd_type == HERE_DOC || cmd->cmd_type == RED_I);
} }
int is_output_type(t_cmd *cmd) int is_output_type(t_cmd *cmd)
{ {
return(cmd->cmd_type == RED_O || cmd->cmd_type == RED_O_APP); return (cmd->cmd_type == RED_O || cmd->cmd_type == RED_O_APP);
} }
int is_cmd_type(t_cmd *cmd) int is_cmd_type(t_cmd *cmd)
{ {
return(cmd->cmd_type == CMD || cmd->cmd_type == PAREN); return (cmd->cmd_type == CMD || cmd->cmd_type == PAREN);
} }
int is_operand_type(t_cmd *cmd) int is_operand_type(t_cmd *cmd)
{ {
return(cmd->cmd_type == AND || cmd->cmd_type == OR); return (cmd->cmd_type == AND || cmd->cmd_type == OR);
} }

View File

@ -6,79 +6,80 @@
/* 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/17 10:16:33 by tomoron ### ########.fr */ /* Updated: 2024/04/18 20:48:39 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int filename_corresponds(char *wildcard, char *value) int filename_corresponds(char *wildcard, char *value)
{ {
if(*value == '.' && *wildcard != '.') if (*value == '.' && *wildcard != '.')
return(0); return (0);
while(*wildcard && (*wildcard == '*' || *wildcard == *value)) while (*wildcard && (*wildcard == '*' || *wildcard == *value))
{ {
if(*wildcard == '*') if (*wildcard == '*')
{ {
while(*wildcard && *value && *value != wildcard[1] && *wildcard != wildcard[1]) while (*wildcard && *value && *value != wildcard[1]
&& *wildcard != wildcard[1])
value++; value++;
wildcard++; wildcard++;
} }
while(*wildcard && *value && *value == *wildcard && *wildcard != '*') while (*wildcard && *value && *value == *wildcard && *wildcard != '*')
{ {
wildcard++; wildcard++;
value++; value++;
} }
} }
return(!*wildcard && !*value); return (!*wildcard && !*value);
} }
t_token *get_all_files(DIR *dir, char *wildcard) t_token *get_all_files(DIR *dir, char *wildcard)
{ {
struct dirent *content; struct dirent *content;
t_token *res; t_token *res;
res = 0; res = 0;
content = readdir(dir); content = readdir(dir);
while(content) while (content)
{ {
if(filename_corresponds(wildcard, content->d_name)) if (filename_corresponds(wildcard, content->d_name))
res = token_add_back(res,ft_strdup(content->d_name)); res = token_add_back(res, ft_strdup(content->d_name));
content = readdir(dir); content = readdir(dir);
} }
return(res); return (res);
} }
t_token *wildcards_add_back(t_token *res, t_token *next) t_token *wildcards_add_back(t_token *res, t_token *next)
{ {
if(!res) if (!res)
return(next); return (next);
while(res->next) while (res->next)
res = res->next; res = res->next;
res->next = next; res->next = next;
return(res); return (res);
} }
t_token *expand_wildcards(t_token *res, char *value) t_token *expand_wildcards(t_token *res, char *value)
{ {
DIR *dir; DIR *dir;
char *cwd; char *cwd;
t_token *new; t_token *new;
if(!ft_strchr(value, '*')) if (!ft_strchr(value, '*'))
return(token_add_back(res, value)); return (token_add_back(res, value));
cwd = getcwd(NULL, 100000); cwd = getcwd(NULL, 100000);
if(!cwd) if (!cwd)
return(token_add_back(res, value)); return (token_add_back(res, value));
dir = opendir(cwd); dir = opendir(cwd);
free(cwd); free(cwd);
if(!dir) if (!dir)
return(token_add_back(res, value)); return (token_add_back(res, value));
new = get_all_files(dir, value); new = get_all_files(dir, value);
closedir(dir); closedir(dir);
if(!new) if (!new)
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 = wildcards_add_back(res, new);
return(res); return (res);
} }

View File

@ -2,3 +2,6 @@ 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
exec export in fork when piped
here doc in fork