Merge remote-tracking branch 'origin' into maix/norminette
This commit is contained in:
commit
f35e986145
107 changed files with 476 additions and 138 deletions
52
sources/exec/handle_concat.c
Normal file
52
sources/exec/handle_concat.c
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* handle_concat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/02 15:05:06 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/02 16:01:52 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/buffered_str/buf_str.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_buffer_str out;
|
||||
t_usize i;
|
||||
t_str tmp;
|
||||
|
||||
(void)(shcat);
|
||||
if (self == NULL || ret == NULL || self->kind != sym_concatenation)
|
||||
return (ERROR);
|
||||
out = alloc_new_buffer(16);
|
||||
i = 0;
|
||||
while (i < self->childs_count)
|
||||
{
|
||||
if (node_get_string(&self->childs[i], shcat, &tmp))
|
||||
return (str_free(out), ERROR);
|
||||
push_str_buffer(&out, tmp);
|
||||
free(tmp);
|
||||
i++;
|
||||
}
|
||||
*ret = out.buf;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
33
sources/exec/handle_raw_word.c
Normal file
33
sources/exec/handle_raw_word.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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/string/str_len.h"
|
||||
#include "me/string/str_substring.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);
|
||||
}
|
||||
26
sources/exec/handle_word.c
Normal file
26
sources/exec/handle_word.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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/string/str_clone.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);
|
||||
}
|
||||
|
|
@ -6,13 +6,14 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/02 14:18:02 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/02 15:26:55 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/minishell.h"
|
||||
#include "app/node.h"
|
||||
#include "app/signal_handler.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "parser/api.h"
|
||||
|
||||
|
|
@ -74,9 +75,30 @@ void ft_check(t_utils *shcat, char **input)
|
|||
}
|
||||
}
|
||||
|
||||
t_error handle_concat(t_node *self, t_utils* shcat, t_str *ret);
|
||||
|
||||
void print_node_concat(t_node *self)
|
||||
{
|
||||
if (self->kind != sym_concatenation)
|
||||
{
|
||||
t_usize i = 0;
|
||||
while (i < self->childs_count)
|
||||
print_node_concat(&self->childs[i++]);
|
||||
}
|
||||
else
|
||||
{
|
||||
t_str ret;
|
||||
if (handle_concat(self, NULL, &ret))
|
||||
return ((void)printf("ERROR\n"));
|
||||
printf("concat value = '%s'\n", ret);
|
||||
free(ret);
|
||||
}
|
||||
}
|
||||
|
||||
void exec_shcat(t_utils *shcat)
|
||||
{
|
||||
print_node_data(&shcat->current_node, 0);
|
||||
print_node_concat(&shcat->current_node);
|
||||
free_node(shcat->current_node);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue