updated code to now work
This commit is contained in:
parent
bac90251fe
commit
4b2a22cc46
8 changed files with 309 additions and 8 deletions
3
Makefile
3
Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||
# Updated: 2024/10/10 17:25:22 by maiboyer ### ########.fr #
|
||||
# Updated: 2024/10/11 10:51:13 by maiboyer ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -139,6 +139,7 @@ build_filelist:
|
|||
@$(MAKE) --no-print-directory -C ./line/ build_filelist
|
||||
@$(MAKE) --no-print-directory -C ./parser/ build_filelist
|
||||
@$(MAKE) --no-print-directory -f ./Minishell.mk build_filelist
|
||||
@$(MAKE) --no-print-directory -C test ./Test.mk build_filelist
|
||||
|
||||
# phony
|
||||
.PHONY: all bonus clean fclean re header footer build_filelist
|
||||
|
|
|
|||
1
includes/test
Symbolic link
1
includes/test
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../test/include/test
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/16 18:15:57 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/10 18:49:27 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/11 11:30:00 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -40,12 +40,10 @@ static t_error _check_base(t_str base)
|
|||
|
||||
static void _set_modulus(t_num_str_state *s)
|
||||
{
|
||||
s->modulus = 0;
|
||||
s->modulus = 1;
|
||||
s->base_len = str_len(s->base);
|
||||
if (s->base_len == 10)
|
||||
return ((void)(s->modulus = 10000000000000000000lu));
|
||||
while (UINT64_MAX - s->modulus > s->base_len)
|
||||
s->modulus += s->base_len;
|
||||
while (UINT64_MAX / s->modulus >= s->base_len)
|
||||
s->modulus *= s->base_len;
|
||||
}
|
||||
|
||||
static char _get_char(t_u64 value, t_num_str_state *s)
|
||||
|
|
@ -66,7 +64,7 @@ static t_error _format_u64_base_innner(t_num_str_state *s)
|
|||
while (s->modulus)
|
||||
{
|
||||
c = _get_char(s->value / s->modulus, s);
|
||||
if (s->zero || s->print)
|
||||
if (!s->zero || s->print)
|
||||
{
|
||||
s->buffer[s->idx++] = c;
|
||||
s->print = true;
|
||||
|
|
@ -89,6 +87,7 @@ t_error _format_u64(t_num_str args, t_str *out)
|
|||
mem_set_zero(&s, sizeof(s));
|
||||
s.idx = 0;
|
||||
s.base = args.base;
|
||||
s.value = args.value;
|
||||
if (args.is_nonnegative)
|
||||
s.buffer[s.idx++] = '-';
|
||||
_set_modulus(&s);
|
||||
|
|
|
|||
1
test/.gitignore
vendored
Normal file
1
test/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/test
|
||||
6
test/Filelist.test.mk
Normal file
6
test/Filelist.test.mk
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
SRC_FILES = \
|
||||
main \
|
||||
|
||||
GEN_FILES = \
|
||||
\
|
||||
|
||||
145
test/Makefile
Normal file
145
test/Makefile
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
# **************************************************************************** #make
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||
# Updated: 2024/10/11 10:54:39 by maiboyer ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
# Objdir
|
||||
BUILD_DIR = $(shell realpath ../build/test)
|
||||
BASE_PATH = $(shell pwd)
|
||||
|
||||
# Colors
|
||||
GREEN = \033[32m
|
||||
CYAN = \033[36m
|
||||
GREY = \033[0;90m
|
||||
RED = \033[0;31m
|
||||
GOLD = \033[38;5;220m
|
||||
END = \033[0m
|
||||
BOLD = \033[1m
|
||||
ITALIC = \033[3m
|
||||
UNDERLINE = \033[4m
|
||||
|
||||
# Rules
|
||||
SRC_DIR = ./sources
|
||||
GEN_DIR = ./output
|
||||
NAME = minishell
|
||||
|
||||
# PMAKE_DISABLE =
|
||||
PMAKE =
|
||||
ifndef PMAKE_DISABLE
|
||||
ifeq ($(shell uname), Linux)
|
||||
PMAKE = -j$(shell grep -c ^processor /proc/cpuinfo)
|
||||
#CFLAGS_ADDITIONAL += -DPRINT_BACKTRACE
|
||||
endif
|
||||
ifeq ($(shell uname), Darwin)
|
||||
PMAKE = -j$(shell sysctl -n hw.ncpu)
|
||||
#CFLAGS_ADDITIONAL += -DNVALGRIND
|
||||
endif
|
||||
endif
|
||||
|
||||
# TODO: ADD THIS WHEN FINISHING THIS:
|
||||
# CFLAGS_ADDITIONAL += -DNVALGRIND
|
||||
|
||||
# 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 += -O0
|
||||
# CFLAGS_ADDITIONAL += -Wno-cpp -Wno-type-limits -Wno-unused-command-line-argument
|
||||
CFLAGS_ADDITIONAL += -gcolumn-info -g3 -fno-builtin
|
||||
CFLAGS_ADDITIONAL += '-DERROR=((void)printf("ERROR HERE: " __FILE__ ":%d in %s\n", __LINE__, __func__), 1)'
|
||||
CFLAGS_ADDITIONAL += -O2
|
||||
# CFLAGS_ADDITIONAL += -fuse-ld=gold -Wl,--print-symbol-counts -Wl,/tmp/symbols_count.log
|
||||
# CFLAGS_ADDITIONAL += -fuse-ld=lld -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-O3
|
||||
# CFLAGS_ADDITIONAL += -I$(shell realpath ./includes) -I$(shell realpath ./output/include)
|
||||
|
||||
export CFLAGS_ADDITIONAL
|
||||
export CC
|
||||
export BASE_PATH
|
||||
export BUILD_DIR
|
||||
|
||||
|
||||
# All (make all)
|
||||
all:
|
||||
@$(MAKE) --no-print-directory header
|
||||
@$(MAKE) --no-print-directory -f ./Test.mk $(PMAKE)
|
||||
@$(MAKE) --no-print-directory footer
|
||||
|
||||
bonus:
|
||||
@$(MAKE) --no-print-directory header
|
||||
@$(MAKE) --no-print-directory -f ./Test.mk $(PMAKE) bonus
|
||||
@$(MAKE) --no-print-directory footer
|
||||
|
||||
# Header
|
||||
header:
|
||||
@clear
|
||||
@echo -e ''
|
||||
@echo -e '$(GOLD) ******* ****** ******* $(END)'
|
||||
@echo -e '$(GOLD) ****** *** ******* $(END)'
|
||||
@echo -e '$(GOLD) ******* * ******* $(END)'
|
||||
@echo -e '$(GOLD) ****** ******* $(END)'
|
||||
@echo -e '$(GOLD) ******* ******* $(END)'
|
||||
@echo -e '$(GOLD) ******************* ******* * $(END)'
|
||||
@echo -e '$(GOLD) ******************* ******* *** $(END)'
|
||||
@echo -e '$(GOLD) ****** ******* ****** $(END)'
|
||||
@echo -e '$(GOLD) ****** $(END)'
|
||||
@echo -e '$(GOLD) ****** $(END)'
|
||||
@echo -e '$(GREY) Made by maiboyerlpb x rparodi$(END)'
|
||||
|
||||
# Footer
|
||||
footer:
|
||||
@echo -e '$(GOLD) _ $(END)'
|
||||
@echo -e '$(GOLD) | \ $(END)'
|
||||
@echo -e '$(GOLD) | | $(END)'
|
||||
@echo -e '$(GOLD) | | $(END)'
|
||||
@echo -e '$(GOLD) |\ $(CYAN)$(BOLD)$(UNDERLINE)shcat$(END)$(GOLD) | | $(END)'
|
||||
@echo -e '$(GOLD) /, ~\ / / $(END)'
|
||||
@echo -e '$(GOLD) X `-.....-------./ / $(END)'
|
||||
@echo -e '$(GOLD) ~-. ~ ~ | $(END)'
|
||||
@echo -e '$(GOLD) \ / | $(END)'
|
||||
@echo -e '$(GOLD) \ /_ ___\ / $(END)'
|
||||
@echo -e '$(GOLD) | /\ ~~~~~ \ | $(END)'
|
||||
@echo -e '$(GOLD) | | \ || | $(END)'
|
||||
@echo -e '$(GOLD) | |\ \ || ) $(END)'
|
||||
@echo -e '$(GOLD) (_/ (_/ ((_/ $(END)'
|
||||
@echo -e ' $(GREY)The compilation is $(END)$(GOLD)finished$(END)'
|
||||
@echo -e ' $(GREY)Have a good $(END)$(GOLD)correction$(END)'
|
||||
|
||||
|
||||
# Clean (make clean)
|
||||
clean:
|
||||
@echo -e '$(GREY) Removing $(END)$(RED)Objects$(END)'
|
||||
@echo -e '$(GREY) Removing $(END)$(RED)Objects Folder$(END)'
|
||||
@$(RM) -r $(BUILD_DIR)
|
||||
|
||||
# Clean (make fclean)
|
||||
fclean: clean
|
||||
@echo -e '$(GREY) Removing $(END)$(RED)Program$(END)'
|
||||
@$(RM) $(NAME)
|
||||
@echo ""
|
||||
|
||||
# Restart (make re)
|
||||
re: header
|
||||
@$(MAKE) --no-print-directory fclean
|
||||
@$(MAKE) --no-print-directory all
|
||||
|
||||
tokei:
|
||||
/bin/sh -c 'tokei -tC,C\ Header -e tree-sitter-sh'
|
||||
|
||||
|
||||
build_filelist:
|
||||
@$(MAKE) --no-print-directory -C ../stdme/ build_filelist
|
||||
@$(MAKE) --no-print-directory -C ../allocator/ build_filelist
|
||||
@$(MAKE) --no-print-directory -C ../ast/ build_filelist
|
||||
@$(MAKE) --no-print-directory -C ../exec/ build_filelist
|
||||
@$(MAKE) --no-print-directory -C ../line/ build_filelist
|
||||
@$(MAKE) --no-print-directory -C ../parser/ build_filelist
|
||||
@$(MAKE) --no-print-directory -C .. -f ./Minishell.mk build_filelist
|
||||
@$(MAKE) --no-print-directory -f ./Test.mk build_filelist
|
||||
|
||||
# phony
|
||||
.PHONY: all bonus clean fclean re header footer build_filelist
|
||||
107
test/Test.mk
Normal file
107
test/Test.mk
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Test.mk :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/04/28 17:28:30 by maiboyer #+# #+# #
|
||||
# Updated: 2024/10/11 10:55:07 by maiboyer ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
# Functions
|
||||
|
||||
link_group = -Wl,--start-group $(1) -Wl,--end-group
|
||||
|
||||
# Variables
|
||||
ANAME = test
|
||||
BUILD_DIR ?= $(shell realpath ../build/test)
|
||||
NAME = test
|
||||
|
||||
CFLAGS_ADDITIONAL += -DBONUS=1
|
||||
|
||||
export CFLAGS_ADDITIONAL
|
||||
export CC
|
||||
export BASE_PATH
|
||||
export BUILD_DIR
|
||||
|
||||
# Flags
|
||||
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)
|
||||
|
||||
|
||||
SRC_DIR = src
|
||||
GEN_DIR = output
|
||||
|
||||
-include Filelist.$(ANAME).mk
|
||||
|
||||
SRC = $(addsuffix .c,$(addprefix $(SRC_DIR)/,$(SRC_FILES)) $(addprefix $(GEN_DIR)/,$(GEN_FILES)))
|
||||
OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/$(ANAME)/,$(SRC_FILES) $(GEN_FILES)))
|
||||
DEP = $(addsuffix .d,$(addprefix $(BUILD_DIR)/$(ANAME)/,$(SRC_FILES) $(GEN_FILES)))
|
||||
|
||||
# Commands
|
||||
CC ?= clang
|
||||
RM = rm -rf
|
||||
|
||||
# Objects
|
||||
|
||||
# Colors
|
||||
GREEN = \033[32m
|
||||
GREY = \033[0;90m
|
||||
RED = \033[0;31m
|
||||
GOLD = \033[38;5;220m
|
||||
END = \033[0m
|
||||
|
||||
.PHONY: all bonus build_filelist re clean fclean
|
||||
|
||||
LIBS_NAMES = me aq ast parser line exec test
|
||||
LIBS_FILES = $(addprefix $(BUILD_DIR)/, $(addsuffix .a, $(addprefix lib, $(LIBS_NAMES))))
|
||||
LIBS_FLAGS = $(addprefix -l, $(LIBS_NAMES))
|
||||
|
||||
all:
|
||||
@$(MAKE) -C ../stdme/ "LIB_NAME=$(shell realpath ../stdme)/" libme.a
|
||||
@$(MAKE) -C ../allocator/ "LIB_NAME=$(shell realpath ../allocator)/" libaq.a
|
||||
@$(MAKE) -C ../ast/ "LIB_NAME=$(shell realpath ../ast)/" libast.a
|
||||
@$(MAKE) -C ../exec/ "LIB_NAME=$(shell realpath ../exec)/" libexec.a
|
||||
@$(MAKE) -C ../line/ "LIB_NAME=$(shell realpath ../line)/" libline.a
|
||||
@$(MAKE) -C ../parser/ "LIB_NAME=$(shell realpath ../parser)/" libparser.a
|
||||
@$(MAKE) -f ./Test.mk $(NAME)
|
||||
|
||||
bonus: all
|
||||
|
||||
# Dependences for all
|
||||
$(NAME): $(LIBS_FILES)
|
||||
@echo -e '$(GREY) Linking \t$(END)$(GOLD)$(NAME)$(END)'
|
||||
@$(CC) $(CFLAGS) -o $(NAME) -L$(BUILD_DIR) $(call link_group,$(LIBS_FLAGS))
|
||||
|
||||
lib$(ANAME).a: $(BUILD_DIR)/lib$(ANAME).a
|
||||
|
||||
$(BUILD_DIR)/lib$(ANAME).a: $(OBJ)
|
||||
@ar rcs $(BUILD_DIR)/lib$(ANAME).a $(OBJ)
|
||||
|
||||
|
||||
# Creating the objects
|
||||
$(BUILD_DIR)/$(ANAME)/%.o: $(SRC_DIR)/%.c
|
||||
@mkdir -p $(dir $@)
|
||||
@echo -e '$(GREY) Building\t$(END)$(GREEN)$<$(END)'
|
||||
@$(CC) $(CFLAGS) -o $@ -c $<
|
||||
|
||||
$(BUILD_DIR)/$(ANAME)/%.o: $(GEN_DIR)/%.c
|
||||
@mkdir -p $(dir $@)
|
||||
@echo -e '$(GREY) Building\t$(END)$(GREEN)$<$(END)'
|
||||
@$(CC) $(CFLAGS) -o $@ -c $<
|
||||
|
||||
build_filelist:
|
||||
@rm -f Filelist.$(ANAME).mk
|
||||
@printf '%-78s\\\n' "SRC_FILES =" > Filelist.$(ANAME).mk
|
||||
@tree $(SRC_DIR) -ifF | rg '$(SRC_DIR)/(.*)\.c$$' --replace '$$1' | sed -re 's/^(.*)_([0-9]+)$$/\1|\2/g' | sort -t'|' --key=1,1 --key=2,2n | sed -e's/|/_/' | xargs printf '%-78s\\\n' >> Filelist.$(ANAME).mk
|
||||
@echo "" >> Filelist.$(ANAME).mk
|
||||
@printf '%-78s\\\n' "GEN_FILES =" >> Filelist.$(ANAME).mk
|
||||
@tree $(GEN_DIR) -ifF | rg '$(GEN_DIR)/(.*)\.c$$' --replace '$$1' | sed -re 's/^(.*)_([0-9]+)$$/\1|\2/g' | sort -t'|' --key=1,1 --key=2,2n | sed -e's/|/_/' | xargs printf '%-78s\\\n' >> Filelist.$(ANAME).mk
|
||||
@echo "" >> Filelist.$(ANAME).mk
|
||||
@echo -e '$(GREY) Populating $(GREEN) Filelist.$(ANAME).mk$(END)'
|
||||
|
||||
%.h: ;
|
||||
|
||||
-include $(DEP)
|
||||
41
test/src/main.c
Normal file
41
test/src/main.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/11 10:56:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/11 11:30:59 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/convert/numbers_to_str.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
t_error _format_u64(t_num_str args, t_str *out);
|
||||
//if (_format_u64((t_num_str){.value = tmp, .is_nonnegative = false, .base = "0123456789ABCDEF", .prefix = ""}, &str))
|
||||
// continue;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
t_usize i;
|
||||
t_u64 tmp;
|
||||
t_str str;
|
||||
|
||||
(void)(argc--);
|
||||
(void)(argv++);
|
||||
i = 0;
|
||||
while (i < (t_usize)argc)
|
||||
{
|
||||
tmp = atoll(argv[i++]);
|
||||
if (u64_to_str(tmp, &str))
|
||||
continue;
|
||||
printf("%lu -> %s\n", tmp, str);
|
||||
mem_free(str);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue