Update so '$BANANE=truc' works
This commit is contained in:
parent
ecf01a6b8b
commit
11ec5cfa3c
14 changed files with 183 additions and 120 deletions
5
Makefile
5
Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||
# Updated: 2024/08/11 11:56:54 by maiboyer ### ########.fr #
|
||||
# Updated: 2024/08/12 17:00:12 by maiboyer ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -43,7 +43,8 @@ endif
|
|||
endif
|
||||
|
||||
# TODO: ADD THIS WHEN FINISHING THIS:
|
||||
# CFLAGS_ADDITIONAL += -DNVALGRIND
|
||||
CFLAGS_ADDITIONAL += -DNVALGRIND
|
||||
CFLAGS_ADDITIONAL += -O0 -Wno-cpp
|
||||
|
||||
# TODO: REMOVE THIS WHEN FINISHING THIS:
|
||||
CFLAGS_ADDITIONAL += -gcolumn-info -g3
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ from_node/artihmetic_node \
|
|||
from_node/boucle_node \
|
||||
from_node/condition_node \
|
||||
from_node/dev_node \
|
||||
from_node/expand_node \
|
||||
from_node/expansion_node \
|
||||
from_node/file_node \
|
||||
from_node/from_node \
|
||||
|
|
@ -18,12 +17,12 @@ from_node/node_utils \
|
|||
from_node/node_utils2 \
|
||||
from_node/redirect_node \
|
||||
from_node/scripting_node \
|
||||
print_ast/ast_print \
|
||||
print_ast/ast_print_arithmetic \
|
||||
print_ast/ast_print_command \
|
||||
print_ast/ast_print_global \
|
||||
print_ast/ast_print_helper_function \
|
||||
print_ast/ast_print_node \
|
||||
print_ast/ast_print_redirection \
|
||||
print_ast/ast_print_subshell \
|
||||
print_ast/helper_function_print \
|
||||
print_ast/print_arithmetic \
|
||||
print_ast/print_ast \
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/11 14:23:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/02 17:02:03 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/08/12 16:10:42 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -92,7 +92,8 @@ struct s_ast_node
|
|||
t_ast_node_data data;
|
||||
};
|
||||
|
||||
void ast_free(t_ast_node self);
|
||||
t_ast_node ast_alloc(t_ast_node_kind kind);
|
||||
void ast_free(t_ast_node self);
|
||||
void ast_print(t_ast_node self);
|
||||
|
||||
#endif /* AST_H */
|
||||
|
|
|
|||
|
|
@ -6,15 +6,13 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/26 10:55:52 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/09 16:26:13 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/08/12 16:35:07 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_from_node.h"
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
|
|
@ -105,7 +103,7 @@ if (symbol == anon_sym_LT_GT)
|
|||
*/
|
||||
// RAPH
|
||||
|
||||
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out);
|
||||
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out);
|
||||
|
||||
/* FUNCTION THAT ARE DONE */
|
||||
|
||||
|
|
@ -114,12 +112,11 @@ t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out);
|
|||
// RAPH
|
||||
// PLUS RAPH
|
||||
|
||||
t_error build_sym_command_substitution(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
t_error build_sym_command_substitution(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -130,14 +127,12 @@ t_error build_sym_command_substitution(\
|
|||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
continue ;
|
||||
continue;
|
||||
if (ts_node_symbol(ts_node_child(self, i)) == field_term)
|
||||
{
|
||||
if (ret->data.command_substitution.body.len != 0)
|
||||
ast_set_term(\
|
||||
&ret->data.command_substitution.body.buffer[\
|
||||
ret->data.command_substitution.body.len - 1], \
|
||||
_select_term(ts_node_child(self, i)));
|
||||
ast_set_term(&ret->data.command_substitution.body.buffer[ret->data.command_substitution.body.len - 1],
|
||||
_select_term(ts_node_child(self, i)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -157,13 +152,12 @@ t_error build_sym_command_substitution(\
|
|||
/* ret->data.file_redirection.input = tmp; */
|
||||
/* } */
|
||||
|
||||
t_error build_sym_do_group(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
t_error build_sym_do_group(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
t_ast_terminator_kind term;
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
t_ast_terminator_kind term;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
|
|
@ -176,19 +170,15 @@ t_error build_sym_do_group(\
|
|||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (ts_node_symbol(ts_node_child(self, i)) == anon_sym_do \
|
||||
|| ts_node_symbol(ts_node_child(self, i)) == anon_sym_done)
|
||||
if (ts_node_symbol(ts_node_child(self, i)) == anon_sym_do || ts_node_symbol(ts_node_child(self, i)) == anon_sym_done)
|
||||
{
|
||||
i++;
|
||||
continue ;
|
||||
continue;
|
||||
}
|
||||
if (ts_node_field_id_for_child(self, i) == field_term \
|
||||
&& ret->data.compound_statement.body.len != 0)
|
||||
if (ts_node_field_id_for_child(self, i) == field_term && ret->data.compound_statement.body.len != 0)
|
||||
{
|
||||
term = _select_term(ts_node_child(self, i));
|
||||
ast_set_term(
|
||||
&ret->data.compound_statement.body.buffer[\
|
||||
ret->data.compound_statement.body.len - 1], term);
|
||||
ast_set_term(&ret->data.compound_statement.body.buffer[ret->data.compound_statement.body.len - 1], term);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -201,13 +191,12 @@ t_error build_sym_do_group(\
|
|||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_subshell(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
t_error build_sym_subshell(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
t_ast_terminator_kind term;
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
t_ast_terminator_kind term;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
|
|
@ -220,18 +209,15 @@ t_error build_sym_subshell(\
|
|||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (ts_node_field_id_for_child(self, i) == field_term \
|
||||
&& ret->data.subshell.body.len != 0)
|
||||
if (ts_node_field_id_for_child(self, i) == field_term && ret->data.subshell.body.len != 0)
|
||||
{
|
||||
term = _select_term(ts_node_child(self, i));
|
||||
ast_set_term(\
|
||||
&ret->data.subshell.body.buffer[\
|
||||
ret->data.subshell.body.len - 1], term);
|
||||
ast_set_term(&ret->data.subshell.body.buffer[ret->data.subshell.body.len - 1], term);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
continue ;
|
||||
continue;
|
||||
if (ast_from_node(ts_node_child(self, i), input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.subshell.body, tmp);
|
||||
|
|
@ -243,13 +229,12 @@ t_error build_sym_subshell(\
|
|||
|
||||
// t_error buildw
|
||||
|
||||
t_error build_sym_compound_statement(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
t_error build_sym_compound_statement(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
t_ast_terminator_kind term;
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
t_ast_terminator_kind term;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
|
|
@ -262,17 +247,15 @@ t_error build_sym_compound_statement(\
|
|||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (ts_node_field_id_for_child(self, i) == field_term \
|
||||
&& ret->data.compound_statement.body.len != 0)
|
||||
if (ts_node_field_id_for_child(self, i) == field_term && ret->data.compound_statement.body.len != 0)
|
||||
{
|
||||
term = _select_term(ts_node_child(self, i));
|
||||
ast_set_term(&ret->data.compound_statement.body.buffer[\
|
||||
ret->data.compound_statement.body.len - 1], term);
|
||||
ast_set_term(&ret->data.compound_statement.body.buffer[ret->data.compound_statement.body.len - 1], term);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
continue ;
|
||||
continue;
|
||||
if (ast_from_node(ts_node_child(self, i), input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.compound_statement.body, tmp);
|
||||
|
|
@ -282,11 +265,11 @@ t_error build_sym_compound_statement(\
|
|||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_ast_node temp;
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_ast_node temp;
|
||||
|
||||
(void)(self);
|
||||
(void)(input);
|
||||
|
|
@ -301,7 +284,7 @@ t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out)
|
|||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
continue ;
|
||||
continue;
|
||||
if (ast_from_node(ts_node_child(self, i), input, &temp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.word.inner, temp);
|
||||
|
|
@ -310,12 +293,11 @@ t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out)
|
|||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_concatenation(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
t_error build_sym_concatenation(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_ast_node temp;
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_ast_node temp;
|
||||
|
||||
(void)(self);
|
||||
(void)(input);
|
||||
|
|
@ -337,11 +319,10 @@ t_error build_sym_concatenation(\
|
|||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_string_content(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
t_error build_sym_string_content(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_str temp_str;
|
||||
t_ast_node ret;
|
||||
t_str temp_str;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -355,12 +336,11 @@ t_error build_sym_string_content(\
|
|||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_raw_string(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
t_error build_sym_raw_string(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node temp;
|
||||
t_str temp_str;
|
||||
t_ast_node ret;
|
||||
t_ast_node temp;
|
||||
t_str temp_str;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -379,11 +359,11 @@ t_error build_sym_raw_string(\
|
|||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_ast_node temp;
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_ast_node temp;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -403,18 +383,15 @@ t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out)
|
|||
if (ts_node_field_id_for_child(self, i) == field_term)
|
||||
{
|
||||
if (ret->data.program.body.len == 0 && (i++, true))
|
||||
continue ;
|
||||
ast_set_term(&ret->data.program.body.buffer[\
|
||||
ret->data.program.body.len - 1], \
|
||||
_select_term(ts_node_child(self, i)));
|
||||
continue;
|
||||
ast_set_term(&ret->data.program.body.buffer[ret->data.program.body.len - 1], _select_term(ts_node_child(self, i)));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_command_name(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
t_error build_sym_command_name(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -423,11 +400,11 @@ t_error build_sym_command_name(\
|
|||
return (ast_from_node(ts_node_child(self, 0), input, out));
|
||||
}
|
||||
|
||||
t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_str temp_str;
|
||||
t_ast_node temp;
|
||||
t_ast_node ret;
|
||||
t_str temp_str;
|
||||
t_ast_node temp;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -444,12 +421,12 @@ t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out)
|
|||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
t_error build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_usize vec_idx;
|
||||
t_ast_node temp;
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_usize vec_idx;
|
||||
t_ast_node temp;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -471,10 +448,10 @@ t_error build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out)
|
|||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_list(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
t_error build_sym_list(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node *output;
|
||||
t_ast_node *output;
|
||||
t_usize i;
|
||||
t_symbol temp;
|
||||
|
||||
|
|
@ -578,7 +555,7 @@ sym_while_statement
|
|||
sym_word
|
||||
*/
|
||||
|
||||
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out)
|
||||
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -589,8 +566,7 @@ t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out)
|
|||
if (ts_node_symbol(node) == sym_arithmetic_literal)
|
||||
return (build_sym_arithmetic_literal(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_arithmetic_parenthesized_expression)
|
||||
return (build_sym_arithmetic_parenthesized_expression(\
|
||||
node, input, out));
|
||||
return (build_sym_arithmetic_parenthesized_expression(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_arithmetic_postfix_expression)
|
||||
return (build_sym_arithmetic_postfix_expression(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_arithmetic_ternary_expression)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* print_ast.c :+: :+: :+: */
|
||||
/* ast_print.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/03 20:38:29 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/30 18:38:50 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/08/12 16:34:50 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -80,8 +80,6 @@ static inline void ast_print_block2(t_ast_node self)
|
|||
return (ast_print_node_for(self));
|
||||
if (self->kind == AST_FUNCTION_DEFINITION)
|
||||
return (ast_print_node_function_definition(self));
|
||||
if (self == NULL)
|
||||
return ((void)printf("ast == NULL\n"));
|
||||
if (self->kind == AST_HEREDOC_REDIRECTION)
|
||||
return (ast_print_node_heredoc_redirection(self));
|
||||
if (self->kind == AST_IF)
|
||||
|
|
@ -114,7 +112,9 @@ static inline void ast_print_block3(t_ast_node self)
|
|||
printf("Unknown ast->kind: %#04x\n", self->kind);
|
||||
}
|
||||
|
||||
void ast_print_node(t_ast_node self)
|
||||
void ast_print(t_ast_node self)
|
||||
{
|
||||
if (self == NULL)
|
||||
return ((void)printf("ast == NULL\n"));
|
||||
ast_print_block1(self);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/03 20:38:29 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/26 13:21:44 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/08/12 16:33:47 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -64,6 +64,7 @@ void ast_print_node_command(t_ast_node self)
|
|||
ast_print_node(self->data.command.prefixes.buffer[i++]);
|
||||
printf(" ");
|
||||
}
|
||||
return (ast_print_node_command_helper(self));
|
||||
}
|
||||
|
||||
void ast_print_node_expansion_choose_op(t_ast_node self)
|
||||
|
|
|
|||
|
|
@ -6,17 +6,75 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/07 14:13:41 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/11 11:26:08 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/08/12 15:58:55 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec/builtins.h"
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
|
||||
struct s_print_export_state
|
||||
{
|
||||
t_state *state;
|
||||
t_builtin_spawn_info *info;
|
||||
};
|
||||
struct s_assign_export_state
|
||||
{
|
||||
t_state *state;
|
||||
t_builtin_spawn_info *info;
|
||||
t_error err;
|
||||
};
|
||||
static void _assign_export(t_usize idx, t_str *arg, void *vctx)
|
||||
{
|
||||
struct s_assign_export_state *ctx;
|
||||
const char *first_eq;
|
||||
t_str key;
|
||||
t_str value;
|
||||
|
||||
if (arg == NULL || *arg == NULL || idx == 0)
|
||||
return;
|
||||
ctx = vctx;
|
||||
first_eq = str_find_chr(*arg, '=');
|
||||
if (first_eq == NULL || first_eq == *arg)
|
||||
return;
|
||||
key = str_substring(*arg, 0, first_eq - *arg);
|
||||
value = str_substring(first_eq, 1, ~0llu);
|
||||
if (hmap_env_insert(ctx->state->env, key, value))
|
||||
ctx->err = ERROR;
|
||||
}
|
||||
|
||||
static t_error _print_export(t_usize _idx, const t_str *key, t_str *value, void *vctx)
|
||||
{
|
||||
const struct s_print_export_state *ctx = vctx;
|
||||
t_str *val;
|
||||
t_str true_val;
|
||||
|
||||
val = hmap_env_get(ctx->state->tmp_var, (t_str *)key);
|
||||
if (val == NULL)
|
||||
val = value;
|
||||
if (val == NULL)
|
||||
return (NO_ERROR);
|
||||
true_val = *val;
|
||||
if (true_val == NULL)
|
||||
true_val = "";
|
||||
me_printf_fd(ctx->info->stdout, "export %s='%s'\n", *key, true_val);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error builtin_export(t_state *state, t_builtin_spawn_info info, t_i32 *exit_code)
|
||||
{
|
||||
struct s_print_export_state print_ctx;
|
||||
struct s_assign_export_state assign_ctx;
|
||||
print_ctx.info = &info;
|
||||
print_ctx.state = state;
|
||||
assign_ctx.info = &info;
|
||||
assign_ctx.state = state;
|
||||
assign_ctx.err = NO_ERROR;
|
||||
if (info.args.len == 1)
|
||||
return (builtin_env___(state, info, exit_code));
|
||||
|
||||
return (*exit_code = 0, NO_ERROR);
|
||||
return (*exit_code = 0, hmap_env_iter(state->env, _print_export, &print_ctx));
|
||||
return (*exit_code = 0, vec_str_iter(&info.args, _assign_export, &assign_ctx), assign_ctx.err);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/11 17:22:29 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/11 12:48:42 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/08/12 16:57:47 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -304,6 +304,25 @@ t_error _ast_get_str__command_substitution(t_ast_node elem, t_word_iterator *sta
|
|||
// vec_estr_push(out, (t_expandable_str){.do_expand = state->res.kind == AST_WORD_NO_QUOTE, .value = str_clone(exp_out.value)});
|
||||
return (ERROR);
|
||||
}
|
||||
t_error _ast_get_str(t_ast_node elem, t_word_iterator *state, t_vec_estr *out);
|
||||
t_error _ast_into_str(t_ast_node self, t_state *state, t_vec_str *append);
|
||||
|
||||
t_error _ast_get_str__word(t_ast_node elem, t_word_iterator *state, t_vec_estr *out)
|
||||
{
|
||||
t_usize i;
|
||||
t_vec_str res;
|
||||
t_str tmp;
|
||||
|
||||
if (elem == NULL || state == NULL || out == NULL || elem->kind != AST_WORD)
|
||||
return (ERROR);
|
||||
res = vec_str_new(16, str_free);
|
||||
if (_ast_into_str(elem, state->state, &res))
|
||||
return (vec_str_free(res), ERROR);
|
||||
while (!vec_str_pop_front(&res, &tmp))
|
||||
vec_estr_push(out, (t_expandable_str){.do_expand = false, .value = tmp});
|
||||
vec_str_free(res);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error _ast_get_str(t_ast_node elem, t_word_iterator *state, t_vec_estr *out)
|
||||
{
|
||||
|
|
@ -317,7 +336,9 @@ t_error _ast_get_str(t_ast_node elem, t_word_iterator *state, t_vec_estr *out)
|
|||
return (_ast_get_str__arimethic_expansion(elem, state, out));
|
||||
if (elem->kind == AST_COMMAND_SUBSTITUTION)
|
||||
return (_ast_get_str__command_substitution(elem, state, out));
|
||||
return (NO_ERROR);
|
||||
if (elem->kind == AST_WORD)
|
||||
return (_ast_get_str__word(elem, state, out));
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
void _run_word_into_str(t_usize idx, t_ast_node *elem, t_word_iterator *state)
|
||||
|
|
@ -398,9 +419,9 @@ t_error _word_into_str(t_ast_node self, t_state *state, t_vec_str *append)
|
|||
else
|
||||
{
|
||||
ifs = _get_ifs_value(state);
|
||||
while (*ifs != '\0' && str_find_chr(res.value.buffer[i].value, *ifs) == NULL)
|
||||
while (ifs != NULL && *ifs != '\0' && str_find_chr(res.value.buffer[i].value, *ifs) == NULL)
|
||||
ifs++;
|
||||
if (*ifs == '\0')
|
||||
if (ifs == NULL || *ifs == '\0')
|
||||
string_push(&tmp, res.value.buffer[i].value);
|
||||
else
|
||||
{
|
||||
|
|
@ -445,7 +466,9 @@ t_error _word_into_str(t_ast_node self, t_state *state, t_vec_str *append)
|
|||
tmp = string_new(64);
|
||||
i = 0;
|
||||
while (i < res.value.len)
|
||||
{
|
||||
string_push(&tmp, res.value.buffer[i++].value);
|
||||
}
|
||||
vec_str_push(append, tmp.buf);
|
||||
}
|
||||
vec_estr_free(res.value);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/05 14:50:22 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/08/12 16:58:25 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,13 +19,13 @@
|
|||
#include "exec/_run_ast.h"
|
||||
#include "line/line.h"
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/string/string.h"
|
||||
#include "me/types.h"
|
||||
#include "parser/api.h"
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include "me/mem/mem.h"
|
||||
|
||||
t_error ast_from_node(t_parse_node node, t_str input, t_ast_node *out);
|
||||
void ast_print_node(t_ast_node self);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 17:29:13 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 14:47:43 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/08/12 16:05:13 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,6 +16,8 @@ char *str_find_chr(t_const_str str, char chr)
|
|||
{
|
||||
t_usize index;
|
||||
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
index = 0;
|
||||
while (str[index])
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/10 11:11:01 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:53:53 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/08/12 16:05:30 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,6 +17,8 @@ const char *str_find_str(t_const_str str, t_const_str to_find)
|
|||
t_str needle;
|
||||
t_str haystack;
|
||||
|
||||
if (str == NULL || to_find == NULL)
|
||||
return (NULL);
|
||||
if (*to_find == '\0')
|
||||
return (str);
|
||||
while (*str)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue