token_type: add field with no logic for populating it

This commit is contained in:
Khaïs COLIN 2025-04-08 16:36:11 +02:00
parent f9b5471dc4
commit 63f80b9b1f
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
9 changed files with 52 additions and 29 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/28 16:43:11 by khais #+# #+# */ /* Created: 2025/03/28 16:43:11 by khais #+# #+# */
/* Updated: 2025/03/28 16:43:41 by khais ### ########.fr */ /* Updated: 2025/04/08 16:32:32 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,7 +17,7 @@ char *expand_line(char *line, t_minishell *app)
t_worddesc *word; t_worddesc *word;
word = worddesc_create(line, W_HASDOLLAR, word = worddesc_create(line, W_HASDOLLAR,
construct_repeting_char_string(' ', ft_strlen(line))); construct_repeting_char_string(' ', ft_strlen(line)), WORD_TOKEN);
word_var_expansion(word, app); word_var_expansion(word, app);
line = ft_strdup(word->word); line = ft_strdup(word->word);
worddesc_destroy(word); worddesc_destroy(word);

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/28 13:52:02 by khais #+# #+# */ /* Created: 2025/02/28 13:52:02 by khais #+# #+# */
/* Updated: 2025/03/07 11:20:48 by khais ### ########.fr */ /* Updated: 2025/04/08 16:31:19 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -43,7 +43,7 @@ t_worddesc *remove_quotes(t_worddesc *word)
} }
if (buf == NULL) if (buf == NULL)
return (NULL); return (NULL);
output = worddesc_create(buf->buffer, word->flags, NULL); output = worddesc_create(buf->buffer, word->flags, NULL, word->type);
free(buf); free(buf);
return (output); return (output);
} }

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/13 17:20:36 by khais #+# #+# */ /* Created: 2025/02/13 17:20:36 by khais #+# #+# */
/* Updated: 2025/03/27 13:58:41 by khais ### ########.fr */ /* Updated: 2025/04/08 16:30:20 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,7 +27,8 @@
** In case of allocation error, word is freed, as well as any memory allocated ** In case of allocation error, word is freed, as well as any memory allocated
** in this function ** in this function
*/ */
t_worddesc *worddesc_create(char *word, char flags, char *marker) t_worddesc *worddesc_create(char *word, char flags, char *marker,
t_token_type type)
{ {
t_worddesc *retvalue; t_worddesc *retvalue;
@ -39,6 +40,7 @@ t_worddesc *worddesc_create(char *word, char flags, char *marker)
retvalue->word = word; retvalue->word = word;
retvalue->flags = flags; retvalue->flags = flags;
retvalue->marker = marker; retvalue->marker = marker;
retvalue->type = type;
return (retvalue); return (retvalue);
} }

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/27 13:57:44 by khais #+# #+# */ /* Created: 2025/03/27 13:57:44 by khais #+# #+# */
/* Updated: 2025/03/27 13:57:49 by khais ### ########.fr */ /* Updated: 2025/04/09 15:35:11 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,6 +25,21 @@
# define W_HASQUOTEDNULL 0b10000 /* word contains a quoted null character */ # define W_HASQUOTEDNULL 0b10000 /* word contains a quoted null character */
# define W_DQUOTE 0b100000 /* word should be treated as if double-quoted */ # define W_DQUOTE 0b100000 /* word should be treated as if double-quoted */
typedef enum e_token_type
{
NOT_TOKEN,
WORD_TOKEN,
OPEN_PARENTH_TOKEN,
CLOSE_PARENTH_TOKEN,
PIPE_TOKEN,
OR_TOKEN,
AND_TOKEN,
OUT_TRUNC_REDIR_TOKEN,
OUT_APPEND_REDIR_TOKEN,
IN_REDIR_TOKEN,
HERE_DOC_REDIR_TOKEN,
} t_token_type;
/* /*
** A logical word for the parser. ** A logical word for the parser.
** **
@ -37,13 +52,13 @@ typedef struct s_worddesc
/* /*
** The word itself ** The word itself
*/ */
char *word; char *word;
/* /*
** flags for this word ** flags for this word
** **
** See above for flag definitions ** See above for flag definitions
*/ */
char flags; char flags;
/* /*
** a character mask for word to designate the status ** a character mask for word to designate the status
** of its characters and wether or not they are subject to modifications ** of its characters and wether or not they are subject to modifications
@ -55,10 +70,12 @@ typedef struct s_worddesc
** '"' corresponding character is double-quoted ** '"' corresponding character is double-quoted
** '$' corresponding character is a result of $var expansion ** '$' corresponding character is a result of $var expansion
*/ */
char *marker; char *marker;
t_token_type type;
} t_worddesc; } t_worddesc;
t_worddesc *worddesc_create(char *word, char flags, char *marker); t_worddesc *worddesc_create(char *word, char flags, char *marker,
t_token_type type);
void worddesc_destroy(t_worddesc *worddesc); void worddesc_destroy(t_worddesc *worddesc);
t_worddesc *worddesc_copy(t_worddesc *worddesc); t_worddesc *worddesc_copy(t_worddesc *worddesc);
void worddesc_debug(t_worddesc *worddesc, t_buffer *leader, void worddesc_debug(t_worddesc *worddesc, t_buffer *leader,

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/20 14:02:29 by khais #+# #+# */ /* Created: 2025/02/20 14:02:29 by khais #+# #+# */
/* Updated: 2025/03/10 16:55:33 by khais ### ########.fr */ /* Updated: 2025/04/08 16:29:49 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,11 +15,14 @@
void delimit(t_token_build *builder) void delimit(t_token_build *builder)
{ {
t_token_type type;
type = WORD_TOKEN;
if (builder->cur_token == NULL) if (builder->cur_token == NULL)
return ; return ;
builder->wordlist = wordlist_push(builder->wordlist, builder->wordlist = wordlist_push(builder->wordlist,
worddesc_create(builder->cur_token->buffer, worddesc_create(builder->cur_token->buffer,
builder->cur_flags, builder->cur_marker->buffer)); builder->cur_flags, builder->cur_marker->buffer, type));
free(builder->cur_token); free(builder->cur_token);
free(builder->cur_marker); free(builder->cur_marker);
builder->cur_flags = 0; builder->cur_flags = 0;

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/03 15:48:52 by khais #+# #+# */ /* Created: 2025/04/03 15:48:52 by khais #+# #+# */
/* Updated: 2025/04/03 18:01:42 by khais ### ########.fr */ /* Updated: 2025/04/08 16:33:14 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,7 +27,8 @@ static void delimit(t_buffer *word, t_buffer *marker,
{ {
t_worddesc *out; t_worddesc *out;
out = worddesc_create(word->buffer, original->flags, marker->buffer); out = worddesc_create(word->buffer, original->flags, marker->buffer,
WORD_TOKEN);
(*outlist) = wordlist_push(*outlist, out); (*outlist) = wordlist_push(*outlist, out);
free(word); free(word);
free(marker); free(marker);

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/20 15:01:38 by jguelen #+# #+# */ /* Created: 2025/03/20 15:01:38 by jguelen #+# #+# */
/* Updated: 2025/04/03 19:58:36 by khais ### ########.fr */ /* Updated: 2025/04/08 16:31:46 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -69,7 +69,7 @@ static t_wordlist *add_file_to_list(t_wordlist **list, char *filename)
marker = construct_repeting_char_string('\'', ft_strlen(copy)); marker = construct_repeting_char_string('\'', ft_strlen(copy));
if (!marker) if (!marker)
return (wordlist_destroy(*list), free(copy), NULL); return (wordlist_destroy(*list), free(copy), NULL);
file_desc = worddesc_create(copy, '\0', marker); file_desc = worddesc_create(copy, '\0', marker, WORD_TOKEN);
if (!file_desc) if (!file_desc)
{ {
wordlist_destroy(*list); wordlist_destroy(*list);

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/07 11:43:32 by khais #+# #+# */ /* Created: 2025/03/07 11:43:32 by khais #+# #+# */
/* Updated: 2025/03/28 19:05:55 by khais ### ########.fr */ /* Updated: 2025/04/08 16:34:50 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -45,10 +45,10 @@ static void test_here_doc_invalid_args(void)
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
ft_errno(FT_ESUCCESS); ft_errno(FT_ESUCCESS);
assert(-1 == here_doc(NULL, 0, NULL)); assert(-1 == here_doc(NULL, 0, NULL));
marker = worddesc_create(NULL, 0, NULL); marker = worddesc_create(NULL, 0, NULL, WORD_TOKEN);
assert(-1 == here_doc(marker, 0, NULL)); assert(-1 == here_doc(marker, 0, NULL));
worddesc_destroy(marker); worddesc_destroy(marker);
marker = worddesc_create(ft_strdup("EOF"), 0, NULL); marker = worddesc_create(ft_strdup("EOF"), 0, NULL, WORD_TOKEN);
assert(-1 == here_doc(marker, -1, NULL)); assert(-1 == here_doc(marker, -1, NULL));
worddesc_destroy(marker); worddesc_destroy(marker);
do_leak_check(); do_leak_check();
@ -62,7 +62,7 @@ static void test_here_doc_only_end_marker(void)
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
ft_errno(FT_ESUCCESS); ft_errno(FT_ESUCCESS);
marker = worddesc_create(ft_strdup("EOF"), 0, NULL); marker = worddesc_create(ft_strdup("EOF"), 0, NULL, WORD_TOKEN);
infile = open("./here_doc_only_eof.input", O_RDONLY); infile = open("./here_doc_only_eof.input", O_RDONLY);
result = here_doc(marker, infile, NULL); result = here_doc(marker, infile, NULL);
close(infile); close(infile);
@ -81,7 +81,7 @@ static void test_here_doc_input_plus_end_marker(void)
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
ft_errno(FT_ESUCCESS); ft_errno(FT_ESUCCESS);
marker = worddesc_create(ft_strdup("EOF"), 0, NULL); marker = worddesc_create(ft_strdup("EOF"), 0, NULL, WORD_TOKEN);
infile = open("./here_doc_input_plus_eof.input", O_RDONLY); infile = open("./here_doc_input_plus_eof.input", O_RDONLY);
result = here_doc(marker, infile, NULL); result = here_doc(marker, infile, NULL);
close(infile); close(infile);
@ -99,7 +99,7 @@ static void test_here_doc_input_no_end_marker(void)
int result; int result;
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
marker = worddesc_create(ft_strdup("EOF"), 0, NULL); marker = worddesc_create(ft_strdup("EOF"), 0, NULL, WORD_TOKEN);
infile = open("./here_doc_input_no_eof.input", O_RDONLY); infile = open("./here_doc_input_no_eof.input", O_RDONLY);
result = here_doc(marker, infile, NULL); result = here_doc(marker, infile, NULL);
close(infile); close(infile);
@ -121,7 +121,7 @@ static void test_here_doc_with_expansion(void)
app.env = env_set_entry(&app.env, ft_strdup("USER"), ft_strdup("kcolin")); app.env = env_set_entry(&app.env, ft_strdup("USER"), ft_strdup("kcolin"));
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
ft_errno(FT_ESUCCESS); ft_errno(FT_ESUCCESS);
marker = worddesc_create(ft_strdup("EOF"), 0, NULL); marker = worddesc_create(ft_strdup("EOF"), 0, NULL, WORD_TOKEN);
infile = open("./here_doc_with_expansion.input", O_RDONLY); infile = open("./here_doc_with_expansion.input", O_RDONLY);
result = here_doc(marker, infile, &app); result = here_doc(marker, infile, &app);
close(infile); close(infile);
@ -144,7 +144,7 @@ static void test_here_doc_with_no_expansion(void)
ft_bzero(&app, sizeof(t_minishell)); ft_bzero(&app, sizeof(t_minishell));
app.env = env_set_entry(&app.env, ft_strdup("USER"), ft_strdup("kcolin")); app.env = env_set_entry(&app.env, ft_strdup("USER"), ft_strdup("kcolin"));
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
marker = worddesc_create(ft_strdup("EOF"), W_QUOTED, NULL); marker = worddesc_create(ft_strdup("EOF"), W_QUOTED, NULL, WORD_TOKEN);
infile = open("./here_doc_with_expansion.input", O_RDONLY); infile = open("./here_doc_with_expansion.input", O_RDONLY);
result = here_doc(marker, infile, &app); result = here_doc(marker, infile, &app);
close(infile); close(infile);

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/10 14:59:19 by khais #+# #+# */ /* Created: 2025/03/10 14:59:19 by khais #+# #+# */
/* Updated: 2025/03/10 16:02:01 by khais ### ########.fr */ /* Updated: 2025/04/08 16:35:12 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,7 +32,7 @@ static void test_wordlist_idx_pop_single_elem(void)
t_worddesc *got; t_worddesc *got;
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
list = wordlist_create(worddesc_create(ft_strdup("hello"), 0, ft_strdup(""))); list = wordlist_create(worddesc_create(ft_strdup("hello"), 0, ft_strdup(""), WORD_TOKEN));
assert(NULL == wordlist_pop_idx(&list, 1)); assert(NULL == wordlist_pop_idx(&list, 1));
got = wordlist_pop_idx(&list, 0); got = wordlist_pop_idx(&list, 0);
assert(NULL != got); assert(NULL != got);
@ -48,8 +48,8 @@ static void test_wordlist_idx_pop_second_then_first(void)
t_worddesc *got; t_worddesc *got;
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
list = wordlist_create(worddesc_create(ft_strdup("hello"), 0, NULL)); list = wordlist_create(worddesc_create(ft_strdup("hello"), 0, NULL, WORD_TOKEN));
list = wordlist_push(list, worddesc_create(ft_strdup("world"), 0, NULL)); list = wordlist_push(list, worddesc_create(ft_strdup("world"), 0, NULL, WORD_TOKEN));
wordlist_debug(list); wordlist_debug(list);
got = wordlist_pop_idx(&list, 1); got = wordlist_pop_idx(&list, 1);
assert(NULL != got); assert(NULL != got);