File strucutre
This commit is contained in:
parent
83768e22d7
commit
1ca50de514
|
@ -1,12 +1,14 @@
|
|||
SRC = main.c \
|
||||
ft_lib.c \
|
||||
ft_strlib.c \
|
||||
ft_io.c \
|
||||
argparse.c
|
||||
argparse.c \
|
||||
ft_linked_list.c
|
||||
HEADERS = main.h \
|
||||
ft_lib.h \
|
||||
ft_strlib.h \
|
||||
ft_io.h \
|
||||
colors.h \
|
||||
argparse.h
|
||||
argparse.h \
|
||||
ft_linked_list.h
|
||||
|
||||
OBJDIR = obj
|
||||
INCDIR = include
|
||||
|
@ -60,9 +62,9 @@ tests: test
|
|||
test: re run fclean
|
||||
|
||||
SUCCESS_MSG=printf '\n\033[102;30m --- %s --- \033[m\n\n' "Test passed!"
|
||||
FAIL_MSG=printf '\n\033[101;30m --- %s --- \033[m\n\n' "Test failed!"
|
||||
SUCCESS_MSG_VALG=printf '\n\033[102;97m --- %s --- \033[m\n\n' "Valgrind ran without errors!"
|
||||
FAIL_MSG_VALG=printf '\n\033[101;97m --- %s --- \033[m\n\n' "Valgrind Failed!"
|
||||
FAIL_MSG=printf '\n\033[101;37m --- %s --- \033[m\n\n' "Test failed!"
|
||||
SUCCESS_MSG_VALG=printf '\n\033[102;30m --- %s --- \033[m\n\n' "Valgrind ran without errors!"
|
||||
FAIL_MSG_VALG=printf '\n\033[101;37m --- %s --- \033[m\n\n' "Valgrind Failed!"
|
||||
SUCCESS=&& $(SUCCESS_MSG) || $(FAIL_MSG)
|
||||
SUCCESS_VALG=&& $(SUCCESS_MSG_VALG) || $(FAIL_MSG_VALG)
|
||||
FAIL=&& $(FAIL_MSG) || $(SUCCESS_MSG)
|
||||
|
@ -76,6 +78,6 @@ run:
|
|||
./$(NAME) 1 "./dicts/numb.dict" $(FAIL)
|
||||
./$(NAME) 1 2 3 $(FAIL)
|
||||
|
||||
valgrind:
|
||||
valgrind: re
|
||||
$(VALGRIND) ./$(NAME) 1 $(SUCCESS_VALG)
|
||||
$(VALGRIND) ./$(NAME) "./dicts/numbers2.dict" 1 $(SUCCESS_VALG)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/01 15:12:53 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/01 15:13:56 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/01 17:28:05 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
@ -6,8 +6,91 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/01 15:25:42 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/01 15:25:50 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/01 17:21:01 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_linked_list.h"
|
||||
#include "ft_strlib.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
t_map_entry *ll_map_new_node(char *key, char *value)
|
||||
{
|
||||
t_map_entry *new_node;
|
||||
|
||||
new_node = (t_map_entry *) malloc(sizeof(t_map_entry));
|
||||
new_node->key = key;
|
||||
new_node->value = value;
|
||||
new_node->next = NULL;
|
||||
return (new_node);
|
||||
}
|
||||
|
||||
char *ll_map_get(t_map_entry *head, char *key)
|
||||
{
|
||||
t_map_entry *current;
|
||||
|
||||
if (head != NULL)
|
||||
{
|
||||
current = head;
|
||||
while (current != NULL)
|
||||
{
|
||||
if (!ft_strcmp(current->key, key))
|
||||
return (current->value);
|
||||
current = current->next;
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void ll_map_push(t_map_entry *head, char *key, char *value)
|
||||
{
|
||||
t_map_entry *current;
|
||||
|
||||
if (head != NULL)
|
||||
{
|
||||
current = head;
|
||||
while (current->next != NULL)
|
||||
current = current->next;
|
||||
current->next = ll_map_new_node(key, value);
|
||||
}
|
||||
else
|
||||
ft_putstr("head is NULL\n");
|
||||
}
|
||||
|
||||
t_map_entry *ll_pop_last(t_map_entry *head)
|
||||
{
|
||||
t_map_entry *current;
|
||||
t_map_entry *retval;
|
||||
|
||||
if (head != NULL)
|
||||
{
|
||||
if (head->next == NULL)
|
||||
{
|
||||
retval = ll_map_new_node(head->key, head->value);
|
||||
free(head);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
current = head;
|
||||
while (current->next->next != NULL)
|
||||
current = current->next;
|
||||
|
||||
retval = ll_map_new_node(current->next->key, current->next->value);
|
||||
free(current->next);
|
||||
current->next = NULL;
|
||||
return (retval);
|
||||
}
|
||||
else
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void ll_clear(t_map_entry *head)
|
||||
{
|
||||
if (head != NULL)
|
||||
{
|
||||
while (head->next != NULL)
|
||||
free(ll_pop_last(head));
|
||||
free(ll_pop_last(head));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lib.c :+: :+: :+: */
|
||||
/* ft_strlib.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/01 07:13:31 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/01 08:29:48 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/01 17:20:44 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_lib.h"
|
||||
#include "ft_strlib.h"
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
|
@ -51,3 +51,13 @@ int puterr(char *errmsg, int errcode)
|
|||
ft_putstr(RESET);
|
||||
return (errcode);
|
||||
}
|
||||
|
||||
int ft_strcmp(char *s1, char *s2)
|
||||
{
|
||||
while (*s1 && *s2 && *s1 == *s2)
|
||||
{
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
return (*s1 - *s2);
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/01 15:25:59 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/01 15:26:10 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/01 17:18:42 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -20,4 +20,10 @@ typedef struct s_map_entry
|
|||
struct s_map_entry *next;
|
||||
} t_map_entry;
|
||||
|
||||
char *ll_map_get(t_map_entry *head, char *key);
|
||||
void ll_map_push(t_map_entry *head, char *key, char *value);
|
||||
void ll_clear(t_map_entry *head);
|
||||
t_map_entry *ll_map_new_node(char *key, char *value);
|
||||
t_map_entry *ll_pop_last(t_map_entry *head);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lib.h :+: :+: :+: */
|
||||
/* ft_strlib.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/01 07:14:29 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/01 08:30:14 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/01 17:21:46 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_LIB_H
|
||||
# define FT_LIB_H
|
||||
#ifndef FT_STRLIB_H
|
||||
# define FT_STRLIB_H
|
||||
# include <unistd.h>
|
||||
# include <limits.h>
|
||||
# include "colors.h"
|
||||
|
@ -20,5 +20,6 @@ void ft_putchar(char c);
|
|||
void ft_putstr(char *str);
|
||||
void ft_putnbr(int nb);
|
||||
int puterr(char *errmsg, int errcode);
|
||||
int ft_strcmp(char *s1, char *s2);
|
||||
|
||||
#endif
|
101
ex00/main.c
101
ex00/main.c
|
@ -6,106 +6,16 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/01 07:11:58 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/01 16:35:17 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/01 17:20:50 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "main.h"
|
||||
#include "ft_lib.h"
|
||||
#include "ft_strlib.h"
|
||||
#include "argparse.h"
|
||||
#include "ft_linked_list.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ft_strcmp(char *s1, char *s2)
|
||||
{
|
||||
while (*s1 && *s2 && *s1 == *s2)
|
||||
{
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
return (*s1 - *s2);
|
||||
}
|
||||
|
||||
t_map_entry *ll_map_new_node(char *key, char *value)
|
||||
{
|
||||
t_map_entry *new_node;
|
||||
|
||||
new_node = (t_map_entry *) malloc(sizeof(t_map_entry));
|
||||
new_node->key = key;
|
||||
new_node->value = value;
|
||||
return (new_node);
|
||||
}
|
||||
|
||||
char *ll_map_get(t_map_entry *head, char *key)
|
||||
{
|
||||
t_map_entry *current;
|
||||
|
||||
if (head != NULL)
|
||||
{
|
||||
current = head;
|
||||
while (current != NULL)
|
||||
{
|
||||
if (!ft_strcmp(current->key, key))
|
||||
return (current->value);
|
||||
current = current->next;
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void ll_map_push(t_map_entry *head, char *key, char *value)
|
||||
{
|
||||
t_map_entry *current;
|
||||
|
||||
current = head;
|
||||
if (head != NULL)
|
||||
{
|
||||
while (current->next != NULL)
|
||||
current = current->next;
|
||||
current->next = ll_map_new_node(key, value);
|
||||
}
|
||||
else
|
||||
ft_putstr("head is NULL\n");
|
||||
}
|
||||
|
||||
t_map_entry *ll_pop_last(t_map_entry *head)
|
||||
{
|
||||
t_map_entry *current;
|
||||
t_map_entry *retval;
|
||||
|
||||
if (head != NULL)
|
||||
{
|
||||
if (head->next == NULL)
|
||||
{
|
||||
retval = ll_map_new_node(head->key, head->value);
|
||||
free(head);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
current = head;
|
||||
while (current->next->next != NULL)
|
||||
current = current->next;
|
||||
|
||||
retval = ll_map_new_node(current->next->key, current->next->value);
|
||||
free(current->next);
|
||||
current->next = NULL;
|
||||
return (retval);
|
||||
}
|
||||
else
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void ll_clear(t_map_entry *head)
|
||||
{
|
||||
if (head != NULL)
|
||||
{
|
||||
while (head->next != NULL)
|
||||
free(ll_pop_last(head));
|
||||
free(ll_pop_last(head));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
@ -119,7 +29,12 @@ int main(int argc, char **argv)
|
|||
// return (puterr("Dict Error\n", 2));
|
||||
t_map_entry *head = ll_map_new_node("hello", "world");
|
||||
ll_map_push(head, "hello2", "world2");
|
||||
// printf("%s\n", ll_map_get(head, "hello2"));
|
||||
ll_map_push(head, "hello3", "world3");
|
||||
ll_map_push(head, "hello4", "world4");
|
||||
ll_map_push(head, "hello5", "world5");
|
||||
ll_map_push(head, "hello6", "world6");
|
||||
printf("%s\n", ll_map_get(head, "hello2"));
|
||||
printf("%s\n", ll_map_get(head, "hello3"));
|
||||
ll_clear(head);
|
||||
return (0);
|
||||
}
|
||||
|
|
Binary file not shown.
BIN
ex00/obj/ft_io.o
BIN
ex00/obj/ft_io.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
ex00/obj/main.o
BIN
ex00/obj/main.o
Binary file not shown.
BIN
ex00/rush-02
BIN
ex00/rush-02
Binary file not shown.
Loading…
Reference in New Issue