Big changes, whatever

This commit is contained in:
Timo Schmidt 2023-04-01 18:57:33 +02:00
parent 06e43ef2b5
commit 450bd4607a
7 changed files with 65 additions and 34 deletions

View File

@ -51,7 +51,7 @@ $(NAME): $(OBJ)
$(OBJ): | $(OBJDIR) $(OBJ): | $(OBJDIR)
$(OBJDIR)/%.o: %.c $(DEPS) $(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' "<<<Norminette Failed!"; exit 1; } @#norminette $< >/dev/null || { printf '\033[101;97m%s\033[m\n' "!Norminette Failed>>>"; norminette $<; printf '\033[101;97m%s\033[m\n' "<<<Norminette Failed!"; exit 1; }
@$(CC) $(CFLAGS) -c $< -o $@ @$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR): $(OBJDIR):

View File

@ -6,7 +6,7 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */ /* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/01 15:12:53 by tischmid #+# #+# */ /* 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]; *str_nbr = argv[1];
if (argc == 3) if (argc == 3)
{ {
if (!file_exists(argv[1])) if (!file_readable(argv[1]))
return (0); return (0);
*path = argv[1]; *path = argv[1];
*str_nbr = argv[2]; *str_nbr = argv[2];

View File

@ -6,7 +6,7 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */ /* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/01 08:51:59 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 <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
int file_exists(char *path) int file_readable(char *path)
{ {
int fd_num_dict; int fd;
fd_num_dict = open(path, O_RDONLY, 0); fd = open(path, O_RDONLY, 0);
if (fd_num_dict < 0) if (fd < 0)
return (0); return (0);
if (close(fd_num_dict) < 0) if (close(fd) < 0)
return (0); return (0);
return (1); return (1);
} }

View File

@ -6,7 +6,7 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */ /* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/01 15:25:42 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 <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
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_entry = (t_map_entry *) malloc(sizeof(t_map_entry));
new_node->key = key; new_entry->key = key;
new_node->value = value; new_entry->value = value;
new_node->next = NULL; new_entry->next = NULL;
return (new_node); return (new_entry);
} }
char *ll_map_get(t_map_entry *head, char *key) 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; current = head;
while (current->next != NULL) while (current->next != NULL)
current = current->next; current = current->next;
current->next = ll_map_new_node(key, value); current->next = ll_map_new_entry(key, value);
} }
else else
ft_putstr("head is NULL\n"); ft_putstr("head is NULL\n");
@ -67,7 +67,7 @@ t_map_entry *ll_pop_last(t_map_entry *head)
{ {
if (head->next == NULL) if (head->next == NULL)
{ {
retval = ll_map_new_node(head->key, head->value); retval = ll_map_new_entry(head->key, head->value);
free(head); free(head);
return (retval); return (retval);
} }
@ -76,7 +76,7 @@ t_map_entry *ll_pop_last(t_map_entry *head)
while (current->next->next != NULL) while (current->next->next != NULL)
current = current->next; 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); free(current->next);
current->next = NULL; current->next = NULL;
return (retval); return (retval);

View File

@ -6,13 +6,13 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */ /* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/01 08:52:17 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 #ifndef FT_IO_H
# define FT_IO_H # define FT_IO_H
int file_exists(char *path); int file_readable(char *path);
#endif #endif

View File

@ -6,7 +6,7 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */ /* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/01 15:25:59 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); char *ll_map_get(t_map_entry *head, char *key);
void ll_map_push(t_map_entry *head, char *key, char *value); void ll_map_push(t_map_entry *head, char *key, char *value);
void ll_clear(t_map_entry *head); 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); t_map_entry *ll_pop_last(t_map_entry *head);
#endif #endif

View File

@ -6,7 +6,7 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */ /* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/01 07:11:58 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 <stdio.h> #include <stdio.h>
#include "ft_io.h"
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
/* 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) int main(int argc, char **argv)
{ {
char *str_nbr; char *str_nbr;
@ -27,14 +65,7 @@ int main(int argc, char **argv)
return (puterr("Error\n", 1)); return (puterr("Error\n", 1));
// if (!parse_dict(path, map)) // if (!parse_dict(path, map))
// return (puterr("Dict Error\n", 2)); // return (puterr("Dict Error\n", 2));
t_map_entry *head = ll_map_new_node("hello", "world"); // ll_clear(map);
ll_map_push(head, "hello2", "world2"); parse_dict(path);
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); return (0);
} }