Compare commits
3 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aa9db0ed4a | |||
| 980dff66be | |||
| 92796351f3 |
229 changed files with 11078 additions and 0 deletions
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
build
|
||||
/checker
|
||||
/push_swap
|
||||
*.list
|
||||
*.o
|
||||
*.d
|
||||
276
Makefile
Normal file
276
Makefile
Normal file
|
|
@ -0,0 +1,276 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||
# Updated: 2024/02/15 17:58:38 by maiboyer ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
define_module = $(addprefix $(1)/, $(2))
|
||||
|
||||
BUILD_DIR = build
|
||||
SRC_DIR = src
|
||||
INCLUDE_DIR = include
|
||||
LIBS_DIR = .
|
||||
GENERIC_DIR =
|
||||
GENERIC_INCLUDE =
|
||||
|
||||
NAME = push_swap
|
||||
|
||||
ifeq ($(MAKECMDGOALS), bonus)
|
||||
CFLAGS += -DBONUS=1
|
||||
BUILD_DIR := $(BUILD_DIR)/bonus/
|
||||
NAME = checker
|
||||
endif
|
||||
|
||||
LIB_NAME ?=
|
||||
TARGET = $(NAME)
|
||||
CC ?= clang
|
||||
CFLAGS += -Wall -Werror -Wextra -g3 -L$(BUILD_DIR) -Wno-unused-command-line-argument -MMD
|
||||
BONUS_FILES =
|
||||
LIBS_NAME =
|
||||
SUBJECT_URL = 'https://cdn.intra.42.fr/pdf/pdf/118610/en.subject.pdf'
|
||||
|
||||
GENERIC_FILES =
|
||||
SRC_FILES = \
|
||||
app/actual_main \
|
||||
app/best_index_to_move \
|
||||
app/best_move \
|
||||
app/do_move \
|
||||
app/find_place \
|
||||
app/iter_find \
|
||||
app/main \
|
||||
app/main_bonus \
|
||||
app/moves \
|
||||
app/moves/push \
|
||||
app/moves/rev_rotate \
|
||||
app/moves/rotate \
|
||||
app/moves/swap \
|
||||
app/rotate \
|
||||
app/run_with_items \
|
||||
app/sort2 \
|
||||
app/sort3 \
|
||||
app/sort5 \
|
||||
app/state \
|
||||
app/target \
|
||||
bonus/move1 \
|
||||
buffered_str/mod \
|
||||
char/isalnum \
|
||||
char/isalpha \
|
||||
char/isascii \
|
||||
char/isdigit \
|
||||
char/islower \
|
||||
char/isprint \
|
||||
char/isspace \
|
||||
char/isupper \
|
||||
char/tolower \
|
||||
char/toupper \
|
||||
convert/atoi \
|
||||
convert/itoa \
|
||||
convert/str_to_i16 \
|
||||
convert/str_to_i16_utils \
|
||||
convert/str_to_i32 \
|
||||
convert/str_to_i32_utils \
|
||||
convert/str_to_i64 \
|
||||
convert/str_to_i64_utils \
|
||||
convert/str_to_i8 \
|
||||
convert/str_to_i8_utils \
|
||||
convert/str_to_u16 \
|
||||
convert/str_to_u16_utils \
|
||||
convert/str_to_u32 \
|
||||
convert/str_to_u32_utils \
|
||||
convert/str_to_u64 \
|
||||
convert/str_to_u64_utils \
|
||||
convert/str_to_u8 \
|
||||
convert/str_to_u8_utils \
|
||||
fs/close \
|
||||
fs/open \
|
||||
fs/putchar_fd \
|
||||
fs/putendl_fd \
|
||||
fs/putnbr_fd \
|
||||
fs/putstr_fd \
|
||||
fs/read \
|
||||
fs/read_to_vec \
|
||||
fs/write \
|
||||
gnl/get_next_line \
|
||||
hash/hasher \
|
||||
hash/hash_signed \
|
||||
hash/hash_unsigned \
|
||||
hash/sip/sip13 \
|
||||
hash/sip/sip_utils \
|
||||
hash/sip/sip_utils2 \
|
||||
img/qoi/qoi_decode \
|
||||
img/qoi/qoi_encode \
|
||||
img/qoi/qoi_fs \
|
||||
img/qoi/qoi_utils \
|
||||
list/list_add_back \
|
||||
list/list_add_front \
|
||||
list/list_alloc_node \
|
||||
list/list_free_all \
|
||||
list/list_free_one \
|
||||
list/list_get_last \
|
||||
list/list_iter \
|
||||
list/list_map \
|
||||
list/list_size \
|
||||
mem/mem_alloc \
|
||||
mem/mem_alloc_array \
|
||||
mem/mem_compare \
|
||||
mem/mem_copy \
|
||||
mem/mem_find \
|
||||
mem/mem_find_bytes \
|
||||
mem/mem_move \
|
||||
mem/mem_set \
|
||||
mem/mem_set_zero \
|
||||
num/u16/rotate \
|
||||
num/u32/rotate \
|
||||
num/u64/from_bytes \
|
||||
num/u64/rotate \
|
||||
num/u8/rotate \
|
||||
num/usize/rotate \
|
||||
printf/formatter/char \
|
||||
printf/formatter/decimal \
|
||||
printf/formatter/hex \
|
||||
printf/formatter/oct \
|
||||
printf/formatter/ptr \
|
||||
printf/formatter/unsigned_decimal \
|
||||
printf/formatter/utils \
|
||||
printf/formatter/utils2 \
|
||||
printf/formatter/utils3 \
|
||||
printf/formatter/utils_numbers \
|
||||
printf/matchers \
|
||||
printf/printf \
|
||||
printf/vprintf \
|
||||
string/str_clone \
|
||||
string/str_find_chr \
|
||||
string/str_find_rev_chr \
|
||||
string/str_find_str \
|
||||
string/str_iter \
|
||||
string/str_join \
|
||||
string/str_l_cat \
|
||||
string/str_l_copy \
|
||||
string/str_len \
|
||||
string/str_map \
|
||||
string/str_n_compare \
|
||||
string/str_n_find_str \
|
||||
string/str_split \
|
||||
string/str_substring \
|
||||
string/str_trim \
|
||||
vec/vec_buf_str \
|
||||
vec/vec_buf_str_functions2 \
|
||||
vec/vec_buf_str_functions3 \
|
||||
vec/vec_i64 \
|
||||
vec/vec_i64_bool \
|
||||
vec/vec_i64_bool_functions2 \
|
||||
vec/vec_i64_bool_functions3 \
|
||||
vec/vec_i64_bool_sort \
|
||||
vec/vec_i64_functions2 \
|
||||
vec/vec_i64_functions3 \
|
||||
vec/vec_i64_sort \
|
||||
vec/vec_u8 \
|
||||
vec/vec_u8_functions2 \
|
||||
vec/vec_u8_functions3
|
||||
|
||||
BONUS = $(addsuffix .c,$(addprefix $(SRC_DIR)/,$(BONUS_FILES)))
|
||||
SRC = $(addsuffix .c,$(addprefix $(SRC_DIR)/,$(SRC_FILES))) \
|
||||
$(addsuffix .c,$(addprefix $(GENERIC_DIR)/,$(GENERIC_FILES)))
|
||||
BONUS_OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(BONUS_FILES)))
|
||||
OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(SRC_FILES))) \
|
||||
$(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(GENERIC_FILES)))
|
||||
DEPS = $(addsuffix .d,$(addprefix $(BUILD_DIR)/,$(SRC_FILES))) \
|
||||
$(addsuffix .d,$(addprefix $(BUILD_DIR)/,$(GENERIC_FILES)))
|
||||
LIBS = $(addprefix $(LIBS_DIR)/,$(LIBS_NAME))
|
||||
INCLUDES = $(addprefix -I,$(INCLUDE_DIR) $(GENERIC_INCLUDE) $(LIBS) $(addsuffix /include,$(LIBS)))
|
||||
COL_GRAY = \\e[90m
|
||||
COL_WHITE = \\e[37m
|
||||
COL_GREEN = \\e[32m
|
||||
COL_BOLD = \\e[1m
|
||||
COL_RESET = \\e[0m
|
||||
|
||||
|
||||
.PHONY: remove_name clean all fclean bonus format re generate_filelist subject get_lib
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
bonus: all
|
||||
@printf \\n$(COL_GRAY)Building\ Output\ \(with\ bonus\)\ $(COL_WHITE)$(COL_BOLD)%-28s$(COL_RESET)\ \
|
||||
$(NAME)
|
||||
@printf $(COL_RESET)$(COL_GREEN)done$(COL_RESET)\\n
|
||||
|
||||
get_lib:
|
||||
@printf $(LIB_NAME)/$(NAME)
|
||||
|
||||
$(NAME): $(OBJ) libs_build
|
||||
@printf \\n$(COL_GRAY)Building\ Output\ $(COL_WHITE)$(COL_BOLD)%-28s$(COL_RESET)\ \
|
||||
$(NAME)
|
||||
@$(CC) $(INCLUDES) $(OBJ) $(CFLAGS) -o $(NAME)
|
||||
@#ar rcs $(BUILD_DIR)/$(NAME) $(OBJ)
|
||||
@printf $(COL_GREEN)done$(COL_RESET)\\n
|
||||
|
||||
libs_build:
|
||||
@- $(foreach LIB,$(LIBS),\
|
||||
printf \\n; \
|
||||
printf $(COL_GRAY)Building\ library\ $(COL_RESET); \
|
||||
printf $(COL_WHITE)$(COL_BOLD)%-25s$(COL_RESET)\\n $(LIB); \
|
||||
make LIB_NAME=$(LIB)/ BUILD_DIR=$(realpath $(BUILD_DIR)) -C $(LIB) --no-print-directory all; \
|
||||
printf \\n; \
|
||||
)
|
||||
|
||||
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
|
||||
@mkdir -p $(dir $@)
|
||||
@printf $(COL_GRAY)Building\ $(COL_BOLD)$(COL_WHITE)%-50s\ $(LIB_NAME)$<
|
||||
@$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@
|
||||
@printf $(COL_RESET)$(COL_GREEN)done$(COL_RESET)\\n
|
||||
|
||||
$(BUILD_DIR)/%.o: $(GENERIC_DIR)/%.c
|
||||
@mkdir -p $(dir $@)
|
||||
@printf $(COL_GRAY)Building\ $(COL_BOLD)$(COL_WHITE)%-50s\ $(LIB_NAME)$<
|
||||
@$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@
|
||||
@printf $(COL_RESET)$(COL_GREEN)done$(COL_RESET)\\n
|
||||
|
||||
clean:
|
||||
@- $(foreach LIB,$(LIBS), \
|
||||
make clean LIB_NAME=$(LIB)/ BUILD_DIR=$(realpath $(BUILD_DIR)) -C $(LIB) --no-print-directory || true;\
|
||||
)
|
||||
@- $(if $(LIB_NAME),,\
|
||||
printf $(COL_WHITE)Clearing\ Artefacts\ ; \
|
||||
printf $(COL_GRAY)\%-25s$(COL_RESET)\ \($(BUILD_DIR)\); \
|
||||
rm -rf $(BUILD_DIR); \
|
||||
printf $(COL_GREEN)done$(COL_RESET)\\n; \
|
||||
)
|
||||
@echo >/dev/null
|
||||
|
||||
fclean: clean
|
||||
@- $(foreach LIB,$(LIBS), \
|
||||
make fclean LIB_NAME=$(LIB)/ BUILD_DIR=$(realpath $(BUILD_DIR)) -C $(LIB) --no-print-directory || true;\
|
||||
)
|
||||
@printf $(COL_WHITE)Clearing\ Output\ $(COL_GRAY)%-28s$(COL_RESET)\ \
|
||||
\($(LIB_NAME)$(NAME)\)
|
||||
@rm -f $(BUILD_DIR)$(NAME)
|
||||
@rm -f push_swap
|
||||
@rm -f checker
|
||||
@printf $(COL_GREEN)done$(COL_RESET)\\n
|
||||
|
||||
re: fclean all
|
||||
|
||||
generate_filelist:
|
||||
@/usr/bin/env zsh -c "tree -iFf --noreport output | rg '^output/src/(.*)\.c\$$' --replace '\$$1' | sort -u" > ./gen.list
|
||||
@/usr/bin/env zsh -c "tree -iFf --noreport src | rg '^src/(.*)\.c\$$' --replace '\$$1' | sort -u" > ./src.list
|
||||
|
||||
format:
|
||||
@zsh -c "c_formatter_42 **/*.c **/*.h"
|
||||
|
||||
subject: subject.txt
|
||||
@bat --plain subject.txt
|
||||
|
||||
subject.txt:
|
||||
@curl $(SUBJECT_URL) | pdftotext -layout -nopgbrk - subject.txt
|
||||
|
||||
fuck_raphael:
|
||||
@echo "Oh que oui~~~\net jte nioc"
|
||||
|
||||
-include $(DEPS)
|
||||
|
||||
30
include/app/best_index_to_move.h
Normal file
30
include/app/best_index_to_move.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* best_index_to_move.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/08 14:18:43 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/08 14:20:01 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BEST_INDEX_TO_MOVE_H
|
||||
# define BEST_INDEX_TO_MOVE_H
|
||||
|
||||
# include "app/best_move.h"
|
||||
# include "app/state.h"
|
||||
# include "me/types.h"
|
||||
# include "me/vec/vec_i64.h"
|
||||
|
||||
struct s_best_index_to_move
|
||||
{
|
||||
t_state *state;
|
||||
t_vec_i64 *from;
|
||||
t_vec_i64 *to;
|
||||
t_iter_pos_func f;
|
||||
t_usize i;
|
||||
};
|
||||
|
||||
#endif /* BEST_INDEX_TO_MOVE_H */
|
||||
43
include/app/best_move.h
Normal file
43
include/app/best_move.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* best_move.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 20:10:21 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/08 13:30:30 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BEST_MOVE_H
|
||||
# define BEST_MOVE_H
|
||||
|
||||
# include "app/state.h"
|
||||
# include "me/vec/vec_i64.h"
|
||||
|
||||
struct s_functions
|
||||
{
|
||||
void (*forward)(void *);
|
||||
void (*reverse)(void *);
|
||||
};
|
||||
|
||||
typedef t_usize (*t_iter_pos_func)(t_vec_i64 *);
|
||||
|
||||
typedef struct s_best_move_args
|
||||
{
|
||||
t_iter_pos_func iter_func;
|
||||
t_usize index;
|
||||
t_vec_i64 *from;
|
||||
t_vec_i64 *to;
|
||||
void *args;
|
||||
struct s_functions main;
|
||||
struct s_functions other;
|
||||
struct s_functions both;
|
||||
bool print_stuff;
|
||||
} t_best_move_args;
|
||||
|
||||
void run_func_with_best_rotate_for_item(t_state *state,
|
||||
t_best_move_args data);
|
||||
|
||||
#endif /* BEST_MOVE_H */
|
||||
58
include/app/best_move_inner.h
Normal file
58
include/app/best_move_inner.h
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* best_move_inner.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 21:31:42 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/08 14:22:49 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BEST_MOVE_INNER_H
|
||||
# define BEST_MOVE_INNER_H
|
||||
|
||||
# include "app/best_move.h"
|
||||
# include "app/rotate.h"
|
||||
# include "app/state.h"
|
||||
# include "me/types.h"
|
||||
# include "me/vec/vec_i64.h"
|
||||
|
||||
typedef void (*t_banana_func)(void *);
|
||||
|
||||
static inline t_banana_func choose_func(struct s_functions *funcs,
|
||||
t_rotation rotate)
|
||||
{
|
||||
if (rotate.direction == FORWARD)
|
||||
return (funcs->forward);
|
||||
else if (rotate.direction == REVERSE)
|
||||
return (funcs->reverse);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static inline t_isize abs_diff(t_isize lhs, t_isize rhs)
|
||||
{
|
||||
if (lhs > rhs)
|
||||
return (lhs - rhs);
|
||||
else
|
||||
return (rhs - lhs);
|
||||
}
|
||||
|
||||
static inline t_isize min(t_isize lhs, t_isize rhs)
|
||||
{
|
||||
if (lhs > rhs)
|
||||
return (rhs);
|
||||
else
|
||||
return (lhs);
|
||||
}
|
||||
|
||||
static inline t_isize max(t_isize lhs, t_isize rhs)
|
||||
{
|
||||
if (lhs < rhs)
|
||||
return (rhs);
|
||||
else
|
||||
return (lhs);
|
||||
}
|
||||
|
||||
#endif /* BEST_MOVE_INNER_H */
|
||||
22
include/app/find_iter.h
Normal file
22
include/app/find_iter.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* find_iter.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/31 14:24:10 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/31 14:24:47 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FIND_ITER_H
|
||||
# define FIND_ITER_H
|
||||
|
||||
# include "me/types.h"
|
||||
# include "me/vec/vec_i64.h"
|
||||
|
||||
t_usize min_iter_zero_pos(t_vec_i64 *vec);
|
||||
t_usize max_iter_zero_pos(t_vec_i64 *vec);
|
||||
|
||||
#endif /* FIND_ITER_H */
|
||||
29
include/app/find_place.h
Normal file
29
include/app/find_place.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* find_place.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 22:00:27 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/29 22:15:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FIND_PLACE_H
|
||||
# define FIND_PLACE_H
|
||||
|
||||
# include "app/state.h"
|
||||
# include "me/types.h"
|
||||
|
||||
typedef struct s_find_place_iter_state
|
||||
{
|
||||
t_usize current_index;
|
||||
t_usize found_index;
|
||||
t_i64 to_find_elem;
|
||||
|
||||
} t_find_place_iter_state;
|
||||
|
||||
t_usize find_place(t_i64 elem, t_state *state);
|
||||
|
||||
#endif /* FIND_PLACE_H */
|
||||
24
include/app/iter_state.h
Normal file
24
include/app/iter_state.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* iter_state.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/31 14:19:06 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/31 14:19:50 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ITER_STATE_H
|
||||
# define ITER_STATE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
typedef struct s_iter_state
|
||||
{
|
||||
t_usize pos;
|
||||
t_i64 elem;
|
||||
} t_iter_state;
|
||||
|
||||
#endif /* ITER_STATE_H */
|
||||
23
include/app/moves.h
Normal file
23
include/app/moves.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* moves.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/11 16:13:08 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/29 19:07:15 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MOVES_H
|
||||
# define MOVES_H
|
||||
|
||||
# include "app/state.h"
|
||||
# include "app/types/type_move.h"
|
||||
# include "me/types.h"
|
||||
|
||||
void do_move(t_move m, t_state *s);
|
||||
t_const_str get_str_for_move(t_move m);
|
||||
|
||||
#endif /* MOVES_H */
|
||||
56
include/app/rotate.h
Normal file
56
include/app/rotate.h
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rotate.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 19:00:18 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/08 13:33:09 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ROTATE_H
|
||||
# define ROTATE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
enum e_rotation_direction
|
||||
{
|
||||
FORWARD,
|
||||
REVERSE,
|
||||
};
|
||||
typedef struct s_rotation
|
||||
{
|
||||
t_isize value;
|
||||
t_isize ring_size;
|
||||
enum e_rotation_direction direction;
|
||||
} t_rotation;
|
||||
|
||||
static inline t_rotation forward(t_isize by, t_isize ring_size)
|
||||
{
|
||||
return ((t_rotation){.value = by, .ring_size = ring_size,
|
||||
.direction = FORWARD});
|
||||
}
|
||||
|
||||
static inline t_rotation reverse(t_isize by, t_isize ring_size)
|
||||
{
|
||||
return ((t_rotation){.value = by, .ring_size = ring_size,
|
||||
.direction = REVERSE});
|
||||
}
|
||||
|
||||
static inline t_rotation flip(t_rotation rot)
|
||||
{
|
||||
enum e_rotation_direction flipped;
|
||||
|
||||
if (rot.direction == FORWARD)
|
||||
flipped = REVERSE;
|
||||
else if (rot.direction == REVERSE)
|
||||
flipped = FORWARD;
|
||||
else
|
||||
return (rot);
|
||||
return ((t_rotation){.value = rot.ring_size - rot.value,
|
||||
.ring_size = rot.ring_size, .direction = flipped});
|
||||
}
|
||||
|
||||
#endif /* ROTATE_H */
|
||||
73
include/app/state.h
Normal file
73
include/app/state.h
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* state.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/11 14:27:25 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/08 19:05:37 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STATE_H
|
||||
# define STATE_H
|
||||
|
||||
# include "me/types.h"
|
||||
# include "me/vec/vec_i64.h"
|
||||
# include "me/vec/vec_i64_bool.h"
|
||||
|
||||
# ifndef BONUS
|
||||
# define BONUS 0
|
||||
# endif
|
||||
|
||||
typedef struct s_state
|
||||
{
|
||||
t_vec_i64_bool sorted;
|
||||
t_vec_i64 stack_a;
|
||||
t_vec_i64 stack_b;
|
||||
} t_state;
|
||||
|
||||
t_state parses_arguments(t_usize count, t_str nums[]);
|
||||
void free_state(t_state state);
|
||||
|
||||
static inline void make_sorted_true_for_elem(t_state *s, t_i64 elem)
|
||||
{
|
||||
t_usize i;
|
||||
|
||||
i = 0;
|
||||
while (i < s->sorted.len)
|
||||
{
|
||||
if (s->sorted.buffer[i].value == elem)
|
||||
{
|
||||
s->sorted.buffer[i].active = true;
|
||||
return ;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void make_sorted_true_from_stack(t_state *s, t_vec_i64 *stack)
|
||||
{
|
||||
t_usize i;
|
||||
|
||||
i = 0;
|
||||
while (i < stack->len)
|
||||
{
|
||||
make_sorted_true_for_elem(s, stack->buffer[i++]);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void make_sorted_all_false(t_state *s)
|
||||
{
|
||||
t_usize i;
|
||||
|
||||
i = 0;
|
||||
while (i < s->sorted.len)
|
||||
{
|
||||
s->sorted.buffer[i].active = false;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* STATE_H */
|
||||
21
include/app/target.h
Normal file
21
include/app/target.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* target.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 20:30:43 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/29 20:31:28 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TARGET_H
|
||||
# define TARGET_H
|
||||
|
||||
# include "app/rotate.h"
|
||||
# include "me/types.h"
|
||||
|
||||
t_rotation target(t_usize from, t_usize to, t_usize ring_size);
|
||||
|
||||
#endif /* TARGET_H */
|
||||
24
include/app/types/type_i64_bool.h
Normal file
24
include/app/types/type_i64_bool.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* type_i64_bool.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 19:14:52 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/29 19:15:56 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TYPE_I64_BOOL_H
|
||||
# define TYPE_I64_BOOL_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
typedef struct s_i64_bool
|
||||
{
|
||||
t_i64 value;
|
||||
bool active;
|
||||
} t_i64_bool;
|
||||
|
||||
#endif /* TYPE_I64_BOOL_H */
|
||||
31
include/app/types/type_move.h
Normal file
31
include/app/types/type_move.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* type_move.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/12 21:26:56 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/12 21:27:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TYPE_MOVE_H
|
||||
# define TYPE_MOVE_H
|
||||
|
||||
typedef enum e_move
|
||||
{
|
||||
SWAP_A = 1 << 0,
|
||||
SWAP_B = 1 << 1,
|
||||
SWAP_BOTH = SWAP_A | SWAP_B,
|
||||
PUSH_A = 1 << 2,
|
||||
PUSH_B = 1 << 3,
|
||||
ROTATE_A = 1 << 4,
|
||||
ROTATE_B = 1 << 5,
|
||||
ROTATE_BOTH = ROTATE_A | ROTATE_B,
|
||||
REVERSE_ROTATE_A = 1 << 6,
|
||||
REVERSE_ROTATE_B = 1 << 7,
|
||||
REVERSE_ROTATE_BOTH = REVERSE_ROTATE_A | REVERSE_ROTATE_B,
|
||||
} t_move;
|
||||
|
||||
#endif /* TYPE_MOVE_H */
|
||||
49
include/me/buffered_str/buf_str.h
Normal file
49
include/me/buffered_str/buf_str.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* buf_str.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/16 17:54:28 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/31 15:34:29 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BUF_STR_H
|
||||
# define BUF_STR_H
|
||||
# include "me/types.h"
|
||||
|
||||
typedef struct s_buffer_str
|
||||
{
|
||||
t_str buf;
|
||||
t_usize capacity;
|
||||
t_usize len;
|
||||
} t_buffer_str;
|
||||
|
||||
bool push_str_buffer(t_buffer_str *buf, t_const_str to_push);
|
||||
bool push_str_char(t_buffer_str *buf, char to_push);
|
||||
void str_clear(t_buffer_str *buf);
|
||||
t_buffer_str alloc_new_buffer(t_usize capacity);
|
||||
|
||||
static inline void str_free(t_buffer_str buf)
|
||||
{
|
||||
void free(void *);
|
||||
|
||||
free(buf.buf);
|
||||
}
|
||||
|
||||
static inline char str_pop(t_buffer_str *buf)
|
||||
{
|
||||
char c;
|
||||
|
||||
c = '\0';
|
||||
if (buf->buf && buf->len)
|
||||
{
|
||||
c = buf->buf[buf->len - 1];
|
||||
buf->buf[buf->len - 1] = '\0';
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
#endif
|
||||
20
include/me/char/isalnum.h
Normal file
20
include/me/char/isalnum.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* isalnum.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:39:39 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISALNUM_H
|
||||
# define ISALNUM_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_isalnum(char chr);
|
||||
|
||||
#endif
|
||||
20
include/me/char/isalpha.h
Normal file
20
include/me/char/isalpha.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* isalpha.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:39:36 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISALPHA_H
|
||||
# define ISALPHA_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_isalpha(char chr);
|
||||
|
||||
#endif
|
||||
20
include/me/char/isascii.h
Normal file
20
include/me/char/isascii.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* isascii.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 17:51:01 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:39:33 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISASCII_H
|
||||
# define ISASCII_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_isascii(char chr);
|
||||
|
||||
#endif
|
||||
20
include/me/char/isdigit.h
Normal file
20
include/me/char/isdigit.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* isdigit.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:41:55 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISDIGIT_H
|
||||
# define ISDIGIT_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_isdigit(char chr);
|
||||
|
||||
#endif
|
||||
20
include/me/char/islower.h
Normal file
20
include/me/char/islower.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* islower.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:48:25 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISLOWER_H
|
||||
# define ISLOWER_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_islower(char chr);
|
||||
|
||||
#endif
|
||||
20
include/me/char/isprint.h
Normal file
20
include/me/char/isprint.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* isprint.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:44:49 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISPRINT_H
|
||||
# define ISPRINT_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_isprint(char chr);
|
||||
|
||||
#endif
|
||||
20
include/me/char/isspace.h
Normal file
20
include/me/char/isspace.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* isspace.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 14:26:25 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:45:02 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISSPACE_H
|
||||
# define ISSPACE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_isspace(char chr);
|
||||
|
||||
#endif
|
||||
20
include/me/char/isupper.h
Normal file
20
include/me/char/isupper.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* isupper.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:45:16 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISUPPER_H
|
||||
# define ISUPPER_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_isupper(char chr);
|
||||
|
||||
#endif
|
||||
20
include/me/char/tolower.h
Normal file
20
include/me/char/tolower.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tolower.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:47:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:45:33 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TOLOWER_H
|
||||
# define TOLOWER_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_tolower(char chr);
|
||||
|
||||
#endif
|
||||
20
include/me/char/toupper.h
Normal file
20
include/me/char/toupper.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* toupper.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:47:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:45:52 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TOUPPER_H
|
||||
# define TOUPPER_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_toupper(char chr);
|
||||
|
||||
#endif
|
||||
21
include/me/convert/atoi.h
Normal file
21
include/me/convert/atoi.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* atoi.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 14:14:00 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/11 15:36:12 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ATOI_H
|
||||
# define ATOI_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_i32 me_atoi(t_const_str str);
|
||||
t_i64 me_atoi_64(t_const_str str);
|
||||
|
||||
#endif
|
||||
20
include/me/convert/itoa.h
Normal file
20
include/me/convert/itoa.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* itoa.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/03 21:05:46 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:48:37 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ITOA_H
|
||||
# define ITOA_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_str me_itoa(t_i32 nb);
|
||||
|
||||
#endif
|
||||
30
include/me/convert/str_to_numbers.h
Normal file
30
include/me/convert/str_to_numbers.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_to_numbers.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/01 21:08:13 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/15 18:02:28 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_TO_NUMBERS_H
|
||||
# define STR_TO_NUMBERS_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_error str_to_isize(t_const_str str, t_u32 radix, t_isize *out);
|
||||
t_error str_to_i64(t_const_str str, t_u32 radix, t_i64 *out);
|
||||
t_error str_to_i32(t_const_str str, t_u32 radix, t_i32 *out);
|
||||
t_error str_to_i16(t_const_str str, t_u32 radix, t_i16 *out);
|
||||
t_error str_to_i8(t_const_str str, t_u32 radix, t_i8 *out);
|
||||
|
||||
t_error str_to_usize(t_const_str str, t_u32 radix, t_usize *out);
|
||||
t_error str_to_u64(t_const_str str, t_u32 radix, t_u64 *out);
|
||||
t_error str_to_u32(t_const_str str, t_u32 radix, t_u32 *out);
|
||||
t_error str_to_u16(t_const_str str, t_u32 radix, t_u16 *out);
|
||||
t_error str_to_u8(t_const_str str, t_u32 radix, t_u8 *out);
|
||||
|
||||
#endif /* STR_TO_NUMBERS_H */
|
||||
20
include/me/fs/close.h
Normal file
20
include/me/fs/close.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* close.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 15:56:56 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:49:22 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CLOSE_H
|
||||
# define CLOSE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_close(t_file file, t_i32 *error);
|
||||
|
||||
#endif
|
||||
22
include/me/fs/open.h
Normal file
22
include/me/fs/open.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* open.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/03 15:29:38 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/05 16:43:37 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef OPEN_H
|
||||
# define OPEN_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_error me_open(t_const_str path, bool read, bool write, t_file *file_out);
|
||||
t_error me_open_truncate(t_const_str path, t_file *file_out);
|
||||
t_error me_open_create(t_const_str path, t_file *file_out);
|
||||
|
||||
#endif
|
||||
20
include/me/fs/putchar_fd.h
Normal file
20
include/me/fs/putchar_fd.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* putchar_fd.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 04:42:45 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:49:06 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PUTCHAR_FD_H
|
||||
# define PUTCHAR_FD_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void me_putchar_fd(char chr, t_file file);
|
||||
|
||||
#endif
|
||||
20
include/me/fs/putendl_fd.h
Normal file
20
include/me/fs/putendl_fd.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* putendl_fd.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 04:42:45 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:31:54 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PUTENDL_FD_H
|
||||
# define PUTENDL_FD_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void me_putendl_fd(t_str str, t_file file);
|
||||
|
||||
#endif
|
||||
20
include/me/fs/putnbr_fd.h
Normal file
20
include/me/fs/putnbr_fd.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* putnbr_fd.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 12:45:06 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:32:41 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PUTNBR_FD_H
|
||||
# define PUTNBR_FD_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void me_putnbr_fd(t_i32 n, t_file file);
|
||||
|
||||
#endif
|
||||
20
include/me/fs/putstr_fd.h
Normal file
20
include/me/fs/putstr_fd.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* putstr_fd.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 04:42:45 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:35:53 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PUTSTR_FD_H
|
||||
# define PUTSTR_FD_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void me_putstr_fd(t_str str, t_file file);
|
||||
|
||||
#endif
|
||||
20
include/me/fs/read.h
Normal file
20
include/me/fs/read.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* read.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/03 15:21:19 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:37:03 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef READ_H
|
||||
# define READ_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_usize me_read(t_file fd, t_u8 *buffer, t_i64 buffer_max, bool *eof_out);
|
||||
|
||||
#endif
|
||||
25
include/me/fs/read_to_vec.h
Normal file
25
include/me/fs/read_to_vec.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* read_to_vec.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/24 18:50:37 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/24 18:57:36 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef READ_TO_VEC_H
|
||||
# define READ_TO_VEC_H
|
||||
|
||||
# include "me/types.h"
|
||||
# include "me/vec/vec_u8.h"
|
||||
|
||||
# ifndef READ_BUFFER_SIZE
|
||||
# define READ_BUFFER_SIZE 4096
|
||||
# endif
|
||||
|
||||
bool read_to_vec(t_const_str path, t_vec_u8 *out);
|
||||
|
||||
#endif
|
||||
20
include/me/fs/write.h
Normal file
20
include/me/fs/write.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* write.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/03 15:27:33 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:36:48 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef WRITE_H
|
||||
# define WRITE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_write(t_file fd, t_u8 *buffer, t_i64 size);
|
||||
|
||||
#endif
|
||||
43
include/me/gnl/gnl.h
Normal file
43
include/me/gnl/gnl.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* gnl.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer42@students.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/23 14:40:15 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 19:21:56 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef GNL_H
|
||||
# define GNL_H
|
||||
|
||||
# ifndef BUFFER_SIZE
|
||||
# define BUFFER_SIZE 128
|
||||
# endif
|
||||
|
||||
# ifndef BUFFER_LENGTH
|
||||
# define BUFFER_LENGTH 512
|
||||
# endif
|
||||
|
||||
# include "me/buffered_str/buf_str.h"
|
||||
# include "me/types.h"
|
||||
|
||||
typedef struct s_static_buffer
|
||||
{
|
||||
t_file fd;
|
||||
bool used;
|
||||
char buf[BUFFER_SIZE + 1];
|
||||
bool init;
|
||||
} t_static_buffer;
|
||||
|
||||
typedef struct s_copy_flags
|
||||
{
|
||||
bool error;
|
||||
bool empty_read;
|
||||
} t_copy_flags;
|
||||
|
||||
t_buffer_str get_next_line(t_file fd, bool *error);
|
||||
|
||||
#endif
|
||||
52
include/me/hash/hasher.h
Normal file
52
include/me/hash/hasher.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* hasher.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/10 19:50:39 by maix #+# #+# */
|
||||
/* Updated: 2023/12/27 16:44:09 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef HASHER_H
|
||||
# define HASHER_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
typedef void (*t_hash_bytes)(void *hasher, t_u8 *bytes,
|
||||
t_usize count);
|
||||
typedef t_u64 (*t_hasher_finish)(void *hasher);
|
||||
typedef t_u64 (*t_hasher_reset_and_finish)(void *hasher);
|
||||
|
||||
typedef struct s_hasher
|
||||
{
|
||||
void *hasher;
|
||||
t_hash_bytes hash_bytes;
|
||||
t_hasher_finish finish;
|
||||
t_hasher_reset_and_finish reset_and_finish;
|
||||
|
||||
} t_hasher;
|
||||
|
||||
void hasher_write_bytes(t_hasher *hasher,
|
||||
t_u8 *bytes, t_usize count);
|
||||
|
||||
void hasher_write_u8(t_hasher *hasher, t_u8 n);
|
||||
void hasher_write_u16(t_hasher *hasher, t_u16 n);
|
||||
void hasher_write_u32(t_hasher *hasher, t_u32 n);
|
||||
void hasher_write_u64(t_hasher *hasher, t_u64 n);
|
||||
void hasher_write_usize(t_hasher *hasher, t_usize n);
|
||||
|
||||
void hasher_write_i8(t_hasher *hasher, t_i8 n);
|
||||
void hasher_write_i16(t_hasher *hasher, t_i16 n);
|
||||
void hasher_write_i32(t_hasher *hasher, t_i32 n);
|
||||
void hasher_write_i64(t_hasher *hasher, t_i64 n);
|
||||
void hasher_write_isize(t_hasher *hasher, t_isize n);
|
||||
|
||||
void hasher_write_str(t_hasher *hasher, t_str str);
|
||||
|
||||
t_u64 hasher_finish(t_hasher *hasher);
|
||||
t_u64 hasher_reset_and_finish(t_hasher *hasher);
|
||||
|
||||
#endif
|
||||
38
include/me/hash/sip.h
Normal file
38
include/me/hash/sip.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* sip.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/10 19:33:46 by maix #+# #+# */
|
||||
/* Updated: 2023/12/11 15:10:07 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef SIP_H
|
||||
# define SIP_H
|
||||
# include "me/hash/hasher.h"
|
||||
# include "me/types.h"
|
||||
|
||||
typedef struct s_sip_state
|
||||
{
|
||||
t_u64 v0;
|
||||
t_u64 v2;
|
||||
t_u64 v1;
|
||||
t_u64 v3;
|
||||
} t_sip_state;
|
||||
|
||||
typedef struct s_sip13
|
||||
{
|
||||
t_u64 k0;
|
||||
t_u64 k1;
|
||||
t_usize length;
|
||||
t_u64 tail;
|
||||
t_usize ntail;
|
||||
t_sip_state state;
|
||||
} t_sip13;
|
||||
|
||||
t_hasher hasher_sip13_new(void);
|
||||
|
||||
#endif
|
||||
24
include/me/hash/sip/sip_utils.h
Normal file
24
include/me/hash/sip/sip_utils.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* sip_utils.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/10 19:34:10 by maix #+# #+# */
|
||||
/* Updated: 2023/12/27 16:48:51 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef SIP_UTILS_H
|
||||
# define SIP_UTILS_H
|
||||
# include "me/hash/sip.h"
|
||||
# include "me/types.h"
|
||||
|
||||
void compress(t_sip_state *state);
|
||||
t_sip_state create_state_with_key(t_u64 k0, t_u64 k1);
|
||||
t_u64 sip13_finish(t_sip13 *hasher);
|
||||
t_u64 sip13_reset_and_finish(t_sip13 *hasher);
|
||||
void sip13_write_bytes(t_sip13 *self, t_u8 *msg, t_usize count);
|
||||
|
||||
#endif
|
||||
305
include/me/img/qoi.h
Normal file
305
include/me/img/qoi.h
Normal file
|
|
@ -0,0 +1,305 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* qoi.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/24 17:39:36 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/25 18:35:05 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
|
||||
Copyright (c) 2021, Dominic Szablewski - https://phoboslab.org
|
||||
SPDX-License-Identifier: MIT
|
||||
|
||||
|
||||
QOI - The "Quite OK Image" format for fast, lossless image compression
|
||||
|
||||
-- About
|
||||
|
||||
QOI encodes and decodes images in a lossless format. Compared to stb_image and
|
||||
stb_image_write QOI offers 20x-50x faster encoding, 3x-4x faster decoding and
|
||||
20% better compression.
|
||||
|
||||
|
||||
-- Synopsis
|
||||
|
||||
// Define `QOI_IMPLEMENTATION` in *one* C/C++ file before including this
|
||||
// library to create the implementation.
|
||||
|
||||
#define QOI_IMPLEMENTATION
|
||||
#include "qoi.h"
|
||||
|
||||
// Encode and store an RGBA buffer to the file system. The t_qoi_desc describes
|
||||
// the input pixel data.
|
||||
qoi_write("image_new.qoi", rgba_pixels, &(t_qoi_desc){
|
||||
.width = 1920,
|
||||
.height = 1080,
|
||||
.channels = 4,
|
||||
.colorspace = QOI_SRGB
|
||||
});
|
||||
|
||||
// Load and decode a QOI image from the file system t_i32o a 32bbp RGBA buffer.
|
||||
// The t_qoi_desc struct will be filled with the width, height,
|
||||
number of channels
|
||||
// and colorspace read from the file header.
|
||||
t_qoi_desc desc;
|
||||
void *rgba_pixels = qoi_read("image.qoi", &desc, 4);
|
||||
|
||||
|
||||
|
||||
-- Documentation
|
||||
|
||||
This library provides the following functions;
|
||||
- qoi_read -- read and decode a QOI file
|
||||
- qoi_decode -- decode the raw bytes of a QOI image from memory
|
||||
- qoi_write -- encode and write a QOI file
|
||||
- qoi_encode -- encode an rgba buffer t_i32o a QOI image in memory
|
||||
|
||||
See the function declaration below for the signature and more information.
|
||||
|
||||
If you don't want/need the qoi_read and qoi_write functions, you can define
|
||||
QOI_NO_STDIO before including this library.
|
||||
|
||||
This library uses malloc() and free(). To supply your own malloc implementation
|
||||
you can define QOI_MALLOC and QOI_FREE before including this library.
|
||||
|
||||
This library uses memset() to zero-initialize the index. To supply your own
|
||||
implementation you can define QOI_ZEROARR before including this library.
|
||||
|
||||
|
||||
-- Data Format
|
||||
|
||||
A QOI file has a 14 byte header, followed by any number of data "chunks" and an
|
||||
8-byte end marker.
|
||||
|
||||
struct qoi_header_t {
|
||||
char magic[4]; // magic bytes "qoif"
|
||||
ut_i3232_t width; // image width in pixels (BE)
|
||||
ut_i3232_t height; // sprite.height in pixels (BE)
|
||||
ut_i328_t channels; // 3 = RGB, 4 = RGBA
|
||||
ut_i328_t colorspace; // 0 = sRGB with linear alpha, 1 = all channels
|
||||
linear
|
||||
};
|
||||
|
||||
Images are encoded row by row, left to right, top to bottom. The decoder and
|
||||
encoder start with {r: 0, g: 0, b: 0, a: 255} as the previous pixel value. An
|
||||
image is complete when all pixels specified by width * height have been covered.
|
||||
|
||||
Pixels are encoded as
|
||||
- a run of the previous pixel
|
||||
- an index t_i32o an array of previously seen pixels
|
||||
- a difference to the previous pixel value in r,g,b
|
||||
- full r,g,b or r,g,b,a values
|
||||
|
||||
The color channels are assumed to not be premultiplied with the alpha channel
|
||||
("un-premultiplied alpha").
|
||||
|
||||
A running array[64] (zero-initialized) of previously seen pixel values is
|
||||
mat_i32ained by the encoder and decoder. Each pixel that is seen by the encoder
|
||||
and decoder is put t_i32o this array at the position formed by a hash function
|
||||
of the color value. In the encoder, if the pixel value at the index matches the
|
||||
current pixel, this index position is written to the stream as QOI_OP_INDEX.
|
||||
The hash function for the index is:
|
||||
|
||||
index_position = (r * 3 + g * 5 + b * 7 + a * 11) % 64
|
||||
|
||||
Each chunk starts with a 2- or 8-bit tag, followed by a number of data bits. The
|
||||
bit length of chunks is divisible by 8 - i.e. all chunks are byte aligned. All
|
||||
values encoded in these data bits have the most significant bit on the left.
|
||||
|
||||
The 8-bit tags have precedence over the 2-bit tags. A decoder must check for the
|
||||
presence of an 8-bit tag first.
|
||||
|
||||
The byte stream's end is marked with 7 0x00 bytes followed a single 0x01 byte.
|
||||
|
||||
|
||||
The possible chunks are:
|
||||
|
||||
|
||||
.- QOI_OP_INDEX ----------.
|
||||
| Byte[0] |
|
||||
| 7 6 5 4 3 2 1 0 |
|
||||
|-------+-----------------|
|
||||
| 0 0 | index |
|
||||
`-------------------------`
|
||||
2-bit tag b00
|
||||
6-bit index t_i32o the color index array: 0..63
|
||||
|
||||
A valid encoder must not issue 2 or more consecutive QOI_OP_INDEX chunks to the
|
||||
same index. QOI_OP_RUN should be used instead.
|
||||
|
||||
|
||||
.- QOI_OP_DIFF -----------.
|
||||
| Byte[0] |
|
||||
| 7 6 5 4 3 2 1 0 |
|
||||
|-------+-----+-----+-----|
|
||||
| 0 1 | dr | dg | db |
|
||||
`-------------------------`
|
||||
2-bit tag b01
|
||||
2-bit red channel difference from the previous pixel between -2..1
|
||||
2-bit green channel difference from the previous pixel between -2..1
|
||||
2-bit blue channel difference from the previous pixel between -2..1
|
||||
|
||||
The difference to the current channel values are using a wraparound operation,
|
||||
so "1 - 2" will result in 255, while "255 + 1" will result in 0.
|
||||
|
||||
Values are stored as unsigned t_i32egers with a bias of 2. E.g. -2 is stored as
|
||||
0 (b00). 1 is stored as 3 (b11).
|
||||
|
||||
The alpha value remains unchanged from the previous pixel.
|
||||
|
||||
|
||||
.- QOI_OP_LUMA -------------------------------------.
|
||||
| Byte[0] | Byte[1] |
|
||||
| 7 6 5 4 3 2 1 0 | 7 6 5 4 3 2 1 0 |
|
||||
|-------+-----------------+-------------+-----------|
|
||||
| 1 0 | green diff | dr - dg | db - dg |
|
||||
`---------------------------------------------------`
|
||||
2-bit tag b10
|
||||
6-bit green channel difference from the previous pixel -32..31
|
||||
4-bit red channel difference minus green channel difference -8..7
|
||||
4-bit blue channel difference minus green channel difference -8..7
|
||||
|
||||
The green channel is used to indicate the general direction of change and is
|
||||
encoded in 6 bits. The red and blue channels (dr and db) base their diffs off
|
||||
of the green channel difference and are encoded in 4 bits. I.e.:
|
||||
dr_dg = (cur_px.r - prev_px.r) - (cur_px.g - prev_px.g)
|
||||
db_dg = (cur_px.b - prev_px.b) - (cur_px.g - prev_px.g)
|
||||
|
||||
The difference to the current channel values are using a wraparound operation,
|
||||
so "10 - 13" will result in 253, while "250 + 7" will result in 1.
|
||||
|
||||
Values are stored as unsigned t_i32egers with a bias of 32 for the green channel
|
||||
and a bias of 8 for the red and blue channel.
|
||||
|
||||
The alpha value remains unchanged from the previous pixel.
|
||||
|
||||
|
||||
.- QOI_OP_RUN ------------.
|
||||
| Byte[0] |
|
||||
| 7 6 5 4 3 2 1 0 |
|
||||
|-------+-----------------|
|
||||
| 1 1 | run |
|
||||
`-------------------------`
|
||||
2-bit tag b11
|
||||
6-bit run-length repeating the previous pixel: 1..62
|
||||
|
||||
The run-length is stored with a bias of -1. Note that the run-lengths 63 and 64
|
||||
(b111110 and b111111) are illegal as they are occupied by the QOI_OP_RGB and
|
||||
QOI_OP_RGBA tags.
|
||||
|
||||
|
||||
.- QOI_OP_RGB ------------------------------------------.
|
||||
| Byte[0] | Byte[1] | Byte[2] | Byte[3] |
|
||||
| 7 6 5 4 3 2 1 0 | 7 .. 0 | 7 .. 0 | 7 .. 0 |
|
||||
|-------------------------+---------+---------+---------|
|
||||
| 1 1 1 1 1 1 1 0 | red | green | blue |
|
||||
`-------------------------------------------------------`
|
||||
8-bit tag b11111110
|
||||
8-bit red channel value
|
||||
8-bit green channel value
|
||||
8-bit blue channel value
|
||||
|
||||
The alpha value remains unchanged from the previous pixel.
|
||||
|
||||
|
||||
.- QOI_OP_RGBA ---------------------------------------------------.
|
||||
| Byte[0] | Byte[1] | Byte[2] | Byte[3] | Byte[4] |
|
||||
| 7 6 5 4 3 2 1 0 | 7 .. 0 | 7 .. 0 | 7 .. 0 | 7 .. 0 |
|
||||
|-------------------------+---------+---------+---------+---------|
|
||||
| 1 1 1 1 1 1 1 1 | red | green | blue | alpha |
|
||||
`-----------------------------------------------------------------`
|
||||
8-bit tag b11111111
|
||||
8-bit red channel value
|
||||
8-bit green channel value
|
||||
8-bit blue channel value
|
||||
8-bit alpha channel value
|
||||
|
||||
*/
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
Header - Public functions */
|
||||
|
||||
#ifndef QOI_H
|
||||
# define QOI_H
|
||||
|
||||
# include "me/mem/mem_alloc.h"
|
||||
# include "me/mem/mem_set_zero.h"
|
||||
# include "me/types.h"
|
||||
/* A pot_i32er to a t_qoi_desc struct has to be supplied to all of qoi's
|
||||
functions. It describes either the input format (for qoi_write and qoi_encode),
|
||||
or is filled with the description read from the file header (for qoi_read and
|
||||
qoi_decode).
|
||||
|
||||
The colorspace in this t_qoi_desc is an enum where
|
||||
0 = sRGB, i.e. gamma scaled RGB channels and a linear alpha channel
|
||||
1 = all channels are linear
|
||||
You may use the constants QOI_SRGB or QOI_LINEAR. The colorspace is purely
|
||||
informative. It will be saved to the file header, but does not affect
|
||||
how chunks are en-/decoded. */
|
||||
|
||||
# define QOI_SRGB 0
|
||||
# define QOI_LINEAR 1
|
||||
|
||||
typedef struct s_t_qoi_desc
|
||||
{
|
||||
t_u32 width;
|
||||
t_u32 height;
|
||||
t_u8 channels;
|
||||
t_u8 colorspace;
|
||||
} t_qoi_desc;
|
||||
|
||||
# ifndef QOI_NO_STDIO
|
||||
|
||||
/* Encode raw RGB or RGBA pixels t_i32o a QOI image and write it to the file
|
||||
system. The t_qoi_desc struct must be filled with the image width, height,
|
||||
number of channels (3 = RGB, 4 = RGBA) and the colorspace.
|
||||
|
||||
The function returns 0 on failure (invalid parameters, or fopen or malloc
|
||||
failed) or the number of bytes written on success. */
|
||||
|
||||
t_i32 qoi_write(t_const_str filename, const void *data,
|
||||
const t_qoi_desc *desc);
|
||||
|
||||
/* Read and decode a QOI image from the file system. If channels is 0, the
|
||||
number of channels from the file header is used. If channels is 3 or 4 the
|
||||
output format will be forced t_i32o this number of channels.
|
||||
|
||||
The function either returns NULL on failure (invalid data, or malloc or fopen
|
||||
failed) or a pot_i32er to the decoded pixels. On success, the t_qoi_desc struct
|
||||
will be filled with the description from the file header.
|
||||
|
||||
The returned pixel data should be free()d after use. */
|
||||
|
||||
void *qoi_read(t_const_str filename, t_qoi_desc *desc,
|
||||
t_i32 channels);
|
||||
|
||||
# endif /* QOI_NO_STDIO */
|
||||
|
||||
/* Encode raw RGB or RGBA pixels t_i32o a QOI image in memory.
|
||||
|
||||
The function either returns NULL on failure (invalid parameters or malloc
|
||||
failed) or a pot_i32er to the encoded data on success. On success the out_len
|
||||
is set to the size in bytes of the encoded data.
|
||||
|
||||
The returned qoi data should be free()d after use. */
|
||||
|
||||
void *qoi_encode(const void *data, const t_qoi_desc *desc,
|
||||
t_i32 *out_len);
|
||||
|
||||
/* Decode a QOI image from memory.
|
||||
|
||||
The function either returns NULL on failure (invalid parameters or malloc
|
||||
failed) or a pot_i32er to the decoded pixels. On success, the t_qoi_desc struct
|
||||
is filled with the description from the file header.
|
||||
|
||||
The returned pixel data should be free()d after use. */
|
||||
|
||||
void *qoi_decode(const void *data, t_i32 size, t_qoi_desc *desc,
|
||||
t_i32 channels);
|
||||
|
||||
#endif /* QOI_H */
|
||||
86
include/me/img/qoi/qoi_decode.h
Normal file
86
include/me/img/qoi/qoi_decode.h
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* qoi_decode.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/25 22:33:19 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/25 22:58:27 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef QOI_DECODE_H
|
||||
# define QOI_DECODE_H
|
||||
|
||||
# include "me/img/qoi.h"
|
||||
# include "me/img/qoi/qoi_utils.h"
|
||||
|
||||
typedef struct s_decode_vals
|
||||
{
|
||||
t_i32 px_len;
|
||||
t_i32 chunks_len;
|
||||
t_i32 px_pos;
|
||||
t_i32 p;
|
||||
t_i32 run;
|
||||
t_i32 b1;
|
||||
t_i32 b2;
|
||||
t_i32 vg;
|
||||
t_u32 header_magic;
|
||||
t_qoi_rgba index[64];
|
||||
t_qoi_rgba px;
|
||||
|
||||
} t_decode_vals;
|
||||
|
||||
static inline void qoi_op_luma_decode(t_decode_vals *vals, const t_u8 *bytes)
|
||||
{
|
||||
vals->b2 = bytes[vals->p++];
|
||||
vals->vg = (vals->b1 & 0x3f) - 32;
|
||||
vals->px.rgba.r += vals->vg - 8 + ((vals->b2 >> 4) & 0x0f);
|
||||
vals->px.rgba.g += vals->vg;
|
||||
vals->px.rgba.b += vals->vg - 8 + (vals->b2 & 0x0f);
|
||||
}
|
||||
|
||||
static inline void qoi_op_diff_decode(t_decode_vals *vals, const t_u8 *bytes)
|
||||
{
|
||||
(void)(bytes);
|
||||
vals->px.rgba.r += ((vals->b1 >> 4) & 0x03) - 2;
|
||||
vals->px.rgba.g += ((vals->b1 >> 2) & 0x03) - 2;
|
||||
vals->px.rgba.b += (vals->b1 & 0x03) - 2;
|
||||
}
|
||||
|
||||
static inline void qoi_op_rgba_decode(t_decode_vals *vals, const t_u8 *bytes)
|
||||
{
|
||||
vals->px.rgba.r = bytes[vals->p++];
|
||||
vals->px.rgba.g = bytes[vals->p++];
|
||||
vals->px.rgba.b = bytes[vals->p++];
|
||||
vals->px.rgba.a = bytes[vals->p++];
|
||||
}
|
||||
|
||||
static inline void qoi_op_rgb_decode(t_decode_vals *vals, const t_u8 *bytes)
|
||||
{
|
||||
vals->px.rgba.r = bytes[vals->p++];
|
||||
vals->px.rgba.g = bytes[vals->p++];
|
||||
vals->px.rgba.b = bytes[vals->p++];
|
||||
}
|
||||
|
||||
static inline void qoi_decode_inner_inner(t_decode_vals *vals, \
|
||||
const t_u8 *bytes)
|
||||
{
|
||||
vals->b1 = bytes[vals->p++];
|
||||
if (vals->b1 == QOI_OP_RGB)
|
||||
qoi_op_rgb_decode(vals, bytes);
|
||||
else if (vals->b1 == QOI_OP_RGBA)
|
||||
qoi_op_rgba_decode(vals, bytes);
|
||||
else if ((vals->b1 & QOI_MASK_2) == QOI_OP_INDEX)
|
||||
vals->px = vals->index[vals->b1];
|
||||
else if ((vals->b1 & QOI_MASK_2) == QOI_OP_DIFF)
|
||||
qoi_op_diff_decode(vals, bytes);
|
||||
else if ((vals->b1 & QOI_MASK_2) == QOI_OP_LUMA)
|
||||
qoi_op_luma_decode(vals, bytes);
|
||||
else if ((vals->b1 & QOI_MASK_2) == QOI_OP_RUN)
|
||||
vals->run = (vals->b1 & 0x3f);
|
||||
vals->index[qoi_color_hash(vals->px) % 64] = vals->px;
|
||||
}
|
||||
|
||||
#endif /* QOI_DECODE_H */
|
||||
155
include/me/img/qoi/qoi_encode.h
Normal file
155
include/me/img/qoi/qoi_encode.h
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* qoi_encode.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/25 22:36:06 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/25 22:56:36 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef QOI_ENCODE_H
|
||||
# define QOI_ENCODE_H
|
||||
|
||||
# include "me/img/qoi.h"
|
||||
# include "me/img/qoi/qoi_utils.h"
|
||||
|
||||
typedef struct s_encode_vals
|
||||
{
|
||||
t_i32 i;
|
||||
t_i32 max_size;
|
||||
t_i32 p;
|
||||
t_i32 run;
|
||||
t_i32 px_len;
|
||||
t_i32 px_end;
|
||||
t_i32 px_pos;
|
||||
t_i32 channels;
|
||||
t_i32 index_pos;
|
||||
t_qoi_rgba index[64];
|
||||
t_qoi_rgba px;
|
||||
t_qoi_rgba px_prev;
|
||||
} t_encode_vals;
|
||||
|
||||
typedef struct s_v
|
||||
{
|
||||
t_i8 r;
|
||||
t_i8 g;
|
||||
t_i8 b;
|
||||
t_i8 g_r;
|
||||
t_i8 g_b;
|
||||
} t_v;
|
||||
|
||||
static inline void qoi_encode_if_thingy1(t_encode_vals *vals,
|
||||
t_v *v, t_u8 *bytes)
|
||||
{
|
||||
v->r = vals->px.rgba.r - vals->px_prev.rgba.r;
|
||||
v->g = vals->px.rgba.g - vals->px_prev.rgba.g;
|
||||
v->b = vals->px.rgba.b - vals->px_prev.rgba.b;
|
||||
v->g_r = v->r - v->g;
|
||||
v->g_b = v->b - v->g;
|
||||
if (v->r > -3 && v->r < 2 && v->g > -3 && v->g < 2 && v->b > -3
|
||||
&& v->b < 2)
|
||||
bytes[vals->p++] = QOI_OP_DIFF | (v->r + 2) << 4 | (v->g
|
||||
+ 2) << 2 | (v->b + 2);
|
||||
else if (v->g_r > -9 && v->g_r < 8 && v->g > -33 && v->g < 32
|
||||
&& v->g_b > -9 && v->g_b < 8)
|
||||
{
|
||||
bytes[vals->p++] = QOI_OP_LUMA | (v->g + 32);
|
||||
bytes[vals->p++] = (v->g_r + 8) << 4 | (v->g_b + 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
bytes[vals->p++] = QOI_OP_RGB;
|
||||
bytes[vals->p++] = vals->px.rgba.r;
|
||||
bytes[vals->p++] = vals->px.rgba.g;
|
||||
bytes[vals->p++] = vals->px.rgba.b;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void qoi_encode_inner_inner_inner(t_encode_vals *vals,
|
||||
t_v *v, t_u8 *bytes)
|
||||
{
|
||||
if (vals->run > 0)
|
||||
{
|
||||
bytes[vals->p++] = QOI_OP_RUN | (vals->run - 1);
|
||||
vals->run = 0;
|
||||
}
|
||||
vals->index_pos = qoi_color_hash(vals->px) % 64;
|
||||
if (vals->index[vals->index_pos].v == vals->px.v)
|
||||
bytes[vals->p++] = QOI_OP_INDEX | vals->index_pos;
|
||||
else
|
||||
{
|
||||
vals->index[vals->index_pos] = vals->px;
|
||||
if (vals->px.rgba.a == vals->px_prev.rgba.a)
|
||||
qoi_encode_if_thingy1(vals, v, bytes);
|
||||
else
|
||||
{
|
||||
bytes[vals->p++] = QOI_OP_RGBA;
|
||||
bytes[vals->p++] = vals->px.rgba.r;
|
||||
bytes[vals->p++] = vals->px.rgba.g;
|
||||
bytes[vals->p++] = vals->px.rgba.b;
|
||||
bytes[vals->p++] = vals->px.rgba.a;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline void qoi_encode_inner_inner(t_encode_vals *vals,
|
||||
const t_u8 *pixels, t_u8 *bytes)
|
||||
{
|
||||
t_v v;
|
||||
|
||||
v = (t_v){0};
|
||||
while (vals->px_pos < vals->px_len)
|
||||
{
|
||||
vals->px.rgba.r = pixels[vals->px_pos + 0];
|
||||
vals->px.rgba.g = pixels[vals->px_pos + 1];
|
||||
vals->px.rgba.b = pixels[vals->px_pos + 2];
|
||||
if (vals->channels == 4)
|
||||
vals->px.rgba.a = pixels[vals->px_pos + 3];
|
||||
if (vals->px.v == vals->px_prev.v)
|
||||
{
|
||||
vals->run++;
|
||||
if (vals->run == 62 || vals->px_pos == vals->px_end)
|
||||
{
|
||||
bytes[vals->p++] = QOI_OP_RUN | (vals->run - 1);
|
||||
vals->run = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
qoi_encode_inner_inner_inner(vals, &v, bytes);
|
||||
vals->px_prev = vals->px;
|
||||
vals->px_pos += vals->channels;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void *qoi_encode_inner(t_encode_vals *vals,
|
||||
const t_qoi_desc *desc,
|
||||
const t_u8 *pixels, t_i32 *out_len)
|
||||
{
|
||||
t_u8 *bytes;
|
||||
|
||||
bytes = (t_u8 *)mem_alloc(vals->max_size);
|
||||
if (!bytes)
|
||||
return (NULL);
|
||||
qoi_write_32(bytes, &vals->p, QOI_MAGIC);
|
||||
qoi_write_32(bytes, &vals->p, desc->width);
|
||||
qoi_write_32(bytes, &vals->p, desc->height);
|
||||
bytes[vals->p++] = desc->channels;
|
||||
bytes[vals->p++] = desc->colorspace;
|
||||
mem_set_zero(vals->index, sizeof(vals->index));
|
||||
vals->px_prev.rgba.a = 255;
|
||||
vals->px = vals->px_prev;
|
||||
vals->px_len = desc->width * desc->height * desc->channels;
|
||||
vals->px_end = vals->px_len - desc->channels;
|
||||
vals->channels = desc->channels;
|
||||
qoi_encode_inner_inner(vals, pixels, bytes);
|
||||
vals->i = 0;
|
||||
while (vals->i < (t_i32) sizeof(t_u8[8]))
|
||||
bytes[vals->p++] = ((t_u8[8]){0, 0, 0, 0, 0, 0, 0, 1})[vals->i++];
|
||||
*out_len = vals->p;
|
||||
return (bytes);
|
||||
}
|
||||
|
||||
#endif /* QOI_ENCODE_H */
|
||||
56
include/me/img/qoi/qoi_utils.h
Normal file
56
include/me/img/qoi/qoi_utils.h
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* qoi_utils.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/24 18:59:56 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/25 22:33:07 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef QOI_UTILS_H
|
||||
# define QOI_UTILS_H
|
||||
|
||||
# include "me/img/qoi.h"
|
||||
# include "me/types.h"
|
||||
|
||||
# define QOI_OP_INDEX 0x00 /* 00xxxxxx */
|
||||
# define QOI_OP_DIFF 0x40 /* 01xxxxxx */
|
||||
# define QOI_OP_LUMA 0x80 /* 10xxxxxx */
|
||||
# define QOI_OP_RUN 0xc0 /* 11xxxxxx */
|
||||
# define QOI_OP_RGB 0xfe /* 11111110 */
|
||||
# define QOI_OP_RGBA 0xff /* 11111111 */
|
||||
# define QOI_MASK_2 0xc0 /* 11000000 */
|
||||
# define QOI_MAGIC 0x716f6966u
|
||||
//(((t_u32)'q') << 24 | ((t_u32)'o') << 16 | ((t_u32)'i') << 8 | ((t_u32)'f'))
|
||||
# define QOI_HEADER_SIZE 14
|
||||
/* 2GB is the max file size that this implementation can safely handle. We guard
|
||||
against anything larger than that, assuming the worst case with 5 bytes per
|
||||
pixel, rounded down to a nice clean value. 400 million pixels ought to be
|
||||
enough for anybody. */
|
||||
# define QOI_PIXELS_MAX 400000000u
|
||||
|
||||
typedef union u_qoi_rgba
|
||||
{
|
||||
struct s_qoi_rgba
|
||||
{
|
||||
t_u8 r;
|
||||
t_u8 g;
|
||||
t_u8 b;
|
||||
t_u8 a;
|
||||
} rgba;
|
||||
t_u32 v;
|
||||
} t_qoi_rgba;
|
||||
|
||||
void qoi_write_32(t_u8 *bytes, t_i32 *p, t_u32 v);
|
||||
|
||||
t_u32 qoi_read_32(const t_u8 *bytes, t_i32 *p);
|
||||
|
||||
static inline t_u32 qoi_color_hash(t_qoi_rgba c)
|
||||
{
|
||||
return (c.rgba.r * 3 + c.rgba.g * 5 + c.rgba.b * 7 + c.rgba.a * 11);
|
||||
}
|
||||
|
||||
#endif /* QOI_UTILS_H */
|
||||
20
include/me/list/list_add_back.h
Normal file
20
include/me/list/list_add_back.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_add_back.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 20:38:45 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:27:56 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_ADD_BACK_H
|
||||
# define LIST_ADD_BACK_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void list_add_back(t_list **list, t_list *new);
|
||||
|
||||
#endif
|
||||
19
include/me/list/list_add_front.h
Normal file
19
include/me/list/list_add_front.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_add_front.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 20:15:23 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:28:15 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_ADD_FRONT_H
|
||||
# define LIST_ADD_FRONT_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void list_add_front(t_list **lst, t_list *new);
|
||||
#endif
|
||||
20
include/me/list/list_alloc_node.h
Normal file
20
include/me/list/list_alloc_node.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_alloc_node.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 19:57:28 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:28:30 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_ALLOC_NODE_H
|
||||
# define LIST_ALLOC_NODE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_list *list_alloc_node(void *content);
|
||||
|
||||
#endif
|
||||
20
include/me/list/list_free_all.h
Normal file
20
include/me/list/list_free_all.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_free_all.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 21:35:20 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:28:47 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_FREE_ALL_H
|
||||
# define LIST_FREE_ALL_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void list_free_all(t_list **lst, void (*del)(void *));
|
||||
|
||||
#endif
|
||||
20
include/me/list/list_free_one.h
Normal file
20
include/me/list/list_free_one.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_free_one.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 21:30:20 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:29:15 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_FREE_ONE_H
|
||||
# define LIST_FREE_ONE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void list_free_one(t_list *lst, void (*del)(void *));
|
||||
|
||||
#endif
|
||||
20
include/me/list/list_get_last.h
Normal file
20
include/me/list/list_get_last.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_get_last.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 20:37:08 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:29:37 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_GET_LAST_H
|
||||
# define LIST_GET_LAST_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_list *list_get_last(t_list *list);
|
||||
|
||||
#endif
|
||||
20
include/me/list/list_iter.h
Normal file
20
include/me/list/list_iter.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_iter.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 21:39:05 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:29:51 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_ITER_H
|
||||
# define LIST_ITER_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void list_iter(t_list *list, void (*f)(void *));
|
||||
|
||||
#endif
|
||||
20
include/me/list/list_map.h
Normal file
20
include/me/list/list_map.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_map.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 21:40:24 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:30:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_MAP_H
|
||||
# define LIST_MAP_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_list *list_map(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||
|
||||
#endif
|
||||
20
include/me/list/list_size.h
Normal file
20
include/me/list/list_size.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_size.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 20:23:19 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:30:23 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_SIZE_H
|
||||
# define LIST_SIZE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_usize list_size(t_list *lst);
|
||||
|
||||
#endif
|
||||
20
include/me/mem/mem_alloc.h
Normal file
20
include/me/mem/mem_alloc.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_alloc.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/06 14:47:49 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:41:31 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_ALLOC_H
|
||||
# define MEM_ALLOC_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void *mem_alloc(t_usize size);
|
||||
|
||||
#endif
|
||||
20
include/me/mem/mem_alloc_array.h
Normal file
20
include/me/mem/mem_alloc_array.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_alloc_array.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 15:53:21 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:19:45 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_ALLOC_ARRAY_H
|
||||
# define MEM_ALLOC_ARRAY_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void *mem_alloc_array(t_usize item_count, t_usize item_size);
|
||||
|
||||
#endif
|
||||
20
include/me/mem/mem_compare.h
Normal file
20
include/me/mem/mem_compare.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_compare.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:21:14 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_COMPARE_H
|
||||
# define MEM_COMPARE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_i32 mem_compare(const void *lhs, const void *rhs, t_usize count);
|
||||
|
||||
#endif
|
||||
20
include/me/mem/mem_copy.h
Normal file
20
include/me/mem/mem_copy.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_copy.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:21:31 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_COPY_H
|
||||
# define MEM_COPY_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void *mem_copy(void *destination, const void *source, t_usize count);
|
||||
|
||||
#endif
|
||||
20
include/me/mem/mem_find.h
Normal file
20
include/me/mem/mem_find.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_find.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:24:03 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_FIND_H
|
||||
# define MEM_FIND_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void *mem_find(void *buf, t_u8 find, t_usize count);
|
||||
|
||||
#endif
|
||||
21
include/me/mem/mem_find_bytes.h
Normal file
21
include/me/mem/mem_find_bytes.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_find_bytes.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/06 18:24:04 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_FIND_BYTES_H
|
||||
# define MEM_FIND_BYTES_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void *mem_find_bytes(void *buf, t_u8 *find, t_usize find_count,
|
||||
t_usize count);
|
||||
|
||||
#endif
|
||||
20
include/me/mem/mem_move.h
Normal file
20
include/me/mem/mem_move.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_move.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:24:26 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_MOVE_H
|
||||
# define MEM_MOVE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void *mem_move(void *destination, const void *source, t_usize count);
|
||||
|
||||
#endif
|
||||
20
include/me/mem/mem_set.h
Normal file
20
include/me/mem/mem_set.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_set.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:25:19 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_SET_H
|
||||
# define MEM_SET_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void mem_set(void *buf, t_u8 byte, t_usize count);
|
||||
|
||||
#endif
|
||||
20
include/me/mem/mem_set_zero.h
Normal file
20
include/me/mem/mem_set_zero.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_set_zero.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:58:11 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:24:51 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_SET_ZERO_H
|
||||
# define MEM_SET_ZERO_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void mem_set_zero(void *buf, t_usize count);
|
||||
|
||||
#endif
|
||||
21
include/me/num/u16.h
Normal file
21
include/me/num/u16.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* u16.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/11 14:10:03 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 14:16:58 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef U16_H
|
||||
# define U16_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_u16 u16_rotate_left(t_u16 n, t_usize by);
|
||||
t_u16 u16_rotate_right(t_u16 n, t_usize by);
|
||||
|
||||
#endif
|
||||
21
include/me/num/u32.h
Normal file
21
include/me/num/u32.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* u32.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/11 14:10:03 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 14:17:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef U32_H
|
||||
# define U32_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_u32 u32_rotate_left(t_u32 n, t_usize by);
|
||||
t_u32 u32_rotate_right(t_u32 n, t_usize by);
|
||||
|
||||
#endif
|
||||
24
include/me/num/u64.h
Normal file
24
include/me/num/u64.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* u64.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/11 14:10:03 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 17:59:34 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef U64_H
|
||||
# define U64_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_u64 u64_rotate_left(t_u64 n, t_usize by);
|
||||
t_u64 u64_rotate_right(t_u64 n, t_usize by);
|
||||
|
||||
t_u64 u64_from_7bytes(t_u8 *bytes, t_usize start, t_usize len);
|
||||
t_u64 u64_from_bytes(t_u8 *bytes, t_usize len);
|
||||
|
||||
#endif
|
||||
21
include/me/num/u8.h
Normal file
21
include/me/num/u8.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* u8.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/11 14:10:03 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 14:17:24 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef U8_H
|
||||
# define U8_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_u8 u8_rotate_left(t_u8 n, t_usize by);
|
||||
t_u8 u8_rotate_right(t_u8 n, t_usize by);
|
||||
|
||||
#endif
|
||||
21
include/me/num/usize.h
Normal file
21
include/me/num/usize.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* usize.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/11 14:10:03 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 14:17:32 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef USIZE_H
|
||||
# define USIZE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_usize usize_rotate_left(t_usize n, t_usize by);
|
||||
t_usize usize_rotate_right(t_usize n, t_usize by);
|
||||
|
||||
#endif
|
||||
27
include/me/printf/formatter/formatter.h
Normal file
27
include/me/printf/formatter/formatter.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* formatter.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/16 18:18:19 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/11/18 19:11:23 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FORMATTER_H
|
||||
# define FORMATTER_H
|
||||
# include "me/printf/printf.h"
|
||||
# include "me/types.h"
|
||||
|
||||
void printf_x_low(t_printf_arg data, t_printf_func f);
|
||||
void printf_x_up(t_printf_arg data, t_printf_func f);
|
||||
void printf_o(t_printf_arg data, t_printf_func f);
|
||||
void printf_d(t_printf_arg data, t_printf_func f);
|
||||
void printf_u(t_printf_arg data, t_printf_func f);
|
||||
void printf_c(t_printf_arg data, t_printf_func f);
|
||||
void printf_s(t_printf_arg data, t_printf_func f);
|
||||
void printf_p(t_printf_arg data, t_printf_func f);
|
||||
|
||||
#endif
|
||||
76
include/me/printf/formatter/utils.h
Normal file
76
include/me/printf/formatter/utils.h
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* utils.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/16 17:58:41 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/01 21:24:21 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef UTILS_H
|
||||
# define UTILS_H
|
||||
|
||||
# include "me/printf/matchers/matchers.h"
|
||||
# include "me/printf/printf.h"
|
||||
# include "me/types.h"
|
||||
# include <stdarg.h>
|
||||
|
||||
typedef struct s_prec_strs
|
||||
{
|
||||
t_str *out;
|
||||
t_str *pretty;
|
||||
bool free_out;
|
||||
} t_prec_strs;
|
||||
|
||||
typedef struct s_pad_and_stuff_args
|
||||
{
|
||||
t_usize fill_zero;
|
||||
t_usize fill;
|
||||
t_usize len;
|
||||
t_usize pretty_len;
|
||||
t_usize sign_len;
|
||||
t_str pretty;
|
||||
t_str str;
|
||||
t_str sign;
|
||||
bool allow_zero_fill;
|
||||
|
||||
} t_pad_and_stuff_args;
|
||||
typedef struct s_pad_inner_args
|
||||
{
|
||||
void *p_args;
|
||||
t_usize fmt_len;
|
||||
t_printf_func f;
|
||||
va_list *arguments;
|
||||
t_matcher_list *matchers;
|
||||
} t_pad_inner_args;
|
||||
|
||||
void set_var_for_pad_and_stuff(t_pad_and_stuff_args *a,
|
||||
t_printf_arg *d);
|
||||
void print_with_func(t_pad_and_stuff_args *a, t_printf_arg *d,
|
||||
t_printf_func f, t_const_str t);
|
||||
void pad_and_stuff(t_pad_and_stuff_args a, t_printf_arg d,
|
||||
t_printf_func f);
|
||||
void handle_prec_and_align(t_const_str fmt, t_usize *c_idx,
|
||||
t_printf_arg *c_arg);
|
||||
bool handle_atoi_stuff(t_const_str fmt, t_usize *c_idx,
|
||||
t_usize *nxt, t_printf_arg *c_arg);
|
||||
void set_params2(t_const_str fmt, t_usize *c_idx, t_usize *nxt,
|
||||
t_printf_arg *c_arg);
|
||||
bool set_params(t_const_str fmt, t_usize *c_idx, t_usize *nxt,
|
||||
t_printf_arg *c_arg);
|
||||
void ret_reset(t_usize *c_idx, t_usize *nxt, t_const_str fmt);
|
||||
t_printf_arg print_substr(t_usize *c_idx, t_usize *nxt, t_const_str fmt,
|
||||
t_pad_inner_args extra);
|
||||
void pad_inner(t_const_str fmt, t_usize *c_idx, t_usize *nxt,
|
||||
t_pad_inner_args extra);
|
||||
void advance_atoi(t_const_str fmt, t_usize *idx);
|
||||
void me_printf_str_inner(t_const_str fmt, t_printf_func f,
|
||||
va_list *arguments, void *p_args);
|
||||
void print_sign_if_needed(t_pad_and_stuff_args a, t_printf_arg d,
|
||||
t_printf_func f);
|
||||
void handle_weird_precision_stuff(t_printf_arg *data,
|
||||
t_prec_strs strs, t_usize value);
|
||||
#endif
|
||||
52
include/me/printf/matchers/matchers.h
Normal file
52
include/me/printf/matchers/matchers.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* matchers.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/16 18:09:07 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/11/18 18:10:33 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MATCHERS_H
|
||||
# define MATCHERS_H
|
||||
|
||||
# include "me/printf/printf.h"
|
||||
# include "me/types.h"
|
||||
# include <stdarg.h>
|
||||
# define PRINTF_BUFFER_CHUNK 20
|
||||
|
||||
typedef struct s_matcher_tmp
|
||||
{
|
||||
char chr_val;
|
||||
t_i64 i64_val;
|
||||
t_u64 u64_val;
|
||||
} t_matcher_tmp_val;
|
||||
|
||||
typedef void (*t_matcher_func)(t_printf_arg data,
|
||||
t_printf_func f);
|
||||
typedef struct s_matcher
|
||||
{
|
||||
t_const_str matcher;
|
||||
t_usize matcher_len;
|
||||
t_printf_type arg_type;
|
||||
t_matcher_func f;
|
||||
} t_matcher;
|
||||
|
||||
typedef struct s_matcher_list
|
||||
{
|
||||
t_matcher data[PRINTF_BUFFER_CHUNK];
|
||||
struct s_matcher_list *next;
|
||||
} t_matcher_list;
|
||||
|
||||
t_matcher_list *get_matchers(void);
|
||||
bool insert_matcher(t_matcher matcher);
|
||||
t_matcher *find_matcher(t_const_str fmt,
|
||||
t_matcher_list *matchers, t_usize *c_idx);
|
||||
void call_matcher(t_matcher *matcher,
|
||||
t_printf_arg matcher_arguments, va_list args,
|
||||
t_printf_func f);
|
||||
|
||||
#endif
|
||||
69
include/me/printf/printf.h
Normal file
69
include/me/printf/printf.h
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* printf.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/16 18:10:27 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/09 15:06:53 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PRINTF_H
|
||||
|
||||
# define PRINTF_H
|
||||
# include "me/types.h"
|
||||
# include <stdarg.h>
|
||||
|
||||
typedef struct s_fprintf_arg
|
||||
{
|
||||
t_usize total_print;
|
||||
t_file fd;
|
||||
} t_fprintf_arg;
|
||||
|
||||
typedef enum e_printf_flags
|
||||
{
|
||||
PRECISION = 1 << 1,
|
||||
ALIGN = 1 << 2,
|
||||
ZERO_ALIGN = 1 << 3,
|
||||
SIGN = 1 << 4,
|
||||
} t_printf_flags;
|
||||
|
||||
typedef enum e_printf_type
|
||||
{
|
||||
CHAR = 1 << 0,
|
||||
STR = 1 << 1,
|
||||
U64 = 1 << 2,
|
||||
I64 = 1 << 3,
|
||||
VOID_PTR = 1 << 4,
|
||||
I32 = 1 << 5,
|
||||
U32 = 1 << 6,
|
||||
} t_printf_type;
|
||||
|
||||
typedef struct s_printf_extra_args
|
||||
{
|
||||
t_u64 precision;
|
||||
t_u64 align;
|
||||
bool left_align;
|
||||
bool space_align;
|
||||
bool pretty;
|
||||
} t_printf_extra_args;
|
||||
|
||||
typedef struct s_printf_args
|
||||
{
|
||||
void *argument;
|
||||
void *p_args;
|
||||
t_printf_extra_args extra;
|
||||
t_printf_flags flags;
|
||||
} t_printf_arg;
|
||||
|
||||
typedef void (*t_printf_func)(t_const_str to_write,
|
||||
t_usize to_write_len, void *p_args);
|
||||
|
||||
t_usize me_printf(t_const_str fmt, ...);
|
||||
t_usize me_eprintf(t_const_str fmt, ...);
|
||||
t_usize me_vprintf(t_const_str fmt, va_list *args);
|
||||
t_usize me_veprintf(t_const_str fmt, va_list *args);
|
||||
|
||||
#endif
|
||||
20
include/me/string/str_clone.h
Normal file
20
include/me/string/str_clone.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_clone.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 16:05:48 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 17:30:19 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_CLONE_H
|
||||
# define STR_CLONE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_str str_clone(t_const_str source);
|
||||
|
||||
#endif
|
||||
20
include/me/string/str_find_chr.h
Normal file
20
include/me/string/str_find_chr.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_find_chr.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 17:29:13 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:07:01 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_FIND_CHR_H
|
||||
# define STR_FIND_CHR_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
char *str_find_chr(t_const_str str, char chr);
|
||||
|
||||
#endif
|
||||
20
include/me/string/str_find_rev_chr.h
Normal file
20
include/me/string/str_find_rev_chr.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_find_rev_chr.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 17:29:13 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:07:15 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_FIND_REV_CHR_H
|
||||
# define STR_FIND_REV_CHR_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
char *str_find_rev_chr(t_const_str str, char chr);
|
||||
|
||||
#endif
|
||||
20
include/me/string/str_find_str.h
Normal file
20
include/me/string/str_find_str.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_find_str.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/10 11:11:01 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:53:44 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_FIND_STR_H
|
||||
# define STR_FIND_STR_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
const char *str_find_str(t_const_str str, t_const_str to_find);
|
||||
|
||||
#endif
|
||||
20
include/me/string/str_iter.h
Normal file
20
include/me/string/str_iter.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_iter.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 18:26:00 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:08:09 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_ITER_H
|
||||
# define STR_ITER_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void str_iter(t_str s, void (*f)(t_usize, char *));
|
||||
|
||||
#endif
|
||||
20
include/me/string/str_join.h
Normal file
20
include/me/string/str_join.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_join.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 23:02:58 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:08:32 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_JOIN_H
|
||||
# define STR_JOIN_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_str str_join(t_const_str s1, t_const_str s2);
|
||||
|
||||
#endif
|
||||
20
include/me/string/str_l_cat.h
Normal file
20
include/me/string/str_l_cat.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_l_cat.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/09 18:01:09 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:09:07 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_L_CAT_H
|
||||
# define STR_L_CAT_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_usize str_l_cat(t_str dest, t_const_str src, t_usize buffer_size);
|
||||
|
||||
#endif
|
||||
20
include/me/string/str_l_copy.h
Normal file
20
include/me/string/str_l_copy.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_l_copy.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/09 18:01:09 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:09:38 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_L_COPY_H
|
||||
# define STR_L_COPY_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_usize str_l_copy(t_str dest, t_const_str src, t_usize buffer_size);
|
||||
|
||||
#endif
|
||||
20
include/me/string/str_len.h
Normal file
20
include/me/string/str_len.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_len.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 17:07:41 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 16:08:07 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_LEN_H
|
||||
# define STR_LEN_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_usize str_len(t_const_str str);
|
||||
|
||||
#endif
|
||||
20
include/me/string/str_map.h
Normal file
20
include/me/string/str_map.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_map.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 18:26:00 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:11:40 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_MAP_H
|
||||
# define STR_MAP_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_str str_map(t_const_str s, char (*f)(t_usize, char));
|
||||
|
||||
#endif
|
||||
20
include/me/string/str_n_compare.h
Normal file
20
include/me/string/str_n_compare.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_n_compare.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 18:53:47 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:17:14 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_N_COMPARE_H
|
||||
# define STR_N_COMPARE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_i32 str_n_compare(t_const_str lhs, t_const_str rhs, t_usize n);
|
||||
|
||||
#endif
|
||||
20
include/me/string/str_n_find_str.h
Normal file
20
include/me/string/str_n_find_str.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_n_find_str.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/10 11:11:01 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:53:35 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_N_FIND_STR_H
|
||||
# define STR_N_FIND_STR_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
const char *str_n_find_str(t_const_str str, t_const_str to_find, t_usize len);
|
||||
|
||||
#endif
|
||||
20
include/me/string/str_split.h
Normal file
20
include/me/string/str_split.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_split.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/17 15:56:59 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:18:07 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_SPLIT_H
|
||||
# define STR_SPLIT_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_str *str_split(t_const_str str, char chr);
|
||||
|
||||
#endif
|
||||
20
include/me/string/str_substring.h
Normal file
20
include/me/string/str_substring.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_substring.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 22:42:55 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:18:41 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_SUBSTRING_H
|
||||
# define STR_SUBSTRING_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_str str_substring(t_const_str str, t_usize start, t_usize len);
|
||||
|
||||
#endif
|
||||
20
include/me/string/str_trim.h
Normal file
20
include/me/string/str_trim.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_trim.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 23:43:42 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:19:11 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_TRIM_H
|
||||
# define STR_TRIM_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_str str_trim(t_const_str str, t_const_str charset);
|
||||
|
||||
#endif
|
||||
49
include/me/types.h
Normal file
49
include/me/types.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* types.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/03 14:31:12 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/05 00:08:41 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TYPES_H
|
||||
# define TYPES_H
|
||||
|
||||
# include <stdbool.h>
|
||||
# include <stddef.h>
|
||||
# include <unistd.h>
|
||||
|
||||
typedef char *t_str;
|
||||
typedef const char *t_const_str;
|
||||
|
||||
typedef unsigned char t_u8;
|
||||
typedef char t_i8;
|
||||
typedef unsigned short t_u16;
|
||||
typedef short t_i16;
|
||||
typedef int t_i32;
|
||||
typedef unsigned int t_u32;
|
||||
typedef unsigned long long t_u64;
|
||||
typedef long long t_i64;
|
||||
typedef ssize_t t_isize;
|
||||
typedef size_t t_usize;
|
||||
|
||||
typedef float t_f32;
|
||||
typedef double t_f64;
|
||||
|
||||
typedef int t_file;
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
typedef bool t_error;
|
||||
|
||||
# define ERROR 1
|
||||
# define NO_ERROR 0
|
||||
|
||||
#endif
|
||||
60
include/me/vec/vec_buf_str.h
Normal file
60
include/me/vec/vec_buf_str.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vec_buf_str.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/15 18:02:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef VEC_BUF_STR_H
|
||||
# define VEC_BUF_STR_H
|
||||
|
||||
# include "me/buffered_str/buf_str.h"
|
||||
# include "me/types.h"
|
||||
|
||||
typedef bool (*t_vec_buf_str_sort_fn)(t_buffer_str *,
|
||||
t_buffer_str *);
|
||||
typedef void (*t_free_buf_str_item)(t_buffer_str);
|
||||
|
||||
typedef struct s_vec_buf_str
|
||||
{
|
||||
t_free_buf_str_item free_func;
|
||||
t_usize len;
|
||||
t_usize capacity;
|
||||
t_buffer_str *buffer;
|
||||
} t_vec_buf_str;
|
||||
|
||||
t_vec_buf_str vec_buf_str_new(t_usize capacity,
|
||||
t_free_buf_str_item free_function);
|
||||
t_error vec_buf_str_push(t_vec_buf_str *vec,
|
||||
t_buffer_str element);
|
||||
t_error vec_buf_str_push_front(t_vec_buf_str *vec,
|
||||
t_buffer_str element);
|
||||
t_error vec_buf_str_pop(t_vec_buf_str *vec,
|
||||
t_buffer_str *value);
|
||||
t_error vec_buf_str_pop_front(t_vec_buf_str *vec,
|
||||
t_buffer_str *value);
|
||||
void vec_buf_str_free(t_vec_buf_str vec);
|
||||
t_error vec_buf_str_reserve(t_vec_buf_str *vec,
|
||||
t_usize wanted_capacity);
|
||||
t_error vec_buf_str_find(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_buffer_str *), t_usize *index);
|
||||
t_error vec_buf_str_find_starting(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_buffer_str *),
|
||||
t_usize starting_index, t_usize *index);
|
||||
t_error vec_buf_str_all(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_buffer_str *), bool *result);
|
||||
t_error vec_buf_str_any(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_buffer_str *), bool *result);
|
||||
void vec_buf_str_iter(t_vec_buf_str *vec,
|
||||
void (*fn)(t_usize index, t_buffer_str *value,
|
||||
void *state), void *state);
|
||||
void vec_buf_str_reverse(t_vec_buf_str *vec);
|
||||
void vec_buf_str_sort(t_vec_buf_str *vec,
|
||||
t_vec_buf_str_sort_fn is_sorted);
|
||||
|
||||
#endif
|
||||
51
include/me/vec/vec_i64.h
Normal file
51
include/me/vec/vec_i64.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vec_i64.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/15 18:02:14 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef VEC_I64_H
|
||||
# define VEC_I64_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
typedef bool (*t_vec_i64_sort_fn)(t_i64 *, t_i64 *);
|
||||
typedef void (*t_free_i64_item)(t_i64);
|
||||
|
||||
typedef struct s_vec_i64
|
||||
{
|
||||
t_free_i64_item free_func;
|
||||
t_usize len;
|
||||
t_usize capacity;
|
||||
t_i64 *buffer;
|
||||
} t_vec_i64;
|
||||
|
||||
t_vec_i64 vec_i64_new(t_usize capacity,
|
||||
t_free_i64_item free_function);
|
||||
t_error vec_i64_push(t_vec_i64 *vec, t_i64 element);
|
||||
t_error vec_i64_push_front(t_vec_i64 *vec, t_i64 element);
|
||||
t_error vec_i64_pop(t_vec_i64 *vec, t_i64 *value);
|
||||
t_error vec_i64_pop_front(t_vec_i64 *vec, t_i64 *value);
|
||||
void vec_i64_free(t_vec_i64 vec);
|
||||
t_error vec_i64_reserve(t_vec_i64 *vec, t_usize wanted_capacity);
|
||||
t_error vec_i64_find(t_vec_i64 *vec, bool (*fn)(const t_i64 *),
|
||||
t_usize *index);
|
||||
t_error vec_i64_find_starting(t_vec_i64 *vec,
|
||||
bool (*fn)(const t_i64 *), t_usize starting_index,
|
||||
t_usize *index);
|
||||
t_error vec_i64_all(t_vec_i64 *vec, bool (*fn)(const t_i64 *),
|
||||
bool *result);
|
||||
t_error vec_i64_any(t_vec_i64 *vec, bool (*fn)(const t_i64 *),
|
||||
bool *result);
|
||||
void vec_i64_iter(t_vec_i64 *vec, void (*fn)(t_usize index,
|
||||
t_i64 *value, void *state), void *state);
|
||||
void vec_i64_reverse(t_vec_i64 *vec);
|
||||
void vec_i64_sort(t_vec_i64 *vec, t_vec_i64_sort_fn is_sorted);
|
||||
|
||||
#endif
|
||||
60
include/me/vec/vec_i64_bool.h
Normal file
60
include/me/vec/vec_i64_bool.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vec_i64_bool.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/15 18:02:10 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef VEC_I64_BOOL_H
|
||||
# define VEC_I64_BOOL_H
|
||||
|
||||
# include "app/types/type_i64_bool.h"
|
||||
# include "me/types.h"
|
||||
|
||||
typedef bool (*t_vec_i64_bool_sort_fn)(t_i64_bool *,
|
||||
t_i64_bool *);
|
||||
typedef void (*t_free_i64_bool_item)(t_i64_bool);
|
||||
|
||||
typedef struct s_vec_i64_bool
|
||||
{
|
||||
t_free_i64_bool_item free_func;
|
||||
t_usize len;
|
||||
t_usize capacity;
|
||||
t_i64_bool *buffer;
|
||||
} t_vec_i64_bool;
|
||||
|
||||
t_vec_i64_bool vec_i64_bool_new(t_usize capacity,
|
||||
t_free_i64_bool_item free_function);
|
||||
t_error vec_i64_bool_push(t_vec_i64_bool *vec,
|
||||
t_i64_bool element);
|
||||
t_error vec_i64_bool_push_front(t_vec_i64_bool *vec,
|
||||
t_i64_bool element);
|
||||
t_error vec_i64_bool_pop(t_vec_i64_bool *vec,
|
||||
t_i64_bool *value);
|
||||
t_error vec_i64_bool_pop_front(t_vec_i64_bool *vec,
|
||||
t_i64_bool *value);
|
||||
void vec_i64_bool_free(t_vec_i64_bool vec);
|
||||
t_error vec_i64_bool_reserve(t_vec_i64_bool *vec,
|
||||
t_usize wanted_capacity);
|
||||
t_error vec_i64_bool_find(t_vec_i64_bool *vec,
|
||||
bool (*fn)(const t_i64_bool *), t_usize *index);
|
||||
t_error vec_i64_bool_find_starting(t_vec_i64_bool *vec,
|
||||
bool (*fn)(const t_i64_bool *),
|
||||
t_usize starting_index, t_usize *index);
|
||||
t_error vec_i64_bool_all(t_vec_i64_bool *vec,
|
||||
bool (*fn)(const t_i64_bool *), bool *result);
|
||||
t_error vec_i64_bool_any(t_vec_i64_bool *vec,
|
||||
bool (*fn)(const t_i64_bool *), bool *result);
|
||||
void vec_i64_bool_iter(t_vec_i64_bool *vec,
|
||||
void (*fn)(t_usize index, t_i64_bool *value,
|
||||
void *state), void *state);
|
||||
void vec_i64_bool_reverse(t_vec_i64_bool *vec);
|
||||
void vec_i64_bool_sort(t_vec_i64_bool *vec,
|
||||
t_vec_i64_bool_sort_fn is_sorted);
|
||||
|
||||
#endif
|
||||
50
include/me/vec/vec_u8.h
Normal file
50
include/me/vec/vec_u8.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vec_u8.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/15 18:02:19 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef VEC_U8_H
|
||||
# define VEC_U8_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
typedef bool (*t_vec_u8_sort_fn)(t_u8 *, t_u8 *);
|
||||
typedef void (*t_free_u8_item)(t_u8);
|
||||
|
||||
typedef struct s_vec_u8
|
||||
{
|
||||
t_free_u8_item free_func;
|
||||
t_usize len;
|
||||
t_usize capacity;
|
||||
t_u8 *buffer;
|
||||
} t_vec_u8;
|
||||
|
||||
t_vec_u8 vec_u8_new(t_usize capacity, t_free_u8_item free_function);
|
||||
t_error vec_u8_push(t_vec_u8 *vec, t_u8 element);
|
||||
t_error vec_u8_push_front(t_vec_u8 *vec, t_u8 element);
|
||||
t_error vec_u8_pop(t_vec_u8 *vec, t_u8 *value);
|
||||
t_error vec_u8_pop_front(t_vec_u8 *vec, t_u8 *value);
|
||||
void vec_u8_free(t_vec_u8 vec);
|
||||
t_error vec_u8_reserve(t_vec_u8 *vec, t_usize wanted_capacity);
|
||||
t_error vec_u8_find(t_vec_u8 *vec, bool (*fn)(const t_u8 *),
|
||||
t_usize *index);
|
||||
t_error vec_u8_find_starting(t_vec_u8 *vec,
|
||||
bool (*fn)(const t_u8 *), t_usize starting_index,
|
||||
t_usize *index);
|
||||
t_error vec_u8_all(t_vec_u8 *vec, bool (*fn)(const t_u8 *),
|
||||
bool *result);
|
||||
t_error vec_u8_any(t_vec_u8 *vec, bool (*fn)(const t_u8 *),
|
||||
bool *result);
|
||||
void vec_u8_iter(t_vec_u8 *vec, void (*fn)(t_usize index,
|
||||
t_u8 *value, void *state), void *state);
|
||||
void vec_u8_reverse(t_vec_u8 *vec);
|
||||
void vec_u8_sort(t_vec_u8 *vec, t_vec_u8_sort_fn is_sorted);
|
||||
|
||||
#endif
|
||||
60
include/me/vec2/vec2.h
Normal file
60
include/me/vec2/vec2.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vec2.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/31 14:54:39 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/31 15:07:54 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef VEC2_H
|
||||
# define VEC2_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
typedef struct s_vi2d
|
||||
{
|
||||
t_i32 x;
|
||||
t_i32 y;
|
||||
} t_vi2d;
|
||||
|
||||
typedef struct s_vu2d
|
||||
{
|
||||
t_u32 x;
|
||||
t_u32 y;
|
||||
} t_vu2d;
|
||||
|
||||
typedef struct s_vf2d
|
||||
{
|
||||
t_f32 x;
|
||||
t_f32 y;
|
||||
} t_vf2d;
|
||||
|
||||
static inline t_vf2d vf2d(t_f32 x, t_f32 y)
|
||||
{
|
||||
return ((t_vf2d){.x = x, .y = y});
|
||||
}
|
||||
|
||||
static inline t_vi2d vi2d(t_i32 x, t_i32 y)
|
||||
{
|
||||
return ((t_vi2d){.x = x, .y = y});
|
||||
}
|
||||
|
||||
static inline t_vu2d vu2d(t_u32 x, t_u32 y)
|
||||
{
|
||||
return ((t_vu2d){.x = x, .y = y});
|
||||
}
|
||||
|
||||
static inline t_vi2d vi2d_add(t_vi2d lhs, t_vi2d rhs)
|
||||
{
|
||||
return ((t_vi2d){.x = lhs.x + rhs.x, .y = lhs.y + rhs.y});
|
||||
}
|
||||
|
||||
static inline t_vi2d vi2d_sub(t_vi2d lhs, t_vi2d rhs)
|
||||
{
|
||||
return ((t_vi2d){.x = lhs.x - rhs.x, .y = lhs.y - rhs.y});
|
||||
}
|
||||
#endif /* VEC2_H */
|
||||
26
src/app/actual_main.c
Normal file
26
src/app/actual_main.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* actual_main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/09 15:10:39 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/09 15:26:33 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "app/state.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include "me/string/str_n_compare.h"
|
||||
#include "me/types.h"
|
||||
|
||||
int main_normal(t_i32 argc, t_str argv[]);
|
||||
int main_checker(t_i32 argc, t_str argv[]);
|
||||
|
||||
int main(t_i32 argc, t_str argv[])
|
||||
{
|
||||
if (BONUS)
|
||||
return (main_checker(argc, argv));
|
||||
return (main_normal(argc, argv));
|
||||
}
|
||||
77
src/app/best_index_to_move.c
Normal file
77
src/app/best_index_to_move.c
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* best_index_to_move.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/08 14:14:54 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/08 14:21:51 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "app/best_index_to_move.h"
|
||||
#include "app/best_move.h"
|
||||
#include "app/find_iter.h"
|
||||
#include "app/rotate.h"
|
||||
#include "app/state.h"
|
||||
#include "app/target.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_i64.h"
|
||||
#include "me/vec/vec_i64_bool.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static void inc(void *s)
|
||||
{
|
||||
t_usize *p;
|
||||
|
||||
p = (t_usize *)s;
|
||||
*p += 1;
|
||||
}
|
||||
|
||||
static inline t_usize count_move_for_index(struct s_best_index_to_move d)
|
||||
{
|
||||
t_usize tmp;
|
||||
|
||||
tmp = 0;
|
||||
run_func_with_best_rotate_for_item(d.state,
|
||||
(t_best_move_args){
|
||||
.index = d.i,
|
||||
.args = &tmp,
|
||||
.iter_func = d.f,
|
||||
.from = d.from,
|
||||
.to = d.to,
|
||||
.other = {inc, inc},
|
||||
.main = {inc, inc},
|
||||
.both = {inc, inc},
|
||||
});
|
||||
return (tmp);
|
||||
}
|
||||
|
||||
t_usize best_index_to_move(t_state *state, t_vec_i64 *from, t_vec_i64 *to,
|
||||
t_iter_pos_func f)
|
||||
{
|
||||
t_usize min_val;
|
||||
t_usize min_pos;
|
||||
t_usize i;
|
||||
t_usize tmp;
|
||||
|
||||
if (from->len == 0)
|
||||
return (0);
|
||||
i = 0;
|
||||
min_val = ~0;
|
||||
min_pos = 0;
|
||||
while (i < from->len)
|
||||
{
|
||||
tmp = count_move_for_index((struct s_best_index_to_move){state, from,
|
||||
to, f, i});
|
||||
if (tmp < min_val)
|
||||
{
|
||||
min_val = tmp;
|
||||
min_pos = i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (min_pos);
|
||||
}
|
||||
99
src/app/best_move.c
Normal file
99
src/app/best_move.c
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* best_move.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 20:04:33 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/08 14:22:55 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "app/best_move.h"
|
||||
#include "app/best_move_inner.h"
|
||||
#include "app/find_iter.h"
|
||||
#include "app/find_place.h"
|
||||
#include "app/rotate.h"
|
||||
#include "app/state.h"
|
||||
#include "app/target.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_i64.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static inline t_isize move_count(t_rotation lhs, t_rotation rhs)
|
||||
{
|
||||
if (lhs.direction == rhs.direction)
|
||||
return (max(lhs.value, rhs.value));
|
||||
else
|
||||
return (abs_diff(lhs.value, rhs.value));
|
||||
}
|
||||
|
||||
void find_least_move(t_rotation *main, t_rotation *other)
|
||||
{
|
||||
t_isize main_fliped;
|
||||
t_isize other_fliped;
|
||||
t_isize none_fliped;
|
||||
t_rotation tmp;
|
||||
t_isize minimum;
|
||||
|
||||
none_fliped = move_count(*main, *other);
|
||||
main_fliped = move_count(flip(*main), *other);
|
||||
other_fliped = move_count(*main, flip(*other));
|
||||
minimum = min(none_fliped, min(main_fliped, other_fliped));
|
||||
if (minimum == none_fliped)
|
||||
return ;
|
||||
else if (minimum == main_fliped)
|
||||
{
|
||||
tmp = flip(*main);
|
||||
*main = tmp;
|
||||
}
|
||||
else if (minimum == other_fliped)
|
||||
{
|
||||
tmp = flip(*other);
|
||||
*other = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void func(t_best_move_args *data, t_rotation *main,
|
||||
t_rotation *other)
|
||||
{
|
||||
t_isize i;
|
||||
|
||||
i = 0;
|
||||
while (i++ < min(main->value, other->value))
|
||||
choose_func(&data->both, *main)(data->args);
|
||||
i = 0;
|
||||
if (main->value > other->value)
|
||||
while (i++ < main->value - other->value)
|
||||
choose_func(&data->main, *main)(data->args);
|
||||
else
|
||||
while (i++ < other->value - main->value)
|
||||
choose_func(&data->other, *other)(data->args);
|
||||
}
|
||||
|
||||
void run_func_with_best_rotate_for_item(t_state *state,
|
||||
t_best_move_args data)
|
||||
{
|
||||
t_isize target_index;
|
||||
t_rotation main;
|
||||
t_rotation other;
|
||||
t_isize i;
|
||||
|
||||
target_index = (find_place(data.from->buffer[data.index], state)
|
||||
+ (data.to->len - data.iter_func(data.to))) % max(data.to->len, 1);
|
||||
main = target(0, data.index, data.from->len);
|
||||
other = target(target_index, 0, data.to->len);
|
||||
find_least_move(&main, &other);
|
||||
if (main.direction == other.direction)
|
||||
func(&data, &main, &other);
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
while (i++ < main.value)
|
||||
choose_func(&data.main, main)(data.args);
|
||||
i = 0;
|
||||
while (i++ < other.value)
|
||||
choose_func(&data.other, other)(data.args);
|
||||
}
|
||||
}
|
||||
29
src/app/do_move.c
Normal file
29
src/app/do_move.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* do_move.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/31 14:25:57 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/02 22:54:12 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "app/best_move.h"
|
||||
#include "app/moves.h"
|
||||
#include "app/state.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_i64.h"
|
||||
|
||||
void push_a(void *s);
|
||||
void push_b(void *s);
|
||||
void swap_a(void *s);
|
||||
void swap_b(void *s);
|
||||
void swap_both(void *s);
|
||||
void rotate_a(void *s);
|
||||
void rotate_b(void *s);
|
||||
void rotate_both(void *s);
|
||||
void rev_rotate_a(void *s);
|
||||
void rev_rotate_b(void *s);
|
||||
void rev_rotate_both(void *s);
|
||||
52
src/app/find_place.c
Normal file
52
src/app/find_place.c
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* find_place.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 22:01:12 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/08 14:06:05 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "app/find_place.h"
|
||||
#include "app/types/type_i64_bool.h"
|
||||
#include "me/vec/vec_i64_bool.h"
|
||||
|
||||
static void find_place_iter(t_usize index, t_i64_bool *elem,
|
||||
t_find_place_iter_state *state)
|
||||
{
|
||||
(void)(index);
|
||||
if (!(elem->active || elem->value == state->to_find_elem))
|
||||
return ;
|
||||
if (elem->value == state->to_find_elem)
|
||||
state->found_index = state->current_index;
|
||||
state->current_index++;
|
||||
}
|
||||
|
||||
t_usize find_place(t_i64 elem, t_state *state)
|
||||
{
|
||||
t_find_place_iter_state iter_state;
|
||||
|
||||
iter_state.current_index = 0;
|
||||
iter_state.found_index = 0;
|
||||
iter_state.to_find_elem = elem;
|
||||
vec_i64_bool_iter(&state->sorted, (void (*)())find_place_iter, &iter_state);
|
||||
return (iter_state.found_index);
|
||||
}
|
||||
|
||||
/*
|
||||
state
|
||||
.sorted
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|&(e, active)| active || elem == e)
|
||||
.enumerate()
|
||||
.find(|(_, (e, _))| *e == elem)
|
||||
.map(|(i, _)| i)
|
||||
.unwrap_or_else(|| {
|
||||
println!("why...");
|
||||
0
|
||||
})
|
||||
*/
|
||||
57
src/app/iter_find.c
Normal file
57
src/app/iter_find.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* iter_find.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/31 14:17:53 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/31 14:23:26 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "app/iter_state.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_i64.h"
|
||||
|
||||
static void iter_min(t_usize index, t_i64 *elem, t_iter_state *state)
|
||||
{
|
||||
if (*elem < state->elem)
|
||||
{
|
||||
state->elem = *elem;
|
||||
state->pos = index;
|
||||
}
|
||||
}
|
||||
|
||||
static void iter_max(t_usize index, t_i64 *elem, t_iter_state *state)
|
||||
{
|
||||
if (*elem > state->elem)
|
||||
{
|
||||
state->elem = *elem;
|
||||
state->pos = index;
|
||||
}
|
||||
}
|
||||
|
||||
t_usize min_iter_zero_pos(t_vec_i64 *vec)
|
||||
{
|
||||
t_iter_state state;
|
||||
|
||||
if (vec->len == 0)
|
||||
return (0);
|
||||
state.pos = 0;
|
||||
state.elem = vec->buffer[0];
|
||||
vec_i64_iter(vec, (void (*)())iter_min, &state);
|
||||
return (state.pos);
|
||||
}
|
||||
|
||||
t_usize max_iter_zero_pos(t_vec_i64 *vec)
|
||||
{
|
||||
t_iter_state state;
|
||||
|
||||
if (vec->len == 0)
|
||||
return (0);
|
||||
state.pos = 0;
|
||||
state.elem = vec->buffer[0];
|
||||
vec_i64_iter(vec, (void (*)())iter_max, &state);
|
||||
return (state.pos);
|
||||
}
|
||||
64
src/app/main.c
Normal file
64
src/app/main.c
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/01 21:00:12 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/15 17:42:03 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "app/state.h"
|
||||
#include "app/types/type_i64_bool.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include "me/string/str_n_compare.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_i64.h"
|
||||
#include "me/vec/vec_i64_bool.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if BONUS == 1
|
||||
|
||||
# define ERR_INVALID_NUM "Error\n"
|
||||
# define ERR_DUPLICATE "Error\n"
|
||||
|
||||
#else
|
||||
|
||||
//# define ERR_INVALID_NUM "Error:\nInvalid Number\n"
|
||||
//# define ERR_DUPLICATE "Error:\nDuplicate Number\n"
|
||||
# define ERR_INVALID_NUM "Error\n"
|
||||
# define ERR_DUPLICATE "Error\n"
|
||||
|
||||
#endif
|
||||
|
||||
void sort_3(t_state *state);
|
||||
void sort_2(t_state *state);
|
||||
void sort_5(t_state *state);
|
||||
bool is_sorted(t_vec_i64 *v);
|
||||
void run_with_items(t_state *state);
|
||||
|
||||
int main_normal(t_i32 argc, t_str argv[])
|
||||
{
|
||||
t_state state;
|
||||
|
||||
(void)(argc--, argv++);
|
||||
state = parses_arguments(argc, argv);
|
||||
if (is_sorted(&state.stack_a))
|
||||
return (free_state(state), 0);
|
||||
if (state.stack_a.len == 0)
|
||||
(free_state(state), exit(0));
|
||||
else if (state.stack_a.len == 2)
|
||||
sort_2(&state);
|
||||
else if (state.stack_a.len == 3)
|
||||
sort_3(&state);
|
||||
else if (state.stack_a.len == 5)
|
||||
sort_5(&state);
|
||||
else
|
||||
run_with_items(&state);
|
||||
free_state(state);
|
||||
return (0);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue