Projet Fini
This commit is contained in:
parent
dd914622ed
commit
61a3861d39
9
Makefile
9
Makefile
|
@ -6,18 +6,16 @@
|
||||||
# By: erey-bet <marvin@42.fr> +#+ +:+ +#+ #
|
# By: erey-bet <marvin@42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2022/09/27 04:19:30 by erey-bet #+# #+# #
|
# Created: 2022/09/27 04:19:30 by erey-bet #+# #+# #
|
||||||
# Updated: 2022/12/02 19:24:34 by erey-bet ### ########.fr #
|
# Updated: 2022/12/08 16:58:13 by erey-bet ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
SRCS = push_swap.c operations.c tools.c parsing.c
|
SRCS = push_swap.c operations.c tools.c parsing.c
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
CC = clang
|
CC = clang
|
||||||
CFLAGS = -g -Wall -Wextra -Werror
|
CFLAGS = -Wall -Wextra -Werror
|
||||||
NAME = push_swap
|
NAME = push_swap
|
||||||
|
|
||||||
# TU OUBLIS PAS LE -G DANS CFLAGS HEIN
|
|
||||||
|
|
||||||
all: ${NAME}
|
all: ${NAME}
|
||||||
|
|
||||||
${NAME}: ${OBJS}
|
${NAME}: ${OBJS}
|
||||||
|
@ -35,6 +33,8 @@ fclean: clean
|
||||||
|
|
||||||
re: fclean all
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY: all clean fclean re coffee
|
||||||
|
|
||||||
coffee:
|
coffee:
|
||||||
@clear
|
@clear
|
||||||
@echo ""
|
@echo ""
|
||||||
|
@ -137,4 +137,3 @@ coffee:
|
||||||
@echo ' """------"""'
|
@echo ' """------"""'
|
||||||
${MAKE} coffee
|
${MAKE} coffee
|
||||||
|
|
||||||
.PHONY: all clean fclean re coffee gdb
|
|
||||||
|
|
51
parsing.c
51
parsing.c
|
@ -6,7 +6,7 @@
|
||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/12/07 19:23:59 by erey-bet #+# #+# */
|
/* Created: 2022/12/07 19:23:59 by erey-bet #+# #+# */
|
||||||
/* Updated: 2022/12/07 19:24:04 by erey-bet ### ########.fr */
|
/* Updated: 2022/12/08 11:22:53 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -25,6 +25,43 @@ void choice(long *tab, int y)
|
||||||
write(1, "ra\n", 3);
|
write(1, "ra\n", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int put_error(void)
|
||||||
|
{
|
||||||
|
write(2, "Error\n", 6);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
char **set_only_space(char *argv[], int i)
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
|
||||||
|
x = 0;
|
||||||
|
while (argv[i][x])
|
||||||
|
if (ft_strchr("\a\b\t\n\v\f\r", argv[i][x++]) != NULL)
|
||||||
|
argv[i][x - 1] = ' ';
|
||||||
|
return (argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
int if_there_is_double(long *tab, int y)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int x;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < y)
|
||||||
|
{
|
||||||
|
x = 0;
|
||||||
|
while (x < y)
|
||||||
|
{
|
||||||
|
if (tab[i] == tab[x] && i != x)
|
||||||
|
return (1);
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
int parsing(int argc, char *argv[], long *tab)
|
int parsing(int argc, char *argv[], long *tab)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -36,10 +73,7 @@ int parsing(int argc, char *argv[], long *tab)
|
||||||
y = 0;
|
y = 0;
|
||||||
while (++i < argc)
|
while (++i < argc)
|
||||||
{
|
{
|
||||||
x = 0;
|
argv = set_only_space(argv, i);
|
||||||
while (argv[i][x])
|
|
||||||
if (ft_strchr("\a\b\t\n\v\f\r", argv[i][x++]) != NULL)
|
|
||||||
argv[i][x - 1] = ' ';
|
|
||||||
x = 0;
|
x = 0;
|
||||||
tmp = ft_split(argv[i], ' ');
|
tmp = ft_split(argv[i], ' ');
|
||||||
while (tmp[x] != NULL)
|
while (tmp[x] != NULL)
|
||||||
|
@ -47,13 +81,12 @@ int parsing(int argc, char *argv[], long *tab)
|
||||||
if (ft_atoi_check(tmp[x]))
|
if (ft_atoi_check(tmp[x]))
|
||||||
tab[y++] = ft_atoi(tmp[x]);
|
tab[y++] = ft_atoi(tmp[x]);
|
||||||
else
|
else
|
||||||
{
|
return (put_error());
|
||||||
write(1, "Error\n", 6);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (if_there_is_double(tab, y) || (y < argc - 1))
|
||||||
|
return (put_error());
|
||||||
choice(tab, y);
|
choice(tab, y);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
39
push_swap.c
39
push_swap.c
|
@ -6,49 +6,12 @@
|
||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/11/23 16:48:12 by erey-bet #+# #+# */
|
/* Created: 2022/11/23 16:48:12 by erey-bet #+# #+# */
|
||||||
/* Updated: 2022/12/07 18:35:18 by erey-bet ### ########.fr */
|
/* Updated: 2022/12/08 16:57:34 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "push_swap.h"
|
#include "push_swap.h"
|
||||||
|
|
||||||
/*void ft_putchar(char c)
|
|
||||||
{
|
|
||||||
write(1, &c, 1);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*void print_stack(t_stack sa, t_stack sb)
|
|
||||||
{
|
|
||||||
write(1, "A: ", 3);
|
|
||||||
for (int i = 0; i < sa.len; i++)
|
|
||||||
{
|
|
||||||
ft_putchar(sa.list[i] + '0');
|
|
||||||
write(1, ", ", 2);
|
|
||||||
}
|
|
||||||
ft_putchar('\n');
|
|
||||||
if (sb.len > 0)
|
|
||||||
{
|
|
||||||
write(1, "B: ", 3);
|
|
||||||
for (int i = 0; i < sb.len; i++)
|
|
||||||
{
|
|
||||||
ft_putchar(sb.list[i] + '0');
|
|
||||||
write(1, ", ", 2);
|
|
||||||
}
|
|
||||||
ft_putchar('\n');
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*void print_one_stack(t_stack s)
|
|
||||||
{
|
|
||||||
write(1, "A: ", 3);
|
|
||||||
for (int i = 0; i < s.len; i++)
|
|
||||||
{
|
|
||||||
ft_putchar(s.list[i] + '0');
|
|
||||||
write(1, ", ", 2);
|
|
||||||
}
|
|
||||||
ft_putchar('\n');
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void post_push_swap(t_stack sa, t_stack sb, int x, int sa_len)
|
void post_push_swap(t_stack sa, t_stack sb, int x, int sa_len)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
10
push_swap.h
10
push_swap.h
|
@ -6,7 +6,7 @@
|
||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/11/23 16:51:31 by erey-bet #+# #+# */
|
/* Created: 2022/11/23 16:51:31 by erey-bet #+# #+# */
|
||||||
/* Updated: 2022/12/04 18:02:57 by erey-bet ### ########.fr */
|
/* Updated: 2022/12/08 11:23:13 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -35,12 +35,12 @@ void push(t_stack *s_push, t_stack *s_receive, char *message);
|
||||||
void rotate(t_stack *s, char *message);
|
void rotate(t_stack *s, char *message);
|
||||||
|
|
||||||
// Tools
|
// Tools
|
||||||
int get_min(long *tab, int len);
|
int get_min(long *tab, int len);
|
||||||
long *get_index(long *tab, int len);
|
long *get_index(long *tab, int len);
|
||||||
int max_len_binary(t_stack s);
|
int max_len_binary(t_stack s);
|
||||||
int check_sa(t_stack s);
|
int check_sa(t_stack s);
|
||||||
|
|
||||||
// Parsing
|
// Parsing
|
||||||
int parsing(int argc, char *argv[], long *tab);
|
int parsing(int argc, char *argv[], long *tab);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue