How 0xysan/minishell works
This project is a custom shell – a “minishell” – implemented for the 42 Cursus. Its purpose is to provide a command-line interpreter with command execution, built-in commands (like cd, echo, exit, etc.), environment manipulation, support for pipes and redirection, and proper signal handling.
Project Type & Purpose
• It as a command line shell (minishell) where the user inputs commands, which are parsed, executed (with support for built-in commands and external binaries), and managed with proper I/O redirection and signals.
• The README confirms features such as command execution with arguments, piping/redirection, environment handling, and signal management.
Main Components
a. Main Program & Core Loop:
• It initiating the main loop: reading user input, processing the commands, and dispatching tasks.
b. Command Parsing & Preprocessing:
• "process_input" directory that contains modules (handles.c, preprocess_input.c, preprocess_utils.c) responsible for analyzing and tokenizing the user’s command input.
c. Command Execution:
• "cmds_exec" directory which implements functions to execute parsed commands using functions found in cmds_execute.c, cmds_handler.c, exec_input.c, and exec_utils.c.
• Also, include the "ft_cmds" directory where built-in commands are defined (e.g., ft_cd.c, ft_echo.c, ft_exit.c, ft_export.c).
d. Environment Variable Management:
e. I/O and Formatting Utilities:
• "ft_dprintf" directory for custom formatted output routines, and the "libft" directory which provides a set of common utility functions used throughout the project.
f. Pipes, File Descriptors & Redirection Support:
g. Signal Handling:
• "sig_n_utils" module as a separate component that encapsulates the signal handling logic (sighandler.c, utils.c, utils2.c).
Relationships & Interactions
• The Main Program (main.c) should be connected to the Command Parsing module ("process_input"), indicating the control flow where raw user input is processed.
• Parsed commands are then dispatched to the Command Execution modules ("cmds_exec" for external command execution and "ft_cmds" for built-in functions).
• Environment management ("ft_env") interacts with built-in commands and command execution for preserving system state.
• The pipes and file descriptor module ("pipes_n_fds") interacts with command execution, especially for handling inter-process communication when piping is involved.
• The signal handling component ("sig_n_utils") overlays atop the overall flow, capturing signals (like Ctrl+C/Ctrl+D) and relaying them to the main loop or command execution as needed.
Architectural Patterns & Design Principles
• The separation of concerns is evident: input processing, command execution, environment handling, and signal management are all isolated.
• Use of modular design is highlighted by splitting functionality into dedicated directories.
• Dependency management – common libraries (libft and ft_dprintf) are abstracted to avoid redundancy.