normed the stdme headers

This commit is contained in:
Maieul BOYER 2024-07-11 19:01:59 +02:00
parent 79e039c94a
commit 398dd520d0
No known key found for this signature in database
84 changed files with 297 additions and 2819 deletions

View file

@ -1,77 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_command.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 15:00:53 by rparodi #+# #+# */
/* Updated: 2024/06/21 13:55:02 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/env.h"
#include "app/node.h"
#include "app/state.h"
#include "gmr/symbols.h"
#include "me/mem/mem.h"
#include "me/types.h"
#include "me/vec/vec_str.h"
// #include "app/node/handle_program.h"
#include "app/node/handle_command.h"
#include "me/str/str.h"
#include "minishell.h"
#include <time.h>
void handle_command_free_infork(void *vshcat)
{
t_utils *shcat;
shcat = vshcat;
(void)(shcat);
//ft_exit(shcat, 255);
}
t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code)
{
t_usize i;
t_spawn_info spawn_info;
spawn_info.arguments =
vec_str_new(64, (void (*)(t_str))mem_free); // TODO: FIX VECTOR
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]));
vec_str_push(&spawn_info.arguments,
str_clone(spawn_info.binary_path));
printf("%s\n", spawn_info.arguments.buffer[0]);
}
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
{
}
i++;
}
spawn_info.stdin = inherited();
spawn_info.stdout = inherited();
spawn_info.stderr = inherited();
spawn_info.forked_free = handle_command_free_infork;
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);
}

View file

@ -1,52 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_concat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 15:05:06 by maiboyer #+# #+# */
/* Updated: 2024/05/07 14:59:27 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/node/handle_concat.h"
#include "app/node.h"
#include "app/node/handle_raw_word.h"
#include "app/node/handle_word.h"
#include "app/state.h"
#include "gmr/symbols.h"
#include "me/string/string.h"
#include "me/types.h"
t_error node_get_string(t_node *self, t_utils *shcat, t_str *ret)
{
if (self->kind == sym_word)
return (handle_word(self, shcat, ret));
if (self->kind == sym_raw_string)
return (handle_raw_string(self, shcat, ret));
return (ERROR);
}
t_error handle_concat(t_node *self, t_utils *shcat, t_str *ret)
{
t_string out;
t_usize i;
t_str tmp;
(void)(shcat);
if (self == NULL || ret == NULL || self->kind != sym_concatenation)
return (ERROR);
out = string_new(16);
i = 0;
while (i < self->childs_count)
{
if (node_get_string(&self->childs[i], shcat, &tmp))
return (string_free(out), ERROR);
string_push(&out, tmp);
mem_free(tmp);
i++;
}
*ret = out.buf;
return (NO_ERROR);
}

View file

@ -1,42 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_expension.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/03 15:24:25 by maiboyer #+# #+# */
/* Updated: 2024/05/07 14:55:25 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/node/handle_expension.h"
#include "gmr/symbols.h"
#include "me/hashmap/hashmap_env.h"
#include "me/types.h"
t_error handle_expension_complex(t_node *self, t_utils *shcat, t_str *ret)
{
(void)(self);
(void)(shcat);
(void)(ret);
return (ERROR);
}
t_error handle_expension_simple(t_node *self, t_utils *shcat, t_str *ret)
{
(void)(self);
(void)(shcat);
(void)(ret);
//get_hashmap_env(shcat->env, (t_str *)&"fjdksf");
return (ERROR);
}
t_error handle_expension(t_node *self, t_utils *shcat, t_str *ret)
{
if (self->childs_count != 0 && self->childs[0].kind == anon_sym_DOLLAR)
return (handle_expension_simple(self, shcat, ret));
if (self->childs_count != 0 &&
self->childs[0].kind == anon_sym_DOLLAR_LBRACE)
return (handle_expension_complex(self, shcat, ret));
return (ERROR);
}

View file

@ -1,36 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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);
}

View file

@ -1,33 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_raw_word.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 15:57:33 by maiboyer #+# #+# */
/* Updated: 2024/05/02 16:03:09 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/node/handle_raw_word.h"
#include "app/node.h"
#include "app/state.h"
#include "gmr/symbols.h"
#include "me/str/str.h"
#include "me/str/str.h"
#include "me/types.h"
t_error handle_raw_string(t_node *self, t_utils *shcat, t_str *ret)
{
t_str tmp;
t_usize i;
(void)(shcat);
if (self == NULL || ret == NULL || self->kind != sym_raw_string)
return (ERROR);
tmp = node_getstr(self);
i = str_len(tmp);
*ret = str_substring(tmp, 1, i - 2);
return (NO_ERROR);
}

View file

@ -1,26 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_word.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 15:59:04 by maiboyer #+# #+# */
/* Updated: 2024/05/02 16:00:00 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/node/handle_word.h"
#include "app/state.h"
#include "gmr/symbols.h"
#include "me/str/str.h"
#include "me/types.h"
t_error handle_word(t_node *self, t_utils *shcat, t_str *ret)
{
(void)(shcat);
if (self == NULL || ret == NULL || self->kind != sym_word)
return (ERROR);
*ret = str_clone(node_getstr(self));
return (NO_ERROR);
}

View file

@ -1,21 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* and_and.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/12 19:16:12 by rparodi #+# #+# */
/* Updated: 2024/05/18 17:48:43 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "separator.h"
t_error and_and_exec(t_node *first, t_node *second, t_i32 *ret_value)
{
if (ft_command_exec(first, ret_value) == ERROR)
return (ERROR);
ft_command_exec(second, ret_value);
return (NO_ERROR);
}

View file

@ -1,23 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipe_pipe.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/12 19:21:01 by rparodi #+# #+# */
/* Updated: 2024/05/12 19:44:46 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "separator.h"
t_error pipe_pipe(t_node *first, t_node *second, t_i32 *ret_value)
{
if (first || ft_command_exec(first, ret_value))
return (NO_ERROR);
else if (second || ft_command_exec(second, ret_value))
return (NO_ERROR);
else
return (ERROR);
}

View file

@ -1,41 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* semicolon.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/12 16:00:33 by rparodi #+# #+# */
/* Updated: 2024/05/22 15:04:52 by maiboyer ### ########.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_command.h"
#include "minishell.h"
#include "me/str/str.h"
t_error ft_command_exec(t_node *self, t_i32 *ret);
t_error ft_command_exec(t_node *self, t_i32 *ret);
t_error semicolon_exec(t_node *first, t_node *second, t_i32 *ret_value)
{
if (!first && !second)
return (ERROR);
else if (!first)
ft_command_exec(second, ret_value);
else if (!second)
ft_command_exec(first, ret_value);
else
{
ft_command_exec(first, ret_value);
ft_command_exec(second, ret_value);
}
return (NO_ERROR);
}

View file

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* separator.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/12 16:53:15 by rparodi #+# #+# */
/* Updated: 2024/05/12 19:57:14 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SEPARATOR_H
# define SEPARATOR_H
# include "minishell.h"
t_error ft_command_exec(t_node *node, t_i32 *ret_value);
t_error pipe_pipe(t_node *first, t_node *second, t_i32 *ret_value);
t_error and_and_exec(t_node *first, t_node *second, t_i32 *ret_value);
t_error semicolon_exec(t_node *first, t_node *second, t_i32 *ret_value);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* simple_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/12 19:13:42 by rparodi #+# #+# */
/* Updated: 2024/05/17 15:33:13 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "separator.h"
t_error ft_command_exec(t_node *node, t_i32 *ret_value)
{
printf("execve : %s\n", node->single_str);
(void)(ret_value);
return (NO_ERROR);
}