How ddosoos/mini_shell works
Project Type and Purpose
• This is a monolithic C-language shell implementation (a command-line interpreter).
• Purpose: read user commands (interactive or piped), parse them into a binary-tree AST, and execute them (either built-in functions or external programs) with support for pipes, redirections, logical operators, wildcards, and here-docs.
Main Components
a. Input Handling
• get_next_line (GNL library) – reads lines from stdin or piped input
• Mode Handler – distinguishes interactive vs. non-interactive mode
b. Lexical Analysis (Lexer)
• Tokenizer – splits raw input into tokens (words, operators, quotes)
• Syntax Checker – validates token sequence
c. Parsing (Parser)
• AST Builder – uses a binary tree structure to represent command precedence, pipes, redirections, logical operators, parentheses
d. Execution Engine
• Executor – traverses the AST, forks processes, sets up pipes/redirections
• Built-ins Handler – implements echo, cd, pwd, export, unset, env, exit, history
• External Command Runner – invokes execve for non-built-in commands
• Environment Manager – tracks and manipulates environment variables
• I/O Manager – opens/closes files for <, >, >>, here-docs
• Signal Handler – intercepts Ctrl-C, Ctrl-D, etc.
e. Utility Libraries
• libft – basic C routines (strings, memory, linked lists)
• ft_printf – formatted output
f. Build and Configuration
• Makefile – compiles GNL, libft, ft_printf, and links into minishell
• .gitignore, subject PDF (for reference)
Relationships & Data Flow
• User/Script → GNL → Lexer → Parser → AST
• AST → Executor →
• if built-in: Built-ins Handler
• else: fork + execve (External Runner)
• Executor ↔ Environment Manager (for $VAR, export/unset)
• Executor ↔ I/O Manager (for redirections, here-docs)
• Executor ↔ Signal Handler (for interactive interrupts)
• Executor ↔ Pipes (connect stdout of one process to stdin of next)
• Executor → Output (stdout/stderr to terminal or pipe)
Architectural Patterns & Principles
• Modular layering: Input → Lexing → Parsing → Execution
• AST (binary tree) for operator precedence and grouping
• Separation of concerns: built-ins vs. external commands, environment vs. I/O
• Reuse of custom utility libraries (GNL, libft, ft_printf)