Compare commits

..

2 Commits

Author SHA1 Message Date
Aleksei Chubukov
9d56f17870 overtime 2023-12-07 20:07:15 +04:00
Aleksei Chubukov
1d9fc70142 overtime 2023-12-07 20:06:51 +04:00
9 changed files with 158 additions and 4 deletions

View File

@ -6,12 +6,12 @@
# By: achubuko <marvin@42.fr> +#+ +:+ +#+ # # By: achubuko <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/12/02 21:33:22 by achubuko #+# #+# # # Created: 2023/12/02 21:33:22 by achubuko #+# #+# #
# Updated: 2023/12/03 17:29:02 by achubuko ### ########.fr # # Updated: 2023/12/07 19:30:21 by achubuko ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
NAME=rush-02 NAME=rush-02
_CFLAGS = -Wall -Wextra -Werror _CFLAGS = -Wall -Wextra -fsanitize=address
CFLAGS = -g CFLAGS = -g
CFLAGS := $(_CFLAGS) $(CFLAGS) CFLAGS := $(_CFLAGS) $(CFLAGS)
##################################### #####################################
@ -20,7 +20,7 @@ CFLAGS := $(_CFLAGS) $(CFLAGS)
# all: default rule # all: default rule
# norme prerequisite is not mandatory # norme prerequisite is not mandatory
all: $(NAME) norme all: $(NAME)
# clean: Delete *.o for project and libraries # clean: Delete *.o for project and libraries
clean: clean:

39
ex00/dict_struct.c Normal file
View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* dict_struct.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/03 20:35:11 by achubuko #+# #+# */
/* Updated: 2023/12/03 23:07:41 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
#include "dict_struct.h"
t_dict *dict_create(void)
{
t_dict *d;
d = malloc(sizeof(t_dict));
d->size = 0;
return (d);
}
void dict_destroy(t_dict *dict)
{
free(dict);
}
void dict_update(t_dict *d, char *path)
{
}
t_dict *dict_create_default(char *path)
{
t_dict *d;
d = dict_create();
dict_update(d, path);
return (d);
}

34
ex00/dict_struct.h Normal file
View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* dict_struct.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/03 20:36:01 by achubuko #+# #+# */
/* Updated: 2023/12/03 22:20:58 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DICT_STRUCT_H
# define DICT_STRUCT_H
# include <stdlib.h>
typedef struct s_dictitem
{
unsigned int num_significant;
unsigned int num_base;
char *text;
} t_dictitem;
typedef struct s_dict
{
int size;
t_dictitem dict[42];
} t_dict;
t_dict *dict_create_default(char *path);
void dict_update(t_dict *d, char *path);
void dict_destroy(t_dict *dict);
void dict_init_default(t_dict *d, char *path);
t_dict *dict_create(void);
#endif

View File

@ -13,4 +13,5 @@
void print_digit_words(char *str) void print_digit_words(char *str)
{ {
///TODO:
} }

View File

@ -9,6 +9,7 @@
/* Updated: 2023/12/03 23:36:29 by achubuko ### ########.fr */ /* Updated: 2023/12/03 23:36:29 by achubuko ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "ft_open.h" #include "ft_open.h"
t_file *ft_open(char *path) t_file *ft_open(char *path)
@ -45,7 +46,7 @@ void ft_growbuffer(t_file *f, ssize_t grow)
cur[pos] = 0; cur[pos] = 0;
pos++; pos++;
} }
free(prev); // free(prev);
f->buffer = cur; f->buffer = cur;
} }

30
ex00/ft_open.h Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_open.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/03 19:51:40 by achubuko #+# #+# */
/* Updated: 2023/12/03 23:14:56 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_OPEN_H
# define FT_OPEN_H
# include <unistd.h>
# include <fcntl.h>
# include <stdlib.h>
typedef struct s_file
{
int descriptor;
char *read_window;
size_t read_window_cursor;
size_t read_window_size;
size_t read_size;
char *buffer;
size_t buffer_size;
} t_file;
t_file *ft_open(char *path);
char *ft_dispence_line(t_file *f);
#endif

View File

@ -41,6 +41,13 @@ int main(int argc, char **argv)
if (argc == 3) if (argc == 3)
dict_update(d, argv[2]); dict_update(d, argv[2]);
chk = invalid_arg_num(argv[1]); chk = invalid_arg_num(argv[1]);
t_file *file = ft_open(argv[1]);
ft_buffer_line(file);
printf("%s\n", file->buffer);
if (!chk) if (!chk)
print_digit_words(argv[1]); print_digit_words(argv[1]);
else else

View File

@ -16,4 +16,6 @@
# include "digits_to_words.h" # include "digits_to_words.h"
# include "ft_utils.h" # include "ft_utils.h"
# include "dict_struct.h" # include "dict_struct.h"
#include "ft_open.h"
#endif #endif

40
tests/test_ft_open.c Normal file
View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test_ft_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/03 22:39:20 by achubuko #+# #+# */
/* Updated: 2023/12/03 22:50:28 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
#include "unity.h"
#include "ft_open.h"
t_file *g_f;
void setUp(void)
{
g_f = ft_open("test_ft_open.txt");
}
void tearDown(void)
{
close(g_f->descriptor);
free(g_f);
}
void test_ft_dispence_line_once(void)
{
TEST_ASSERT_EQUAL_STRING("hello World!", ft_dispence_line(g_f));
}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_ft_dispence_line_once);
return (UNITY_END());
}