MiniDevil As beautiful as a shell
token.h
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* token.h :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: baelgadi <baelgadi@student.42.fr> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2025/12/03 23:14:10 by zotaj-di #+# #+# */
9 /* Updated: 2026/03/11 03:00:54 by baelgadi ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #ifndef TOKEN_H
14 # define TOKEN_H
15 
16 # include "structs.h"
17 
18 # ifdef BONUS
19 # define MASK_DOLLAR '\x02'
20 # define MASK_STAR '\x01'
21 # endif
22 
23 /* ────────────── token.c ──────────────── */
24 
25 t_token *create_token(t_token_type type, char *value);
26 
27 void free_token(t_token *token);
28 
29 void free_token_list(t_token *head);
30 
31 void add_token(t_token **head, t_token *new_token);
32 
33 /* ────────────── tokenizer_utils.c ──────────────── */
34 
35 int is_operator(char c);
36 
37 int is_whitespace(char c);
38 
39 int is_word_end(char c);
40 
41 t_token_type get_operator_token_type(char *str, int *len);
42 
43 /* ────────────── tokenizer.c ──────────────── */
44 
45 int process_word_token(char *s, t_token **head);
46 
47 int process_operator_token(char *input, t_token **head);
48 
49 t_token *tokenize(char *input);
50 
51 /* ────────────── expander_utils.c ──────────────── */
52 
53 int is_dollar_quote(t_token *tok);
54 
55 int is_var_char(char c);
56 
57 char *extract_var_name(char *str, int *len);
58 
59 char *append_char(char *str, char c);
60 
61 char *append_str(char *s1, char *s2);
62 
63 /* ────────────── expander.c ──────────────── */
64 
65 char *expand_variables(char *str, t_env *env_list,
66  t_quote_type quote_type, int exit_status);
67 
68 int expand_all_tokens(t_token *tokens, t_shell *shell);
69 
70 /* ────────────── tilde_expand.c ──────────────── */
71 
72 char *expand_full(char *str, t_env *env, t_quote_type qt,
73  int exit_status);
74 
75 /* ────────────── B O N U S ──────────────── */
76 
79 int defer_expand_tokens(t_token *tokens, t_shell *shell);
80 
81 void expand_wildcards(t_token **head);
82 
83 int wildcard_match(char *pattern, char *str);
84 
85 void print_ambig(char *name);
86 
87 void sort_matches(char **arr, int count);
88 
89 char *build_chain_pattern(t_token *start, int *has_wildcard);
90 
91 void replace_chain(char **m, int cnt, t_wild_ctx *ctx);
92 
93 t_token *build_match_list(char **m, int cnt, t_token **last);
94 
95 void free_chain(t_token *start, t_token *end);
96 
97 int check_ambig(t_token *prev, int cnt, t_token *cur);
98 
101 #endif
Central type definitions for mandatory part.
t_token_type
Token types produced by Lexer.
Definition: structs.h:24
t_quote_type
Quote context of a token.
Definition: structs.h:41
Environment variable (doubly linked list)
Definition: structs.h:87
Shell state.
Definition: structs.h:164
Lexer token (singly linked list)
Definition: structs.h:71
(BONUS) Wildcard context
Definition: structs.h:209
char * expand_variables(char *str, t_env *env_list, t_quote_type quote_type, int exit_status)
Expand all $VARIABLE in a string.
Definition: expander.c:111
int process_word_token(char *s, t_token **head)
Process a word token composed of quoted and unquoted chunks.
Definition: tokenizer.c:80
int is_word_end(char c)
Check if a character ends a word token.
void free_token_list(t_token *head)
Free the entire token linked list.
Definition: token.c:64
char * expand_full(char *str, t_env *env, t_quote_type qt, int exit_status)
Handles variable expansion and tilde expansion.
Definition: tilde_expand.c:60
int is_var_char(char c)
Check if a character is valid in a variable name.
void add_token(t_token **head, t_token *new_token)
Add a token to the end of a linked list.
Definition: token.c:84
t_token * tokenize(char *input)
Tokenize the input string into a linked list of tokens.
Definition: tokenizer.c:144
void free_token(t_token *token)
Free a single token and its value str.
Definition: token.c:51
int is_whitespace(char c)
Check if a character is whitespace.
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.
int process_operator_token(char *input, t_token **head)
Process an operator token.
Definition: tokenizer.c:118
t_token_type get_operator_token_type(char *str, int *len)
Determine operator token type and its length in characters.
int is_operator(char c)
Check if a character is a shell operator.
int expand_all_tokens(t_token *tokens, t_shell *shell)
Expand all token values before parsing.
Definition: expander.c:150
char * append_char(char *str, char c)
Append a single character to an allocated string.
t_token * create_token(t_token_type type, char *value)
Allocate and initialize a new token.
Definition: token.c:26
int is_dollar_quote(t_token *tok)
Check if a token is a $ connected to a quoted token.