From ff5edf543f69bb0c8c1bda3a05503360783a5174 Mon Sep 17 00:00:00 2001 From: marcnava-42cursus Date: Thu, 12 Feb 2026 20:32:12 +0100 Subject: [PATCH] Updated AGENTS file with redirections options --- AGENTS.md | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 4345c06..3e09296 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -3,6 +3,7 @@ ## Project Structure & Module Organization - `src/` holds the shell implementation, with submodules for `builtins/`, `executor/`, `parser/`, and `variables/`. - `src/builtins/` currently includes: `cd`, `echo`, `env`, `exit`, `export`, `pwd`, `unset`. +- `src/executor/` includes pipeline/process orchestration plus file redirections in `redirections.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 (see `docs/tests.md`). @@ -25,22 +26,25 @@ ## Parser & Lexer Functionality (Current `src/parser`) - Runtime entrypoint is `parse(line, minishell)` from `src/minishell.c` (`readline -> parse -> execute`). -- `parse` splits the input line by unquoted `|` using `extract_next_command` + `find_boundary`. -- Each non-empty segment is trimmed and converted into a `t_command` via `cmdnew`. -- `set_argv` splits by unquoted spaces; quote characters are preserved in the resulting argument text. +- `parse` calls `lex(line)` and then converts token lists to `t_command` nodes with `parse_tokens`. +- `command_new` builds one command from tokens up to `TOKEN_PIPE`. +- `words_add` stores consecutive `TOKEN_WORD` tokens in `command->argv` and increments `argc`. - `expand_envs` is currently a TODO (no `$VAR` expansion is applied in parser stage). -- Redirections/heredoc are not converted into `t_command.redirections` yet in `src/parser/parser.c`. -- `set_path` resolves builtins and direct paths (`/`, `./`, `../`), otherwise searches `PATH` with `access(..., F_OK)`. +- Redirection tokens are converted into `t_redirection` and stored in `t_command.redirections`; heredocs are stored in `t_command.heredocs`. +- Path resolution is handled in executor (`executor_resolve_command_path`) before `execve`. - `src/parser/lexer.c` provides a separate lexer (`lex`) that tokenizes into `TOKEN_WORD`, `TOKEN_PIPE`, `TOKEN_REDIRECT_IN`, `TOKEN_REDIRECT_OUT`, `TOKEN_APPEND`, and `TOKEN_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 does not consume the lexer output yet. +- Current parser flow consumes lexer output directly. + +## Executor Redirections (Current `src/executor`) +- File redirections are applied in `src/executor/redirections.c` via `open` + `dup2` before 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_FILENO` and `STDOUT_FILENO` after builtin execution. ## Parser & Lexer Known Gaps -- `src/parser/parser.c` currently calls `tokenize()` with no valid declaration/definition in that unit, causing a build error with `-Werror`. -- `src/parser/parser.c` writes `command->infile` and `command->outfile`, but those fields are not present in `t_command` (`include/core.h`), causing build errors. -- `src/parser/parser.c` keeps a `tokens` variable that is unused, also failing under `-Werror`. -- `include/parser.h` exports `parse` only; `lex` is not declared in public headers. +- 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