update: fixed leak and stuff
This commit is contained in:
parent
75581c7ee0
commit
8d796c4094
8 changed files with 39 additions and 26 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/02 18:41:16 by maiboyer #+# #+# */
|
/* Created: 2024/10/02 18:41:16 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/08 13:40:48 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/08 14:52:02 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -50,10 +50,10 @@ static const struct s_ts_pass_def g_ts_passes[] = {\
|
||||||
{ts_double_lcarret, "double lcarret => dlcarret"}, \
|
{ts_double_lcarret, "double lcarret => dlcarret"}, \
|
||||||
{ts_double_rcarret, "double rcarrer => drcarret"}, \
|
{ts_double_rcarret, "double rcarrer => drcarret"}, \
|
||||||
{ts_fold_into_word, "fold into words"}, \
|
{ts_fold_into_word, "fold into words"}, \
|
||||||
{ts_fold_cmd, "fold into cmd"}, \
|
|
||||||
// there should be an ts_fold_arith here
|
// there should be an ts_fold_arith here
|
||||||
{ts_split_paren, "split double parenthesis"}, \
|
{ts_split_paren, "split double parenthesis"}, \
|
||||||
{ts_fold_redir, "fold redir+argument"}, \
|
{ts_fold_redir, "fold redir+argument"}, \
|
||||||
|
{ts_fold_cmd, "fold into cmd"}, \
|
||||||
};
|
};
|
||||||
|
|
||||||
t_error ts_apply_passes(t_vec_token ts, t_vec_token *out)
|
t_error ts_apply_passes(t_vec_token ts, t_vec_token *out)
|
||||||
|
|
@ -72,7 +72,7 @@ t_error ts_apply_passes(t_vec_token ts, t_vec_token *out)
|
||||||
else
|
else
|
||||||
me_printf("Applied '%s' pass\n", g_ts_passes[i].name);
|
me_printf("Applied '%s' pass\n", g_ts_passes[i].name);
|
||||||
ts = next;
|
ts = next;
|
||||||
//ts_print(&ts);
|
ts_print(&ts);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (*out = ts, NO_ERROR);
|
return (*out = ts, NO_ERROR);
|
||||||
|
|
@ -104,7 +104,7 @@ t_error ts_dq_apply_passes(t_vec_token ts, t_vec_token *out)
|
||||||
else
|
else
|
||||||
me_printf("Applied '%s' dq_pass\n", g_ts_dq_passes[i].name);
|
me_printf("Applied '%s' dq_pass\n", g_ts_dq_passes[i].name);
|
||||||
ts = next;
|
ts = next;
|
||||||
//ts_print(&ts);
|
ts_print(&ts);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (*out = ts, NO_ERROR);
|
return (*out = ts, NO_ERROR);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/02 19:04:32 by maiboyer #+# #+# */
|
/* Created: 2024/10/02 19:04:32 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/08 13:40:23 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/08 14:44:55 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
static bool _is_cmd_node(enum e_token ttype)
|
static bool _is_cmd_node(enum e_token ttype)
|
||||||
{
|
{
|
||||||
return (ttype == TOK_WHITESPACE || ttype == TOK_WORD);
|
return (ttype == TOK_WHITESPACE || ttype == TOK_WORD || ttype == TOK_REDIR);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This is a sample pass
|
/// This is a sample pass
|
||||||
|
|
@ -49,12 +49,18 @@ t_error ts_fold_cmd(t_vec_token input, t_vec_token *output)
|
||||||
tmp = token_new_meta(TOK_CMD);
|
tmp = token_new_meta(TOK_CMD);
|
||||||
while (i + j < input.len \
|
while (i + j < input.len \
|
||||||
&& _is_cmd_node(input.buffer[i + j].type))
|
&& _is_cmd_node(input.buffer[i + j].type))
|
||||||
vec_token_push(&tmp.subtokens, token_clone(&input.buffer[i + j++]));
|
{
|
||||||
|
if (input.buffer[i + j].type != TOK_WHITESPACE)
|
||||||
|
vec_token_push(&tmp.subtokens, token_clone(&input.buffer[i + j]));
|
||||||
|
j++;
|
||||||
|
}
|
||||||
vec_token_push(&out, tmp);
|
vec_token_push(&out, tmp);
|
||||||
i += j;
|
i += j;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
vec_token_push(&out, token_clone(&input.buffer[i++]));
|
vec_token_push(&out, token_clone(&input.buffer[i++]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
vec_token_free(input);
|
vec_token_free(input);
|
||||||
return (*output = out, NO_ERROR);
|
return (*output = out, NO_ERROR);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/28 14:37:13 by maiboyer #+# #+# */
|
/* Created: 2024/09/28 14:37:13 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/06 13:33:34 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/08 14:46:59 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,10 +16,8 @@
|
||||||
|
|
||||||
void token_free(t_token tok)
|
void token_free(t_token tok)
|
||||||
{
|
{
|
||||||
if (tok.string.buf != NULL)
|
string_free(tok.string);
|
||||||
string_free(tok.string);
|
vec_token_free(tok.subtokens);
|
||||||
if (tok.subtokens.buffer != NULL)
|
|
||||||
vec_token_free(tok.subtokens);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t_token token_new(enum e_token type)
|
t_token token_new(enum e_token type)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/06 13:32:28 by maiboyer #+# #+# */
|
/* Created: 2024/10/06 13:32:28 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/07 16:47:20 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/08 14:28:28 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -64,5 +64,7 @@ t_str token_name(t_token *token)
|
||||||
return ("DRPAREN");
|
return ("DRPAREN");
|
||||||
if (token->type == TOK_CMD)
|
if (token->type == TOK_CMD)
|
||||||
return ("CMD");
|
return ("CMD");
|
||||||
|
if (token->type == TOK_REDIR)
|
||||||
|
return ("REDIR");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/06 13:33:12 by maiboyer #+# #+# */
|
/* Created: 2024/10/06 13:33:12 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/08 13:40:57 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/08 14:51:41 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/07 18:04:13 by rparodi #+# #+# */
|
/* Created: 2024/10/07 18:04:13 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/10/08 14:20:10 by rparodi ### ########.fr */
|
/* Updated: 2024/10/08 14:51:28 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "me/vec/vec_token.h"
|
#include "me/vec/vec_token.h"
|
||||||
#include "parser/token.h"
|
#include "parser/token.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
int _get_precedance(t_token *token)
|
int _get_precedance(t_token *token)
|
||||||
{
|
{
|
||||||
|
|
@ -25,8 +26,9 @@ int _get_precedance(t_token *token)
|
||||||
return (1);
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
t_str token_name(t_token *token);
|
||||||
|
|
||||||
t_error yarn(t_vec_token *list, t_vec_token *output)
|
t_error yarn(t_vec_token ts, t_vec_token *out)
|
||||||
{
|
{
|
||||||
t_token tmp;
|
t_token tmp;
|
||||||
t_token tmp2;
|
t_token tmp2;
|
||||||
|
|
@ -35,7 +37,7 @@ t_error yarn(t_vec_token *list, t_vec_token *output)
|
||||||
|
|
||||||
output_queue = vec_token_new(16, token_free);;
|
output_queue = vec_token_new(16, token_free);;
|
||||||
operator_stack = vec_token_new(16, token_free);;
|
operator_stack = vec_token_new(16, token_free);;
|
||||||
while (!vec_token_pop_front(list, &tmp))
|
while (!vec_token_pop_front(&ts, &tmp))
|
||||||
{
|
{
|
||||||
if (tmp.type == TOK_CMD)
|
if (tmp.type == TOK_CMD)
|
||||||
vec_token_push(&output_queue, tmp);
|
vec_token_push(&output_queue, tmp);
|
||||||
|
|
@ -59,14 +61,20 @@ t_error yarn(t_vec_token *list, t_vec_token *output)
|
||||||
}
|
}
|
||||||
if (!(vec_token_last(&operator_stack) != NULL && vec_token_last(&operator_stack)->type == TOK_LPAREN))
|
if (!(vec_token_last(&operator_stack) != NULL && vec_token_last(&operator_stack)->type == TOK_LPAREN))
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
vec_token_pop(&operator_stack, NULL);
|
token_free(tmp);
|
||||||
|
vec_token_pop(&operator_stack, &tmp);
|
||||||
|
token_free(tmp);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
printf("TOK WTF? %s", token_name(&tmp));
|
||||||
}
|
}
|
||||||
while (!vec_token_pop(&operator_stack, &tmp))
|
while (!vec_token_pop(&operator_stack, &tmp))
|
||||||
{
|
{
|
||||||
if (tmp.type == TOK_LPAREN)
|
if (tmp.type == TOK_LPAREN)
|
||||||
return (ERROR);
|
return (token_free(tmp), ERROR);
|
||||||
vec_token_push(&output_queue, tmp);
|
vec_token_push(&output_queue, tmp);
|
||||||
}
|
}
|
||||||
return (*output = output_queue, NO_ERROR);
|
vec_token_free(ts);
|
||||||
|
vec_token_free(operator_stack);
|
||||||
|
return (*out = output_queue, NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/10/08 14:22:42 by rparodi ### ########.fr */
|
/* Updated: 2024/10/08 14:41:06 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -101,21 +101,20 @@ void print_node_data(t_node *t, t_usize depth)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
t_error yarn(t_vec_token *list, t_vec_token *output);
|
t_error yarn(t_vec_token ts, t_vec_token *output);
|
||||||
|
|
||||||
void parse_str(t_state *state)
|
void parse_str(t_state *state)
|
||||||
{
|
{
|
||||||
t_vec_token tokens;
|
t_vec_token tokens;
|
||||||
t_vec_token tok_yarn;
|
|
||||||
|
|
||||||
if (tokenize(state->str_input, &tokens))
|
if (tokenize(state->str_input, &tokens))
|
||||||
return ;
|
return ;
|
||||||
if (ts_apply_passes(tokens, &tokens))
|
if (ts_apply_passes(tokens, &tokens))
|
||||||
return ;
|
return ;
|
||||||
if (yarn(&tokens, &tok_yarn))
|
if (yarn(tokens, &tokens))
|
||||||
return ;
|
return ;
|
||||||
printf("\n\nEND TOKENS\n");
|
printf("\n\nEND TOKENS\n");
|
||||||
ts_print(&tok_yarn);
|
ts_print(&tokens);
|
||||||
vec_token_free(tokens);
|
vec_token_free(tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
make && valgrind --leak-check=full --show-leak-kinds=none --track-origins=yes --track-fds=yes --trace-children=yes --read-var-info=yes --read-inline-info=yes ./minishell <<<'cat </dev/null | cat | cat "./.envrc"'
|
make && valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --track-fds=yes --trace-children=yes --read-var-info=yes --read-inline-info=yes ./minishell <<<'cat </dev/null | (cat | cat "./.envrc") | banane | truc'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue