-
Notifications
You must be signed in to change notification settings - Fork 0
2. Minishell Structure
Ilia Munaev edited this page May 21, 2025
·
4 revisions
Minishell uses a set of well-defined structures to manage its internal state, environment variables, error tracking, and memory safety.
Represents the central state of the shell. It holds everything needed to run, manage, and clean up commands and environments.
- env – The current environment exported to children (NULL-terminated array).
- hash_table – Custom hash table storing all environment variables.
- exit_status – Exit code of the last executed command.
- syntax_exit_status – Tracks last parsing/syntax error return value.
- allocation_error – True if a memory allocation failed (used to safely stop execution).
typedef struct s_mshell {
char **env;
t_hash_tbl *hash_table;
uint8_t exit_status;
uint8_t syntax_exit_status;
bool allocation_error;
} t_mshell;Each environment variable is stored in a linked list node.
-
key – Variable name (e.g.
PATH) -
value – Value (e.g.
/usr/bin:/bin) - val_assigned – 1 if a value is assigned, 0 if only declared
- next – Next variable in case of hash collision
typedef struct s_mshell_var {
char *key;
char *value;
int val_assigned;
struct s_mshell_var *next;
} t_mshell_var;Environment variables are stored in a hash table for fast access and update.
- buckets – Each index contains a linked list of variables with the same hash index
#define HASH_SIZE 128
typedef struct s_hash_table {
t_mshell_var *buckets[HASH_SIZE];
} t_hash_tbl;Maps builtin command names to their handler functions.
-
name – Name of the builtin command (e.g.
"cd","exit") - func – Pointer to the function implementing the command
typedef struct s_builtin_dispatch {
const char *name;
uint8_t (*func)(t_cmd *);
} t_builtin_disp;