- Building and Running
- Basic Commands
- Commands with Redirection
- Support for cd
- Commands with Pipes
- Batched Commands
- Proposed Extension 1: Subshells
- Proposed Extension 2: Nested Subshells
- Further Enhancements
- Testing
- Code Quality
gcc -Wall -Wextra -g s3main.c s3.c jobs.c lexer_fsm.c terminal_control.c -o s3./s3./run_tests.shStatus: ✅ Fully Implemented
launch_program()- Forks and launches basic commandschild()- Executesexecvp()in child processparse_command()- Tokenizes command line using custom FSM lexer
Status: ✅ Fully Implemented
launch_program_with_redirection()- Handles commands with redirectionchild_with_output_redirected()- Redirects stdout to filechild_with_input_redirected()- Redirects stdin from filefind_redirection_in_line()- Detects redirection operators
Status: ✅ Fully Implemented
run_cd()- Changes directory usingchdir()is_cd()- Detects cd commandsconstruct_shell_prompt()- Updates prompt with current directory
Status: ✅ Fully Implemented
launch_pipeline()- Manages multi-stage pipelinescommand_has_pipes()- Detects pipe operatorssplit_pipeline()- Tokenizes pipeline stagesfind_redirection_operator()- Handles redirection within pipelines
- Single-stage pipes (
cmd1 | cmd2) - Multi-stage pipes (
cmd1 | cmd2 | cmd3 | ...)
Status: ✅ Fully Implemented
process_input()- Parses and executes batched commandstrim_whitespace()- Cleans up command tokens
- Sequential execution of multiple commands
- Independent execution (failure of one doesn't stop others)
- Works with pipes, redirection, and subshells
- Proper parenthesis tracking for subshells
Status: ✅ Fully Implemented
run_subshell()- Forks and executes subshellis_subshell()- Detects subshell syntax
Status: ✅ Fully Implemented
process_input()- Tracks parenthesis depth for nested subshellsrun_subshell()- Recursively handles nested subshells
- Unlimited nesting depth
- Proper parenthesis matching
- Recursive execution model
- Isolation at each level
- Background job execution with
& - Job listing with
jobscommand - Foreground job control with
fg [job_id] - Background job continuation with
bg [job_id] - Job state tracking (RUNNING, STOPPED)
- Process group management
- Signal handling (SIGINT, SIGTSTP, SIGTTOU, SIGTTIN)
init_jobs()- Initializes job tableadd_job()- Adds job to tracking tableremove_job_by_pgid()- Removes completed jobsfind_job_by_id()- Locates job by IDprint_jobs()- Lists all jobswait_for_job()- Waits for foreground job with WUNTRACED supportput_job_in_foreground()- Brings job to foregroundput_job_in_background()- Resumes job in background
[/home/user s3]$ sleep 30 &
[1] 12345
[/home/user s3]$ jobs
[1] RUNNING sleep 30 &
[/home/user s3]$ fg 1
# Press Ctrl-Z to suspend
[1] STOPPED sleep 30
[/home/user s3]$ bg 1
[1] sleep 30 &
[/home/user s3]$ jobs
[1] RUNNING sleep 30 &- Finite State Machine for robust tokenization
- Quote handling (single and double quotes)
- Escape sequence support (
\) - Operator recognition (|, <, >, >>, ;, (, ), &)
- Whitespace handling
- Error detection and reporting
- Arrow key navigation (up/down for history, left/right for editing)
- Command history with duplicate prevention
- Raw mode terminal control for character-by-character input
- Backspace support with proper cursor positioning
- In-line editing capabilities
enable_raw_mode()- Enables raw terminal mode for immediate character inputdisable_raw_mode()- Restores canonical terminal modeadd_history()- Adds commands to history linked listmove_cursor_left()/move_cursor_right()- Cursor movement controlclear_and_redraw()- Redraws prompt and command line
- Wildcard expansion for
*,?, and[...]patterns - Smart detection - only globs when wildcard characters are present
- Multiple argument globbing support
- Seamless integration with all command types
globbing()- Detects wildcard characters and expands filenames usingglob()
[/home/user s3]$ ls *.c
jobs.c lexer_fsm.c s3.c s3main.c terminal_control.c
[/home/user s3]$ echo *.h
jobs.h lexer_fsm.h s3.h terminal_control.h
[/home/user s3]$ cat s3*.c
# Displays contents of all files matching s3*.cwith full Test coverage
may need manual etsting for ctrlZ and ctrlz

# Run full test suite
./run_tests.sh
# Expected output: All tests passed! (23/23)- s3main.c - Main shell loop and initialization
- s3.c - Core shell functionality
- s3.h - Function declarations and constants
- jobs.c - Job control implementation
- jobs.h - Job control interface
- lexer_fsm.c - FSM-based lexer implementation
- lexer_fsm.h - Lexer interface
- terminal_control.c - Functions for terminal control
- terminal_control.h - Terminal interface
- Implemented most shell functionality except from tab completition.