From 08b6535d4a715f74185e4585a6190d04625499ff Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 11 Apr 2025 11:48:28 +0200 Subject: [PATCH] feat(09): starting the parsing of the file --- cpp09/ex00/BitcoinExchange.hpp | 4 +++- cpp09/ex00/Makefile | 17 +++++++++------- cpp09/ex00/main.cpp | 36 +++++++++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/cpp09/ex00/BitcoinExchange.hpp b/cpp09/ex00/BitcoinExchange.hpp index cbc0071..98c6af8 100644 --- a/cpp09/ex00/BitcoinExchange.hpp +++ b/cpp09/ex00/BitcoinExchange.hpp @@ -6,13 +6,15 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/08 12:18:18 by rparodi #+# #+# */ -/* Updated: 2025/04/08 12:19:08 by rparodi ### ########.fr */ +/* Updated: 2025/04/10 16:05:21 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once #include +#include +#include #define CLR_RESET "\033[0m" diff --git a/cpp09/ex00/Makefile b/cpp09/ex00/Makefile index d445499..b93481a 100644 --- a/cpp09/ex00/Makefile +++ b/cpp09/ex00/Makefile @@ -6,7 +6,7 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2025/04/08 12:15:25 by rparodi ### ########.fr # +# Updated: 2025/04/11 11:23:29 by rparodi ### ########.fr # # # # **************************************************************************** # @@ -49,11 +49,13 @@ END = \033[0m # All (make all) all: header $(NAME) footer -# Bonus (make bonus) -bonus: header $(OBJ) footer - @mkdir -p $(OBJDIRNAME) - @printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n' - @$(CXX) $(CXXFLAGS) -o $(NAME) $(OBJ) +get_db: + @rm -rf ./cpp_09.tgz ./cpp_09 ./data.csv &> /dev/null + @wget https://cdn.intra.42.fr/document/document/32672/cpp_09.tgz &> /dev/null + @tar -xvf cpp_09.tgz &> /dev/null + @cp ./cpp_09/data.csv . &> /dev/null + @rm -rf ./cpp_09.tgz ./cpp_09 &> /dev/null + @printf '$(GREY)Downloaded $(END)$(GREEN)data.csv$(END)\n' # Clean (make clean) clean: @@ -64,6 +66,7 @@ clean: # Clean (make fclean) fclean: clean @printf '$(GREY) Removing $(END)$(RED)Program$(END)\n' + @$(RM) ./data.csv @$(RM) $(NAME) @echo "" @@ -123,5 +126,5 @@ clangd: > .clangd # Phony -.PHONY: all bonus clean fclean re clangd +.PHONY: all clean fclean re get_db clangd -include ${OBJ:.o=.d} diff --git a/cpp09/ex00/main.cpp b/cpp09/ex00/main.cpp index a5a9026..94d55d3 100644 --- a/cpp09/ex00/main.cpp +++ b/cpp09/ex00/main.cpp @@ -6,16 +6,46 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/08 12:15:32 by rparodi #+# #+# */ -/* Updated: 2025/04/08 12:21:16 by rparodi ### ########.fr */ +/* Updated: 2025/04/11 11:47:18 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "BitcoinExchange.hpp" +#include +#include +#include + +std::mapparse_file(std::string name) { + std::map to_ret; + std::string tmp; + std::ifstream file(name); + + while (std::getline(file, tmp)) { + ; + } + return to_ret; +} int main(int argc, char *argv[]) { if (argc != 2) { std::cerr << CLR_RED << "Usage: " << argv[0] << " " << CLR_RESET << std::endl; - } else { - + exit(1); } + if (access(argv[1], F_OK)) { + std::cerr << CLR_RED << "The file given in arguments have to exist" << CLR_RESET << std::endl; + exit(1); + } + if (access(argv[1], R_OK)) { + std::cerr << CLR_RED << "The file given in arguments have to be readable by the owner" << CLR_RESET << std::endl; + exit( 1); + } + if (access("data.csv", F_OK)) { + std::cerr << CLR_RED << "The file `data.csv` have to exist (to take it from the insta make get_db)" << CLR_RESET << std::endl; + exit(1); + } + if (access("data.csv", R_OK)) { + std::cerr << CLR_RED << "The program have to read on the file `data.csv`" << CLR_RESET << std::endl; + exit( 1); + } + std::map user_db = parse_file(argv[1]); }