From 7facbe215e9d318adc32fab793e05364c4b4d7ea Mon Sep 17 00:00:00 2001 From: "Evgeniy A. Dushistov" Date: Fri, 14 Aug 2020 12:36:02 +0300 Subject: [PATCH 1/4] refactoring: run clang-format against code --- src/libwrapper.cpp | 6 +++--- src/libwrapper.hpp | 6 +++--- src/readline.cpp | 6 +++--- src/sdcv.cpp | 9 +++++---- src/stardict_lib.cpp | 4 ++-- src/utils.hpp | 2 +- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/libwrapper.cpp b/src/libwrapper.cpp index b852e7f..f900edc 100644 --- a/src/libwrapper.cpp +++ b/src/libwrapper.cpp @@ -314,7 +314,7 @@ public: private: FILE *output; }; -} +} // namespace search_result Library::process_phrase(const char *loc_str, IReadLine &io, bool force) { @@ -330,7 +330,7 @@ search_result Library::process_phrase(const char *loc_str, IReadLine &io, bool f gsize bytes_read; gsize bytes_written; glib::Error err; - search_result rval = SEARCH_SUCCESS; + search_result rval = SEARCH_SUCCESS; glib::CharStr str; if (!utf8_input_) str.reset(g_locale_to_utf8(loc_str, -1, &bytes_read, &bytes_written, get_addr(err))); @@ -444,7 +444,7 @@ search_result Library::process_phrase(const char *loc_str, IReadLine &io, bool f loc_str = utf8_to_locale_ign_err(get_impl(str)); if (!json_) printf(_("Nothing similar to %s, sorry :(\n"), utf8_output_ ? get_impl(str) : loc_str.c_str()); - rval = SEARCH_NO_RESULT; + rval = SEARCH_NO_RESULT; } if (json_) { diff --git a/src/libwrapper.hpp b/src/libwrapper.hpp index 154161b..f9496da 100644 --- a/src/libwrapper.hpp +++ b/src/libwrapper.hpp @@ -25,9 +25,9 @@ typedef std::vector TSearchResultList; //possible return values for Library.process_phase() enum search_result { - SEARCH_SUCCESS = 0, - SEARCH_FAILURE, - SEARCH_NO_RESULT + SEARCH_SUCCESS = 0, + SEARCH_FAILURE, + SEARCH_NO_RESULT }; //this class is wrapper around Dicts class for easy use diff --git a/src/readline.cpp b/src/readline.cpp index 2204c17..60a01e8 100644 --- a/src/readline.cpp +++ b/src/readline.cpp @@ -57,7 +57,7 @@ public: return stdio_getline(stdin, line); } }; -} +} // namespace #else namespace @@ -72,7 +72,7 @@ std::string get_hist_file_path() const std::string hist_file_path = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history"; if (g_file_test(hist_file_path.c_str(), G_FILE_TEST_IS_REGULAR)) return hist_file_path; - + return std::string(g_get_user_data_dir()) + G_DIR_SEPARATOR + "sdcv_history"; } @@ -116,7 +116,7 @@ public: add_history(phrase.c_str()); } }; -} +} // namespace #endif //WITH_READLINE IReadLine *create_readline_object() diff --git a/src/sdcv.cpp b/src/sdcv.cpp index 16466ad..ca222b8 100644 --- a/src/sdcv.cpp +++ b/src/sdcv.cpp @@ -53,7 +53,7 @@ static void free_str_array(gchar **arr) g_free(*p); g_free(arr); } -} +} // namespace namespace glib { using StrArr = ResourceWrapper; @@ -61,13 +61,14 @@ using StrArr = ResourceWrapper; static void list_dicts(const std::list &dicts_dir_list, bool use_json); -int main(int argc, char *argv[]) try { +int main(int argc, char *argv[]) +try { setlocale(LC_ALL, ""); #if ENABLE_NLS bindtextdomain("sdcv", //"./locale"//< for testing GETTEXT_TRANSLATIONS_PATH //< should be - ); + ); textdomain("sdcv"); #endif @@ -210,7 +211,7 @@ int main(int argc, char *argv[]) try { std::unique_ptr io(create_readline_object()); if (optind < argc) { - search_result rval = SEARCH_SUCCESS; + search_result rval = SEARCH_SUCCESS; for (int i = optind; i < argc; ++i) if ((rval = lib.process_phrase(argv[i], *io, non_interactive)) != SEARCH_SUCCESS) { return rval; diff --git a/src/stardict_lib.cpp b/src/stardict_lib.cpp index a911ddd..18e957b 100644 --- a/src/stardict_lib.cpp +++ b/src/stardict_lib.cpp @@ -71,7 +71,7 @@ static void unicode_strdown(gunichar *str) ++str; } } -} +} // namespace bool DictInfo::load_from_ifo_file(const std::string &ifofilename, bool istreedict) @@ -826,7 +826,7 @@ bool WordListIndex::lookup(const char *str, glong &idx) } return bFound; } -} +} // namespace bool SynFile::load(const std::string &url, gulong wc) { diff --git a/src/utils.hpp b/src/utils.hpp index 1081fd3..d6f112b 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -68,7 +68,7 @@ namespace glib { typedef ResourceWrapper CharStr; typedef ResourceWrapper Error; -} +} // namespace glib extern std::string utf8_to_locale_ign_err(const std::string &utf8_str); From 431a5774ba30f86cde47cee7cfb7b3deb6478fe0 Mon Sep 17 00:00:00 2001 From: "Evgeniy A. Dushistov" Date: Fri, 14 Aug 2020 12:37:21 +0300 Subject: [PATCH 2/4] fix warning --- src/stardict_lib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stardict_lib.cpp b/src/stardict_lib.cpp index 18e957b..6acb0fc 100644 --- a/src/stardict_lib.cpp +++ b/src/stardict_lib.cpp @@ -758,7 +758,7 @@ bool OffsetIndex::lookup(const char *str, glong &idx) return bFound; } -bool WordListIndex::load(const std::string &url, gulong wc, gulong fsize, bool verbose) +bool WordListIndex::load(const std::string &url, gulong wc, gulong fsize, bool) { gzFile in = gzopen(url.c_str(), "rb"); if (in == nullptr) From 824764ab507ca049e9567d90e9f0b931f7fe6145 Mon Sep 17 00:00:00 2001 From: "Evgeniy A. Dushistov" Date: Fri, 14 Aug 2020 12:46:42 +0300 Subject: [PATCH 3/4] handle possibly invalid data: origin_data == nullptr --- src/stardict_lib.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/stardict_lib.cpp b/src/stardict_lib.cpp index 6acb0fc..0af4304 100644 --- a/src/stardict_lib.cpp +++ b/src/stardict_lib.cpp @@ -334,6 +334,7 @@ bool DictBase::SearchData(std::vector &SearchWords, guint32 idxitem if (dictfile) fseek(dictfile, idxitem_offset, SEEK_SET); + THROW_IF_ERROR(origin_data != nullptr); if (dictfile) { const size_t nitems = fread(origin_data, idxitem_size, 1, dictfile); THROW_IF_ERROR(nitems == 1); From 0836551bb4b30488bdf5e2d061137338e12aa6ef Mon Sep 17 00:00:00 2001 From: "Evgeniy A. Dushistov" Date: Fri, 14 Aug 2020 12:52:37 +0300 Subject: [PATCH 4/4] require cmake at least 3.5, and glib 2.36 this should be fine to support ubuntu 16.04 lts --- CMakeLists.txt | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5077c4a..615d728 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,24 +1,14 @@ project(sdcv) -# Older versions have a different signature for CMAKE_MINIMUM_REQUIRED, -# check it manually just to make sure -if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.8) - message(FATAL_ERROR "${PROJECT_NAME} requires at least CMake v2.8." - " You are running v${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}." - " Please upgrade." ) -endif(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.8) - -# If we get this far, use the modern signature. This will also cause newer -# CMake versions to try to be backwards-compatible with the desired version -cmake_minimum_required(VERSION 2.8 FATAL_ERROR) -cmake_policy(VERSION 2.8) +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +cmake_policy(VERSION 3.5) include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/compiler.cmake") set(ZLIB_FIND_REQUIRED True) include(FindZLIB) -set(GLIB2_REQ "'glib-2.0 >= 2.6.1'") +set(GLIB2_REQ "'glib-2.0 >= 2.36'") set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindGLIB2.cmake")