unfinished

This commit is contained in:
Aleksei Chubukov 2023-12-03 23:36:55 +04:00
parent cde0372716
commit b5efa9ea07
9 changed files with 121 additions and 45 deletions

View File

@ -6,7 +6,7 @@
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/02 23:40:54 by achubuko #+# #+# */
/* Updated: 2023/12/03 17:26:57 by achubuko ### ########.fr */
/* Updated: 2023/12/03 22:21:52 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
#include "digits_to_words.h"
@ -14,4 +14,3 @@
void print_digit_words(char *str)
{
}

View File

@ -6,11 +6,13 @@
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/02 23:35:43 by achubuko #+# #+# */
/* Updated: 2023/12/03 17:26:46 by achubuko ### ########.fr */
/* Updated: 2023/12/03 22:02:54 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DIGITS_TO_WORDS_H
# define DIGITS_TO_WORDS_H
# include "ft_utils.h"
# include "digits_to_words.h"
void print_digit_words(char *str);
#endif

View File

@ -6,22 +6,77 @@
/* By: asargsya <asargsya@student.42yerevan.am> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/03 19:08:11 by asargsya #+# #+# */
/* Updated: 2023/12/03 20:17:25 by achubuko ### ########.fr */
/* Updated: 2023/12/03 23:36:29 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_open.h"
void ft_dict_open(char *path)
t_file *ft_open(char *path)
{
int fd;
char buf[1024];
int buflen;
t_file *file;
fd = open(path, O_RDONLY);
buflen = read(fd, buf, 1024);
while (buflen > 0)
{
write(1, buf, buflen);
}
close(fd);
file = malloc(sizeof(t_file));
file->descriptor = open(path, O_RDONLY);
file->read_window_size = 4096;
file->read_window = malloc(sizeof(char) * file->read_window_size);
file->read_size = 0;
file->read_window_cursor = 0;
file->buffer = 0;
file->buffer_size = 0;
return (file);
}
void ft_growbuffer(t_file *f, ssize_t grow)
{
char *prev;
char *cur;
ssize_t pos;
prev = f->buffer;
cur = malloc(sizeof(char) * (f->buffer_size + grow));
pos = 0;
while (prev && cur && pos < f->buffer_size)
{
cur[pos] = prev[pos];
pos++;
}
while (cur && pos < f->buffer_size + grow)
{
cur[pos] = 0;
pos++;
}
free(prev);
f->buffer = cur;
}
ssize_t ft_churn(t_file *f)
{
f->read_size = read(f->descriptor, f->read_window, f->read_window_size);
f->read_window_cursor = 0;
return (f->read_size);
}
ssize_t ft_buffer_line(t_file *f)
{
char *c;
ssize_t len;
ft_growbuffer(f, 100);
len = 0;
c = 0;
while (1)
{
if (f->read_window_cursor >= f->read_size)
{
ft_churn(f);
}
f->buffer[len] = f->read_window[f->read_window_cursor];
if (len + 1 >= f->buffer_size)
ft_growbuffer(f, 100);
if (f->read_window[f->read_window_cursor] == '\n')
return (len);
len++;
f->read_window_cursor++;
}
return (0);
}

View File

@ -6,14 +6,21 @@
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/02 21:56:30 by achubuko #+# #+# */
/* Updated: 2023/12/03 18:14:54 by asargsya ### ########.fr */
/* Updated: 2023/12/03 21:58:36 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_utils.h"
uint32_t ft_atoui32(char *str)
t_dec ft_atoui32(char *str)
{
return (*str - '0');
t_dec dec;
dec.significant = 0;
dec.base = 1;
while (*str)
{
}
return (dec);
}
size_t ft_strlen(char *s)

View File

@ -6,7 +6,7 @@
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/02 21:57:06 by achubuko #+# #+# */
/* Updated: 2023/12/03 18:08:38 by achubuko ### ########.fr */
/* Updated: 2023/12/03 21:46:56 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_UTILS_H
@ -14,7 +14,12 @@
# include <stddef.h>
# include <stdint.h>
uint32_t ft_atoui32(char *str);
typedef struct s_dec
{
int significant;
int base;
} t_dec;
t_dec ft_atoui32(char *str);
size_t ft_strlen(char *s);
int ft_str_is_numeric(char *str);
#endif

View File

@ -6,30 +6,43 @@
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/02 21:01:21 by achubuko #+# #+# */
/* Updated: 2023/12/03 18:09:34 by achubuko ### ########.fr */
/* Updated: 2023/12/03 22:21:05 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
#include "main.h"
int main(int argc, char **argv)
int invalid_arg_num(char *arg)
{
if (argc <= 1 || argc > 3)
if (ft_str_is_numeric(arg) == 0)
{
write(1, "Error: program requires 1 or 2 arguments passed!", 48);
return (1);
write(1, "Argument #1 must be a number!\n", 29);
return (3);
}
if (ft_str_is_numeric(argv[1]) == 1)
else if (ft_str_is_numeric(arg) == -1)
{
print_digit_words(argv[1]);
}
else if (ft_str_is_numeric(argv[1]) == -1)
{
write(1, "Argument #1 must be positive!", 28);
write(1, "Argument #1 must be positive!\n", 29);
return (2);
}
else
{
write(1, "Argument #1 must be a number!", 28);
return (3);
}
return (0);
}
int main(int argc, char **argv)
{
int chk;
t_dict *d;
if (argc <= 1 || argc > 3)
{
write(1, "Error: program requires 1 or 2 arguments passed!\n", 49);
return (1);
}
d = dict_create_default("numbers.dict");
if (argc == 3)
dict_update(d, argv[2]);
chk = invalid_arg_num(argv[1]);
if (!chk)
print_digit_words(argv[1]);
else
return (chk);
}

View File

@ -6,7 +6,7 @@
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/02 21:14:25 by achubuko #+# #+# */
/* Updated: 2023/12/02 23:43:11 by achubuko ### ########.fr */
/* Updated: 2023/12/03 22:19:00 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MAIN_H
@ -15,4 +15,5 @@
# include <stdlib.h>
# include "digits_to_words.h"
# include "ft_utils.h"
# include "dict_struct.h"
#endif

View File

@ -6,10 +6,10 @@
# By: achubuko <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/02 22:04:03 by achubuko #+# #+# #
# Updated: 2023/12/02 23:31:12 by achubuko ### ########.fr #
# Updated: 2023/12/03 22:46:50 by achubuko ### ########.fr #
# #
# **************************************************************************** #
NAME := test_ft_utils
NAME := $(foreach f,$(wildcard test*.c),$(subst .c,,$f))
_CFLAGS = -Wall -Wextra -Werror
CFLAGS = -g
CFLAGS := $(_CFLAGS) $(CFLAGS) -I../ex00 -I../contrib/Unity/src/

View File

@ -6,7 +6,7 @@
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/02 22:12:42 by achubuko #+# #+# */
/* Updated: 2023/12/03 18:44:35 by achubuko ### ########.fr */
/* Updated: 2023/12/03 22:45:24 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
#include "unity.h"
@ -44,11 +44,6 @@ void test_ft_strlen(void)
TEST_ASSERT_EQUAL_INT(strlen(f), ft_strlen(f));
}
void test_ft_atoui32_42(void)
{
TEST_ASSERT_EQUAL_UINT32(42, ft_atoui32("42"));
}
int main(void)
{
UNITY_BEGIN();
@ -56,6 +51,5 @@ int main(void)
RUN_TEST(test_ft_str_is_numeric_num);
RUN_TEST(test_ft_str_is_numeric_nonnum);
RUN_TEST(test_ft_str_is_numeric_neg);
RUN_TEST(test_ft_atoui32_42);
return (UNITY_END());
}