-
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.
finished checker need to fix newline issue
- Loading branch information
1 parent
241a54e
commit 7765faa
Showing
21 changed files
with
494 additions
and
278 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 |
---|---|---|
@@ -1,34 +1,34 @@ | ||
SRCS = main.c ft_split.c util_func1.c util_func2.c operations.c operations2.c sort.c range.c extra_sort.c | ||
# SRCB = | ||
SRCB = main_bonus.c ft_split_bonus.c util_func1_bonus.c util_func2_bonus.c util_func3_bonus.c operations_bonus.c operations2_bonus.c operations3_bonus.c sort_bonus.c range_bonus.c extra_sort_bonus.c get_next_line_bonus.c checker_bonus.c | ||
DIR = ./srcs/ | ||
BONUS_DIR = ./bonus/ | ||
OBJS = $(SRCS:%.c=$(DIR)%.o) | ||
# OBJB = $(SRCB:%.c=$(BONUS_DIR)%.o) | ||
OBJB = $(SRCB:%.c=$(BONUS_DIR)%.o) | ||
CC = cc | ||
CFLAGS = -Wall -Wextra -Werror | ||
NAME = push_swap | ||
# BONUS_NAME = so_long_bonus | ||
BONUS_NAME = checker | ||
|
||
all: $(NAME) | ||
|
||
# bonus: $(BONUS_NAME) | ||
bonus: $(BONUS_NAME) | ||
|
||
# $(BONUS_NAME): $(OBJB) $(BONUS_DIR)so_long_bonus.h | ||
# $(CC) $(OBJB) $(IFLAGS) -o $(BONUS_NAME) | ||
$(BONUS_NAME): $(OBJB) $(BONUS_DIR)push_swap_bonus.h | ||
$(CC) $(OBJB) $(IFLAGS) -o $(BONUS_NAME) | ||
|
||
$(NAME): $(OBJS) $(DIR)push_swap.h | ||
$(CC) $(OBJS) $(IFLAGS) -o $(NAME) | ||
|
||
$(DIR)%.o: $(DIR)%.c $(DIR)push_swap.h | ||
$(CC) $(CFLAGS) -c $< -o $@ | ||
|
||
# $(BONUS_DIR)%.o: $(BONUS_DIR)%.c $(BONUS_DIR)so_long_bonus.h | ||
# $(CC) $(CFLAGS) -c $< -o $@ | ||
$(BONUS_DIR)%.o: $(BONUS_DIR)%.c $(BONUS_DIR)push_swap_bonus.h | ||
$(CC) $(CFLAGS) -c $< -o $@ | ||
|
||
clean: | ||
rm -rf $(OBJS) | ||
rm -rf $(OBJS) $(OBJB) | ||
|
||
fclean: clean | ||
rm -rf $(NAME) | ||
rm -rf $(NAME) $(BONUS_NAME) | ||
|
||
re: fclean all |
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 |
---|---|---|
|
@@ -6,11 +6,11 @@ | |
/* By: ael-maaz <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/04/08 16:59:08 by ael-maaz #+# #+# */ | ||
/* Updated: 2024/04/08 16:59:16 by ael-maaz ### ########.fr */ | ||
/* Updated: 2024/04/08 18:48:58 by ael-maaz ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
#include "push_swap_bonus.h" | ||
|
||
void sort_three(t_stack *a) | ||
{ | ||
|
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 |
---|---|---|
|
@@ -6,11 +6,11 @@ | |
/* By: ael-maaz <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/12/10 16:02:02 by ael-maaz #+# #+# */ | ||
/* Updated: 2024/04/01 22:35:05 by ael-maaz ### ########.fr */ | ||
/* Updated: 2024/04/08 18:49:02 by ael-maaz ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
#include "push_swap_bonus.h" | ||
|
||
static int word_c(char *str, char c) | ||
{ | ||
|
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,131 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* get_next_line_bonus.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ael-maaz <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/11 19:08:58 by ael-maaz #+# #+# */ | ||
/* Updated: 2024/04/09 02:27:30 by ael-maaz ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap_bonus.h" | ||
|
||
char *ft_read(int fd, char *buffer, int index) | ||
{ | ||
char *tmp; | ||
char *frees; | ||
|
||
tmp = malloc(sizeof(char) * 30000 + 1); | ||
if (!tmp) | ||
return (free(buffer), buffer = NULL, NULL); | ||
while (index > 0) | ||
{ | ||
index = read(fd, tmp, 30000); | ||
if (index == -1) | ||
return (free(buffer), free(tmp), NULL); | ||
if (index != 0) | ||
{ | ||
tmp[index] = '\0'; | ||
frees = buffer; | ||
buffer = ft_strjoin(buffer, tmp); | ||
if (!buffer) | ||
return (free(frees), free(tmp), NULL); | ||
free(frees); | ||
if (ft_strchr(buffer, '\n')) | ||
break ; | ||
} | ||
} | ||
return (free(tmp), buffer); | ||
} | ||
|
||
char *gettline(char *buffer) | ||
{ | ||
char *line; | ||
int i; | ||
int j; | ||
|
||
j = -1; | ||
if (!buffer) | ||
return (NULL); | ||
i = 0; | ||
while (buffer[i] && buffer[i] != '\n') | ||
i++; | ||
if (buffer[i] == '\n') | ||
i++; | ||
line = malloc(sizeof(char) *(i + 1)); | ||
if (!line) | ||
return (NULL); | ||
ft_memfunc(line, "", 0, i + 1); | ||
line[i] = '\0'; | ||
while (++j < i) | ||
line[j] = buffer[j]; | ||
return (line); | ||
} | ||
|
||
char *ft_substr(char *s, int start, int len) | ||
{ | ||
char *p; | ||
|
||
if (!s) | ||
return (NULL); | ||
p = malloc(sizeof(char) * (len + 1)); | ||
if (!p) | ||
return (free(s), NULL); | ||
ft_memfunc(p, s + start, 1, len - start); | ||
p[len - start] = 0; | ||
free(s); | ||
return (p); | ||
} | ||
|
||
char *rest(char *buffer) | ||
{ | ||
char *rest; | ||
int i; | ||
|
||
i = 0; | ||
if (!buffer) | ||
{ | ||
free (buffer); | ||
return (NULL); | ||
} | ||
while (buffer[i]) | ||
{ | ||
if (buffer[i] == '\n') | ||
{ | ||
if (buffer[i + 1] == '\0') | ||
return (free(buffer), buffer = NULL, NULL); | ||
rest = ft_substr(buffer, i + 1, ft_strlen(buffer)); | ||
return (rest); | ||
} | ||
i++; | ||
} | ||
free (buffer); | ||
return (NULL); | ||
} | ||
|
||
char *get_next_line(int fd) | ||
{ | ||
char *line; | ||
static char *buffer; | ||
|
||
if (fd < 0 || read(fd, 0, 0) < 0) | ||
return (free(buffer), buffer = NULL, NULL); | ||
buffer = ft_read(fd, buffer, 1); | ||
if (!buffer) | ||
{ | ||
free(buffer); | ||
buffer = NULL; | ||
return (NULL); | ||
} | ||
line = gettline(buffer); | ||
if (!line) | ||
{ | ||
free(buffer); | ||
buffer = NULL; | ||
return (NULL); | ||
} | ||
buffer = rest(buffer); | ||
return (line); | ||
} |
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* main.c :+: :+: :+: */ | ||
/* main_bonus.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ael-maaz <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/04/01 16:58:38 by ael-maaz #+# #+# */ | ||
/* Updated: 2024/04/08 18:14:53 by ael-maaz ### ########.fr */ | ||
/* Updated: 2024/04/09 02:49:20 by ael-maaz ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
#include "push_swap_bonus.h" | ||
|
||
int fill_stack(char **av, int ac, t_stack *stack_a, int i) | ||
{ | ||
|
@@ -89,35 +89,26 @@ int init_stacks(char **av, int ac, t_stack *stack_a, t_stack *stack_b) | |
return (error); | ||
} | ||
|
||
// void print_stacks(t_stack a,t_stack b) | ||
// { | ||
// printf("-----------------stack a-----------\n"); | ||
// while(a.top >= 0) | ||
// printf("%d\n", a.stack[a.top--]); | ||
// printf("-----------------stack b------------\n"); | ||
// while(b.top >= 0) | ||
// printf("%d\n", b.stack[b.top--]); | ||
// } | ||
|
||
int main(int ac, char **av) | ||
{ | ||
t_stack a; | ||
t_stack b; | ||
|
||
if (ac > 1) | ||
{ | ||
get_range(40); | ||
if (init_stacks(av, ac, &a, &b) == 1) | ||
{ | ||
write(2, "Error\n", 6); | ||
return (0); | ||
} | ||
return (write(2, "Error\n", 6), 0); | ||
if (duplicates(a) == 0) | ||
return (write(2, "Error\n", 6), 0); | ||
if (is_sorted(&a) == 0) | ||
return (0); | ||
bubble_sort(&a); | ||
range(&a, &b); | ||
if (read_input(&a, &b) == -1) | ||
return(write(2, "Error\n", 6), 0); | ||
if (is_sorted(&a) == 0 && b.top == -1) | ||
return(write(1, "OK\n", 3), 0); | ||
else | ||
return(write(1, "KO\n", 3), 0); | ||
free(a.stack); | ||
free(b.stack); | ||
} | ||
|
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* operations2.c :+: :+: :+: */ | ||
/* operations2_bonus.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ael-maaz <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/04/03 16:37:55 by ael-maaz #+# #+# */ | ||
/* Updated: 2024/04/05 23:04:30 by ael-maaz ### ########.fr */ | ||
/* Updated: 2024/04/09 01:55:23 by ael-maaz ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
#include "push_swap_bonus.h" | ||
|
||
void rra(t_stack *a) | ||
{ | ||
|
@@ -27,7 +27,6 @@ void rra(t_stack *a) | |
i++; | ||
} | ||
a->stack[a->top] = tmp; | ||
ft_putstr("rra\n"); | ||
} | ||
} | ||
|
||
|
@@ -46,7 +45,6 @@ void rrb(t_stack *b) | |
i++; | ||
} | ||
b->stack[b->top] = tmp; | ||
ft_putstr("rrb\n"); | ||
} | ||
} | ||
|
||
|
@@ -65,7 +63,6 @@ void ra(t_stack *a) | |
i--; | ||
} | ||
a->stack[0] = tmp; | ||
ft_putstr("ra\n"); | ||
} | ||
} | ||
|
||
|
@@ -84,6 +81,5 @@ void rb(t_stack *b) | |
i--; | ||
} | ||
b->stack[0] = tmp; | ||
ft_putstr("rb\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,31 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* operations3_bonus.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ael-maaz <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/04/09 01:47:53 by ael-maaz #+# #+# */ | ||
/* Updated: 2024/04/09 01:49:22 by ael-maaz ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap_bonus.h" | ||
|
||
void rr(t_stack *a, t_stack *b) | ||
{ | ||
ra(a); | ||
rb(b); | ||
} | ||
|
||
void rrr(t_stack *a, t_stack *b) | ||
{ | ||
rra(a); | ||
rrb(b); | ||
} | ||
|
||
void ss(t_stack *a, t_stack *b) | ||
{ | ||
sa(a); | ||
sb(b); | ||
} |
Oops, something went wrong.