31 value = ft_itoa(exit_status);
66 if (ft_isdigit(var_name[0]) && var_name[0] ==
'0')
118 return (ft_strdup(str));
119 result = ft_strdup(
"");
125 if (str[i] ==
'$' && str[i + 1])
162 expanded = ft_strdup(tokens->
value);
164 expanded = ft_strdup(
"");
171 tokens->
value = expanded;
174 tokens = tokens->
next;
Environment variable management prototypes.
char * get_env_value(t_env *env_list, char *key)
Look up an environment variable's value by its key.
char * expand_variables(char *str, t_env *env_list, t_quote_type quote_type, int exit_status)
Expand all $VARIABLE in a string.
static int process_dollar(char *str, int i, char **result, t_env *env_list)
Process a normal $VARIABLE expansion.
static int handle_special_var(char *str, char **result, int exit_status)
Handle $? expansion (last exit status)
static int handle_dollar_sign(char *str, char **result, t_env *env_list, int exit_status)
Dispatch $ expansion (special vars then normal)
int expand_all_tokens(t_token *tokens, t_shell *shell)
Expand all token values before parsing.
int is_var_char(char c)
Check if a character is valid in a variable name.
int is_dollar_quote(t_token *token)
Check if a token is a $ connected to a quoted token.
char * extract_var_name(char *str, int *len)
Extract a variable name from after the $
char * append_str(char *s1, char *s2)
Concatenates 2 strings and frees the first.
char * append_char(char *str, char c)
Append a single character to an allocated string.
t_quote_type
Quote context of a token.
Environment variable (doubly linked list)
t_env * env
Environment linked list.
int exit_status
Last command's exit status.
Lexer token (singly linked list)
char * value
Text content (allocated)
t_token_type type
Token type (word, pipe, redir)
struct s_token * next
Next token.
t_quote_type quote_type
Quote context.
char * expand_full(char *str, t_env *env, t_quote_type qt, int exit_status)
Handles variable expansion and tilde expansion.
Lexer, tokenizer, expander, and quote handling prototypes.