From 20fcf7d906be662a37fba168f795a45f7d556a2b Mon Sep 17 00:00:00 2001 From: Alexey Chubukov Date: Tue, 28 Nov 2023 19:40:55 +0400 Subject: [PATCH] more stuff --- .editorconfig | 4 +++ Makefile | 4 ++- c02/ex01.c | 43 ++++++++++++++++---------- c02/ex02.c | 9 ++++++ c02/ex03.c | 9 ++++++ c02/ex04.c | 9 ++++++ c02/ex05.c | 9 ++++++ c02/ex06.c | 9 ++++++ c02/ex07.c | 9 ++++++ c02/ex08.c | 9 ++++++ c02/ex09.c | 9 ++++++ c02/ex10.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ common/tests.h | 5 +-- 13 files changed, 193 insertions(+), 19 deletions(-) create mode 100644 .editorconfig create mode 100644 c02/ex02.c create mode 100644 c02/ex03.c create mode 100644 c02/ex04.c create mode 100644 c02/ex05.c create mode 100644 c02/ex06.c create mode 100644 c02/ex07.c create mode 100644 c02/ex08.c create mode 100644 c02/ex09.c create mode 100644 c02/ex10.c diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f0eed7e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +root = true +[*] +indent_style = tab +indent_size = 4 diff --git a/Makefile b/Makefile index 31db7a2..d40e310 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,8 @@ all_builds := $(foreach e, 00 01 02 03 04 05 06 07 08, build/c00/ex$e) \ $(foreach e, 00 01 02 03 04 05 06 07 08, build/c01/ex$e) \ $(foreach e, 00 01 02 03 04 05 06 07 08 09 10 11 12, build/c02/ex$e) \ +MAKEFLAGS := -k + all: norme $(all_builds) build: mkdir $@ @@ -22,4 +24,4 @@ build/c%: $(OFFSHORE_PROJECTS)/c$$*/*.c $$(OFFSHORE_MAINS)/c$$*.c $$(wildcard $( mkdir -p $(@D) $(CC) -o $@ $(CFLAGS_MANDATORY) -Icommon $(CFLAGS) $^ norme: $$(wildcard $(OFFSHORE_PROJECTS)/c*) - norminette -R CheckForbiddenSourceHeader $^ + norminette $^ || true diff --git a/c02/ex01.c b/c02/ex01.c index a58ecb1..e4d2feb 100644 --- a/c02/ex01.c +++ b/c02/ex01.c @@ -1,25 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ex01.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: achubuko +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/27 21:57:45 by achubuko #+# #+# */ +/* Updated: 2023/11/27 21:59:11 by achubuko ### ########.fr */ +/* */ +/* ************************************************************************** */ #include "tests.h" -char *ft_strncpy(char*, char*, size_t); + +char *ft_strncpy(char*, char*, size_t); int main(void) { - char s1[100] = TEST_SOURCE; - char d1[100] = TEST_DESTINATION; - char*r1; - char s2[100] = TEST_SOURCE; - char d2[100] = TEST_DESTINATION; - char*r2; - char s3[100] = TEST_SOURCE; - char d3[100] = TEST_DESTINATION; - char*r3; - char s4[100] = TEST_SOURCE; - char d4[100] = TEST_DESTINATION; - char*r4; + char s1[100] = TEST_SOURCE; + char d1[100] = TEST_DESTINATION; + char *r1; + char s2[100] = TEST_SOURCE; + char d2[100] = TEST_DESTINATION; + char *r2; + char s3[100] = TEST_SOURCE; + char d3[100] = TEST_DESTINATION; + char *r3; + char s4[100] = TEST_SOURCE; + char d4[100] = TEST_DESTINATION; + char *r4; - printf("initial strings:\n"); dump(s1, TEST_SOURCE_LENGHT); dump(d1, TEST_DESTINATION_LENGHT); - r1 = strncpy(d1 ,s1, 4); + r1 = strncpy(d1 , s1, 4); printf("strncpy(d, s, 4):\n"); dump(s1, TEST_SOURCE_LENGHT); dump(d1, TEST_DESTINATION_LENGHT); @@ -28,7 +39,7 @@ int main(void) dump(s2, TEST_SOURCE_LENGHT); dump(d2, TEST_DESTINATION_LENGHT); printf("buffers comparison: s:%i d:%i\n", bufcmp(s1, s2, TEST_SOURCE_LENGHT), bufcmp(d1, d2, TEST_DESTINATION_LENGHT)); - r3 = strncpy(d3 ,s3, 20); + r3 = strncpy(d3 , s3, 20); printf("strncpy(d, s, 20):\n"); dump(s3, TEST_SOURCE_LENGHT); dump(d3, TEST_DESTINATION_LENGHT); diff --git a/c02/ex02.c b/c02/ex02.c new file mode 100644 index 0000000..114fd95 --- /dev/null +++ b/c02/ex02.c @@ -0,0 +1,9 @@ +#include + +int ft_str_is_alpha(char *str); + +int main(int argc, char **argv) +{ + if (argc == 2) + printf("%i\n", ft_str_is_alpha(argv[1])); +} diff --git a/c02/ex03.c b/c02/ex03.c new file mode 100644 index 0000000..a912f24 --- /dev/null +++ b/c02/ex03.c @@ -0,0 +1,9 @@ +#include + +int ft_str_is_numeric(char *str); + +int main(int argc, char **argv) +{ + if (argc == 2) + printf("%i\n", ft_str_is_numeric(argv[1])); +} diff --git a/c02/ex04.c b/c02/ex04.c new file mode 100644 index 0000000..afce489 --- /dev/null +++ b/c02/ex04.c @@ -0,0 +1,9 @@ +#include + +int ft_str_is_lowercase(char *str); + +int main(int argc, char **argv) +{ + if (argc == 2) + printf("%i\n", ft_str_is_lowercase(argv[1])); +} diff --git a/c02/ex05.c b/c02/ex05.c new file mode 100644 index 0000000..997713c --- /dev/null +++ b/c02/ex05.c @@ -0,0 +1,9 @@ +#include + +int ft_str_is_uppercase(char *str); + +int main(int argc, char **argv) +{ + if (argc == 2) + printf("%i\n", ft_str_is_uppercase(argv[1])); +} diff --git a/c02/ex06.c b/c02/ex06.c new file mode 100644 index 0000000..d538488 --- /dev/null +++ b/c02/ex06.c @@ -0,0 +1,9 @@ +#include + +int ft_str_is_printable(char *str); + +int main(int argc, char **argv) +{ + if (argc == 2) + printf("%i\n", ft_str_is_printable(argv[1])); +} diff --git a/c02/ex07.c b/c02/ex07.c new file mode 100644 index 0000000..b1ddd16 --- /dev/null +++ b/c02/ex07.c @@ -0,0 +1,9 @@ +#include + +char *ft_strupcase(char *str); + +int main(int argc, char **argv) +{ + if (argc == 2) + printf("%s\n", ft_strupcase(argv[1])); +} diff --git a/c02/ex08.c b/c02/ex08.c new file mode 100644 index 0000000..17730f3 --- /dev/null +++ b/c02/ex08.c @@ -0,0 +1,9 @@ +#include + +char *ft_strlowcase(char *str); + +int main(int argc, char **argv) +{ + if (argc == 2) + printf("%s\n", ft_strlowcase(argv[1])); +} diff --git a/c02/ex09.c b/c02/ex09.c new file mode 100644 index 0000000..8ff9fa7 --- /dev/null +++ b/c02/ex09.c @@ -0,0 +1,9 @@ +#include + +char *ft_strcapitalize(char *str); + +int main(int argc, char **argv) +{ + if (argc == 2) + printf("%s\n", ft_strcapitalize(argv[1])); +} diff --git a/c02/ex10.c b/c02/ex10.c new file mode 100644 index 0000000..1acbbbf --- /dev/null +++ b/c02/ex10.c @@ -0,0 +1,84 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ex10.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: achubuko +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/28 01:25:43 by achubuko #+# #+# */ +/* Updated: 2023/11/28 01:26:11 by achubuko ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#define TEST_BUF_SIZE 100 + +unsigned int ft_strlcpy(char *dest, char *src, unsigned int size); + +int main(void) +{ + char s[TEST_BUF_SIZE] = TEST_SOURCE; + char d[TEST_BUF_SIZE] = TEST_DESTINATION; + size_t r1; + char s1[TEST_BUF_SIZE] = TEST_SOURCE; + char d1[TEST_BUF_SIZE] = TEST_DESTINATION; + size_t r2; + char s2[TEST_BUF_SIZE] = TEST_SOURCE; + char d2[TEST_BUF_SIZE] = TEST_DESTINATION; + + printf("initial strings:\n"); + dump(s, TEST_SOURCE_LENGHT); + dump(d, TEST_DESTINATION_LENGHT); + + printf("strlcpy(d, s, 4):\n"); + r1 = strlcpy(d1, s1, 4); + dump(s1, TEST_SOURCE_LENGHT); + dump(d1, TEST_DESTINATION_LENGHT); + printf("ft_strlcpy(d, s, 4:\n"); + r2 = ft_strlcpy(d2, s2, 4); + dump(s2, TEST_SOURCE_LENGHT); + dump(d2, TEST_DESTINATION_LENGHT); + printf("buffers comparison: s:%i d:%i\n", + bufcmp(s1, s2, TEST_SOURCE_LENGHT), + bufcmp(d1, d2, TEST_DESTINATION_LENGHT)); + printf("return values: orig: %lu ft: %lu\n", r1, r2); + memcpy(d1, d, TEST_BUF_SIZE); + memcpy(s1, s, TEST_BUF_SIZE); + memcpy(d2, d, TEST_BUF_SIZE); + memcpy(s2, s, TEST_BUF_SIZE); + + printf("strlcpy(d, s, 20):\n"); + r1 = strlcpy(d1, s1, 20); + dump(s1, TEST_SOURCE_LENGHT); + dump(d1, TEST_DESTINATION_LENGHT); + printf("ft_strlcpy(d, s, 20):\n"); + r2 = ft_strlcpy(d2, s2, 20); + dump(s2, TEST_SOURCE_LENGHT); + dump(d2, TEST_DESTINATION_LENGHT); + memcpy(d1, d, TEST_BUF_SIZE); + memcpy(s1, s, TEST_BUF_SIZE); + memcpy(d2, d, TEST_BUF_SIZE); + memcpy(s2, s, TEST_BUF_SIZE); + printf("buffers comparison: s:%i d:%i\n", + bufcmp(s1, s2, TEST_SOURCE_LENGHT), + bufcmp(d1, d2, TEST_DESTINATION_LENGHT)); + printf("return values: orig: %lu ft: %lu\n", r1, r2); + + printf("strlcpy(s, d, 20):\n"); + r1 = strlcpy(s1, d1, 20); + dump(s1, TEST_SOURCE_LENGHT); + dump(d1, TEST_DESTINATION_LENGHT); + printf("ft_strlcpy(s, d, 20):\n"); + r2 = ft_strlcpy(s2, d2, 20); + dump(s2, TEST_SOURCE_LENGHT); + dump(d2, TEST_DESTINATION_LENGHT); + memcpy(d1, d, TEST_BUF_SIZE); + memcpy(s1, s, TEST_BUF_SIZE); + memcpy(d2, d, TEST_BUF_SIZE); + memcpy(s2, s, TEST_BUF_SIZE); + printf("buffers comparison: s:%i d:%i\n", + bufcmp(s1, s2, TEST_SOURCE_LENGHT), + bufcmp(d1, d2, TEST_DESTINATION_LENGHT)); + printf("return values: orig: %lu ft: %lu\n", r1, r2); +} diff --git a/common/tests.h b/common/tests.h index ad40d89..fd0c054 100644 --- a/common/tests.h +++ b/common/tests.h @@ -10,5 +10,6 @@ #define FG_MAG "\x1B[35m" #define COLOR_RESET "\x1B[0m" #endif -int bufcmp(char *this, char *other, int len); -void dump(char *data, int len); + +int bufcmp(char*, char*, int); +void dump(char*, int);