From 11643631f54388227e88a439e97e653171b1e6b8 Mon Sep 17 00:00:00 2001 From: krcroft Date: Wed, 1 Apr 2020 08:18:30 -0700 Subject: [PATCH] Apply clang-format rules --- src/dos/program_autotype.cpp | 141 ++++++++++++++++++++--------------- src/dos/program_autotype.h | 25 ++++--- 2 files changed, 92 insertions(+), 74 deletions(-) diff --git a/src/dos/program_autotype.cpp b/src/dos/program_autotype.cpp index 3b4b501e..c02e1775 100644 --- a/src/dos/program_autotype.cpp +++ b/src/dos/program_autotype.cpp @@ -12,51 +12,63 @@ #include "programs.h" #include "program_autotype.h" -void AUTOTYPE::PrintUsage() { - WriteOut_NoParsing( - "\033[32;1mAUTOTYPE\033[0m [-list] [-w WAIT] [-p PACE] button_1 [button_2 [...]] \n\n" - "Where:\n" - " -list: prints all available button names.\n" - " -w WAIT: seconds before typing begins. Two second default; max of 30.\n" - " -p PACE: seconds between each keystroke. Half-second default; max of 10.\n" - "\n" - " The sequence is comprised of one or more space-separated buttons.\n" - " Autotyping begins after WAIT seconds, and each button is entered \n" - " every PACE seconds. The , character inserts an extra PACE delay.\n" - "\n" - "Some examples:\n" - " \033[32;1mAUTOTYPE\033[0m -w 1 -p 0.3 up enter , right enter\n" - " \033[32;1mAUTOTYPE\033[0m -p 0.2 1 3 , , enter\n" - " \033[32;1mAUTOTYPE\033[0m -w 1.3 esc esc esc enter p l a y e r enter\n"); +void AUTOTYPE::PrintUsage() +{ + constexpr const char *msg = + "\033[32;1mAUTOTYPE\033[0m [-list] [-w WAIT] [-p PACE] " + "button_1 [button_2 [...]] \n\n" + "Where:\n" + " -list: prints all available button names.\n" + " -w WAIT: seconds before typing begins. Two second default; " + "max of 30.\n" + " -p PACE: seconds between each keystroke. Half-second " + "default; max of 10.\n" + "\n" + " The sequence is comprised of one or more space-separated " + "buttons.\n" + " Autotyping begins after WAIT seconds, and each button is " + "entered \n" + " every PACE seconds. The , character inserts an extra PACE " + "delay.\n" + "\n" + "Some examples:\n" + " \033[32;1mAUTOTYPE\033[0m -w 1 -p 0.3 up enter , right " + "enter\n" + " \033[32;1mAUTOTYPE\033[0m -p 0.2 f1 kp_8 , , enter\n" + " \033[32;1mAUTOTYPE\033[0m -w 1.3 esc enter , p l a y e r " + "enter\n"; + WriteOut_NoParsing(msg); } // Prints the key-names for the mapper's currently-bound events. -void AUTOTYPE::PrintKeys() { - const std::vector names = MAPPER_GetEventNames("key_"); +void AUTOTYPE::PrintKeys() +{ + const std::vector names = MAPPER_GetEventNames("key_"); - // Keep track of the longest key name - size_t max_length = 0; - for (const auto &name : names) - max_length = (std::max)(name.length(), max_length); + // Keep track of the longest key name + size_t max_length = 0; + for (const auto &name : names) + max_length = (std::max)(name.length(), max_length); - // Sanity check to avoid dividing by 0 - if (!max_length) { - WriteOut_NoParsing("AUTOTYPE: The mapper has no key bindings\n"); - return; - } + // Sanity check to avoid dividing by 0 + if (!max_length) { + WriteOut_NoParsing( + "AUTOTYPE: The mapper has no key bindings\n"); + return; + } - // Setup our rows and columns - const size_t wrap_width = 72; // confortable columns not pushed to the edge - const size_t columns = wrap_width / max_length; - const size_t rows = ceil_udivide(names.size(), columns); + // Setup our rows and columns + const size_t wrap_width = 72; // confortable columns not pushed to the edge + const size_t columns = wrap_width / max_length; + const size_t rows = ceil_udivide(names.size(), columns); - // Build the string output by rows and columns - auto name = names.begin(); - for (size_t row = 0; row < rows; ++row) { - for (size_t i = row; i < names.size(); i += rows) - WriteOut(" %-*s", max_length, name[i].c_str()); - WriteOut_NoParsing("\n"); - } + // Build the string output by rows and columns + auto name = names.begin(); + for (size_t row = 0; row < rows; ++row) { + for (size_t i = row; i < names.size(); i += rows) + WriteOut(" %-*s", max_length, name[i].c_str()); + WriteOut_NoParsing("\n"); + } } /* @@ -65,49 +77,53 @@ void AUTOTYPE::PrintKeys() { * - flag is the command-line flag, ie: -d or -delay * - default is the default value if the flag doesn't exist * - value will be populated with the default or provided value - * + * * Returns: * true if 'value' is set to the default or read from the arg. * false if the argument was used but could not be parsed. */ -bool AUTOTYPE::ReadDoubleArg(const std::string &name, - const char *flag, - const double &def_value, - const double &min_value, - const double &max_value, - double &value) { +bool AUTOTYPE::ReadDoubleArg(const std::string &name, + const char *flag, + const double &def_value, + const double &min_value, + const double &max_value, + double &value) +{ bool result = false; std::string str_value; + // Is the user trying to set this flag? if (cmd->FindString(flag, str_value, true)) { - // Can the user's value be parsed? const double user_value = to_finite(str_value); if (std::isfinite(user_value)) { result = true; + // Clamp the user's value if needed value = clamp(user_value, min_value, max_value); - // Inform them if we had to clamp their value - if (std::fabs(user_value - value) > std::numeric_limits::epsilon()) - WriteOut("AUTOTYPE: bounding %s value of %.2f to %.2f\n", + // Inform them if we had to clamp their value + if (std::fabs(user_value - value) > + std::numeric_limits::epsilon()) + WriteOut("AUTOTYPE: bounding %s value of %.2f " + "to %.2f\n", name.c_str(), user_value, value); - // Otherwise inform them we couldn't parse their value - } else { - WriteOut("AUTOTYPE: %s value '%s' is not a valid floating point number\n", + + } else { // Otherwise we couldn't parse their value + WriteOut("AUTOTYPE: %s value '%s' is not a valid " + "floating point number\n", name.c_str(), str_value.c_str()); } - // Otherwise the user hasn't set this flag, so use the default - } else { + } else { // Otherwise thay haven't passed this flag value = def_value; result = true; } return result; } -void AUTOTYPE::Run() { - - //Hack To allow long commandlines +void AUTOTYPE::Run() +{ + // Hack To allow long commandlines ChangeToLongCmd(); // Usage @@ -121,13 +137,13 @@ void AUTOTYPE::Run() { PrintKeys(); return; } - + // Get the wait delay in milliseconds double wait_s; constexpr double def_wait_s = 2.0; constexpr double min_wait_s = 0.0; constexpr double max_wait_s = 30.0; - if (!ReadDoubleArg("WAIT", "-w", def_wait_s, min_wait_s,max_wait_s, wait_s)) + if (!ReadDoubleArg("WAIT", "-w", def_wait_s, min_wait_s, max_wait_s, wait_s)) return; const auto wait_ms = static_cast(wait_s * 1000); @@ -150,6 +166,7 @@ void AUTOTYPE::Run() { MAPPER_AutoType(sequence, wait_ms, pace_ms); } -void AUTOTYPE_ProgramStart(Program * *make) { - *make = new AUTOTYPE; -} \ No newline at end of file +void AUTOTYPE_ProgramStart(Program **make) +{ + *make = new AUTOTYPE; +} diff --git a/src/dos/program_autotype.h b/src/dos/program_autotype.h index 600edc87..d9102475 100644 --- a/src/dos/program_autotype.h +++ b/src/dos/program_autotype.h @@ -1,17 +1,18 @@ #include "programs.h" class AUTOTYPE : public Program { - public: - void Run(); - private: - void PrintUsage(); - void PrintKeys(); - bool ReadDoubleArg(const std::string &name, - const char *flag, - const double &def_value, - const double &min_value, - const double &max_value, - double &value); +public: + void Run(); + +private: + void PrintUsage(); + void PrintKeys(); + bool ReadDoubleArg(const std::string &name, + const char *flag, + const double &def_value, + const double &min_value, + const double &max_value, + double &value); }; -void AUTOTYPE_ProgramStart(Program * *make); \ No newline at end of file +void AUTOTYPE_ProgramStart(Program **make); \ No newline at end of file