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
33 changes: 24 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
# By: ttsubo <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2025/04/03 12:55:20 by ttsubo #+# #+# #
# Updated: 2025/05/02 22:01:21 by ttsubo ### ########.fr #
# Updated: 2025/05/04 16:50:59 by ttsubo ### ########.fr #
# #
# **************************************************************************** #

NAME = minishell
CC = cc
MAKEFLAGS += --no-print-directory
W_FLG = -Wall -Wextra -Werror
I_FLG = -Iinc/ -Ilib/libft/
L_FLG = -lreadline -lft

HEADER_DIRS = lib/libft/ inc/ inc/builtin/ inc/common/ \
inc/invoke_cmd/ inc/parser/ inc/signal/ inc/tokenizer/
I_FLG = $(addprefix -I, $(HEADER_DIRS))

# 1.Add more directories as they are added.
SRC_DIR = src/
PARSER_SRC_DIR = src/parser/
Expand Down Expand Up @@ -45,6 +48,16 @@ define define_rule
$(CC) $(W_FLG) $(I_FLG) -c $$< -o $$@)
endef

TMP_LOG := .tmp_build.log

define run_step
@echo -n "$(1)... "
@($(2) > /dev/null 2>$(TMP_LOG)) \
&& echo "✅" \
|| (echo "❌" && cat $(TMP_LOG))
@rm -f $(TMP_LOG)
endef

# 2.Add the source code when it is added
ROOT_SRC = main.c minish_signal.c initialize.c error.c
COMMON_SRC = validate_key.c error_mes.c
Expand Down Expand Up @@ -74,10 +87,10 @@ TEST=MAIN
all: $(NAME)

$(NAME): $(FT_DIR)$(LIBFT) $(OBJS)
$(CC) $(W_FLG) $(OBJS) -L$(FT_DIR) $(L_FLG) -o $(NAME)
$(call run_step,Building $@, $(CC) $(W_FLG) $(OBJS) -L$(FT_DIR) $(L_FLG) -o $(NAME))

$(FT_DIR)$(LIBFT):
$(MAKE) -C $(FT_DIR)
$(call run_step,Building libft, $(MAKE) -C $(FT_DIR))

