diff options
author | biao716.wang <biao716.wang@samsung.com> | 2020-03-19 01:04:30 +0900 |
---|---|---|
committer | biao716.wang <biao716.wang@samsung.com> | 2020-03-19 01:04:30 +0900 |
commit | 1d6613f4446f69f63beddf2d97c201154fb35e33 (patch) | |
tree | f32eae75900a0df14ab8fa1e2bd436af159ef91d /Source/CursesDialog | |
parent | aabcd8e66e3268a232efe2e416635d5b6bf84ad5 (diff) | |
download | cmake-upstream/3.16.4.tar.gz cmake-upstream/3.16.4.tar.bz2 cmake-upstream/3.16.4.zip |
Imported Upstream version 3.16.4upstream/3.16.4
Change-Id: Ic5262ea6c0872b353ea2dc35fe1e944063ae8409
Signed-off-by: biao716.wang <biao716.wang@samsung.com>
Diffstat (limited to 'Source/CursesDialog')
28 files changed, 455 insertions, 489 deletions
diff --git a/Source/CursesDialog/CMakeLists.txt b/Source/CursesDialog/CMakeLists.txt index c5ac1f1a6..700971751 100644 --- a/Source/CursesDialog/CMakeLists.txt +++ b/Source/CursesDialog/CMakeLists.txt @@ -1,32 +1,28 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -set( CURSES_SRCS - CursesDialog/cmCursesOptionsWidget - CursesDialog/cmCursesBoolWidget - CursesDialog/cmCursesCacheEntryComposite - CursesDialog/cmCursesDummyWidget - CursesDialog/cmCursesFilePathWidget - CursesDialog/cmCursesForm - CursesDialog/cmCursesLabelWidget - CursesDialog/cmCursesLongMessageForm - CursesDialog/cmCursesMainForm - CursesDialog/cmCursesPathWidget - CursesDialog/cmCursesStringWidget - CursesDialog/cmCursesWidget - CursesDialog/ccmake - ) - -if( NOT CMAKE_USE_SYSTEM_FORM ) - include_directories(${CMake_SOURCE_DIR}/Source/CursesDialog/form - ${CMake_BINARY_DIR}/Source/CursesDialog/form) -endif() -include_directories(${CURSES_INCLUDE_PATH}) - - -add_executable(ccmake ${CURSES_SRCS} ) +add_executable(ccmake + ccmake.cxx + cmCursesBoolWidget.cxx + cmCursesCacheEntryComposite.cxx + cmCursesDummyWidget.cxx + cmCursesFilePathWidget.cxx + cmCursesForm.cxx + cmCursesLabelWidget.cxx + cmCursesLongMessageForm.cxx + cmCursesMainForm.cxx + cmCursesOptionsWidget.cxx + cmCursesPathWidget.cxx + cmCursesStringWidget.cxx + cmCursesWidget.cxx + ) +target_include_directories(ccmake PRIVATE ${CURSES_INCLUDE_PATH}) target_link_libraries(ccmake CMakeLib) if(CMAKE_USE_SYSTEM_FORM) + find_path(CURSES_FORM_INCLUDE_DIR NAMES form.h HINTS ${CURSES_INCLUDE_PATH} ${CURSES_INCLUDE_PATH}/ncurses) + if(CURSES_FORM_INCLUDE_DIR) + target_include_directories(ccmake PRIVATE ${CURSES_FORM_INCLUDE_DIR}) + endif() target_link_libraries(ccmake ${CURSES_FORM_LIBRARY} ${CURSES_LIBRARY} diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx index 28a0e95b9..9e9dfbd19 100644 --- a/Source/CursesDialog/ccmake.cxx +++ b/Source/CursesDialog/ccmake.cxx @@ -1,47 +1,50 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ -#include "cmConfigure.h" + +#include <csignal> +#include <cstring> +#include <iostream> +#include <string> +#include <vector> + +#include "cmsys/Encoding.hxx" #include "cmCursesForm.h" #include "cmCursesMainForm.h" #include "cmCursesStandardIncludes.h" #include "cmDocumentation.h" -#include "cmDocumentationEntry.h" +#include "cmDocumentationEntry.h" // IWYU pragma: keep +#include "cmState.h" #include "cmSystemTools.h" #include "cmake.h" -#include "cmsys/Encoding.hxx" -#include <iostream> -#include <signal.h> -#include <string.h> -#include <string> -#include <vector> - static const char* cmDocumentationName[][2] = { - { CM_NULLPTR, " ccmake - Curses Interface for CMake." }, - { CM_NULLPTR, CM_NULLPTR } + { nullptr, " ccmake - Curses Interface for CMake." }, + { nullptr, nullptr } }; static const char* cmDocumentationUsage[][2] = { - { CM_NULLPTR, " ccmake <path-to-source>\n" - " ccmake <path-to-existing-build>" }, - { CM_NULLPTR, + { nullptr, + " ccmake <path-to-source>\n" + " ccmake <path-to-existing-build>" }, + { nullptr, "Specify a source directory to (re-)generate a build system for " "it in the current working directory. Specify an existing build " "directory to re-generate its build system." }, - { CM_NULLPTR, CM_NULLPTR } + { nullptr, nullptr } }; static const char* cmDocumentationUsageNote[][2] = { - { CM_NULLPTR, "Run 'ccmake --help' for more information." }, - { CM_NULLPTR, CM_NULLPTR } + { nullptr, "Run 'ccmake --help' for more information." }, + { nullptr, nullptr } }; -static const char* cmDocumentationOptions[] - [2] = { CMAKE_STANDARD_OPTIONS_TABLE, - { CM_NULLPTR, CM_NULLPTR } }; +static const char* cmDocumentationOptions[][2] = { + CMAKE_STANDARD_OPTIONS_TABLE, + { nullptr, nullptr } +}; -cmCursesForm* cmCursesForm::CurrentForm = CM_NULLPTR; +cmCursesForm* cmCursesForm::CurrentForm = nullptr; extern "C" { @@ -54,7 +57,8 @@ void onsig(int /*unused*/) cbreak(); /* nl- or cr not needed */ keypad(stdscr, true); /* Use key symbols as KEY_DOWN */ refresh(); - int x, y; + int x; + int y; getmaxyx(stdscr, y, x); cmCursesForm::CurrentForm->Render(1, 1, x, y); cmCursesForm::CurrentForm->UpdateStatusBar(); @@ -63,37 +67,31 @@ void onsig(int /*unused*/) } } -void CMakeMessageHandler(const char* message, const char* title, - bool& /*unused*/, void* clientData) -{ - cmCursesForm* self = static_cast<cmCursesForm*>(clientData); - self->AddError(message, title); -} - int main(int argc, char const* const* argv) { + cmSystemTools::EnsureStdPipes(); cmsys::Encoding::CommandLineArguments encoding_args = cmsys::Encoding::CommandLineArguments::Main(argc, argv); argc = encoding_args.argc(); argv = encoding_args.argv(); + cmSystemTools::InitializeLibUV(); cmSystemTools::FindCMakeResources(argv[0]); cmDocumentation doc; doc.addCMakeStandardDocSections(); if (doc.CheckOptions(argc, argv)) { - cmake hcm(cmake::RoleInternal); + cmake hcm(cmake::RoleInternal, cmState::Unknown); hcm.SetHomeDirectory(""); hcm.SetHomeOutputDirectory(""); hcm.AddCMakePaths(); - std::vector<cmDocumentationEntry> generators; - hcm.GetGeneratorDocumentation(generators); + auto generators = hcm.GetGeneratorsDocumentation(); doc.SetName("ccmake"); doc.SetSection("Name", cmDocumentationName); doc.SetSection("Usage", cmDocumentationUsage); if (argc == 1) { doc.AppendSection("Usage", cmDocumentationUsageNote); } - doc.SetSection("Generators", generators); + doc.AppendSection("Generators", generators); doc.PrependSection("Options", cmDocumentationOptions); return doc.PrintRequestedDocumentation(std::cout) ? 0 : 1; } @@ -106,7 +104,7 @@ int main(int argc, char const* const* argv) if (strcmp(argv[j], "-debug") == 0) { debug = true; } else { - args.push_back(argv[j]); + args.emplace_back(argv[j]); } } @@ -131,7 +129,8 @@ int main(int argc, char const* const* argv) signal(SIGWINCH, onsig); - int x, y; + int x; + int y; getmaxyx(stdscr, y, x); if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) { endwin(); @@ -154,7 +153,10 @@ int main(int argc, char const* const* argv) return 1; } - cmSystemTools::SetMessageCallback(CMakeMessageHandler, myform); + cmSystemTools::SetMessageCallback( + [myform](const std::string& message, const char* title) { + myform->AddError(message, title); + }); cmCursesForm::CurrentForm = myform; @@ -169,7 +171,7 @@ int main(int argc, char const* const* argv) touchwin(stdscr); endwin(); delete cmCursesForm::CurrentForm; - cmCursesForm::CurrentForm = CM_NULLPTR; + cmCursesForm::CurrentForm = nullptr; std::cout << std::endl << std::endl; diff --git a/Source/CursesDialog/cmCursesBoolWidget.cxx b/Source/CursesDialog/cmCursesBoolWidget.cxx index 80a5b5b9c..97b081128 100644 --- a/Source/CursesDialog/cmCursesBoolWidget.cxx +++ b/Source/CursesDialog/cmCursesBoolWidget.cxx @@ -2,11 +2,11 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCursesBoolWidget.h" +#include <string> + #include "cmCursesWidget.h" #include "cmStateTypes.h" -#include <string> - cmCursesBoolWidget::cmCursesBoolWidget(int width, int height, int left, int top) : cmCursesWidget(width, height, left, top) diff --git a/Source/CursesDialog/cmCursesBoolWidget.h b/Source/CursesDialog/cmCursesBoolWidget.h index 90bcc2209..8c9625635 100644 --- a/Source/CursesDialog/cmCursesBoolWidget.h +++ b/Source/CursesDialog/cmCursesBoolWidget.h @@ -3,7 +3,7 @@ #ifndef cmCursesBoolWidget_h #define cmCursesBoolWidget_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCursesStandardIncludes.h" #include "cmCursesWidget.h" @@ -12,16 +12,17 @@ class cmCursesMainForm; class cmCursesBoolWidget : public cmCursesWidget { - CM_DISABLE_COPY(cmCursesBoolWidget) - public: cmCursesBoolWidget(int width, int height, int left, int top); + cmCursesBoolWidget(cmCursesBoolWidget const&) = delete; + cmCursesBoolWidget& operator=(cmCursesBoolWidget const&) = delete; + // Description: // Handle user input. Called by the container of this widget // when this widget has focus. Returns true if the input was // handled. - bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE; + bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) override; // Description: // Set/Get the value (on/off). diff --git a/Source/CursesDialog/cmCursesCacheEntryComposite.cxx b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx index d071c9178..4d3131b07 100644 --- a/Source/CursesDialog/cmCursesCacheEntryComposite.cxx +++ b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx @@ -2,6 +2,12 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCursesCacheEntryComposite.h" +#include <cassert> +#include <utility> +#include <vector> + +#include <cm/memory> + #include "cmCursesBoolWidget.h" #include "cmCursesFilePathWidget.h" #include "cmCursesLabelWidget.h" @@ -11,11 +17,8 @@ #include "cmCursesWidget.h" #include "cmState.h" #include "cmStateTypes.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" -#include "cmake.h" - -#include <assert.h> -#include <vector> cmCursesCacheEntryComposite::cmCursesCacheEntryComposite( const std::string& key, int labelwidth, int entrywidth) @@ -23,68 +26,70 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite( , LabelWidth(labelwidth) , EntryWidth(entrywidth) { - this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key); - this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " "); - this->Entry = CM_NULLPTR; - this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1); + this->Label = + cm::make_unique<cmCursesLabelWidget>(this->LabelWidth, 1, 1, 1, key); + this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, " "); + this->Entry = + cm::make_unique<cmCursesStringWidget>(this->EntryWidth, 1, 1, 1); } cmCursesCacheEntryComposite::cmCursesCacheEntryComposite( - const std::string& key, cmake* cm, bool isNew, int labelwidth, + const std::string& key, cmState* state, bool isNew, int labelwidth, int entrywidth) : Key(key) , LabelWidth(labelwidth) , EntryWidth(entrywidth) { - this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key); + this->Label = + cm::make_unique<cmCursesLabelWidget>(this->LabelWidth, 1, 1, 1, key); if (isNew) { - this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, "*"); + this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, "*"); } else { - this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " "); + this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, " "); } - this->Entry = CM_NULLPTR; - const char* value = cm->GetState()->GetCacheEntryValue(key); + const char* value = state->GetCacheEntryValue(key); assert(value); - switch (cm->GetState()->GetCacheEntryType(key)) { - case cmStateEnums::BOOL: - this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1); - if (cmSystemTools::IsOn(value)) { - static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true); - } else { - static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(false); - } + switch (state->GetCacheEntryType(key)) { + case cmStateEnums::BOOL: { + auto bw = cm::make_unique<cmCursesBoolWidget>(this->EntryWidth, 1, 1, 1); + bw->SetValueAsBool(cmIsOn(value)); + this->Entry = std::move(bw); break; - case cmStateEnums::PATH: - this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1); - static_cast<cmCursesPathWidget*>(this->Entry)->SetString(value); + } + case cmStateEnums::PATH: { + auto pw = cm::make_unique<cmCursesPathWidget>(this->EntryWidth, 1, 1, 1); + pw->SetString(value); + this->Entry = std::move(pw); break; - case cmStateEnums::FILEPATH: - this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1); - static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(value); + } + case cmStateEnums::FILEPATH: { + auto fpw = + cm::make_unique<cmCursesFilePathWidget>(this->EntryWidth, 1, 1, 1); + fpw->SetString(value); + this->Entry = std::move(fpw); break; + } case cmStateEnums::STRING: { - const char* stringsProp = - cm->GetState()->GetCacheEntryProperty(key, "STRINGS"); + const char* stringsProp = state->GetCacheEntryProperty(key, "STRINGS"); if (stringsProp) { - cmCursesOptionsWidget* ow = - new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1); - this->Entry = ow; - std::vector<std::string> options; - cmSystemTools::ExpandListArgument(stringsProp, options); - for (std::vector<std::string>::iterator si = options.begin(); - si != options.end(); ++si) { - ow->AddOption(*si); + auto ow = + cm::make_unique<cmCursesOptionsWidget>(this->EntryWidth, 1, 1, 1); + for (std::string const& opt : cmExpandedList(stringsProp)) { + ow->AddOption(opt); } ow->SetOption(value); + this->Entry = std::move(ow); } else { - this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1); - static_cast<cmCursesStringWidget*>(this->Entry)->SetString(value); + auto sw = + cm::make_unique<cmCursesStringWidget>(this->EntryWidth, 1, 1, 1); + sw->SetString(value); + this->Entry = std::move(sw); } break; } case cmStateEnums::UNINITIALIZED: - cmSystemTools::Error("Found an undefined variable: ", key.c_str()); + cmSystemTools::Error("Found an undefined variable: " + key); break; default: // TODO : put warning message here @@ -92,17 +97,12 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite( } } -cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite() -{ - delete this->Label; - delete this->IsNewLabel; - delete this->Entry; -} +cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite() = default; const char* cmCursesCacheEntryComposite::GetValue() { if (this->Label) { return this->Label->GetValue(); } - return CM_NULLPTR; + return nullptr; } diff --git a/Source/CursesDialog/cmCursesCacheEntryComposite.h b/Source/CursesDialog/cmCursesCacheEntryComposite.h index 3c500785d..a71136331 100644 --- a/Source/CursesDialog/cmCursesCacheEntryComposite.h +++ b/Source/CursesDialog/cmCursesCacheEntryComposite.h @@ -3,32 +3,40 @@ #ifndef cmCursesCacheEntryComposite_h #define cmCursesCacheEntryComposite_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep +#include <memory> #include <string> class cmCursesLabelWidget; class cmCursesWidget; -class cmake; +class cmState; class cmCursesCacheEntryComposite { - CM_DISABLE_COPY(cmCursesCacheEntryComposite) - public: cmCursesCacheEntryComposite(const std::string& key, int labelwidth, int entrywidth); - cmCursesCacheEntryComposite(const std::string& key, cmake* cm, bool isNew, - int labelwidth, int entrywidth); + cmCursesCacheEntryComposite(const std::string& key, cmState* state, + bool isNew, int labelwidth, int entrywidth); ~cmCursesCacheEntryComposite(); + + cmCursesCacheEntryComposite(cmCursesCacheEntryComposite const&) = delete; + cmCursesCacheEntryComposite& operator=(cmCursesCacheEntryComposite const&) = + delete; + + cmCursesCacheEntryComposite(cmCursesCacheEntryComposite&&) = default; + cmCursesCacheEntryComposite& operator=(cmCursesCacheEntryComposite&&) = + default; + const char* GetValue(); friend class cmCursesMainForm; protected: - cmCursesLabelWidget* Label; - cmCursesLabelWidget* IsNewLabel; - cmCursesWidget* Entry; + std::unique_ptr<cmCursesLabelWidget> Label; + std::unique_ptr<cmCursesLabelWidget> IsNewLabel; + std::unique_ptr<cmCursesWidget> Entry; std::string Key; int LabelWidth; int EntryWidth; diff --git a/Source/CursesDialog/cmCursesDummyWidget.h b/Source/CursesDialog/cmCursesDummyWidget.h index d9bb6babc..07b7288ab 100644 --- a/Source/CursesDialog/cmCursesDummyWidget.h +++ b/Source/CursesDialog/cmCursesDummyWidget.h @@ -3,7 +3,7 @@ #ifndef cmCursesDummyWidget_h #define cmCursesDummyWidget_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCursesStandardIncludes.h" #include "cmCursesWidget.h" @@ -12,16 +12,17 @@ class cmCursesMainForm; class cmCursesDummyWidget : public cmCursesWidget { - CM_DISABLE_COPY(cmCursesDummyWidget) - public: cmCursesDummyWidget(int width, int height, int left, int top); + cmCursesDummyWidget(cmCursesDummyWidget const&) = delete; + cmCursesDummyWidget& operator=(cmCursesDummyWidget const&) = delete; + // Description: // Handle user input. Called by the container of this widget // when this widget has focus. Returns true if the input was // handled. - bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE; + bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) override; }; #endif // cmCursesDummyWidget_h diff --git a/Source/CursesDialog/cmCursesFilePathWidget.h b/Source/CursesDialog/cmCursesFilePathWidget.h index 6ad535b99..3f71259d5 100644 --- a/Source/CursesDialog/cmCursesFilePathWidget.h +++ b/Source/CursesDialog/cmCursesFilePathWidget.h @@ -3,16 +3,17 @@ #ifndef cmCursesFilePathWidget_h #define cmCursesFilePathWidget_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCursesPathWidget.h" class cmCursesFilePathWidget : public cmCursesPathWidget { - CM_DISABLE_COPY(cmCursesFilePathWidget) - public: cmCursesFilePathWidget(int width, int height, int left, int top); + + cmCursesFilePathWidget(cmCursesFilePathWidget const&) = delete; + cmCursesFilePathWidget& operator=(cmCursesFilePathWidget const&) = delete; }; #endif // cmCursesFilePathWidget_h diff --git a/Source/CursesDialog/cmCursesForm.cxx b/Source/CursesDialog/cmCursesForm.cxx index 06c1e9c70..bd65c4a08 100644 --- a/Source/CursesDialog/cmCursesForm.cxx +++ b/Source/CursesDialog/cmCursesForm.cxx @@ -7,7 +7,7 @@ bool cmCursesForm::Debug = false; cmCursesForm::cmCursesForm() { - this->Form = CM_NULLPTR; + this->Form = nullptr; } cmCursesForm::~cmCursesForm() @@ -15,7 +15,7 @@ cmCursesForm::~cmCursesForm() if (this->Form) { unpost_form(this->Form); free_form(this->Form); - this->Form = CM_NULLPTR; + this->Form = nullptr; } } diff --git a/Source/CursesDialog/cmCursesForm.h b/Source/CursesDialog/cmCursesForm.h index 553105c76..e3626e66a 100644 --- a/Source/CursesDialog/cmCursesForm.h +++ b/Source/CursesDialog/cmCursesForm.h @@ -3,20 +3,23 @@ #ifndef cmCursesForm_h #define cmCursesForm_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep -#include "cmCursesStandardIncludes.h" +#include <string> #include "cmsys/FStream.hxx" +#include "cmCursesStandardIncludes.h" + class cmCursesForm { - CM_DISABLE_COPY(cmCursesForm) - public: cmCursesForm(); virtual ~cmCursesForm(); + cmCursesForm(cmCursesForm const&) = delete; + cmCursesForm& operator=(cmCursesForm const&) = delete; + // Description: // Handle user input. virtual void HandleInput() = 0; @@ -33,7 +36,7 @@ public: // Description: // During a CMake run, an error handle should add errors // to be displayed afterwards. - virtual void AddError(const char*, const char*) {} + virtual void AddError(const std::string&, const char*) {} // Description: // Turn debugging on. This will create ccmakelog.txt. diff --git a/Source/CursesDialog/cmCursesLabelWidget.cxx b/Source/CursesDialog/cmCursesLabelWidget.cxx index 1dfd4ce47..83aea5a2c 100644 --- a/Source/CursesDialog/cmCursesLabelWidget.cxx +++ b/Source/CursesDialog/cmCursesLabelWidget.cxx @@ -14,9 +14,7 @@ cmCursesLabelWidget::cmCursesLabelWidget(int width, int height, int left, this->SetValue(name); } -cmCursesLabelWidget::~cmCursesLabelWidget() -{ -} +cmCursesLabelWidget::~cmCursesLabelWidget() = default; bool cmCursesLabelWidget::HandleInput(int& /*key*/, cmCursesMainForm* /*fm*/, WINDOW* /*w*/) diff --git a/Source/CursesDialog/cmCursesLabelWidget.h b/Source/CursesDialog/cmCursesLabelWidget.h index 267de7c8c..9e7568187 100644 --- a/Source/CursesDialog/cmCursesLabelWidget.h +++ b/Source/CursesDialog/cmCursesLabelWidget.h @@ -3,29 +3,30 @@ #ifndef cmCursesLabelWidget_h #define cmCursesLabelWidget_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep + +#include <string> #include "cmCursesStandardIncludes.h" #include "cmCursesWidget.h" -#include <string> - class cmCursesMainForm; class cmCursesLabelWidget : public cmCursesWidget { - CM_DISABLE_COPY(cmCursesLabelWidget) - public: cmCursesLabelWidget(int width, int height, int left, int top, const std::string& name); - ~cmCursesLabelWidget() CM_OVERRIDE; + ~cmCursesLabelWidget() override; + + cmCursesLabelWidget(cmCursesLabelWidget const&) = delete; + cmCursesLabelWidget& operator=(cmCursesLabelWidget const&) = delete; // Description: // Handle user input. Called by the container of this widget // when this widget has focus. Returns true if the input was // handled - bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE; + bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) override; }; #endif // cmCursesLabelWidget_h diff --git a/Source/CursesDialog/cmCursesLongMessageForm.cxx b/Source/CursesDialog/cmCursesLongMessageForm.cxx index 7fb065d30..e2d8d06b4 100644 --- a/Source/CursesDialog/cmCursesLongMessageForm.cxx +++ b/Source/CursesDialog/cmCursesLongMessageForm.cxx @@ -2,14 +2,14 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCursesLongMessageForm.h" +#include <cstdio> +#include <cstring> + #include "cmCursesForm.h" #include "cmCursesMainForm.h" #include "cmCursesStandardIncludes.h" #include "cmVersion.h" -#include <stdio.h> -#include <string.h> - inline int ctrl(int z) { return (z & 037); @@ -19,15 +19,14 @@ cmCursesLongMessageForm::cmCursesLongMessageForm( std::vector<std::string> const& messages, const char* title) { // Append all messages into on big string - std::vector<std::string>::const_iterator it; - for (it = messages.begin(); it != messages.end(); it++) { - this->Messages += (*it); + for (std::string const& message : messages) { + this->Messages += message; // Add one blank line after each message this->Messages += "\n\n"; } this->Title = title; - this->Fields[0] = CM_NULLPTR; - this->Fields[1] = CM_NULLPTR; + this->Fields[0] = nullptr; + this->Fields[1] = nullptr; } cmCursesLongMessageForm::~cmCursesLongMessageForm() @@ -39,11 +38,12 @@ cmCursesLongMessageForm::~cmCursesLongMessageForm() void cmCursesLongMessageForm::UpdateStatusBar() { - int x, y; + int x; + int y; getmaxyx(stdscr, y, x); char bar[cmCursesMainForm::MAX_WIDTH]; - size_t size = strlen(this->Title.c_str()); + size_t size = this->Title.size(); if (size >= cmCursesMainForm::MAX_WIDTH) { size = cmCursesMainForm::MAX_WIDTH - 1; } @@ -82,7 +82,8 @@ void cmCursesLongMessageForm::UpdateStatusBar() void cmCursesLongMessageForm::PrintKeys() { - int x, y; + int x; + int y; getmaxyx(stdscr, y, x); if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) { return; @@ -99,13 +100,14 @@ void cmCursesLongMessageForm::PrintKeys() void cmCursesLongMessageForm::Render(int /*left*/, int /*top*/, int /*width*/, int /*height*/) { - int x, y; + int x; + int y; getmaxyx(stdscr, y, x); if (this->Form) { unpost_form(this->Form); free_form(this->Form); - this->Form = CM_NULLPTR; + this->Form = nullptr; } const char* msg = this->Messages.c_str(); @@ -114,7 +116,7 @@ void cmCursesLongMessageForm::Render(int /*left*/, int /*top*/, int /*width*/, if (this->Fields[0]) { free_field(this->Fields[0]); - this->Fields[0] = CM_NULLPTR; + this->Fields[0] = nullptr; } this->Fields[0] = new_field(y - 6, x - 2, 1, 1, 0, 0); diff --git a/Source/CursesDialog/cmCursesLongMessageForm.h b/Source/CursesDialog/cmCursesLongMessageForm.h index cd8e0953a..42f9c710b 100644 --- a/Source/CursesDialog/cmCursesLongMessageForm.h +++ b/Source/CursesDialog/cmCursesLongMessageForm.h @@ -3,31 +3,32 @@ #ifndef cmCursesLongMessageForm_h #define cmCursesLongMessageForm_h -#include "cmConfigure.h" - -#include "cmCursesForm.h" -#include "cmCursesStandardIncludes.h" +#include "cmConfigure.h" // IWYU pragma: keep #include <string> #include <vector> +#include "cmCursesForm.h" +#include "cmCursesStandardIncludes.h" + class cmCursesLongMessageForm : public cmCursesForm { - CM_DISABLE_COPY(cmCursesLongMessageForm) - public: cmCursesLongMessageForm(std::vector<std::string> const& messages, const char* title); - ~cmCursesLongMessageForm() CM_OVERRIDE; + ~cmCursesLongMessageForm() override; + + cmCursesLongMessageForm(cmCursesLongMessageForm const&) = delete; + cmCursesLongMessageForm& operator=(cmCursesLongMessageForm const&) = delete; // Description: // Handle user input. - void HandleInput() CM_OVERRIDE; + void HandleInput() override; // Description: // Display form. Use a window of size width x height, starting // at top, left. - void Render(int left, int top, int width, int height) CM_OVERRIDE; + void Render(int left, int top, int width, int height) override; // Description: // This method should normally called only by the form. @@ -37,7 +38,7 @@ public: // Description: // This method should normally called only by the form. // The only exception is during a resize. - void UpdateStatusBar() CM_OVERRIDE; + void UpdateStatusBar() override; protected: std::string Messages; diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx index 026320a1f..6b71e8a10 100644 --- a/Source/CursesDialog/cmCursesMainForm.cxx +++ b/Source/CursesDialog/cmCursesMainForm.cxx @@ -2,7 +2,13 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCursesMainForm.h" -#include "cmAlgorithms.h" +#include <algorithm> +#include <cstdio> +#include <cstring> +#include <utility> + +#include <cm/memory> + #include "cmCursesCacheEntryComposite.h" #include "cmCursesDummyWidget.h" #include "cmCursesForm.h" @@ -13,44 +19,39 @@ #include "cmCursesWidget.h" #include "cmState.h" #include "cmStateTypes.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmVersion.h" #include "cmake.h" -#include <stdio.h> -#include <string.h> - inline int ctrl(int z) { return (z & 037); } -cmCursesMainForm::cmCursesMainForm(std::vector<std::string> const& args, +cmCursesMainForm::cmCursesMainForm(std::vector<std::string> args, int initWidth) - : Args(args) + : Args(std::move(args)) , InitialWidth(initWidth) { this->NumberOfPages = 0; - this->Fields = CM_NULLPTR; - this->Entries = CM_NULLPTR; this->AdvancedMode = false; this->NumberOfVisibleEntries = 0; this->OkToGenerate = false; - this->HelpMessage.push_back( + this->HelpMessage.emplace_back( "Welcome to ccmake, curses based user interface for CMake."); - this->HelpMessage.push_back(""); - this->HelpMessage.push_back(s_ConstHelpMessage); - this->CMakeInstance = new cmake(cmake::RoleProject); + this->HelpMessage.emplace_back(); + this->HelpMessage.emplace_back(s_ConstHelpMessage); + this->CMakeInstance = + cm::make_unique<cmake>(cmake::RoleProject, cmState::Project); this->CMakeInstance->SetCMakeEditCommand( cmSystemTools::GetCMakeCursesCommand()); // create the arguments for the cmake object - std::string whereCMake = cmSystemTools::GetProgramPath(this->Args[0]); - whereCMake += "/cmake"; + std::string whereCMake = + cmStrCat(cmSystemTools::GetProgramPath(this->Args[0]), "/cmake"); this->Args[0] = whereCMake; this->CMakeInstance->SetArgs(this->Args); - this->SearchString = ""; - this->OldSearchString = ""; this->SearchMode = false; } @@ -59,36 +60,17 @@ cmCursesMainForm::~cmCursesMainForm() if (this->Form) { unpost_form(this->Form); free_form(this->Form); - this->Form = CM_NULLPTR; - } - delete[] this->Fields; - - // Clean-up composites - if (this->Entries) { - cmDeleteAll(*this->Entries); - } - delete this->Entries; - if (this->CMakeInstance) { - delete this->CMakeInstance; - this->CMakeInstance = CM_NULLPTR; + this->Form = nullptr; } } // See if a cache entry is in the list of entries in the ui. bool cmCursesMainForm::LookForCacheEntry(const std::string& key) { - if (!this->Entries) { - return false; - } - - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { - if (key == (*it)->Key) { - return true; - } - } - - return false; + return std::any_of(this->Entries.begin(), this->Entries.end(), + [&key](cmCursesCacheEntryComposite const& entry) { + return key == entry.Key; + }); } // Create new cmCursesCacheEntryComposite entries from the cache @@ -96,19 +78,17 @@ void cmCursesMainForm::InitializeUI() { // Create a vector of cmCursesCacheEntryComposite's // which contain labels, entries and new entry markers - std::vector<cmCursesCacheEntryComposite*>* newEntries = - new std::vector<cmCursesCacheEntryComposite*>; + std::vector<cmCursesCacheEntryComposite> newEntries; std::vector<std::string> cacheKeys = this->CMakeInstance->GetState()->GetCacheEntryKeys(); - newEntries->reserve(cacheKeys.size()); + newEntries.reserve(cacheKeys.size()); // Count non-internal and non-static entries int count = 0; - for (std::vector<std::string>::const_iterator it = cacheKeys.begin(); - it != cacheKeys.end(); ++it) { + for (std::string const& key : cacheKeys) { cmStateEnums::CacheEntryType t = - this->CMakeInstance->GetState()->GetCacheEntryType(*it); + this->CMakeInstance->GetState()->GetCacheEntryType(key); if (t != cmStateEnums::INTERNAL && t != cmStateEnums::STATIC && t != cmStateEnums::UNINITIALIZED) { ++count; @@ -117,58 +97,49 @@ void cmCursesMainForm::InitializeUI() int entrywidth = this->InitialWidth - 35; - cmCursesCacheEntryComposite* comp; if (count == 0) { // If cache is empty, display a label saying so and a // dummy entry widget (does not respond to input) - comp = new cmCursesCacheEntryComposite("EMPTY CACHE", 30, 30); - comp->Entry = new cmCursesDummyWidget(1, 1, 1, 1); - newEntries->push_back(comp); + cmCursesCacheEntryComposite comp("EMPTY CACHE", 30, 30); + comp.Entry = cm::make_unique<cmCursesDummyWidget>(1, 1, 1, 1); + newEntries.emplace_back(std::move(comp)); } else { // Create the composites. // First add entries which are new - for (std::vector<std::string>::const_iterator it = cacheKeys.begin(); - it != cacheKeys.end(); ++it) { - std::string key = *it; + for (std::string const& key : cacheKeys) { cmStateEnums::CacheEntryType t = - this->CMakeInstance->GetState()->GetCacheEntryType(*it); + this->CMakeInstance->GetState()->GetCacheEntryType(key); if (t == cmStateEnums::INTERNAL || t == cmStateEnums::STATIC || t == cmStateEnums::UNINITIALIZED) { continue; } if (!this->LookForCacheEntry(key)) { - newEntries->push_back(new cmCursesCacheEntryComposite( - key, this->CMakeInstance, true, 30, entrywidth)); + newEntries.emplace_back(key, this->CMakeInstance->GetState(), true, 30, + entrywidth); this->OkToGenerate = false; } } // then add entries which are old - for (std::vector<std::string>::const_iterator it = cacheKeys.begin(); - it != cacheKeys.end(); ++it) { - std::string key = *it; + for (std::string const& key : cacheKeys) { cmStateEnums::CacheEntryType t = - this->CMakeInstance->GetState()->GetCacheEntryType(*it); + this->CMakeInstance->GetState()->GetCacheEntryType(key); if (t == cmStateEnums::INTERNAL || t == cmStateEnums::STATIC || t == cmStateEnums::UNINITIALIZED) { continue; } if (this->LookForCacheEntry(key)) { - newEntries->push_back(new cmCursesCacheEntryComposite( - key, this->CMakeInstance, false, 30, entrywidth)); + newEntries.emplace_back(key, this->CMakeInstance->GetState(), false, + 30, entrywidth); } } } - // Clean old entries - if (this->Entries) { - cmDeleteAll(*this->Entries); - } - delete this->Entries; - this->Entries = newEntries; + // Replace old entries + this->Entries = std::move(newEntries); // Compute fields from composites this->RePost(); @@ -180,21 +151,20 @@ void cmCursesMainForm::RePost() if (this->Form) { unpost_form(this->Form); free_form(this->Form); - this->Form = CM_NULLPTR; + this->Form = nullptr; } - delete[] this->Fields; + this->Fields.clear(); if (this->AdvancedMode) { - this->NumberOfVisibleEntries = this->Entries->size(); + this->NumberOfVisibleEntries = this->Entries.size(); } else { // If normal mode, count only non-advanced entries this->NumberOfVisibleEntries = 0; - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { + for (cmCursesCacheEntryComposite& entry : this->Entries) { const char* existingValue = - this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue()); + this->CMakeInstance->GetState()->GetCacheEntryValue(entry.GetValue()); bool advanced = this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool( - (*it)->GetValue(), "ADVANCED"); + entry.GetValue(), "ADVANCED"); if (!existingValue || (!this->AdvancedMode && advanced)) { continue; } @@ -207,39 +177,32 @@ void cmCursesMainForm::RePost() } // Assign the fields: 3 for each entry: label, new entry marker // ('*' or ' ') and entry widget - this->Fields = new FIELD*[3 * this->NumberOfVisibleEntries + 1]; - size_t cc; - for (cc = 0; cc < 3 * this->NumberOfVisibleEntries + 1; cc++) { - this->Fields[cc] = CM_NULLPTR; - } + this->Fields.reserve(3 * this->NumberOfVisibleEntries + 1); // Assign fields - int j = 0; - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { + for (cmCursesCacheEntryComposite& entry : this->Entries) { const char* existingValue = - this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue()); + this->CMakeInstance->GetState()->GetCacheEntryValue(entry.GetValue()); bool advanced = this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool( - (*it)->GetValue(), "ADVANCED"); + entry.GetValue(), "ADVANCED"); if (!existingValue || (!this->AdvancedMode && advanced)) { continue; } - this->Fields[3 * j] = (*it)->Label->Field; - this->Fields[3 * j + 1] = (*it)->IsNewLabel->Field; - this->Fields[3 * j + 2] = (*it)->Entry->Field; - j++; + this->Fields.push_back(entry.Label->Field); + this->Fields.push_back(entry.IsNewLabel->Field); + this->Fields.push_back(entry.Entry->Field); } // if no cache entries there should still be one dummy field - if (j == 0) { - it = this->Entries->begin(); - this->Fields[0] = (*it)->Label->Field; - this->Fields[1] = (*it)->IsNewLabel->Field; - this->Fields[2] = (*it)->Entry->Field; + if (this->Fields.empty()) { + const auto& front = this->Entries.front(); + this->Fields.push_back(front.Label->Field); + this->Fields.push_back(front.IsNewLabel->Field); + this->Fields.push_back(front.Entry->Field); this->NumberOfVisibleEntries = 1; } // Has to be null terminated. - this->Fields[3 * this->NumberOfVisibleEntries] = CM_NULLPTR; + this->Fields.push_back(nullptr); } void cmCursesMainForm::Render(int left, int top, int width, int height) @@ -259,7 +222,7 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) // Delete the previous form unpost_form(this->Form); free_form(this->Form); - this->Form = CM_NULLPTR; + this->Form = nullptr; } // Wrong window size @@ -272,17 +235,16 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) height -= 7; if (this->AdvancedMode) { - this->NumberOfVisibleEntries = this->Entries->size(); + this->NumberOfVisibleEntries = this->Entries.size(); } else { // If normal, display only non-advanced entries this->NumberOfVisibleEntries = 0; - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { + for (cmCursesCacheEntryComposite& entry : this->Entries) { const char* existingValue = - this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue()); + this->CMakeInstance->GetState()->GetCacheEntryValue(entry.GetValue()); bool advanced = this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool( - (*it)->GetValue(), "ADVANCED"); + entry.GetValue(), "ADVANCED"); if (!existingValue || (!this->AdvancedMode && advanced)) { continue; } @@ -295,13 +257,12 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) if (height > 0) { bool isNewPage; int i = 0; - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { + for (cmCursesCacheEntryComposite& entry : this->Entries) { const char* existingValue = - this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue()); + this->CMakeInstance->GetState()->GetCacheEntryValue(entry.GetValue()); bool advanced = this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool( - (*it)->GetValue(), "ADVANCED"); + entry.GetValue(), "ADVANCED"); if (!existingValue || (!this->AdvancedMode && advanced)) { continue; } @@ -312,16 +273,16 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) if (isNewPage) { this->NumberOfPages++; } - (*it)->Label->Move(left, top + row - 1, isNewPage); - (*it)->IsNewLabel->Move(left + 32, top + row - 1, false); - (*it)->Entry->Move(left + 33, top + row - 1, false); - (*it)->Entry->SetPage(this->NumberOfPages); + entry.Label->Move(left, top + row - 1, isNewPage); + entry.IsNewLabel->Move(left + 32, top + row - 1, false); + entry.Entry->Move(left + 33, top + row - 1, false); + entry.Entry->SetPage(this->NumberOfPages); i++; } } // Post the form - this->Form = new_form(this->Fields); + this->Form = new_form(this->Fields.data()); post_form(this->Form); // Update toolbar this->UpdateStatusBar(); @@ -333,7 +294,8 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) void cmCursesMainForm::PrintKeys(int process /* = 0 */) { - int x, y; + int x; + int y; getmaxyx(stdscr, y, x); if (x < cmCursesMainForm::MIN_WIDTH || x < this->InitialWidth || y < cmCursesMainForm::MIN_HEIGHT) { @@ -341,23 +303,21 @@ void cmCursesMainForm::PrintKeys(int process /* = 0 */) } // Give the current widget (if it exists), a chance to print keys - cmCursesWidget* cw = CM_NULLPTR; + cmCursesWidget* cw = nullptr; if (this->Form) { FIELD* currentField = current_field(this->Form); cw = reinterpret_cast<cmCursesWidget*>(field_userptr(currentField)); } char fmt_s[] = "%s"; - if (cw == CM_NULLPTR || !cw->PrintKeys()) { + if (cw == nullptr || !cw->PrintKeys()) { char firstLine[512] = ""; char secondLine[512] = ""; char thirdLine[512] = ""; if (process) { - const char* clearLine = - " "; - strcpy(firstLine, clearLine); - strcpy(secondLine, clearLine); - strcpy(thirdLine, clearLine); + memset(firstLine, ' ', 68); + memset(secondLine, ' ', 68); + memset(thirdLine, ' ', 68); } else { if (this->OkToGenerate) { sprintf(firstLine, @@ -372,15 +332,16 @@ void cmCursesMainForm::PrintKeys(int process /* = 0 */) sprintf(thirdLine, toggleKeyInstruction, this->AdvancedMode ? "On" : "Off"); } - sprintf(secondLine, "Press [h] for help " - "Press [q] to quit without generating"); + sprintf(secondLine, + "Press [h] for help " + "Press [q] to quit without generating"); } curses_move(y - 4, 0); char fmt[512] = "Press [enter] to edit option Press [d] to delete an entry"; if (process) { - strcpy(fmt, " "); + memset(fmt, ' ', 57); } printw(fmt_s, fmt); curses_move(y - 3, 0); @@ -405,7 +366,8 @@ void cmCursesMainForm::PrintKeys(int process /* = 0 */) // on the status bar. Designed for a width of 80 chars. void cmCursesMainForm::UpdateStatusBar(const char* message) { - int x, y; + int x; + int y; getmaxyx(stdscr, y, x); // If window size is too small, display error and return if (x < cmCursesMainForm::MIN_WIDTH || x < this->InitialWidth || @@ -413,9 +375,10 @@ void cmCursesMainForm::UpdateStatusBar(const char* message) curses_clear(); curses_move(0, 0); char fmt[] = "Window is too small. A size of at least %dx%d is required."; - printw(fmt, (cmCursesMainForm::MIN_WIDTH < this->InitialWidth - ? this->InitialWidth - : cmCursesMainForm::MIN_WIDTH), + printw(fmt, + (cmCursesMainForm::MIN_WIDTH < this->InitialWidth + ? this->InitialWidth + : cmCursesMainForm::MIN_WIDTH), cmCursesMainForm::MIN_HEIGHT); touchwin(stdscr); wrefresh(stdscr); @@ -425,7 +388,7 @@ void cmCursesMainForm::UpdateStatusBar(const char* message) // Get the key of the current entry FIELD* cur = current_field(this->Form); int findex = field_index(cur); - cmCursesWidget* lbl = CM_NULLPTR; + cmCursesWidget* lbl = nullptr; if (findex >= 0) { lbl = reinterpret_cast<cmCursesWidget*>( field_userptr(this->Fields[findex - 2])); @@ -456,41 +419,27 @@ void cmCursesMainForm::UpdateStatusBar(const char* message) // Join the key, help string and pad with spaces // (or truncate) as necessary char bar[cmCursesMainForm::MAX_WIDTH]; - size_t i, curFieldLen = strlen(curField); + size_t curFieldLen = strlen(curField); size_t helpLen = strlen(help); - size_t width; - if (x < cmCursesMainForm::MAX_WIDTH) { - width = x; - } else { - width = cmCursesMainForm::MAX_WIDTH; - } + size_t width = std::min<size_t>(x, cmCursesMainForm::MAX_WIDTH); if (message) { curField = message; curFieldLen = strlen(message); + strncpy(bar, curField, width); if (curFieldLen < width) { - strcpy(bar, curField); - for (i = curFieldLen; i < width; ++i) { - bar[i] = ' '; - } - } else { - strncpy(bar, curField, width); + memset(bar + curFieldLen, ' ', width - curFieldLen); } } else { - if (curFieldLen >= width) { - strncpy(bar, curField, width); - } else { - strcpy(bar, curField); + strncpy(bar, curField, width); + if (curFieldLen < width) { bar[curFieldLen] = ':'; bar[curFieldLen + 1] = ' '; - if (curFieldLen + helpLen + 2 >= width) { - strncpy(bar + curFieldLen + 2, help, width - curFieldLen - 2); - } else { - strcpy(bar + curFieldLen + 2, help); - for (i = curFieldLen + helpLen + 2; i < width; ++i) { - bar[i] = ' '; - } + strncpy(bar + curFieldLen + 2, help, width - curFieldLen - 2); + if (curFieldLen + helpLen + 2 < width) { + memset(bar + curFieldLen + helpLen + 2, ' ', + width - (curFieldLen + helpLen + 2)); } } } @@ -503,9 +452,7 @@ void cmCursesMainForm::UpdateStatusBar(const char* message) char vertmp[128]; sprintf(vertmp, "CMake Version %s", cmVersion::GetCMakeVersion()); size_t sideSpace = (width - strlen(vertmp)); - for (i = 0; i < sideSpace; i++) { - version[i] = ' '; - } + memset(version, ' ', sideSpace); sprintf(version + sideSpace, "%s", vertmp); version[width] = '\0'; @@ -520,21 +467,17 @@ void cmCursesMainForm::UpdateStatusBar(const char* message) pos_form_cursor(this->Form); } -void cmCursesMainForm::UpdateProgress(const char* msg, float prog, void* vp) +void cmCursesMainForm::UpdateProgress(const std::string& msg, float prog) { - cmCursesMainForm* cm = static_cast<cmCursesMainForm*>(vp); - if (!cm) { - return; - } char tmp[1024]; const char* cmsg = tmp; if (prog >= 0) { - sprintf(tmp, "%s %i%%", msg, (int)(100 * prog)); + sprintf(tmp, "%s %i%%", msg.c_str(), static_cast<int>(100 * prog)); } else { - cmsg = msg; + cmsg = msg.c_str(); } - cm->UpdateStatusBar(cmsg); - cm->PrintKeys(1); + this->UpdateStatusBar(cmsg); + this->PrintKeys(1); curses_move(1, 1); touchwin(stdscr); refresh(); @@ -542,7 +485,8 @@ void cmCursesMainForm::UpdateProgress(const char* msg, float prog, void* vp) int cmCursesMainForm::Configure(int noconfigure) { - int xi, yi; + int xi; + int yi; getmaxyx(stdscr, yi, xi); curses_move(1, 1); @@ -550,14 +494,16 @@ int cmCursesMainForm::Configure(int noconfigure) this->PrintKeys(1); touchwin(stdscr); refresh(); - this->CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress, - this); + this->CMakeInstance->SetProgressCallback( + [this](const std::string& msg, float prog) { + this->UpdateProgress(msg, prog); + }); // always save the current gui values to disk this->FillCacheManagerFromUI(); this->CMakeInstance->SaveCache( this->CMakeInstance->GetHomeOutputDirectory()); - this->LoadCache(CM_NULLPTR); + this->LoadCache(nullptr); // Get rid of previous errors this->Errors = std::vector<std::string>(); @@ -574,7 +520,7 @@ int cmCursesMainForm::Configure(int noconfigure) } else { retVal = this->CMakeInstance->Configure(); } - this->CMakeInstance->SetProgressCallback(CM_NULLPTR, CM_NULLPTR); + this->CMakeInstance->SetProgressCallback(nullptr); keypad(stdscr, true); /* Use key symbols as KEY_DOWN */ @@ -583,12 +529,14 @@ int cmCursesMainForm::Configure(int noconfigure) if (cmSystemTools::GetErrorOccuredFlag()) { this->OkToGenerate = false; } - int xx, yy; + int xx; + int yy; getmaxyx(stdscr, yy, xx); - cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm( - this->Errors, cmSystemTools::GetErrorOccuredFlag() - ? "Errors occurred during the last pass." - : "CMake produced the following output."); + cmCursesLongMessageForm* msgs = + new cmCursesLongMessageForm(this->Errors, + cmSystemTools::GetErrorOccuredFlag() + ? "Errors occurred during the last pass." + : "CMake produced the following output."); // reset error condition cmSystemTools::ResetErrorOccuredFlag(); CurrentForm = msgs; @@ -611,7 +559,8 @@ int cmCursesMainForm::Configure(int noconfigure) int cmCursesMainForm::Generate() { - int xi, yi; + int xi; + int yi; getmaxyx(stdscr, yi, xi); curses_move(1, 1); @@ -619,8 +568,10 @@ int cmCursesMainForm::Generate() this->PrintKeys(1); touchwin(stdscr); refresh(); - this->CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress, - this); + this->CMakeInstance->SetProgressCallback( + [this](const std::string& msg, float prog) { + this->UpdateProgress(msg, prog); + }); // Get rid of previous errors this->Errors = std::vector<std::string>(); @@ -628,7 +579,7 @@ int cmCursesMainForm::Generate() // run the generate process int retVal = this->CMakeInstance->Generate(); - this->CMakeInstance->SetProgressCallback(CM_NULLPTR, CM_NULLPTR); + this->CMakeInstance->SetProgressCallback(nullptr); keypad(stdscr, true); /* Use key symbols as KEY_DOWN */ if (retVal != 0 || !this->Errors.empty()) { @@ -638,7 +589,8 @@ int cmCursesMainForm::Generate() } // reset error condition cmSystemTools::ResetErrorOccuredFlag(); - int xx, yy; + int xx; + int yy; getmaxyx(stdscr, yy, xx); const char* title = "Messages during last pass."; if (cmSystemTools::GetErrorOccuredFlag()) { @@ -664,9 +616,10 @@ int cmCursesMainForm::Generate() return 0; } -void cmCursesMainForm::AddError(const char* message, const char* /*unused*/) +void cmCursesMainForm::AddError(const std::string& message, + const char* /*unused*/) { - this->Errors.push_back(message); + this->Errors.emplace_back(message); } void cmCursesMainForm::RemoveEntry(const char* value) @@ -675,28 +628,29 @@ void cmCursesMainForm::RemoveEntry(const char* value) return; } - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { - const char* val = (*it)->GetValue(); - if (val && !strcmp(value, val)) { - this->CMakeInstance->UnwatchUnusedCli(value); - this->Entries->erase(it); - break; - } + auto removeIt = + std::find_if(this->Entries.begin(), this->Entries.end(), + [value](cmCursesCacheEntryComposite& entry) -> bool { + const char* val = entry.GetValue(); + return val != nullptr && !strcmp(value, val); + }); + + if (removeIt != this->Entries.end()) { + this->CMakeInstance->UnwatchUnusedCli(value); + this->Entries.erase(removeIt); } } // copy from the list box to the cache manager void cmCursesMainForm::FillCacheManagerFromUI() { - size_t size = this->Entries->size(); - for (size_t i = 0; i < size; i++) { - std::string cacheKey = (*this->Entries)[i]->Key; + for (cmCursesCacheEntryComposite& entry : this->Entries) { + const std::string& cacheKey = entry.Key; const char* existingValue = this->CMakeInstance->GetState()->GetCacheEntryValue(cacheKey); if (existingValue) { std::string oldValue = existingValue; - std::string newValue = (*this->Entries)[i]->Entry->GetValue(); + std::string newValue = entry.Entry->GetValue(); std::string fixedOldValue; std::string fixedNewValue; cmStateEnums::CacheEntryType t = @@ -723,7 +677,7 @@ void cmCursesMainForm::FixValue(cmStateEnums::CacheEntryType type, cmSystemTools::ConvertToUnixSlashes(out); } if (type == cmStateEnums::BOOL) { - if (cmSystemTools::IsOff(out.c_str())) { + if (cmIsOff(out)) { out = "OFF"; } else { out = "ON"; @@ -733,7 +687,8 @@ void cmCursesMainForm::FixValue(cmStateEnums::CacheEntryType type, void cmCursesMainForm::HandleInput() { - int x = 0, y = 0; + int x = 0; + int y = 0; if (!this->Form) { return; @@ -781,7 +736,7 @@ void cmCursesMainForm::HandleInput() this->JumpToCacheEntry(this->SearchString.c_str()); this->OldSearchString = this->SearchString; } - this->SearchString = ""; + this->SearchString.clear(); } /* else if ( key == KEY_ESCAPE ) @@ -797,7 +752,7 @@ void cmCursesMainForm::HandleInput() } } else if (key == ctrl('h') || key == KEY_BACKSPACE || key == KEY_DC) { if (!this->SearchString.empty()) { - this->SearchString.resize(this->SearchString.size() - 1); + this->SearchString.pop_back(); } } } else if (currentWidget && !this->SearchMode) { @@ -877,7 +832,7 @@ void cmCursesMainForm::HandleInput() cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>( field_userptr(this->Fields[findex - 2])); const char* curField = lbl->GetValue(); - const char* helpString = CM_NULLPTR; + const char* helpString = nullptr; const char* existingValue = this->CMakeInstance->GetState()->GetCacheEntryValue(curField); @@ -886,17 +841,9 @@ void cmCursesMainForm::HandleInput() curField, "HELPSTRING"); } if (helpString) { - char* message = new char - [strlen(curField) + strlen(helpString) + - strlen( - "Current option is: \n Help string for this option is: \n") + - 10]; - sprintf( - message, - "Current option is: %s\nHelp string for this option is: %s\n", - curField, helpString); - this->HelpMessage[1] = message; - delete[] message; + this->HelpMessage[1] = + cmStrCat("Current option is: ", curField, '\n', + "Help string for this option is: ", helpString, '\n'); } else { this->HelpMessage[1] = ""; } @@ -962,7 +909,7 @@ void cmCursesMainForm::HandleInput() // (findex always corresponds to the value field) FIELD* nextCur; if (findex == 2) { - nextCur = CM_NULLPTR; + nextCur = nullptr; } else if (findex == 3 * this->NumberOfVisibleEntries - 1) { nextCur = this->Fields[findex - 5]; } else { @@ -992,17 +939,14 @@ void cmCursesMainForm::HandleInput() if (nextCur) { // make the next or prev. current field after deletion - nextCur = CM_NULLPTR; - std::vector<cmCursesCacheEntryComposite*>::iterator it; - for (it = this->Entries->begin(); it != this->Entries->end(); - ++it) { - if (nextVal == (*it)->Key) { - nextCur = (*it)->Entry->Field; - } - } - - if (nextCur) { - set_current_field(this->Form, nextCur); + auto nextEntryIt = std::find_if( + this->Entries.begin(), this->Entries.end(), + [&nextVal](cmCursesCacheEntryComposite const& entry) { + return nextVal == entry.Key; + }); + + if (nextEntryIt != this->Entries.end()) { + set_current_field(this->Form, nextEntryIt->Entry->Field); } } } @@ -1041,7 +985,7 @@ void cmCursesMainForm::JumpToCacheEntry(const char* astr) int findex = start_index; for (;;) { if (!str.empty()) { - cmCursesWidget* lbl = CM_NULLPTR; + cmCursesWidget* lbl = nullptr; if (findex >= 0) { lbl = reinterpret_cast<cmCursesWidget*>( field_userptr(this->Fields[findex - 2])); diff --git a/Source/CursesDialog/cmCursesMainForm.h b/Source/CursesDialog/cmCursesMainForm.h index e35cf3ed7..b8769b7cf 100644 --- a/Source/CursesDialog/cmCursesMainForm.h +++ b/Source/CursesDialog/cmCursesMainForm.h @@ -3,17 +3,18 @@ #ifndef cmCursesMainForm_h #define cmCursesMainForm_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep +#include <cstddef> +#include <memory> +#include <string> +#include <vector> + +#include "cmCursesCacheEntryComposite.h" #include "cmCursesForm.h" #include "cmCursesStandardIncludes.h" #include "cmStateTypes.h" -#include <stddef.h> -#include <string> -#include <vector> - -class cmCursesCacheEntryComposite; class cmake; /** \class cmCursesMainForm @@ -23,11 +24,12 @@ class cmake; */ class cmCursesMainForm : public cmCursesForm { - CM_DISABLE_COPY(cmCursesMainForm) - public: - cmCursesMainForm(std::vector<std::string> const& args, int initwidth); - ~cmCursesMainForm() CM_OVERRIDE; + cmCursesMainForm(std::vector<std::string> args, int initwidth); + ~cmCursesMainForm() override; + + cmCursesMainForm(cmCursesMainForm const&) = delete; + cmCursesMainForm& operator=(cmCursesMainForm const&) = delete; /** * Set the widgets which represent the cache entries. @@ -37,13 +39,13 @@ public: /** * Handle user input. */ - void HandleInput() CM_OVERRIDE; + void HandleInput() override; /** * Display form. Use a window of size width x height, starting * at top, left. */ - void Render(int left, int top, int width, int height) CM_OVERRIDE; + void Render(int left, int top, int width, int height) override; /** * Returns true if an entry with the given key is in the @@ -64,7 +66,7 @@ public: * exception is during a resize. The optional argument specifies the * string to be displayed in the status bar. */ - void UpdateStatusBar() CM_OVERRIDE { this->UpdateStatusBar(CM_NULLPTR); } + void UpdateStatusBar() override { this->UpdateStatusBar(nullptr); } virtual void UpdateStatusBar(const char* message); /** @@ -80,7 +82,7 @@ public: * During a CMake run, an error handle should add errors * to be displayed afterwards. */ - void AddError(const char* message, const char* title) CM_OVERRIDE; + void AddError(const std::string& message, const char* title) override; /** * Used to do a configure. If argument is specified, it does only the check @@ -101,8 +103,7 @@ public: /** * Progress callback */ - static void UpdateProgressOld(const char* msg, float prog, void*); - static void UpdateProgress(const char* msg, float prog, void*); + void UpdateProgress(const std::string& msg, float prog); protected: // Copy the cache values from the user interface to the actual @@ -122,10 +123,10 @@ protected: void JumpToCacheEntry(const char* str); // Copies of cache entries stored in the user interface - std::vector<cmCursesCacheEntryComposite*>* Entries; + std::vector<cmCursesCacheEntryComposite> Entries; // Errors produced during last run of cmake std::vector<std::string> Errors; - // Command line argumens to be passed to cmake each time + // Command line arguments to be passed to cmake each time // it is run std::vector<std::string> Args; // Message displayed when user presses 'h' @@ -136,11 +137,7 @@ protected: static const char* s_ConstHelpMessage; // Fields displayed. Includes labels, new entry markers, entries - FIELD** Fields; - // Where is source of current project - std::string WhereSource; - // Where is cmake executable - std::string WhereCMake; + std::vector<FIELD*> Fields; // Number of entries shown (depends on mode -normal or advanced-) size_t NumberOfVisibleEntries; bool AdvancedMode; @@ -150,7 +147,7 @@ protected: int NumberOfPages; int InitialWidth; - cmake* CMakeInstance; + std::unique_ptr<cmake> CMakeInstance; std::string SearchString; std::string OldSearchString; diff --git a/Source/CursesDialog/cmCursesOptionsWidget.cxx b/Source/CursesDialog/cmCursesOptionsWidget.cxx index d26a98f86..eb773ad0f 100644 --- a/Source/CursesDialog/cmCursesOptionsWidget.cxx +++ b/Source/CursesDialog/cmCursesOptionsWidget.cxx @@ -23,6 +23,9 @@ cmCursesOptionsWidget::cmCursesOptionsWidget(int width, int height, int left, bool cmCursesOptionsWidget::HandleInput(int& key, cmCursesMainForm* /*fm*/, WINDOW* w) { + if (this->Options.empty()) { + return false; + } switch (key) { case 10: // 10 == enter case KEY_ENTER: @@ -75,9 +78,8 @@ void cmCursesOptionsWidget::SetOption(const std::string& value) this->CurrentOption = 0; // default to 0 index this->SetValue(value); int index = 0; - for (std::vector<std::string>::iterator i = this->Options.begin(); - i != this->Options.end(); ++i) { - if (*i == value) { + for (auto const& opt : this->Options) { + if (opt == value) { this->CurrentOption = index; } index++; diff --git a/Source/CursesDialog/cmCursesOptionsWidget.h b/Source/CursesDialog/cmCursesOptionsWidget.h index 7f4416f95..0de8e6407 100644 --- a/Source/CursesDialog/cmCursesOptionsWidget.h +++ b/Source/CursesDialog/cmCursesOptionsWidget.h @@ -3,28 +3,29 @@ #ifndef cmCursesOptionsWidget_h #define cmCursesOptionsWidget_h -#include "cmConfigure.h" - -#include "cmCursesStandardIncludes.h" -#include "cmCursesWidget.h" +#include "cmConfigure.h" // IWYU pragma: keep #include <string> #include <vector> +#include "cmCursesStandardIncludes.h" +#include "cmCursesWidget.h" + class cmCursesMainForm; class cmCursesOptionsWidget : public cmCursesWidget { - CM_DISABLE_COPY(cmCursesOptionsWidget) - public: cmCursesOptionsWidget(int width, int height, int left, int top); + cmCursesOptionsWidget(cmCursesOptionsWidget const&) = delete; + cmCursesOptionsWidget& operator=(cmCursesOptionsWidget const&) = delete; + // Description: // Handle user input. Called by the container of this widget // when this widget has focus. Returns true if the input was // handled. - bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE; + bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) override; void SetOption(const std::string&); void AddOption(std::string const&); void NextOption(); diff --git a/Source/CursesDialog/cmCursesPathWidget.cxx b/Source/CursesDialog/cmCursesPathWidget.cxx index 05c3279c3..bb3808e89 100644 --- a/Source/CursesDialog/cmCursesPathWidget.cxx +++ b/Source/CursesDialog/cmCursesPathWidget.cxx @@ -2,13 +2,13 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCursesPathWidget.h" +#include <vector> + #include "cmCursesMainForm.h" #include "cmCursesStringWidget.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include <vector> - cmCursesPathWidget::cmCursesPathWidget(int width, int height, int left, int top) : cmCursesStringWidget(width, height, left, top) diff --git a/Source/CursesDialog/cmCursesPathWidget.h b/Source/CursesDialog/cmCursesPathWidget.h index ae6c16d02..fb365e9c5 100644 --- a/Source/CursesDialog/cmCursesPathWidget.h +++ b/Source/CursesDialog/cmCursesPathWidget.h @@ -3,29 +3,30 @@ #ifndef cmCursesPathWidget_h #define cmCursesPathWidget_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep + +#include <string> #include "cmCursesStandardIncludes.h" #include "cmCursesStringWidget.h" -#include <string> - class cmCursesMainForm; class cmCursesPathWidget : public cmCursesStringWidget { - CM_DISABLE_COPY(cmCursesPathWidget) - public: cmCursesPathWidget(int width, int height, int left, int top); + cmCursesPathWidget(cmCursesPathWidget const&) = delete; + cmCursesPathWidget& operator=(cmCursesPathWidget const&) = delete; + /** * This method is called when different keys are pressed. The * subclass can have a special implementation handler for this. */ - void OnTab(cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE; - void OnReturn(cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE; - void OnType(int& key, cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE; + void OnTab(cmCursesMainForm* fm, WINDOW* w) override; + void OnReturn(cmCursesMainForm* fm, WINDOW* w) override; + void OnType(int& key, cmCursesMainForm* fm, WINDOW* w) override; protected: std::string LastString; diff --git a/Source/CursesDialog/cmCursesStandardIncludes.h b/Source/CursesDialog/cmCursesStandardIncludes.h index 5c5950483..5b0ad5824 100644 --- a/Source/CursesDialog/cmCursesStandardIncludes.h +++ b/Source/CursesDialog/cmCursesStandardIncludes.h @@ -3,11 +3,16 @@ #ifndef cmCursesStandardIncludes_h #define cmCursesStandardIncludes_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep + +// Record whether __attribute__ is currently defined. See purpose below. +#ifndef __attribute__ +# define cm_no__attribute__ +#endif #if defined(__hpux) -#define _BOOL_DEFINED -#include <sys/time.h> +# define _BOOL_DEFINED +# include <sys/time.h> #endif #include <form.h> @@ -29,4 +34,12 @@ inline void curses_clear() #undef erase #undef clear +// The curses headers on some platforms (e.g. Solaris) may +// define __attribute__ as a macro. This breaks C++ headers +// in some cases, so undefine it now. +#if defined(cm_no__attribute__) && defined(__attribute__) +# undef __attribute__ +#endif +#undef cm_no__attribute__ + #endif // cmCursesStandardIncludes_h diff --git a/Source/CursesDialog/cmCursesStringWidget.cxx b/Source/CursesDialog/cmCursesStringWidget.cxx index ff189f01e..6296af20b 100644 --- a/Source/CursesDialog/cmCursesStringWidget.cxx +++ b/Source/CursesDialog/cmCursesStringWidget.cxx @@ -2,15 +2,14 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCursesStringWidget.h" +#include <cstdio> + #include "cmCursesForm.h" #include "cmCursesMainForm.h" #include "cmCursesStandardIncludes.h" #include "cmCursesWidget.h" #include "cmStateTypes.h" -#include <stdio.h> -#include <string.h> - inline int ctrl(int z) { return (z & 037); @@ -35,13 +34,13 @@ void cmCursesStringWidget::OnTab(cmCursesMainForm* /*unused*/, void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW* /*unused*/) { - FORM* form = fm->GetForm(); if (this->InEdit) { cmCursesForm::LogMessage("String widget leaving edit."); this->InEdit = false; fm->PrintKeys(); - delete[] this->OriginalString; + this->OriginalString.clear(); // trick to force forms to update the field buffer + FORM* form = fm->GetForm(); form_driver(form, REQ_NEXT_FIELD); form_driver(form, REQ_PREV_FIELD); this->Done = true; @@ -49,9 +48,7 @@ void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW* /*unused*/) cmCursesForm::LogMessage("String widget entering edit."); this->InEdit = true; fm->PrintKeys(); - char* buf = field_buffer(this->Field, 0); - this->OriginalString = new char[strlen(buf) + 1]; - strcpy(this->OriginalString, buf); + this->OriginalString = field_buffer(this->Field, 0); } } @@ -64,7 +61,8 @@ void cmCursesStringWidget::OnType(int& key, cmCursesMainForm* fm, bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) { - int x, y; + int x; + int y; FORM* form = fm->GetForm(); // when not in edit mode, edit mode is entered by pressing enter or i (vim @@ -74,7 +72,7 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm, return false; } - this->OriginalString = CM_NULLPTR; + this->OriginalString.clear(); this->Done = false; char debugMessage[128]; @@ -112,7 +110,7 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm, key == ctrl('p') || key == KEY_NPAGE || key == ctrl('d') || key == KEY_PPAGE || key == ctrl('u')) { this->InEdit = false; - delete[] this->OriginalString; + this->OriginalString.clear(); // trick to force forms to update the field buffer form_driver(form, REQ_NEXT_FIELD); form_driver(form, REQ_PREV_FIELD); @@ -124,7 +122,7 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm, this->InEdit = false; fm->PrintKeys(); this->SetString(this->OriginalString); - delete[] this->OriginalString; + this->OriginalString.clear(); touchwin(w); wrefresh(w); return true; @@ -179,32 +177,26 @@ const char* cmCursesStringWidget::GetValue() bool cmCursesStringWidget::PrintKeys() { - int x, y; + int x; + int y; getmaxyx(stdscr, y, x); if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) { return false; } if (this->InEdit) { char fmt_s[] = "%s"; - char firstLine[512]; // Clean the toolbar - for (int i = 0; i < 512; i++) { - firstLine[i] = ' '; - } - firstLine[511] = '\0'; curses_move(y - 4, 0); - printw(fmt_s, firstLine); - curses_move(y - 3, 0); - printw(fmt_s, firstLine); - curses_move(y - 2, 0); - printw(fmt_s, firstLine); - curses_move(y - 1, 0); - printw(fmt_s, firstLine); - + clrtoeol(); curses_move(y - 3, 0); printw(fmt_s, "Editing option, press [enter] to confirm"); + clrtoeol(); curses_move(y - 2, 0); printw(fmt_s, " press [esc] to cancel"); + clrtoeol(); + curses_move(y - 1, 0); + clrtoeol(); + return true; } return false; diff --git a/Source/CursesDialog/cmCursesStringWidget.h b/Source/CursesDialog/cmCursesStringWidget.h index 5eb33666d..ce06c6da7 100644 --- a/Source/CursesDialog/cmCursesStringWidget.h +++ b/Source/CursesDialog/cmCursesStringWidget.h @@ -3,13 +3,13 @@ #ifndef cmCursesStringWidget_h #define cmCursesStringWidget_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep + +#include <string> #include "cmCursesStandardIncludes.h" #include "cmCursesWidget.h" -#include <string> - class cmCursesMainForm; /** \class cmCursesStringWidget @@ -20,8 +20,6 @@ class cmCursesMainForm; class cmCursesStringWidget : public cmCursesWidget { - CM_DISABLE_COPY(cmCursesStringWidget) - public: cmCursesStringWidget(int width, int height, int left, int top); @@ -30,14 +28,14 @@ public: * when this widget has focus. Returns true if the input was * handled. */ - bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE; + bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) override; /** * Set/Get the string. */ void SetString(const std::string& value); const char* GetString(); - const char* GetValue() CM_OVERRIDE; + const char* GetValue() override; /** * Set/Get InEdit flag. Can be used to tell the widget to leave @@ -59,12 +57,12 @@ public: * in the toolbar and return true. Otherwise, return false * and the parent widget will print. */ - bool PrintKeys() CM_OVERRIDE; + bool PrintKeys() override; protected: // true if the widget is in edit mode bool InEdit; - char* OriginalString; + std::string OriginalString; bool Done; }; diff --git a/Source/CursesDialog/cmCursesWidget.cxx b/Source/CursesDialog/cmCursesWidget.cxx index 054f27e29..cc07411d4 100644 --- a/Source/CursesDialog/cmCursesWidget.cxx +++ b/Source/CursesDialog/cmCursesWidget.cxx @@ -14,7 +14,7 @@ cmCursesWidget::~cmCursesWidget() { if (this->Field) { free_field(this->Field); - this->Field = CM_NULLPTR; + this->Field = nullptr; } } diff --git a/Source/CursesDialog/cmCursesWidget.h b/Source/CursesDialog/cmCursesWidget.h index 3470d7096..9d03c6e42 100644 --- a/Source/CursesDialog/cmCursesWidget.h +++ b/Source/CursesDialog/cmCursesWidget.h @@ -3,23 +3,24 @@ #ifndef cmCursesWidget_h #define cmCursesWidget_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep + +#include <string> #include "cmCursesStandardIncludes.h" #include "cmStateTypes.h" -#include <string> - class cmCursesMainForm; class cmCursesWidget { - CM_DISABLE_COPY(cmCursesWidget) - public: cmCursesWidget(int width, int height, int left, int top); virtual ~cmCursesWidget(); + cmCursesWidget(cmCursesWidget const&) = delete; + cmCursesWidget& operator=(cmCursesWidget const&) = delete; + /** * Handle user input. Called by the container of this widget * when this widget has focus. Returns true if the input was diff --git a/Source/CursesDialog/form/.gitattributes b/Source/CursesDialog/form/.gitattributes index 62d728cf6..12ede74cd 100644 --- a/Source/CursesDialog/form/.gitattributes +++ b/Source/CursesDialog/form/.gitattributes @@ -1 +1 @@ -* -format.clang-format +* -format.clang-format-6.0 diff --git a/Source/CursesDialog/form/CMakeLists.txt b/Source/CursesDialog/form/CMakeLists.txt index 0677043a9..b468f5b31 100644 --- a/Source/CursesDialog/form/CMakeLists.txt +++ b/Source/CursesDialog/form/CMakeLists.txt @@ -3,12 +3,9 @@ project(CMAKE_FORM) -include_regular_expression("^.*$") -include_directories(${CURSES_INCLUDE_PATH} "${CMAKE_CURRENT_BINARY_DIR}") - configure_file(cmFormConfigure.h.in "${CMAKE_CURRENT_BINARY_DIR}/cmFormConfigure.h") -set( FORM_SRCS +add_library(cmForm fld_arg.c fld_attr.c fld_current.c @@ -49,10 +46,16 @@ set( FORM_SRCS fty_num.c fty_regex.c ) - -include_directories(${CMAKE_FORM_SOURCE_DIR}) -add_library(cmForm ${FORM_SRCS} ) + +target_include_directories(cmForm + PUBLIC + ${CURSES_INCLUDE_PATH} + ${CMAKE_FORM_BINARY_DIR} + ${CMAKE_FORM_SOURCE_DIR} + ) + target_link_libraries(cmForm ${CURSES_LIBRARY}) + if(CURSES_EXTRA_LIBRARY) target_link_libraries(cmForm ${CURSES_EXTRA_LIBRARY}) endif() diff --git a/Source/CursesDialog/form/frm_post.c b/Source/CursesDialog/form/frm_post.c index 924fe6a9e..fc0a35946 100644 --- a/Source/CursesDialog/form/frm_post.c +++ b/Source/CursesDialog/form/frm_post.c @@ -67,7 +67,7 @@ int post_form(FORM * form) if ((form->cols > width) || (form->rows > height)) RETURN(E_NO_ROOM); - /* reset form->curpage to an invald value. This forces Set_Form_Page + /* reset form->curpage to an invalid value. This forces Set_Form_Page to do the page initialization which is required by post_form. */ page = form->curpage; |