diff --git a/ex00/Makefile b/ex00/Makefile index dd59fd3..fa3546c 100644 --- a/ex00/Makefile +++ b/ex00/Makefile @@ -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) diff --git a/ex00/argparse.c b/ex00/argparse.c index 60c1593..9087a1a 100644 --- a/ex00/argparse.c +++ b/ex00/argparse.c @@ -6,7 +6,7 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/ex00/ft_linked_list.c b/ex00/ft_linked_list.c index 90ed8cf..d8149c3 100644 --- a/ex00/ft_linked_list.c +++ b/ex00/ft_linked_list.c @@ -6,8 +6,91 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 +#include + +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)); + } +} diff --git a/ex00/ft_lib.c b/ex00/ft_strlib.c similarity index 82% rename from ex00/ft_lib.c rename to ex00/ft_strlib.c index 0ca4a94..b923833 100644 --- a/ex00/ft_lib.c +++ b/ex00/ft_strlib.c @@ -1,16 +1,16 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lib.c :+: :+: :+: */ +/* ft_strlib.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); +} diff --git a/ex00/include/ft_linked_list.h b/ex00/include/ft_linked_list.h index eb66481..e8e7c6e 100644 --- a/ex00/include/ft_linked_list.h +++ b/ex00/include/ft_linked_list.h @@ -6,7 +6,7 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 diff --git a/ex00/include/ft_lib.h b/ex00/include/ft_strlib.h similarity index 82% rename from ex00/include/ft_lib.h rename to ex00/include/ft_strlib.h index d1685c0..7470be4 100644 --- a/ex00/include/ft_lib.h +++ b/ex00/include/ft_strlib.h @@ -1,17 +1,17 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lib.h :+: :+: :+: */ +/* ft_strlib.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 # include # 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 diff --git a/ex00/main.c b/ex00/main.c index 527e897..6e69a8a 100644 --- a/ex00/main.c +++ b/ex00/main.c @@ -6,106 +6,16 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 -#include - -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); } diff --git a/ex00/obj/argparse.o b/ex00/obj/argparse.o deleted file mode 100644 index 1630c0e..0000000 Binary files a/ex00/obj/argparse.o and /dev/null differ diff --git a/ex00/obj/ft_io.o b/ex00/obj/ft_io.o deleted file mode 100644 index f2d9023..0000000 Binary files a/ex00/obj/ft_io.o and /dev/null differ diff --git a/ex00/obj/ft_lib.o b/ex00/obj/ft_lib.o deleted file mode 100644 index 5ae350c..0000000 Binary files a/ex00/obj/ft_lib.o and /dev/null differ diff --git a/ex00/obj/ft_strlib.o b/ex00/obj/ft_strlib.o new file mode 100644 index 0000000..b9ce7ce Binary files /dev/null and b/ex00/obj/ft_strlib.o differ diff --git a/ex00/obj/main.o b/ex00/obj/main.o index becf24d..2ab8ff0 100644 Binary files a/ex00/obj/main.o and b/ex00/obj/main.o differ diff --git a/ex00/rush-02 b/ex00/rush-02 deleted file mode 100755 index d743da1..0000000 Binary files a/ex00/rush-02 and /dev/null differ