From 4d7083c0f9e6fa7d9846c3018db0281c35159a5f Mon Sep 17 00:00:00 2001 From: Simon CROS Date: Mon, 20 Dec 2021 22:36:08 +0100 Subject: [PATCH] Add english language --- .vscode/settings.json | 61 ++++++++++++++++++++++++++++++++++++++++- Makefile | 9 ++++++ includes/complexity.hpp | 3 ++ src/Makefile | 8 ++++++ src/lang/en_GB.cpp | 52 +++++++++++++++++++++++++++++++++++ src/lang/fr_FR.cpp | 52 +++++++++++++++++++++++++++++++++++ src/main.cpp | 4 ++- src/print.cpp | 45 +----------------------------- 8 files changed, 188 insertions(+), 46 deletions(-) create mode 100644 src/Makefile create mode 100644 src/lang/en_GB.cpp create mode 100644 src/lang/fr_FR.cpp diff --git a/.vscode/settings.json b/.vscode/settings.json index 105f3da..cb43112 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,65 @@ "algorithm": "cpp", "random": "cpp", "numeric": "cpp", - "iostream": "cpp" + "iostream": "cpp", + "__bit_reference": "cpp", + "__bits": "cpp", + "__config": "cpp", + "__debug": "cpp", + "__errc": "cpp", + "__functional_base": "cpp", + "__hash_table": "cpp", + "__locale": "cpp", + "__mutex_base": "cpp", + "__node_handle": "cpp", + "__nullptr": "cpp", + "__split_buffer": "cpp", + "__string": "cpp", + "__threading_support": "cpp", + "__tuple": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "complex": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "exception": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "locale": "cpp", + "memory": "cpp", + "mutex": "cpp", + "new": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "utility": "cpp", + "vector": "cpp" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 12d4fea..fe79dc8 100644 --- a/Makefile +++ b/Makefile @@ -9,12 +9,15 @@ override CPPFLAGS := -std=c++17 -Wall -Wextra # Sources +LANG := fr_FR + override SRCS := \ main.cpp \ exec.cpp \ args.cpp \ print.cpp \ utils.cpp \ + lang/$(LANG).cpp \ override HEADERS := \ complexity.hpp \ @@ -29,6 +32,12 @@ override OBJDIRS := $(sort $(dir $(OBJS))) all: $(NAME) +fr: + $(MAKE) LANG="fr_FR" re + +en: + $(MAKE) LANG="en_GB" re + obj/%.o: src/%.cpp $(HEADERS) | $(CPPC) $(CPPFLAGS) -c $< -o $@ -Iincludes diff --git a/includes/complexity.hpp b/includes/complexity.hpp index 7fd238d..769fb18 100644 --- a/includes/complexity.hpp +++ b/includes/complexity.hpp @@ -30,6 +30,9 @@ const string &assertExecutable(const string &path); struct program_opts getOptions(int &argc, char **&argv); struct program_params getParameters(int argc, char **argv); string exec(char **argv, optional input = nullopt); + +// Print +void print_start(program_params params); void print(program_params params, int done, int total, int best, int worst, int successful, int ok); #endif diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..a6cde16 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,8 @@ +X=hello + +foo: + @echo $(X) + +bar: X=world +bar: + @echo $(X) diff --git a/src/lang/en_GB.cpp b/src/lang/en_GB.cpp new file mode 100644 index 0000000..d5062a4 --- /dev/null +++ b/src/lang/en_GB.cpp @@ -0,0 +1,52 @@ +#include "complexity.hpp" + +#include + +using namespace std; + +const string getHelp() { + string help; + + help += "\033[1mNAME\033[0m\n"; + help += " \033[1mcomplexity\033[0m -- starting benchmark for push_swap\n"; + help += "\n"; + help += "\033[1mSYNOPSIS\033[0m\n"; + help += " \033[1m./complexity\033[0m [\033[1m-hs\033[0m] [\033[1m-f\033[0m \033[4mfile\033[0m] \033[4mnumbers\033[0m \033[4miterations\033[0m [\033[4mgoal\033[0m] [\033[4mchecker\033[0m]\n"; + help += "\n"; + help += "\033[1mDESCRIPTION\033[0m\n"; + help += " push_swap executable will be default searched from current and parent directory.\n"; + help += " \n"; + help += " Following options are available :\n"; + help += " \n"; + help += " \033[1m-v\033[0m, \033[1m--version\033[0m\n"; + help += " Show version of tester.\n"; + help += " \n"; + help += " \033[1m-h\033[0m, \033[1m--help\033[0m\n"; + help += " Show this help.\n"; + help += " \n"; + help += " \033[1m-s\033[0m, \033[1m--sorted\033[0m\n"; + help += " Only pass sorted numbers to program.\n"; + help += " \n"; + help += " \033[1m-f\033[0m \033[4mpush_swap\033[0m, \033[1m--file\033[0m=\033[4mpush_swap\033[0m\n"; + help += " Use \033[4mpush_swap\033[0m for push_swap executable.\n"; + return help; +} + +void print_start(program_params params) { + cout << "\033[97mStarting the test : \033[95m" << params.numbers << "\033[97m elements, \033[95m" << params.iterations << "\033[97m iterations\033[0m" << endl; +} + +void print(program_params params, int done, int total, int best, int worst, int successful, int ok) { + cout << "Worst = \033[31m" << (worst) << "\033[0m instructions" << endl; + cout << "Median = \033[33m" << (total / done) << "\033[0m instructions" << endl; + cout << "Best = \033[36m" << (best) << "\033[0m instructions" << endl; + if (params.objective.has_value()) + cout << "Objective = \033[94m" << (successful * 100 / done) << "\033[0m % under \033[94m" << (params.objective.value()) << "\033[0m (\033[91m" << (done - successful) << "\033[0m above) " << endl; + else + cout << "Objective = enter a number as the third argument" << endl; + if (params.checker.has_value()) + cout << "Precision = \033[97m" << (ok * 100 / done) << "\033[0m % OK (\033[91m" << (done - ok) << "\033[0m KO) " << endl; + else + cout << "Precision = enter a tester as the fourth argument" << endl; + cout << "\033[32m" << (done * 100 / params.iterations) << "\033[0m % effective" << endl; +} diff --git a/src/lang/fr_FR.cpp b/src/lang/fr_FR.cpp new file mode 100644 index 0000000..91e02b0 --- /dev/null +++ b/src/lang/fr_FR.cpp @@ -0,0 +1,52 @@ +#include "complexity.hpp" + +#include + +using namespace std; + +const string getHelp() { + string help; + + help += "\033[1mNAME\033[0m\n"; + help += " \033[1mcomplexity\033[0m -- lance un benchmark de votre push_swap\n"; + help += "\n"; + help += "\033[1mSYNOPSIS\033[0m\n"; + help += " \033[1m./complexity\033[0m [\033[1m-hs\033[0m] [\033[1m-f\033[0m \033[4mfile\033[0m] \033[4mnumbers\033[0m \033[4miterations\033[0m [\033[4mgoal\033[0m] [\033[4mchecker\033[0m]\n"; + help += "\n"; + help += "\033[1mDESCRIPTION\033[0m\n"; + help += " L'exécutable push_swap est cherché par défaut dans le répertoire courant et parent.\n"; + help += " \n"; + help += " Les options suivantes sont disponibles :\n"; + help += " \n"; + help += " \033[1m-v\033[0m, \033[1m--version\033[0m\n"; + help += " Affiche la version du testeur.\n"; + help += " \n"; + help += " \033[1m-h\033[0m, \033[1m--help\033[0m\n"; + help += " Affiche l'aide.\n"; + help += " \n"; + help += " \033[1m-s\033[0m, \033[1m--sorted\033[0m\n"; + help += " Envoie uniquement des nombres triés au programme.\n"; + help += " \n"; + help += " \033[1m-f\033[0m \033[4mpush_swap\033[0m, \033[1m--file\033[0m=\033[4mpush_swap\033[0m\n"; + help += " Utilise \033[4mpush_swap\033[0m en tant qu'exécutable push_swap.\n"; + return help; +} + +void print_start(program_params params) { + cout << "\033[97mDémarrage du test : \033[95m" << params.numbers << "\033[97m éléments, \033[95m" << params.iterations << "\033[97m itérations\033[0m" << endl; +} + +void print(program_params params, int done, int total, int best, int worst, int successful, int ok) { + cout << "Pire = \033[31m" << (worst) << "\033[0m instructions" << endl; + cout << "Moyenne = \033[33m" << (total / done) << "\033[0m instructions" << endl; + cout << "Meilleur = \033[36m" << (best) << "\033[0m instructions" << endl; + if (params.objective.has_value()) + cout << "Objectif = \033[94m" << (successful * 100 / done) << "\033[0m % sous \033[94m" << (params.objective.value()) << "\033[0m (\033[91m" << (done - successful) << "\033[0m au dessus) " << endl; + else + cout << "Objectif = entrez un nombre en troisième argument" << endl; + if (params.checker.has_value()) + cout << "Précision = \033[97m" << (ok * 100 / done) << "\033[0m % OK (\033[91m" << (done - ok) << "\033[0m KO) " << endl; + else + cout << "Précision = entrez un testeur en quatrième argument" << endl; + cout << "\033[32m" << (done * 100 / params.iterations) << "\033[0m % effectué" << endl; +} diff --git a/src/main.cpp b/src/main.cpp index e72798f..90c25b6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,8 @@ #include #include +#include + using namespace std; int main(int argc, char **argv) { @@ -56,7 +58,7 @@ int main(int argc, char **argv) { int ok = 0; hideCursor(); - cout << "\033[97mDémarrage du test : \033[95m" << params.numbers << "\033[97m éléments, \033[95m" << params.iterations << "\033[97m itérations\033[0m" << endl; + print_start(params); while (done < params.iterations) { vector nums(params.numbers); vector args; diff --git a/src/print.cpp b/src/print.cpp index fa1273f..d947e66 100644 --- a/src/print.cpp +++ b/src/print.cpp @@ -13,52 +13,9 @@ void showCursor() { } const string getVersion() { - return "Complexity 1.1.0"; + return "Complexity 1.2.0"; } const string getUsage() { return "usage: ./complexity [-vhs] [-f push_swap] numbers iterations [goal] [checker]"; } - -const string getHelp() { - string help; - - help += "\033[1mNAME\033[0m\n"; - help += " \033[1mcomplexity\033[0m -- lance un benchmark de votre push_swap\n"; - help += "\n"; - help += "\033[1mSYNOPSIS\033[0m\n"; - help += " \033[1m./complexity\033[0m [\033[1m-hs\033[0m] [\033[1m-f\033[0m \033[4mfile\033[0m] \033[4mnumbers\033[0m \033[4miterations\033[0m [\033[4mgoal\033[0m] [\033[4mchecker\033[0m]\n"; - help += "\n"; - help += "\033[1mDESCRIPTION\033[0m\n"; - help += " L'exécutable push_swap est cherché par défaut dans le répertoire courant et parent.\n"; - help += " \n"; - help += " Les options suivantes sont disponibles :\n"; - help += " \n"; - help += " \033[1m-v\033[0m, \033[1m--version\033[0m\n"; - help += " Affiche la version du testeur.\n"; - help += " \n"; - help += " \033[1m-h\033[0m, \033[1m--help\033[0m\n"; - help += " Affiche l'aide.\n"; - help += " \n"; - help += " \033[1m-s\033[0m, \033[1m--sorted\033[0m\n"; - help += " Envoie uniquement des nombres triés au programme.\n"; - help += " \n"; - help += " \033[1m-f\033[0m \033[4mpush_swap\033[0m, \033[1m--file\033[0m=\033[4mpush_swap\033[0m\n"; - help += " Utilise \033[4mpush_swap\033[0m en tant qu'exécutable push_swap.\n"; - return help; -} - -void print(program_params params, int done, int total, int best, int worst, int successful, int ok) { - cout << "Pire = \033[31m" << (worst) << "\033[0m instructions" << endl; - cout << "Moyenne = \033[33m" << (total / done) << "\033[0m instructions" << endl; - cout << "Meilleur = \033[36m" << (best) << "\033[0m instructions" << endl; - if (params.objective.has_value()) - cout << "Objectif = \033[94m" << (successful * 100 / done) << "\033[0m % sous \033[94m" << (params.objective.value()) << "\033[0m (\033[91m" << (done - successful) << "\033[0m au dessus) " << endl; - else - cout << "Objectif = entrez un nombre en troisième argument" << endl; - if (params.checker.has_value()) - cout << "Précision = \033[97m" << (ok * 100 / done) << "\033[0m % OK (\033[91m" << (done - ok) << "\033[0m KO) " << endl; - else - cout << "Précision = entrez un testeur en quatrième argument" << endl; - cout << "\033[32m" << (done * 100 / params.iterations) << "\033[0m % effectué" << endl; -}