11 Commits

Author SHA1 Message Date
Evgeniy A. Dushistov
eeee360fb0 t_json: add data about new dictionary 2022-06-24 21:33:33 +03:00
Evgeniy A. Dushistov
f69973e1fa fix bash syntax error 2022-06-24 21:26:10 +03:00
Evgeniy A. Dushistov
931fc98478 check file size before mapping on linux 2022-06-24 21:25:55 +03:00
Evgeniy A. Dushistov
6f30be7815 clang-format for mapfile 2022-06-24 21:24:03 +03:00
Evgeniy A. Dushistov
1a926d1b69 version 0.5.4 2022-06-24 20:57:57 +03:00
Evgeniy A. Dushistov
e89cfa18b1 Revert "replace deprecated g_pattern_match_string function"
This reverts commit 452a4e07fb.
2022-06-24 20:57:57 +03:00
Evgeniy A. Dushistov
12d9ea5b97 more robust parsing of ifo file
fixes #79 fixes #81
2022-06-24 20:54:30 +03:00
Evgeniy A. Dushistov
920c2bafb9 stardict_lib.hpp: remove unused headers plus clang-format 2022-06-24 20:53:53 +03:00
Evgeniy A. Dushistov
5d2332b0cb use cmake to check if compiler supports c++11 2022-06-24 20:10:43 +03:00
Evgeniy A. Dushistov
452a4e07fb replace deprecated g_pattern_match_string function 2022-06-24 20:06:54 +03:00
Evgeniy A. Dushistov
59ef936288 clang-format for stardict_lib.cpp 2022-06-24 20:03:45 +03:00
11 changed files with 51 additions and 248 deletions

View File

@@ -20,12 +20,14 @@ jobs:
fail-fast: true fail-fast: true
matrix: matrix:
os: [ubuntu-22.04, ubuntu-latest] os: [ubuntu-latest]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v2
- uses: jwlawson/actions-setup-cmake@v2
with: with:
cmake-version: '3.10' submodules: 'recursive'
- uses: jwlawson/actions-setup-cmake@v1.4
with:
cmake-version: '3.5.1'
github-api-token: ${{ secrets.GITHUB_TOKEN }} github-api-token: ${{ secrets.GITHUB_TOKEN }}
- name: Check versions - name: Check versions
run: | run: |
@@ -34,10 +36,6 @@ jobs:
gcc --version gcc --version
echo "end of versions checking" echo "end of versions checking"
shell: bash shell: bash
- uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: libglib2.0-dev
version: 1.0
- name: Run tests - name: Run tests
run: | run: |
set -e set -e

View File

