Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ #
# By: dayano <dayano@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2025/04/03 12:55:20 by ttsubo #+# #+# #
# Updated: 2025/04/26 11:30:48 by ttsubo ### ########.fr #
# Updated: 2025/04/29 16:48:58 by dayano ### ########.fr #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -45,9 +45,10 @@ define define_rule
endef

# 2.Add the source code when it is added
ROOT_SRC = main.c minish_signal.c initialize.c
ROOT_SRC = main.c minish_signal.c initialize.c error.c
INVOKE_CMD_SRC = create_envp.c exec_pipeline.c execute_cmd.c \
execute_cmd_helper.c invoke_command.c pipeline_helper.c
execute_cmd_helper.c invoke_command.c pipeline_helper.c \
redirect.c fds.c wait_pipeline.c
TOKENIZER_SRC = tokenizer.c tokenizer_error.c read_token.c \
is_quote_closed.c get_token_capa.c is_redirect_validate.c
PARSER_SRC = allocate_cmds.c parser.c parser_utils.c setup_cmds.c \
Expand Down
10 changes: 6 additions & 4 deletions inc/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
/* ::: :::::::: */
/* cmd.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ */
/* By: dayano <dayano@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/13 13:47:36 by ttsubo #+# #+# */
/* Updated: 2025/04/14 21:30:15 by ttsubo ### ########.fr */
/* Updated: 2025/04/29 16:53:33 by dayano ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef CMD_H
# define CMD_H

# include <unistd.h>

typedef enum e_redir_type
{
REDIR_NONE,
Expand All @@ -29,8 +31,8 @@ typedef struct s_cmd
char **argv;
int capa;
int status;
int pid;
pid_t pid;
struct s_cmd *next;
} t_cmd;

#endif
#endif
18 changes: 18 additions & 0 deletions inc/error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* error.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dayano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/29 13:48:47 by dayano #+# #+# */
/* Updated: 2025/04/29 14:35:12 by dayano ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef ERROR_H
# define ERROR_H

void print_error(char *cmd_or_path);

#endif
8 changes: 7 additions & 1 deletion inc/exec_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: dayano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/21 13:12:27 by dayano #+# #+# */
/* Updated: 2025/04/24 14:17:43 by dayano ### ########.fr */
/* Updated: 2025/04/29 16:11:28 by dayano ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -15,6 +15,12 @@

# include "cmd.h"

typedef struct s_pipe_io
{
int prev_fds[2];
int curr_fds[2];
} t_pipe_io;

void exec_pipeline(t_cmd *cmd_head, t_minish *minish);
int wait_pipeline(t_cmd *cmd_head);

Expand Down
4 changes: 3 additions & 1 deletion inc/execute_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: dayano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/21 21:39:18 by dayano #+# #+# */
/* Updated: 2025/04/28 12:00:45 by dayano ### ########.fr */
/* Updated: 2025/04/28 13:56:33 by dayano ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -15,6 +15,8 @@

# define PATH_PREFIX_LEN 5
# define EQUAL_LEN 1

# define CMD_FAILED_EXIT_STATUS 126
# define CMD_NOT_FOUND_EXIT_STATUS 127

void execute_cmd(t_cmd *cmd, t_minish *minish);
Expand Down
15 changes: 13 additions & 2 deletions inc/invoke_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,26 @@
/* By: dayano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/20 21:21:13 by dayano #+# #+# */
/* Updated: 2025/04/21 21:00:48 by dayano ### ########.fr */
/* Updated: 2025/04/29 16:47:04 by dayano ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef INVOKE_COMMAND_H
# define INVOKE_COMMAND_H

# include "cmd.h"
# include <stdbool.h>

int invoke_commands(t_cmd *cmd_head, t_minish *minish);
int invoke_commands(t_cmd *cmd_head, t_minish *minish);
int exec_unit_builtin(t_cmd *cmd_head);

// wait_pipeline.c
int wait_pipeline(t_cmd *cmd_head);

// fds.c
void init_fds(int fds[2]);
void cleanup_fds(int fds1[2]);
void swap_fds(int prev_fds[2], int curr_fds[2]);
void create_pipe(bool need, int fds[2], t_cmd *cmd);

#endif
9 changes: 8 additions & 1 deletion inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: dayano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/03 12:50:38 by ttsubo #+# #+# */
/* Updated: 2025/04/28 12:00:56 by dayano ### ########.fr */
/* Updated: 2025/04/29 16:09:27 by dayano ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -19,6 +19,7 @@
# include "create_envp.h"
# include "env_utils.h"
# include "env_utils_2.h"
# include "error.h"
# include "exec_pipeline.h"
# include "execute_cmd.h"
# include "initialize.h"
Expand All @@ -27,13 +28,19 @@
# include "minish_signal.h"
# include "parser.h"
# include "pipeline_helper.h"
# include "redirect.h"
# include "struct.h"
# include "tokenizer.h"
# include <errno.h>
# include <readline/history.h>
# include <readline/readline.h>
# include <stdbool.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <sys/types.h>
# include <sys/wait.h>
# include <sysexits.h>
# include <unistd.h>

#endif
5 changes: 3 additions & 2 deletions inc/pipeline_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
/* By: dayano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/24 14:32:27 by dayano #+# #+# */
/* Updated: 2025/04/24 15:02:17 by dayano ### ########.fr */
/* Updated: 2025/04/28 14:56:23 by dayano ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef PIPELINE_HELPER_H
# define PIPELINE_HELPER_H

# include "cmd.h"
# include <fcntl.h>
# include <stdbool.h>

// pipeline_helper.c
void redirect_stdout(t_cmd *cmd);
bool is_redirect(t_cmd *cmd);
bool is_head(t_cmd *cmd);
bool is_head(t_cmd *cmd, t_cmd *cmd_head);
bool is_tail(t_cmd *cmd);
bool is_builtin(t_cmd *cmd);

Expand Down
22 changes: 22 additions & 0 deletions inc/redirect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redirect.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dayano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/28 15:20:03 by dayano #+# #+# */
/* Updated: 2025/04/28 15:30:35 by dayano ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef REDIRECT_H
# define REDIRECT_H

# include "cmd.h"

void redirect(t_cmd *cmd);
void redirect_stdout(t_cmd *cmd);
void redirect_stdin(t_cmd *cmd);

#endif
30 changes: 30 additions & 0 deletions src/error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* error.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dayano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/29 13:16:23 by dayano #+# #+# */
/* Updated: 2025/04/29 14:33:57 by dayano ### ########.fr */
/* */
/* ************************************************************************** */

#include "main.h"

/**
* @brief print error
* format: minish: <cmd>: <error msg>
*
* @param cmd_or_path
*/
void print_error(char *cmd_or_path)
{
char *error_msg;

error_msg = strerror(errno);
ft_putstr_fd("minish: ", STDERR_FILENO);
ft_putstr_fd(cmd_or_path, STDERR_FILENO);
ft_putstr_fd(": ", STDERR_FILENO);
ft_putendl_fd(error_msg, STDERR_FILENO);
}
Loading