From 6d1cf4d1369abebdd8b2ca3f0476436cd8209343 Mon Sep 17 00:00:00 2001 From: grignetta <121875111+grignetta@users.noreply.github.com> Date: Fri, 29 Aug 2025 08:33:42 +0200 Subject: [PATCH 01/18] Remove embedded libft to replace with submodule --- .../allocs_and_frees.h | 0 builtins.h => include/builtins.h | 0 env.h => include/env.h | 0 exec.h => include/exec.h | 0 lexer_parser.h => include/lexer_parser.h | 0 minishell.h => include/minishell.h | 0 quotes.h => include/quotes.h | 0 redirections.h => include/redirections.h | 0 structs.h => include/structs.h | 0 utils.h => include/utils.h | 0 libft/.DS_Store | Bin 6148 -> 0 bytes libft/Makefile | 99 --------------- libft/ft_atoi | Bin 19528 -> 0 bytes libft/ft_atoi.c | 49 -------- libft/ft_bzero.c | 25 ---- libft/ft_calloc.c | 24 ---- libft/ft_exact_strcmp.c | 20 --- libft/ft_isalnum.c | 23 ---- libft/ft_isalpha.c | 22 ---- libft/ft_isascii.c | 21 ---- libft/ft_isdigit.c | 21 ---- libft/ft_isprint.c | 21 ---- libft/ft_itoa.c | 80 ------------ libft/ft_memchr.c | 29 ----- libft/ft_memcmp.c | 34 ----- libft/ft_memcpy.c | 28 ----- libft/ft_memmove.c | 40 ------ libft/ft_memset | Bin 19368 -> 0 bytes libft/ft_memset.c | 26 ---- libft/ft_print_char.c | 19 --- libft/ft_print_char_fd.c | 19 --- libft/ft_print_hex.c | 62 ---------- libft/ft_print_hex_fd.c | 62 ---------- libft/ft_print_int.c | 64 ---------- libft/ft_print_int_fd.c | 64 ---------- libft/ft_print_percent.c | 19 --- libft/ft_print_percent_fd.c | 19 --- libft/ft_print_ptr.c | 58 --------- libft/ft_print_ptr_fd.c | 58 --------- libft/ft_print_str.c | 29 ----- libft/ft_print_str_fd.c | 29 ----- libft/ft_print_unsign_int.c | 62 ---------- libft/ft_print_unsign_int_fd.c | 62 ---------- libft/ft_printf.c | 69 ----------- libft/ft_printf.h | 40 ------ libft/ft_printf_fd.c | 96 --------------- libft/ft_printf_fd.h | 40 ------ libft/ft_putchar_fd.c | 18 --- libft/ft_putendl_fd.c | 25 ---- libft/ft_putnbr_fd.c | 31 ----- libft/ft_putstr_fd.c | 25 ---- libft/ft_realloc.c | 35 ------ libft/ft_split.c | 83 ------------- libft/ft_strcat.c | 32 ----- libft/ft_strchr.c | 35 ------ libft/ft_strcmp.c | 23 ---- libft/ft_strcpy.c | 28 ----- libft/ft_strdup.c | 33 ----- libft/ft_striteri.c | 27 ---- libft/ft_strjoin.c | 37 ------ libft/ft_strlcat.c | 39 ------ libft/ft_strlcpy.c | 35 ------ libft/ft_strlen.c | 26 ---- libft/ft_strmapi.c | 33 ----- libft/ft_strncat.c | 30 ----- libft/ft_strncmp.c | 28 ----- libft/ft_strncpy.c | 31 ----- libft/ft_strndup.c | 29 ----- libft/ft_strnstr.c | 39 ------ libft/ft_strpbrk.c | 26 ---- libft/ft_strrchr.c | 27 ---- libft/ft_strtok.c | 71 ----------- libft/ft_strtrim.c | 56 --------- libft/ft_substr.c | 48 -------- libft/ft_tolower.c | 20 --- libft/ft_toupper.c | 20 --- libft/get_next_line.c | 116 ------------------ libft/get_next_line_utils.c | 66 ---------- libft/libft.h | 97 --------------- .../builtins/exec_builtins.c | 0 .../builtins/exec_builtins_cd.c | 0 .../builtins/exec_builtins_echo.c | 0 .../builtins/exec_builtins_env.c | 0 .../builtins/exec_builtins_exit.c | 0 .../builtins/exec_builtins_export.c | 0 .../builtins/exec_builtins_export_utils.c | 0 .../builtins/exec_builtins_pwd.c | 0 .../builtins/exec_builtins_unset.c | 0 env_handling.c => src/env/env_handling.c | 0 env_main.c => src/env/env_main.c | 0 env_utils.c => src/env/env_utils.c | 0 execute_node.c => src/exec/execute_node.c | 0 .../exec/execute_node_error_messages.c | 0 .../exec/execute_node_exec_cmd.c | 0 .../exec/execute_node_handle_child_cmd.c | 0 .../exec/execute_node_handle_heredoc.c | 0 .../exec/execute_node_handle_heredoc_utils.c | 0 .../exec/execute_node_handle_redirect.c | 0 .../exec/execute_node_handle_redirect_error.c | 0 .../exec/execute_node_handle_redirect_utils.c | 0 .../exec/execute_node_utils.c | 0 .../exec/execute_parse_tree.c | 0 .../exec/execute_pipeline_utils.c | 0 .../exec/execute_pipeline_utils_1.c | 0 .../expand/handle_dollar_sign.c | 0 .../expand/handle_dollar_sign_utils.c | 0 .../expand/handle_quotes_main_1.c | 0 .../expand/handle_quotes_main_2.c | 0 .../expand/handle_quotes_redirect.c | 0 .../expand/handle_quotes_utils_1.c | 0 .../expand/handle_quotes_utils_2.c | 0 free_functions.c => src/free/free_functions.c | 0 .../free/free_functions_1.c | 0 .../heredoc/pipeline_here_doc_dol_closed.c | 0 .../heredoc/pipeline_here_doc_dol_open.c | 0 .../heredoc/pipeline_here_doc_main.c | 0 lexer.c => src/lexer/lexer.c | 0 lexer_main.c => src/lexer/lexer_main.c | 0 error_handling.c => src/main/error_handling.c | 0 init_1.c => src/main/init_1.c | 0 init_2.c => src/main/init_2.c | 0 main.c => src/main/main.c | 0 .../main/main_handle_input.c | 0 signals.c => src/main/signals.c | 0 .../parser/parser_is_all_rest.c | 0 .../parser/parser_is_cmd_suffix.c | 0 parser_main.c => src/parser/parser_main.c | 0 parser_utils.c => src/parser/parser_utils.c | 0 .../path/get_path_for_exec.c | 0 .../path/get_path_for_exec_colon.c | 0 .../path/get_path_for_exec_utils.c | 0 {test_files => tests/test_files}/empty | 0 .../test_files}/file name with spaces | 0 {test_files => tests/test_files}/infile | 0 {test_files => tests/test_files}/infile_big | 0 .../test_files}/invalid_permission | 0 {test_files => tests/test_files}/loop | Bin {test_files => tests/test_files}/loop.c | 0 m_suppress => tools/suppress/m_suppress | 0 suppress => tools/suppress/suppress | 0 suppress_lnx => tools/suppress/suppress_lnx | 0 suppress_mac => tools/suppress/suppress_mac | 0 142 files changed, 2702 deletions(-) rename allocs_and_frees.h => include/allocs_and_frees.h (100%) rename builtins.h => include/builtins.h (100%) rename env.h => include/env.h (100%) rename exec.h => include/exec.h (100%) rename lexer_parser.h => include/lexer_parser.h (100%) rename minishell.h => include/minishell.h (100%) rename quotes.h => include/quotes.h (100%) rename redirections.h => include/redirections.h (100%) rename structs.h => include/structs.h (100%) rename utils.h => include/utils.h (100%) delete mode 100644 libft/.DS_Store delete mode 100644 libft/Makefile delete mode 100755 libft/ft_atoi delete mode 100644 libft/ft_atoi.c delete mode 100644 libft/ft_bzero.c delete mode 100644 libft/ft_calloc.c delete mode 100644 libft/ft_exact_strcmp.c delete mode 100644 libft/ft_isalnum.c delete mode 100644 libft/ft_isalpha.c delete mode 100644 libft/ft_isascii.c delete mode 100644 libft/ft_isdigit.c delete mode 100644 libft/ft_isprint.c delete mode 100644 libft/ft_itoa.c delete mode 100644 libft/ft_memchr.c delete mode 100644 libft/ft_memcmp.c delete mode 100644 libft/ft_memcpy.c delete mode 100644 libft/ft_memmove.c delete mode 100755 libft/ft_memset delete mode 100644 libft/ft_memset.c delete mode 100644 libft/ft_print_char.c delete mode 100644 libft/ft_print_char_fd.c delete mode 100644 libft/ft_print_hex.c delete mode 100644 libft/ft_print_hex_fd.c delete mode 100644 libft/ft_print_int.c delete mode 100644 libft/ft_print_int_fd.c delete mode 100644 libft/ft_print_percent.c delete mode 100644 libft/ft_print_percent_fd.c delete mode 100644 libft/ft_print_ptr.c delete mode 100644 libft/ft_print_ptr_fd.c delete mode 100644 libft/ft_print_str.c delete mode 100644 libft/ft_print_str_fd.c delete mode 100644 libft/ft_print_unsign_int.c delete mode 100644 libft/ft_print_unsign_int_fd.c delete mode 100644 libft/ft_printf.c delete mode 100644 libft/ft_printf.h delete mode 100644 libft/ft_printf_fd.c delete mode 100644 libft/ft_printf_fd.h delete mode 100644 libft/ft_putchar_fd.c delete mode 100644 libft/ft_putendl_fd.c delete mode 100644 libft/ft_putnbr_fd.c delete mode 100644 libft/ft_putstr_fd.c delete mode 100644 libft/ft_realloc.c delete mode 100644 libft/ft_split.c delete mode 100644 libft/ft_strcat.c delete mode 100644 libft/ft_strchr.c delete mode 100644 libft/ft_strcmp.c delete mode 100644 libft/ft_strcpy.c delete mode 100644 libft/ft_strdup.c delete mode 100644 libft/ft_striteri.c delete mode 100644 libft/ft_strjoin.c delete mode 100644 libft/ft_strlcat.c delete mode 100644 libft/ft_strlcpy.c delete mode 100644 libft/ft_strlen.c delete mode 100644 libft/ft_strmapi.c delete mode 100644 libft/ft_strncat.c delete mode 100644 libft/ft_strncmp.c delete mode 100644 libft/ft_strncpy.c delete mode 100644 libft/ft_strndup.c delete mode 100644 libft/ft_strnstr.c delete mode 100644 libft/ft_strpbrk.c delete mode 100644 libft/ft_strrchr.c delete mode 100644 libft/ft_strtok.c delete mode 100644 libft/ft_strtrim.c delete mode 100644 libft/ft_substr.c delete mode 100644 libft/ft_tolower.c delete mode 100644 libft/ft_toupper.c delete mode 100644 libft/get_next_line.c delete mode 100644 libft/get_next_line_utils.c delete mode 100644 libft/libft.h rename exec_builtins.c => src/builtins/exec_builtins.c (100%) rename exec_builtins_cd.c => src/builtins/exec_builtins_cd.c (100%) rename exec_builtins_echo.c => src/builtins/exec_builtins_echo.c (100%) rename exec_builtins_env.c => src/builtins/exec_builtins_env.c (100%) rename exec_builtins_exit.c => src/builtins/exec_builtins_exit.c (100%) rename exec_builtins_export.c => src/builtins/exec_builtins_export.c (100%) rename exec_builtins_export_utils.c => src/builtins/exec_builtins_export_utils.c (100%) rename exec_builtins_pwd.c => src/builtins/exec_builtins_pwd.c (100%) rename exec_builtins_unset.c => src/builtins/exec_builtins_unset.c (100%) rename env_handling.c => src/env/env_handling.c (100%) rename env_main.c => src/env/env_main.c (100%) rename env_utils.c => src/env/env_utils.c (100%) rename execute_node.c => src/exec/execute_node.c (100%) rename execute_node_error_messages.c => src/exec/execute_node_error_messages.c (100%) rename execute_node_exec_cmd.c => src/exec/execute_node_exec_cmd.c (100%) rename execute_node_handle_child_cmd.c => src/exec/execute_node_handle_child_cmd.c (100%) rename execute_node_handle_heredoc.c => src/exec/execute_node_handle_heredoc.c (100%) rename execute_node_handle_heredoc_utils.c => src/exec/execute_node_handle_heredoc_utils.c (100%) rename execute_node_handle_redirect.c => src/exec/execute_node_handle_redirect.c (100%) rename execute_node_handle_redirect_error.c => src/exec/execute_node_handle_redirect_error.c (100%) rename execute_node_handle_redirect_utils.c => src/exec/execute_node_handle_redirect_utils.c (100%) rename execute_node_utils.c => src/exec/execute_node_utils.c (100%) rename execute_parse_tree.c => src/exec/execute_parse_tree.c (100%) rename execute_pipeline_utils.c => src/exec/execute_pipeline_utils.c (100%) rename execute_pipeline_utils_1.c => src/exec/execute_pipeline_utils_1.c (100%) rename handle_dollar_sign.c => src/expand/handle_dollar_sign.c (100%) rename handle_dollar_sign_utils.c => src/expand/handle_dollar_sign_utils.c (100%) rename handle_quotes_main_1.c => src/expand/handle_quotes_main_1.c (100%) rename handle_quotes_main_2.c => src/expand/handle_quotes_main_2.c (100%) rename handle_quotes_redirect.c => src/expand/handle_quotes_redirect.c (100%) rename handle_quotes_utils_1.c => src/expand/handle_quotes_utils_1.c (100%) rename handle_quotes_utils_2.c => src/expand/handle_quotes_utils_2.c (100%) rename free_functions.c => src/free/free_functions.c (100%) rename free_functions_1.c => src/free/free_functions_1.c (100%) rename pipeline_here_doc_dol_closed.c => src/heredoc/pipeline_here_doc_dol_closed.c (100%) rename pipeline_here_doc_dol_open.c => src/heredoc/pipeline_here_doc_dol_open.c (100%) rename pipeline_here_doc_main.c => src/heredoc/pipeline_here_doc_main.c (100%) rename lexer.c => src/lexer/lexer.c (100%) rename lexer_main.c => src/lexer/lexer_main.c (100%) rename error_handling.c => src/main/error_handling.c (100%) rename init_1.c => src/main/init_1.c (100%) rename init_2.c => src/main/init_2.c (100%) rename main.c => src/main/main.c (100%) rename main_handle_input.c => src/main/main_handle_input.c (100%) rename signals.c => src/main/signals.c (100%) rename parser_is_all_rest.c => src/parser/parser_is_all_rest.c (100%) rename parser_is_cmd_suffix.c => src/parser/parser_is_cmd_suffix.c (100%) rename parser_main.c => src/parser/parser_main.c (100%) rename parser_utils.c => src/parser/parser_utils.c (100%) rename get_path_for_exec.c => src/path/get_path_for_exec.c (100%) rename get_path_for_exec_colon.c => src/path/get_path_for_exec_colon.c (100%) rename get_path_for_exec_utils.c => src/path/get_path_for_exec_utils.c (100%) rename {test_files => tests/test_files}/empty (100%) rename {test_files => tests/test_files}/file name with spaces (100%) rename {test_files => tests/test_files}/infile (100%) rename {test_files => tests/test_files}/infile_big (100%) rename {test_files => tests/test_files}/invalid_permission (100%) rename {test_files => tests/test_files}/loop (100%) rename {test_files => tests/test_files}/loop.c (100%) rename m_suppress => tools/suppress/m_suppress (100%) rename suppress => tools/suppress/suppress (100%) rename suppress_lnx => tools/suppress/suppress_lnx (100%) rename suppress_mac => tools/suppress/suppress_mac (100%) diff --git a/allocs_and_frees.h b/include/allocs_and_frees.h similarity index 100% rename from allocs_and_frees.h rename to include/allocs_and_frees.h diff --git a/builtins.h b/include/builtins.h similarity index 100% rename from builtins.h rename to include/builtins.h diff --git a/env.h b/include/env.h similarity index 100% rename from env.h rename to include/env.h diff --git a/exec.h b/include/exec.h similarity index 100% rename from exec.h rename to include/exec.h diff --git a/lexer_parser.h b/include/lexer_parser.h similarity index 100% rename from lexer_parser.h rename to include/lexer_parser.h diff --git a/minishell.h b/include/minishell.h similarity index 100% rename from minishell.h rename to include/minishell.h diff --git a/quotes.h b/include/quotes.h similarity index 100% rename from quotes.h rename to include/quotes.h diff --git a/redirections.h b/include/redirections.h similarity index 100% rename from redirections.h rename to include/redirections.h diff --git a/structs.h b/include/structs.h similarity index 100% rename from structs.h rename to include/structs.h diff --git a/utils.h b/include/utils.h similarity index 100% rename from utils.h rename to include/utils.h diff --git a/libft/.DS_Store b/libft/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 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 V*QzVYLVT98|J5ExYv4od{|9fzo+tnS diff --git a/libft/ft_atoi.c b/libft/ft_atoi.c deleted file mode 100644 index 0a2602a..0000000 --- a/libft/ft_atoi.c +++ /dev/null @@ -1,49 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_atoi.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov = 9 && **nptr <= 13))) - (*nptr)++; - if (**nptr == '-') - (*minus)++; - if (**nptr == '-' || **nptr == '+') - (*nptr)++; - while (**nptr == '0') - (*nptr)++; -} - -int ft_atoi(const char *nptr) -{ - int minus; - long long int number; - - number = 0; - minus = 0; - move_spaces(&nptr, &minus); - if (ft_strcmp(nptr, "9223372036854775808") == 0 && minus == 1) - return (INT_MIN); - if ((*nptr <= 47) || (*nptr >= 58 && *nptr < 127)) - return (0); - while (*nptr >= '0' && *nptr <= '9') - { - if (number > (LLONG_MAX - (*nptr - '0')) / 10) - return (INT_MAX); - number = number * 10 + (*nptr - '0'); - nptr++; - } - if (minus == 1 && number != 0) - return (-number); - return (number); -} diff --git a/libft/ft_bzero.c b/libft/ft_bzero.c deleted file mode 100644 index 107a23d..0000000 --- a/libft/ft_bzero.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_bzero.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/06 12:24:58 by mmasarov #+# #+# */ -/* Updated: 2023/09/07 09:57:58 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_bzero(void *s, size_t n) -{ - size_t i; - - i = 0; - while (i < n) - { - ((unsigned char *)s)[i] = 0; - i++; - } -} diff --git a/libft/ft_calloc.c b/libft/ft_calloc.c deleted file mode 100644 index 9ca4a3e..0000000 --- a/libft/ft_calloc.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_calloc.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/13 09:22:59 by mmasarov #+# #+# */ -/* Updated: 2023/09/13 10:01:52 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_calloc(size_t nmemb, size_t size) -{ - void *ptr; - - ptr = (void *)malloc(nmemb * size); - if (!ptr) - return (0); - ft_memset(ptr, 0, (nmemb * size)); - return (ptr); -} diff --git a/libft/ft_exact_strcmp.c b/libft/ft_exact_strcmp.c deleted file mode 100644 index 6766403..0000000 --- a/libft/ft_exact_strcmp.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_exact_strcmp.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/06 10:12:34 by mmasarov #+# #+# */ -/* Updated: 2023/09/06 10:25:27 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isalnum(int c) -{ - if ((c >= 'a' && c <= 'z') - || (c >= 'A' && c <= 'Z') - || (c >= '0' && c <= '9')) - return (8); - else - return (0); -} diff --git a/libft/ft_isalpha.c b/libft/ft_isalpha.c deleted file mode 100644 index b91d3c0..0000000 --- a/libft/ft_isalpha.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isalpha.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/06 09:26:15 by mmasarov #+# #+# */ -/* Updated: 2023/09/13 15:51:28 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isalpha(int c) -{ - if ((c >= 'a' && c <= 'z') - || (c >= 'A' && c <= 'Z')) - return (1024); - else - return (0); -} diff --git a/libft/ft_isascii.c b/libft/ft_isascii.c deleted file mode 100644 index 15528c5..0000000 --- a/libft/ft_isascii.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isascii.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/06 10:26:04 by mmasarov #+# #+# */ -/* Updated: 2023/09/06 10:44:18 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isascii(int c) -{ - if (c >= 0 && c <= 127) - return (1); - else - return (0); -} diff --git a/libft/ft_isdigit.c b/libft/ft_isdigit.c deleted file mode 100644 index a9f6b17..0000000 --- a/libft/ft_isdigit.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isdigit.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/06 10:00:37 by mmasarov #+# #+# */ -/* Updated: 2023/09/06 10:11:18 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isdigit(int c) -{ - if (c >= '0' && c <= '9') - return (2048); - else - return (0); -} diff --git a/libft/ft_isprint.c b/libft/ft_isprint.c deleted file mode 100644 index f6ac899..0000000 --- a/libft/ft_isprint.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isprint.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/06 10:45:00 by mmasarov #+# #+# */ -/* Updated: 2023/09/06 10:48:23 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isprint(int c) -{ - if (c >= 32 && c <= 126) - return (16384); - else - return (0); -} diff --git a/libft/ft_itoa.c b/libft/ft_itoa.c deleted file mode 100644 index 2e8fb03..0000000 --- a/libft/ft_itoa.c +++ /dev/null @@ -1,80 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_itoa.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/12 11:40:53 by mmasarov #+# #+# */ -/* Updated: 2023/09/12 13:03:16 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static int ft_numlen(int num) -{ - int count; - - count = 0; - if (num == -2147483648 || num == 2147483647) - { - count = 10; - return (count); - } - if (num == 0) - count = 1; - while (num) - { - num = num / 10; - count++; - } - return (count); -} - -static int ft_is_negative(int n) -{ - int minus; - - minus = 0; - if (n < 0) - minus = 1; - return (minus); -} - -static char *ft_digits(void) -{ - char *digits; - - digits = "0123456789"; - return (digits); -} - -char *ft_itoa(int n) -{ - char *num_str; - size_t len; - int minus; - - minus = ft_is_negative(n); - if (n < 0) - n = n * (-1); - len = ft_numlen(n) + minus; - num_str = malloc((sizeof(char) * (len + 1))); - if (num_str == NULL) - return (NULL); - if (n == -2147483648) - { - num_str = ft_strcpy(num_str, "-2147483648"); - return (num_str); - } - num_str[len] = '\0'; - while (len-- > (unsigned int)minus) - { - num_str[len] = ft_digits()[n % 10]; - n /= 10; - } - if (minus == 1) - num_str[len] = '-'; - return (num_str); -} diff --git a/libft/ft_memchr.c b/libft/ft_memchr.c deleted file mode 100644 index d86b2bd..0000000 --- a/libft/ft_memchr.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/07 11:57:01 by mmasarov #+# #+# */ -/* Updated: 2023/09/07 13:35:21 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memchr(const void *s, int c, size_t n) -{ - size_t i; - char *string; - - i = 0; - string = (void *)s; - while (i < n) - { - if (string[i] == (char)c) - return (&string[i]); - i++; - } - return (NULL); -} diff --git a/libft/ft_memcmp.c b/libft/ft_memcmp.c deleted file mode 100644 index b0d67c8..0000000 --- a/libft/ft_memcmp.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memcmp.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/07 13:35:55 by mmasarov #+# #+# */ -/* Updated: 2023/09/07 13:57:32 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_memcmp(const void *s1, const void *s2, size_t n) -{ - char *str1; - char *str2; - size_t i; - - i = 0; - if (n == 0) - return (0); - str1 = (void *)s1; - str2 = (void *)s2; - while (i < n) - { - if ((unsigned char)str1[i] < (unsigned char)str2[i] - || (unsigned char)str1[i] > (unsigned char)str2[i]) - return ((unsigned char)str1[i] - (unsigned char)str2[i]); - i++; - } - return (0); -} diff --git a/libft/ft_memcpy.c b/libft/ft_memcpy.c deleted file mode 100644 index 172208c..0000000 --- a/libft/ft_memcpy.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memcpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/06 13:14:51 by mmasarov #+# #+# */ -/* Updated: 2023/09/07 09:57:26 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memcpy(void *dest, const void *src, size_t n) -{ - size_t i; - - i = 0; - if (!dest && !src) - return (0); - while (i < n) - { - ((unsigned char *)dest)[i] = ((unsigned char *)src)[i]; - i++; - } - return (dest); -} diff --git a/libft/ft_memmove.c b/libft/ft_memmove.c deleted file mode 100644 index 1e68dd0..0000000 --- a/libft/ft_memmove.c +++ /dev/null @@ -1,40 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memmove.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/06 14:11:01 by mmasarov #+# #+# */ -/* Updated: 2023/09/13 15:53:55 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memmove(void *dest, const void *src, size_t n) -{ - char *d; - char *s; - size_t i; - - d = (char *)dest; - s = (char *)src; - i = 0; - if (src < dest) - { - while (n--) - { - d[n] = s[n]; - } - } - else if (src > dest) - { - while (n--) - { - d[i] = s[i]; - i++; - } - } - return (dest); -} diff --git a/libft/ft_memset b/libft/ft_memset deleted file mode 100755 index ccbfdd19c7b1ade5eacfbaa1ae05a8973b89823e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 19368 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 D{7*nU diff --git a/libft/ft_memset.c b/libft/ft_memset.c deleted file mode 100644 index 1409a0a..0000000 --- a/libft/ft_memset.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memset.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/06 11:16:16 by mmasarov #+# #+# */ -/* Updated: 2023/09/13 15:53:06 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memset(void *s, int c, size_t n) -{ - size_t i; - - i = 0; - while (i < n) - { - ((unsigned char *)s)[i] = c; - i++; - } - return (s); -} diff --git a/libft/ft_print_char.c b/libft/ft_print_char.c deleted file mode 100644 index 8409bff..0000000 --- a/libft/ft_print_char.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_char.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:36:38 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:38:00 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf.h" - -int ft_print_char(char c) -{ - write (1, &c, 1); - return (1); -} diff --git a/libft/ft_print_char_fd.c b/libft/ft_print_char_fd.c deleted file mode 100644 index 7372de7..0000000 --- a/libft/ft_print_char_fd.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_char.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:36:38 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:38:00 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf_fd.h" - -int ft_print_char_fd(unsigned int fd, char c) -{ - write (fd, &c, 1); - return (1); -} diff --git a/libft/ft_print_hex.c b/libft/ft_print_hex.c deleted file mode 100644 index 077ade9..0000000 --- a/libft/ft_print_hex.c +++ /dev/null @@ -1,62 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_hex.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:38:19 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:45:02 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf.h" - -int ft_hex_len(unsigned int num) -{ - int size; - - size = 0; - while (num) - { - num = num / 16; - size++; - } - return (size); -} - -void ft_put_hex(unsigned int num, char placeholder) -{ - if (num >= 16) - { - ft_put_hex(num / 16, placeholder); - ft_put_hex(num % 16, placeholder); - } - else - { - if (num <= 9) - ft_print_char(num + '0'); - else - { - if (placeholder == 'x') - ft_print_char(num - 10 + 'a'); - else if (placeholder == 'X') - ft_print_char(num - 10 + 'A'); - } - } -} - -int ft_print_hex(unsigned int num, char placeholder) -{ - int return_len; - - return_len = 0; - if (num == 0) - return_len += write(1, "0", 1); - else - { - return_len += ft_hex_len(num); - ft_put_hex(num, placeholder); - } - return (return_len); -} diff --git a/libft/ft_print_hex_fd.c b/libft/ft_print_hex_fd.c deleted file mode 100644 index 5bcf5c4..0000000 --- a/libft/ft_print_hex_fd.c +++ /dev/null @@ -1,62 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_hex.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:38:19 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:45:02 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf_fd.h" - -int ft_hex_len(unsigned int num) -{ - int size; - - size = 0; - while (num) - { - num = num / 16; - size++; - } - return (size); -} - -void ft_put_hex_fd(unsigned int fd, unsigned int num, char placeholder) -{ - if (num >= 16) - { - ft_put_hex_fd(fd, num / 16, placeholder); - ft_put_hex_fd(fd, num % 16, placeholder); - } - else - { - if (num <= 9) - ft_print_char_fd(fd, num + '0'); - else - { - if (placeholder == 'x') - ft_print_char_fd(fd, num - 10 + 'a'); - else if (placeholder == 'X') - ft_print_char_fd(fd, num - 10 + 'A'); - } - } -} - -int ft_print_hex_fd(unsigned int fd, unsigned int num, char placeholder) -{ - int return_len; - - return_len = 0; - if (num == 0) - return_len += write(fd, "0", 1); - else - { - return_len += ft_hex_len(num); - ft_put_hex_fd(fd, num, placeholder); - } - return (return_len); -} diff --git a/libft/ft_print_int.c b/libft/ft_print_int.c deleted file mode 100644 index 6f09bf0..0000000 --- a/libft/ft_print_int.c +++ /dev/null @@ -1,64 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_int.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:53:47 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:56:53 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf.h" - -int ft_int_len(int num) -{ - int size; - - size = 0; - if (num < 0) - { - num *= -1; - size += 1; - } - if (num == 0) - size += 1; - while (num) - { - num = num / 10; - size++; - } - return (size); -} - -void ft_put_int(int num) -{ - if (num == -2147483648) - { - write(1, "-2", 2); - num = 147483648; - } - if (num < 0) - { - ft_print_char('-'); - num *= -1; - } - if (num >= 10) - { - ft_put_int(num / 10); - ft_put_int(num % 10); - } - if (num <= 9) - ft_print_char(num + '0'); -} - -int ft_print_int(int nbr) -{ - int return_len; - - return_len = 0; - return_len += ft_int_len(nbr); - ft_put_int(nbr); - return (return_len); -} diff --git a/libft/ft_print_int_fd.c b/libft/ft_print_int_fd.c deleted file mode 100644 index ddd34c6..0000000 --- a/libft/ft_print_int_fd.c +++ /dev/null @@ -1,64 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_int.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:53:47 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:56:53 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf_fd.h" - -int ft_int_len(int num) -{ - int size; - - size = 0; - if (num < 0) - { - num *= -1; - size += 1; - } - if (num == 0) - size += 1; - while (num) - { - num = num / 10; - size++; - } - return (size); -} - -void ft_put_int_fd(unsigned int fd, int num) -{ - if (num == -2147483648) - { - write(fd, "-2", 2); - num = 147483648; - } - if (num < 0) - { - ft_print_char_fd(fd, '-'); - num *= -1; - } - if (num >= 10) - { - ft_put_int_fd(fd, num / 10); - ft_put_int_fd(fd, num % 10); - } - if (num <= 9) - ft_print_char_fd(fd, num + '0'); -} - -int ft_print_int_fd(unsigned int fd, int nbr) -{ - int return_len; - - return_len = 0; - return_len += ft_int_len(nbr); - ft_put_int_fd(fd, nbr); - return (return_len); -} diff --git a/libft/ft_print_percent.c b/libft/ft_print_percent.c deleted file mode 100644 index 13daba7..0000000 --- a/libft/ft_print_percent.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_percent.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 14:03:00 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 14:03:19 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf.h" - -int ft_print_percent(void) -{ - write(1, "%", 1); - return (1); -} diff --git a/libft/ft_print_percent_fd.c b/libft/ft_print_percent_fd.c deleted file mode 100644 index 3348130..0000000 --- a/libft/ft_print_percent_fd.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_percent.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 14:03:00 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 14:03:19 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf_fd.h" - -int ft_print_percent_fd(unsigned int fd) -{ - write(fd, "%", 1); - return (1); -} diff --git a/libft/ft_print_ptr.c b/libft/ft_print_ptr.c deleted file mode 100644 index 3d8443d..0000000 --- a/libft/ft_print_ptr.c +++ /dev/null @@ -1,58 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_ptr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:45:41 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:48:57 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf.h" - -int ft_ptr_len(unsigned long long num) -{ - int size; - - size = 0; - while (num) - { - num = num / 16; - size++; - } - return (size); -} - -void ft_put_ptr(unsigned long long ptr) -{ - if (ptr >= 16) - { - ft_put_ptr(ptr / 16); - ft_put_ptr(ptr % 16); - } - else - { - if (ptr <= 9) - ft_print_char(ptr + '0'); - else - ft_print_char(ptr - 10 + 'a'); - } -} - -int ft_print_ptr(unsigned long long ptr) -{ - int return_len; - - return_len = 0; - if (ptr == 0) - return_len = write(1, "(nil)", 5); - else - { - return_len += write(1, "0x", 2); - return_len += ft_ptr_len(ptr); - ft_put_ptr(ptr); - } - return (return_len); -} diff --git a/libft/ft_print_ptr_fd.c b/libft/ft_print_ptr_fd.c deleted file mode 100644 index ed686ef..0000000 --- a/libft/ft_print_ptr_fd.c +++ /dev/null @@ -1,58 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_ptr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:45:41 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:48:57 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf_fd.h" - -int ft_ptr_len(unsigned long long num) -{ - int size; - - size = 0; - while (num) - { - num = num / 16; - size++; - } - return (size); -} - -void ft_put_ptr_fd(unsigned int fd, unsigned long long ptr) -{ - if (ptr >= 16) - { - ft_put_ptr_fd(fd, ptr / 16); - ft_put_ptr_fd(fd, ptr % 16); - } - else - { - if (ptr <= 9) - ft_print_char_fd(fd, ptr + '0'); - else - ft_print_char_fd(fd, ptr - 10 + 'a'); - } -} - -int ft_print_ptr_fd(unsigned int fd, unsigned long long ptr) -{ - int return_len; - - return_len = 0; - if (ptr == 0) - return_len = write(fd, "(nil)", 5); - else - { - return_len += write(fd, "0x", 2); - return_len += ft_ptr_len(ptr); - ft_put_ptr_fd(fd, ptr); - } - return (return_len); -} diff --git a/libft/ft_print_str.c b/libft/ft_print_str.c deleted file mode 100644 index 933504d..0000000 --- a/libft/ft_print_str.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_str.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:57:10 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:58:02 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf.h" - -int ft_print_str(const char *str) -{ - int i; - - i = 0; - if (str == 0) - return (write(1, "(null)", 6)); - while (*str) - { - ft_print_char(*str); - str++; - i++; - } - return (i); -} diff --git a/libft/ft_print_str_fd.c b/libft/ft_print_str_fd.c deleted file mode 100644 index 3f2ac05..0000000 --- a/libft/ft_print_str_fd.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_str.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:57:10 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:58:02 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf_fd.h" - -int ft_print_str_fd(unsigned int fd, const char *str) -{ - int i; - - i = 0; - if (str == 0) - return (write(fd, "(null)", 6)); - while (*str) - { - ft_print_char_fd(fd, *str); - str++; - i++; - } - return (i); -} diff --git a/libft/ft_print_unsign_int.c b/libft/ft_print_unsign_int.c deleted file mode 100644 index 3255e26..0000000 --- a/libft/ft_print_unsign_int.c +++ /dev/null @@ -1,62 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_unsign_int.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 14:03:41 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 14:06:44 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf.h" - -int ft_unsign_int_len(unsigned int num) -{ - int size; - - size = 0; - while (num) - { - size++; - num = num / 10; - } - return (size); -} - -char *ft_put_unsign_int(unsigned int num) -{ - char *nbr; - int len; - - len = ft_unsign_int_len(num); - nbr = malloc(sizeof(char) * (len + 1)); - if (!nbr) - return (0); - nbr[len] = '\0'; - while (num != 0) - { - nbr[len - 1] = num % 10 + '0'; - num = num / 10; - len--; - } - return (nbr); -} - -int ft_print_unsign_int(unsigned int num) -{ - int return_len; - char *nbr; - - return_len = 0; - if (num == 0) - return_len += write(1, "0", 1); - else - { - nbr = ft_put_unsign_int(num); - return_len += ft_print_str(nbr); - free(nbr); - } - return (return_len); -} diff --git a/libft/ft_print_unsign_int_fd.c b/libft/ft_print_unsign_int_fd.c deleted file mode 100644 index d6a1a69..0000000 --- a/libft/ft_print_unsign_int_fd.c +++ /dev/null @@ -1,62 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_unsign_int.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 14:03:41 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 14:06:44 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf_fd.h" - -int ft_unsign_int_len(unsigned int num) -{ - int size; - - size = 0; - while (num) - { - size++; - num = num / 10; - } - return (size); -} - -char *ft_put_unsign_int(unsigned int num) -{ - char *nbr; - int len; - - len = ft_unsign_int_len(num); - nbr = malloc(sizeof(char) * (len + 1)); - if (!nbr) - return (0); - nbr[len] = '\0'; - while (num != 0) - { - nbr[len - 1] = num % 10 + '0'; - num = num / 10; - len--; - } - return (nbr); -} - -int ft_print_unsign_int_fd(unsigned int fd, unsigned int num) -{ - int return_len; - char *nbr; - - return_len = 0; - if (num == 0) - return_len += write(fd, "0", 1); - else - { - nbr = ft_put_unsign_int(num); - return_len += ft_print_str_fd(fd, nbr); - free(nbr); - } - return (return_len); -} diff --git a/libft/ft_printf.c b/libft/ft_printf.c deleted file mode 100644 index 08d3d79..0000000 --- a/libft/ft_printf.c +++ /dev/null @@ -1,69 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_printf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/28 09:27:54 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:53:28 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf.h" - -int ft_format(char placeholder, va_list args) -{ - int print_len; - - print_len = 0; - if (placeholder == 'c') - print_len += ft_print_char(va_arg(args, unsigned int)); - else if (placeholder == 's') - print_len += ft_print_str(va_arg(args, const char *)); - else if (placeholder == 'p') - print_len += ft_print_ptr(va_arg(args, unsigned long long)); - else if (placeholder == 'i' || placeholder == 'd') - print_len += ft_print_int(va_arg(args, int)); - else if (placeholder == 'u') - print_len += ft_print_unsign_int(va_arg(args, unsigned int)); - else if (placeholder == 'x' || placeholder == 'X') - print_len += ft_print_hex(va_arg(args, unsigned int), placeholder); - else if (placeholder == '%') - print_len += ft_print_percent(); - else - { - print_len += ft_print_char('%'); - print_len += ft_print_char(placeholder); - } - return (print_len); -} - -int ft_printf(const char *print, ...) -{ - int return_len; - va_list args; - int i; - - if (!print) - return (-1); - return_len = 0; - va_start(args, print); - i = 0; - while (print[i]) - { - if (print[i] == '%') - { - return_len += ft_format(print[i + 1], args); - i++; - } - else - { - ft_print_char(print[i]); - return_len++; - } - i++; - } - va_end(args); - return (return_len); -} diff --git a/libft/ft_printf.h b/libft/ft_printf.h deleted file mode 100644 index 9812d89..0000000 --- a/libft/ft_printf.h +++ /dev/null @@ -1,40 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_printf.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:58:33 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 14:02:30 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef FT_PRINTF_H -# define FT_PRINTF_H - -# include -# include -# include -# include -# include - -int ft_print_char(char c); -int ft_hex_len(unsigned int num); -void ft_put_hex(unsigned int num, char placeholder); -int ft_print_hex(unsigned int num, char placeholder); -int ft_int_len(int num); -void ft_put_int(int num); -int ft_print_int(int nbr); -int ft_print_percent(void); -int ft_ptr_len(unsigned long long num); -void ft_put_ptr(unsigned long long ptr); -int ft_print_ptr(unsigned long long ptr); -int ft_print_str(const char *str); -int ft_unsign_int_len(unsigned int num); -char *ft_put_unsign_int(unsigned int num); -int ft_print_unsign_int(unsigned int num); -int ft_format(char placeholder, va_list args); -int ft_printf(const char *print, ...); - -#endif diff --git a/libft/ft_printf_fd.c b/libft/ft_printf_fd.c deleted file mode 100644 index 43defc4..0000000 --- a/libft/ft_printf_fd.c +++ /dev/null @@ -1,96 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_printf_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: dpadenko +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:58:33 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 14:02:30 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef FT_PRINTF_FD_H -# define FT_PRINTF_FD_H - -# include -# include -# include -# include -# include - -int ft_print_char_fd(unsigned int fd, char c); -int ft_hex_len(unsigned int num); -void ft_put_hex_fd(unsigned int fd, unsigned int num, char placeholder); -int ft_print_hex_fd(unsigned int fd, unsigned int num, char placeholder); -int ft_int_len(int num); -void ft_put_int_fd(unsigned int fd, int num); -int ft_print_int_fd(unsigned int fd, int nbr); -int ft_print_percent_fd(unsigned int fd); -int ft_ptr_len(unsigned long long num); -void ft_put_ptr_fd(unsigned int fd, unsigned long long ptr); -int ft_print_ptr_fd(unsigned int fd, unsigned long long ptr); -int ft_print_str_fd(unsigned int fd, const char *str); -int ft_unsign_int_len(unsigned int num); -char *ft_put_unsign_int(unsigned int num); -int ft_print_unsign_int_fd(unsigned int fd, unsigned int num); -int ft_format_fd(unsigned int fd, char placeholder, va_list args); -int ft_printf_fd(unsigned int fd, const char *print, ...); - -#endif diff --git a/libft/ft_putchar_fd.c b/libft/ft_putchar_fd.c deleted file mode 100644 index bda8268..0000000 --- a/libft/ft_putchar_fd.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putchar_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/12 16:08:55 by mmasarov #+# #+# */ -/* Updated: 2023/09/12 16:14:11 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putchar_fd(char c, int fd) -{ - write(fd, &c, 1); -} diff --git a/libft/ft_putendl_fd.c b/libft/ft_putendl_fd.c deleted file mode 100644 index b1f4038..0000000 --- a/libft/ft_putendl_fd.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putendl_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/12 16:21:00 by mmasarov #+# #+# */ -/* Updated: 2023/09/12 16:28:14 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putendl_fd(char *s, int fd) -{ - int i; - - i = 0; - while (s[i]) - { - write (fd, &s[i++], 1); - } - write (fd, "\n", 1); -} diff --git a/libft/ft_putnbr_fd.c b/libft/ft_putnbr_fd.c deleted file mode 100644 index 3c81624..0000000 --- a/libft/ft_putnbr_fd.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putnbr_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/12 15:15:37 by mmasarov #+# #+# */ -/* Updated: 2023/09/12 16:08:29 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putnbr_fd(int n, int fd) -{ - if (n == (-2147483648)) - { - ft_putchar_fd('-', fd); - ft_putchar_fd('2', fd); - n = 147483648; - } - if (n < 0) - { - ft_putchar_fd('-', fd); - n = (int)(n * -1); - } - if (n >= 10) - ft_putnbr_fd(n / 10, fd); - ft_putchar_fd((char)(n % 10 + 48), fd); -} diff --git a/libft/ft_putstr_fd.c b/libft/ft_putstr_fd.c deleted file mode 100644 index 0ecd469..0000000 --- a/libft/ft_putstr_fd.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putstr_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/12 16:15:51 by mmasarov #+# #+# */ -/* Updated: 2023/09/12 16:20:41 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putstr_fd(char *s, int fd) -{ - int i; - - i = 0; - while (s[i]) - { - write(fd, &s[i], 1); - i++; - } -} diff --git a/libft/ft_realloc.c b/libft/ft_realloc.c deleted file mode 100644 index a95be6e..0000000 --- a/libft/ft_realloc.c +++ /dev/null @@ -1,35 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_realloc.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: dpadenko +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/13 12:40:04 by mmasarov #+# #+# */ -/* Updated: 2023/09/13 15:26:39 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static void ft_free(char **array, int j) -{ - while (--j >= 0) - free(array[j]); - free(array); -} - -static size_t n_words(const char *str, char c) -{ - int i; - int count; - - i = 0; - count = 0; - while (str && str[i]) - { - if (str[i] != c) - { - count++; - while (str[i] != c && str[i]) - i++; - } - else - i++; - } - return (count); -} - -static size_t size_word(const char *s, char c, int i) -{ - size_t size; - - size = 0; - while (s[i] != c && s[i]) - { - size++; - i++; - } - return (size); -} - -char **ft_split(char const *s, char c) -{ - char **array; - size_t i; - size_t j; - size_t size; - - i = 0; - j = -1; - array = malloc(sizeof(char *) * (n_words(s, c) + 1)); - if (!array) - return (NULL); - while (++j < n_words(s, c)) - { - while (s[i] == c) - i++; - size = size_word(s, c, i); - array[j] = ft_substr(s, i, size); - if (!array[j]) - { - ft_free(array, j); - return (NULL); - } - i = i + size; - } - array[j] = 0; - return (array); -} diff --git a/libft/ft_strcat.c b/libft/ft_strcat.c deleted file mode 100644 index cb6cc5c..0000000 --- a/libft/ft_strcat.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strcat.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/12 14:46:18 by mmasarov #+# #+# */ -/* Updated: 2023/09/12 15:14:12 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_striteri(char *s, void (*f)(unsigned int, char*)) -{ - int i; - - i = 0; - if (!s || !f) - return ; - while (s[i]) - { - f(i, &s[i]); - i++; - } -} diff --git a/libft/ft_strjoin.c b/libft/ft_strjoin.c deleted file mode 100644 index af19030..0000000 --- a/libft/ft_strjoin.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strjoin.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/11 10:15:44 by mmasarov #+# #+# */ -/* Updated: 2023/09/13 15:52:29 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strjoin(char const *s1, char const *s2) -{ - char *newstr; - int i; - int x; - - i = 0; - x = 0; - if (!s1) - return (ft_strdup(s2)); - if (!s2) - return (ft_strdup(s1)); - newstr = (char *)malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1)); - if (!newstr) - return (NULL); - while (s1[i]) - newstr[x++] = s1[i++]; - i = 0; - while (s2[i]) - newstr[x++] = s2[i++]; - newstr[x] = '\0'; - return (newstr); -} diff --git a/libft/ft_strlcat.c b/libft/ft_strlcat.c deleted file mode 100644 index b3a7ef9..0000000 --- a/libft/ft_strlcat.c +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlcat.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/06 16:46:24 by mmasarov #+# #+# */ -/* Updated: 2023/09/07 09:52:59 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -size_t ft_strlcat(char *dst, const char *src, size_t dest_size) -{ - size_t dest_len; - size_t src_len; - size_t i; - size_t e; - - e = 0; - i = ft_strlen(dst); - dest_len = ft_strlen(dst); - src_len = ft_strlen(src); - if (dest_size == 0) - return (src_len + dest_size); - while (src[e] != '\0' && i + 1 < dest_size) - { - dst[i] = src[e]; - i++; - e++; - } - dst[i] = '\0'; - if (dest_size < dest_len) - return (src_len + dest_size); - else - return (dest_len + src_len); -} diff --git a/libft/ft_strlcpy.c b/libft/ft_strlcpy.c deleted file mode 100644 index baef551..0000000 --- a/libft/ft_strlcpy.c +++ /dev/null @@ -1,35 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlcpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/06 15:23:33 by mmasarov #+# #+# */ -/* Updated: 2023/09/07 09:56:31 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -size_t ft_strlcpy(char *dst, const char *src, size_t size) -{ - size_t i; - size_t src_len; - - i = 0; - src_len = 0; - while (src[src_len] != '\0') - { - src_len++; - } - if (size < 1) - return (src_len); - while (src[i] != '\0' && i < size - 1) - { - dst[i] = src[i]; - i++; - } - dst[i] = '\0'; - return (src_len); -} diff --git a/libft/ft_strlen.c b/libft/ft_strlen.c deleted file mode 100644 index 6b3890c..0000000 --- a/libft/ft_strlen.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlen.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/06 10:49:03 by mmasarov #+# #+# */ -/* Updated: 2023/09/06 11:13:47 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -size_t ft_strlen(const char *s) -{ - unsigned long len; - - len = 0; - while (s && *s) - { - len++; - s++; - } - return (len); -} diff --git a/libft/ft_strmapi.c b/libft/ft_strmapi.c deleted file mode 100644 index 557a0d7..0000000 --- a/libft/ft_strmapi.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strmapi.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/12 13:06:53 by mmasarov #+# #+# */ -/* Updated: 2023/09/12 14:45:52 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) -{ - char *new_str; - int i; - - i = 0; - if (!s) - return (0); - new_str = malloc(sizeof(char) * (ft_strlen(s) + 1)); - if (!new_str) - return (0); - while (s[i]) - { - new_str[i] = f(i, s[i]); - i++; - } - new_str[i] = '\0'; - return (new_str); -} diff --git a/libft/ft_strncat.c b/libft/ft_strncat.c deleted file mode 100644 index 7a45a52..0000000 --- a/libft/ft_strncat.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strncat.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/07 11:32:06 by mmasarov #+# #+# */ -/* Updated: 2023/09/07 11:56:32 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_strncmp(const char *s1, const char *s2, size_t n) -{ - size_t i; - - i = 0; - while ((s1[i] || s2[i]) && i < n) - { - if ((unsigned char)s1[i] < (unsigned char)s2[i] - || (unsigned char)s1[i] > (unsigned char)s2[i]) - return ((unsigned char)s1[i] - (unsigned char)s2[i]); - i++; - } - return (0); -} diff --git a/libft/ft_strncpy.c b/libft/ft_strncpy.c deleted file mode 100644 index 5eaf409..0000000 --- a/libft/ft_strncpy.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strncpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov n) - len = n; - dup = malloc(len + 1); - if (dup == NULL) - return (NULL); - ft_memcpy(dup, s, len); - dup[len] = '\0'; - return (dup); -} diff --git a/libft/ft_strnstr.c b/libft/ft_strnstr.c deleted file mode 100644 index 4adddd9..0000000 --- a/libft/ft_strnstr.c +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strnstr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/07 13:58:01 by mmasarov #+# #+# */ -/* Updated: 2023/09/07 16:14:17 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strnstr(const char *big, const char *little, size_t len) -{ - size_t i; - size_t e; - - if (*little && *big && len == 0) - return (NULL); - if (little == big) - return ((char *)big); - i = 0; - e = 0; - while (big[e]) - { - i = 0; - while (big[e] == little[i] && big[e] && e < len) - { - i++; - e++; - } - if (little[i] == '\0') - return ((char *)&big[e - i]); - e = (e - i) + 1; - } - return (NULL); -} diff --git a/libft/ft_strpbrk.c b/libft/ft_strpbrk.c deleted file mode 100644 index ea5c3f2..0000000 --- a/libft/ft_strpbrk.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strpbrk.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/07 10:54:00 by mmasarov #+# #+# */ -/* Updated: 2023/09/07 11:31:30 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strrchr(const char *s, int c) -{ - int i; - - i = ft_strlen(s); - while (i >= 0) - { - if (s[i] == (char)c) - return ((char *)s + i); - i--; - } - return (NULL); -} diff --git a/libft/ft_strtok.c b/libft/ft_strtok.c deleted file mode 100644 index c23ecb5..0000000 --- a/libft/ft_strtok.c +++ /dev/null @@ -1,71 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strtok.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov start && ft_char_set(s1[end - 1], set)) - end--; - new_str = malloc(sizeof(char) * (end - start + 1)); - if (!new_str) - return (NULL); - while (start < end) - { - new_str[i] = s1[start]; - start++; - i++; - } - new_str[i] = '\0'; - return (new_str); -} diff --git a/libft/ft_substr.c b/libft/ft_substr.c deleted file mode 100644 index 2b54ac2..0000000 --- a/libft/ft_substr.c +++ /dev/null @@ -1,48 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_substr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/04 14:14:56 by mmasarov #+# #+# */ -/* Updated: 2023/09/11 10:15:23 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static size_t ft_special_cases(char const *s, unsigned int start, size_t len) -{ - size_t lenght; - - lenght = ft_strlen(s); - if (lenght < start) - len = 0; - if ((lenght + start) < len) - len = lenght + start; - if (start == (lenght - 1) && len != 0) - len = 1; - if ((lenght - start) < len) - len = lenght - start; - return (len); -} - -char *ft_substr(char const *s, unsigned int start, size_t len) -{ - char *str; - size_t i; - - i = 0; - len = ft_special_cases(s, start, len); - str = malloc(sizeof(char) * (len + 1)); - if (!str) - return (NULL); - while (i < len) - { - str[i] = s[start + i]; - i++; - } - str[i] = '\0'; - return (str); -} diff --git a/libft/ft_tolower.c b/libft/ft_tolower.c deleted file mode 100644 index 100685b..0000000 --- a/libft/ft_tolower.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_tolower.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/07 10:17:59 by mmasarov #+# #+# */ -/* Updated: 2023/09/07 10:28:02 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_tolower(int c) -{ - if (c >= 'A' && c <= 'Z') - c = c + 32; - return (c); -} diff --git a/libft/ft_toupper.c b/libft/ft_toupper.c deleted file mode 100644 index aa68f44..0000000 --- a/libft/ft_toupper.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_toupper.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/09/07 09:59:37 by mmasarov #+# #+# */ -/* Updated: 2023/09/07 10:17:33 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_toupper(int c) -{ - if (c >= 'a' && c <= 'z') - c = c - 32; - return (c); -} diff --git a/libft/get_next_line.c b/libft/get_next_line.c deleted file mode 100644 index e4a50c7..0000000 --- a/libft/get_next_line.c +++ /dev/null @@ -1,116 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: dpadenko - -char *del_buf_return_res(char **buffer, char *res, int len_to_del) -{ - int new_len; - int i; - char *new_buffer; - - i = len_to_del; - new_len = 0; - while ((*buffer)[i++]) - new_len++; - if (new_len == 0) - return (my_free_gnl(buffer), res); - new_buffer = (char *)malloc(new_len + 1); - if (!new_buffer) - return (free(res), my_free_gnl(buffer), NULL); - i = 0; - while ((*buffer)[len_to_del]) - new_buffer[i++] = (*buffer)[len_to_del++]; - new_buffer[i] = '\0'; - my_free_gnl(buffer); - *buffer = new_buffer; - return (res); -} - -char *extract_til_nl_or_end(char **buff) -{ - int i; - int j; - char *res; - - i = 0; - if (!*buff) - return (NULL); - while ((*buff) && (*buff)[i]) - { - if ((*buff)[i++] == '\n') - break ; - } - res = (char *)malloc(i + 1); - if (!res) - return (my_free_gnl(buff), NULL); - j = 0; - while (j < i) - { - res[j] = (*buff)[j]; - j++; - } - res[j] = '\0'; - return (del_buf_return_res(buff, res, i)); -} - -char *read_buff_size(int fd, char **buffer) -{ - int read_bytes; - char *temp; - - temp = (char *)malloc(BUFFER_SIZE + 1); - if (!temp) - return (my_free_gnl(buffer), NULL); - read_bytes = read(fd, temp, BUFFER_SIZE); - if (read_bytes == 0) - return (free(temp), NULL); - if (read_bytes < 0) - return (free(temp), my_free_gnl(buffer), NULL); - temp[read_bytes] = '\0'; - return (temp); -} - -int check_nl(char *str) -{ - int i; - - i = 0; - while (str && str[i]) - { - if (str[i] == '\n') - return (1); - i++; - } - return (0); -} - -char *get_next_line(int fd) -{ - static char *buff; - char *read_bytes; - - if (fd < 0 || BUFFER_SIZE <= 0) - return (NULL); - while (1) - { - if (check_nl(buff)) - return (extract_til_nl_or_end(&buff)); - read_bytes = read_buff_size(fd, &buff); - if (!read_bytes && buff) - return (extract_til_nl_or_end(&buff)); - else if (!read_bytes) - return (NULL); - buff = ft_strjoin_gnl(buff, read_bytes); - } -} diff --git a/libft/get_next_line_utils.c b/libft/get_next_line_utils.c deleted file mode 100644 index 7b39d71..0000000 --- a/libft/get_next_line_utils.c +++ /dev/null @@ -1,66 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line_utils.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: dpadenko -# include -# include -# include -# include -# include -# include - -/* part one functions*/ -int ft_atoi(const char *nptr); -void ft_bzero(void *s, size_t n); -void *ft_calloc(size_t nmemb, size_t size); -int ft_isalnum(int c); -int ft_isalpha(int c); -int ft_isascii(int c); -int ft_isdigit(int c); -int ft_isprint(int c); -void *ft_memchr(const void *s, int c, size_t n); -int ft_memcmp(const void *s1, const void *s2, size_t n); -void *ft_memcpy(void *dest, const void *src, size_t n); -void *ft_memmove(void *dest, const void *src, size_t n); -void *ft_memset(void *s, int c, size_t n); -char *ft_strchr(const char *s, int c); -char *ft_strrchr(const char *s, int c); -char *ft_strdup(const char *s); -size_t ft_strlcat(char *dst, const char *src, size_t dest_size); -size_t ft_strlcpy(char *dst, const char *src, size_t size); -size_t ft_strlen(const char *s); -int ft_strncmp(const char *s1, const char *s2, size_t n); -char *ft_strnstr(const char *big, const char *little, size_t len); -char *ft_substr(char const *s, unsigned int start, size_t len); -int ft_tolower(int c); -int ft_toupper(int c); - -/* part two functions*/ -//char *ft_substr(char const *s, unsigned int start, size_t len); -char *ft_strjoin(char const *s1, char const *s2); -char *ft_strtrim(char const *s1, char const *set); -char **ft_split(char const *s, char c); -char *ft_itoa(int n); -char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); -void ft_striteri(char *s, void (*f)(unsigned int, char*)); -void ft_putchar_fd(char c, int fd); -void ft_putendl_fd(char *s, int fd); -void ft_putnbr_fd(int n, int fd); -void ft_putstr_fd(char *s, int fd); - -/* Added functions*/ -char *ft_strtok(char *str, const char *delim); -char *ft_strpbrk(char *str, char *delim); -char *ft_strncat(char *dest, const char *src, size_t n); -char *ft_strcat(char *dest, const char *src); -int ft_strcmp(const char *s1, const char *s2); -char *ft_strcpy(char *dest, const char *src); -char *ft_strndup(const char *s, size_t n); -char *ft_strncpy(char *dest, const char *src, size_t n); -void *ft_realloc(void *ptr, size_t old_size, size_t new_size); - -/* Printf added*/ -//int ft_printf(const char *print, ...); -int ft_printf_fd(unsigned int fd, const char *print, ...); -int ft_vprintf_fd(unsigned int fd, const char *print, va_list args); - -/* get_next_line added*/ -# ifndef BUFFER_SIZE -# define BUFFER_SIZE 5 -# endif - -//# include -//# include -//# include - -size_t ft_strlen_gnl(char *str); -void my_free_gnl(char **str); -char *ft_strjoin_gnl(char *read_str, char *buff); -char *del_buf_return_res(char **buffer, char *res, int len_to_del); -char *extract_til_nl_or_end(char **buff); -char *read_buff_size(int fd, char **buffer); -int check_nl(char *str); -char *get_next_line(int fd); -int ft_exact_strcmp(const char *s1, const char *s2); - -#endif diff --git a/exec_builtins.c b/src/builtins/exec_builtins.c similarity index 100% rename from exec_builtins.c rename to src/builtins/exec_builtins.c diff --git a/exec_builtins_cd.c b/src/builtins/exec_builtins_cd.c similarity index 100% rename from exec_builtins_cd.c rename to src/builtins/exec_builtins_cd.c diff --git a/exec_builtins_echo.c b/src/builtins/exec_builtins_echo.c similarity index 100% rename from exec_builtins_echo.c rename to src/builtins/exec_builtins_echo.c diff --git a/exec_builtins_env.c b/src/builtins/exec_builtins_env.c similarity index 100% rename from exec_builtins_env.c rename to src/builtins/exec_builtins_env.c diff --git a/exec_builtins_exit.c b/src/builtins/exec_builtins_exit.c similarity index 100% rename from exec_builtins_exit.c rename to src/builtins/exec_builtins_exit.c diff --git a/exec_builtins_export.c b/src/builtins/exec_builtins_export.c similarity index 100% rename from exec_builtins_export.c rename to src/builtins/exec_builtins_export.c diff --git a/exec_builtins_export_utils.c b/src/builtins/exec_builtins_export_utils.c similarity index 100% rename from exec_builtins_export_utils.c rename to src/builtins/exec_builtins_export_utils.c diff --git a/exec_builtins_pwd.c b/src/builtins/exec_builtins_pwd.c similarity index 100% rename from exec_builtins_pwd.c rename to src/builtins/exec_builtins_pwd.c diff --git a/exec_builtins_unset.c b/src/builtins/exec_builtins_unset.c similarity index 100% rename from exec_builtins_unset.c rename to src/builtins/exec_builtins_unset.c diff --git a/env_handling.c b/src/env/env_handling.c similarity index 100% rename from env_handling.c rename to src/env/env_handling.c diff --git a/env_main.c b/src/env/env_main.c similarity index 100% rename from env_main.c rename to src/env/env_main.c diff --git a/env_utils.c b/src/env/env_utils.c similarity index 100% rename from env_utils.c rename to src/env/env_utils.c diff --git a/execute_node.c b/src/exec/execute_node.c similarity index 100% rename from execute_node.c rename to src/exec/execute_node.c diff --git a/execute_node_error_messages.c b/src/exec/execute_node_error_messages.c similarity index 100% rename from execute_node_error_messages.c rename to src/exec/execute_node_error_messages.c diff --git a/execute_node_exec_cmd.c b/src/exec/execute_node_exec_cmd.c similarity index 100% rename from execute_node_exec_cmd.c rename to src/exec/execute_node_exec_cmd.c diff --git a/execute_node_handle_child_cmd.c b/src/exec/execute_node_handle_child_cmd.c similarity index 100% rename from execute_node_handle_child_cmd.c rename to src/exec/execute_node_handle_child_cmd.c diff --git a/execute_node_handle_heredoc.c b/src/exec/execute_node_handle_heredoc.c similarity index 100% rename from execute_node_handle_heredoc.c rename to src/exec/execute_node_handle_heredoc.c diff --git a/execute_node_handle_heredoc_utils.c b/src/exec/execute_node_handle_heredoc_utils.c similarity index 100% rename from execute_node_handle_heredoc_utils.c rename to src/exec/execute_node_handle_heredoc_utils.c diff --git a/execute_node_handle_redirect.c b/src/exec/execute_node_handle_redirect.c similarity index 100% rename from execute_node_handle_redirect.c rename to src/exec/execute_node_handle_redirect.c diff --git a/execute_node_handle_redirect_error.c b/src/exec/execute_node_handle_redirect_error.c similarity index 100% rename from execute_node_handle_redirect_error.c rename to src/exec/execute_node_handle_redirect_error.c diff --git a/execute_node_handle_redirect_utils.c b/src/exec/execute_node_handle_redirect_utils.c similarity index 100% rename from execute_node_handle_redirect_utils.c rename to src/exec/execute_node_handle_redirect_utils.c diff --git a/execute_node_utils.c b/src/exec/execute_node_utils.c similarity index 100% rename from execute_node_utils.c rename to src/exec/execute_node_utils.c diff --git a/execute_parse_tree.c b/src/exec/execute_parse_tree.c similarity index 100% rename from execute_parse_tree.c rename to src/exec/execute_parse_tree.c diff --git a/execute_pipeline_utils.c b/src/exec/execute_pipeline_utils.c similarity index 100% rename from execute_pipeline_utils.c rename to src/exec/execute_pipeline_utils.c diff --git a/execute_pipeline_utils_1.c b/src/exec/execute_pipeline_utils_1.c similarity index 100% rename from execute_pipeline_utils_1.c rename to src/exec/execute_pipeline_utils_1.c diff --git a/handle_dollar_sign.c b/src/expand/handle_dollar_sign.c similarity index 100% rename from handle_dollar_sign.c rename to src/expand/handle_dollar_sign.c diff --git a/handle_dollar_sign_utils.c b/src/expand/handle_dollar_sign_utils.c similarity index 100% rename from handle_dollar_sign_utils.c rename to src/expand/handle_dollar_sign_utils.c diff --git a/handle_quotes_main_1.c b/src/expand/handle_quotes_main_1.c similarity index 100% rename from handle_quotes_main_1.c rename to src/expand/handle_quotes_main_1.c diff --git a/handle_quotes_main_2.c b/src/expand/handle_quotes_main_2.c similarity index 100% rename from handle_quotes_main_2.c rename to src/expand/handle_quotes_main_2.c diff --git a/handle_quotes_redirect.c b/src/expand/handle_quotes_redirect.c similarity index 100% rename from handle_quotes_redirect.c rename to src/expand/handle_quotes_redirect.c diff --git a/handle_quotes_utils_1.c b/src/expand/handle_quotes_utils_1.c similarity index 100% rename from handle_quotes_utils_1.c rename to src/expand/handle_quotes_utils_1.c diff --git a/handle_quotes_utils_2.c b/src/expand/handle_quotes_utils_2.c similarity index 100% rename from handle_quotes_utils_2.c rename to src/expand/handle_quotes_utils_2.c diff --git a/free_functions.c b/src/free/free_functions.c similarity index 100% rename from free_functions.c rename to src/free/free_functions.c diff --git a/free_functions_1.c b/src/free/free_functions_1.c similarity index 100% rename from free_functions_1.c rename to src/free/free_functions_1.c diff --git a/pipeline_here_doc_dol_closed.c b/src/heredoc/pipeline_here_doc_dol_closed.c similarity index 100% rename from pipeline_here_doc_dol_closed.c rename to src/heredoc/pipeline_here_doc_dol_closed.c diff --git a/pipeline_here_doc_dol_open.c b/src/heredoc/pipeline_here_doc_dol_open.c similarity index 100% rename from pipeline_here_doc_dol_open.c rename to src/heredoc/pipeline_here_doc_dol_open.c diff --git a/pipeline_here_doc_main.c b/src/heredoc/pipeline_here_doc_main.c similarity index 100% rename from pipeline_here_doc_main.c rename to src/heredoc/pipeline_here_doc_main.c diff --git a/lexer.c b/src/lexer/lexer.c similarity index 100% rename from lexer.c rename to src/lexer/lexer.c diff --git a/lexer_main.c b/src/lexer/lexer_main.c similarity index 100% rename from lexer_main.c rename to src/lexer/lexer_main.c diff --git a/error_handling.c b/src/main/error_handling.c similarity index 100% rename from error_handling.c rename to src/main/error_handling.c diff --git a/init_1.c b/src/main/init_1.c similarity index 100% rename from init_1.c rename to src/main/init_1.c diff --git a/init_2.c b/src/main/init_2.c similarity index 100% rename from init_2.c rename to src/main/init_2.c diff --git a/main.c b/src/main/main.c similarity index 100% rename from main.c rename to src/main/main.c diff --git a/main_handle_input.c b/src/main/main_handle_input.c similarity index 100% rename from main_handle_input.c rename to src/main/main_handle_input.c diff --git a/signals.c b/src/main/signals.c similarity index 100% rename from signals.c rename to src/main/signals.c diff --git a/parser_is_all_rest.c b/src/parser/parser_is_all_rest.c similarity index 100% rename from parser_is_all_rest.c rename to src/parser/parser_is_all_rest.c diff --git a/parser_is_cmd_suffix.c b/src/parser/parser_is_cmd_suffix.c similarity index 100% rename from parser_is_cmd_suffix.c rename to src/parser/parser_is_cmd_suffix.c diff --git a/parser_main.c b/src/parser/parser_main.c similarity index 100% rename from parser_main.c rename to src/parser/parser_main.c diff --git a/parser_utils.c b/src/parser/parser_utils.c similarity index 100% rename from parser_utils.c rename to src/parser/parser_utils.c diff --git a/get_path_for_exec.c b/src/path/get_path_for_exec.c similarity index 100% rename from get_path_for_exec.c rename to src/path/get_path_for_exec.c diff --git a/get_path_for_exec_colon.c b/src/path/get_path_for_exec_colon.c similarity index 100% rename from get_path_for_exec_colon.c rename to src/path/get_path_for_exec_colon.c diff --git a/get_path_for_exec_utils.c b/src/path/get_path_for_exec_utils.c similarity index 100% rename from get_path_for_exec_utils.c rename to src/path/get_path_for_exec_utils.c diff --git a/test_files/empty b/tests/test_files/empty similarity index 100% rename from test_files/empty rename to tests/test_files/empty diff --git a/test_files/file name with spaces b/tests/test_files/file name with spaces similarity index 100% rename from test_files/file name with spaces rename to tests/test_files/file name with spaces diff --git a/test_files/infile b/tests/test_files/infile similarity index 100% rename from test_files/infile rename to tests/test_files/infile diff --git a/test_files/infile_big b/tests/test_files/infile_big similarity index 100% rename from test_files/infile_big rename to tests/test_files/infile_big diff --git a/test_files/invalid_permission b/tests/test_files/invalid_permission similarity index 100% rename from test_files/invalid_permission rename to tests/test_files/invalid_permission diff --git a/test_files/loop b/tests/test_files/loop similarity index 100% rename from test_files/loop rename to tests/test_files/loop diff --git a/test_files/loop.c b/tests/test_files/loop.c similarity index 100% rename from test_files/loop.c rename to tests/test_files/loop.c diff --git a/m_suppress b/tools/suppress/m_suppress similarity index 100% rename from m_suppress rename to tools/suppress/m_suppress diff --git a/suppress b/tools/suppress/suppress similarity index 100% rename from suppress rename to tools/suppress/suppress diff --git a/suppress_lnx b/tools/suppress/suppress_lnx similarity index 100% rename from suppress_lnx rename to tools/suppress/suppress_lnx diff --git a/suppress_mac b/tools/suppress/suppress_mac similarity index 100% rename from suppress_mac rename to tools/suppress/suppress_mac From 5887411b157f9d98b67f23e0a8240e4d67b7191d Mon Sep 17 00:00:00 2001 From: grignetta <121875111+grignetta@users.noreply.github.com> Date: Fri, 29 Aug 2025 08:36:15 +0200 Subject: [PATCH 02/18] Add libft as git submodule --- .gitmodules | 3 +++ libft | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 libft diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f66c464 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libft"] + path = libft + url = git@github.com:grignetta/42_libft.git diff --git a/libft b/libft new file mode 160000 index 0000000..8692d2d --- /dev/null +++ b/libft @@ -0,0 +1 @@ +Subproject commit 8692d2d8fbd52ea3cb82777281a97052d7d236dc From fdd375b3117f65dbc2ecd98969a386f3d1fd0008 Mon Sep 17 00:00:00 2001 From: grignetta <121875111+grignetta@users.noreply.github.com> Date: Fri, 29 Aug 2025 08:52:43 +0200 Subject: [PATCH 03/18] libft updated with ft_strcpy --- libft | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libft b/libft index 8692d2d..e98b621 160000 --- a/libft +++ b/libft @@ -1 +1 @@ -Subproject commit 8692d2d8fbd52ea3cb82777281a97052d7d236dc +Subproject commit e98b621e40471a2c658f33d5c8c57e70ff16d658 From 41ab91191bafec6aaaf11df28e5e29684df4ceab Mon Sep 17 00:00:00 2001 From: grignetta <121875111+grignetta@users.noreply.github.com> Date: Fri, 29 Aug 2025 10:51:44 +0200 Subject: [PATCH 04/18] libft updated --- libft | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libft b/libft index e98b621..baa1091 160000 --- a/libft +++ b/libft @@ -1 +1 @@ -Subproject commit e98b621e40471a2c658f33d5c8c57e70ff16d658 +Subproject commit baa1091ec6073151b03c0d500a071379e4e665b4 From 96e7752c9dda4f43fa83763bfe3fa07b4ba3d35b Mon Sep 17 00:00:00 2001 From: grignetta <121875111+grignetta@users.noreply.github.com> Date: Fri, 29 Aug 2025 11:02:36 +0200 Subject: [PATCH 05/18] ft_realloc added in libft --- libft | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libft b/libft index baa1091..3cc33f9 160000 --- a/libft +++ b/libft @@ -1 +1 @@ -Subproject commit baa1091ec6073151b03c0d500a071379e4e665b4 +Subproject commit 3cc33f9399102e36e6e22253f8dcca7303a0e245 From b9d41e4bc617634246cbe029de29e84da37607a2 Mon Sep 17 00:00:00 2001 From: grignetta <121875111+grignetta@users.noreply.github.com> Date: Fri, 29 Aug 2025 22:28:56 +0200 Subject: [PATCH 06/18] file split to different folders, makefile for printf_fd obj folder should be updated --- Makefile | 118 +++++++++++------------------ include/minishell.h | 3 +- libft | 2 +- printf_fd/Makefile | 34 +++++++++ printf_fd/ft_print_char_fd.c | 19 +++++ printf_fd/ft_print_hex_fd.c | 62 +++++++++++++++ printf_fd/ft_print_int_fd.c | 64 ++++++++++++++++ printf_fd/ft_print_percent_fd.c | 19 +++++ printf_fd/ft_print_ptr_fd.c | 58 ++++++++++++++ printf_fd/ft_print_str_fd.c | 29 +++++++ printf_fd/ft_print_unsign_int_fd.c | 62 +++++++++++++++ printf_fd/ft_printf_fd.c | 96 +++++++++++++++++++++++ printf_fd/ft_printf_fd.h | 41 ++++++++++ 13 files changed, 533 insertions(+), 74 deletions(-) create mode 100644 printf_fd/Makefile create mode 100644 printf_fd/ft_print_char_fd.c create mode 100644 printf_fd/ft_print_hex_fd.c create mode 100644 printf_fd/ft_print_int_fd.c create mode 100644 printf_fd/ft_print_percent_fd.c create mode 100644 printf_fd/ft_print_ptr_fd.c create mode 100644 printf_fd/ft_print_str_fd.c create mode 100644 printf_fd/ft_print_unsign_int_fd.c create mode 100644 printf_fd/ft_printf_fd.c create mode 100644 printf_fd/ft_printf_fd.h diff --git a/Makefile b/Makefile index 91c6eb3..b58058c 100644 --- a/Makefile +++ b/Makefile @@ -1,90 +1,64 @@ NAME = minishell -HEADER = lexer.h CC = cc -CFLAGS = -g -Wall -Wextra -Werror# -fsanitize=address +CFLAGS = -g -Wall -Wextra -Werror -MMD -MP # -fsanitize=address + +INC_DIR = include +SRC_DIR = src +OBJ_DIR = obj LIBDIR = ./libft -OBJDIR = ./obj LIBFT = $(LIBDIR)/libft.a -SOURCES = env_main.c \ - env_utils.c \ - env_handling.c \ - error_handling.c \ - exec_builtins_exit.c \ - exec_builtins_cd.c \ - exec_builtins_echo.c \ - exec_builtins_env.c \ - exec_builtins_export.c \ - exec_builtins_export_utils.c \ - exec_builtins_pwd.c \ - exec_builtins_unset.c \ - exec_builtins.c \ - execute_node.c \ - execute_node_handle_redirect.c \ - execute_node_handle_redirect_utils.c \ - execute_node_handle_redirect_error.c \ - execute_node_handle_heredoc.c \ - execute_node_handle_heredoc_utils.c \ - execute_node_exec_cmd.c \ - handle_dollar_sign.c \ - handle_dollar_sign_utils.c \ - execute_node_utils.c \ - execute_parse_tree.c \ - execute_pipeline_utils.c \ - free_functions.c \ - lexer_main.c \ - lexer.c \ - main.c \ - main_handle_input.c \ - parser_is_all_rest.c \ - parser_is_cmd_suffix.c \ - parser_main.c \ - parser_utils.c \ - init_1.c \ - init_2.c \ - handle_quotes_main_1.c \ - handle_quotes_main_2.c \ - handle_quotes_utils_1.c \ - handle_quotes_utils_2.c \ - handle_quotes_redirect.c \ - execute_pipeline_utils_1.c \ - execute_node_handle_child_cmd.c \ - execute_node_error_messages.c \ - free_functions_1.c \ - pipeline_here_doc_dol_closed.c \ - pipeline_here_doc_main.c \ - pipeline_here_doc_dol_open.c \ - get_path_for_exec.c \ - get_path_for_exec_utils.c \ - get_path_for_exec_colon.c \ - signals.c \ - - -OBJ = $(addprefix $(OBJDIR)/, $(SOURCES:.c=.o)) +PRINTFD_DIR := ./printf_fd +PRINTFD_LIB := $(PRINTFD_DIR)/libprintf_fd.a + +# -------- Readline (Linux/macOS) -------- +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Darwin) + RL_INC := -I/opt/homebrew/opt/readline/include + RL_LIB := -L/opt/homebrew/opt/readline/lib -lreadline +else + RL_INC := + RL_LIB := -lreadline +endif + +SRC = $(shell find $(SRC_DIR) -type f -name '*.c') +OBJ = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC)) +DEP = $(OBJ:.o=.d) + +.PHONY: all clean fclean re libs all: $(NAME) -$(OBJDIR): - mkdir -p $(OBJDIR) +$(NAME): $(LIBFT) $(PRINTFD_LIB) $(OBJ) + $(CC) $(CFLAGS) $(OBJ) -L$(LIBDIR) -lft $(PRINTFD_LIB) $(RL_LIB) -o $@ + +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR) + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) -I$(INC_DIR) -I$(LIBDIR) -I$(PRINTFD_DIR) $(RL_INC) -c $< -o $@ -$(OBJDIR)/%.o: %.c | $(OBJDIR) - $(CC) $(CFLAGS) -o $@ -c $< -I. +$(OBJ_DIR): + @mkdir -p $(OBJ_DIR) -$(NAME): $(LIBFT) $(OBJ) - $(CC) $(CFLAGS) $(OBJ) -L$(LIBDIR) -lft -lreadline -o $(NAME) +$(LIBDIR)/.git: + @git submodule update --init --recursive -$(LIBFT): - $(MAKE) -C $(LIBDIR) all +$(LIBFT): | $(LIBDIR)/.git + $(MAKE) -C $(LIBDIR) all -.PHONY: clean fclean all re +$(PRINTFD_LIB): + $(MAKE) -C $(PRINTFD_DIR) all clean: - $(MAKE) -C $(LIBDIR) clean - rm -rf $(OBJDIR) + $(MAKE) -C $(LIBDIR) clean + $(MAKE) -C $(PRINTFD_DIR) clean + rm -rf $(OBJ_DIR) fclean: clean - $(MAKE) -C $(LIBDIR) fclean - rm -rf $(NAME) + $(MAKE) -C $(LIBDIR) fclean + $(MAKE) -C $(PRINTFD_DIR) fclean + rm -f $(NAME) + +re: fclean all -re: fclean all \ No newline at end of file +-include $(DEP) diff --git a/include/minishell.h b/include/minishell.h index 8c2a652..262c62e 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -23,7 +23,8 @@ # include # include # include -# include "libft/libft.h" +# include "libft.h" +# include "ft_printf_fd.h" # include # include # include diff --git a/libft b/libft index 3cc33f9..405246e 160000 --- a/libft +++ b/libft @@ -1 +1 @@ -Subproject commit 3cc33f9399102e36e6e22253f8dcca7303a0e245 +Subproject commit 405246e8bb84f8f3cfeef6e4fa64d58d15e68a01 diff --git a/printf_fd/Makefile b/printf_fd/Makefile new file mode 100644 index 0000000..fa0a333 --- /dev/null +++ b/printf_fd/Makefile @@ -0,0 +1,34 @@ +NAME = libprintf_fd.a +CC = cc +CFLAGS = -Wall -Wextra -Werror -I. +AR = ar rcs + +SRC = \ + ft_printf_fd.c \ + ft_print_char_fd.c \ + ft_print_str_fd.c \ + ft_print_int_fd.c \ + ft_print_unsign_int_fd.c \ + ft_print_hex_fd.c \ + ft_print_ptr_fd.c \ + ft_print_percent_fd.c + +OBJ := $(SRC:.c=.o) + +all: $(NAME) + +$(NAME): $(OBJ) + $(AR) $@ $^ + +%.o: %.c ft_printf_fd.h + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJ) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/printf_fd/ft_print_char_fd.c b/printf_fd/ft_print_char_fd.c new file mode 100644 index 0000000..7372de7 --- /dev/null +++ b/printf_fd/ft_print_char_fd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_char.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:36:38 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:38:00 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf_fd.h" + +int ft_print_char_fd(unsigned int fd, char c) +{ + write (fd, &c, 1); + return (1); +} diff --git a/printf_fd/ft_print_hex_fd.c b/printf_fd/ft_print_hex_fd.c new file mode 100644 index 0000000..5bcf5c4 --- /dev/null +++ b/printf_fd/ft_print_hex_fd.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_hex.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:38:19 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:45:02 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf_fd.h" + +int ft_hex_len(unsigned int num) +{ + int size; + + size = 0; + while (num) + { + num = num / 16; + size++; + } + return (size); +} + +void ft_put_hex_fd(unsigned int fd, unsigned int num, char placeholder) +{ + if (num >= 16) + { + ft_put_hex_fd(fd, num / 16, placeholder); + ft_put_hex_fd(fd, num % 16, placeholder); + } + else + { + if (num <= 9) + ft_print_char_fd(fd, num + '0'); + else + { + if (placeholder == 'x') + ft_print_char_fd(fd, num - 10 + 'a'); + else if (placeholder == 'X') + ft_print_char_fd(fd, num - 10 + 'A'); + } + } +} + +int ft_print_hex_fd(unsigned int fd, unsigned int num, char placeholder) +{ + int return_len; + + return_len = 0; + if (num == 0) + return_len += write(fd, "0", 1); + else + { + return_len += ft_hex_len(num); + ft_put_hex_fd(fd, num, placeholder); + } + return (return_len); +} diff --git a/printf_fd/ft_print_int_fd.c b/printf_fd/ft_print_int_fd.c new file mode 100644 index 0000000..ddd34c6 --- /dev/null +++ b/printf_fd/ft_print_int_fd.c @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_int.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:53:47 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:56:53 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf_fd.h" + +int ft_int_len(int num) +{ + int size; + + size = 0; + if (num < 0) + { + num *= -1; + size += 1; + } + if (num == 0) + size += 1; + while (num) + { + num = num / 10; + size++; + } + return (size); +} + +void ft_put_int_fd(unsigned int fd, int num) +{ + if (num == -2147483648) + { + write(fd, "-2", 2); + num = 147483648; + } + if (num < 0) + { + ft_print_char_fd(fd, '-'); + num *= -1; + } + if (num >= 10) + { + ft_put_int_fd(fd, num / 10); + ft_put_int_fd(fd, num % 10); + } + if (num <= 9) + ft_print_char_fd(fd, num + '0'); +} + +int ft_print_int_fd(unsigned int fd, int nbr) +{ + int return_len; + + return_len = 0; + return_len += ft_int_len(nbr); + ft_put_int_fd(fd, nbr); + return (return_len); +} diff --git a/printf_fd/ft_print_percent_fd.c b/printf_fd/ft_print_percent_fd.c new file mode 100644 index 0000000..3348130 --- /dev/null +++ b/printf_fd/ft_print_percent_fd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_percent.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 14:03:00 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 14:03:19 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf_fd.h" + +int ft_print_percent_fd(unsigned int fd) +{ + write(fd, "%", 1); + return (1); +} diff --git a/printf_fd/ft_print_ptr_fd.c b/printf_fd/ft_print_ptr_fd.c new file mode 100644 index 0000000..ed686ef --- /dev/null +++ b/printf_fd/ft_print_ptr_fd.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_ptr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:45:41 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:48:57 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf_fd.h" + +int ft_ptr_len(unsigned long long num) +{ + int size; + + size = 0; + while (num) + { + num = num / 16; + size++; + } + return (size); +} + +void ft_put_ptr_fd(unsigned int fd, unsigned long long ptr) +{ + if (ptr >= 16) + { + ft_put_ptr_fd(fd, ptr / 16); + ft_put_ptr_fd(fd, ptr % 16); + } + else + { + if (ptr <= 9) + ft_print_char_fd(fd, ptr + '0'); + else + ft_print_char_fd(fd, ptr - 10 + 'a'); + } +} + +int ft_print_ptr_fd(unsigned int fd, unsigned long long ptr) +{ + int return_len; + + return_len = 0; + if (ptr == 0) + return_len = write(fd, "(nil)", 5); + else + { + return_len += write(fd, "0x", 2); + return_len += ft_ptr_len(ptr); + ft_put_ptr_fd(fd, ptr); + } + return (return_len); +} diff --git a/printf_fd/ft_print_str_fd.c b/printf_fd/ft_print_str_fd.c new file mode 100644 index 0000000..3f2ac05 --- /dev/null +++ b/printf_fd/ft_print_str_fd.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_str.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:57:10 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:58:02 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf_fd.h" + +int ft_print_str_fd(unsigned int fd, const char *str) +{ + int i; + + i = 0; + if (str == 0) + return (write(fd, "(null)", 6)); + while (*str) + { + ft_print_char_fd(fd, *str); + str++; + i++; + } + return (i); +} diff --git a/printf_fd/ft_print_unsign_int_fd.c b/printf_fd/ft_print_unsign_int_fd.c new file mode 100644 index 0000000..d6a1a69 --- /dev/null +++ b/printf_fd/ft_print_unsign_int_fd.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_unsign_int.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 14:03:41 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 14:06:44 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf_fd.h" + +int ft_unsign_int_len(unsigned int num) +{ + int size; + + size = 0; + while (num) + { + size++; + num = num / 10; + } + return (size); +} + +char *ft_put_unsign_int(unsigned int num) +{ + char *nbr; + int len; + + len = ft_unsign_int_len(num); + nbr = malloc(sizeof(char) * (len + 1)); + if (!nbr) + return (0); + nbr[len] = '\0'; + while (num != 0) + { + nbr[len - 1] = num % 10 + '0'; + num = num / 10; + len--; + } + return (nbr); +} + +int ft_print_unsign_int_fd(unsigned int fd, unsigned int num) +{ + int return_len; + char *nbr; + + return_len = 0; + if (num == 0) + return_len += write(fd, "0", 1); + else + { + nbr = ft_put_unsign_int(num); + return_len += ft_print_str_fd(fd, nbr); + free(nbr); + } + return (return_len); +} diff --git a/printf_fd/ft_printf_fd.c b/printf_fd/ft_printf_fd.c new file mode 100644 index 0000000..43defc4 --- /dev/null +++ b/printf_fd/ft_printf_fd.c @@ -0,0 +1,96 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dpadenko +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:58:33 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 14:02:30 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_PRINTF_FD_H +# define FT_PRINTF_FD_H + +# include +# include +# include +# include +# include + +int ft_print_char_fd(unsigned int fd, char c); +int ft_hex_len(unsigned int num); +void ft_put_hex_fd(unsigned int fd, unsigned int num, char placeholder); +int ft_print_hex_fd(unsigned int fd, unsigned int num, char placeholder); +int ft_int_len(int num); +void ft_put_int_fd(unsigned int fd, int num); +int ft_print_int_fd(unsigned int fd, int nbr); +int ft_print_percent_fd(unsigned int fd); +int ft_ptr_len(unsigned long long num); +void ft_put_ptr_fd(unsigned int fd, unsigned long long ptr); +int ft_print_ptr_fd(unsigned int fd, unsigned long long ptr); +int ft_print_str_fd(unsigned int fd, const char *str); +int ft_unsign_int_len(unsigned int num); +char *ft_put_unsign_int(unsigned int num); +int ft_print_unsign_int_fd(unsigned int fd, unsigned int num); +int ft_format_fd(unsigned int fd, char placeholder, va_list args); +int ft_printf_fd(unsigned int fd, const char *print, ...); +int ft_vprintf_fd(unsigned int fd, const char *print, va_list args); + +#endif From 55e0760011fb9694342ab48b0968af6e5e15afb5 Mon Sep 17 00:00:00 2001 From: grignetta <121875111+grignetta@users.noreply.github.com> Date: Fri, 29 Aug 2025 22:32:58 +0200 Subject: [PATCH 07/18] Remove garbage files --- "\025\002\315L\006" | 0 "\037\340\272 \006" | 0 "\250v\242S\006" | 0 "\271P\315\203\005" | 0 4 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 "\025\002\315L\006" delete mode 100644 "\037\340\272 \006" delete mode 100644 "\250v\242S\006" delete mode 100644 "\271P\315\203\005" diff --git "a/\025\002\315L\006" "b/\025\002\315L\006" deleted file mode 100644 index e69de29..0000000 diff --git "a/\037\340\272 \006" "b/\037\340\272 \006" deleted file mode 100644 index e69de29..0000000 diff --git "a/\250v\242S\006" "b/\250v\242S\006" deleted file mode 100644 index e69de29..0000000 diff --git "a/\271P\315\203\005" "b/\271P\315\203\005" deleted file mode 100644 index e69de29..0000000 From 90c26fc367994d0b39db33868f0a332799cc6065 Mon Sep 17 00:00:00 2001 From: grignetta <121875111+grignetta@users.noreply.github.com> Date: Fri, 29 Aug 2025 22:40:54 +0200 Subject: [PATCH 08/18] printf_fd makefile changed adding obj dir --- printf_fd/Makefile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/printf_fd/Makefile b/printf_fd/Makefile index fa0a333..fc25a1d 100644 --- a/printf_fd/Makefile +++ b/printf_fd/Makefile @@ -13,18 +13,23 @@ SRC = \ ft_print_ptr_fd.c \ ft_print_percent_fd.c -OBJ := $(SRC:.c=.o) +OBJDIR = obj_printf_fd +OBJ = $(addprefix $(OBJDIR)/, $(SRC:.c=.o)) -all: $(NAME) +all: $(OBJDIR) $(NAME) + +$(OBJDIR): + mkdir -p $(OBJDIR) $(NAME): $(OBJ) $(AR) $@ $^ -%.o: %.c ft_printf_fd.h +$(OBJDIR)/%.o: %.c ft_printf_fd.h | $(OBJDIR) $(CC) $(CFLAGS) -c $< -o $@ clean: rm -f $(OBJ) + rm -rf $(OBJDIR) fclean: clean rm -f $(NAME) From 0a62ebeb0014cee7c808087b2f28da578620a6b8 Mon Sep 17 00:00:00 2001 From: grignetta <121875111+grignetta@users.noreply.github.com> Date: Fri, 29 Aug 2025 22:44:54 +0200 Subject: [PATCH 09/18] .gitignore updated, .swo, .vscode removed --- .gitignore | 4 +++- .swo | Bin 12288 -> 0 bytes .vscode/c_cpp_properties.json | 27 --------------------------- .vscode/tasks.json | 28 ---------------------------- 4 files changed, 3 insertions(+), 56 deletions(-) delete mode 100644 .swo delete mode 100644 .vscode/c_cpp_properties.json delete mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore index 533c9c8..6dd9549 100644 --- a/.gitignore +++ b/.gitignore @@ -66,4 +66,6 @@ $HOME $USER $USER'$USER' -*.swp \ No newline at end of file +*.swp +*.swo +.vscode/ diff --git a/.swo b/.swo deleted file mode 100644 index 89a94b8e9c45abf6e438a358be52e1eac888586c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI%u?mAQ5P;#+t&`HefVI15oqU82T?%$jiGq_w-21RTNKLekbrQ4uf#f(6a>uuY zywd0G9u-L@W`uT`$3yv|Ro5)}TC6MGc53Yedk7%lUf@vX*DSStT;g+dI+pHRq5}jF zKmY**5I_I{1Q6IwpnrSvG1dHEMek4Ctsx2_fB*srAb Date: Sat, 30 Aug 2025 14:41:26 +0200 Subject: [PATCH 10/18] Update README with project details and instructions Added detailed project description, features, architecture, build instructions, and testing guidelines for minishell. --- README.md | 319 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 318 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d50785..87ac39c 100644 --- a/README.md +++ b/README.md @@ -1 +1,318 @@ -# minishell \ No newline at end of file +# minishell (42cursus) + +> **Passing the Gate.** Minishell is widely seen as the *main threshold* of 42: the first big systems project where you must design, test, and debug a real UNIX program under strict constraints (no leaks, precise signals, exact exit codes, brittle specs). Many students struggle not because it’s “hard C,” but because **small behavioral details** matter and are tested. +> Written in a group together with https://github.com/grignetta + +--- + +## TL;DR + +* **Goal:** Re‑implement a tiny Bash‑like shell. +* **You must get right:** parsing, quoting, environment/expansion, redirections, pipelines, builtins, **signals** (Ctrl‑C/D/), **heredocs**, and **exit codes**. +* **Why this project matters:** It forces you to build a clean architecture (lexer → parser → executor) and to develop production habits: test harnesses, robust error handling, and clean resource management. + +--- + +## Features (Mandatory Scope) + +* Prompt loop using **readline** with history. +* **Lexer/Parser** producing a parse tree (or equivalent) that supports: + + * Words, operators (`|`, `<`, `>`, `<<`, `>>`), and correct **precedence**. + * **Quotes**: single quotes = literal, double quotes = expand `$` & `$?`. +* **Expansion**: `$VAR`, `$?` (last exit status), rules with quotes. +* **Redirections**: `>`, `>>`, `<`, `<<` (heredoc with optional expansion). +* **Pipelines**: `cmd1 | cmd2 | ...` with correct FD wiring. +* **Builtins** implemented in‑process when appropriate: + + * `echo` (with `-n`), `cd`, `pwd`, `export`, `unset`, `env`, `exit`. +* **Signals** & termios behavior matching Bash‐like expectations. +* **No memory leaks** over long interactive sessions; correct cleanup for all code paths. + +--- + +## Architecture + +``` +include/ # headers +src/ + main/ # entry, init, signals, errors + env/ # env storage & manipulation + lexer/ # tokenization + parser/ # grammar -> AST + expand/ # quotes & $ expansion + exec/ # executor, redirs, pipes + heredoc/ # heredoc management + builtins/ # builtins implementations + path/ # PATH resolution + free/ # cleanup helpers +printf_fd/ # libprintf_fd.a (ft_printf_fd & helpers) +libft/ # submodule (libft.a) +tools/suppress/ # sanitizer suppression files (readline, etc.) +``` + +* **Executor rule of thumb:** + + * **Single builtin with redirs** → run **in parent** (so it can change shell state). + * **Pipelines / external commands** → run in **children**. + +--- + +## Build & Run + +```sh +# clone with submodules +git clone --recursive https://github.com/michaela811/minishell.git minishell +cd minishell + +# build +make + +# run +./minishell +``` + +### Make targets + +* `make` – build `minishell`, `libft.a`, and `libprintf_fd.a`. +* `make clean|fclean|re` – standard hygiene. + +> If you forgot submodules: `git submodule update --init --recursive`. + +--- + +## The Controls You Must Pass (Signals & TTY behavior) + +Getting **Ctrl keys** right is a common failure point. The parent shell and its children must behave differently. + +### Ctrl‑C (SIGINT) + +* **At prompt (no child running):** + + * Effect: print a newline, **redisplay prompt**, don’t exit. + * **Exit status** becomes `130` for `$?`. + * Implementation: handle SIGINT in the parent (reset current line via readline hooks), do **not** terminate the shell. +* **While a child runs:** + + * The child receives SIGINT and terminates; parent prints newline and sets status `130`. + +### Ctrl‑\ (SIGQUIT) + +* **At prompt (no child):** ignore (no message, no exit). +* **While a child runs:** if the child doesn’t ignore SIGQUIT, it ends with core‑dump semantics; many testers check for the message `Quit: 3` and **status `131`**. + +### Ctrl‑D (EOF) + +* **At empty prompt:** exit cleanly; print `exit` and return last status. +* **In heredoc:** treated as end of file for the heredoc **only**. + +> **Summary table** +> +> | Key | At prompt (parent) | While child runs | `$?` | +> | ------- | ------------------ | ---------------- | ----- | +> | Ctrl‑C | newline + prompt | kills child | 130 | +> | Ctrl‑\ | ignored | “Quit: 3” | 131 | +> | Ctrl‑D | exit shell | (n/a) | last | +> | Ctrl‑Z | ignored | default in child | (n/a) | + +--- + +## Heredoc Rules That Are Tested + +* **Delimiter quoting controls expansion**: + + * Unquoted delimiter → expand `$VAR` and `$?` inside heredoc. + * Quoted delimiter → **no expansion**. + +* **Signals inside heredoc**: + + * `Ctrl‑C` must **abort** the heredoc, clean temp files, and set status `130`. +* Use a temp file or pipe; ensure **FD hygiene** in pipelines. + +--- + +## Exit Codes You’ll Be Graded On + +* `0` – success. +* `126` – found but **not executable** (permissions / directory exec attempt). +* `127` – **command not found**. +* `130` – terminated by **SIGINT**. +* `131` – terminated by **SIGQUIT**. + +Also ensure `exit` builtin accepts: `exit`, `exit `, error on too many args, numeric parsing as Bash. + +--- + +## Redirections & Pipelines – Common Edge Cases + +* Redirect errors (e.g., `cat < nofile`) must not create processes needlessly; print error and set correct status. +* Mix of redirs & pipelines: last command’s exit status propagates to `$?`. +* `cd` with redirs (e.g., `cd > file`) must still run in parent when possible; handle errors before state changes. + +--- + +## Expansion & Quotes – Quick Rules + +* Single quotes `'...'` → literal. +* Double quotes `"..."` → expand `$VAR` and `$?`; keep spaces as literal characters. +* Unquoted words are subject to splitting by the parser **before** expansion is resolved into argv; design your lexer/parser so that quotes affect tokenization, not post‑processing hacks. + +--- + +## Memory Hygiene & Suppression Files (about “suppress/susspend”) + +`readline` and some system libs can report **false‑positive leaks** under ASan/LSan or Valgrind. Use **suppression files** to focus on *your* leaks. + +* Suppression files live in `tools/suppress/`: + + * `suppress_lnx`, `suppress_mac`, `m_suppress`, etc. +* **Run with Address/Leak sanitizer** (Linux example): + + ```sh + ASAN_OPTIONS="detect_leaks=1:halt_on_error=1:suppressions=tools/suppress/suppress_lnx" \ + LSAN_OPTIONS="suppressions=tools/suppress/suppress_lnx" \ + ./minishell + ``` +* **On macOS** (different env vars): + + ```sh + export ASAN_OPTIONS="detect_leaks=1:suppressions=tools/suppress/suppress_mac" + export LSAN_OPTIONS="suppressions=tools/suppress/suppress_mac" + ./minishell + ``` +* **Why use suppressions?** + + * School testers expect you to eliminate *your* leaks; third‑party library internals (e.g., `readline`) aren’t your responsibility. + +> Still use `valgrind`/ASan on targeted unit tests (builtins, parser failures, heredoc aborts) to prove no leaks on every path. + +--- + +## Step‑by‑Step Plan to Pass + +1. **REPL skeleton** with readline, history, and clean Ctrl‑C/D behavior at prompt. +2. **Lexer** producing tokens (words, ops). Handle quotes during tokenization. +3. **Parser** building an AST/commands list; validate grammar, produce friendly errors. +4. **Executor skeleton** (no pipes/redirs yet): spawn external cmd, run builtins in parent. +5. **PATH resolution** + clear error messages (126/127). +6. **Redirections** (>, >>, <) with FD lifecycle and error propagation. +7. **Pipelines**: connect FDs, collect last status. +8. **Expansion**: `$VAR`, `$?`, quoting rules. +9. **Builtins** complete & consistent (env table, export/unset behavior). +10. **Heredoc** with delimiter rules + SIGINT abort. +11. **Signals in children**: restore defaults; print correct messages. +12. **Cleanups**: sweeping frees on all early‑return/error paths. +13. **Test matrix**: scripts to cover signals, pipes, redirs, heredoc, big env, weird filenames. + +--- + +## Testing + +#### Manual tests (quick checklist) +- **Ctrl‑C at prompt:** + 1. Run `./minishell`. + 2. Press **Ctrl‑C** once: you should see a newline + fresh prompt. + 3. Type `echo $?` → expect `130`. +- **Ctrl‑C while child runs:** + 1. Type `sleep 5` and press **Enter**. + 2. Press **Ctrl‑C** → the sleep ends immediately. + 3. Type `echo $?` → expect `130`. +- **Ctrl‑\ at prompt:** + 1. Press **Ctrl‑\** → nothing should print, prompt remains. + 2. `echo ok` → prints `ok`. `$?` unchanged. +- **Ctrl‑\ while child runs:** + 1. Run `cat` and press **Enter** (it waits on stdin). + 2. Press **Ctrl‑\** → you should see `Quit: 3` and return to prompt. + 3. `echo $?` → expect `131`. +- **Ctrl‑D at prompt (EOF):** + 1. From a fresh `./minishell`, press **Ctrl‑D** on an empty line. + 2. Shell prints `exit` and terminates. + 3. In your outer shell, run `echo $?` → expect previous minishell status (often `0`). +- **Ctrl‑Z (suspend):** + - **At prompt:** press **Ctrl‑Z** → nothing should happen (ignored). + - **While child runs:** run `cat`, then **Ctrl‑Z** → the child stops (`Stopped`) while minishell stays responsive. Since minishell has no job control, manually `kill -SIGCONT ` or `kill -9 ` from another terminal if needed. + +#### Pipeline interruption +- Run: `sleep 5 | cat` → press **Ctrl‑C**. +- Expect all children to terminate and `$?` to reflect the **last command** (typically `130`). + +#### Heredoc specifics +- **Unquoted delimiter (expands):** + ``` + echo start; cat < Date: Sat, 30 Aug 2025 15:02:52 +0200 Subject: [PATCH 11/18] Update README to remove Ctrl-Z section Removed Ctrl-Z behavior description from README. --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 87ac39c..40fab68 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,6 @@ Getting **Ctrl keys** right is a common failure point. The parent shell and its > | Ctrl‑C | newline + prompt | kills child | 130 | > | Ctrl‑\ | ignored | “Quit: 3” | 131 | > | Ctrl‑D | exit shell | (n/a) | last | -> | Ctrl‑Z | ignored | default in child | (n/a) | --- @@ -228,9 +227,6 @@ Also ensure `exit` builtin accepts: `exit`, `exit `, error on too many args, 1. From a fresh `./minishell`, press **Ctrl‑D** on an empty line. 2. Shell prints `exit` and terminates. 3. In your outer shell, run `echo $?` → expect previous minishell status (often `0`). -- **Ctrl‑Z (suspend):** - - **At prompt:** press **Ctrl‑Z** → nothing should happen (ignored). - - **While child runs:** run `cat`, then **Ctrl‑Z** → the child stops (`Stopped`) while minishell stays responsive. Since minishell has no job control, manually `kill -SIGCONT ` or `kill -9 ` from another terminal if needed. #### Pipeline interruption - Run: `sleep 5 | cat` → press **Ctrl‑C**. From 82a2fa12774d93b4c77dda28a68cbafe1d5b3b7f Mon Sep 17 00:00:00 2001 From: grignetta <121875111+grignetta@users.noreply.github.com> Date: Sat, 30 Aug 2025 16:46:17 +0200 Subject: [PATCH 12/18] ft_isspace renamed to ft_isspace_minishell to avoid conflicts with libft, makefile libs order changed --- Makefile | 2 +- include/utils.h | 2 +- src/builtins/exec_builtins_exit.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index b58058c..d30ad7a 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ DEP = $(OBJ:.o=.d) all: $(NAME) $(NAME): $(LIBFT) $(PRINTFD_LIB) $(OBJ) - $(CC) $(CFLAGS) $(OBJ) -L$(LIBDIR) -lft $(PRINTFD_LIB) $(RL_LIB) -o $@ + $(CC) $(CFLAGS) $(OBJ) $(PRINTFD_LIB) -L$(LIBDIR) -lft $(RL_LIB) -o $@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR) @mkdir -p $(dir $@) diff --git a/include/utils.h b/include/utils.h index 433a8b6..bae3e22 100644 --- a/include/utils.h +++ b/include/utils.h @@ -11,7 +11,7 @@ /* ************************************************************************** */ int is_directory(const char *path); -int ft_isspace(char c); +int ft_isspace_minishell(char c); int directory_check(char *arg_0); int is_string_numeric(const char *str); int overflow_check(char *result); diff --git a/src/builtins/exec_builtins_exit.c b/src/builtins/exec_builtins_exit.c index 4312340..ddc5f23 100644 --- a/src/builtins/exec_builtins_exit.c +++ b/src/builtins/exec_builtins_exit.c @@ -32,7 +32,7 @@ static int handle_exit(char *result, t_exec_vars *vars) int is_string_numeric(const char *str) { - while (ft_isspace((unsigned char)*str)) + while (ft_isspace_minishell((unsigned char)*str)) str++; if (*str == '+' || *str == '-') str++; @@ -44,14 +44,14 @@ int is_string_numeric(const char *str) } while (*str) { - if (!ft_isspace((unsigned char)*str)) + if (!ft_isspace_minishell((unsigned char)*str)) return (0); str++; } return (1); } -int ft_isspace(char c) +int ft_isspace_minishell(char c) { return (c == ' ' || c == '\f' From 38af4f369b6097355d7d60f986c236efbcaf1c02 Mon Sep 17 00:00:00 2001 From: Dari <121875111+grignetta@users.noreply.github.com> Date: Sat, 30 Aug 2025 17:03:10 +0200 Subject: [PATCH 13/18] Refactor README for clarity and conciseness Removed duplicate sections and improved formatting in README. --- README.md | 320 +++++++++++++++++++++--------------------------------- 1 file changed, 124 insertions(+), 196 deletions(-) diff --git a/README.md b/README.md index 40fab68..58d0118 100644 --- a/README.md +++ b/README.md @@ -6,33 +6,30 @@ --- ## TL;DR - -* **Goal:** Re‑implement a tiny Bash‑like shell. -* **You must get right:** parsing, quoting, environment/expansion, redirections, pipelines, builtins, **signals** (Ctrl‑C/D/), **heredocs**, and **exit codes**. -* **Why this project matters:** It forces you to build a clean architecture (lexer → parser → executor) and to develop production habits: test harnesses, robust error handling, and clean resource management. +- **Goal:** Re‑implement a tiny Bash‑like shell. +- **You must get right:** parsing, quoting, environment/expansion, redirections, pipelines, builtins, **signals** (Ctrl‑C/D/\), **heredocs**, and **exit codes**. +- **Why this project matters:** It forces you to build a clean architecture (lexer → parser → executor) and to develop production habits: test harnesses, robust error handling, and clean resource management. --- ## Features (Mandatory Scope) - -* Prompt loop using **readline** with history. -* **Lexer/Parser** producing a parse tree (or equivalent) that supports: - - * Words, operators (`|`, `<`, `>`, `<<`, `>>`), and correct **precedence**. - * **Quotes**: single quotes = literal, double quotes = expand `$` & `$?`. -* **Expansion**: `$VAR`, `$?` (last exit status), rules with quotes. -* **Redirections**: `>`, `>>`, `<`, `<<` (heredoc with optional expansion). -* **Pipelines**: `cmd1 | cmd2 | ...` with correct FD wiring. -* **Builtins** implemented in‑process when appropriate: - - * `echo` (with `-n`), `cd`, `pwd`, `export`, `unset`, `env`, `exit`. -* **Signals** & termios behavior matching Bash‐like expectations. -* **No memory leaks** over long interactive sessions; correct cleanup for all code paths. +- Prompt loop using **readline** with history. +- **Lexer/Parser** producing a parse tree (or equivalent) that supports: + - Words, operators (`|`, `<`, `>`, `<<`, `>>`), and correct **precedence**. + - **Quotes**: single quotes = literal, double quotes = expand `$` & `$?`. +- **Expansion**: `$VAR`, `$?` (last exit status), rules with quotes. +- **Redirections**: `>`, `>>`, `<`, `<<` (heredoc with optional expansion). +- **Pipelines**: `cmd1 | cmd2 | ...` with correct FD wiring. +- **Builtins** implemented in‑process when appropriate: + - `echo` (with `-n`), `cd`, `pwd`, `export`, `unset`, `env`, `exit`. +- **Signals** & termios behavior matching Bash‐like expectations. +- **No memory leaks** over long interactive sessions; correct cleanup for all code paths. + +> Bonus ideas (if allowed by your scope): logical ops `&&` / `||`, parentheses, wildcards, etc. (Not required by the classic subject.) --- ## Architecture - ``` include/ # headers src/ @@ -51,15 +48,13 @@ libft/ # submodule (libft.a) tools/suppress/ # sanitizer suppression files (readline, etc.) ``` -* **Executor rule of thumb:** - - * **Single builtin with redirs** → run **in parent** (so it can change shell state). - * **Pipelines / external commands** → run in **children**. +- **Executor rule of thumb:** + - **Single builtin with redirs** → run **in parent** (so it can change shell state). + - **Pipelines / external commands** → run in **children**. --- ## Build & Run - ```sh # clone with submodules git clone --recursive https://github.com/michaela811/minishell.git minishell @@ -73,139 +68,37 @@ make ``` ### Make targets - -* `make` – build `minishell`, `libft.a`, and `libprintf_fd.a`. -* `make clean|fclean|re` – standard hygiene. +- `make` – build `minishell`, `libft.a`, and `libprintf_fd.a`. +- `make clean|fclean|re` – standard hygiene. > If you forgot submodules: `git submodule update --init --recursive`. --- ## The Controls You Must Pass (Signals & TTY behavior) - Getting **Ctrl keys** right is a common failure point. The parent shell and its children must behave differently. ### Ctrl‑C (SIGINT) - -* **At prompt (no child running):** - - * Effect: print a newline, **redisplay prompt**, don’t exit. - * **Exit status** becomes `130` for `$?`. - * Implementation: handle SIGINT in the parent (reset current line via readline hooks), do **not** terminate the shell. -* **While a child runs:** - - * The child receives SIGINT and terminates; parent prints newline and sets status `130`. - -### Ctrl‑\ (SIGQUIT) - -* **At prompt (no child):** ignore (no message, no exit). -* **While a child runs:** if the child doesn’t ignore SIGQUIT, it ends with core‑dump semantics; many testers check for the message `Quit: 3` and **status `131`**. - -### Ctrl‑D (EOF) - -* **At empty prompt:** exit cleanly; print `exit` and return last status. -* **In heredoc:** treated as end of file for the heredoc **only**. - -> **Summary table** -> -> | Key | At prompt (parent) | While child runs | `$?` | -> | ------- | ------------------ | ---------------- | ----- | -> | Ctrl‑C | newline + prompt | kills child | 130 | -> | Ctrl‑\ | ignored | “Quit: 3” | 131 | -> | Ctrl‑D | exit shell | (n/a) | last | - ---- - -## Heredoc Rules That Are Tested - -* **Delimiter quoting controls expansion**: - - * Unquoted delimiter → expand `$VAR` and `$?` inside heredoc. - * Quoted delimiter → **no expansion**. - -* **Signals inside heredoc**: - - * `Ctrl‑C` must **abort** the heredoc, clean temp files, and set status `130`. -* Use a temp file or pipe; ensure **FD hygiene** in pipelines. - ---- - -## Exit Codes You’ll Be Graded On - -* `0` – success. -* `126` – found but **not executable** (permissions / directory exec attempt). -* `127` – **command not found**. -* `130` – terminated by **SIGINT**. -* `131` – terminated by **SIGQUIT**. - -Also ensure `exit` builtin accepts: `exit`, `exit `, error on too many args, numeric parsing as Bash. - ---- - -## Redirections & Pipelines – Common Edge Cases - -* Redirect errors (e.g., `cat < nofile`) must not create processes needlessly; print error and set correct status. -* Mix of redirs & pipelines: last command’s exit status propagates to `$?`. -* `cd` with redirs (e.g., `cd > file`) must still run in parent when possible; handle errors before state changes. +- **At prompt (no child running):** + - Effect: print a newline, **redisplay prompt**, don’t exit. + - **Exit status** becomes `130` for `$?`. + - Implementation: handle SIGINT in the parent (reset current line via readline hooks), do **not** terminate the shell. +- **While a child runs:** + - The **child** receives SIGINT with *default* disposition and terminates. + - The **parent** prints a newline and sets last status to **`130`** (128 + SIGINT). The shell itself stays alive and shows the next prompt. + +**What this means in practice** +- The terminal sends SIGINT to the **foreground process group** (your shell + its children). +- To avoid killing the shell, **parent** installs a custom handler (or temporarily ignores SIGINT) while it **waits** for the child. +- The **child** must have `SIGINT`/`SIGQUIT` restored to **default** before `execve()` so external programs behave normally. +- After `waitpid()`, if the child died from SIGINT, set `$? = 130` and print a newline to keep the prompt on a fresh line. + +**Pipelines** +- All children in the pipeline receive SIGINT. Wait for each PID and set `$?` to the **last command’s** status (commonly `130` if the pipeline was interrupted). --- -## Expansion & Quotes – Quick Rules - -* Single quotes `'...'` → literal. -* Double quotes `"..."` → expand `$VAR` and `$?`; keep spaces as literal characters. -* Unquoted words are subject to splitting by the parser **before** expansion is resolved into argv; design your lexer/parser so that quotes affect tokenization, not post‑processing hacks. - ---- - -## Memory Hygiene & Suppression Files (about “suppress/susspend”) - -`readline` and some system libs can report **false‑positive leaks** under ASan/LSan or Valgrind. Use **suppression files** to focus on *your* leaks. - -* Suppression files live in `tools/suppress/`: - - * `suppress_lnx`, `suppress_mac`, `m_suppress`, etc. -* **Run with Address/Leak sanitizer** (Linux example): - - ```sh - ASAN_OPTIONS="detect_leaks=1:halt_on_error=1:suppressions=tools/suppress/suppress_lnx" \ - LSAN_OPTIONS="suppressions=tools/suppress/suppress_lnx" \ - ./minishell - ``` -* **On macOS** (different env vars): - - ```sh - export ASAN_OPTIONS="detect_leaks=1:suppressions=tools/suppress/suppress_mac" - export LSAN_OPTIONS="suppressions=tools/suppress/suppress_mac" - ./minishell - ``` -* **Why use suppressions?** - - * School testers expect you to eliminate *your* leaks; third‑party library internals (e.g., `readline`) aren’t your responsibility. - -> Still use `valgrind`/ASan on targeted unit tests (builtins, parser failures, heredoc aborts) to prove no leaks on every path. - ---- - -## Step‑by‑Step Plan to Pass - -1. **REPL skeleton** with readline, history, and clean Ctrl‑C/D behavior at prompt. -2. **Lexer** producing tokens (words, ops). Handle quotes during tokenization. -3. **Parser** building an AST/commands list; validate grammar, produce friendly errors. -4. **Executor skeleton** (no pipes/redirs yet): spawn external cmd, run builtins in parent. -5. **PATH resolution** + clear error messages (126/127). -6. **Redirections** (>, >>, <) with FD lifecycle and error propagation. -7. **Pipelines**: connect FDs, collect last status. -8. **Expansion**: `$VAR`, `$?`, quoting rules. -9. **Builtins** complete & consistent (env table, export/unset behavior). -10. **Heredoc** with delimiter rules + SIGINT abort. -11. **Signals in children**: restore defaults; print correct messages. -12. **Cleanups**: sweeping frees on all early‑return/error paths. -13. **Test matrix**: scripts to cover signals, pipes, redirs, heredoc, big env, weird filenames. - ---- - -## Testing +### Testing #### Manual tests (quick checklist) - **Ctrl‑C at prompt:** @@ -234,6 +127,7 @@ Also ensure `exit` builtin accepts: `exit`, `exit `, error on too many args, #### Heredoc specifics - **Unquoted delimiter (expands):** + ``` echo start; cat <`, error on too many args, Should print literal `$USER $?`. - **SIGINT abort:** Start `cat <`, error on too many args, numeric parsing as Bash. + +--- + +## Redirections & Pipelines – Common Edge Cases +- Redirect errors (e.g., `cat < nofile`) must not create processes needlessly; print error and set correct status. +- Mix of redirs & pipelines: last command’s exit status propagates to `$?`. +- `cd` with redirs (e.g., `cd > file`) must still run in parent when possible; handle errors before state changes. + +--- + +## Expansion & Quotes – Quick Rules +- Single quotes `'...'` → literal. +- Double quotes `"..."` → expand `$VAR` and `$?`; keep spaces as literal characters. +- Unquoted words are subject to splitting by the parser **before** expansion is resolved into argv; design your lexer/parser so that quotes affect tokenization, not post‑processing hacks. + +--- + +## Memory Hygiene & Leak Suppressions (Valgrind / ASan) +`readline` and other libs often keep allocations until process exit, which show up as leaks unless you filter them. The goal here is to prove **your code** is leak‑free while ignoring 3rd‑party internals. + +### Valgrind (Linux) — recommended +**Typical command you can copy‑paste:** ```sh -chmod +x tests/ctrl_keys.exp -./tests/ctrl_keys.exp +valgrind \ + --suppressions=tools/suppress/suppress_lnx \ + --leak-check=full \ + --show-leak-kinds=all \ + --track-origins=yes \ + --trace-children=yes \ + --track-fds=yes \ + ./minishell ``` -If a check fails, `expect` will time out or mismatch the pattern. +**What each flag does:** +- `--suppressions=FILE` – ignore known leaks from libraries (e.g., readline). Put your rules in `tools/suppress/suppress_lnx`. +- `--leak-check=full` – show a full backtrace for each leak. +- `--show-leak-kinds=all` – report **definite / indirect / possible / reachable** (see below). +- `--track-origins=yes` – trace uninitialized values to their origin (slower but super useful). +- `--trace-children=yes` – follow fork/exec children. Good for minishell because you spawn processes (pipes, heredoc helpers). If you only want to check the parent shell, set this to `no`. +- `--track-fds=yes` – report file descriptors not closed at exit. + +**Understanding leak kinds:** +- **definitely lost** – real leaks. Fix these. +- **indirectly lost** – leaked via a leaked parent block. Usually fix. +- **possibly lost** – suspicious pointer arithmetic; investigate. +- **still reachable** – memory held until exit (often okay for libs like readline). + +> **Rule of thumb:** your grade depends on fixing **definite/indirect** leaks and FD leaks in your code paths (normal run, errors, heredoc abort). Suppress (or tolerate as *reachable*) what comes from libraries you don’t control. --- -## Developer Notes +## Step‑by‑Step Plan to Pass +1. **REPL skeleton** with readline, history, and clean Ctrl‑C/D behavior at prompt. +2. **Lexer** producing tokens (words, ops). Handle quotes during tokenization. +3. **Parser** building an AST/commands list; validate grammar, produce friendly errors. +4. **Executor skeleton** (no pipes/redirs yet): spawn external cmd, run builtins in parent. +5. **PATH resolution** + clear error messages (126/127). +6. **Redirections** (>, >>, <) with FD lifecycle and error propagation. +7. **Pipelines**: connect FDs, collect last status. +8. **Expansion**: `$VAR`, `$?`, quoting rules. +9. **Builtins** complete & consistent (env table, export/unset behavior). +10. **Heredoc** with delimiter rules + SIGINT abort. +11. **Signals in children**: restore defaults; print correct messages. +12. **Cleanups**: sweeping frees on all early‑return/error paths. +13. **Test matrix**: scripts to cover signals, pipes, redirs, heredoc, big env, weird filenames. -* `libft/` is a **git submodule**. -* `printf_fd/` builds `libprintf_fd.a` and is linked by the top‑level Makefile. -* Object files mirror the `src/` tree; header deps generated via `-MMD -MP`. +--- + +## Developer Notes +- `libft/` is a **git submodule**. +- `printf_fd/` builds `libprintf_fd.a` and is linked by the top‑level Makefile. +- Object files mirror the `src/` tree; header deps generated via `-MMD -MP`. --- ## Credits - Written by Michaela and https://github.com/grignetta. From cce5e985917ea22569ab3b64f1cec14205fd185a Mon Sep 17 00:00:00 2001 From: Dari <121875111+grignetta@users.noreply.github.com> Date: Sat, 30 Aug 2025 17:04:41 +0200 Subject: [PATCH 14/18] Remove duplicate memory leak bullet point Removed redundant bullet point about memory leaks. --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 58d0118..1b8e7d5 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,7 @@ - **Builtins** implemented in‑process when appropriate: - `echo` (with `-n`), `cd`, `pwd`, `export`, `unset`, `env`, `exit`. - **Signals** & termios behavior matching Bash‐like expectations. -- **No memory leaks** over long interactive sessions; correct cleanup for all code paths. - -> Bonus ideas (if allowed by your scope): logical ops `&&` / `||`, parentheses, wildcards, etc. (Not required by the classic subject.) +- **No memory leaks** over long interactive sessions; correct cleanup for all code paths --- From fbbba2a5c25027c97989a7da504303512acfd000 Mon Sep 17 00:00:00 2001 From: grignetta <121875111+grignetta@users.noreply.github.com> Date: Sun, 31 Aug 2025 10:00:45 +0200 Subject: [PATCH 15/18] libft submodule removed, printf_fd folder removed --- Makefile | 33 ++++++---- include/minishell.h | 18 +++--- printf_fd/Makefile | 39 ------------ printf_fd/ft_print_char_fd.c | 19 ------ printf_fd/ft_print_hex_fd.c | 62 ------------------- printf_fd/ft_print_int_fd.c | 64 -------------------- printf_fd/ft_print_percent_fd.c | 19 ------ printf_fd/ft_print_ptr_fd.c | 58 ------------------ printf_fd/ft_print_str_fd.c | 29 --------- printf_fd/ft_print_unsign_int_fd.c | 62 ------------------- printf_fd/ft_printf_fd.c | 96 ------------------------------ printf_fd/ft_printf_fd.h | 41 ------------- src/builtins/exec_builtins_exit.c | 4 +- 13 files changed, 32 insertions(+), 512 deletions(-) delete mode 100644 printf_fd/Makefile delete mode 100644 printf_fd/ft_print_char_fd.c delete mode 100644 printf_fd/ft_print_hex_fd.c delete mode 100644 printf_fd/ft_print_int_fd.c delete mode 100644 printf_fd/ft_print_percent_fd.c delete mode 100644 printf_fd/ft_print_ptr_fd.c delete mode 100644 printf_fd/ft_print_str_fd.c delete mode 100644 printf_fd/ft_print_unsign_int_fd.c delete mode 100644 printf_fd/ft_printf_fd.c delete mode 100644 printf_fd/ft_printf_fd.h diff --git a/Makefile b/Makefile index d30ad7a..42aa642 100644 --- a/Makefile +++ b/Makefile @@ -9,8 +9,8 @@ OBJ_DIR = obj LIBDIR = ./libft LIBFT = $(LIBDIR)/libft.a -PRINTFD_DIR := ./printf_fd -PRINTFD_LIB := $(PRINTFD_DIR)/libprintf_fd.a +#PRINTFD_DIR := ./printf_fd +#PRINTFD_LIB := $(PRINTFD_DIR)/libprintf_fd.a # -------- Readline (Linux/macOS) -------- UNAME_S := $(shell uname -s) @@ -30,33 +30,42 @@ DEP = $(OBJ:.o=.d) all: $(NAME) -$(NAME): $(LIBFT) $(PRINTFD_LIB) $(OBJ) - $(CC) $(CFLAGS) $(OBJ) $(PRINTFD_LIB) -L$(LIBDIR) -lft $(RL_LIB) -o $@ +#$(NAME): $(LIBFT) $(PRINTFD_LIB) $(OBJ) +# $(CC) $(CFLAGS) $(OBJ) $(PRINTFD_LIB) -L$(LIBDIR) -lft $(RL_LIB) -o $@ + +$(NAME): $(LIBFT) $(OBJ) + $(CC) $(CFLAGS) $(OBJ) -L$(LIBDIR) -lft $(RL_LIB) -o $@ + $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR) @mkdir -p $(dir $@) - $(CC) $(CFLAGS) -I$(INC_DIR) -I$(LIBDIR) -I$(PRINTFD_DIR) $(RL_INC) -c $< -o $@ +# $(CC) $(CFLAGS) -I$(INC_DIR) -I$(LIBDIR) -I$(PRINTFD_DIR) $(RL_INC) -c $< -o $@ + $(CC) $(CFLAGS) -I$(INC_DIR) -I$(LIBDIR) $(RL_INC) -c $< -o $@ $(OBJ_DIR): @mkdir -p $(OBJ_DIR) -$(LIBDIR)/.git: - @git submodule update --init --recursive +#$(LIBDIR)/.git: +# @git submodule update --init --recursive -$(LIBFT): | $(LIBDIR)/.git +#$(LIBFT): | $(LIBDIR)/.git +# $(MAKE) -C $(LIBDIR) all + +$(LIBFT): $(MAKE) -C $(LIBDIR) all -$(PRINTFD_LIB): - $(MAKE) -C $(PRINTFD_DIR) all + +#$(PRINTFD_LIB): +# $(MAKE) -C $(PRINTFD_DIR) all clean: $(MAKE) -C $(LIBDIR) clean - $(MAKE) -C $(PRINTFD_DIR) clean +# $(MAKE) -C $(PRINTFD_DIR) clean rm -rf $(OBJ_DIR) fclean: clean $(MAKE) -C $(LIBDIR) fclean - $(MAKE) -C $(PRINTFD_DIR) fclean +# $(MAKE) -C $(PRINTFD_DIR) fclean rm -f $(NAME) re: fclean all diff --git a/include/minishell.h b/include/minishell.h index 262c62e..909568e 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -33,15 +33,15 @@ # include # include # include -# include -# include -# include -# include -# include -# include -# include -# include -# include +# include "structs.h" +# include "lexer_parser.h" +# include "allocs_and_frees.h" +# include "quotes.h" +# include "env.h" +# include "redirections.h" +# include "utils.h" +# include "exec.h" +# include "builtins.h" # include # include diff --git a/printf_fd/Makefile b/printf_fd/Makefile deleted file mode 100644 index fc25a1d..0000000 --- a/printf_fd/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -NAME = libprintf_fd.a -CC = cc -CFLAGS = -Wall -Wextra -Werror -I. -AR = ar rcs - -SRC = \ - ft_printf_fd.c \ - ft_print_char_fd.c \ - ft_print_str_fd.c \ - ft_print_int_fd.c \ - ft_print_unsign_int_fd.c \ - ft_print_hex_fd.c \ - ft_print_ptr_fd.c \ - ft_print_percent_fd.c - -OBJDIR = obj_printf_fd -OBJ = $(addprefix $(OBJDIR)/, $(SRC:.c=.o)) - -all: $(OBJDIR) $(NAME) - -$(OBJDIR): - mkdir -p $(OBJDIR) - -$(NAME): $(OBJ) - $(AR) $@ $^ - -$(OBJDIR)/%.o: %.c ft_printf_fd.h | $(OBJDIR) - $(CC) $(CFLAGS) -c $< -o $@ - -clean: - rm -f $(OBJ) - rm -rf $(OBJDIR) - -fclean: clean - rm -f $(NAME) - -re: fclean all - -.PHONY: all clean fclean re diff --git a/printf_fd/ft_print_char_fd.c b/printf_fd/ft_print_char_fd.c deleted file mode 100644 index 7372de7..0000000 --- a/printf_fd/ft_print_char_fd.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_char.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:36:38 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:38:00 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf_fd.h" - -int ft_print_char_fd(unsigned int fd, char c) -{ - write (fd, &c, 1); - return (1); -} diff --git a/printf_fd/ft_print_hex_fd.c b/printf_fd/ft_print_hex_fd.c deleted file mode 100644 index 5bcf5c4..0000000 --- a/printf_fd/ft_print_hex_fd.c +++ /dev/null @@ -1,62 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_hex.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:38:19 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:45:02 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf_fd.h" - -int ft_hex_len(unsigned int num) -{ - int size; - - size = 0; - while (num) - { - num = num / 16; - size++; - } - return (size); -} - -void ft_put_hex_fd(unsigned int fd, unsigned int num, char placeholder) -{ - if (num >= 16) - { - ft_put_hex_fd(fd, num / 16, placeholder); - ft_put_hex_fd(fd, num % 16, placeholder); - } - else - { - if (num <= 9) - ft_print_char_fd(fd, num + '0'); - else - { - if (placeholder == 'x') - ft_print_char_fd(fd, num - 10 + 'a'); - else if (placeholder == 'X') - ft_print_char_fd(fd, num - 10 + 'A'); - } - } -} - -int ft_print_hex_fd(unsigned int fd, unsigned int num, char placeholder) -{ - int return_len; - - return_len = 0; - if (num == 0) - return_len += write(fd, "0", 1); - else - { - return_len += ft_hex_len(num); - ft_put_hex_fd(fd, num, placeholder); - } - return (return_len); -} diff --git a/printf_fd/ft_print_int_fd.c b/printf_fd/ft_print_int_fd.c deleted file mode 100644 index ddd34c6..0000000 --- a/printf_fd/ft_print_int_fd.c +++ /dev/null @@ -1,64 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_int.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:53:47 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:56:53 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf_fd.h" - -int ft_int_len(int num) -{ - int size; - - size = 0; - if (num < 0) - { - num *= -1; - size += 1; - } - if (num == 0) - size += 1; - while (num) - { - num = num / 10; - size++; - } - return (size); -} - -void ft_put_int_fd(unsigned int fd, int num) -{ - if (num == -2147483648) - { - write(fd, "-2", 2); - num = 147483648; - } - if (num < 0) - { - ft_print_char_fd(fd, '-'); - num *= -1; - } - if (num >= 10) - { - ft_put_int_fd(fd, num / 10); - ft_put_int_fd(fd, num % 10); - } - if (num <= 9) - ft_print_char_fd(fd, num + '0'); -} - -int ft_print_int_fd(unsigned int fd, int nbr) -{ - int return_len; - - return_len = 0; - return_len += ft_int_len(nbr); - ft_put_int_fd(fd, nbr); - return (return_len); -} diff --git a/printf_fd/ft_print_percent_fd.c b/printf_fd/ft_print_percent_fd.c deleted file mode 100644 index 3348130..0000000 --- a/printf_fd/ft_print_percent_fd.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_percent.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 14:03:00 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 14:03:19 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf_fd.h" - -int ft_print_percent_fd(unsigned int fd) -{ - write(fd, "%", 1); - return (1); -} diff --git a/printf_fd/ft_print_ptr_fd.c b/printf_fd/ft_print_ptr_fd.c deleted file mode 100644 index ed686ef..0000000 --- a/printf_fd/ft_print_ptr_fd.c +++ /dev/null @@ -1,58 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_ptr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:45:41 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:48:57 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf_fd.h" - -int ft_ptr_len(unsigned long long num) -{ - int size; - - size = 0; - while (num) - { - num = num / 16; - size++; - } - return (size); -} - -void ft_put_ptr_fd(unsigned int fd, unsigned long long ptr) -{ - if (ptr >= 16) - { - ft_put_ptr_fd(fd, ptr / 16); - ft_put_ptr_fd(fd, ptr % 16); - } - else - { - if (ptr <= 9) - ft_print_char_fd(fd, ptr + '0'); - else - ft_print_char_fd(fd, ptr - 10 + 'a'); - } -} - -int ft_print_ptr_fd(unsigned int fd, unsigned long long ptr) -{ - int return_len; - - return_len = 0; - if (ptr == 0) - return_len = write(fd, "(nil)", 5); - else - { - return_len += write(fd, "0x", 2); - return_len += ft_ptr_len(ptr); - ft_put_ptr_fd(fd, ptr); - } - return (return_len); -} diff --git a/printf_fd/ft_print_str_fd.c b/printf_fd/ft_print_str_fd.c deleted file mode 100644 index 3f2ac05..0000000 --- a/printf_fd/ft_print_str_fd.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_str.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:57:10 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 13:58:02 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf_fd.h" - -int ft_print_str_fd(unsigned int fd, const char *str) -{ - int i; - - i = 0; - if (str == 0) - return (write(fd, "(null)", 6)); - while (*str) - { - ft_print_char_fd(fd, *str); - str++; - i++; - } - return (i); -} diff --git a/printf_fd/ft_print_unsign_int_fd.c b/printf_fd/ft_print_unsign_int_fd.c deleted file mode 100644 index d6a1a69..0000000 --- a/printf_fd/ft_print_unsign_int_fd.c +++ /dev/null @@ -1,62 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_unsign_int.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mmasarov +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 14:03:41 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 14:06:44 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf_fd.h" - -int ft_unsign_int_len(unsigned int num) -{ - int size; - - size = 0; - while (num) - { - size++; - num = num / 10; - } - return (size); -} - -char *ft_put_unsign_int(unsigned int num) -{ - char *nbr; - int len; - - len = ft_unsign_int_len(num); - nbr = malloc(sizeof(char) * (len + 1)); - if (!nbr) - return (0); - nbr[len] = '\0'; - while (num != 0) - { - nbr[len - 1] = num % 10 + '0'; - num = num / 10; - len--; - } - return (nbr); -} - -int ft_print_unsign_int_fd(unsigned int fd, unsigned int num) -{ - int return_len; - char *nbr; - - return_len = 0; - if (num == 0) - return_len += write(fd, "0", 1); - else - { - nbr = ft_put_unsign_int(num); - return_len += ft_print_str_fd(fd, nbr); - free(nbr); - } - return (return_len); -} diff --git a/printf_fd/ft_printf_fd.c b/printf_fd/ft_printf_fd.c deleted file mode 100644 index 43defc4..0000000 --- a/printf_fd/ft_printf_fd.c +++ /dev/null @@ -1,96 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_printf_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: dpadenko +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/04 13:58:33 by mmasarov #+# #+# */ -/* Updated: 2023/10/04 14:02:30 by mmasarov ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef FT_PRINTF_FD_H -# define FT_PRINTF_FD_H - -# include -# include -# include -# include -# include - -int ft_print_char_fd(unsigned int fd, char c); -int ft_hex_len(unsigned int num); -void ft_put_hex_fd(unsigned int fd, unsigned int num, char placeholder); -int ft_print_hex_fd(unsigned int fd, unsigned int num, char placeholder); -int ft_int_len(int num); -void ft_put_int_fd(unsigned int fd, int num); -int ft_print_int_fd(unsigned int fd, int nbr); -int ft_print_percent_fd(unsigned int fd); -int ft_ptr_len(unsigned long long num); -void ft_put_ptr_fd(unsigned int fd, unsigned long long ptr); -int ft_print_ptr_fd(unsigned int fd, unsigned long long ptr); -int ft_print_str_fd(unsigned int fd, const char *str); -int ft_unsign_int_len(unsigned int num); -char *ft_put_unsign_int(unsigned int num); -int ft_print_unsign_int_fd(unsigned int fd, unsigned int num); -int ft_format_fd(unsigned int fd, char placeholder, va_list args); -int ft_printf_fd(unsigned int fd, const char *print, ...); -int ft_vprintf_fd(unsigned int fd, const char *print, va_list args); - -#endif diff --git a/src/builtins/exec_builtins_exit.c b/src/builtins/exec_builtins_exit.c index ddc5f23..6df3f36 100644 --- a/src/builtins/exec_builtins_exit.c +++ b/src/builtins/exec_builtins_exit.c @@ -66,7 +66,7 @@ int overflow_check(char *result) char *end; char *num; - while (isspace((unsigned char)*result)) + while (ft_isspace_minishell((unsigned char)*result)) result++; end = result; if (*result == '+' || *result == '-') @@ -77,7 +77,7 @@ int overflow_check(char *result) end++; while (*end != '\0') { - if (!isspace((unsigned char)*end)) + if (!ft_isspace_minishell((unsigned char)*end)) return (0); end++; } From cfbb5407bc3834fec0749a3ef56dfd6f7337a0fa Mon Sep 17 00:00:00 2001 From: grignetta <121875111+grignetta@users.noreply.github.com> Date: Sun, 31 Aug 2025 10:04:02 +0200 Subject: [PATCH 16/18] Remove libft submodule --- libft | 1 - 1 file changed, 1 deletion(-) delete mode 160000 libft diff --git a/libft b/libft deleted file mode 160000 index 405246e..0000000 --- a/libft +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 405246e8bb84f8f3cfeef6e4fa64d58d15e68a01 From 1c395699a6ddaf2ddc7573aed2acf0120effa930 Mon Sep 17 00:00:00 2001 From: grignetta <121875111+grignetta@users.noreply.github.com> Date: Sun, 31 Aug 2025 10:06:26 +0200 Subject: [PATCH 17/18] libft added as a usual folder --- libft/.DS_Store | Bin 0 -> 6148 bytes libft/Makefile | 99 ++++++++++++++++++++++++++++ libft/ft_atoi | Bin 0 -> 19528 bytes libft/ft_atoi.c | 49 ++++++++++++++ libft/ft_bzero.c | 25 +++++++ libft/ft_calloc.c | 24 +++++++ libft/ft_exact_strcmp.c | 20 ++++++ libft/ft_isalnum.c | 23 +++++++ libft/ft_isalpha.c | 22 +++++++ libft/ft_isascii.c | 21 ++++++ libft/ft_isdigit.c | 21 ++++++ libft/ft_isprint.c | 21 ++++++ libft/ft_itoa.c | 80 +++++++++++++++++++++++ libft/ft_memchr.c | 29 +++++++++ libft/ft_memcmp.c | 34 ++++++++++ libft/ft_memcpy.c | 28 ++++++++ libft/ft_memmove.c | 40 ++++++++++++ libft/ft_memset | Bin 0 -> 19368 bytes libft/ft_memset.c | 26 ++++++++ libft/ft_print_char.c | 19 ++++++ libft/ft_print_char_fd.c | 19 ++++++ libft/ft_print_hex.c | 62 ++++++++++++++++++ libft/ft_print_hex_fd.c | 62 ++++++++++++++++++ libft/ft_print_int.c | 64 ++++++++++++++++++ libft/ft_print_int_fd.c | 64 ++++++++++++++++++ libft/ft_print_percent.c | 19 ++++++ libft/ft_print_percent_fd.c | 19 ++++++ libft/ft_print_ptr.c | 58 +++++++++++++++++ libft/ft_print_ptr_fd.c | 58 +++++++++++++++++ libft/ft_print_str.c | 29 +++++++++ libft/ft_print_str_fd.c | 29 +++++++++ libft/ft_print_unsign_int.c | 62 ++++++++++++++++++ libft/ft_print_unsign_int_fd.c | 62 ++++++++++++++++++ libft/ft_printf.c | 69 ++++++++++++++++++++ libft/ft_printf.h | 40 ++++++++++++ libft/ft_printf_fd.c | 96 +++++++++++++++++++++++++++ libft/ft_printf_fd.h | 40 ++++++++++++ libft/ft_putchar_fd.c | 18 +++++ libft/ft_putendl_fd.c | 25 +++++++ libft/ft_putnbr_fd.c | 31 +++++++++ libft/ft_putstr_fd.c | 25 +++++++ libft/ft_realloc.c | 35 ++++++++++ libft/ft_split.c | 83 +++++++++++++++++++++++ libft/ft_strcat.c | 32 +++++++++ libft/ft_strchr.c | 35 ++++++++++ libft/ft_strcmp.c | 23 +++++++ libft/ft_strcpy.c | 28 ++++++++ libft/ft_strdup.c | 33 ++++++++++ libft/ft_striteri.c | 27 ++++++++ libft/ft_strjoin.c | 37 +++++++++++ libft/ft_strlcat.c | 39 +++++++++++ libft/ft_strlcpy.c | 35 ++++++++++ libft/ft_strlen.c | 26 ++++++++ libft/ft_strmapi.c | 33 ++++++++++ libft/ft_strncat.c | 30 +++++++++ libft/ft_strncmp.c | 28 ++++++++ libft/ft_strncpy.c | 31 +++++++++ libft/ft_strndup.c | 29 +++++++++ libft/ft_strnstr.c | 39 +++++++++++ libft/ft_strpbrk.c | 26 ++++++++ libft/ft_strrchr.c | 27 ++++++++ libft/ft_strtok.c | 71 ++++++++++++++++++++ libft/ft_strtrim.c | 56 ++++++++++++++++ libft/ft_substr.c | 48 ++++++++++++++ libft/ft_tolower.c | 20 ++++++ libft/ft_toupper.c | 20 ++++++ libft/get_next_line.c | 116 +++++++++++++++++++++++++++++++++ libft/get_next_line_utils.c | 66 +++++++++++++++++++ libft/libft.h | 97 +++++++++++++++++++++++++++ 69 files changed, 2702 insertions(+) create mode 100644 libft/.DS_Store create mode 100644 libft/Makefile create mode 100755 libft/ft_atoi create mode 100644 libft/ft_atoi.c create mode 100644 libft/ft_bzero.c create mode 100644 libft/ft_calloc.c create mode 100644 libft/ft_exact_strcmp.c create mode 100644 libft/ft_isalnum.c create mode 100644 libft/ft_isalpha.c create mode 100644 libft/ft_isascii.c create mode 100644 libft/ft_isdigit.c create mode 100644 libft/ft_isprint.c create mode 100644 libft/ft_itoa.c create mode 100644 libft/ft_memchr.c create mode 100644 libft/ft_memcmp.c create mode 100644 libft/ft_memcpy.c create mode 100644 libft/ft_memmove.c create mode 100755 libft/ft_memset create mode 100644 libft/ft_memset.c create mode 100644 libft/ft_print_char.c create mode 100644 libft/ft_print_char_fd.c create mode 100644 libft/ft_print_hex.c create mode 100644 libft/ft_print_hex_fd.c create mode 100644 libft/ft_print_int.c create mode 100644 libft/ft_print_int_fd.c create mode 100644 libft/ft_print_percent.c create mode 100644 libft/ft_print_percent_fd.c create mode 100644 libft/ft_print_ptr.c create mode 100644 libft/ft_print_ptr_fd.c create mode 100644 libft/ft_print_str.c create mode 100644 libft/ft_print_str_fd.c create mode 100644 libft/ft_print_unsign_int.c create mode 100644 libft/ft_print_unsign_int_fd.c create mode 100644 libft/ft_printf.c create mode 100644 libft/ft_printf.h create mode 100644 libft/ft_printf_fd.c create mode 100644 libft/ft_printf_fd.h create mode 100644 libft/ft_putchar_fd.c create mode 100644 libft/ft_putendl_fd.c create mode 100644 libft/ft_putnbr_fd.c create mode 100644 libft/ft_putstr_fd.c create mode 100644 libft/ft_realloc.c create mode 100644 libft/ft_split.c create mode 100644 libft/ft_strcat.c create mode 100644 libft/ft_strchr.c create mode 100644 libft/ft_strcmp.c create mode 100644 libft/ft_strcpy.c create mode 100644 libft/ft_strdup.c create mode 100644 libft/ft_striteri.c create mode 100644 libft/ft_strjoin.c create mode 100644 libft/ft_strlcat.c create mode 100644 libft/ft_strlcpy.c create mode 100644 libft/ft_strlen.c create mode 100644 libft/ft_strmapi.c create mode 100644 libft/ft_strncat.c create mode 100644 libft/ft_strncmp.c create mode 100644 libft/ft_strncpy.c create mode 100644 libft/ft_strndup.c create mode 100644 libft/ft_strnstr.c create mode 100644 libft/ft_strpbrk.c create mode 100644 libft/ft_strrchr.c create mode 100644 libft/ft_strtok.c create mode 100644 libft/ft_strtrim.c create mode 100644 libft/ft_substr.c create mode 100644 libft/ft_tolower.c create mode 100644 libft/ft_toupper.c create mode 100644 libft/get_next_line.c create mode 100644 libft/get_next_line_utils.c create mode 100644 libft/libft.h diff --git a/libft/.DS_Store b/libft/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 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 V*QzVYLVT98|J5ExYv4od{|9fzo+tnS literal 0 HcmV?d00001 diff --git a/libft/ft_atoi.c b/libft/ft_atoi.c new file mode 100644 index 0000000..0a2602a --- /dev/null +++ b/libft/ft_atoi.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov = 9 && **nptr <= 13))) + (*nptr)++; + if (**nptr == '-') + (*minus)++; + if (**nptr == '-' || **nptr == '+') + (*nptr)++; + while (**nptr == '0') + (*nptr)++; +} + +int ft_atoi(const char *nptr) +{ + int minus; + long long int number; + + number = 0; + minus = 0; + move_spaces(&nptr, &minus); + if (ft_strcmp(nptr, "9223372036854775808") == 0 && minus == 1) + return (INT_MIN); + if ((*nptr <= 47) || (*nptr >= 58 && *nptr < 127)) + return (0); + while (*nptr >= '0' && *nptr <= '9') + { + if (number > (LLONG_MAX - (*nptr - '0')) / 10) + return (INT_MAX); + number = number * 10 + (*nptr - '0'); + nptr++; + } + if (minus == 1 && number != 0) + return (-number); + return (number); +} diff --git a/libft/ft_bzero.c b/libft/ft_bzero.c new file mode 100644 index 0000000..107a23d --- /dev/null +++ b/libft/ft_bzero.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/06 12:24:58 by mmasarov #+# #+# */ +/* Updated: 2023/09/07 09:57:58 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + size_t i; + + i = 0; + while (i < n) + { + ((unsigned char *)s)[i] = 0; + i++; + } +} diff --git a/libft/ft_calloc.c b/libft/ft_calloc.c new file mode 100644 index 0000000..9ca4a3e --- /dev/null +++ b/libft/ft_calloc.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/13 09:22:59 by mmasarov #+# #+# */ +/* Updated: 2023/09/13 10:01:52 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_calloc(size_t nmemb, size_t size) +{ + void *ptr; + + ptr = (void *)malloc(nmemb * size); + if (!ptr) + return (0); + ft_memset(ptr, 0, (nmemb * size)); + return (ptr); +} diff --git a/libft/ft_exact_strcmp.c b/libft/ft_exact_strcmp.c new file mode 100644 index 0000000..6766403 --- /dev/null +++ b/libft/ft_exact_strcmp.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_exact_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/06 10:12:34 by mmasarov #+# #+# */ +/* Updated: 2023/09/06 10:25:27 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int c) +{ + if ((c >= 'a' && c <= 'z') + || (c >= 'A' && c <= 'Z') + || (c >= '0' && c <= '9')) + return (8); + else + return (0); +} diff --git a/libft/ft_isalpha.c b/libft/ft_isalpha.c new file mode 100644 index 0000000..b91d3c0 --- /dev/null +++ b/libft/ft_isalpha.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/06 09:26:15 by mmasarov #+# #+# */ +/* Updated: 2023/09/13 15:51:28 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalpha(int c) +{ + if ((c >= 'a' && c <= 'z') + || (c >= 'A' && c <= 'Z')) + return (1024); + else + return (0); +} diff --git a/libft/ft_isascii.c b/libft/ft_isascii.c new file mode 100644 index 0000000..15528c5 --- /dev/null +++ b/libft/ft_isascii.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/06 10:26:04 by mmasarov #+# #+# */ +/* Updated: 2023/09/06 10:44:18 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isascii(int c) +{ + if (c >= 0 && c <= 127) + return (1); + else + return (0); +} diff --git a/libft/ft_isdigit.c b/libft/ft_isdigit.c new file mode 100644 index 0000000..a9f6b17 --- /dev/null +++ b/libft/ft_isdigit.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/06 10:00:37 by mmasarov #+# #+# */ +/* Updated: 2023/09/06 10:11:18 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isdigit(int c) +{ + if (c >= '0' && c <= '9') + return (2048); + else + return (0); +} diff --git a/libft/ft_isprint.c b/libft/ft_isprint.c new file mode 100644 index 0000000..f6ac899 --- /dev/null +++ b/libft/ft_isprint.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/06 10:45:00 by mmasarov #+# #+# */ +/* Updated: 2023/09/06 10:48:23 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isprint(int c) +{ + if (c >= 32 && c <= 126) + return (16384); + else + return (0); +} diff --git a/libft/ft_itoa.c b/libft/ft_itoa.c new file mode 100644 index 0000000..2e8fb03 --- /dev/null +++ b/libft/ft_itoa.c @@ -0,0 +1,80 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/12 11:40:53 by mmasarov #+# #+# */ +/* Updated: 2023/09/12 13:03:16 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int ft_numlen(int num) +{ + int count; + + count = 0; + if (num == -2147483648 || num == 2147483647) + { + count = 10; + return (count); + } + if (num == 0) + count = 1; + while (num) + { + num = num / 10; + count++; + } + return (count); +} + +static int ft_is_negative(int n) +{ + int minus; + + minus = 0; + if (n < 0) + minus = 1; + return (minus); +} + +static char *ft_digits(void) +{ + char *digits; + + digits = "0123456789"; + return (digits); +} + +char *ft_itoa(int n) +{ + char *num_str; + size_t len; + int minus; + + minus = ft_is_negative(n); + if (n < 0) + n = n * (-1); + len = ft_numlen(n) + minus; + num_str = malloc((sizeof(char) * (len + 1))); + if (num_str == NULL) + return (NULL); + if (n == -2147483648) + { + num_str = ft_strcpy(num_str, "-2147483648"); + return (num_str); + } + num_str[len] = '\0'; + while (len-- > (unsigned int)minus) + { + num_str[len] = ft_digits()[n % 10]; + n /= 10; + } + if (minus == 1) + num_str[len] = '-'; + return (num_str); +} diff --git a/libft/ft_memchr.c b/libft/ft_memchr.c new file mode 100644 index 0000000..d86b2bd --- /dev/null +++ b/libft/ft_memchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/07 11:57:01 by mmasarov #+# #+# */ +/* Updated: 2023/09/07 13:35:21 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + size_t i; + char *string; + + i = 0; + string = (void *)s; + while (i < n) + { + if (string[i] == (char)c) + return (&string[i]); + i++; + } + return (NULL); +} diff --git a/libft/ft_memcmp.c b/libft/ft_memcmp.c new file mode 100644 index 0000000..b0d67c8 --- /dev/null +++ b/libft/ft_memcmp.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/07 13:35:55 by mmasarov #+# #+# */ +/* Updated: 2023/09/07 13:57:32 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + char *str1; + char *str2; + size_t i; + + i = 0; + if (n == 0) + return (0); + str1 = (void *)s1; + str2 = (void *)s2; + while (i < n) + { + if ((unsigned char)str1[i] < (unsigned char)str2[i] + || (unsigned char)str1[i] > (unsigned char)str2[i]) + return ((unsigned char)str1[i] - (unsigned char)str2[i]); + i++; + } + return (0); +} diff --git a/libft/ft_memcpy.c b/libft/ft_memcpy.c new file mode 100644 index 0000000..172208c --- /dev/null +++ b/libft/ft_memcpy.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/06 13:14:51 by mmasarov #+# #+# */ +/* Updated: 2023/09/07 09:57:26 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dest, const void *src, size_t n) +{ + size_t i; + + i = 0; + if (!dest && !src) + return (0); + while (i < n) + { + ((unsigned char *)dest)[i] = ((unsigned char *)src)[i]; + i++; + } + return (dest); +} diff --git a/libft/ft_memmove.c b/libft/ft_memmove.c new file mode 100644 index 0000000..1e68dd0 --- /dev/null +++ b/libft/ft_memmove.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/06 14:11:01 by mmasarov #+# #+# */ +/* Updated: 2023/09/13 15:53:55 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memmove(void *dest, const void *src, size_t n) +{ + char *d; + char *s; + size_t i; + + d = (char *)dest; + s = (char *)src; + i = 0; + if (src < dest) + { + while (n--) + { + d[n] = s[n]; + } + } + else if (src > dest) + { + while (n--) + { + d[i] = s[i]; + i++; + } + } + return (dest); +} diff --git a/libft/ft_memset b/libft/ft_memset new file mode 100755 index 0000000000000000000000000000000000000000..ccbfdd19c7b1ade5eacfbaa1ae05a8973b89823e GIT binary patch literal 19368 zcmeHPeQ+Dcb>9OB64a3(NXix^Iu@+RjZ}x=hbft|Obeh$3QQ=;mdRS0SU!WmkwgUo z^x+_hnZ%aMCSyjSYj-k@(>gP1+_-6)KhoBjdZy!+9(i16rtR1>t*uT!tS0tEtzAcP z;|$xxLVs^>9|#=5deZifPUm(6ynVm-wflCDw|ltN!z1IPK1~x`{NheQTrBJ$F(ue_ zP*p%;Vn8(GdxyA5)Pt{+m?Mul1X8D5@>SEI!u_CR*FlvU^ackOOu2!(x7~4N=cdETjw!{Ua?e|K`o9zJE@f92k#2;WavY`{ z?{3)1yf|hb`pv_9OvT%19KtI9OjUYCcQ!M%x4%1^?#gCz#j{;!2ljUD?T;4n(LNcQ z+C?#FP8~WjDd1*>FqK9*7Mm3><)6$?{@&HMpFZ)(8;OVSZN2NGrB`~{2gM{EDrC=7 zf_SP^4AOD>{|IVoE`z>m{?(iWHuxF<9;qSQ2CS_HJ^?IJ15a&$>%e!^&=<&Giqf@L z7)I)B(wNTVlG)6sO|T>~3U<=6jk#ndCk~B|4IMQ4qJ7al!Wf%4Y@|)goXHey)0#MZ zFq_Yr6UnJ8ScD_FOx`?zof>m|h zGJaV(2*w;aXFS%hM`QCpWTYB~W#M1W?i*H`NYhrvk@EchACYGDGOETyODP3p5qPdg+SeiU5vn6}W9f3s_Hz{YqN32xNc}xiM0Q_GEL}~!@a}=c3#R%Vc74&_~t8(pz>@;{0Gem@B(WrP7r& zzFrD^fL*tC61G+L|9l2Qax@9M#L{Q4EEV5OEKOcY{Q1Z#we@XuVe(4i{K#rTd*%G( zn~#PQizBO=1on?yvi=FRD?%Fp=Hd*e&*4ln&6UfTRdV)3Gu*!K^` zf1&aF)XDgL@ssiU1fOLU!|~eyl7-8t{nIBNK3KzLjfR_O;16~Ha40svv zGT>#v%Yc^wF9ZKiGoax&Fs;+SKZgD_;B&*(QppDWIOtQLcYxjpdh?G;rDs8BK>r%_ zGoU{PeFyXo?C&?DPDT6lF`=CeYn@FE!N(O&zu{l{VW~trZ!z2;e?i-cYCk>~fJ-10 z9u0MTqD4OwJSPrpyZsk$-6?-oB)=5@QPxA93i-70$)J5h1dN2jpZ6VXu3tc4uq6Ky zKIb8C0WHf%9XTEmh-dLR2f0b|(NOr;d}E=G$NVFq$a39CXxA45!=awf*C#>)iw%cD zv0P{%9_opQb`6ChL!pkLP#v%Yc^wF9Ti% zybO35_`i|?ey@?=W5gCs7N$+yQ1zZ;v*K6P`;c1|&+kiiDxTkir1wgx@OzWA52M2J z_pg=m#9vS^JMy0Ccpahqj;jzaEBPh|7N1p=-Z!Pv;Sh11qD+*TSW)ju(w>$|PzB<4 ztVmP{yaXx>`@2!`toPHB(_Z99Lihz%w*QK1FMb)8Jm(MFK*_(RFO;?uJ@t7o@h^hv~RbA%U5TeS6Q88?N(Fd z?hTsq+sJ{Fm7qq$(sV15wgnz)8Tz!~DTsZ(hMy3rYgi-_YRzD|Yfj@#9e_bGx zvmp!Y1Xy<*4t-BCyj@ zBzH(=K!1^J1|<{If0xu^l1b^=k?RXj7i4U4T|##-Gu2`{T^ZtxAlWLr$0$*M_R_f{EGftBsm)VO<;?97cqCY zd=t#0dWx76%@0EDas3gp`P7#0fIO)mBIdrWD$@OLe@|++gqrEWRDE!XxF88aG#jX0 zEkmdfN-b)BNGg1rs>8DSC-|1Suc0D!+ePC%>cOSZ_oN05cH`d=@&$=Bb|6&nyi@-w zTsLl$b0xF`7sD2O!lI!Gq(1mX2peudwUN@$*tw0QtuF%AIs-IsPN~bQ1$8RgQ*H0S zxz^G^3E^vKNXkgsUVv;1$$U>7Z%=`_k=*#6m}t*|*+rT2J(1X)5n5}b!_302Rl7OV zuKPosp;oP}A-n}jJB6;_2?!U9s^WsLyI%N1x9j`$efn5Cu7MUPp&vwuZ}4}G;OS%^jmI1v~K8y zZ$htHqvF8UwZ>6DVjW)|fsWh*tUVz7LGF+b_k+!7XcZt%BHwEGX_A>-v3n|G z7aSFwhv=S3rPizLW9uqcRm^%L^4o1M%$o%vrg6f;oGX}i6yuKvri4ak@yJ&c>~z|k zMjf-Pn8R6%H0t>4JY(AVdD}?kEt3_kV#+o~$Hqqh1n{7=T!T?2@0b-93WjM}SvYdc zL_iabKAx5S7A;U0>&3wfl4jLujY+cf5F7))oAGX-fkRh%}ak_9@K!jTQyQQJ9&C{Gxb9HlI2rYD~QD%3(KBMGM23EzTiQ zKASf3)6gdsahjaloP(~)AXSTNIl0)xldpVV4o{zyrl6iW?P$ueaQb*!PAASCxsek<3M=M5 zbr}DoCuvQik0AM?gVBhg86Q&oxK=xGUAl`O7cQUctCab15%amdYP?Q-rly}jdHr3j zUteB#SK|$W*XPxEQ1Cjp8gCT5KCZ?$mDl0bIQ`|WM4Y-`G>J$}yjk?r#6#tCtCimT zqDAojr5cBmNG0Ob{i0RW)x_IGq9)!hct2F>&5vKjcpp@aW7l$LCF0cm;`;KwrBdn_ zxC_TB5!UYz;hH$_(yDFzf_GmtFX6z;U&d^FZ;ajN+r!$UhyHq`15fCS58E_-JDNIMVX5R{J;V z*Y8L_ZDN8N>?*bV{GrroUpG%K0@rAF>zXHjq4eGJ?G1^qpSSNxKkMh!Gw6U%tiSGp zz}t|Yt7^508@?>Gj*X~#C7G7^`uW)pJdAnko}X>N+kES<$NhvOF0UAP9XlfN%7{)q zt^B*MiwA*6)~kziz*~J=1n+ZMWtnial#QGXst`{Br}msvc`%j1pMr)l-#TLK!J)sb z^kZs%b}R9>fRnyE56>xm_o|-umefwS{&#^#szXZd`@nb9z(vZk3w9B2ey7CRaazNk zGg5S*7K;rdoi}E(`Ke^qNMl`8Fp|ZyB9)(;&ziQGjt=zf?X9guM|m?w(z22ZxXIhr zf|$0FbGY9Y=jIk*Qo$L}w5wGsR-}e8dMti;#27g;Y~VO=wK7%>!zYf!504$JmdJC% zfUrh1MiR-C$ zJ+blHQRP^y>a4O{VmRlKp<8`8*+>`i#%wZ|ri070UZAChK`SM8OKqb3fS)Q9lpAOD zXyDv4r-d3^^OSS-x$5esiD+SA4r>-r+j8hE*RZfNt$7j6VMQFpP9%!8@w{o-3l-2* zF@vM;nY4o9Lt|J_&j_hLiv_cYrWbMu;ZQ7cq~tVKu~@sD@u{$ zyZirT$f-{(r(2#Zin>>T?(zF7lq>Bc%8n_!Q(oQf#n)W+ynbi;VfMf8vX3bPrr&W5 znA_hUxa@g9z?6UI;P$)w|HsO{jTIuQqNrP+d8U5`b!sAyAMY=i4l8#|*pB(XM5WT6 z_aRKfuKx4*v;FI+(ArvEcIEvF|Gy}1edd{dAGY-5k?nb3v)Tm^h4mb6jc5Fa5YXIX z`|`Rr>R7C(_S5{Q!gf54&j2G8w&&k>R@6c(23cicd#0-pR@#f0((Z96$5CiGKJ(X5 zAzvJy*Joj6&v97aH5`J@KoX|ZSxvD0EoH>1uszczW$#iG`;|ktU$$fY&JFBODZ{UG z$CQEF{$m^1hv}(5%12xVE>`T>z`kpbW1n;xxL6Ta_U?W@MmIK;AMl0curk+FWj{n+ zDpK?8K1sv_>JMWCY%e}Mo_zmk1m;Q+5d6Y(KoU{nKn`1ut61zYYTLgacQnR7#Qr}4 D{7*nU literal 0 HcmV?d00001 diff --git a/libft/ft_memset.c b/libft/ft_memset.c new file mode 100644 index 0000000..1409a0a --- /dev/null +++ b/libft/ft_memset.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/06 11:16:16 by mmasarov #+# #+# */ +/* Updated: 2023/09/13 15:53:06 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memset(void *s, int c, size_t n) +{ + size_t i; + + i = 0; + while (i < n) + { + ((unsigned char *)s)[i] = c; + i++; + } + return (s); +} diff --git a/libft/ft_print_char.c b/libft/ft_print_char.c new file mode 100644 index 0000000..8409bff --- /dev/null +++ b/libft/ft_print_char.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_char.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:36:38 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:38:00 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +int ft_print_char(char c) +{ + write (1, &c, 1); + return (1); +} diff --git a/libft/ft_print_char_fd.c b/libft/ft_print_char_fd.c new file mode 100644 index 0000000..7372de7 --- /dev/null +++ b/libft/ft_print_char_fd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_char.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:36:38 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:38:00 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf_fd.h" + +int ft_print_char_fd(unsigned int fd, char c) +{ + write (fd, &c, 1); + return (1); +} diff --git a/libft/ft_print_hex.c b/libft/ft_print_hex.c new file mode 100644 index 0000000..077ade9 --- /dev/null +++ b/libft/ft_print_hex.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_hex.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:38:19 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:45:02 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +int ft_hex_len(unsigned int num) +{ + int size; + + size = 0; + while (num) + { + num = num / 16; + size++; + } + return (size); +} + +void ft_put_hex(unsigned int num, char placeholder) +{ + if (num >= 16) + { + ft_put_hex(num / 16, placeholder); + ft_put_hex(num % 16, placeholder); + } + else + { + if (num <= 9) + ft_print_char(num + '0'); + else + { + if (placeholder == 'x') + ft_print_char(num - 10 + 'a'); + else if (placeholder == 'X') + ft_print_char(num - 10 + 'A'); + } + } +} + +int ft_print_hex(unsigned int num, char placeholder) +{ + int return_len; + + return_len = 0; + if (num == 0) + return_len += write(1, "0", 1); + else + { + return_len += ft_hex_len(num); + ft_put_hex(num, placeholder); + } + return (return_len); +} diff --git a/libft/ft_print_hex_fd.c b/libft/ft_print_hex_fd.c new file mode 100644 index 0000000..5bcf5c4 --- /dev/null +++ b/libft/ft_print_hex_fd.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_hex.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:38:19 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:45:02 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf_fd.h" + +int ft_hex_len(unsigned int num) +{ + int size; + + size = 0; + while (num) + { + num = num / 16; + size++; + } + return (size); +} + +void ft_put_hex_fd(unsigned int fd, unsigned int num, char placeholder) +{ + if (num >= 16) + { + ft_put_hex_fd(fd, num / 16, placeholder); + ft_put_hex_fd(fd, num % 16, placeholder); + } + else + { + if (num <= 9) + ft_print_char_fd(fd, num + '0'); + else + { + if (placeholder == 'x') + ft_print_char_fd(fd, num - 10 + 'a'); + else if (placeholder == 'X') + ft_print_char_fd(fd, num - 10 + 'A'); + } + } +} + +int ft_print_hex_fd(unsigned int fd, unsigned int num, char placeholder) +{ + int return_len; + + return_len = 0; + if (num == 0) + return_len += write(fd, "0", 1); + else + { + return_len += ft_hex_len(num); + ft_put_hex_fd(fd, num, placeholder); + } + return (return_len); +} diff --git a/libft/ft_print_int.c b/libft/ft_print_int.c new file mode 100644 index 0000000..6f09bf0 --- /dev/null +++ b/libft/ft_print_int.c @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_int.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:53:47 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:56:53 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +int ft_int_len(int num) +{ + int size; + + size = 0; + if (num < 0) + { + num *= -1; + size += 1; + } + if (num == 0) + size += 1; + while (num) + { + num = num / 10; + size++; + } + return (size); +} + +void ft_put_int(int num) +{ + if (num == -2147483648) + { + write(1, "-2", 2); + num = 147483648; + } + if (num < 0) + { + ft_print_char('-'); + num *= -1; + } + if (num >= 10) + { + ft_put_int(num / 10); + ft_put_int(num % 10); + } + if (num <= 9) + ft_print_char(num + '0'); +} + +int ft_print_int(int nbr) +{ + int return_len; + + return_len = 0; + return_len += ft_int_len(nbr); + ft_put_int(nbr); + return (return_len); +} diff --git a/libft/ft_print_int_fd.c b/libft/ft_print_int_fd.c new file mode 100644 index 0000000..ddd34c6 --- /dev/null +++ b/libft/ft_print_int_fd.c @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_int.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:53:47 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:56:53 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf_fd.h" + +int ft_int_len(int num) +{ + int size; + + size = 0; + if (num < 0) + { + num *= -1; + size += 1; + } + if (num == 0) + size += 1; + while (num) + { + num = num / 10; + size++; + } + return (size); +} + +void ft_put_int_fd(unsigned int fd, int num) +{ + if (num == -2147483648) + { + write(fd, "-2", 2); + num = 147483648; + } + if (num < 0) + { + ft_print_char_fd(fd, '-'); + num *= -1; + } + if (num >= 10) + { + ft_put_int_fd(fd, num / 10); + ft_put_int_fd(fd, num % 10); + } + if (num <= 9) + ft_print_char_fd(fd, num + '0'); +} + +int ft_print_int_fd(unsigned int fd, int nbr) +{ + int return_len; + + return_len = 0; + return_len += ft_int_len(nbr); + ft_put_int_fd(fd, nbr); + return (return_len); +} diff --git a/libft/ft_print_percent.c b/libft/ft_print_percent.c new file mode 100644 index 0000000..13daba7 --- /dev/null +++ b/libft/ft_print_percent.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_percent.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 14:03:00 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 14:03:19 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +int ft_print_percent(void) +{ + write(1, "%", 1); + return (1); +} diff --git a/libft/ft_print_percent_fd.c b/libft/ft_print_percent_fd.c new file mode 100644 index 0000000..3348130 --- /dev/null +++ b/libft/ft_print_percent_fd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_percent.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 14:03:00 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 14:03:19 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf_fd.h" + +int ft_print_percent_fd(unsigned int fd) +{ + write(fd, "%", 1); + return (1); +} diff --git a/libft/ft_print_ptr.c b/libft/ft_print_ptr.c new file mode 100644 index 0000000..3d8443d --- /dev/null +++ b/libft/ft_print_ptr.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_ptr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:45:41 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:48:57 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +int ft_ptr_len(unsigned long long num) +{ + int size; + + size = 0; + while (num) + { + num = num / 16; + size++; + } + return (size); +} + +void ft_put_ptr(unsigned long long ptr) +{ + if (ptr >= 16) + { + ft_put_ptr(ptr / 16); + ft_put_ptr(ptr % 16); + } + else + { + if (ptr <= 9) + ft_print_char(ptr + '0'); + else + ft_print_char(ptr - 10 + 'a'); + } +} + +int ft_print_ptr(unsigned long long ptr) +{ + int return_len; + + return_len = 0; + if (ptr == 0) + return_len = write(1, "(nil)", 5); + else + { + return_len += write(1, "0x", 2); + return_len += ft_ptr_len(ptr); + ft_put_ptr(ptr); + } + return (return_len); +} diff --git a/libft/ft_print_ptr_fd.c b/libft/ft_print_ptr_fd.c new file mode 100644 index 0000000..ed686ef --- /dev/null +++ b/libft/ft_print_ptr_fd.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_ptr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:45:41 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:48:57 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf_fd.h" + +int ft_ptr_len(unsigned long long num) +{ + int size; + + size = 0; + while (num) + { + num = num / 16; + size++; + } + return (size); +} + +void ft_put_ptr_fd(unsigned int fd, unsigned long long ptr) +{ + if (ptr >= 16) + { + ft_put_ptr_fd(fd, ptr / 16); + ft_put_ptr_fd(fd, ptr % 16); + } + else + { + if (ptr <= 9) + ft_print_char_fd(fd, ptr + '0'); + else + ft_print_char_fd(fd, ptr - 10 + 'a'); + } +} + +int ft_print_ptr_fd(unsigned int fd, unsigned long long ptr) +{ + int return_len; + + return_len = 0; + if (ptr == 0) + return_len = write(fd, "(nil)", 5); + else + { + return_len += write(fd, "0x", 2); + return_len += ft_ptr_len(ptr); + ft_put_ptr_fd(fd, ptr); + } + return (return_len); +} diff --git a/libft/ft_print_str.c b/libft/ft_print_str.c new file mode 100644 index 0000000..933504d --- /dev/null +++ b/libft/ft_print_str.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_str.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:57:10 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:58:02 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +int ft_print_str(const char *str) +{ + int i; + + i = 0; + if (str == 0) + return (write(1, "(null)", 6)); + while (*str) + { + ft_print_char(*str); + str++; + i++; + } + return (i); +} diff --git a/libft/ft_print_str_fd.c b/libft/ft_print_str_fd.c new file mode 100644 index 0000000..3f2ac05 --- /dev/null +++ b/libft/ft_print_str_fd.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_str.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:57:10 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:58:02 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf_fd.h" + +int ft_print_str_fd(unsigned int fd, const char *str) +{ + int i; + + i = 0; + if (str == 0) + return (write(fd, "(null)", 6)); + while (*str) + { + ft_print_char_fd(fd, *str); + str++; + i++; + } + return (i); +} diff --git a/libft/ft_print_unsign_int.c b/libft/ft_print_unsign_int.c new file mode 100644 index 0000000..3255e26 --- /dev/null +++ b/libft/ft_print_unsign_int.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_unsign_int.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 14:03:41 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 14:06:44 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +int ft_unsign_int_len(unsigned int num) +{ + int size; + + size = 0; + while (num) + { + size++; + num = num / 10; + } + return (size); +} + +char *ft_put_unsign_int(unsigned int num) +{ + char *nbr; + int len; + + len = ft_unsign_int_len(num); + nbr = malloc(sizeof(char) * (len + 1)); + if (!nbr) + return (0); + nbr[len] = '\0'; + while (num != 0) + { + nbr[len - 1] = num % 10 + '0'; + num = num / 10; + len--; + } + return (nbr); +} + +int ft_print_unsign_int(unsigned int num) +{ + int return_len; + char *nbr; + + return_len = 0; + if (num == 0) + return_len += write(1, "0", 1); + else + { + nbr = ft_put_unsign_int(num); + return_len += ft_print_str(nbr); + free(nbr); + } + return (return_len); +} diff --git a/libft/ft_print_unsign_int_fd.c b/libft/ft_print_unsign_int_fd.c new file mode 100644 index 0000000..d6a1a69 --- /dev/null +++ b/libft/ft_print_unsign_int_fd.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_unsign_int.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 14:03:41 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 14:06:44 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf_fd.h" + +int ft_unsign_int_len(unsigned int num) +{ + int size; + + size = 0; + while (num) + { + size++; + num = num / 10; + } + return (size); +} + +char *ft_put_unsign_int(unsigned int num) +{ + char *nbr; + int len; + + len = ft_unsign_int_len(num); + nbr = malloc(sizeof(char) * (len + 1)); + if (!nbr) + return (0); + nbr[len] = '\0'; + while (num != 0) + { + nbr[len - 1] = num % 10 + '0'; + num = num / 10; + len--; + } + return (nbr); +} + +int ft_print_unsign_int_fd(unsigned int fd, unsigned int num) +{ + int return_len; + char *nbr; + + return_len = 0; + if (num == 0) + return_len += write(fd, "0", 1); + else + { + nbr = ft_put_unsign_int(num); + return_len += ft_print_str_fd(fd, nbr); + free(nbr); + } + return (return_len); +} diff --git a/libft/ft_printf.c b/libft/ft_printf.c new file mode 100644 index 0000000..08d3d79 --- /dev/null +++ b/libft/ft_printf.c @@ -0,0 +1,69 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/28 09:27:54 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 13:53:28 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +int ft_format(char placeholder, va_list args) +{ + int print_len; + + print_len = 0; + if (placeholder == 'c') + print_len += ft_print_char(va_arg(args, unsigned int)); + else if (placeholder == 's') + print_len += ft_print_str(va_arg(args, const char *)); + else if (placeholder == 'p') + print_len += ft_print_ptr(va_arg(args, unsigned long long)); + else if (placeholder == 'i' || placeholder == 'd') + print_len += ft_print_int(va_arg(args, int)); + else if (placeholder == 'u') + print_len += ft_print_unsign_int(va_arg(args, unsigned int)); + else if (placeholder == 'x' || placeholder == 'X') + print_len += ft_print_hex(va_arg(args, unsigned int), placeholder); + else if (placeholder == '%') + print_len += ft_print_percent(); + else + { + print_len += ft_print_char('%'); + print_len += ft_print_char(placeholder); + } + return (print_len); +} + +int ft_printf(const char *print, ...) +{ + int return_len; + va_list args; + int i; + + if (!print) + return (-1); + return_len = 0; + va_start(args, print); + i = 0; + while (print[i]) + { + if (print[i] == '%') + { + return_len += ft_format(print[i + 1], args); + i++; + } + else + { + ft_print_char(print[i]); + return_len++; + } + i++; + } + va_end(args); + return (return_len); +} diff --git a/libft/ft_printf.h b/libft/ft_printf.h new file mode 100644 index 0000000..9812d89 --- /dev/null +++ b/libft/ft_printf.h @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:58:33 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 14:02:30 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_PRINTF_H +# define FT_PRINTF_H + +# include +# include +# include +# include +# include + +int ft_print_char(char c); +int ft_hex_len(unsigned int num); +void ft_put_hex(unsigned int num, char placeholder); +int ft_print_hex(unsigned int num, char placeholder); +int ft_int_len(int num); +void ft_put_int(int num); +int ft_print_int(int nbr); +int ft_print_percent(void); +int ft_ptr_len(unsigned long long num); +void ft_put_ptr(unsigned long long ptr); +int ft_print_ptr(unsigned long long ptr); +int ft_print_str(const char *str); +int ft_unsign_int_len(unsigned int num); +char *ft_put_unsign_int(unsigned int num); +int ft_print_unsign_int(unsigned int num); +int ft_format(char placeholder, va_list args); +int ft_printf(const char *print, ...); + +#endif diff --git a/libft/ft_printf_fd.c b/libft/ft_printf_fd.c new file mode 100644 index 0000000..43defc4 --- /dev/null +++ b/libft/ft_printf_fd.c @@ -0,0 +1,96 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dpadenko +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 13:58:33 by mmasarov #+# #+# */ +/* Updated: 2023/10/04 14:02:30 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_PRINTF_FD_H +# define FT_PRINTF_FD_H + +# include +# include +# include +# include +# include + +int ft_print_char_fd(unsigned int fd, char c); +int ft_hex_len(unsigned int num); +void ft_put_hex_fd(unsigned int fd, unsigned int num, char placeholder); +int ft_print_hex_fd(unsigned int fd, unsigned int num, char placeholder); +int ft_int_len(int num); +void ft_put_int_fd(unsigned int fd, int num); +int ft_print_int_fd(unsigned int fd, int nbr); +int ft_print_percent_fd(unsigned int fd); +int ft_ptr_len(unsigned long long num); +void ft_put_ptr_fd(unsigned int fd, unsigned long long ptr); +int ft_print_ptr_fd(unsigned int fd, unsigned long long ptr); +int ft_print_str_fd(unsigned int fd, const char *str); +int ft_unsign_int_len(unsigned int num); +char *ft_put_unsign_int(unsigned int num); +int ft_print_unsign_int_fd(unsigned int fd, unsigned int num); +int ft_format_fd(unsigned int fd, char placeholder, va_list args); +int ft_printf_fd(unsigned int fd, const char *print, ...); + +#endif diff --git a/libft/ft_putchar_fd.c b/libft/ft_putchar_fd.c new file mode 100644 index 0000000..bda8268 --- /dev/null +++ b/libft/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/12 16:08:55 by mmasarov #+# #+# */ +/* Updated: 2023/09/12 16:14:11 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/libft/ft_putendl_fd.c b/libft/ft_putendl_fd.c new file mode 100644 index 0000000..b1f4038 --- /dev/null +++ b/libft/ft_putendl_fd.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/12 16:21:00 by mmasarov #+# #+# */ +/* Updated: 2023/09/12 16:28:14 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putendl_fd(char *s, int fd) +{ + int i; + + i = 0; + while (s[i]) + { + write (fd, &s[i++], 1); + } + write (fd, "\n", 1); +} diff --git a/libft/ft_putnbr_fd.c b/libft/ft_putnbr_fd.c new file mode 100644 index 0000000..3c81624 --- /dev/null +++ b/libft/ft_putnbr_fd.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/12 15:15:37 by mmasarov #+# #+# */ +/* Updated: 2023/09/12 16:08:29 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putnbr_fd(int n, int fd) +{ + if (n == (-2147483648)) + { + ft_putchar_fd('-', fd); + ft_putchar_fd('2', fd); + n = 147483648; + } + if (n < 0) + { + ft_putchar_fd('-', fd); + n = (int)(n * -1); + } + if (n >= 10) + ft_putnbr_fd(n / 10, fd); + ft_putchar_fd((char)(n % 10 + 48), fd); +} diff --git a/libft/ft_putstr_fd.c b/libft/ft_putstr_fd.c new file mode 100644 index 0000000..0ecd469 --- /dev/null +++ b/libft/ft_putstr_fd.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/12 16:15:51 by mmasarov #+# #+# */ +/* Updated: 2023/09/12 16:20:41 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putstr_fd(char *s, int fd) +{ + int i; + + i = 0; + while (s[i]) + { + write(fd, &s[i], 1); + i++; + } +} diff --git a/libft/ft_realloc.c b/libft/ft_realloc.c new file mode 100644 index 0000000..a95be6e --- /dev/null +++ b/libft/ft_realloc.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_realloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dpadenko +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/13 12:40:04 by mmasarov #+# #+# */ +/* Updated: 2023/09/13 15:26:39 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static void ft_free(char **array, int j) +{ + while (--j >= 0) + free(array[j]); + free(array); +} + +static size_t n_words(const char *str, char c) +{ + int i; + int count; + + i = 0; + count = 0; + while (str && str[i]) + { + if (str[i] != c) + { + count++; + while (str[i] != c && str[i]) + i++; + } + else + i++; + } + return (count); +} + +static size_t size_word(const char *s, char c, int i) +{ + size_t size; + + size = 0; + while (s[i] != c && s[i]) + { + size++; + i++; + } + return (size); +} + +char **ft_split(char const *s, char c) +{ + char **array; + size_t i; + size_t j; + size_t size; + + i = 0; + j = -1; + array = malloc(sizeof(char *) * (n_words(s, c) + 1)); + if (!array) + return (NULL); + while (++j < n_words(s, c)) + { + while (s[i] == c) + i++; + size = size_word(s, c, i); + array[j] = ft_substr(s, i, size); + if (!array[j]) + { + ft_free(array, j); + return (NULL); + } + i = i + size; + } + array[j] = 0; + return (array); +} diff --git a/libft/ft_strcat.c b/libft/ft_strcat.c new file mode 100644 index 0000000..cb6cc5c --- /dev/null +++ b/libft/ft_strcat.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/12 14:46:18 by mmasarov #+# #+# */ +/* Updated: 2023/09/12 15:14:12 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_striteri(char *s, void (*f)(unsigned int, char*)) +{ + int i; + + i = 0; + if (!s || !f) + return ; + while (s[i]) + { + f(i, &s[i]); + i++; + } +} diff --git a/libft/ft_strjoin.c b/libft/ft_strjoin.c new file mode 100644 index 0000000..af19030 --- /dev/null +++ b/libft/ft_strjoin.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/11 10:15:44 by mmasarov #+# #+# */ +/* Updated: 2023/09/13 15:52:29 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + char *newstr; + int i; + int x; + + i = 0; + x = 0; + if (!s1) + return (ft_strdup(s2)); + if (!s2) + return (ft_strdup(s1)); + newstr = (char *)malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1)); + if (!newstr) + return (NULL); + while (s1[i]) + newstr[x++] = s1[i++]; + i = 0; + while (s2[i]) + newstr[x++] = s2[i++]; + newstr[x] = '\0'; + return (newstr); +} diff --git a/libft/ft_strlcat.c b/libft/ft_strlcat.c new file mode 100644 index 0000000..b3a7ef9 --- /dev/null +++ b/libft/ft_strlcat.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/06 16:46:24 by mmasarov #+# #+# */ +/* Updated: 2023/09/07 09:52:59 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcat(char *dst, const char *src, size_t dest_size) +{ + size_t dest_len; + size_t src_len; + size_t i; + size_t e; + + e = 0; + i = ft_strlen(dst); + dest_len = ft_strlen(dst); + src_len = ft_strlen(src); + if (dest_size == 0) + return (src_len + dest_size); + while (src[e] != '\0' && i + 1 < dest_size) + { + dst[i] = src[e]; + i++; + e++; + } + dst[i] = '\0'; + if (dest_size < dest_len) + return (src_len + dest_size); + else + return (dest_len + src_len); +} diff --git a/libft/ft_strlcpy.c b/libft/ft_strlcpy.c new file mode 100644 index 0000000..baef551 --- /dev/null +++ b/libft/ft_strlcpy.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/06 15:23:33 by mmasarov #+# #+# */ +/* Updated: 2023/09/07 09:56:31 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcpy(char *dst, const char *src, size_t size) +{ + size_t i; + size_t src_len; + + i = 0; + src_len = 0; + while (src[src_len] != '\0') + { + src_len++; + } + if (size < 1) + return (src_len); + while (src[i] != '\0' && i < size - 1) + { + dst[i] = src[i]; + i++; + } + dst[i] = '\0'; + return (src_len); +} diff --git a/libft/ft_strlen.c b/libft/ft_strlen.c new file mode 100644 index 0000000..6b3890c --- /dev/null +++ b/libft/ft_strlen.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/06 10:49:03 by mmasarov #+# #+# */ +/* Updated: 2023/09/06 11:13:47 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlen(const char *s) +{ + unsigned long len; + + len = 0; + while (s && *s) + { + len++; + s++; + } + return (len); +} diff --git a/libft/ft_strmapi.c b/libft/ft_strmapi.c new file mode 100644 index 0000000..557a0d7 --- /dev/null +++ b/libft/ft_strmapi.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/12 13:06:53 by mmasarov #+# #+# */ +/* Updated: 2023/09/12 14:45:52 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + char *new_str; + int i; + + i = 0; + if (!s) + return (0); + new_str = malloc(sizeof(char) * (ft_strlen(s) + 1)); + if (!new_str) + return (0); + while (s[i]) + { + new_str[i] = f(i, s[i]); + i++; + } + new_str[i] = '\0'; + return (new_str); +} diff --git a/libft/ft_strncat.c b/libft/ft_strncat.c new file mode 100644 index 0000000..7a45a52 --- /dev/null +++ b/libft/ft_strncat.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/07 11:32:06 by mmasarov #+# #+# */ +/* Updated: 2023/09/07 11:56:32 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + size_t i; + + i = 0; + while ((s1[i] || s2[i]) && i < n) + { + if ((unsigned char)s1[i] < (unsigned char)s2[i] + || (unsigned char)s1[i] > (unsigned char)s2[i]) + return ((unsigned char)s1[i] - (unsigned char)s2[i]); + i++; + } + return (0); +} diff --git a/libft/ft_strncpy.c b/libft/ft_strncpy.c new file mode 100644 index 0000000..5eaf409 --- /dev/null +++ b/libft/ft_strncpy.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov n) + len = n; + dup = malloc(len + 1); + if (dup == NULL) + return (NULL); + ft_memcpy(dup, s, len); + dup[len] = '\0'; + return (dup); +} diff --git a/libft/ft_strnstr.c b/libft/ft_strnstr.c new file mode 100644 index 0000000..4adddd9 --- /dev/null +++ b/libft/ft_strnstr.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/07 13:58:01 by mmasarov #+# #+# */ +/* Updated: 2023/09/07 16:14:17 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strnstr(const char *big, const char *little, size_t len) +{ + size_t i; + size_t e; + + if (*little && *big && len == 0) + return (NULL); + if (little == big) + return ((char *)big); + i = 0; + e = 0; + while (big[e]) + { + i = 0; + while (big[e] == little[i] && big[e] && e < len) + { + i++; + e++; + } + if (little[i] == '\0') + return ((char *)&big[e - i]); + e = (e - i) + 1; + } + return (NULL); +} diff --git a/libft/ft_strpbrk.c b/libft/ft_strpbrk.c new file mode 100644 index 0000000..ea5c3f2 --- /dev/null +++ b/libft/ft_strpbrk.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strpbrk.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/07 10:54:00 by mmasarov #+# #+# */ +/* Updated: 2023/09/07 11:31:30 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strrchr(const char *s, int c) +{ + int i; + + i = ft_strlen(s); + while (i >= 0) + { + if (s[i] == (char)c) + return ((char *)s + i); + i--; + } + return (NULL); +} diff --git a/libft/ft_strtok.c b/libft/ft_strtok.c new file mode 100644 index 0000000..c23ecb5 --- /dev/null +++ b/libft/ft_strtok.c @@ -0,0 +1,71 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtok.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov start && ft_char_set(s1[end - 1], set)) + end--; + new_str = malloc(sizeof(char) * (end - start + 1)); + if (!new_str) + return (NULL); + while (start < end) + { + new_str[i] = s1[start]; + start++; + i++; + } + new_str[i] = '\0'; + return (new_str); +} diff --git a/libft/ft_substr.c b/libft/ft_substr.c new file mode 100644 index 0000000..2b54ac2 --- /dev/null +++ b/libft/ft_substr.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/04 14:14:56 by mmasarov #+# #+# */ +/* Updated: 2023/09/11 10:15:23 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static size_t ft_special_cases(char const *s, unsigned int start, size_t len) +{ + size_t lenght; + + lenght = ft_strlen(s); + if (lenght < start) + len = 0; + if ((lenght + start) < len) + len = lenght + start; + if (start == (lenght - 1) && len != 0) + len = 1; + if ((lenght - start) < len) + len = lenght - start; + return (len); +} + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + char *str; + size_t i; + + i = 0; + len = ft_special_cases(s, start, len); + str = malloc(sizeof(char) * (len + 1)); + if (!str) + return (NULL); + while (i < len) + { + str[i] = s[start + i]; + i++; + } + str[i] = '\0'; + return (str); +} diff --git a/libft/ft_tolower.c b/libft/ft_tolower.c new file mode 100644 index 0000000..100685b --- /dev/null +++ b/libft/ft_tolower.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/07 10:17:59 by mmasarov #+# #+# */ +/* Updated: 2023/09/07 10:28:02 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + c = c + 32; + return (c); +} diff --git a/libft/ft_toupper.c b/libft/ft_toupper.c new file mode 100644 index 0000000..aa68f44 --- /dev/null +++ b/libft/ft_toupper.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmasarov +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/07 09:59:37 by mmasarov #+# #+# */ +/* Updated: 2023/09/07 10:17:33 by mmasarov ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + c = c - 32; + return (c); +} diff --git a/libft/get_next_line.c b/libft/get_next_line.c new file mode 100644 index 0000000..e4a50c7 --- /dev/null +++ b/libft/get_next_line.c @@ -0,0 +1,116 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dpadenko + +char *del_buf_return_res(char **buffer, char *res, int len_to_del) +{ + int new_len; + int i; + char *new_buffer; + + i = len_to_del; + new_len = 0; + while ((*buffer)[i++]) + new_len++; + if (new_len == 0) + return (my_free_gnl(buffer), res); + new_buffer = (char *)malloc(new_len + 1); + if (!new_buffer) + return (free(res), my_free_gnl(buffer), NULL); + i = 0; + while ((*buffer)[len_to_del]) + new_buffer[i++] = (*buffer)[len_to_del++]; + new_buffer[i] = '\0'; + my_free_gnl(buffer); + *buffer = new_buffer; + return (res); +} + +char *extract_til_nl_or_end(char **buff) +{ + int i; + int j; + char *res; + + i = 0; + if (!*buff) + return (NULL); + while ((*buff) && (*buff)[i]) + { + if ((*buff)[i++] == '\n') + break ; + } + res = (char *)malloc(i + 1); + if (!res) + return (my_free_gnl(buff), NULL); + j = 0; + while (j < i) + { + res[j] = (*buff)[j]; + j++; + } + res[j] = '\0'; + return (del_buf_return_res(buff, res, i)); +} + +char *read_buff_size(int fd, char **buffer) +{ + int read_bytes; + char *temp; + + temp = (char *)malloc(BUFFER_SIZE + 1); + if (!temp) + return (my_free_gnl(buffer), NULL); + read_bytes = read(fd, temp, BUFFER_SIZE); + if (read_bytes == 0) + return (free(temp), NULL); + if (read_bytes < 0) + return (free(temp), my_free_gnl(buffer), NULL); + temp[read_bytes] = '\0'; + return (temp); +} + +int check_nl(char *str) +{ + int i; + + i = 0; + while (str && str[i]) + { + if (str[i] == '\n') + return (1); + i++; + } + return (0); +} + +char *get_next_line(int fd) +{ + static char *buff; + char *read_bytes; + + if (fd < 0 || BUFFER_SIZE <= 0) + return (NULL); + while (1) + { + if (check_nl(buff)) + return (extract_til_nl_or_end(&buff)); + read_bytes = read_buff_size(fd, &buff); + if (!read_bytes && buff) + return (extract_til_nl_or_end(&buff)); + else if (!read_bytes) + return (NULL); + buff = ft_strjoin_gnl(buff, read_bytes); + } +} diff --git a/libft/get_next_line_utils.c b/libft/get_next_line_utils.c new file mode 100644 index 0000000..7b39d71 --- /dev/null +++ b/libft/get_next_line_utils.c @@ -0,0 +1,66 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dpadenko +# include +# include +# include +# include +# include +# include + +/* part one functions*/ +int ft_atoi(const char *nptr); +void ft_bzero(void *s, size_t n); +void *ft_calloc(size_t nmemb, size_t size); +int ft_isalnum(int c); +int ft_isalpha(int c); +int ft_isascii(int c); +int ft_isdigit(int c); +int ft_isprint(int c); +void *ft_memchr(const void *s, int c, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); +void *ft_memcpy(void *dest, const void *src, size_t n); +void *ft_memmove(void *dest, const void *src, size_t n); +void *ft_memset(void *s, int c, size_t n); +char *ft_strchr(const char *s, int c); +char *ft_strrchr(const char *s, int c); +char *ft_strdup(const char *s); +size_t ft_strlcat(char *dst, const char *src, size_t dest_size); +size_t ft_strlcpy(char *dst, const char *src, size_t size); +size_t ft_strlen(const char *s); +int ft_strncmp(const char *s1, const char *s2, size_t n); +char *ft_strnstr(const char *big, const char *little, size_t len); +char *ft_substr(char const *s, unsigned int start, size_t len); +int ft_tolower(int c); +int ft_toupper(int c); + +/* part two functions*/ +//char *ft_substr(char const *s, unsigned int start, size_t len); +char *ft_strjoin(char const *s1, char const *s2); +char *ft_strtrim(char const *s1, char const *set); +char **ft_split(char const *s, char c); +char *ft_itoa(int n); +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); +void ft_striteri(char *s, void (*f)(unsigned int, char*)); +void ft_putchar_fd(char c, int fd); +void ft_putendl_fd(char *s, int fd); +void ft_putnbr_fd(int n, int fd); +void ft_putstr_fd(char *s, int fd); + +/* Added functions*/ +char *ft_strtok(char *str, const char *delim); +char *ft_strpbrk(char *str, char *delim); +char *ft_strncat(char *dest, const char *src, size_t n); +char *ft_strcat(char *dest, const char *src); +int ft_strcmp(const char *s1, const char *s2); +char *ft_strcpy(char *dest, const char *src); +char *ft_strndup(const char *s, size_t n); +char *ft_strncpy(char *dest, const char *src, size_t n); +void *ft_realloc(void *ptr, size_t old_size, size_t new_size); + +/* Printf added*/ +//int ft_printf(const char *print, ...); +int ft_printf_fd(unsigned int fd, const char *print, ...); +int ft_vprintf_fd(unsigned int fd, const char *print, va_list args); + +/* get_next_line added*/ +# ifndef BUFFER_SIZE +# define BUFFER_SIZE 5 +# endif + +//# include +//# include +//# include + +size_t ft_strlen_gnl(char *str); +void my_free_gnl(char **str); +char *ft_strjoin_gnl(char *read_str, char *buff); +char *del_buf_return_res(char **buffer, char *res, int len_to_del); +char *extract_til_nl_or_end(char **buff); +char *read_buff_size(int fd, char **buffer); +int check_nl(char *str); +char *get_next_line(int fd); +int ft_exact_strcmp(const char *s1, const char *s2); + +#endif From ea25383da616f232d0a3da5c2ee7410184d409f7 Mon Sep 17 00:00:00 2001 From: Dari <121875111+grignetta@users.noreply.github.com> Date: Sun, 31 Aug 2025 10:11:45 +0200 Subject: [PATCH 18/18] Revise README for libft description and cloning steps Updated README to clarify libft as a standard library and modified clone instructions. --- README.md | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 1b8e7d5..75b6560 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ src/ path/ # PATH resolution free/ # cleanup helpers printf_fd/ # libprintf_fd.a (ft_printf_fd & helpers) -libft/ # submodule (libft.a) +libft/ # standard library with additional functions for this project (libft.a) tools/suppress/ # sanitizer suppression files (readline, etc.) ``` @@ -54,8 +54,8 @@ tools/suppress/ # sanitizer suppression files (readline, etc.) ## Build & Run ```sh -# clone with submodules -git clone --recursive https://github.com/michaela811/minishell.git minishell +# clone +git clone https://github.com/michaela811/minishell.git minishell cd minishell # build @@ -69,8 +69,6 @@ make - `make` – build `minishell`, `libft.a`, and `libprintf_fd.a`. - `make clean|fclean|re` – standard hygiene. -> If you forgot submodules: `git submodule update --init --recursive`. - --- ## The Controls You Must Pass (Signals & TTY behavior) @@ -127,7 +125,7 @@ Getting **Ctrl keys** right is a common failure point. The parent shell and its - **Unquoted delimiter (expands):** ``` - echo start; cat <