5.1 KiB
5.1 KiB
Repository Guidelines
Project Structure & Module Organization
src/holds the shell implementation, with submodules forbuiltins/,executor/,parser/, andvariables/.src/builtins/currently includes:cd,echo,env,exit,export,pwd,unset.src/executor/includes pipeline/process orchestration plus file redirections inredirections.c.include/contains public headers used across modules.lib/is populated at build time with third-party 42 libraries (libft, get_next_line, ft_printf, ft_args).docs/stores project references and manual test notes (seedocs/tests.md).build/is the object output directory generated bymake.
Build, Test, and Development Commands
makeormake all: buildminishell(auto-clones required libs intolib/).make clean: remove objects inbuild/.make fclean: remove objects and theminishellbinary (also cleans libs).make re: full rebuild../minishell: run locally after a build.make DEBUG=lldbormake DEBUG=valgrindormake DEBUG=address: rebuild with debug/ASan-friendly flags.
Coding Style & Naming Conventions
- The codebase follows 42 Norminette v4 rules. Run
norminette *.c *.h(or on specific files) before submitting changes. - Keep file names lowercase with underscores (e.g.,
src/builtins/echo/echo.c). - Keep headers in
include/and expose only what modules need. - Before adding or changing code, check
allowed.txtto know which functions are permitted. - Any function not listed in
allowed.txtis not allowed in this project.
Parser & Lexer Functionality (Current src/parser)
- Runtime entrypoint is
parse(line, minishell)fromsrc/minishell.c(readline -> parse -> execute). parsecallslex(line)and then converts token lists tot_commandnodes withparse_tokens.command_newbuilds one command from tokens up toTOKEN_PIPE.words_addstores consecutiveTOKEN_WORDtokens incommand->argvand incrementsargc.expand_envsis currently a TODO (no$VARexpansion is applied in parser stage).- Redirection tokens are converted into
t_redirectionand stored int_command.redirections; heredocs are stored int_command.heredocs. - Path resolution is handled in executor (
executor_resolve_command_path) beforeexecve. src/parser/lexer.cprovides a separate lexer (lex) that tokenizes intoTOKEN_WORD,TOKEN_PIPE,TOKEN_REDIRECT_IN,TOKEN_REDIRECT_OUT,TOKEN_APPEND, andTOKEN_HEREDOC.- The lexer tracks single/double quote context so metacharacters inside quotes remain part of words.
- Meta runs are read as contiguous chunks in
read_token(for example, repeated|/</>are captured as one token value). - Current parser flow consumes lexer output directly.
Executor Redirections (Current src/executor)
- File redirections are applied in
src/executor/redirections.cviaopen+dup2before command execution. - Supported file redirections: input
<, output truncate>, output append>>. - Redirections are applied for both forked commands (child path) and single builtins executed in parent.
- Parent-builtin redirections save/restore
STDIN_FILENOandSTDOUT_FILENOafter builtin execution.
Parser & Lexer Known Gaps
- Heredoc tokens are parsed and stored, but runtime heredoc execution/input feeding is still pending in executor.
- No explicit unmatched-quote syntax error handling is implemented in parser/lexer path.
Testing Guidelines
- There is no automated test runner. Use manual checks in
docs/tests.mdand basic shell behavior checks (pipes, redirects, builtins). - A local builtin edge-case script exists at
tests/builtins_edge_cases.sh(expects a compiled./minishell). - When debugging memory issues, run under valgrind and use the suppression file in
valgrind/readline.supp.
Builtins Status
cd: handlesHOMEfallback,cd -viaOLDPWD, updatesPWD/OLDPWD, and returns failure on invalid usage (too many arguments, missingHOME/OLDPWD).echo: supports repeated-nflags (-n,-nnn) and prints remaining args preserving spaces between tokens.env: prints current environment asKEY=VALUE; returns failure when called with extra arguments.exit: validates numeric argument (with overflow checks), returns1ontoo many argumentswithout exiting, and exits with2on non-numeric argument.export: supportsNAME=VALUEandNAME(stored as empty value), validates identifiers, and returns failure when any identifier is invalid.pwd: prints working directory using dynamicgetcwdand returns failure ifgetcwdfails.unset: validates identifiers and removes matching variables from the environment map.
Commit & Pull Request Guidelines
- Commit messages in this repo use a simple
type: summaryformat (examples:update: ...,fix: ...). Keep summaries short and specific. - For PRs, include:
- What changed and why.
- How to test (commands or manual steps).
- Notes on any parser/executor/builtin behavior changes.
Configuration Tips
- The project depends on
readline; ensure your system haslibreadline-devor equivalent before building.