$(foreach DIR,$(MODULE_DIRS), \
$(if $(filter $(DIR),root), \
Expand All @@ -87,14 +100,16 @@ $(foreach DIR,$(MODULE_DIRS), \
)

clean:
$(MAKE) -C $(FT_DIR) clean
[ -d $(OBJ_DIR) ] && find $(OBJ_DIR) -type f -name '*.o' -exec rm -f {} + || true
[ -d $(OBJ_DIR) ] && find $(OBJ_DIR) -type d -empty -not -name '.' -exec rmdir {} + || true
$(call run_step,cleaning libft, $(MAKE) -C $(FT_DIR) clean)
$(call run_step,cleaning $(NAME) objs, \
[ -d $(OBJ_DIR) ] && find $(OBJ_DIR) -type f -name '*.o' -exec rm -f {} + || true)
$(call run_step,cleaning $(NAME) empty dirs, \
[ -d $(OBJ_DIR) ] && find $(OBJ_DIR) -type d -empty -not -name '.' -exec rmdir {} + || true)

fclean:
$(MAKE) -C $(FT_DIR) fclean
$(call run_step,Removing libft bin, $(MAKE) -C $(FT_DIR) fclean)
$(MAKE) clean
rm -rf $(NAME)
$(call run_step,Removing binary, rm -rf $(NAME))

re:
$(MAKE) fclean
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 8 additions & 1 deletion inc/env_utils.h → inc/builtin/env_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ttsubo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/17 10:25:47 by dayano #+# #+# */
/* Updated: 2025/04/28 15:47:53 by ttsubo ### ########.fr */
/* Updated: 2025/05/04 12:14:29 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -17,5 +17,12 @@

void free_env_content(char *value);
void remove_env_node(t_env **env_lst, t_env *target);
void free_env_list(t_env *head);
void cleanup_minish(t_minish *minish);
void handle_error_and_exit(const char *func_name, t_minish *minish);
void add_env_back(t_env **lst, t_env *new);
t_env *get_env_node(t_env *current, const char *key);
char *get_env_value(t_env *current, const char *key);
bool has_env_key(t_env *current, const char *key);

#endif
4 changes: 2 additions & 2 deletions inc/expand_env.h → inc/builtin/expand_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
/* By: ttsubo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/26 11:24:25 by ttsubo #+# #+# */
/* Updated: 2025/04/29 11:45:55 by ttsubo ### ########.fr */
/* Updated: 2025/05/04 12:15:01 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef EXPAND_ENV_H
# define EXPAND_ENV_H

# include "common.h"
# include "env_utils_3.h"
# include "env_utils.h"
# include "struct.h"
# include <stdbool.h>

Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion inc/common.h → inc/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ttsubo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/29 11:44:19 by ttsubo #+# #+# */
/* Updated: 2025/04/29 14:12:51 by ttsubo ### ########.fr */
/* Updated: 2025/05/04 12:18:40 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -16,6 +16,10 @@
# include <stdbool.h>
# include <stddef.h>
# include "libft.h"
# include "cmd.h"
# include "error.h"
# include "initialize.h"
# include "struct.h"

bool is_key_start(int c);
bool is_key_char(int c);
Expand Down
6 changes: 4 additions & 2 deletions inc/error.h → inc/common/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
/* ::: :::::::: */
/* error.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dayano <dayano@student.42.fr> +#+ +:+ +#+ */
/* By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/29 13:48:47 by dayano #+# #+# */
/* Updated: 2025/04/29 14:35:12 by dayano ### ########.fr */
/* Updated: 2025/05/04 12:20:34 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef ERROR_H
# define ERROR_H
# include <errno.h>
# include <string.h>

void print_error(char *cmd_or_path);

Expand Down
File renamed without changes.
File renamed without changes.
22 changes: 0 additions & 22 deletions inc/env_utils_2.h

This file was deleted.

23 changes: 0 additions & 23 deletions inc/env_utils_3.h

This file was deleted.

8 changes: 6 additions & 2 deletions inc/create_envp.h → inc/invoke_cmd/create_envp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
/* ::: :::::::: */
/* create_envp.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dayano <dayano@student.42.fr> +#+ +:+ +#+ */
/* By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/24 13:58:03 by dayano #+# #+# */
/* Updated: 2025/04/24 13:59:24 by dayano ### ########.fr */
/* Updated: 2025/05/04 12:26:30 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef CREATE_ENVP_H
# define CREATE_ENVP_H

# define EQUAL_LEN 1

# include "libft.h"
# include "struct.h"
# include <stdlib.h>

char **create_envp(t_minish *minish);

Expand Down
11 changes: 9 additions & 2 deletions inc/exec_pipeline.h → inc/invoke_cmd/exec_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
/* ::: :::::::: */
/* exec_pipeline.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dayano <dayano@student.42.fr> +#+ +:+ +#+ */
/* By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/21 13:12:27 by dayano #+# #+# */
/* Updated: 2025/04/29 16:11:28 by dayano ### ########.fr */
/* Updated: 2025/05/04 12:33:03 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef EXEC_PIPELINE_H
# define EXEC_PIPELINE_H

# include "cmd.h"
# include "common.h"
# include "execute_cmd.h"
# include "invoke_command.h"
# include "pipeline_helper.h"
# include "struct.h"
# include "redirect.h"
# include <sysexits.h>

typedef struct s_pipe_io
{
Expand Down
5 changes: 2 additions & 3 deletions inc/execute_cmd.h → inc/invoke_cmd/execute_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
/* ::: :::::::: */
/* execute_cmd.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dayano <dayano@student.42.fr> +#+ +:+ +#+ */
/* By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/21 21:39:18 by dayano #+# #+# */
/* Updated: 2025/04/28 13:56:33 by dayano ### ########.fr */
/* Updated: 2025/05/04 13:15:50 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef EXECUTE_CMD_H
# define EXECUTE_CMD_H

# define PATH_PREFIX_LEN 5
# define EQUAL_LEN 1

# define CMD_FAILED_EXIT_STATUS 126
# define CMD_NOT_FOUND_EXIT_STATUS 127
Expand Down
10 changes: 8 additions & 2 deletions inc/invoke_command.h → inc/invoke_cmd/invoke_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
/* ::: :::::::: */
/* invoke_command.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dayano <dayano@student.42.fr> +#+ +:+ +#+ */
/* By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/20 21:21:13 by dayano #+# #+# */
/* Updated: 2025/05/01 16:38:55 by dayano ### ########.fr */
/* Updated: 2025/05/04 12:37:03 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef INVOKE_COMMAND_H
# define INVOKE_COMMAND_H

# include "cmd.h"
# include "create_envp.h"
# include "exec_pipeline.h"
# include "execute_cmd.h"
# include "pipeline_helper.h"
# include "redirect.h"
# include <wait.h>
# include <stdbool.h>

int invoke_commands(t_cmd *cmd_head, t_minish *minish);
Expand Down
File renamed without changes.
File renamed without changes.
28 changes: 3 additions & 25 deletions inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,23 @@
/* ::: :::::::: */
/* main.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dayano <dayano@student.42.fr> +#+ +:+ +#+ */
/* By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/03 12:50:38 by ttsubo #+# #+# */
/* Updated: 2025/04/29 16:09:27 by dayano ### ########.fr */
/* Updated: 2025/05/04 12:26:20 by ttsubo ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef MAIN_H
# define MAIN_H

# include "builtin.h"
# include "builtin_utils.h"
# include "cmd.h"
# include "create_envp.h"
# include "env_utils.h"
# include "env_utils_2.h"
# include "env_utils_3.h"
# include "error.h"
# include "exec_pipeline.h"
# include "execute_cmd.h"
# include "initialize.h"
# include "common.h"
# include "invoke_command.h"
# include "libft.h"
# 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
File renamed without changes.
File renamed without changes.
File renamed without changes.