merged from master!
This commit is contained in:
commit
b4c6aed6c4
15 changed files with 210 additions and 19 deletions
8
.clangd
8
.clangd
|
|
@ -17,4 +17,12 @@ CompileFlags: # Tweak the parse settings
|
|||
- "-I/home/maix/school/shcat/includes/"
|
||||
- "-I/home/maix/school/shcat/output/include/"
|
||||
- "-I/home/maix/school/shcat/generic_sources/header/"
|
||||
- "-I/home/rparodi/Documents/shcat/vendor/"
|
||||
- "-I/home/rparodi/Documents/shcat/stdme/include/"
|
||||
- "-I/home/rparodi/Documents/shcat/stdme/vendor/"
|
||||
- "-I/home/rparodi/Documents/shcat/stdme/output/include/"
|
||||
- "-I/home/rparodi/Documents/shcat/stdme/generic_sources/header/"
|
||||
- "-I/home/rparodi/Documents/shcat/includes/"
|
||||
- "-I/home/rparodi/Documents/shcat/output/include/"
|
||||
- "-I/home/rparodi/Documents/shcat/generic_sources/header/"
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/04 18:41:01 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/04 19:08:13 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/09 14:28:42 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/28 18:35:22 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/04/30 16:41:44 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/09 16:23:54 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
22
includes/app/node/handle_command.h
Normal file
22
includes/app/node/handle_command.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* handle_command.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/09 14:42:43 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/09 14:59:28 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef HANDLE_COMMAND_H
|
||||
# define HANDLE_COMMAND_H
|
||||
|
||||
# include "me/types.h"
|
||||
# include "app/state.h"
|
||||
# include "app/node.h"
|
||||
|
||||
t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code);
|
||||
|
||||
#endif
|
||||
22
includes/app/node/handle_program.h
Normal file
22
includes/app/node/handle_program.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* handle_program.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/09 14:42:43 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/09 15:51:11 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef HANDLE_PROGRAM_H
|
||||
# define HANDLE_PROGRAM_H
|
||||
|
||||
# include "me/types.h"
|
||||
# include "app/state.h"
|
||||
# include "app/node.h"
|
||||
|
||||
t_error handle_program(t_node *self, t_utils *shcat, t_i32 *out_exit_code);
|
||||
|
||||
#endif
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/02 15:49:56 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/04 18:40:53 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/09 16:23:54 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
#include "app/node.h"
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
#include "me/types.h"
|
||||
#include "me/os/process.h"
|
||||
|
||||
typedef struct s_parser
|
||||
{
|
||||
|
|
@ -24,13 +25,14 @@ typedef struct s_parser
|
|||
|
||||
typedef struct s_utils
|
||||
{
|
||||
t_str name_shell;
|
||||
t_str str_input;
|
||||
t_str *strs_input;
|
||||
t_str *path;
|
||||
t_parser parser;
|
||||
t_hashmap_env *env;
|
||||
t_node current_node;
|
||||
t_str name_shell;
|
||||
t_str str_input;
|
||||
t_str *strs_input;
|
||||
t_str *path;
|
||||
t_parser parser;
|
||||
t_hashmap_env *env;
|
||||
t_node current_node;
|
||||
t_process ret;
|
||||
} t_utils;
|
||||
|
||||
#endif /* STATE_H */
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 14:41:15 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/03 15:22:24 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/09 16:28:26 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -48,4 +48,6 @@ void ft_echo(t_str txt, t_str flag);
|
|||
void ft_exit(t_utils *maiboyerlpb, t_u8 exit_status);
|
||||
void ft_free(void *ptr);
|
||||
|
||||
t_error handle_node_getstr(t_node *self, t_utils *shcat, t_str *out);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ static bool scan_heredoc_content(Scanner *scanner, t_lexer_data *lexer, enum Tok
|
|||
lexer->mark_end(lexer);
|
||||
if (scan_heredoc_end_identifier(heredoc, lexer)) {
|
||||
if (lexer->result_symbol == HEREDOC_END) {
|
||||
array_pop(&scanner->heredocs);
|
||||
(void) array_pop(&scanner->heredocs);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -444,7 +444,7 @@ static bool scan(Scanner *scanner, t_lexer_data *lexer, const bool *valid_symbol
|
|||
if (scan_heredoc_end_identifier(heredoc, lexer)) {
|
||||
array_delete(&heredoc->current_leading_word);
|
||||
array_delete(&heredoc->delimiter);
|
||||
array_pop(&scanner->heredocs);
|
||||
(void)array_pop(&scanner->heredocs);
|
||||
lexer->result_symbol = HEREDOC_END;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
69
sources/exec/handle_command.c
Normal file
69
sources/exec/handle_command.c
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* handle_command.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/09 15:00:53 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/09 17:14:32 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "app/env.h"
|
||||
#include "app/state.h"
|
||||
#include "me/types.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "app/node.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
// #include "app/node/handle_program.h"
|
||||
#include "app/node/handle_command.h"
|
||||
#include "minishell.h"
|
||||
#include "me/string/str_clone.h"
|
||||
#include <time.h>
|
||||
|
||||
t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code)
|
||||
{
|
||||
t_usize i;
|
||||
t_spawn_info spawn_info;
|
||||
t_str tmp;
|
||||
|
||||
spawn_info.arguments = vec_str_new(self->childs_count, (void (*)(t_str))free);
|
||||
if (self->kind != sym_command)
|
||||
return (ERROR);
|
||||
i = 0;
|
||||
while (i < self->childs_count)
|
||||
{
|
||||
if (self->childs[i].kind == sym_command_name)
|
||||
spawn_info.binary_path = str_clone(node_getstr(&self->childs[i]));
|
||||
else if (self->childs[i].kind == sym_file_redirect)
|
||||
printf("PAS ENCORE HANDLE FDP redirect!\n");
|
||||
else if (self->childs[i].kind == sym_variable_assignment)
|
||||
printf("PAS ENCORE HANDLE FDP asignement!\n");
|
||||
else
|
||||
{
|
||||
printf("%s %s\n", self->childs[i].kind_str, node_getstr(&self->childs[i]));
|
||||
if (handle_node_getstr(&self->childs[i], shcat, &tmp))
|
||||
return (vec_str_free(spawn_info.arguments), ERROR);
|
||||
if (vec_str_push(&spawn_info.arguments, tmp))
|
||||
return (ERROR);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
vec_str_push_front(&spawn_info.arguments, str_clone(spawn_info.binary_path));
|
||||
vec_str_push(&spawn_info.arguments, NULL);
|
||||
spawn_info.stdin = inherited();
|
||||
spawn_info.stdout = inherited();
|
||||
spawn_info.stderr = inherited();
|
||||
spawn_info.forked_free = NULL;
|
||||
if (build_envp(shcat->env, &spawn_info.environement))
|
||||
return (vec_str_free(spawn_info.arguments), ERROR);
|
||||
if (spawn_process(spawn_info, &shcat->ret))
|
||||
return (ERROR);
|
||||
waitpid(shcat->ret.pid, NULL, 0);
|
||||
close(shcat->ret.stdin.vals.ro.fd);
|
||||
close(shcat->ret.stdout.vals.ro.fd);
|
||||
close(shcat->ret.stderr.vals.ro.fd);
|
||||
*out_exit_code = 0;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
36
sources/exec/handle_program.c
Normal file
36
sources/exec/handle_program.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* handle_program.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/09 14:34:48 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/09 15:06:42 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
# include "app/state.h"
|
||||
# include "me/types.h"
|
||||
# include "gmr/symbols.h"
|
||||
# include "app/node.h"
|
||||
# include "app/node/handle_program.h"
|
||||
# include "app/node/handle_command.h"
|
||||
|
||||
t_error handle_program(t_node *self, t_utils *shcat, t_i32 *out_exit_code)
|
||||
{
|
||||
t_usize i;
|
||||
|
||||
if (self->kind != sym_program)
|
||||
return (ERROR);
|
||||
i = 0;
|
||||
while (i < self->childs_count)
|
||||
{
|
||||
if (self->childs[i].kind == sym_command)
|
||||
if (handle_command(&self->childs[i], shcat, out_exit_code))
|
||||
return (ERROR);
|
||||
i++;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
@ -12,12 +12,15 @@
|
|||
|
||||
#include "app/env.h"
|
||||
#include "app/node.h"
|
||||
#include "app/node/handle_program.h"
|
||||
#include "app/signal_handler.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "minishell.h"
|
||||
#include "parser/api.h"
|
||||
#include "app/node/handle_concat.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
#undef free
|
||||
#undef malloc
|
||||
|
|
@ -32,6 +35,21 @@ t_first_tree *ts_parser_parse_string(t_first_parser *, t_first_tree *oldtree,
|
|||
void ts_parser_delete(t_first_parser *self);
|
||||
void ts_parser_set_language(t_first_parser *self, t_language *lang);
|
||||
|
||||
|
||||
t_error handle_node_getstr(t_node *self, t_utils *shcat, t_str *out)
|
||||
{
|
||||
switch (self->kind)
|
||||
{
|
||||
case sym_word:
|
||||
*out = node_getstr(self);
|
||||
return (NO_ERROR);
|
||||
case sym_concatenation:
|
||||
return (handle_concat(self, shcat, out));
|
||||
default:
|
||||
return (ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
void print_node_data(t_node *t, t_usize depth)
|
||||
{
|
||||
t_usize idx;
|
||||
|
|
@ -104,9 +122,12 @@ void print_node_concat(t_node *self)
|
|||
|
||||
void exec_shcat(t_utils *shcat)
|
||||
{
|
||||
t_i32 ret;
|
||||
|
||||
print_node_data(&shcat->current_node, 0);
|
||||
print_node_concat(&shcat->current_node);
|
||||
handle_program(&shcat->current_node, shcat, &ret);
|
||||
free_node(shcat->current_node);
|
||||
(void)ret;
|
||||
}
|
||||
|
||||
void ft_take_args(t_utils *shcat)
|
||||
|
|
@ -117,8 +138,6 @@ void ft_take_args(t_utils *shcat)
|
|||
shcat->str_input = readline((t_const_str)shcat->name_shell);
|
||||
if (!shcat->str_input)
|
||||
ft_exit(shcat, 0);
|
||||
else if (ft_strcmp(shcat->str_input, "exit") == 0)
|
||||
ft_exit(shcat, 0);
|
||||
shcat->current_node = parse_str(&shcat->parser, shcat->str_input);
|
||||
exec_shcat(shcat);
|
||||
add_history(shcat->str_input);
|
||||
|
|
@ -174,6 +193,8 @@ t_i32 main(t_i32 argc, t_str argv[], t_str envp[])
|
|||
utils = (t_utils){};
|
||||
utils.parser = create_myparser();
|
||||
utils.env = create_env_map();
|
||||
if (install_signal())
|
||||
return (1);
|
||||
utils.name_shell = "\001\x1B[93m\002"
|
||||
"42sh"
|
||||
"\001\x1B[32m\002"
|
||||
|
|
|
|||
2
src.list
2
src.list
|
|
@ -1,6 +1,8 @@
|
|||
env.c
|
||||
exec/handle_command.c
|
||||
exec/handle_concat.c
|
||||
exec/handle_expension.c
|
||||
exec/handle_program.c
|
||||
exec/handle_raw_word.c
|
||||
exec/handle_word.c
|
||||
ft_cmd.c
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/03 16:22:41 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/04/30 21:17:22 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/09 16:55:16 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -84,6 +84,8 @@ t_error find_binary(t_spawn_info *info, t_process *process)
|
|||
t_buffer_str s;
|
||||
|
||||
(void)(process);
|
||||
if (info->binary_path == NULL)
|
||||
return (ERROR);
|
||||
s = alloc_new_buffer(256);
|
||||
if (str_start_with(info->binary_path, "/")
|
||||
|| str_find_chr(info->binary_path, '/') != NULL)
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/04 22:25:44 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/04 22:26:10 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/09 16:57:24 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
bool find_null(const t_str *s)
|
||||
{
|
||||
|
|
@ -29,5 +30,7 @@ bool str_start_with(t_const_str s, t_const_str prefix)
|
|||
|
||||
bool find_path(const t_str *s)
|
||||
{
|
||||
if (*s == NULL)
|
||||
return (false);
|
||||
return (str_start_with(*s, "PATH="));
|
||||
}
|
||||
|
|
|
|||
2
to_do_raph.md
Normal file
2
to_do_raph.md
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# Important:
|
||||
- Parse envp and put it in shcat->env with functions in `me/hashmap/hashmap_env.h`
|
||||
Loading…
Add table
Add a link
Reference in a new issue