42sh — Shell State
Top-level header defining the central t_shell struct and
variable-management API.
Top-level header for the 42sh shell, includes all sub-systems and defines the central t_shell state struct.
- Author
wengzhang, jguillem, jspitz, pulgamecanica, zweng
Defines
-
LST_VAR(n)
Cast a
t_listnode’s content tot_var *.
-
LST_JOB(n)
Cast a
t_listnode’s content tot_job *.
-
LST_ALIAS(n)
Cast a
t_listnode’s content tot_alias *.
-
LST_PROC(n)
Cast a
t_listnode’s content tot_process *.
Functions
-
char *var_get_value(t_shell *shell, const char *name)
Get the value string of variable
name, or NULL if unset.
-
int var_set(t_shell *shell, const char *name, const char *value)
Set (or create) variable
nametovalue. Returns 0 on success.
-
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.
-
char *cmd_entrypoint
-c 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.
-
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
main.c
Functions
-
int main(int argc, char *argv[], char *envp[])