main reads arguments and prints the stacks, debug option added for vscode and in the makefile

This commit is contained in:
whaffman 2024-11-05 13:42:20 +01:00
parent 7341246f53
commit 563ebe60a6
12 changed files with 173 additions and 9 deletions

2
.gitignore vendored
View File

@ -2,7 +2,5 @@ a.out
*.o
*.a
*~
.vscode/
push_swap
obj/
lib/

31
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,31 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug push_swap",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/push_swap",
"args": ["2", "5", "4", "1"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build push_swap",
"miDebuggerPath": "/usr/bin/gdb",
"logging": {
"trace": true,
"traceResponse": true,
"engineLogging": true
}
}
]
}

17
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build push_swap",
"type": "shell",
"command": "make",
"args": [],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$gcc"],
"detail": "Generated task for building the project using make"
}
]
}

View File

@ -6,7 +6,7 @@
# By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ #
# +#+ +#+#+ +#++#+ +#+ \o/ #
# Created: 2024/10/15 11:48:46 by whaffman #+#+# #+#+# #+# #+# | #
# Updated: 2024/11/04 13:26:31 by whaffman ### ### ### ### / \ #
# Updated: 2024/11/04 13:56:19 by whaffman ### ### ### ### / \ #
# #
# **************************************************************************** #
@ -28,7 +28,7 @@ CC = cc
RM = rm -rf
INCLUDES = -I./$(INC_PATH) -I./$(LIBFT_INC_PATH)
CFLAGS = -Wall -Wextra -Werror
CFLAGS = -Wall -Wextra -Werror -g
LDFLAGS = -L./libft
LDLIBS = -lft
@ -65,4 +65,9 @@ run: all
@$(eval ARG = $(shell shuf -i 0-100 -n 5))
./$(NAME) $(ARG)
debug: CFLAGS += -DDEBUG -g
debug: all
@echo $(CFLAGS)
@$(MAKE) re
.PHONY: all bonus clean fclean re

View File

@ -1,2 +1,4 @@
-I
./inc/
./inc/
-I
./libft/inc/

33
inc/push_swap.h Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: o_ :::::: ::: */
/* push_swap.h :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2024/11/04 13:58:35 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2024/11/04 14:11:03 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
typedef struct s_clist
{
void *content;
struct s_clist *next;
struct s_clist *prev;
} t_clist;
typedef struct s_node
{
int n;
int ra;
int rb;
int rr;
int rra;
int rrb;
int rrr;
int pa;
int pb;
int sa;
int sb;
} t_node;

View File

@ -69,4 +69,7 @@ fclean: clean
re: fclean all
debug: CFLAGS += -DDEBUG -g
debug: $(NAME)
.PHONY: all clean fclean re

0
src/moves/push.c Normal file
View File

View File

0
src/moves/rotate.c Normal file
View File

0
src/moves/swap.c Normal file
View File

View File

@ -12,13 +12,88 @@
#include "libft.h"
#include <stdio.h>
#include <stdlib.h>
int new_element(t_list **stack, const char *str)
{
int *n;
char *test;
t_list *elem;
n = malloc(sizeof (int));
if (!n)
return (0);
*n = ft_atoi(str);
test = ft_itoa(*n);
if (ft_strncmp(str, test, 20))
{
free(test);
return (0);
}
free(test);
elem = ft_lstnew(n);
if (!elem)
return (0);
ft_lstadd_front(stack, elem);
return (1);
}
t_list *ft_lstat(t_list *list, int n)
{
if (!list)
return (NULL);
while (list->next && n > 0)
{
list = list->next;
n--;
}
if (n > 0)
return (NULL);
return (list);
}
void print_stack(const char *name, t_list *stack)
{
int lst_size;
t_list *node;
ft_printf("%s |", name);
if (!stack)
{
ft_printf("\n");
return ;
}
lst_size = ft_lstsize(stack);
while (lst_size > 0)
{
node = ft_lstat(stack, lst_size - 1);
ft_printf("%d ", *((int *) node->content));
lst_size--;
}
ft_printf("\n");
}
void print_stacks(t_list *stack_a, t_list *stack_b)
{
print_stack("A", stack_a);
print_stack("B", stack_b);
}
int main(int argc, char *argv[])
{
int i;
t_list *stack_a;
t_list *stack_b;
i = 1;
while (i < argc)
ft_printf("%s\n", argv[i++]);
stack_a = NULL;
stack_b = NULL;
while (argc-- > 1)
{
if (!new_element(&stack_a, argv[argc]))
{
ft_putstr_fd("Error\n", 2);
return (1);
}
}
print_stacks(stack_a, stack_b);
return (0);
}