From 0c38b8e263a7e2e00a828eeddb464dc53ef1e803 Mon Sep 17 00:00:00 2001 From: sacha portable Date: Thu, 7 May 2026 22:02:16 +0200 Subject: [PATCH 01/15] docs: update source.c file description for source builtin functionality --- src/builtins/config/source.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/builtins/config/source.c b/src/builtins/config/source.c index 056bd5f..9367183 100644 --- a/src/builtins/config/source.c +++ b/src/builtins/config/source.c @@ -2,9 +2,9 @@ ** EPITECH PROJECT, 2026 ** 42sh ** File description: -** source / . builtin: opens the file with openator(), splits it -** into lines with str_to_array_of_word_array(), then executes -** each line via exec_any() in the current shell context. +** source / . builtin stub: currently only reloads the czshrc config +** via update_rc(); file execution (open, split lines, run each via +** exec_any) is not yet implemented — the builtin is registered but empty. ** Authors: @Celz-Pch @Lukas-sgx @ErwanTheKing @sacha-lma @Jessymgadd */ From 9932d2f1dea4c5e6e6f38bf1176d6e4b1ffa2775 Mon Sep 17 00:00:00 2001 From: sacha portable Date: Thu, 7 May 2026 22:02:21 +0200 Subject: [PATCH 02/15] docs: add flowchart to README.md illustrating 42sh architecture and REPL loop --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.md b/README.md index 78dbe33..968f26a 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,35 @@ make fclean # remove .o files and the binary ## Project Architecture +```mermaid +flowchart TD + A([42sh binary]) --> B["init_main()\nbuild env_t list · parse PATH · load history · load RC"] + B --> C["setup_shell_signals()\nSIGINT/SIGTSTP/SIGQUIT → SIG_IGN · shell becomes pgid leader"] + C --> REPL + + subgraph REPL ["REPL loop — src/core/main.c"] + D["write_print()\ndisplay styled prompt"] --> E["get_command()\nraw-termios input or getline"] + E --> F["serialize()\ntrim whitespace"] + F --> G["execute_command()\nsplit on ';'"] + end + + G --> H{operator?} + H -->|"&& \|\|"| I["execute_operator()\nshort-circuit chain"] + H -->|"\|"| J["execute_pipeline()\nfork/pipe/wait per segment"] + H -->|plain| K["execute_single_command()\nparse → builtin? → external"] + + K --> L{builtin?} + L -->|yes| M["execute_builtin()\nenv · cd · setenv · repeat · foreach …"] + L -->|no| N["exec_any()\nresolve PATH · fork · execve"] + + I --> K + J --> K + M --> REPL + N --> REPL + + style REPL fill:#e3f2fd,stroke:#1565c0,color:#000 +``` + ``` 42sh/ ├── Makefile From a17b497f5658dec9dbc20d1cc54cf1cfb684316f Mon Sep 17 00:00:00 2001 From: sacha portable Date: Thu, 7 May 2026 22:02:24 +0200 Subject: [PATCH 03/15] docs: update description of my_str_is_alphanum function for clarity on variable name validation --- src/utils/validation/my_str_is_alphanum.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/validation/my_str_is_alphanum.c b/src/utils/validation/my_str_is_alphanum.c index 4adeaa1..725edb7 100644 --- a/src/utils/validation/my_str_is_alphanum.c +++ b/src/utils/validation/my_str_is_alphanum.c @@ -2,9 +2,9 @@ ** EPITECH PROJECT, 2026 ** 42sh ** File description: -** Full key name check: my_str_is_alphanum returns 1 if every -** character is a letter, digit, or underscore, used by setenv -** to validate the complete variable key name. +** Variable name validator: my_str_is_alphanum returns 1 if any +** character in the string is not in [a-z A-Z 0-9], used by setenv +** and foreach to reject invalid environment variable names. ** Authors: @Celz-Pch @Lukas-sgx @ErwanTheKing @sacha-lma @Jessymgadd */ From d427452a4c97c8fc20388d1b46a72b6683fbb06d Mon Sep 17 00:00:00 2001 From: sacha portable Date: Thu, 7 May 2026 22:02:28 +0200 Subject: [PATCH 04/15] docs: refine prompt configuration parser description for clarity and detail --- src/config/manage_prompt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config/manage_prompt.c b/src/config/manage_prompt.c index b89cdbb..966c168 100644 --- a/src/config/manage_prompt.c +++ b/src/config/manage_prompt.c @@ -2,9 +2,9 @@ ** EPITECH PROJECT, 2026 ** 42sh ** File description: -** Prompt configuration parser: get_color/get_b_color convert -** color name strings to ANSI codes; manage_format, manage_time, -** manage_date, manage_branche, manage_folder, manage_user fill +** Prompt config parser: get_color/get_b_color map color name strings +** to ANSI codes; manage_prompt dispatches [prompt] key=value pairs +** to manage_user, manage_folder, manage_branche, manage_date, manage_time. ** Authors: @Celz-Pch @Lukas-sgx @ErwanTheKing @sacha-lma @Jessymgadd */ From 4943589ee43111d72afdaf103057bc78745d8c6d Mon Sep 17 00:00:00 2001 From: sacha portable Date: Thu, 7 May 2026 22:02:32 +0200 Subject: [PATCH 05/15] docs: update history.c file description to clarify functionality of history builtin --- src/builtins/history/history.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/builtins/history/history.c b/src/builtins/history/history.c index 5dd4036..0635a9f 100644 --- a/src/builtins/history/history.c +++ b/src/builtins/history/history.c @@ -2,9 +2,9 @@ ** EPITECH PROJECT, 2026 ** 42sh ** File description: -** history builtin: iterates the history_cmd_t doubly-linked list -** from oldest to newest and prints each entry as: -** ID HH:MM command +** history builtin: opens ~/.c_zsh_history with openator() and prints +** its full content to stdout; entries are written by manage_history +** in the format " ID\tHH:MM\tcommand" on each command execution. ** Authors: @Celz-Pch @Lukas-sgx @ErwanTheKing @sacha-lma @Jessymgadd */ From 1b516a49b092a943f2a581d78970efda8f179c44 Mon Sep 17 00:00:00 2001 From: sacha portable Date: Thu, 7 May 2026 22:02:35 +0200 Subject: [PATCH 06/15] docs: update get_folder.c description for clarity on path component retrieval --- src/utils/display/get_folder.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/display/get_folder.c b/src/utils/display/get_folder.c index 390bdee..8a7964c 100644 --- a/src/utils/display/get_folder.c +++ b/src/utils/display/get_folder.c @@ -2,9 +2,9 @@ ** EPITECH PROJECT, 2026 ** 42sh ** File description: -** Working directory for the prompt: get_folder calls getcwd() -** then shortens the path to its last two components -** (e.g. 'project/src') for a compact prompt appearance. +** Working directory for the prompt: get_folder calls getcwd(), +** splits on '/' and returns a heap-allocated copy of the last +** path component for compact display in the shell prompt. ** Authors: @Celz-Pch @Lukas-sgx @ErwanTheKing @sacha-lma @Jessymgadd */ From 27f71794e0956448fa47ea59178f0f9392b2078b Mon Sep 17 00:00:00 2001 From: sacha portable Date: Thu, 7 May 2026 22:02:39 +0200 Subject: [PATCH 07/15] docs: update display_time.c description for clarity on time formatting and output behavior --- src/utils/display/display_time.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/display/display_time.c b/src/utils/display/display_time.c index 63fbda5..6090311 100644 --- a/src/utils/display/display_time.c +++ b/src/utils/display/display_time.c @@ -2,9 +2,9 @@ ** EPITECH PROJECT, 2026 ** 42sh ** File description: -** Time display: display_time prints current HH:MM right-aligned -** using terminal column count from ioctl(TIOCGWINSZ). -** check_null_win falls back to 80 columns when ioctl fails. +** Time display stub: display_time formats the current HH:MM:SS and +** computes the right-aligned column via ioctl(TIOCGWINSZ), but does +** not yet write output; check_null_win falls back to col 0 if ioctl fails. ** Authors: @Celz-Pch @Lukas-sgx @ErwanTheKing @sacha-lma @Jessymgadd */ From b2bb95164277dd03fa42127c2adb471d4c507034 Mon Sep 17 00:00:00 2001 From: sacha portable Date: Thu, 7 May 2026 22:13:42 +0200 Subject: [PATCH 08/15] feat: update architecture diagram to reflect prompt and history management changes --- docs/ARCHITECTURE_DIAGRAM.mmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/ARCHITECTURE_DIAGRAM.mmd b/docs/ARCHITECTURE_DIAGRAM.mmd index 43c8d53..aa7a009 100644 --- a/docs/ARCHITECTURE_DIAGRAM.mmd +++ b/docs/ARCHITECTURE_DIAGRAM.mmd @@ -18,7 +18,7 @@ flowchart TD subgraph REPL ["LOOP 1 — REPL · while buffer ≠ 'exit' · src/core/main.c"] direction TB - PROMPT_DRAW["write_print()\nstyled prompt: dir · git branch · user"] + PROMPT_DRAW["write_print() → display_prompt()\nfolder · user · git branch · time/date (ANSI colors)"] PROMPT_DRAW --> TTY_CHECK %% ───────────────────────────────────────────────────────────── @@ -60,7 +60,7 @@ flowchart TD LINE_READY --> SERIALIZE["serialize()\ntrim leading/trailing whitespace"] GETLINE --> SERIALIZE - SERIALIZE --> ADD_HIST["add_to_history(buffer)\nappend to ~/.c_zsh_history"] + SERIALIZE --> ADD_HIST["manage_history(history, buffer)\nappend to ~/.c_zsh_history"] ADD_HIST --> EXEC_CMD["execute_command(buffer)"] %% ───────────────────────────────────────────────────────────── From 562e7188d70602520aa5bde3baaa3f03c054ef57 Mon Sep 17 00:00:00 2001 From: sacha portable Date: Thu, 7 May 2026 22:13:47 +0200 Subject: [PATCH 09/15] feat: enhance time and date display with formatting and ANSI color support --- src/utils/display/display_time.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/display/display_time.c b/src/utils/display/display_time.c index 813f146..caa0ece 100644 --- a/src/utils/display/display_time.c +++ b/src/utils/display/display_time.c @@ -2,9 +2,9 @@ ** EPITECH PROJECT, 2026 ** 42sh ** File description: -** Time display stub: display_time formats the current HH:MM:SS and -** computes the right-aligned column via ioctl(TIOCGWINSZ), but does -** not yet write output; check_null_win falls back to col 0 if ioctl fails. +** Time/date display: computes right-padding via ioctl(TIOCGWINSZ) and +** calculate_limit, then prints HH:MM:SS via displauy_time() and the date +** in LONG/EU/US/ISO format via display_date(), both with ANSI color support. ** Authors: @Celz-Pch @Lukas-sgx @ErwanTheKing @sacha-lma @Jessymgadd */ From 47ad71ea836a78266d7d2c5274fa00f9656ed794 Mon Sep 17 00:00:00 2001 From: sacha portable Date: Thu, 7 May 2026 22:13:50 +0200 Subject: [PATCH 10/15] feat: update foreach error handling to print undefined variable message --- src/utils/errors/foreach.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/errors/foreach.c b/src/utils/errors/foreach.c index d09e029..4c50a7b 100644 --- a/src/utils/errors/foreach.c +++ b/src/utils/errors/foreach.c @@ -2,9 +2,9 @@ ** EPITECH PROJECT, 2026 ** 42sh ** File description: -** foreach error helper: put_error_var prints a tcsh-compatible -** error message to stderr when the foreach loop variable name -** is invalid (must start with a letter, alphanumeric + _ only). +** foreach error helper: put_error_var prints "VAR: Undefined variable." +** to stdout via my_putstr and returns FAILURE; called when a loop +** variable cannot be resolved during foreach execution. ** Authors: @Celz-Pch @Lukas-sgx @ErwanTheKing @sacha-lma @Jessymgadd */ From cf69da1c1317a5323851d5f3b825db4f1cb021b4 Mon Sep 17 00:00:00 2001 From: sacha portable Date: Thu, 7 May 2026 22:13:55 +0200 Subject: [PATCH 11/15] feat: update history builtin description for clarity on functionality --- src/builtins/history/history.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/builtins/history/history.c b/src/builtins/history/history.c index 6e0e3c1..b75283c 100644 --- a/src/builtins/history/history.c +++ b/src/builtins/history/history.c @@ -2,9 +2,9 @@ ** EPITECH PROJECT, 2026 ** 42sh ** File description: -** history builtin: opens ~/.c_zsh_history with openator() and prints -** its full content to stdout; entries are written by manage_history -** in the format " ID\tHH:MM\tcommand" on each command execution. +** history builtin: opens .c_zsh_history and dispatches to write_history +** (last N entries, oldest-first) or write_reverse_history (-r flag, +** newest-first up to N); N defaults to the full file when omitted. ** Authors: @Celz-Pch @Lukas-sgx @ErwanTheKing @sacha-lma @Jessymgadd */ From 119913566a3e49bd5caf115f32d34b58d7235f0c Mon Sep 17 00:00:00 2001 From: sacha portable Date: Thu, 7 May 2026 22:13:59 +0200 Subject: [PATCH 12/15] feat: improve my_putnbr description for clarity on functionality --- src/utils/io/my_putnbr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/io/my_putnbr.c b/src/utils/io/my_putnbr.c index e368885..c1e1aec 100644 --- a/src/utils/io/my_putnbr.c +++ b/src/utils/io/my_putnbr.c @@ -2,9 +2,9 @@ ** EPITECH PROJECT, 2026 ** 42sh ** File description: -** Integer output: my_putnbr recursively decomposes an integer -** into decimal digits (with INT_MIN handled separately) and -** writes each digit to stdout with my_putchar. +** Integer output: my_putnbr writes the sign if negative, then +** recursively decomposes the absolute value into decimal digits +** and writes each to stdout via write(1); INT_MIN is not handled. ** Authors: @Celz-Pch @Lukas-sgx @ErwanTheKing @sacha-lma @Jessymgadd */ From 226d0de9ec1b968dcd75ff9dfbaae892caa44cd0 Mon Sep 17 00:00:00 2001 From: sacha portable Date: Thu, 7 May 2026 22:14:05 +0200 Subject: [PATCH 13/15] feat: update README flowchart for improved clarity on shell initialization and REPL process --- README.md | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 968f26a..03a27eb 100644 --- a/README.md +++ b/README.md @@ -29,29 +29,30 @@ make fclean # remove .o files and the binary ```mermaid flowchart TD - A([42sh binary]) --> B["init_main()\nbuild env_t list · parse PATH · load history · load RC"] - B --> C["setup_shell_signals()\nSIGINT/SIGTSTP/SIGQUIT → SIG_IGN · shell becomes pgid leader"] - C --> REPL + START([42sh binary]) --> INIT["init_main(env)\nbuild env_t list · parse PATH · load .c_zsh_history · load .czshrc"] + INIT --> SIGS["setup_shell_signals()\nSIGINT / SIGTSTP / SIGQUIT → SIG_IGN · shell becomes pgid leader"] + SIGS --> REPL subgraph REPL ["REPL loop — src/core/main.c"] - D["write_print()\ndisplay styled prompt"] --> E["get_command()\nraw-termios input or getline"] - E --> F["serialize()\ntrim whitespace"] - F --> G["execute_command()\nsplit on ';'"] + PROMPT["display_prompt()\nfolder · user · git branch · time/date with ANSI colors"] --> INPUT["get_command()\nraw-termios char-by-char loop or getline (non-TTY)"] + INPUT --> HIST["manage_history()\nappend to ~/.c_zsh_history"] + HIST --> EXEC["execute_command()\nsplit on ';' (quote-aware)"] end - G --> H{operator?} - H -->|"&& \|\|"| I["execute_operator()\nshort-circuit chain"] - H -->|"\|"| J["execute_pipeline()\nfork/pipe/wait per segment"] - H -->|plain| K["execute_single_command()\nparse → builtin? → external"] + EXEC --> D{segment type?} + D -->|"&& / ||"| OP["execute_operator()\nshort-circuit evaluation of chained commands"] + D -->|"|"| PIPE["execute_pipeline()\nfork · pipe FDs · wait all PIDs"] + D -->|plain| SINGLE["execute_single_command()\nparse_command_context → $VAR expand → quote convert"] - K --> L{builtin?} - L -->|yes| M["execute_builtin()\nenv · cd · setenv · repeat · foreach …"] - L -->|no| N["exec_any()\nresolve PATH · fork · execve"] + OP --> SINGLE + PIPE --> SINGLE - I --> K - J --> K - M --> REPL - N --> REPL + SINGLE --> E{builtin?} + E -->|yes| BUILTIN["execute_builtin()\nenv · setenv · unsetenv · cd · which · where\nprintenv · repeat · foreach · history · source"] + E -->|no| EXT["exec_any()\nloop_bin (PATH search) → run_fork (fork + execve + waitpid)"] + + BUILTIN --> REPL + EXT --> REPL style REPL fill:#e3f2fd,stroke:#1565c0,color:#000 ``` From a348d1caa4e236e8181dade745e6277ac5c1cf20 Mon Sep 17 00:00:00 2001 From: sacha portable Date: Thu, 7 May 2026 22:14:09 +0200 Subject: [PATCH 14/15] feat: update repeat builtin description for clarity on count parsing and command execution --- src/builtins/repeat/repeat.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/builtins/repeat/repeat.c b/src/builtins/repeat/repeat.c index 55364e5..4b7db97 100644 --- a/src/builtins/repeat/repeat.c +++ b/src/builtins/repeat/repeat.c @@ -2,9 +2,9 @@ ** EPITECH PROJECT, 2026 ** 42sh ** File description: -** repeat builtin: builtin_repeat validates the count argument -** with my_char_isnum; repeat() runs exec_any() in a for loop -** 0..N-1 and returns the exit code of the last iteration. +** repeat builtin: parses the count with atoi(), sets up a shifted +** command_ctx_t pointing to the command after N, then runs exec_any() +** in a loop 0..N-1 and returns the exit code of the last iteration. ** Authors: @Celz-Pch @Lukas-sgx @ErwanTheKing @sacha-lma @Jessymgadd */ From 4cf4d33d6e6bfa15781ecb8059a36f37320c93e0 Mon Sep 17 00:00:00 2001 From: sacha portable Date: Thu, 7 May 2026 22:14:13 +0200 Subject: [PATCH 15/15] feat: enhance source builtin description for clarity on config reloading functionality --- src/builtins/config/source.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/builtins/config/source.c b/src/builtins/config/source.c index 58e7d9e..f80b579 100644 --- a/src/builtins/config/source.c +++ b/src/builtins/config/source.c @@ -2,9 +2,9 @@ ** EPITECH PROJECT, 2026 ** 42sh ** File description: -** source / . builtin stub: currently only reloads the czshrc config -** via update_rc(); file execution (open, split lines, run each via -** exec_any) is not yet implemented — the builtin is registered but empty. +** source / . builtin: reloads the shell config by calling update_rc() +** with ctx->argv[1] as the target file path, immediately applying +** RC settings to the running shell; command execution from file pending. ** Authors: @Celz-Pch @Lukas-sgx @ErwanTheKing @sacha-lma @Jessymgadd */