-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Moser
committed
Jan 19, 2024
0 parents
commit 743dfb2
Showing
71 changed files
with
3,922 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# **************************************************************************** # | ||
# # | ||
# ::: :::::::: # | ||
# Makefile :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: mmoser <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2024/01/04 14:37:27 by mmoser #+# #+# # | ||
# Updated: 2024/01/19 16:14:54 by mmoser ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
NAME := push_swap | ||
B_NAME := checker | ||
|
||
LIBS := ft | ||
LIBS_TARGET := libft/libft.a | ||
|
||
CC := cc | ||
CFLAGS := -Wall -Werror -Wextra -g | ||
LINKFLAGS := $(addprefix -L ,$(dir $(LIBS_TARGET))) $(addprefix -l ,$(LIBS)) | ||
RM := rm -rf | ||
|
||
SRC_DIR := src | ||
BUILD_DIR := .build | ||
|
||
# ---------------------------------------------------------------------------- # | ||
PS_DIR := push_swap | ||
CO_DIR := common | ||
CH_DIR := checker | ||
# ---------------------------------------------------------------------------- # | ||
PS_SRCS := main.c sort_alg1.c sort_alg2.c sort_alg3.c | ||
CO_SRCS := parsing.c lst_ops1.c lst_ops2.c helper_foos1.c helper_foos2.c \ | ||
sort_ops1.c sort_ops2.c sort_ops3.c | ||
CH_SRCS := main.c parse_and_check.c | ||
# ---------------------------------------------------------------------------- # | ||
PS_SRCS := $(PS_SRCS:%=$(SRC_DIR)/$(PS_DIR)/%) | ||
CO_SRCS := $(CO_SRCS:%=$(SRC_DIR)/$(CO_DIR)/%) | ||
CH_SRCS := $(CH_SRCS:%=$(SRC_DIR)/$(CH_DIR)/%) | ||
# ---------------------------------------------------------------------------- # | ||
PS_OBJS := $(PS_SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o) | ||
CO_OBJS := $(CO_SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o) | ||
CH_OBJS := $(CH_SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o) | ||
# ---------------------------------------------------------------------------- # | ||
|
||
all: $(NAME) | ||
|
||
bonus: $(B_NAME) | ||
|
||
$(NAME): $(PS_OBJS) $(CO_OBJS) $(LIBS_TARGET) | ||
@printf "\n" | ||
$(CC) $(PS_OBJS) $(CO_OBJS) $(LINKFLAGS) -o $(NAME) | ||
@printf "$(CREATED)" $@ $(CUR_DIR) | ||
|
||
$(B_NAME): $(CH_OBJS) $(CO_OBJS) $(LIBS_TARGET) | ||
$(CC) $(CH_OBJS) $(CO_OBJS) $(LINKFLAGS) -o $(B_NAME) | ||
@printf "$(CREATED)" $@ $(CUR_DIR) | ||
|
||
%.a: | ||
$(MAKE) -C $(@D) | ||
|
||
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | ||
@mkdir -p $(@D) | ||
$(CC) $(CFLAGS) -c $< -o $@ | ||
|
||
clean: | ||
$(MAKE) -C $(dir $(LIBS_TARGET)) clean | ||
$(RM) $(BUILD_DIR) | ||
@printf "$(REMOVED)" $(BUILD_DIR) $(CUR_DIR) | ||
|
||
fclean: clean | ||
$(MAKE) -C $(dir $(LIBS_TARGET)) fclean | ||
$(RM) $(NAME) $(B_NAME) | ||
@printf "$(REMOVED)" $(NAME) $(CUR_DIR) | ||
@printf "$(REMOVED)" $(B_NAME) $(CUR_DIR) | ||
|
||
re: | ||
$(MAKE) fclean | ||
$(MAKE) all | ||
|
||
info-%: | ||
$(MAKE) --dry-run --always-make $* | ||
|
||
print-%: | ||
$(info $($*)) | ||
|
||
re: clean fclean re | ||
|
||
# ----------------------------------- colors --------------------------------- # | ||
|
||
BOLD := \033[1m | ||
BLACK := \033[30;1m | ||
RED := \033[31;1m | ||
GREEN := \033[32;1m | ||
YELLOW := \033[33;1m | ||
BLUE := \033[34;1m | ||
MAGENTA := \033[35;1m | ||
CYAN := \033[36;1m | ||
WHITE := \033[37;1m | ||
RESET := \033[0m | ||
|
||
# ----------------------------------- messages ------------------------------- # | ||
|
||
CUR_DIR := $(dir $(abspath $(firstword $(MAKEFILE_LIST)))) | ||
REMOVED := $(MAGENTA) $(BOLD) REMOVED %s (%s) $(RESET)\n\n | ||
CREATED := $(GREEN) $(BOLD) CREATED %s (%s) $(RESET)\n\n | ||
UPDATED := $(GREEN) $(BOLD) CREATED OR UPDATED %s (%s) $(RESET)\n\n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# **************************************************************************** # | ||
# # | ||
# ::: :::::::: # | ||
# Makefile :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: mmoser <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2024/01/03 11:22:08 by mmoser #+# #+# # | ||
# Updated: 2024/01/03 11:57:11 by mmoser ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
NAME := libft.a | ||
|
||
CC := cc | ||
CFLAGS := -Wall -Werror -Wextra -g | ||
RM := rm -rf | ||
|
||
SRC_DIR := src | ||
BUILD_DIR := .build | ||
|
||
# ---------------------------------------------------------------------------- # | ||
LIBFT_DIR := libft | ||
PF_DIR := ft_printf | ||
GNL_DIR := get_next_line | ||
# ---------------------------------------------------------------------------- # | ||
LIBFT_SRCS := ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c \ | ||
ft_strlen.c ft_memset.c ft_bzero.c ft_memcpy.c ft_memmove.c \ | ||
ft_strlcpy.c ft_strlcat.c ft_toupper.c ft_tolower.c ft_strchr.c \ | ||
ft_strrchr.c ft_strncmp.c ft_memchr.c ft_memcmp.c ft_strnstr.c \ | ||
ft_atoi.c ft_calloc.c ft_strdup.c ft_substr.c ft_strjoin.c \ | ||
ft_strtrim.c ft_split.c ft_itoa.c ft_strmapi.c ft_striteri.c \ | ||
ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c | ||
PF_SRCS := ft_printf.c ft_flags.c ft_output.c ft_numconv.c | ||
GNL_SRCS := get_next_line.c get_next_line_utils.c | ||
# ---------------------------------------------------------------------------- # | ||
LIBFT_SRCS := $(LIBFT_SRCS:%=$(SRC_DIR)/$(LIBFT_DIR)/%) | ||
PF_SRCS := $(PF_SRCS:%=$(SRC_DIR)/$(PF_DIR)/%) | ||
GNL_SRCS := $(GNL_SRCS:%=$(SRC_DIR)/$(GNL_DIR)/%) | ||
# ---------------------------------------------------------------------------- # | ||
LIBFT_OBJS := $(LIBFT_SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o) | ||
PF_OBJS := $(PF_SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o) | ||
GNL_OBJS := $(GNL_SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o) | ||
# ---------------------------------------------------------------------------- # | ||
|
||
all: $(NAME) | ||
|
||
$(NAME): $(LIBFT_OBJS) $(PF_OBJS) $(GNL_OBJS) | ||
@printf "\n" | ||
ar rcs $@ $^ | ||
@printf "$(CREATED)" $(NAME) $(CUR_DIR) | ||
|
||
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | ||
@mkdir -p $(@D) | ||
$(CC) $(CFLAGS) -c $< -o $@ | ||
|
||
clean: | ||
$(RM) $(BUILD_DIR) | ||
@printf "$(REMOVED)" $(BUILD_DIR) $(CUR_DIR) | ||
|
||
fclean: clean | ||
$(RM) $(NAME) | ||
@printf "$(REMOVED)" $(NAME) $(CUR_DIR) | ||
|
||
re: | ||
$(MAKE) fclean | ||
$(MAKE) all | ||
|
||
info-%: | ||
$(MAKE) --dry-run --always-make $* | ||
|
||
print-%: | ||
$(info $($*)) | ||
|
||
.PHONY: clean fclean re | ||
|
||
# ----------------------------------- colors --------------------------------- # | ||
|
||
BOLD := \033[1m | ||
BLACK := \033[30;1m | ||
RED := \033[31;1m | ||
GREEN := \033[32;1m | ||
YELLOW := \033[33;1m | ||
BLUE := \033[34;1m | ||
MAGENTA := \033[35;1m | ||
CYAN := \033[36;1m | ||
WHITE := \033[37;1m | ||
RESET := \033[0m | ||
|
||
# ----------------------------------- messages ------------------------------- # | ||
|
||
CUR_DIR := $(dir $(abspath $(firstword $(MAKEFILE_LIST)))) | ||
REMOVED := $(MAGENTA) $(BOLD) REMOVED %s (%s) $(RESET)\n\n | ||
CREATED := $(GREEN) $(BOLD) CREATED %s (%s) $(RESET)\n\n | ||
UPDATED := $(GREEN) $(BOLD) CREATED OR UPDATED %s (%s) $(RESET)\n\n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* :::::::: */ | ||
/* ft_flags.c :+: :+: */ | ||
/* +:+ */ | ||
/* By: mmoser <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2023/11/23 16:04:03 by mmoser #+# #+# */ | ||
/* Updated: 2023/11/29 10:46:06 by mmoser ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "ft_printf.h" | ||
|
||
void solve_flag_conflicts(t_arg *fdetails) | ||
{ | ||
if (fdetails->prec < 0) | ||
fdetails->dot = false; | ||
if (fdetails->zero == true && fdetails->dash == true) | ||
fdetails->zero = false; | ||
if (fdetails->sign == true && fdetails->space == true) | ||
fdetails->space = false; | ||
if (fdetails->fspec != 'i' && fdetails->fspec != 'd') | ||
{ | ||
fdetails->space = false; | ||
fdetails->sign = false; | ||
} | ||
if (fdetails->fspec != 'x' && fdetails->fspec != 'X') | ||
fdetails->hash = false; | ||
if (fdetails->fspec == 'c' || fdetails->fspec == 'p') | ||
fdetails->dot = false; | ||
if (fdetails->fspec == 'c' || fdetails->fspec == 'p' | ||
|| fdetails->fspec == 's') | ||
fdetails->zero = false; | ||
if (fdetails->dot == true | ||
&& (int) ft_strlen(fdetails->str) > fdetails->prec) | ||
fdetails->zero = false; | ||
} | ||
|
||
void parse_flags(const char **s, t_arg *fdetails) | ||
{ | ||
char c; | ||
|
||
while (!ft_strchr("cspdiuxX%", **s)) | ||
{ | ||
if (**s == '#' && fdetails->hash == false) | ||
fdetails->hash = true; | ||
else if (**s == '0' && fdetails->zero == false) | ||
fdetails->zero = true; | ||
else if (**s == '-' && fdetails->dash == false) | ||
fdetails->dash = true; | ||
else if (**s == '+' && fdetails->sign == false) | ||
fdetails->sign = true; | ||
else if (**s == ' ' && fdetails->space == false) | ||
fdetails->space = true; | ||
else | ||
break ; | ||
c = **s; | ||
while (**s == c) | ||
(*s)++; | ||
} | ||
} | ||
|
||
int get_width(const char **s) | ||
{ | ||
int width; | ||
|
||
while (**s == '0') | ||
(*s)++; | ||
width = ft_atoi(*s); | ||
*s += get_str_len((long)width, 10); | ||
return (width); | ||
} | ||
|
||
int get_prec(const char **s) | ||
{ | ||
int prec; | ||
|
||
while (**s == '0') | ||
(*s)++; | ||
prec = ft_atoi(*s); | ||
if (prec != 0) | ||
*s += get_str_len((long)prec, 10); | ||
return (prec); | ||
} | ||
|
||
void fill_members(const char **s, t_arg *fdetails) | ||
{ | ||
(*s)++; | ||
parse_flags(s, fdetails); | ||
if (**s > '0' && **s <= '9') | ||
fdetails->width = get_width(s); | ||
if (**s == '.') | ||
{ | ||
(*s)++; | ||
fdetails->dot = true; | ||
fdetails->prec = get_prec(s); | ||
} | ||
} |
Oops, something went wrong.