@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
cmake_policy(VERSION 3.10)
project(sdcv) project(sdcv)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
cmake_policy(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS False) set(CMAKE_CXX_EXTENSIONS False)
@@ -27,8 +27,7 @@ if (WITH_READLINE)
find_path(READLINE_INCLUDE_DIR readline/readline.h) find_path(READLINE_INCLUDE_DIR readline/readline.h)
find_library(READLINE_LIBRARY NAMES readline) find_library(READLINE_LIBRARY NAMES readline)
if (NOT (READLINE_INCLUDE_DIR AND READLINE_LIBRARY)) if (NOT (READLINE_INCLUDE_DIR AND READLINE_LIBRARY))
message(STATUS "readline library not FOUND, disable it's usage") set(WITH_READLINE False CACHE FORCE)
set(WITH_READLINE False CACHE BOOL "Use readline library" FORCE)
endif () endif ()
endif (WITH_READLINE) endif (WITH_READLINE)
@@ -38,16 +37,16 @@ set(sdcv_SRCS
src/sdcv.cpp src/sdcv.cpp
src/readline.cpp src/readline.cpp
src/readline.hpp src/readline.hpp
src/libwrapper.cpp src/libwrapper.cpp
src/libwrapper.hpp src/libwrapper.hpp
src/utils.cpp src/utils.cpp
src/utils.hpp src/utils.hpp
src/stardict_lib.cpp src/stardict_lib.cpp
src/stardict_lib.hpp src/stardict_lib.hpp
src/dictziplib.cpp src/dictziplib.cpp
src/dictziplib.hpp src/dictziplib.hpp
src/distance.cpp src/distance.cpp
src/distance.hpp src/distance.hpp
src/mapfile.hpp src/mapfile.hpp
) )
@@ -83,13 +82,10 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake
include_directories( include_directories(
${ZLIB_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR}
${GLIB2_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS}
${READLINE_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/src/lib ${CMAKE_CURRENT_SOURCE_DIR}/src/lib
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
) )
if (WITH_READLINE)
include_directories(${READLINE_INCLUDE_DIR})
endif()
# #
# Packing stuff # Packing stuff
@@ -99,7 +95,7 @@ set(CPACK_PACKAGE_VENDOR "Evgeniy Dushistov <dushistov@mail.ru>")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.org") set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.org")
set(CPACK_PACKAGE_VERSION_MAJOR "0") set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "5") set(CPACK_PACKAGE_VERSION_MINOR "5")
set(CPACK_PACKAGE_VERSION_PATCH "5") set(CPACK_PACKAGE_VERSION_PATCH "4")
set(sdcv_VERSION set(sdcv_VERSION
"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
@@ -111,10 +107,8 @@ add_executable(sdcv ${sdcv_SRCS})
target_link_libraries(sdcv target_link_libraries(sdcv
${GLIB2_LIBRARIES} ${GLIB2_LIBRARIES}
${ZLIB_LIBRARIES} ${ZLIB_LIBRARIES}
${READLINE_LIBRARY}
) )
if (WITH_READLINE)
target_link_libraries(sdcv ${READLINE_LIBRARY})
endif()
if (ENABLE_NLS) if (ENABLE_NLS)
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "locale") set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "locale")
endif () endif ()

12
NEWS
View File

@@ -1,13 +1,3 @@
Version 0.5.5
- Avoid crashes when passing unknown dicts to the -u flag (by NiLuJe)
- Use off_t for stuff mainly assigned to a stat.st_size value
Version 0.5.4
- Use binary search for synonyms
- Various improvments in work with synonyms
- Added --json (same as --json-output) to match man
- Show all matched result
- More robust parsing of ifo file
- Prevent crash if file size of files not matched expecting one for .oft files
Version 0.5.3 Version 0.5.3
- Use single quotes around JSON data to reduce need for escaping - Use single quotes around JSON data to reduce need for escaping
- Store integer magic in cache file - Store integer magic in cache file
@@ -46,7 +36,7 @@ Version 0.4.2
* Russian translation update * Russian translation update
Version 0.4.1 Version 0.4.1
* Recreate cache if idx file was modified * Recreate cache if idx file was modified
* Abbility to use pager(SDCV_PAGER) * Abbility to use pager(SDCV_PAGER)
* Add Chinese (traditional) translation * Add Chinese (traditional) translation
* Add Ukrainian translation * Add Ukrainian translation

View File

