This commit is contained in:
Raphael 2024-08-02 14:46:14 +02:00
parent 1c840b41fd
commit 2b7c561cca
2 changed files with 125 additions and 103 deletions

View file

@ -6,107 +6,11 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/11 17:22:29 by maiboyer #+# #+# */
/* Updated: 2024/08/01 10:15:27 by maiboyer ### ########.fr */
/* Updated: 2024/08/02 14:45:19 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/state.h"
#include "ast/ast.h"
#include "exec/run.h"
#include "me/convert/numbers_to_str.h"
#include "me/fs/fs.h"
#include "me/hashmap/hashmap_env.h"
#include "me/mem/mem.h"
#include "me/os/os.h"
#include "me/str/str.h"
#include "me/string/string.h"
#include "me/types.h"
#include "me/vec/vec_estr.h"
#include "me/vec/vec_str.h"
#include <stdio.h>
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wempty-body"
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wunused-variable"
typedef struct s_expansion_result t_expansion_result;
struct s_expansion_result
{
bool exists;
t_str value;
};
typedef struct s_command_result t_command_result;
struct s_command_result
{
t_process process;
};
typedef struct s_word_result t_word_result;
struct s_word_result
{
bool has_error;
t_vec_estr value;
t_ast_word_kind kind;
};
typedef struct s_word_iterator t_word_iterator;
struct s_word_iterator
{
t_word_result res;
t_state *state;
};
typedef struct s_cmd_pipe t_cmd_pipe;
struct s_cmd_pipe
{
t_fd *output;
bool create_input;
};
t_error run_arithmetic_expansion(t_ast_arithmetic_expansion *arithmetic_expansion, t_state *state, t_i64 *out);
t_error run_command(t_ast_command *command, t_state *state, t_command_result *out);
t_error run_expansion(t_ast_expansion *self, t_state *state, t_expansion_result *out);
t_error run_word(t_ast_word *word, t_state *state, t_word_result *out);
t_error run_case_(t_ast_case *case_, t_state *state, void *out);
t_error run_case_item(t_ast_case_item *case_item, t_state *state, void *out);
t_error run_command_substitution(t_ast_command_substitution *command_substitution, t_state *state, void *out);
t_error run_compound_statement(t_ast_compound_statement *compound_statement, t_state *state, void *out);
t_error run_elif(t_ast_elif *elif, t_state *state, void *out);
t_error run_else_(t_ast_else *else_, t_state *state, void *out);
t_error run_empty(t_ast_empty *empty, t_state *state, void *out);
t_error run_extglob(t_ast_extglob *extglob, t_state *state, void *out);
t_error run_file_redirection(t_ast_file_redirection *file_redirection, t_state *state, void *out);
t_error run_for_(t_ast_for *for_, t_state *state, void *out);
t_error run_function_definition(t_ast_function_definition *function_definition, t_state *state, void *out);
t_error run_heredoc_redirection(t_ast_heredoc_redirection *heredoc_redirection, t_state *state, void *out);
t_error run_if_(t_ast_if *if_, t_state *state, void *out);
t_error run_list(t_ast_list *list, t_state *state, void *out);
t_error run_pipeline(t_ast_pipeline *pipeline, t_state *state, void *out);
t_error run_program(t_ast_program *program, t_state *state, void *out);
t_error run_raw_string(t_ast_raw_string *raw_string, t_state *state, void *out);
t_error run_regex(t_ast_regex *regex, t_state *state, void *out);
t_error run_subshell(t_ast_subshell *subshell, t_state *state, void *out);
t_error run_until(t_ast_until *until, t_state *state, void *out);
t_error run_variable_assignment(t_ast_variable_assignment *variable_assignment, t_state *state, void *out);
t_error run_while_(t_ast_while *while_, t_state *state, void *out);
#define NOT_DONE \
{ \
printf("function `%s` isn't done !\n", __func__); \
return (ERROR); \
}
// Start Internals funcs
#include "./run_ast.h"
bool _is_special_var(t_ast_expansion *self)
{
@ -119,12 +23,16 @@ bool _is_special_var(t_ast_expansion *self)
if (str_len(self->var_name) != 1)
return (false);
name = self->var_name[0];
if (name == '*' || name == '@' || name == '?' || name == '!' || name == '#' || name == '-' || name == '$' || name == '0')
if (name == '*' || name == '@' || \
name == '?' || name == '!' || \
name == '#' || name == '-' || \
name == '$' || name == '0')
return (true);
return (false);
}
t_error _run_expansion_special_var(t_ast_expansion *self, t_state *state, t_expansion_result *out)
t_error _run_expansion_special_var(\
t_ast_expansion *self, t_state *state, t_expansion_result *out)
{
char name;

114
exec/src/run_ast.h Normal file
View file

@ -0,0 +1,114 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* run_ast.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/02 14:41:48 by rparodi #+# #+# */
/* Updated: 2024/08/02 14:44:22 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef RUN_AST_H
# define RUN_AST_H
#include "app/state.h"
#include "ast/ast.h"
#include "exec/run.h"
#include "me/convert/numbers_to_str.h"
#include "me/fs/fs.h"
#include "me/hashmap/hashmap_env.h"
#include "me/mem/mem.h"
#include "me/os/os.h"
#include "me/str/str.h"
#include "me/string/string.h"
#include "me/types.h"
#include "me/vec/vec_estr.h"
#include "me/vec/vec_str.h"
#include <stdio.h>
#define NOT_DONE \
{ \
printf("function `%s` isn't done !\n", __func__); \
return (ERROR); \
}
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wempty-body"
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wunused-variable"
typedef struct s_expansion_result t_expansion_result;
struct s_expansion_result
{
bool exists;
t_str value;
};
typedef struct s_command_result t_command_result;
struct s_command_result
{
t_process process;
};
typedef struct s_word_result t_word_result;
struct s_word_result
{
bool has_error;
t_vec_estr value;
t_ast_word_kind kind;
};
typedef struct s_word_iterator t_word_iterator;
struct s_word_iterator
{
t_word_result res;
t_state *state;
};
typedef struct s_cmd_pipe t_cmd_pipe;
struct s_cmd_pipe
{
t_fd *output;
bool create_input;
};
t_error run_arithmetic_expansion(t_ast_arithmetic_expansion *arithmetic_expansion, t_state *state, t_i64 *out);
t_error run_command(t_ast_command *command, t_state *state, t_command_result *out);
t_error run_expansion(t_ast_expansion *self, t_state *state, t_expansion_result *out);
t_error run_word(t_ast_word *word, t_state *state, t_word_result *out);
t_error run_case_(t_ast_case *case_, t_state *state, void *out);
t_error run_case_item(t_ast_case_item *case_item, t_state *state, void *out);
t_error run_command_substitution(t_ast_command_substitution *command_substitution, t_state *state, void *out);
t_error run_compound_statement(t_ast_compound_statement *compound_statement, t_state *state, void *out);
t_error run_elif(t_ast_elif *elif, t_state *state, void *out);
t_error run_else_(t_ast_else *else_, t_state *state, void *out);
t_error run_empty(t_ast_empty *empty, t_state *state, void *out);
t_error run_extglob(t_ast_extglob *extglob, t_state *state, void *out);
t_error run_file_redirection(t_ast_file_redirection *file_redirection, t_state *state, void *out);
t_error run_for_(t_ast_for *for_, t_state *state, void *out);
t_error run_function_definition(t_ast_function_definition *function_definition, t_state *state, void *out);
t_error run_heredoc_redirection(t_ast_heredoc_redirection *heredoc_redirection, t_state *state, void *out);
t_error run_if_(t_ast_if *if_, t_state *state, void *out);
t_error run_list(t_ast_list *list, t_state *state, void *out);
t_error run_pipeline(t_ast_pipeline *pipeline, t_state *state, void *out);
t_error run_program(t_ast_program *program, t_state *state, void *out);
t_error run_raw_string(t_ast_raw_string *raw_string, t_state *state, void *out);
t_error run_regex(t_ast_regex *regex, t_state *state, void *out);
t_error run_subshell(t_ast_subshell *subshell, t_state *state, void *out);
t_error run_until(t_ast_until *until, t_state *state, void *out);
t_error run_variable_assignment(t_ast_variable_assignment *variable_assignment, t_state *state, void *out);
t_error run_while_(t_ast_while *while_, t_state *state, void *out);
#endif