Compare commits
No commits in common. "9e29826eabc2617967eb4c197072caf561273b59" and "2bbd0ff867a1fe6ecae6cc29a8bd69eba8ef5e3b" have entirely different histories.
9e29826eab
...
2bbd0ff867
24 changed files with 93 additions and 135 deletions
6
Makefile
6
Makefile
|
|
@ -6,7 +6,7 @@
|
||||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||||
# Updated: 2024/10/23 14:49:04 by maiboyer ### ########.fr #
|
# Updated: 2024/10/14 15:20:12 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -49,8 +49,8 @@ CFLAGS_ADDITIONAL += -DNVALGRIND
|
||||||
# TODO: REMOVE THIS WHEN FINISHING THIS:
|
# TODO: REMOVE THIS WHEN FINISHING THIS:
|
||||||
# CFLAGS_ADDITIONAL += -fsanitize=memory -fno-omit-frame-pointer -fsanitize-memory-track-origins #-fuse-ld=lld -ffunction-sections -fdata-sections -Wl,--allow-multiple
|
# CFLAGS_ADDITIONAL += -fsanitize=memory -fno-omit-frame-pointer -fsanitize-memory-track-origins #-fuse-ld=lld -ffunction-sections -fdata-sections -Wl,--allow-multiple
|
||||||
# CFLAGS_ADDITIONAL += -O0
|
# CFLAGS_ADDITIONAL += -O0
|
||||||
# CFLAGS_ADDITIONAL += -Wno-cpp -Wno-type-limits
|
# CFLAGS_ADDITIONAL += -Wno-cpp -Wno-type-limits -Wno-unused-command-line-argument
|
||||||
CFLAGS_ADDITIONAL += -gcolumn-info -g3 -fno-builtin
|
# CFLAGS_ADDITIONAL += -gcolumn-info -g3 -fno-builtin
|
||||||
# CFLAGS_ADDITIONAL += '-DERROR=((void)printf("ERROR HERE: " __FILE__ ":%d in %s\n", __LINE__, __func__), 1)'
|
# CFLAGS_ADDITIONAL += '-DERROR=((void)printf("ERROR HERE: " __FILE__ ":%d in %s\n", __LINE__, __func__), 1)'
|
||||||
# CFLAGS_ADDITIONAL += -O2
|
# CFLAGS_ADDITIONAL += -O2
|
||||||
# CFLAGS_ADDITIONAL += -fuse-ld=gold -Wl,--print-symbol-counts -Wl,/tmp/symbols_count.log
|
# CFLAGS_ADDITIONAL += -fuse-ld=gold -Wl,--print-symbol-counts -Wl,/tmp/symbols_count.log
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ export BASE_PATH
|
||||||
export BUILD_DIR
|
export BUILD_DIR
|
||||||
|
|
||||||
# Flags
|
# Flags
|
||||||
CFLAGS = -Werror -Wextra -Wall -MMD -I./includes -I./output/include -I./stdme/output/include
|
CFLAGS = -Werror -Wextra -Wall -Wno-unused-command-line-argument -MMD -I./includes -I./output/include -I./stdme/output/include -rdynamic -Wl,-E
|
||||||
CFLAGS += $(CFLAGS_ADDITIONAL)
|
CFLAGS += $(CFLAGS_ADDITIONAL)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ lc_alloc/functions1 \
|
||||||
lc_alloc/functions2 \
|
lc_alloc/functions2 \
|
||||||
me_alloc/find_block \
|
me_alloc/find_block \
|
||||||
me_alloc/functions1 \
|
me_alloc/functions1 \
|
||||||
|
me_alloc/functions2 \
|
||||||
me_alloc/internals \
|
me_alloc/internals \
|
||||||
me_alloc/merge_blocks \
|
me_alloc/merge_blocks \
|
||||||
me_alloc/pages \
|
me_alloc/pages \
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||||
# Updated: 2024/10/23 14:48:39 by maiboyer ### ########.fr #
|
# Updated: 2024/08/02 18:57:11 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ NAME = lib$(ANAME).a
|
||||||
LIB_NAME ?=
|
LIB_NAME ?=
|
||||||
TARGET = $(BUILD_DIR)/$(NAME)
|
TARGET = $(BUILD_DIR)/$(NAME)
|
||||||
CC ?= clang
|
CC ?= clang
|
||||||
CFLAGS = -Wall -Werror -Wextra -MMD -DBASE_PATH='"$(BASE_PATH)/"'
|
CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -L$(BUILD_DIR) -MMD -rdynamic -DBASE_PATH='"$(BASE_PATH)/"'
|
||||||
CFLAGS += $(CFLAGS_ADDITIONAL)
|
CFLAGS += $(CFLAGS_ADDITIONAL)
|
||||||
|
|
||||||
LIBS_NAME =
|
LIBS_NAME =
|
||||||
|
|
|
||||||
|
|
@ -14,39 +14,39 @@
|
||||||
#include "aq/libc_wrapper.h"
|
#include "aq/libc_wrapper.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
|
|
||||||
void *malloc(t_usize size);
|
void *__libc_malloc(t_usize size);
|
||||||
void *calloc(t_usize size, t_usize elem);
|
void *__libc_calloc(t_usize size, t_usize elem);
|
||||||
void *realloc(void *ptr, t_usize size);
|
void *__libc_realloc(void *ptr, t_usize size);
|
||||||
void *reallocarray(void *ptr, t_usize size, t_usize elem);
|
void *__libc_reallocarray(void *ptr, t_usize size, t_usize elem);
|
||||||
void free(void *ptr);
|
void __libc_free(void *ptr);
|
||||||
|
|
||||||
void *lc_malloc(t_allocator *self, t_usize size)
|
void *lc_malloc(t_allocator *self, t_usize size)
|
||||||
{
|
{
|
||||||
(void)(self);
|
(void)(self);
|
||||||
return (malloc(size));
|
return (__libc_malloc(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
void *lc_calloc(t_allocator *self, t_usize size, t_usize elem)
|
void *lc_calloc(t_allocator *self, t_usize size, t_usize elem)
|
||||||
{
|
{
|
||||||
(void)(self);
|
(void)(self);
|
||||||
return (calloc(size, elem));
|
return (__libc_calloc(size, elem));
|
||||||
}
|
}
|
||||||
|
|
||||||
void *lc_realloc(t_allocator *self, void *ptr, t_usize size)
|
void *lc_realloc(t_allocator *self, void *ptr, t_usize size)
|
||||||
{
|
{
|
||||||
(void)(self);
|
(void)(self);
|
||||||
return (realloc(ptr, size));
|
return (__libc_realloc(ptr, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
void *lc_realloc_array(t_allocator *self, void *ptr, t_usize size,
|
void *lc_realloc_array(t_allocator *self, void *ptr, t_usize size,
|
||||||
t_usize elem)
|
t_usize elem)
|
||||||
{
|
{
|
||||||
(void)(self);
|
(void)(self);
|
||||||
return (reallocarray(ptr, size, elem));
|
return (__libc_reallocarray(ptr, size, elem));
|
||||||
}
|
}
|
||||||
|
|
||||||
void lc_free(t_allocator *self, void *ptr)
|
void lc_free(t_allocator *self, void *ptr)
|
||||||
{
|
{
|
||||||
(void)(self);
|
(void)(self);
|
||||||
return (free(ptr));
|
return (__libc_free(ptr));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
void *malloc(t_usize size);
|
void *__libc_malloc(t_usize size);
|
||||||
void free(void *ptr);
|
void __libc_free(void *ptr);
|
||||||
|
|
||||||
void *m_malloc(struct s_allocator_melloc *self, t_usize size)
|
void *m_malloc(struct s_allocator_melloc *self, t_usize size)
|
||||||
{
|
{
|
||||||
|
|
@ -64,14 +64,14 @@ void m_uninit(struct s_allocator_melloc *self)
|
||||||
if (list->pages[idx].data != NULL)
|
if (list->pages[idx].data != NULL)
|
||||||
{
|
{
|
||||||
vg_mempool_free(list, list->pages[idx].data);
|
vg_mempool_free(list, list->pages[idx].data);
|
||||||
free(list->pages[idx].data);
|
__libc_free(list->pages[idx].data);
|
||||||
list->pages[idx].size = 0;
|
list->pages[idx].size = 0;
|
||||||
list->pages[idx].data = NULL;
|
list->pages[idx].data = NULL;
|
||||||
}
|
}
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
list_next = list->next;
|
list_next = list->next;
|
||||||
(free(list), vg_mempool_destroy(list), \
|
(__libc_free(list), vg_mempool_destroy(list), \
|
||||||
vg_mem_no_access(list, sizeof(*list)));
|
vg_mem_no_access(list, sizeof(*list)));
|
||||||
list = list_next;
|
list = list_next;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
19
allocator/src/me_alloc/functions2.c
Normal file
19
allocator/src/me_alloc/functions2.c
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* functions2.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/05/14 18:06:34 by maiboyer #+# #+# */
|
||||||
|
/* Updated: 2024/10/12 17:51:05 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "aq/allocator.h"
|
||||||
|
#include "aq/libc_wrapper.h"
|
||||||
|
|
||||||
|
// void lc_uninit(t_allocator *self)
|
||||||
|
// {
|
||||||
|
// (void)(self);
|
||||||
|
// }
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/10 16:51:10 by maiboyer #+# #+# */
|
/* Created: 2024/07/10 16:51:10 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/23 14:52:47 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/12 17:51:07 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,8 +17,8 @@
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
void *malloc(t_usize size);
|
void *__libc_malloc(t_usize size);
|
||||||
void free(void *ptr);
|
void __libc_free(void *ptr);
|
||||||
|
|
||||||
t_error alloc_page_list(t_page_list **out)
|
t_error alloc_page_list(t_page_list **out)
|
||||||
{
|
{
|
||||||
|
|
@ -26,7 +26,7 @@ t_error alloc_page_list(t_page_list **out)
|
||||||
|
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
val = malloc(sizeof(*val));
|
val = __libc_malloc(sizeof(*val));
|
||||||
if (val == NULL)
|
if (val == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
mem_set_zero(val, sizeof(*val));
|
mem_set_zero(val, sizeof(*val));
|
||||||
|
|
@ -43,10 +43,10 @@ t_error _alloc_new_page_inner(t_usize page_size, t_page_list *list)
|
||||||
if (list == NULL)
|
if (list == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
vg_mem_defined(list, sizeof(*list));
|
vg_mem_defined(list, sizeof(*list));
|
||||||
list->pages[list->len].data = malloc(page_size);
|
list->pages[list->len].data = __libc_malloc(page_size);
|
||||||
|
mem_set_zero(list->pages[list->len].data, page_size);
|
||||||
if (list->pages[list->len].data == NULL)
|
if (list->pages[list->len].data == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
mem_set_zero(list->pages[list->len].data, page_size);
|
|
||||||
list->pages[list->len].size = page_size;
|
list->pages[list->len].size = page_size;
|
||||||
vg_mempool_alloc(list, list->pages[list->len].data, page_size);
|
vg_mempool_alloc(list, list->pages[list->len].data, page_size);
|
||||||
chunk = get_first_block(&list->pages[list->len]);
|
chunk = get_first_block(&list->pages[list->len]);
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ ast_free/ast_free_scripting \
|
||||||
print_ast/ast_print \
|
print_ast/ast_print \
|
||||||
print_ast/ast_print_arithmetic \
|
print_ast/ast_print_arithmetic \
|
||||||
print_ast/ast_print_command \
|
print_ast/ast_print_command \
|
||||||
print_ast/ast_print_general \
|
|
||||||
print_ast/ast_print_global \
|
print_ast/ast_print_global \
|
||||||
print_ast/ast_print_helper_function \
|
print_ast/ast_print_helper_function \
|
||||||
print_ast/ast_print_node \
|
print_ast/ast_print_node \
|
||||||
print_ast/ast_print_redirection \
|
print_ast/ast_print_redirection \
|
||||||
|
print_ast/ast_print_subshell \
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||||
# Updated: 2024/10/23 14:48:35 by maiboyer ### ########.fr #
|
# Updated: 2024/08/02 18:58:20 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ NAME = lib$(ANAME).a
|
||||||
LIB_NAME ?=
|
LIB_NAME ?=
|
||||||
TARGET = $(BUILD_DIR)/$(NAME)
|
TARGET = $(BUILD_DIR)/$(NAME)
|
||||||
CC ?= clang
|
CC ?= clang
|
||||||
CFLAGS = -Wall -Werror -Wextra -MMD -DBASE_PATH='"$(BASE_PATH)/"'
|
CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -L$(BUILD_DIR) -MMD -rdynamic -DBASE_PATH='"$(BASE_PATH)/"'
|
||||||
CFLAGS += $(CFLAGS_ADDITIONAL)
|
CFLAGS += $(CFLAGS_ADDITIONAL)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/26 13:07:12 by rparodi #+# #+# */
|
/* Created: 2024/07/26 13:07:12 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/10/24 23:04:06 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/14 14:12:49 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,9 +14,7 @@
|
||||||
|
|
||||||
void ast_print_node_file_redirection_heredoc(t_ast_node self)
|
void ast_print_node_file_redirection_heredoc(t_ast_node self)
|
||||||
{
|
{
|
||||||
if (self == NULL || self->kind != AST_HEREDOC_REDIRECTION)
|
(void)(self);
|
||||||
return ;
|
|
||||||
printf("<<%s ", self->data.heredoc_redirection.delimiter);
|
|
||||||
}
|
}
|
||||||
//{
|
//{
|
||||||
// if (self->data.file_redirection.op == AST_REDIR_HEREDOC)
|
// if (self->data.file_redirection.op == AST_REDIR_HEREDOC)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* ast_print_general.c :+: :+: :+: */
|
/* ast_print_subshell.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||||
# Updated: 2024/10/23 14:48:20 by maiboyer ### ########.fr #
|
# Updated: 2024/08/02 18:58:14 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ NAME = lib$(ANAME).a
|
||||||
LIB_NAME ?=
|
LIB_NAME ?=
|
||||||
TARGET = $(BUILD_DIR)/$(NAME)
|
TARGET = $(BUILD_DIR)/$(NAME)
|
||||||
CC ?= clang
|
CC ?= clang
|
||||||
CFLAGS = -Wall -Werror -Wextra -MMD -DBASE_PATH='"$(BASE_PATH)/"'
|
CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -L$(BUILD_DIR) -MMD -rdynamic -DBASE_PATH='"$(BASE_PATH)/"'
|
||||||
CFLAGS += $(CFLAGS_ADDITIONAL)
|
CFLAGS += $(CFLAGS_ADDITIONAL)
|
||||||
|
|
||||||
-include Filelist.$(ANAME).mk
|
-include Filelist.$(ANAME).mk
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/17 21:43:33 by rparodi #+# #+# */
|
/* Created: 2024/09/17 21:43:33 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/10/23 15:33:10 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/12 17:51:19 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -58,7 +58,6 @@ t_error listing_files(t_string path, t_vec_str *out)
|
||||||
continue ;
|
continue ;
|
||||||
vec_str_push(&ret, str_clone(entry->d_name));
|
vec_str_push(&ret, str_clone(entry->d_name));
|
||||||
}
|
}
|
||||||
close_dir(tmp);
|
|
||||||
return (*out = ret, NO_ERROR);
|
return (*out = ret, NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/07 14:13:41 by rparodi #+# #+# */
|
/* Created: 2024/08/07 14:13:41 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/10/23 16:05:55 by rparodi ### ########.fr */
|
/* Updated: 2024/10/13 17:24:39 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,29 +17,11 @@
|
||||||
#include "me/string/string.h"
|
#include "me/string/string.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "me/vec/vec_str.h"
|
#include "me/vec/vec_str.h"
|
||||||
#include "me/char/char.h"
|
|
||||||
#define CHARSET_LETTER "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
|
|
||||||
#define CHARSET_NUMBER "0123456789"
|
|
||||||
|
|
||||||
t_error _append_key_to_vec(t_usize _, const t_str *key, t_str *v, void *vec);
|
t_error _append_key_to_vec(t_usize _, const t_str *key, t_str *v, void *vec);
|
||||||
bool _sort_str(t_str *_lhs, t_str *_rhs);
|
bool _sort_str(t_str *_lhs, t_str *_rhs);
|
||||||
t_error get_uniq_keys(t_state *state, t_vec_str *out);
|
t_error get_uniq_keys(t_state *state, t_vec_str *out);
|
||||||
|
|
||||||
bool is_valid_name(t_str arg)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (!str_find_chr(CHARSET_LETTER, arg[0]))
|
|
||||||
return (false);
|
|
||||||
while (arg[i] != '\0')
|
|
||||||
{
|
|
||||||
if (!str_find_chr(CHARSET_LETTER CHARSET_NUMBER, arg[i++]))
|
|
||||||
return (false);
|
|
||||||
}
|
|
||||||
return (true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _assign_export(t_usize idx, t_str *arg, void *vctx)
|
static void _assign_export(t_usize idx, t_str *arg, void *vctx)
|
||||||
{
|
{
|
||||||
struct s_assign_export_state *ctx;
|
struct s_assign_export_state *ctx;
|
||||||
|
|
@ -52,15 +34,11 @@ static void _assign_export(t_usize idx, t_str *arg, void *vctx)
|
||||||
ctx = vctx;
|
ctx = vctx;
|
||||||
first_eq = str_find_chr(*arg, '=');
|
first_eq = str_find_chr(*arg, '=');
|
||||||
if (first_eq == NULL || first_eq == *arg)
|
if (first_eq == NULL || first_eq == *arg)
|
||||||
{
|
|
||||||
hmap_env_insert(ctx->state->env, *arg, NULL);
|
hmap_env_insert(ctx->state->env, *arg, NULL);
|
||||||
return ;
|
|
||||||
}
|
|
||||||
key = str_substring(*arg, 0, first_eq - *arg);
|
key = str_substring(*arg, 0, first_eq - *arg);
|
||||||
if (!is_valid_name(key))
|
|
||||||
return ;
|
|
||||||
value = str_substring(first_eq, 1, ~0llu);
|
value = str_substring(first_eq, 1, ~0llu);
|
||||||
hmap_env_insert(ctx->state->env, key, value);
|
if (hmap_env_insert(ctx->state->env, key, value))
|
||||||
|
ctx->err = ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static t_error handle_quotes(t_str raw, t_string *out)
|
static t_error handle_quotes(t_str raw, t_string *out)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/14 12:26:51 by maiboyer #+# #+# */
|
/* Created: 2024/09/14 12:26:51 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/28 11:42:11 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/15 21:30:02 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,29 +21,29 @@ t_error _word_handle_star(t_ast_word *word, t_state *state, t_vec_str *out);
|
||||||
t_error list_files_in_current_directory(t_vec_str *out);
|
t_error list_files_in_current_directory(t_vec_str *out);
|
||||||
t_error _word_into_str_inner(struct s_word_str_args args);
|
t_error _word_into_str_inner(struct s_word_str_args args);
|
||||||
|
|
||||||
t_error _word_split_loop_expand(\
|
t_error _word_split_loop(\
|
||||||
t_expandable_str val, t_vec_str *append, t_string *tmp, bool *exist)
|
bool do_split, t_expandable_str val, t_vec_str *append, t_string *tmp)
|
||||||
{
|
{
|
||||||
t_vec_str split;
|
t_vec_str split;
|
||||||
t_str stmp;
|
t_str stmp;
|
||||||
|
|
||||||
if (val.do_expand && str_find_chr(val.value, ' '))
|
if (do_split)
|
||||||
|
{
|
||||||
|
if (val.do_expand)
|
||||||
{
|
{
|
||||||
if (val.value == NULL)
|
if (val.value == NULL)
|
||||||
val.value = "";
|
val.value = "";
|
||||||
if (str_split(val.value, " \t\n\r\v", &split))
|
if (str_split(val.value, " ", &split))
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
if (split.len != 0 && tmp->len != 0)
|
|
||||||
{
|
|
||||||
vec_str_push(append, tmp->buf);
|
|
||||||
*tmp = string_new(16);
|
|
||||||
}
|
|
||||||
while (!vec_str_pop_front(&split, &stmp))
|
while (!vec_str_pop_front(&split, &stmp))
|
||||||
vec_str_push(append, stmp);
|
vec_str_push(append, stmp);
|
||||||
vec_str_free(split);
|
vec_str_free(split);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*exist = (string_push(tmp, val.value), true);
|
vec_str_push(append, str_clone(val.value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
string_push(tmp, val.value);
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,23 +52,15 @@ t_error _word_split(\
|
||||||
{
|
{
|
||||||
t_string tmp;
|
t_string tmp;
|
||||||
t_usize i;
|
t_usize i;
|
||||||
bool exist;
|
|
||||||
|
|
||||||
tmp = string_new(64);
|
tmp = string_new(64);
|
||||||
i = 0;
|
i = 0;
|
||||||
exist = false;
|
|
||||||
while (i < res->value.len)
|
while (i < res->value.len)
|
||||||
{
|
{
|
||||||
if (do_split)
|
if (_word_split_loop(do_split, res->value.buffer[i++], append, &tmp))
|
||||||
_word_split_loop_expand(res->value.buffer[i], append, &tmp, &exist);
|
return (string_free(tmp), ERROR);
|
||||||
else
|
|
||||||
{
|
|
||||||
string_push(&tmp, res->value.buffer[i].value);
|
|
||||||
exist = true;
|
|
||||||
}
|
}
|
||||||
i++;
|
if (!do_split)
|
||||||
}
|
|
||||||
if (!do_split || tmp.len != 0 || exist)
|
|
||||||
vec_str_push(append, tmp.buf);
|
vec_str_push(append, tmp.buf);
|
||||||
else
|
else
|
||||||
string_free(tmp);
|
string_free(tmp);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/14 12:26:51 by maiboyer #+# #+# */
|
/* Created: 2024/09/14 12:26:51 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/25 15:52:50 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/12 17:51:22 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -22,31 +22,7 @@ bool _word_is_star(t_ast_word *word)
|
||||||
{
|
{
|
||||||
return (BONUS && word->kind == AST_WORD_NO_QUOTE && word->inner.len == 1 \
|
return (BONUS && word->kind == AST_WORD_NO_QUOTE && word->inner.len == 1 \
|
||||||
&& word->inner.buffer[0]->kind == AST_RAW_STRING \
|
&& word->inner.buffer[0]->kind == AST_RAW_STRING \
|
||||||
&& str_find_chr(word->inner.buffer[0]->data.raw_string.str, '*') != NULL);
|
&& str_compare("*", word->inner.buffer[0]->data.raw_string.str));
|
||||||
}
|
|
||||||
|
|
||||||
bool match(t_const_str pattern, t_const_str str)
|
|
||||||
{
|
|
||||||
while (*pattern)
|
|
||||||
{
|
|
||||||
if (*pattern == '*')
|
|
||||||
{
|
|
||||||
if (!*(pattern + 1))
|
|
||||||
return (true);
|
|
||||||
while (*str)
|
|
||||||
{
|
|
||||||
if (match(pattern + 1, str))
|
|
||||||
return (true);
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
return (false);
|
|
||||||
}
|
|
||||||
else if (*pattern != *str)
|
|
||||||
return (false);
|
|
||||||
pattern++;
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
return (!*pattern && !*str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error _word_handle_star(t_ast_word *word, t_state *state, t_vec_str *out)
|
t_error _word_handle_star(t_ast_word *word, t_state *state, t_vec_str *out)
|
||||||
|
|
@ -59,12 +35,7 @@ t_error _word_handle_star(t_ast_word *word, t_state *state, t_vec_str *out)
|
||||||
if (list_files_in_current_directory(&files))
|
if (list_files_in_current_directory(&files))
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
while (!vec_str_pop_front(&files, &s))
|
while (!vec_str_pop_front(&files, &s))
|
||||||
{
|
|
||||||
if (match(word->inner.buffer[0]->data.raw_string.str, s))
|
|
||||||
vec_str_push(out, s);
|
vec_str_push(out, s);
|
||||||
else
|
|
||||||
str_free(s);
|
|
||||||
}
|
|
||||||
vec_str_free(files);
|
vec_str_free(files);
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/14 12:30:09 by maiboyer #+# #+# */
|
/* Created: 2024/09/14 12:30:09 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/24 22:57:49 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/14 15:07:42 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -79,7 +79,6 @@ t_error _spawn_cmd_and_run_end(\
|
||||||
bpath = str_clone(info.binary_path);
|
bpath = str_clone(info.binary_path);
|
||||||
if (spawn_process(info, &out->process))
|
if (spawn_process(info, &out->process))
|
||||||
return (close_fd(cmd_pipe.input), out->exit = 127, _err_cmd(bpath));
|
return (close_fd(cmd_pipe.input), out->exit = 127, _err_cmd(bpath));
|
||||||
close_fd(cmd_pipe.input);
|
|
||||||
str_free(bpath);
|
str_free(bpath);
|
||||||
if (cmd_pipe.create_output || cmd_pipe.input != NULL)
|
if (cmd_pipe.create_output || cmd_pipe.input != NULL)
|
||||||
return (out->exit = -1, NO_ERROR);
|
return (out->exit = -1, NO_ERROR);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/14 12:34:33 by maiboyer #+# #+# */
|
/* Created: 2024/09/14 12:34:33 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/23 15:01:54 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/12 17:51:26 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -46,12 +46,12 @@ t_error run_list(t_ast_list *list, t_state *state, t_list_result *out)
|
||||||
left = -1;
|
left = -1;
|
||||||
right = -1;
|
right = -1;
|
||||||
if (_run_get_exit_code(list->left, state, &left))
|
if (_run_get_exit_code(list->left, state, &left))
|
||||||
left = 127;
|
return (ERROR);
|
||||||
if ((list->op == AST_LIST_OR && left != 0) || (list->op == AST_LIST_AND
|
if ((list->op == AST_LIST_OR && left != 0) || (list->op == AST_LIST_AND
|
||||||
&& left == 0))
|
&& left == 0))
|
||||||
{
|
{
|
||||||
if (_run_get_exit_code(list->right, state, &right))
|
if (_run_get_exit_code(list->right, state, &right))
|
||||||
right = 127;
|
return (ERROR);
|
||||||
out->exit = right;
|
out->exit = right;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/14 12:35:02 by maiboyer #+# #+# */
|
/* Created: 2024/09/14 12:35:02 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/23 15:31:55 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/13 17:24:55 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||||
# Updated: 2024/10/23 14:48:29 by maiboyer ### ########.fr #
|
# Updated: 2024/08/02 18:58:07 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ NAME = lib$(ANAME).a
|
||||||
LIB_NAME ?=
|
LIB_NAME ?=
|
||||||
TARGET = $(BUILD_DIR)/$(NAME)
|
TARGET = $(BUILD_DIR)/$(NAME)
|
||||||
CC ?= clang
|
CC ?= clang
|
||||||
CFLAGS = -Wall -Werror -Wextra -MMD -DBASE_PATH='"$(BASE_PATH)/"'
|
CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -L$(BUILD_DIR) -MMD -rdynamic -DBASE_PATH='"$(BASE_PATH)/"' -g3
|
||||||
CFLAGS += $(CFLAGS_ADDITIONAL)
|
CFLAGS += $(CFLAGS_ADDITIONAL)
|
||||||
|
|
||||||
-include Filelist.$(ANAME).mk
|
-include Filelist.$(ANAME).mk
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/07 18:04:13 by rparodi #+# #+# */
|
/* Created: 2024/10/07 18:04:13 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/10/23 15:30:59 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/12 17:51:57 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ t_error _yard_parenthesis(\
|
||||||
vec_token_pop(stack, &tok);
|
vec_token_pop(stack, &tok);
|
||||||
token_free(tok);
|
token_free(tok);
|
||||||
snode = ast_alloc(AST_SUBSHELL);
|
snode = ast_alloc(AST_SUBSHELL);
|
||||||
if (!vec_ast_pop(output_queue, &tmp))
|
vec_ast_pop(output_queue, &tmp);
|
||||||
vec_ast_push(&snode->data.subshell.body, tmp);
|
vec_ast_push(&snode->data.subshell.body, tmp);
|
||||||
vec_ast_push(output_queue, snode);
|
vec_ast_push(output_queue, snode);
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/06 16:31:41 by rparodi #+# #+# */
|
/* Created: 2024/09/06 16:31:41 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/10/24 23:02:59 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/14 15:03:01 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -67,6 +67,7 @@ void exec_shcat(t_state *state)
|
||||||
if (state->ast != NULL && run_program(&state->ast->data.program, state,
|
if (state->ast != NULL && run_program(&state->ast->data.program, state,
|
||||||
&prog_res))
|
&prog_res))
|
||||||
{
|
{
|
||||||
|
printf("Error when executing the cmd\n");
|
||||||
state->last_exit = 127;
|
state->last_exit = 127;
|
||||||
}
|
}
|
||||||
ast_free(state->ast);
|
ast_free(state->ast);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||||
# Updated: 2024/10/23 14:48:53 by maiboyer ### ########.fr #
|
# Updated: 2024/08/02 18:57:39 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ NAME = libme.a
|
||||||
LIB_NAME ?=
|
LIB_NAME ?=
|
||||||
TARGET = $(BUILD_DIR)/$(NAME)
|
TARGET = $(BUILD_DIR)/$(NAME)
|
||||||
CC ?= clang
|
CC ?= clang
|
||||||
CFLAGS = -Wall -Werror -Wextra -MMD -DBASE_PATH='"$(BASE_PATH)/"'
|
CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -L$(BUILD_DIR) -MMD -rdynamic -DBASE_PATH='"$(BASE_PATH)/"'
|
||||||
CFLAGS += $(CFLAGS_ADDITIONAL)
|
CFLAGS += $(CFLAGS_ADDITIONAL)
|
||||||
|
|
||||||
-include ./Filelist.$(ANAME).mk
|
-include ./Filelist.$(ANAME).mk
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue