From f335c262b2f96c1c55fecc48d80f3892ca3a5fb1 Mon Sep 17 00:00:00 2001 From: Martchus Date: Wed, 24 Jun 2015 00:44:16 +0200 Subject: [PATCH] added commandline utilities --- application/commandlineutils.cpp | 32 ++++++++++++++++++++++++++++++++ application/commandlineutils.h | 19 +++++++++++++++++++ c++utilities.pro | 7 +++++-- general.pri | 12 +++++++++++- 4 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 application/commandlineutils.cpp create mode 100644 application/commandlineutils.h diff --git a/application/commandlineutils.cpp b/application/commandlineutils.cpp new file mode 100644 index 0000000..c883778 --- /dev/null +++ b/application/commandlineutils.cpp @@ -0,0 +1,32 @@ +#include "commandlineutils.h" + +#include +#include + +using namespace std; + +namespace ApplicationUtilities { + +bool confirmPrompt(const char *message, Response defaultResponse) +{ + cout << message; + cout << ' ' << '['; + cout << (defaultResponse == Response::Yes ? 'Y' : 'y'); + cout << '/' << (defaultResponse == Response::No ? 'N' : 'n'); + cout << ']' << ' '; + cout.flush(); + for(string line; ;) { + getline(cin, line); + if(line == "y" || line == "Y" || (defaultResponse == Response::Yes && line.empty())) { + return true; + } else if(line == "n" || line == "N" || (defaultResponse == Response::No && line.empty())) { + return false; + } else { + cout << "Please enter [y] or [n]: "; + cout.flush(); + } + } +} + +} // namespace ApplicationUtilities + diff --git a/application/commandlineutils.h b/application/commandlineutils.h new file mode 100644 index 0000000..ec23009 --- /dev/null +++ b/application/commandlineutils.h @@ -0,0 +1,19 @@ +#ifndef APPLICATIONUTILITIES_COMMANDLINEUTILS_H +#define APPLICATIONUTILITIES_COMMANDLINEUTILS_H + +#include "global.h" + +namespace ApplicationUtilities { + +enum class Response +{ + None, + Yes, + No +}; + +bool LIB_EXPORT confirmPrompt(const char *message, Response defaultResponse = Response::None); + +} // namespace ApplicationUtilities + +#endif // APPLICATIONUTILITIES_COMMANDLINEUTILS_H diff --git a/c++utilities.pro b/c++utilities.pro index 6d27c9c..212b7fb 100644 --- a/c++utilities.pro +++ b/c++utilities.pro @@ -1,4 +1,5 @@ projectname = c++utilities +VERSION = 1.0.6 # include ../../common.pri when building as part of a subdirs project; otherwise include general.pri !include(../../common.pri) { @@ -27,7 +28,8 @@ SOURCES += \ application/fakeqtconfigarguments.cpp \ io/ansiescapecodes.cpp \ misc/random.cpp \ - io/bitreader.cpp + io/bitreader.cpp \ + application/commandlineutils.cpp HEADERS += \ application/global.h \ @@ -51,7 +53,8 @@ HEADERS += \ io/ansiescapecodes.h \ misc/memory.h \ misc/random.h \ - io/bitreader.h + io/bitreader.h \ + application/commandlineutils.h OTHER_FILES += \ README.md \ diff --git a/general.pri b/general.pri index 9156999..9f790b4 100644 --- a/general.pri +++ b/general.pri @@ -12,7 +12,17 @@ unix { QMAKE_LFLAGS += "-Wl,--rpath=./" } # prefix -targetprefix = . +targetprefix = $$(TARGET_PREFIX) +equals(targetprefix, "") { + win32 { + targetprefix = ../../.. + } else { + targetprefix = ../.. + } +} +message("Using target prefix \"$${targetprefix}\".") +# print install root +message("Using install root \"$$(INSTALL_ROOT)\".") # target CONFIG(debug, debug|release) { TARGET = $$targetprefix/$${projectname}d