diff --git a/ex00/Makefile b/ex00/Makefile index fa3546c..2afaa43 100644 --- a/ex00/Makefile +++ b/ex00/Makefile @@ -51,7 +51,7 @@ $(NAME): $(OBJ) $(OBJ): | $(OBJDIR) $(OBJDIR)/%.o: %.c $(DEPS) - @#norminette $< >/dev/null || { printf '\033[102;97m%s\033[m\n' "!Norminette Failed>>>"; norminette $<; printf '\033[101;97m%s\033[m\n' "<</dev/null || { printf '\033[101;97m%s\033[m\n' "!Norminette Failed>>>"; norminette $<; printf '\033[101;97m%s\033[m\n' "<< +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/01 15:12:53 by tischmid #+# #+# */ -/* Updated: 2023/04/01 17:28:05 by tischmid ### ########.fr */ +/* Updated: 2023/04/01 17:48:25 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ int parse_args(int argc, char **argv, char **path, char **str_nbr) *str_nbr = argv[1]; if (argc == 3) { - if (!file_exists(argv[1])) + if (!file_readable(argv[1])) return (0); *path = argv[1]; *str_nbr = argv[2]; diff --git a/ex00/ft_io.c b/ex00/ft_io.c index 3f09fdc..7fcbc1d 100644 --- a/ex00/ft_io.c +++ b/ex00/ft_io.c @@ -6,7 +6,7 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/01 08:51:59 by tischmid #+# #+# */ -/* Updated: 2023/04/01 14:57:53 by tischmid ### ########.fr */ +/* Updated: 2023/04/01 18:03:28 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,14 +15,14 @@ #include #include -int file_exists(char *path) +int file_readable(char *path) { - int fd_num_dict; + int fd; - fd_num_dict = open(path, O_RDONLY, 0); - if (fd_num_dict < 0) + fd = open(path, O_RDONLY, 0); + if (fd < 0) return (0); - if (close(fd_num_dict) < 0) + if (close(fd) < 0) return (0); return (1); } diff --git a/ex00/ft_linked_list.c b/ex00/ft_linked_list.c index d8149c3..5dfeff0 100644 --- a/ex00/ft_linked_list.c +++ b/ex00/ft_linked_list.c @@ -6,7 +6,7 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/01 15:25:42 by tischmid #+# #+# */ -/* Updated: 2023/04/01 17:21:01 by tischmid ### ########.fr */ +/* Updated: 2023/04/01 17:44:52 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,15 +15,15 @@ #include #include -t_map_entry *ll_map_new_node(char *key, char *value) +t_map_entry *ll_map_new_entry(char *key, char *value) { - t_map_entry *new_node; + t_map_entry *new_entry; - 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); + new_entry = (t_map_entry *) malloc(sizeof(t_map_entry)); + new_entry->key = key; + new_entry->value = value; + new_entry->next = NULL; + return (new_entry); } char *ll_map_get(t_map_entry *head, char *key) @@ -52,7 +52,7 @@ void ll_map_push(t_map_entry *head, char *key, char *value) current = head; while (current->next != NULL) current = current->next; - current->next = ll_map_new_node(key, value); + current->next = ll_map_new_entry(key, value); } else ft_putstr("head is NULL\n"); @@ -67,7 +67,7 @@ t_map_entry *ll_pop_last(t_map_entry *head) { if (head->next == NULL) { - retval = ll_map_new_node(head->key, head->value); + retval = ll_map_new_entry(head->key, head->value); free(head); return (retval); } @@ -76,7 +76,7 @@ t_map_entry *ll_pop_last(t_map_entry *head) while (current->next->next != NULL) current = current->next; - retval = ll_map_new_node(current->next->key, current->next->value); + retval = ll_map_new_entry(current->next->key, current->next->value); free(current->next); current->next = NULL; return (retval); diff --git a/ex00/include/ft_io.h b/ex00/include/ft_io.h index 378e0ff..e882a77 100644 --- a/ex00/include/ft_io.h +++ b/ex00/include/ft_io.h @@ -6,13 +6,13 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/01 08:52:17 by tischmid #+# #+# */ -/* Updated: 2023/04/01 08:52:30 by tischmid ### ########.fr */ +/* Updated: 2023/04/01 18:19:46 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_IO_H # define FT_IO_H -int file_exists(char *path); +int file_readable(char *path); #endif diff --git a/ex00/include/ft_linked_list.h b/ex00/include/ft_linked_list.h index e8e7c6e..34ee0ff 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 17:18:42 by tischmid ### ########.fr */ +/* Updated: 2023/04/01 17:44:27 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ typedef struct s_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_map_new_entry(char *key, char *value); t_map_entry *ll_pop_last(t_map_entry *head); #endif diff --git a/ex00/main.c b/ex00/main.c index 6e69a8a..7aab12d 100644 --- a/ex00/main.c +++ b/ex00/main.c @@ -6,7 +6,7 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/01 07:11:58 by tischmid #+# #+# */ -/* Updated: 2023/04/01 17:20:50 by tischmid ### ########.fr */ +/* Updated: 2023/04/01 18:19:25 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,44 @@ #include +#include "ft_io.h" +#include +#include +#include + +/* read `size' bytes from file `path' beginning at `offset', storing + * all chars in `buf', where `buf' is terminated at the first newline + * found. On success, returns number of characters found, -1 on error + * or EOF with 0 chars read. + */ +int readline(/*char *buf, unsigned int size, */ char *path/*, int offset*/) +{ + int counter; + int fd; + char c; + + fd = open(path, O_RDONLY); + if (fd < 0) + return (-1); + counter = 0; + while (read(fd, &c, sizeof(c)) > 0) + if (c == 1) + ++counter; + close(fd); + return (counter); +} + +int parse_dict(char *path/*, t_map_entry *map*/) +{ + printf("Number of 1's: %d\n", readline(path)); + + // if (fd < 0) + // return (0); + // if (close(fd) < 0) + // return (1); + return (1); +} + int main(int argc, char **argv) { char *str_nbr; @@ -27,14 +65,7 @@ int main(int argc, char **argv) return (puterr("Error\n", 1)); // if (!parse_dict(path, map)) // return (puterr("Dict Error\n", 2)); - t_map_entry *head = ll_map_new_node("hello", "world"); - ll_map_push(head, "hello2", "world2"); - 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); + // ll_clear(map); + parse_dict(path); return (0); }