Overview
Minishell is organized into logical modules, each handling specific aspects of shell functionality. The project contains 24 source files, 1 header file, and follows the 42 school coding standards.File Tree
Module Breakdown
Main and Initialization
Main and Initialization
main.c
Purpose: Entry point and main REPL (Read-Eval-Print Loop)Key Functions:main()- Initializes shell and runs the main loop (line 97)enterdata()- Processes each command line (line 17)asignenvp()- Copies environment variables to linked list (line 59)init_data()- Initializes the main data structure (line 84)
g_status- Last command exit status (line 15)
init_shell.c
Purpose: Shell initialization and built-in command routingKey Functions:execute_builtin()- Routes commands to appropriate built-in (line 118)fork_actions()- Handles env and export commands (line 64)other_actions()- Handles echo, pwd, cd, unset (line 93)export()- Implements export built-in (line 35)
Parsing Module
Parsing Module
parse_imput.c
Purpose: Input validation and quote handlingKey Functions:remove_quotes()- Strips quotes from parsed arguments (line 13)detectopenquotes()- Validates quote pairing (line 14)check_wrong_pipes()- Validates pipe syntax (line 15)check_wrong_redir()- Validates redirection syntax (line 16)
more_parsing.c
Purpose: Advanced parsing and input preparationKey Functions:prepare_line()- Preprocesses input for parsing (line 19)ft_more_checkers()- Additional syntax validation (line 20)ft_check_input()- Main input validation entry point (line 21)
split.c
Purpose: String splitting with shell-aware tokenizationKey Functions:ft_split()- Standard string splitting (line 84)ft_splitquotes()- Quote-aware string splitting (line 85)ft_num_word()- Counts words respecting quotes (line 86)
split_utils.c
Purpose: Splitting helper utilitiesKey Functions:free_split()- Frees split arrays (line 89)ft_count_splits()- Counts split elements (line 90)
Execution Module
Execution Module
ft_execute_commands.c
Purpose: Main command execution orchestrationKey Functions:ft_execute_commands()- Main execution entry point (line 97)excecute_pipe_sequence()- Handles piped commands (line 68)child_process()- Sets up child process I/O (line 41)child_execution()- Executes command in child (line 15)
- Single command without pipes → Execute directly or as built-in
- Multiple commands with pipes → Create pipe chain
- Fork child processes for each command
- Set up file descriptors and redirections
- Execute via
execve()or built-in function
ft_execute_one_command.c
Purpose: Single command executionKey Functions:execute_simple_command()- Executes non-piped commands (line 156)prepare_builtin()- Prepares built-in execution environment (line 155)
ft_prepare_nodes.c
Purpose: Command node preparation and setupKey Functions:ft_prepare_nodes()- Creates execution nodes from parsed input (line 133)
Built-in Commands
Built-in Commands
builtins.c
Purpose: Core built-in command implementationsImplemented Commands:echo()- Prints arguments with optional newline (line 87)pwd()- Prints current working directory (line 55)cd()- Changes directory (line 70)unset()- Removes environment variables (line 42)remove_env()- Helper for unset (line 15)
builtins_utils.c
Purpose: Built-in command helper functionsKey Functions:ft_lscopy()- Copies environment variable to list (line 99)ft_lstsort()- Sorts environment list (export display) (line 100)dup_env()- Duplicates environment list (line 101)check_env_name()- Validates environment variable names (line 102)asign_env_value()- Assigns or updates environment values (line 103)
exit.c
Purpose: Exit command implementationKey Functions:ft_exit()- Handles shell exit with status code (line 110)
Environment Variables
Environment Variables
env_parsed.c
Purpose: Environment variable expansionKey Functions:vars()- Main variable expansion function (line 159)env_split()- Splits environment strings (line 160)ft_itoa()- Converts integers to strings (for$?) (line 161)
$VAR- Environment variable expansion$?- Last exit status- Variable expansion in double quotes
env_parsed2.c
Purpose: Additional environment parsing utilitiesKey Functions:ft_asign_rare_value()- Handles special variable cases (line 164)ft_check_dolar_length()- Measures variable name length (line 165)ft_check_dolars()- Detects dollar signs in input (line 166)ft_check_for_quotes()- Tracks quote context during parsing (line 167)ft_checkvar_value()- Retrieves variable value (line 168)
Path Resolution
Path Resolution
set_bin_path.c
Purpose: Extracts and parses PATH environment variableKey Functions:set_bin_path()- Parses PATH into array of directories (line 149)
set_full_cmd_path.c
Purpose: Resolves command to full executable pathKey Functions:set_full_path()- Finds executable in PATH (line 139)set_full_cmd()- Constructs full command array (line 140)
- Absolute path (
/bin/ls) - Relative path (
./program) - PATH search (
ls→/bin/ls)
set_infile_outfile.c
Purpose: File descriptor setup for redirectionsKey Functions:set_infile_outfile()- Opens files for<and>(line 143)get_here_doc()- Implements here-document (<<) (line 145)ft_create_temp()- Creates temporary file for here-docs (line 152)
<- Input redirection>- Output redirection (truncate)>>- Output redirection (append)<<- Here-document (reads until delimiter)
Signal Handling
Signal Handling
signals.c
Purpose: Manages Unix signalsKey Functions:setup_signals()- Initializes signal handlers (line 25)handle_sigint()- Handles Ctrl+C (SIGINT) (line 15)
SIGINT(Ctrl+C): Clears line, displays new promptSIGQUIT(Ctrl+): Ignored in interactive mode
Utility Functions
Utility Functions
utils.c
Purpose: String manipulation and linked list operationsKey Functions:ft_strncmp()- String comparison (line 64)ft_strlen()- String length (line 65)ft_strlcpy()- Safe string copy (line 66)ft_strjoin()- String concatenation (line 67)ft_memcpy()- Memory copy (line 68)ft_lstsort(),ft_lstadd_back(),ft_lstlast(),ft_lstnew()- List operations
utils2.c
Purpose: Additional string and utility functionsLocated at:utils2.cutils3.c
Purpose: Memory management and conversionKey Functions:ft_calloc()- Allocates and zeros memory (line 77)ft_free()- Frees string arrays (line 78)ft_free_stack()- Frees linked lists (line 79)ft_isdigit()- Digit validation (line 80)ft_atoi()- String to integer conversion (line 81)
ft_count_pipes.c
Purpose: Pipe analysis and command segmentationKey Functions:ft_count_pipes()- Counts pipes in command (line 128)ft_strdup2()- Duplicates command segments (line 129)ft_len_to_pipe()- Measures distance to next pipe (line 130)
ft_print_prompt.c
Purpose: Prompt generation and displayKey Functions:print_logo()- Displays startup logo (line 175)ft_print_user()- Generates user prompt string (line 176)
COLOR_AZUL: BlueGREEN: GreenMAGENTA: MagentaRST: Reset
Header File Structure
minishell.h
The main header contains: Includes:- Standard libraries:
unistd.h,stdio.h,stdlib.h,fcntl.h - System:
sys/stat.h,sys/types.h,sys/wait.h - Readline:
readline/readline.h,readline/history.h - Signal handling:
signal.h - Directory operations:
dirent.h
- Color macros for terminal output (lines 27-30)
TEMP_FILEconstant for here-documents (line 32)
t_prompt- Environment variable linked list nodet_node- Command execution nodet_mini- Main shell data structure
extern int g_status- Shared exit status (line 178)
Naming Conventions
42 School Style
The project follows 42 school conventions:- Functions:
snake_casewithft_prefix for custom implementations- Example:
ft_strlen(),ft_split(),ft_execute_commands()
- Example:
- Structures:
typedef struct s_namewitht_namealias- Example:
typedef struct s_mini→t_mini
- Example:
- Variables:
snake_case- Example:
full_cmd,nbr_nodes,bin_path
- Example:
- Constants:
UPPER_SNAKE_CASE- Example:
TEMP_FILE,COLOR_AZUL
- Example:
File Headers
All files include 42 school header comment blocks:Code Organization Principles
- Modular Design: Each file focuses on a specific functionality
- Clear Separation: Parsing, execution, and I/O are separate modules
- Utility Functions: Common operations centralized in utils files
- Header Organization: All public interfaces in single header
- 42 Norm Compliance: Follows 42 school coding standards
Next Steps
- Learn how to build the project
- Understand how to contribute code
- Explore built-in commands implementation details