From 2ba166d1f8deb93cbd10f0e397c31c531de63189 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 14 Aug 2022 12:53:21 +0900 Subject: Fixed UiGuiVersion and argument parsing Signed-off-by: Michele Calgaro --- src/CMakeLists.txt | 1 + src/UiGuiVersion.cpp | 28 +++--- src/UiGuiVersion.h | 4 +- src/main.cpp | 267 ++++++++++++++++++++++++++------------------------- 4 files changed, 154 insertions(+), 146 deletions(-) mode change 100644 => 100755 src/main.cpp (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8be71d9..5e3f6f5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,6 +27,7 @@ set( target universal-indent-gui-tqt ) set( ${target}_SRCS main.cpp + UiGuiVersion.cpp ) tde_add_executable( ${target} AUTOMOC diff --git a/src/UiGuiVersion.cpp b/src/UiGuiVersion.cpp index 4246644..c996ff5 100644 --- a/src/UiGuiVersion.cpp +++ b/src/UiGuiVersion.cpp @@ -19,9 +19,9 @@ #include "UiGuiVersion.h" -#include -#include -#include +#include +#include +#include namespace UiGuiVersion { @@ -32,19 +32,17 @@ namespace UiGuiVersion TQString getBuildDate() { TQStringList monthNames; - TQString buildDateString = ""; - - monthNames << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << - "Oct" << "Nov" << "Dez"; - TQStringList buildDateStringList = TQString(__DATE__).simplified().split(' '); // __DATE__ - // returns eg - // "Feb 4 2009" + monthNames << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" + << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; + TQString buildDateString = ""; + // __DATE__ returns a string like "Feb 4 2009" + TQStringList buildDateStringList = TQStringList::split(' ', TQString(__DATE__).simplifyWhiteSpace()); if (buildDateStringList.count() == 3) { TQDate buildDate(buildDateStringList.last().toInt(), - monthNames.indexOf(buildDateStringList.first()) + 1, - buildDateStringList.at(1).toInt()); + monthNames.findIndex(buildDateStringList.first()) + 1, + buildDateStringList.at(1)->toInt()); buildDateString = buildDate.toString("d. MMMM yyyy"); } @@ -58,13 +56,13 @@ namespace UiGuiVersion TQString getBuildRevision() { TQString buildRevision = ""; - TQStringList buildRevisionStringList = TQString(PROGRAM_REVISION).simplified().split(' '); + TQStringList buildRevisionStringList = TQStringList::split(' ', TQString(PROGRAM_REVISION).simplifyWhiteSpace()); if (buildRevisionStringList.count() == 3) { - buildRevision = buildRevisionStringList.at(1); // PROGRAM_REVISION is eg "$Revision: 907 $" + buildRevision = *buildRevisionStringList.at(1); // PROGRAM_REVISION is eg "$Revision: 907 $" } return buildRevision; } -} // namespace UiGuiVersion +} diff --git a/src/UiGuiVersion.h b/src/UiGuiVersion.h index 44a69f9..e01f512 100644 --- a/src/UiGuiVersion.h +++ b/src/UiGuiVersion.h @@ -23,7 +23,7 @@ class TQString; // Define the version number here. Update this as the last file before a release. -#define PROGRAM_VERSION 1.2 .0 +#define PROGRAM_VERSION 1.2.0 #define PROGRAM_VERSION_STRING "1.2.0" #define RESOURCE_VERSION 1, 2, 0, 0 #define RESOURCE_VERSION_STRING "1,2,0,0\0" @@ -35,4 +35,4 @@ namespace UiGuiVersion TQString getBuildRevision(); } -#endif // UIGUIVERSION_H +#endif diff --git a/src/main.cpp b/src/main.cpp old mode 100644 new mode 100755 index 60e9a7a..4e64f4b --- a/src/main.cpp +++ b/src/main.cpp @@ -23,20 +23,23 @@ // -- #include "debugging/TSLogger.h" // -- #include "UiGuiIniFileParser.h" // -- #include "UiGuiSettings.h" -// -- #include "UiGuiVersion.h" // -- #include "UiGuiSystemInfo.h" // -- #include "IndentHandler.h" // -- #include "SettingsPaths.h" // -- -// -- #include -// -- #include +// -- #include +// -- #include // -- #include // -- #include -// -- #include // -- #include -// -- #include +#include "UiGuiVersion.h" + +#include + +#include +#include // -- using namespace tschweitzer::debugging; @@ -47,134 +50,140 @@ No parameters starts without server and full gui. A string without any parameter prefix will be loaded as file on start. -p --plugin : Run as plugin. Server will be started with a simplified gui. - -s --server : Run as server only without gui. + -s --server : Run as server only, without gui. If -p and -s are set, -p will be used. -v --verbose needs a following parameter defining the verbose level as a number from 0 to 3. */ int main(int argc, char *argv[]) { + TQString file2OpenOnStart = ""; + int verboseLevel = 1; + bool startAsPlugin = false; + bool startAsServer = false; + bool tclapExitExceptionThrown = false; + int returnValue = 0; + return 0; - // -- TQString file2OpenOnStart = ""; - // -- int verboseLevel = 1; - // -- bool startAsPlugin = false; - // -- bool startAsServer = false; - // -- bool tclapExitExceptionThrown = false; - // -- int returnValue = 0; - // -- - // -- // Wrap everything in a try block. Do this every time, - // -- // because exceptions will be thrown for problems. - // -- try { - // -- // Define the command line object. - // -- TCLAP::CmdLine cmd("If -p and -s are set, -p will be used.\nGiving no parameters starts - // full gui without server.", ' ', "UiGUI version " PROGRAM_VERSION_STRING " " PROGRAM_REVISION); - // -- cmd.setExceptionHandling(false); - // -- - // -- // Define a value argument and add it to the command line. - // -- TCLAP::UnlabeledValueArg filenameArg("file", "Opens the by - // filename defined file on start" , false, "", "filename"); - // -- cmd.add( filenameArg ); - // -- - // -- // Define a switch and add it to the command line. - // -- TCLAP::SwitchArg pluginSwitch("p", "plugin", "Run as plugin. Server will be started with - // a simplified gui", false); - // -- cmd.add( pluginSwitch ); - // -- - // -- // Define a switch and add it to the command line. - // -- TCLAP::SwitchArg serverSwitch("s", "server", "Run as server only without gui", false); - // -- cmd.add( serverSwitch ); - // -- - // -- // Define a value argument and add it to the command line. - // -- TCLAP::ValueArg verboselevelArg("v", "verbose", "Sets how many info is written to - // the log. 0 means with debug info, 3 means critical messages only" , false, 1, "int"); - // -- cmd.add( verboselevelArg ); - // -- - // -- // Parse the args. - // -- cmd.parse( argc, argv ); - // -- - // -- // Get the value parsed by each arg. - // -- file2OpenOnStart = filenameArg.getValue().c_str(); - // -- startAsPlugin = pluginSwitch.getValue(); - // -- startAsServer = serverSwitch.getValue(); - // -- verboseLevel = verboselevelArg.getValue(); - // -- } - // -- catch (TCLAP::ArgException &e) { // catch arg exceptions - // -- std::cerr << std::endl << "error: " << e.error() << ". " << e.argId() << std::endl; - // -- returnValue = 1; - // -- } - // -- catch (TCLAP::ExitException &e) { // catch exit exceptions - // -- tclapExitExceptionThrown = true; - // -- returnValue = e.getExitStatus(); - // -- } - // -- catch (...) { // catch any exceptions - // -- std::cerr << std::endl << "There was an error! Maybe faulty command line arguments set. - // See --help." << std::endl; - // -- returnValue = 1; - // -- } - // -- - // -- if ( returnValue != 0 || tclapExitExceptionThrown ) { - // -- return returnValue; - // -- } - // -- - // -- TQApplication app(argc, argv); - // -- UiGuiIndentServer server; - // -- MainWindow *mainWindow = NULL; - // -- IndentHandler *indentHandler = NULL; - // -- - // -- // Init and install the logger function. - // -- // Setting UTF-8 as default 8-Bit encoding to ensure that tqDebug does no false string - // conversion. - // -- TQTextCodec::setCodecForCStrings( TQTextCodec::codecForName("UTF-8") ); - // -- TQTextCodec::setCodecForLocale( TQTextCodec::codecForName("UTF-8") ); - // -- // Force creation of an TSLogger instance here, to avoid recursion with SettingsPaths - // init function. - // -- #ifdef _DEBUG - // -- TSLogger::getInstance(0); - // -- #else - // -- TSLogger::getInstance(verboseLevel); - // -- #endif - // -- qInstallMsgHandler( TSLogger::messageHandler ); - // -- TSLogger::messageHandler( TSLoggerInfoMsg, TQString("Starting UiGUI Version %1 - // %2").arg(PROGRAM_VERSION_STRING).arg(PROGRAM_REVISION).toAscii() ); - // -- TSLogger::messageHandler( TSLoggerInfoMsg, TQString("Running on - // %1").arg(UiGuiSystemInfo::getOperatingSystem()).toAscii() ); - // -- - // -- // Set default values for all by UniversalIndentGUI used settings objects. - // -- TQCoreApplication::setOrganizationName("UniversalIndentGUI"); - // -- TQCoreApplication::setOrganizationDomain("universalindent.sf.net"); - // -- TQCoreApplication::setApplicationName("UniversalIndentGUI"); - // -- - // -- // Start normal with full gui and without server. - // -- if ( !startAsPlugin && !startAsServer ) { - // -- mainWindow = new MainWindow(file2OpenOnStart); - // -- mainWindow->show(); - // -- } - // -- // Start as plugin with server. - // -- else if ( startAsPlugin ) { - // -- server.startServer(); - // -- indentHandler = new IndentHandler(0); - // -- indentHandler->show(); - // -- } - // -- // Start as server only without any gui. - // -- else if ( startAsServer ) { - // -- server.startServer(); - // -- } - // -- - // -- try { - // -- returnValue = app.exec(); - // -- } - // -- catch (std::exception &ex) { - // -- qCritical() << __LINE__ << " " << __FUNCTION__ << ": Something went terribly wrong:" - // << ex.what(); - // -- } - // -- - // -- if ( startAsPlugin || startAsServer ) - // -- server.stopServer(); - // -- - // -- delete indentHandler; - // -- delete mainWindow; - // -- - // -- SettingsPaths::cleanAndRemoveTempDir(); - // -- TSLogger::deleteInstance(); - // -- - // -- return returnValue; + // Wrap everything in a try block. Do this every time, + // because exceptions will be thrown for problems. + try + { + // Define the command line object. + TCLAP::CmdLine cmd("If -p and -s are set, -p will be used.\n" + "Giving no parameters starts full gui without server.", ' ', + "UiGUI version " PROGRAM_VERSION_STRING " " PROGRAM_REVISION); + cmd.setExceptionHandling(false); + + // Define a value argument and add it to the command line. + TCLAP::UnlabeledValueArg filenameArg("file", + "Opens the by filename defined file on start" , false, "", "filename"); + cmd.add(filenameArg); + + // Define a switch and add it to the command line. + TCLAP::SwitchArg pluginSwitch("p", "plugin", + "Run as plugin. Server will be started with a simplified gui", false); + cmd.add(pluginSwitch); + + // Define a switch and add it to the command line. + TCLAP::SwitchArg serverSwitch("s", "server", + "Run as server only without gui", false); + cmd.add(serverSwitch); + + // Define a value argument and add it to the command line. + TCLAP::ValueArg verboselevelArg("v", "verbose", + "Sets how many info is written to the log. 0 means with debug info, " + "3 means critical messages only" , false, 1, "int"); + cmd.add(verboselevelArg); + + // Parse the args. + cmd.parse(argc, argv); + + // Get the value parsed by each arg. + file2OpenOnStart = filenameArg.getValue().c_str(); + startAsPlugin = pluginSwitch.getValue(); + startAsServer = serverSwitch.getValue(); + verboseLevel = verboselevelArg.getValue(); + } + catch (TCLAP::ArgException &e) + { + // catch arg exceptions + std::cerr << std::endl << "error: " << e.error() << ". " << e.argId() << std::endl; + returnValue = 1; + } + catch (TCLAP::ExitException &e) + { + // catch exit exceptions + tclapExitExceptionThrown = true; + returnValue = e.getExitStatus(); + } + catch (...) + { + // catch any exceptions + std::cerr << std::endl << "There was an error! Maybe faulty " + "command line arguments set. See --help." << std::endl; + returnValue = 1; + } + + if (returnValue != 0 || tclapExitExceptionThrown) + { + return returnValue; + } + +// -- TQApplication app(argc, argv); +// -- UiGuiIndentServer server; +// -- MainWindow *mainWindow = NULL; +// -- IndentHandler *indentHandler = NULL; +// -- +// -- // Init and install the logger function. +// -- // Setting UTF-8 as default 8-Bit encoding to ensure that tqDebug does no false string conversion. +// -- TQTextCodec::setCodecForCStrings(TQTextCodec::codecForName("UTF-8")); +// -- TQTextCodec::setCodecForLocale(TQTextCodec::codecForName("UTF-8")); +// -- // Force creation of an TSLogger instance here, to avoid recursion with SettingsPaths init function. +// -- #ifdef _DEBUG +// -- TSLogger::getInstance(0); +// -- #else +// -- TSLogger::getInstance(verboseLevel); +// -- #endif +// -- qInstallMsgHandler(TSLogger::messageHandler); +// -- TSLogger::messageHandler(TSLoggerInfoMsg, TQString("Starting UiGUI Version %1 %2").arg(PROGRAM_VERSION_STRING).arg(PROGRAM_REVISION).toAscii()); +// -- TSLogger::messageHandler(TSLoggerInfoMsg, TQString("Running on %1").arg(UiGuiSystemInfo::getOperatingSystem()).toAscii()); +// -- +// -- // Set default values for all by UniversalIndentGUI used settings objects. +// -- TQCoreApplication::setOrganizationName("UniversalIndentGUI"); +// -- TQCoreApplication::setOrganizationDomain("universalindent.sf.net"); +// -- TQCoreApplication::setApplicationName("UniversalIndentGUI"); +// -- +// -- // Start normal with full gui and without server. +// -- if (!startAsPlugin && !startAsServer) { +// -- mainWindow = new MainWindow(file2OpenOnStart); +// -- mainWindow->show(); +// -- } +// -- // Start as plugin with server. +// -- else if (startAsPlugin) { +// -- server.startServer(); +// -- indentHandler = new IndentHandler(0); +// -- indentHandler->show(); +// -- } +// -- // Start as server only without any gui. +// -- else if (startAsServer) { +// -- server.startServer(); +// -- } +// -- +// -- try { +// -- returnValue = app.exec(); +// -- } +// -- catch (std::exception &ex) { +// -- qCritical() << __LINE__ << " " << __FUNCTION__ << ": Something went terribly wrong:" << ex.what(); +// -- } +// -- +// -- if (startAsPlugin || startAsServer) +// -- server.stopServer(); +// -- +// -- delete indentHandler; +// -- delete mainWindow; +// -- +// -- SettingsPaths::cleanAndRemoveTempDir(); +// -- TSLogger::deleteInstance(); + + return returnValue; } -- cgit v1.2.1