From 37f62a7f9e131f9a49e1494217cbbdcd8efeeebb Mon Sep 17 00:00:00 2001 From: magiblot Date: Sat, 10 Jun 2023 12:06:52 +0200 Subject: [PATCH] Drop fmt dependency --- CMakeLists.txt | 4 ---- deps/CMakeLists.txt | 6 ------ deps/fmt | 1 - source/turbo-core/editstates.cc | 5 ++--- source/turbo-core/fileeditor.cc | 15 ++++++++++----- source/turbo/app.cc | 2 -- source/turbo/editor.cc | 5 ++--- source/turbo/editwindow.cc | 14 +++++++++----- test/test.cc | 6 ++++-- 9 files changed, 27 insertions(+), 31 deletions(-) delete mode 160000 deps/fmt diff --git a/CMakeLists.txt b/CMakeLists.txt index 07ec2d2..7afe4df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required (VERSION 3.5) option(TURBO_BUILD_APP "Build main editor application" ON) option(TURBO_BUILD_TESTS "Build and run tests" OFF) option(TURBO_BUILD_EXAMPLES "Build example apps" OFF) -option(TURBO_USE_SYSTEM_DEPS "Use system-wide dependencies instead of submodules (except Turbo Vision)" OFF) option(TURBO_USE_SYSTEM_TVISION "Use system-wide Turbo Vision instead of the submodule" OFF) option(TURBO_USE_STATIC_RTL "Link against the static version of the runtime library (MSVC only)" OFF) option(TURBO_OPTIMIZE_BUILD "Use Precompiled Headers and Unity Build for the core library" ON) @@ -107,11 +106,9 @@ target_include_directories(${TURBO}-core PRIVATE ) target_link_libraries(${TURBO}-core PUBLIC tvision - fmt ) if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13.0") - install(TARGETS fmt EXPORT ${TURBO}-config) install(TARGETS ${TURBO}-core EXPORT ${TURBO}-config ARCHIVE DESTINATION lib @@ -175,7 +172,6 @@ if (TURBO_BUILD_TESTS) find_library(GTEST_MAIN gtest_main REQUIRED) target_link_libraries(${TURBO}-test PRIVATE ${TURBO}-core - fmt ${GTEST} ${GTEST_MAIN} ) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 1c81604..921bf73 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -18,12 +18,6 @@ function(turbo_find_library name header) target_include_directories(${name} INTERFACE ${${name}_INCLUDE}) endfunction() -if (TURBO_USE_SYSTEM_DEPS) - turbo_find_library(fmt "fmt/core.h") -else() - add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/fmt" EXCLUDE_FROM_ALL) -endif() - set(TV_OPTIMIZE_BUILD ${TURBO_OPTIMIZE_BUILD}) if (TURBO_USE_SYSTEM_TVISION) find_package(tvision CONFIG REQUIRED) diff --git a/deps/fmt b/deps/fmt deleted file mode 160000 index b6f4cea..0000000 --- a/deps/fmt +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b6f4ceaed0a0a24ccf575fab6c56dd50ccf6f1a9 diff --git a/source/turbo-core/editstates.cc b/source/turbo-core/editstates.cc index c6e5e8a..e366c33 100644 --- a/source/turbo-core/editstates.cc +++ b/source/turbo-core/editstates.cc @@ -1,7 +1,6 @@ #define Uses_MsgBox #include -#include #include #include #include @@ -61,8 +60,8 @@ void WrapState::setState(bool enable, TScintilla &scintilla, TFuncView #include -#include #include #include +#include #include #include #include @@ -342,8 +342,12 @@ static bool canOverwrite(FileDialogs &dlgs, const char *path) noexcept void ShowAllDialogs::getSaveAsPath(FileEditor &editor, TFuncView accept) noexcept { char path[MAXPATH]; - auto &&title = editor.filePath.empty() ? "Save untitled file" : fmt::format("Save file '{}' as", TPath::basename(editor.filePath)); - openFileDialog("*.*", title, "~N~ame", fdOKButton, 0, [&] (TView *dialog) { + std::ostringstream os; + if (editor.filePath.empty()) + os << "Save untitled file"; + else + os << "Save file '" << TPath::basename(editor.filePath) << "' as"; + openFileDialog("*.*", os.str(), "~N~ame", fdOKButton, 0, [&] (TView *dialog) { dialog->getData(path); fexpand(path); return canOverwrite(*this, path) && accept(path); @@ -353,8 +357,9 @@ void ShowAllDialogs::getSaveAsPath(FileEditor &editor, TFuncView accept) noexcept { char path[MAXPATH]; - auto &&title = fmt::format("Rename file '{}'", TPath::basename(editor.filePath)); - openFileDialog("*.*", title, "~N~ame", fdOKButton, 0, [&] (TView *dialog) { + std::ostringstream os; + os << "Rename file '" << TPath::basename(editor.filePath) << "'"; + openFileDialog("*.*", os.str(), "~N~ame", fdOKButton, 0, [&] (TView *dialog) { dialog->getData(path); fexpand(path); // Don't do anything if renaming to the same file. If the user needed to diff --git a/source/turbo/app.cc b/source/turbo/app.cc index e35111b..cd71f23 100644 --- a/source/turbo/app.cc +++ b/source/turbo/app.cc @@ -16,8 +16,6 @@ #define Uses_TScreen #include -#include - #include "app.h" #include "apputils.h" #include "editwindow.h" diff --git a/source/turbo/editor.cc b/source/turbo/editor.cc index 454b3ad..52c2051 100644 --- a/source/turbo/editor.cc +++ b/source/turbo/editor.cc @@ -4,8 +4,6 @@ #include "editor.h" #include "editwindow.h" -#include - void TurboEditor::onFilePathSet() noexcept { bool noLastLanguage = !language; @@ -19,7 +17,8 @@ ushort TurboFileDialogs::confirmSaveUntitled(turbo::FileEditor &editor) noexcept if (auto *window = (EditorWindow *) editor.parent) { auto *title = window->formatTitle(EditorWindow::tfNoSavePoint); - return messageBox(fmt::format("Save '{}'?", title), mfConfirmation | mfYesNoCancel); + return messageBox( mfConfirmation | mfYesNoCancel, + "Save '%s'?", title ); } return super::confirmSaveUntitled(editor); } diff --git a/source/turbo/editwindow.cc b/source/turbo/editwindow.cc index c1e6bac..bba00ca 100644 --- a/source/turbo/editwindow.cc +++ b/source/turbo/editwindow.cc @@ -12,8 +12,8 @@ #include "apputils.h" #include "search.h" #include "gotoline.h" -#include #include +#include using std::ios; EditorWindow::EditorWindow( const TRect &bounds, TurboEditor &aEditor, @@ -279,10 +279,14 @@ const char* EditorWindow::formatTitle(ushort flags) noexcept if (lastTitleState != titleState) { lastTitleState = titleState; - TStringView name = !filePath().empty() ? TPath::basename(filePath()) : "Untitled"; - auto &&number = fileNumber.number > 1 ? fmt::format(" ({})", fileNumber.number) : std::string(); - TStringView savePoint = inSavePoint ? "" : "*"; - title = fmt::format("{}{}{}", name, number, savePoint); + TStringView name = filePath().empty() ? "Untitled" : TPath::basename(filePath()); + std::ostringstream os; + os << name; + if (fileNumber.number > 1) + os << " (" << fileNumber.number << ')'; + if (!inSavePoint) + os << '*'; + title = os.str(); } return title.c_str(); } diff --git a/test/test.cc b/test/test.cc index 7a32c84..c0a147a 100644 --- a/test/test.cc +++ b/test/test.cc @@ -1,7 +1,7 @@ #include -#include #include +#include namespace turbo { @@ -10,7 +10,9 @@ TextState TextState::decode(std::string_view input) { size_t caret = input.find(chCaret); if (caret == std::string_view::npos) - throw std::runtime_error(fmt::format("Input text does not have a caret: '{}'", input)); + throw std::runtime_error((std::ostringstream() + << "Input text does not have a caret: '" << input << "'" + ).str()); size_t anchor = input.find(chAnchor); if (anchor == std::string_view::npos) anchor = caret;