Normed and fixed stuff
This commit is contained in:
parent
b693536a90
commit
970507dfdd
2 changed files with 83 additions and 76 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/30 14:29:42 by rparodi #+# #+# */
|
/* Created: 2024/07/30 14:29:42 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/07/30 14:52:31 by rparodi ### ########.fr */
|
/* Updated: 2024/07/30 14:58:13 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,6 +20,14 @@
|
||||||
#include "parser/api.h"
|
#include "parser/api.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
void ast_free_arith(t_ast_node elem);
|
||||||
|
void ast_free_condition(t_ast_node elem);
|
||||||
|
void ast_free_exec(t_ast_node elem);
|
||||||
|
void ast_free_loop(t_ast_node elem);
|
||||||
|
void ast_free_other(t_ast_node elem);
|
||||||
|
void ast_free_redirection(t_ast_node elem);
|
||||||
|
|
||||||
void ast_free_arith(t_ast_node elem)
|
void ast_free_arith(t_ast_node elem)
|
||||||
{
|
{
|
||||||
if (elem->kind == AST_ARITHMETIC_EXPANSION)
|
if (elem->kind == AST_ARITHMETIC_EXPANSION)
|
||||||
|
|
@ -86,13 +94,8 @@ void ast_free_redirection(t_ast_node elem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ast_free(t_ast_node elem)
|
void ast_free_other(t_ast_node elem)
|
||||||
{
|
{
|
||||||
ast_free_arith(elem);
|
|
||||||
ast_free_loop(elem);
|
|
||||||
ast_free_condition(elem);
|
|
||||||
ast_free_exec(elem);
|
|
||||||
ast_free_redirection(elem);
|
|
||||||
if (elem->kind == AST_COMPOUND_STATEMENT)
|
if (elem->kind == AST_COMPOUND_STATEMENT)
|
||||||
{
|
{
|
||||||
vec_ast_free(elem->data.compound_statement.body);
|
vec_ast_free(elem->data.compound_statement.body);
|
||||||
|
|
@ -119,6 +122,12 @@ void ast_free(t_ast_node elem)
|
||||||
{
|
{
|
||||||
if (elem == NULL)
|
if (elem == NULL)
|
||||||
return ;
|
return ;
|
||||||
|
ast_free_arith(elem);
|
||||||
|
ast_free_loop(elem);
|
||||||
|
ast_free_condition(elem);
|
||||||
|
ast_free_exec(elem);
|
||||||
|
ast_free_other(elem);
|
||||||
|
ast_free_redirection(elem);
|
||||||
if (elem->kind == AST_RAW_STRING)
|
if (elem->kind == AST_RAW_STRING)
|
||||||
mem_free(elem->data.raw_string.str);
|
mem_free(elem->data.raw_string.str);
|
||||||
if (elem->kind == AST_WORD)
|
if (elem->kind == AST_WORD)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/19 15:53:50 by maiboyer #+# #+# */
|
/* Created: 2024/05/19 15:53:50 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/07/07 19:17:05 by maiboyer ### ########.fr */
|
/* Updated: 2024/07/30 15:01:04 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,7 +15,6 @@
|
||||||
#include "me/str/str.h"
|
#include "me/str/str.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "unistd.h"
|
#include "unistd.h"
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -41,8 +40,8 @@ struct s_file_slot *get_unused_fd_slot(void)
|
||||||
return (&arr->storage[i]);
|
return (&arr->storage[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
me_abort(
|
me_abort("Unable to find slot for a file descriptor, " \
|
||||||
"Unable to find slot for a file descriptor, increate FILE_SLOT_LEN");
|
"increate FILE_SLOT_LEN");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,8 +116,7 @@ t_error read_fd(t_fd *fd, t_u8 *buffer, t_usize size, t_isize *read_count)
|
||||||
|
|
||||||
if (read_count == NULL)
|
if (read_count == NULL)
|
||||||
read_count = &false_ret;
|
read_count = &false_ret;
|
||||||
if (fd == NULL || buffer == NULL || fd->fd == -1 ||
|
if (fd == NULL || buffer == NULL || fd->fd == -1 || !(fd->perms & FD_READ))
|
||||||
!(fd->perms & FD_READ))
|
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
ret = read(fd->fd, buffer, size);
|
ret = read(fd->fd, buffer, size);
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
|
|
@ -286,8 +284,8 @@ t_error read_file(t_file *file, t_u8 *buffer, t_usize size, t_isize *read_count)
|
||||||
{
|
{
|
||||||
t_isize ret;
|
t_isize ret;
|
||||||
|
|
||||||
if (file == NULL || buffer == NULL || read_count == NULL ||
|
if (file == NULL || buffer == NULL || read_count == NULL
|
||||||
file->ptr == NULL)
|
|| file->ptr == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
ret = fread(buffer, size, 1, file->ptr);
|
ret = fread(buffer, size, 1, file->ptr);
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue