From a1189d3c3b099c774ad4411d39be62aa75e1cc19 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 30 Oct 2016 00:37:28 +0200 Subject: [PATCH] Allow specifying custom exit() function --- CMakeLists.txt | 4 ++-- application/argumentparser.cpp | 8 +++++++- application/argumentparser.h | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ce0b23..e23b73f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,8 +111,8 @@ set(META_APP_AUTHOR "Martchus") set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") set(META_APP_DESCRIPTION "Common C++ classes and routines used by my applications such as argument parser, IO and conversion utilities") set(META_VERSION_MAJOR 4) -set(META_VERSION_MINOR 2) -set(META_VERSION_PATCH 1) +set(META_VERSION_MINOR 3) +set(META_VERSION_PATCH 0) # find required 3rd party libraries include(3rdParty) diff --git a/application/argumentparser.cpp b/application/argumentparser.cpp index 2e4e17e..ca05999 100644 --- a/application/argumentparser.cpp +++ b/application/argumentparser.cpp @@ -33,6 +33,12 @@ const char *applicationVersion = nullptr; /// \brief Specifies the URL to the application website (used by ArgumentParser::printHelp()). const char *applicationUrl = nullptr; +/*! + * \brief Specifies a function quit the application. + * \remarks Currently only used after printing Bash completion. Default is std::exit(). + */ +void(*exitFunction)(int) = &exit; + /// \cond inline bool notEmpty(const char *str) @@ -429,7 +435,7 @@ void ArgumentParser::readArgs(int argc, const char * const *argv) if(completionMode) { printBashCompletion(argc, argv, currentWordIndex, lastDetectedArgument); - exit(0); // prevent the applicaton to continue with the regular execution + exitFunction(0); // prevent the applicaton to continue with the regular execution } } else { // no arguments specified -> flag default argument as present if one is assigned diff --git a/application/argumentparser.h b/application/argumentparser.h index 3285abf..404e481 100644 --- a/application/argumentparser.h +++ b/application/argumentparser.h @@ -30,6 +30,8 @@ CPP_UTILITIES_EXPORT extern const char *applicationUrl; ::ApplicationUtilities::applicationVersion = APP_VERSION; \ ::ApplicationUtilities::applicationUrl = APP_URL +CPP_UTILITIES_EXPORT extern void(*exitFunction)(int); + class Argument; class ArgumentParser;