@@ -1,9 +1,6 @@
#+OPTIONS: ^:nil #+OPTIONS: ^:nil
[[https://github.com/Dushistov/sdcv/actions?query=workflow%3ACI+branch%3Amaster][https://github.com/Dushistov/sdcv/workflows/CI/badge.svg]] [[https://github.com/Dushistov/sdcv/actions?query=workflow%3ACI+branch%3Amaster][https://github.com/Dushistov/sdcv/workflows/CI/badge.svg]]
[[https://github.com/Dushistov/sdcv/blob/master/LICENSE][https://img.shields.io/badge/license-GPL%202-brightgreen.svg]] [[https://github.com/Dushistov/sdcv/blob/master/LICENSE][https://img.shields.io/badge/license-GPL%202-brightgreen.svg]]
* sdcv
*sdcv* is a simple, cross-platform, text-based utility for working with dictionaries in [[http://stardict-4.sourceforge.net/][StarDict]] format.
* How to compile and install * How to compile and install
#+BEGIN_SRC sh #+BEGIN_SRC sh
mkdir /tmp/build-sdcv mkdir /tmp/build-sdcv
@@ -29,26 +26,6 @@ To report bugs use https://github.com/Dushistov/sdcv/issues ,
if it is not possible you can report it via email to dushistov at mail dot ru. if it is not possible you can report it via email to dushistov at mail dot ru.
Be sure to include the word "sdcv" somewhere in the "Subject:" field. Be sure to include the word "sdcv" somewhere in the "Subject:" field.
* Integration with [[https://github.com/junegunn/fzf][fzf]]
Useful when you have multiple dictionaries
#+BEGIN_SRC sh
fzf --prompt="Dict: " \
--phony \
--bind "enter:reload(sdcv {q} -n --json | jq '.[].dict' -r)" \
--preview "sdcv {q} -en --use-dict={}" \
--preview-window=right:70%:wrap \
< <(echo)
#+END_SRC
* Integration with readline
This lines can be added to inputrc file (~/.inputrc, /etc/inputrc),
to abort multiply usage with ESC:
#+begin_src
$if sdcv
"\e\e": "-1\n"
$endif
#+end_src
* Notes to developer * Notes to developer
** make source code release ** make source code release
#+BEGIN_SRC sh #+BEGIN_SRC sh

147
po/ka.po
View File

@@ -1,147 +0,0 @@
# Georgian translation for sdcv.
# Copyright (C) 2025 sdcv authors
# This file is distributed under the same license as the sdcv project.
# Temuri Doghonadze <temuri.doghonadze@gmail.com>, 2025.
#
msgid ""
msgstr ""
"Project-Id-Version: sdcv 0.5\n"
"Report-Msgid-Bugs-To: dushistov@mail.ru\n"
"POT-Creation-Date: 2020-08-14 12:58+0300\n"
"PO-Revision-Date: 2025-01-26 03:17+0100\n"
"Last-Translator: Temuri Doghonadze <temuri.doghonadze@gmail.com>\n"
"Language-Team: Georgian <(nothing)>\n"
"Language: ka\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.5\n"
#: ../src/libwrapper.cpp:300
msgid "popen failed"
msgstr "popen ჩავარდა"
#: ../src/libwrapper.cpp:341
#, c-format
msgid "Can not convert %s to utf8.\n"
msgstr "%s-ის utf8-ში გადაყვანა შეუძლებელია.\n"
#: ../src/libwrapper.cpp:399 ../src/libwrapper.cpp:433
#, c-format
msgid "Found %zu items, similar to %s.\n"
msgstr "აღმოჩენილია %zu ელემენტი, რომელიც %s-ს ჰგავს.\n"
#: ../src/libwrapper.cpp:417
msgid "Your choice[-1 to abort]: "
msgstr "თქვენი არჩევანი[-1 გასაუქმებლად]: "
#: ../src/libwrapper.cpp:427
#, c-format
msgid ""
"Invalid choice.\n"
"It must be from 0 to %zu or -1.\n"
msgstr ""
"არასწორი არჩევანი.\n"
"უნდა იყოს 0-დან %zu-მდე, ან -1.\n"
#: ../src/libwrapper.cpp:446
#, c-format
msgid "Nothing similar to %s, sorry :(\n"
msgstr "%s-ს არაფერი ჰგავს :(\n"
#: ../src/sdcv.cpp:89
msgid "display version information and exit"
msgstr "ვერსიის ჩვენება და გასვლა"
#: ../src/sdcv.cpp:91
msgid "display list of available dictionaries and exit"
msgstr "ხელმისაწვდომი ლექსიკონების ჩვენება და გასვლა"
#: ../src/sdcv.cpp:93
msgid "for search use only dictionary with this bookname"
msgstr "ძებნისთვის, მხოლოდ, ამ სახელის მქონე ლექსიკონის გამოყენება"
#: ../src/sdcv.cpp:94
msgid "bookname"
msgstr "ლექსიკონის_სახელი"
#: ../src/sdcv.cpp:96
msgid "for use in scripts"
msgstr "სკრიპტებში გამოსაყენებლად"
#: ../src/sdcv.cpp:98
msgid "print the result formatted as JSON"
msgstr "შედეგების JSON ფორმატში გამოტანა"
#: ../src/sdcv.cpp:100
msgid "do not fuzzy-search for similar words, only return exact matches"
msgstr ""
"მსგავსი სიტყვებისთვის არაზუსტი ძებნა გამოყენებული არ იქნება. "
"დაბრუნდება, მხოლოდ, ზუსტი დამთხვევები"
#: ../src/sdcv.cpp:102
msgid "output must be in utf8"
msgstr "გამოტანა utf8-ში უნდა იყოს"
#: ../src/sdcv.cpp:104
msgid "input of sdcv in utf8"
msgstr "პროგრამაში შეყვანა utf8 -ში"
#: ../src/sdcv.cpp:106
msgid "use this directory as path to stardict data directory"
msgstr ""
"ამ საქაღალდის გამოყენება stardict-ის მონაცემების საქაღალდის ბილიკად"
#: ../src/sdcv.cpp:107
msgid "path/to/dir"
msgstr "ბილიკი/სასურველ/საქაღალდემდე"
#: ../src/sdcv.cpp:109
msgid ""
"only use the dictionaries in data-dir, do not search in user and system "
"directories"
msgstr ""
"ლექსიკონების, მხოლოდ, data-dir-დან გამოყენება. მომხმარებლის და სისტემურ "
"საქაღალდეებში ძებნა არ მოხდება"
#: ../src/sdcv.cpp:111
msgid "colorize the output"
msgstr "ფერებში გამოტანა"
#: ../src/sdcv.cpp:116
msgid " words"
msgstr " სიტყვა"
#: ../src/sdcv.cpp:122
#, c-format
msgid "Invalid command line arguments: %s\n"
msgstr "არასწორი ბრძანების სტრიქონის არგუმენტები: %s\n"
#: ../src/sdcv.cpp:128
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr "Startdict-ის კონსოლის ვერსია. ვერსია %s\n"
#: ../src/sdcv.cpp:206
#, c-format
msgid "g_mkdir failed: %s\n"
msgstr "g_mkdir ჩავარდა: %s\n"
#: ../src/sdcv.cpp:222
msgid "Enter word or phrase: "
msgstr "შეიყვანეთ სიტყვა ან ფრაზა: "
#: ../src/sdcv.cpp:230
#, c-format
msgid "There are no words/phrases to translate.\n"
msgstr "სათარგმნი სიტყვების/ფრაზების გარეშე.\n"
#: ../src/sdcv.cpp:242
#, c-format
msgid "Dictionary's name Word count\n"
msgstr "ლექსიკონის სახელი სიტყვების რაოდენობა\n"
#: ../src/utils.cpp:48
#, c-format
msgid "Can not convert %s to current locale.\n"
msgstr "ვერ გადავიყვანე %s მიმდინარე ლოკალში.\n"

View File

@@ -27,7 +27,7 @@ public:
private: private:
const char *start; /* start of mmap'd area */ const char *start; /* start of mmap'd area */
const char *end; /* end of mmap'd area */ const char *end; /* end of mmap'd area */
off_t size; /* size of mmap */ unsigned long size; /* size of mmap */
int type; int type;
z_stream zStream; z_stream zStream;
@@ -47,7 +47,7 @@ private:
std::string origFilename; std::string origFilename;
std::string comment; std::string comment;
unsigned long crc; unsigned long crc;
off_t length; unsigned long length;
unsigned long compressedLength; unsigned long compressedLength;
DictCache cache[DICT_CACHE_SIZE]; DictCache cache[DICT_CACHE_SIZE];
MapFile mapfile; MapFile mapfile;

View File

@@ -23,7 +23,6 @@
#endif #endif
#include <cstring> #include <cstring>
#include <cstdio> //for popen
#include <map> #include <map>
#include <memory> #include <memory>
@@ -416,9 +415,10 @@ search_result Library::process_phrase(const char *loc_str, IReadLine &io, bool f
colorize_output_ ? ESC_END : ""); colorize_output_ ? ESC_END : "");
} }
int choise; int choise;
std::unique_ptr<IReadLine> choice_readline(create_readline_object());
for (;;) { for (;;) {
std::string str_choise; std::string str_choise;
io.read(_("Your choice[-1 to abort]: "), str_choise); choice_readline->read(_("Your choice[-1 to abort]: "), str_choise);
sscanf(str_choise.c_str(), "%d", &choise); sscanf(str_choise.c_str(), "%d", &choise);
if (choise >= 0 && choise < int(res_list.size())) { if (choise >= 0 && choise < int(res_list.size())) {
sdcv_pager pager; sdcv_pager pager;

View File

@@ -22,13 +22,13 @@ public:
~MapFile(); ~MapFile();
MapFile(const MapFile &) = delete; MapFile(const MapFile &) = delete;
MapFile &operator=(const MapFile &) = delete; MapFile &operator=(const MapFile &) = delete;
bool open(const char *file_name, off_t file_size); bool open(const char *file_name, unsigned long file_size);
gchar *begin() { return data; } gchar *begin() { return data; }
private: private:
char *data = nullptr; char *data = nullptr;
unsigned long size = 0ul;
#ifdef HAVE_MMAP #ifdef HAVE_MMAP
size_t size = 0u;
int mmap_fd = -1; int mmap_fd = -1;
#elif defined(_WIN32) #elif defined(_WIN32)
HANDLE hFile = 0; HANDLE hFile = 0;
@@ -36,8 +36,9 @@ private:
#endif #endif
}; };
inline bool MapFile::open(const char *file_name, off_t file_size) inline bool MapFile::open(const char *file_name, unsigned long file_size)
{ {
size = file_size;
#ifdef HAVE_MMAP #ifdef HAVE_MMAP
if ((mmap_fd = ::open(file_name, O_RDONLY)) < 0) { if ((mmap_fd = ::open(file_name, O_RDONLY)) < 0) {
// g_print("Open file %s failed!\n",fullfilename); // g_print("Open file %s failed!\n",fullfilename);
@@ -45,16 +46,14 @@ inline bool MapFile::open(const char *file_name, off_t file_size)
} }
struct stat st; struct stat st;
if (fstat(mmap_fd, &st) == -1 || st.st_size < 0 || (st.st_size == 0 && S_ISREG(st.st_mode)) if (fstat(mmap_fd, &st) == -1 || st.st_size < 0 || (st.st_size == 0 && S_ISREG(st.st_mode))
|| st.st_size != file_size) { || sizeof(st.st_size) > sizeof(file_size) || static_cast<unsigned long>(st.st_size) != file_size) {
close(mmap_fd); close(mmap_fd);
return false; return false;
} }
size = static_cast<size_t>(st.st_size); data = (gchar *)mmap(nullptr, file_size, PROT_READ, MAP_SHARED, mmap_fd, 0);
data = (gchar *)mmap(nullptr, size, PROT_READ, MAP_SHARED, mmap_fd, 0);
if ((void *)data == (void *)(-1)) { if ((void *)data == (void *)(-1)) {
// g_print("mmap file %s failed!\n",idxfilename); // g_print("mmap file %s failed!\n",idxfilename);
size = 0u;
data = nullptr; data = nullptr;
return false; return false;
} }

View File

@@ -186,13 +186,10 @@ try {
} }
// add bookname to list // add bookname to list
for (gchar **p = get_impl(use_dict_list); *p != nullptr; ++p) { gchar **p = get_impl(use_dict_list);
auto it = bookname_to_ifo.find(*p); while (*p) {
if (it != bookname_to_ifo.end()) { order_list.push_back(bookname_to_ifo.at(*p));
order_list.push_back(it->second); ++p;
} else {
fprintf(stderr, _("Unknown dictionary: %s\n"), *p);
}
} }
} else { } else {
std::string ordering_cfg_file = std::string(g_get_user_config_dir()) + G_DIR_SEPARATOR_S "sdcv_ordering"; std::string ordering_cfg_file = std::string(g_get_user_config_dir()) + G_DIR_SEPARATOR_S "sdcv_ordering";
@@ -204,12 +201,7 @@ try {
if (ordering_file != nullptr) { if (ordering_file != nullptr) {
std::string line; std::string line;
while (stdio_getline(ordering_file, line)) { while (stdio_getline(ordering_file, line)) {
auto it = bookname_to_ifo.find(line); order_list.push_back(bookname_to_ifo.at(line));
if (it != bookname_to_ifo.end()) {
order_list.push_back(it->second);
} else {
fprintf(stderr, _("Unknown dictionary: %s\n"), line.c_str());
}
} }
fclose(ordering_file); fclose(ordering_file);
} }

View File

@@ -429,7 +429,7 @@ public:
if (idxfile) if (idxfile)
fclose(idxfile); fclose(idxfile);
} }
bool load(const std::string &url, gulong wc, off_t fsize, bool verbose) override; bool load(const std::string &url, gulong wc, gulong fsize, bool verbose) override;
const gchar *get_key(glong idx) override; const gchar *get_key(glong idx) override;
void get_data(glong idx) override { get_key(idx); } void get_data(glong idx) override { get_key(idx); }
const gchar *get_key_and_data(glong idx) override const gchar *get_key_and_data(glong idx) override
@@ -489,7 +489,7 @@ public:
{ {
} }
~WordListIndex() { g_free(idxdatabuf); } ~WordListIndex() { g_free(idxdatabuf); }
bool load(const std::string &url, gulong wc, off_t fsize, bool verbose) override; bool load(const std::string &url, gulong wc, gulong fsize, bool verbose) override;
const gchar *get_key(glong idx) override { return wordlist[idx]; } const gchar *get_key(glong idx) override { return wordlist[idx]; }
void get_data(glong idx) override; void get_data(glong idx) override;
const gchar *get_key_and_data(glong idx) override const gchar *get_key_and_data(glong idx) override
@@ -615,7 +615,7 @@ bool OffsetIndex::save_cache(const std::string &url, bool verbose)
return false; return false;
} }
bool OffsetIndex::load(const std::string &url, gulong wc, off_t fsize, bool verbose) bool OffsetIndex::load(const std::string &url, gulong wc, gulong fsize, bool verbose)
{ {
wordcount = wc; wordcount = wc;
gulong npages = (wc - 1) / ENTR_PER_PAGE + 2; gulong npages = (wc - 1) / ENTR_PER_PAGE + 2;
@@ -758,7 +758,7 @@ bool OffsetIndex::lookup(const char *str, std::set<glong> &idxs, glong &next_idx
return bFound; return bFound;
} }
bool WordListIndex::load(const std::string &url, gulong wc, off_t fsize, bool) bool WordListIndex::load(const std::string &url, gulong wc, gulong fsize, bool)
{ {
gzFile in = gzopen(url.c_str(), "rb"); gzFile in = gzopen(url.c_str(), "rb");
if (in == nullptr) if (in == nullptr)
@@ -771,7 +771,7 @@ bool WordListIndex::load(const std::string &url, gulong wc, off_t fsize, bool)
if (len < 0) if (len < 0)
return false; return false;
if (static_cast<off_t>(len) != fsize) if (gulong(len) != fsize)
return false; return false;
wordlist.resize(wc + 1); wordlist.resize(wc + 1);
@@ -920,7 +920,7 @@ bool Dict::Lookup(const char *str, std::set<glong> &idxs, glong &next_idx)
bool Dict::load(const std::string &ifofilename, bool verbose) bool Dict::load(const std::string &ifofilename, bool verbose)
{ {
off_t idxfilesize; gulong idxfilesize;
if (!load_ifofile(ifofilename, idxfilesize)) if (!load_ifofile(ifofilename, idxfilesize))
return false; return false;
@@ -964,7 +964,7 @@ bool Dict::load(const std::string &ifofilename, bool verbose)
return true; return true;
} }
bool Dict::load_ifofile(const std::string &ifofilename, off_t &idxfilesize) bool Dict::load_ifofile(const std::string &ifofilename, gulong &idxfilesize)
{ {
DictInfo dict_info; DictInfo dict_info;
if (!dict_info.load_from_ifo_file(ifofilename, false)) if (!dict_info.load_from_ifo_file(ifofilename, false))
@@ -989,7 +989,7 @@ bool Dict::LookupWithRule(GPatternSpec *pspec, glong *aIndex, int iBuffLen)
int iIndexCount = 0; int iIndexCount = 0;
for (guint32 i = 0; i < narticles() && iIndexCount < (iBuffLen - 1); i++) for (guint32 i = 0; i < narticles() && iIndexCount < (iBuffLen - 1); i++)
if (g_pattern_spec_match_string(pspec, get_key(i))) if (g_pattern_match_string(pspec, get_key(i)))
aIndex[iIndexCount++] = i; aIndex[iIndexCount++] = i;
aIndex[iIndexCount] = -1; // -1 is the end. aIndex[iIndexCount] = -1; // -1 is the end.
@@ -1047,12 +1047,12 @@ bool Libs::LookupSimilarWord(const gchar *sWord, std::set<glong> &iWordIndices,
} }
// Upper the first character and lower others. // Upper the first character and lower others.
if (!bFound) { if (!bFound) {
const gchar *rest = g_utf8_next_char(sWord); gchar *nextchar = g_utf8_next_char(sWord);
gchar *firstchar = g_utf8_strup(sWord, rest - sWord); gchar *firstchar = g_utf8_strup(sWord, nextchar - sWord);
gchar *rest_lowercase = g_utf8_strdown(rest, -1); nextchar = g_utf8_strdown(nextchar, -1);
casestr = g_strconcat(firstchar, rest_lowercase, nullptr); casestr = g_strdup_printf("%s%s", firstchar, nextchar);
g_free(rest_lowercase);
g_free(firstchar); g_free(firstchar);
g_free(nextchar);
if (strcmp(casestr, sWord)) { if (strcmp(casestr, sWord)) {
if (oLib[iLib]->Lookup(casestr, iWordIndices)) if (oLib[iLib]->Lookup(casestr, iWordIndices))
bFound = true; bFound = true;

View File

@@ -77,8 +77,8 @@ struct DictInfo {
std::string website; std::string website;
std::string date; std::string date;
std::string description; std::string description;
off_t index_file_size; guint32 index_file_size;
off_t syn_file_size; guint32 syn_file_size;
std::string sametypesequence; std::string sametypesequence;
bool load_from_ifo_file(const std::string &ifofilename, bool istreedict); bool load_from_ifo_file(const std::string &ifofilename, bool istreedict);
@@ -91,7 +91,7 @@ public:
guint32 wordentry_size; guint32 wordentry_size;
virtual ~IIndexFile() {} virtual ~IIndexFile() {}
virtual bool load(const std::string &url, gulong wc, off_t fsize, bool verbose) = 0; virtual bool load(const std::string &url, gulong wc, gulong fsize, bool verbose) = 0;
virtual const gchar *get_key(glong idx) = 0; virtual const gchar *get_key(glong idx) = 0;
virtual void get_data(glong idx) = 0; virtual void get_data(glong idx) = 0;
virtual const gchar *get_key_and_data(glong idx) = 0; virtual const gchar *get_key_and_data(glong idx) = 0;
@@ -160,7 +160,7 @@ private:
std::unique_ptr<IIndexFile> idx_file; std::unique_ptr<IIndexFile> idx_file;
std::unique_ptr<SynFile> syn_file; std::unique_ptr<SynFile> syn_file;
bool load_ifofile(const std::string &ifofilename, off_t &idxfilesize); bool load_ifofile(const std::string &ifofilename, gulong &idxfilesize);
}; };
class Libs class Libs