debug: worddesc show more information

This seems appropriate since worddescs are getting more and more complex:
markers, flags, tokentypes, ...
This commit is contained in:
Khaïs COLIN 2025-04-09 15:38:13 +02:00
parent 6576c47b56
commit 4d6a64bf6a
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
9 changed files with 83 additions and 25 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/09 15:07:58 by khais #+# #+# */
/* Updated: 2025/04/14 17:23:33 by khais ### ########.fr */
/* Updated: 2025/04/15 12:06:19 by khais ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/09 15:06:43 by khais #+# #+# */
/* Updated: 2025/04/14 17:22:50 by khais ### ########.fr */
/* Updated: 2025/04/15 12:05:26 by khais ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/21 12:30:07 by khais #+# #+# */
/* Updated: 2025/04/15 14:37:57 by khais ### ########.fr */
/* Updated: 2025/04/15 14:47:13 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -47,7 +47,10 @@ void simple_cmd_debug(t_simple_cmd *cmd, t_buffer *leader, bool is_last)
return ;
indent(leader, is_last);
ft_printf("%s\n", "t_simple_cmd");
redirect_debug(cmd->redirections, leader, false);
wordlist_debug(cmd->words, leader, true);
indent(leader, false);
ft_printf("line = %d\n", cmd->line);
dedent(leader, false);
wordlist_debug(cmd->words, leader, false);
redirect_debug(cmd->redirections, leader, true);
dedent(leader, is_last);
}

View file

@ -5,8 +5,8 @@
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 12:00/08 by khais #+# #+# */
/* Updated: 2025/04/15 12:00:08 by khais ### ########.fr */
/* Created: 2025/02/13 17:20:36 by khais #+# #+# */
/* Updated: 2025/04/15 12:10:01 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -75,12 +75,52 @@ t_worddesc *worddesc_copy(t_worddesc *worddesc)
return (out);
}
static void token_type_debug(t_token_type type, t_buffer *leader, bool is_last)
{
indent(leader, is_last);
if (type == NOT_TOKEN)
ft_printf("t_token_type = %s\n", "NOT_TOKEN");
if (type == WORD_TOKEN)
ft_printf("t_token_type = %s\n", "WORD_TOKEN");
if (type == OPEN_PARENTH_TOKEN)
ft_printf("t_token_type = %s\n", "OPEN_PARENTH_TOKEN");
if (type == CLOSE_PARENTH_TOKEN)
ft_printf("t_token_type = %s\n", "CLOSE_PARENTH_TOKEN");
if (type == PIPE_TOKEN)
ft_printf("t_token_type = %s\n", "PIPE_TOKEN");
if (type == OR_TOKEN)
ft_printf("t_token_type = %s\n", "OR_TOKEN");
if (type == AND_TOKEN)
ft_printf("t_token_type = %s\n", "AND_TOKEN");
if (type == OUT_TRUNC_REDIR_TOKEN)
ft_printf("t_token_type = %s\n", "OUT_TRUNC_REDIR_TOKEN");
if (type == OUT_APPEND_REDIR_TOKEN)
ft_printf("t_token_type = %s\n", "OUT_APPEND_REDIR_TOKEN");
if (type == IN_REDIR_TOKEN)
ft_printf("t_token_type = %s\n", "IN_REDIR_TOKEN");
if (type == HERE_DOC_REDIR_TOKEN)
ft_printf("t_token_type = %s\n", "HERE_DOC_REDIR_TOKEN");
dedent(leader, is_last);
}
void worddesc_debug(t_worddesc *worddesc, t_buffer *leader, bool is_last)
{
indent(leader, is_last);
if (worddesc == NULL)
ft_printf("%s\n", "(nil)");
ft_printf("(null worddesc)\n");
else
ft_printf("[%s]\n", worddesc->word);
{
ft_printf("t_worddesc\n");
indent(leader, false);
ft_printf("word = [%s]\n", worddesc->word);
dedent(leader, false);
indent(leader, false);
ft_printf("marker = [%s]\n", worddesc->marker);
dedent(leader, false);
indent(leader, false);
ft_printf("flags = %d\n", worddesc->flags);
dedent(leader, false);
token_type_debug(worddesc->token_type, leader, true);
}
dedent(leader, is_last);
}

View file

@ -5,8 +5,8 @@
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/14 17:23/51 by khais #+# #+# */
/* Updated: 2025/04/14 17:23:51 by khais ### ########.fr */
/* Created: 2025/04/09 15:40:23 by khais #+# #+# */
/* Updated: 2025/04/15 12:07:34 by khais ### ########.fr */
/* */
/* ************************************************************************** */

26
test.sh
View file

@ -579,8 +579,32 @@ hello hi
EOF
when_run <<EOF "quoted parentheses are not operators"
.debug
.exec
echo unclosed '('
EOF
todo
expecting <<EOF
[dbg: 1]
[exec: 0]
╰─ t_simple_cmd
├─ line = 0
├─ t_wordlist
│ ├─ t_worddesc
│ │ ├─ word = [echo]
│ │ ├─ marker = [ ]
│ │ ├─ flags = 0
│ │ ╰─ t_token_type = WORD_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = [unclosed]
│ │ ├─ marker = [ ]
│ │ ├─ flags = 0
│ │ ╰─ t_token_type = WORD_TOKEN
│ ╰─ t_worddesc
│ ├─ word = ['(']
│ ├─ marker = [ ' ]
│ ├─ flags = 2
│ ╰─ t_token_type = WORD_TOKEN
╰─ redirections = (empty redir list)
EOF
finalize

View file

@ -5,8 +5,8 @@
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/27 14:05/00 by khais #+# #+# */
/* Updated: 2025/03/27 14:05:00 by khais ### ########.fr */
/* Created: 2025/04/09 15:50/06 by khais #+# #+# */
/* Updated: 2025/04/09 15:50:06 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -213,7 +213,6 @@ static void test_filename_star_expansion(void)
//test ., .. and .plop
filepattern = create_single_word(".*");
expanded = expand_star(filepattern);
wordlist_debug(expanded);
assert(wordlist_size(expanded) == 3);
assert_strequal(".", expanded->word->word);
assert_strequal("..", expanded->next->word->word);

View file

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

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/13 15:21:09 by khais #+# #+# */
/* Updated: 2025/03/20 11:57:29 by khais ### ########.fr */
/* Updated: 2025/04/09 15:49:47 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -65,13 +65,6 @@ void assert_simple_commandequal(t_simple_cmd *expected, t_simple_cmd *got, int i
void assert_pipelineequal_raw(t_pipeline *expected, t_pipeline *got)
{
assert(expected == got || expected != NULL);
int j = 0;
while (j < got->num_cmd)
{
ft_dprintf(STDERR_FILENO, "Got pipeline cmd %d: ", j);
wordlist_debug(got->cmds[j]->words);
j++;
}
ft_dprintf(STDERR_FILENO, "Expected pipeline to have %d commands, got pipeline with %d\n", expected->num_cmd, got->num_cmd);
assert(expected->num_cmd == got->num_cmd);
int i = 0;