42sh (Shell State)
Header for the 42sh shell, includes all sub-systems and defines the central t_shell state struct.
- Author
wengzhang, jguillem, jspitz, pulgamecanica, zweng
Defines
Functions
-
char *shell_read_line(t_shell *shell, const char *prompt)
Read one line of shell input — the single owner of stdin.
readline in interactive mode, getline on the shared
stdinFILE* otherwise. The REPL and the heredoc collector both call this so command lines and heredoc bodies stay synchronised.- Returns:
Heap-allocated line without trailing newline, or NULL on EOF.
-
struct t_shell
- #include <42sh.h>
Central runtime state of the shell - one instance lives in
main().This struct holds all global state, including variables, jobs, history file path, and terminal settings.
Public Members
-
t_list *aliases
t_alias*list; alias table.
-
t_hash *cmd_hash
Cached PATH lookups for the
hashbuiltin.
-
char *cmd_entrypoint
./42sh -c <cmd>command string, or NULL.
-
char **env
Cached NULL-terminated array for execve.
-
int env_dirty
1 when
envneeds rebuild before next execve.
-
int exit_confirmed
Double-exit guard when stopped jobs exist.
-
char *history_file
Path from $HISTFILE or $HOME/.sh_history.
-
t_list *heredoc_body_queue
Pre-collected heredoc bodies (FIFO of
char *); populated byshell_read_logical_line, drained by the heredoc collector. NULL outside REPL pre-collection.
-
int interactive
1 if stdin is a TTY (prompt + readline active).
-
t_list *jobs
t_job*list; all known jobs.
-
int last_exit_status
Value of
$?.
-
struct termios original_termios
Saved terminal attributes, restored on exit.
-
int running
Main loop flag; set to 0 to exit.
-
pid_t shell_pgid
Shell’s own process group id.
-
int terminal_fd
File descriptor of the controlling terminal.
-
t_list *variables
t_var*list; all shell/env variables.
-
t_list *aliases