How simoxeur/pipex works
Project Type and Purpose
• This is a small, monolithic C command‐line tool (“pipex”) whose sole purpose is to emulate UNIX shell pipelines and redirections (pipe, fork, dup2, execve).
• Mandatory part handles a two‐command pipeline; bonus part extends to N commands and “here_doc” mode using get_next_line.
High‐Level Architecture
At a glance, the system consists of:
• CLI Layer: Parses arguments (main.c)
• Pipeline Manager: Builds one or more pipes, handles “here_doc” logic (pipex.h, execution.c, ft_fork.c, here_doc_bonus.c)
• Execution Engine: Spawns child processes with proper file descriptors and runs commands via execve
• Utility Library: String manipulation, error handling, array management (utils/*.c, utils.h)
• I/O Helper (Bonus): Line reading for here‐document functionality (get_next_line_bonus.c)
• OS Kernel (External): Underlying pipe/fork/dup2/execve system calls and spawned command binaries
Components and Their Relationships
A. User CLI Input
→ passes: file1, [cmd1 … cmdn], file2 or here_doc LIMITER cmd… file
B. Argument Parser (main.c)
→ validates args, selects mandatory vs bonus flow
C. Pipeline Builder / Controller
→ for each command:
• Creates a new pipe (pipe())
• Duplicates fds (dup2)
• Optionally reads limiter lines with get_next_line (bonus)
D. Execution Engine (execution.c, ft_fork.c)
→ forks processes, calls execve with correct stdin/stdout
E. Utility Library (utils/*.c)
→ string splitting (to parse “cmd –options”), path resolution (ft_find_path), error printing, memory management
F. External Commands & Files
← execve loads external binaries; reads file1 or here_doc input; writes to file2
Architectural Patterns and Principles
• Layered Design: Clear separation between parsing, orchestration, execution, and utilities
• Single Responsibility: Each .c/.h pair focuses on one domain (e.g., pipes vs. string utils)
Essential Details to Capture
• The loop over N commands in the bonus version (multiple pipes)
• The special “here_doc” branch that reads from stdin until a LIMITER
• How file descriptors are opened, duplicated, and closed (utils/close_fds.c)
• Shared utility functions for string splitting and path resolution