From 0b683266bd9ece8a261cd09bfe46154c96350d04 Mon Sep 17 00:00:00 2001 From: klugier Date: Wed, 25 Jul 2018 22:47:31 +0000 Subject: [PATCH] Ide: Command line parameter now can be handle in separate class (CommandLineHandler). This is the only refactoring commit that doesn't bring new content. I am trying to limit length of the main method of TheIDE. git-svn-id: svn://ultimatepp.org/upp/trunk@12102 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/ide/CommandLineHandler.cpp | 68 +++++++++++++++++++++++++++++++ uppsrc/ide/CommandLineHandler.h | 30 ++++++++++++++ uppsrc/ide/ide.upp | 2 + uppsrc/ide/main.cpp | 33 ++++----------- 4 files changed, 109 insertions(+), 24 deletions(-) create mode 100644 uppsrc/ide/CommandLineHandler.cpp create mode 100644 uppsrc/ide/CommandLineHandler.h diff --git a/uppsrc/ide/CommandLineHandler.cpp b/uppsrc/ide/CommandLineHandler.cpp new file mode 100644 index 000000000..8a647136e --- /dev/null +++ b/uppsrc/ide/CommandLineHandler.cpp @@ -0,0 +1,68 @@ +#include "CommandLineHandler.h" + +#include + +using namespace Upp; + +CommandLineHandler::CommandLineHandler(const Vector& args) + : args(clone(args)) +{} + +bool CommandLineHandler::Handle() +{ + if(HandleManipulators()) + return true; + + if(HandleHelp()) + return true; + + return false; +} + +bool CommandLineHandler::HandleManipulators() +{ + if(HandleScale()) + return true; + + return false; +} + +bool CommandLineHandler::HandleScale() +{ + if(args.GetCount() < 2 || args[0].Compare("--scale") != 0) + return false; + + int scale = StrInt(args[1]); + if(IsNull(scale)) { + Cout() << "Scale should be numeric value."; + return true; + } + + Font::SetStdFont(StdFont().Height(GetStdFontCy() * minmax(scale, 50, 400) / 100)); + + args.Remove(0, 2); + + return false; +} + +bool CommandLineHandler::HandleHelp() const +{ + if(args.IsEmpty() || findarg(args[0], "?", "--help", "-h", "-?", "/?") < 0) + return false; + + Cout() << "Usage: theide assembly package\n" + " theide assembly package build_method [-[a][b][e][r][s][S][v][1][2][m][d][M][l][x][X][Hn]] [+FLAG[,FLAG]...] [out]\n" + " theide -f [file..]\n" + " theide [file..] // autodetection mode\n\n"; + + Cout() << "Common options:\n" + " -h or --help - displays this site.\n\n"; + + Cout() << "Advanced options:\n" + " --scale $percent - scale interface by \"percent\" represented by parameter x.\n\n"; + + Cout() << "Internal options (Should not be called by the user):\n" + " --debug_break_process $pid - breaks debug process represented by \"pid\" (MS Windows only).\n"; + + return true; +} diff --git a/uppsrc/ide/CommandLineHandler.h b/uppsrc/ide/CommandLineHandler.h new file mode 100644 index 000000000..e0d9b0411 --- /dev/null +++ b/uppsrc/ide/CommandLineHandler.h @@ -0,0 +1,30 @@ +#ifndef _ide_Command_Line_Handler_h_ +#define _ide_Command_Line_Handler_h_ + +#include + +namespace Upp { + +// TODO: All TheIDE command line arguments should be handle in this class. +class CommandLineHandler { +public: + CommandLineHandler(const Vector& args); + + bool Handle(); + +public: + Vector GetArgs() { return clone(args); } + +private: + bool HandleManipulators(); + bool HandleScale(); + + bool HandleHelp() const; + +private: + Vector args; +}; + +} + +#endif diff --git a/uppsrc/ide/ide.upp b/uppsrc/ide/ide.upp index 49a17b5d1..52da94098 100644 --- a/uppsrc/ide/ide.upp +++ b/uppsrc/ide/ide.upp @@ -72,6 +72,8 @@ file idebar.cpp, idewin.cpp, main.cpp, + CommandLineHandler.h, + CommandLineHandler.cpp, About.h, About.cpp, Macro.cpp, diff --git a/uppsrc/ide/main.cpp b/uppsrc/ide/main.cpp index f179553d1..a1e88f073 100644 --- a/uppsrc/ide/main.cpp +++ b/uppsrc/ide/main.cpp @@ -1,4 +1,5 @@ #include "ide.h" +#include "CommandLineHandler.h" #define FUNCTION_NAME UPP_FUNCTION_NAME << "(): " @@ -116,12 +117,10 @@ void AppMain___() SetLanguage(LNG_ENGLISH); SetDefaultCharset(CHARSET_UTF8); - Vector arg = clone(CommandLine()); - if(arg.GetCount() && arg[0].StartsWith("--scale=")) { - int scale = atoi(Filter(arg[0], CharFilterDigit)); - Font::SetStdFont(StdFont().Height(GetStdFontCy() * minmax(scale, 50, 400) / 100)); - arg.Remove(0); - } + CommandLineHandler cmd_handler(CommandLine()); + if (cmd_handler.Handle()) + return; + auto arg = cmd_handler.GetArgs(); bool first_install = false; @@ -161,12 +160,6 @@ void AppMain___() ResetBlitz(); for(int i = 0; i < arg.GetCount(); i++) { -/* if(arg[i] == "-uninstall") { - Uninstall(); - return; - } - if(!firstinstall && arg[i] == "-install" && !Install()) return; -*/ #ifdef PLATFORM_WIN32 if(arg[i] == "!") { String cmdline; @@ -226,19 +219,11 @@ void AppMain___() Ide ide; ide.Maximize(); bool clset = false; - if(arg.GetCount() && findarg(arg[0], "?", "--help", "-?", "/?") >= 0) { - Cout() << "Usage: theide assembly package\n" - " theide assembly package build_method [-[a][b][e][r][s][S][v][1][2][m][d][M][l][x][X][Hn]] [+FLAG[,FLAG]...] [out]\n" - " theide -f [file..]\n" - " theide [file..] // autodetection mode\n" - ; - return; - } if(arg.GetCount() >= 2 && IsAlpha(arg[0][0]) && IsAlpha(arg[1][0]) && IsAssembly(arg[0]) && arg[0] != "-f") { bool build = arg.GetCount() >= 3 && IsAlpha(arg[2][0]); #ifdef PLATFORM_WIN32 if(build) { - HMODULE hDLL = LoadLibrary ("kernel32"); + HMODULE hDLL = LoadLibrary("kernel32"); bool attach = false; if(hDLL) { typedef BOOL (WINAPI *AttachConsoleType)(DWORD dwProcessId); @@ -484,16 +469,16 @@ void AppMain___() #ifndef _DEBUG } catch(const CParser::Error& e) { - Exclamation("Parser error " + e); + ErrorOK("Parser error " + e); LOG("!!!!! Parser error " + e); } catch(const Exc& e) { - Exclamation("Exception " + e); + ErrorOK("Exception " + e); LOG("!!!!! Exception " << e); } #ifdef PLATFORM_POSIX catch(...) { - Exclamation("Unknown exception !"); + ErrorOK("Unknown exception !"); LOG("!!!!! Unknown exception"); } #endif