From bf81e18e76e50b304ae7d7ca4bd21e49dc1d1139 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 27 Apr 2025 15:50:50 +0200 Subject: [PATCH] feat(09): start the parsing of the input --- cpp09/ex01/Makefile | 10 +--------- cpp09/ex01/RPN.hpp | 26 ++++++++++++++++++++++++++ cpp09/ex01/main.cpp | 29 +++++++++++++++++++++++++++-- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/cpp09/ex01/Makefile b/cpp09/ex01/Makefile index 692071d..32e6fe5 100644 --- a/cpp09/ex01/Makefile +++ b/cpp09/ex01/Makefile @@ -6,7 +6,7 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2025/04/27 13:00:00 by rparodi ### ########.fr # +# Updated: 2025/04/27 13:01:07 by rparodi ### ########.fr # # # # **************************************************************************** # @@ -56,14 +56,6 @@ END = \033[0m # All (make all) all: header $(NAME) footer -get_db: - @rm -rf ./cpp_09.tgz ./cpp_09 ./data.csv &> /dev/null - @wget https://cdn.intra.42.fr/document/document/33121/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: @printf '$(GREY) Removing $(END)$(RED)Objects$(END)\n' diff --git a/cpp09/ex01/RPN.hpp b/cpp09/ex01/RPN.hpp index e69de29..97ab1fb 100644 --- a/cpp09/ex01/RPN.hpp +++ b/cpp09/ex01/RPN.hpp @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* RPN.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/27 13:03:08 by rparodi #+# #+# */ +/* Updated: 2025/04/27 15:39:50 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#define CLR_RESET "\033[0m" + +#define CLR_BLACK "\033[0;30m" +#define CLR_RED "\033[0;31m" +#define CLR_GREEN "\033[0;32m" +#define CLR_YELLOW "\033[0;33m" +#define CLR_BLUE "\033[0;34m" +#define CLR_MAGENTA "\033[0;35m" +#define CLR_CYAN "\033[0;36m" +#define CLR_WHITE "\033[0;37m" +#define CLR_GOLD "\033[38;5;220m" +#define CLR_GREY "\033[38;5;240m" diff --git a/cpp09/ex01/main.cpp b/cpp09/ex01/main.cpp index a685fe4..9c8b82e 100644 --- a/cpp09/ex01/main.cpp +++ b/cpp09/ex01/main.cpp @@ -6,10 +6,35 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/27 12:58:08 by rparodi #+# #+# */ -/* Updated: 2025/04/27 13:00:01 by rparodi ### ########.fr */ +/* Updated: 2025/04/27 15:50:20 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ -int main(int argc, char **argv) { +#include +#include +#include "RPN.hpp" +/** + * @brief check if the input have only numbers and operators + * + * @param str the input of the user + * @return true if the input is valid, false otherwise + */ +bool check_input(std::string str) { + std::string allowed = "0123456789 +-*/"; + for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) { + if (allowed.find(*it) == std::string::npos) + return false; + } + return true; +} + +int main(int argc, char **argv) { + if (argc != 2) { + std::cerr << CLR_RED << "Usage:\t" << argv[0] << " " << CLR_RESET << std::endl; + } + std::string input = argv[1]; + if (!check_input(input)) { + std::cerr << CLR_RED << "Error:\tYour input can only have digits, spaces and the operators '+' '-' '*' '/'" << CLR_RESET << std::endl; + } }