mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-15 17:31:56 +00:00
Compare commits
56 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5478f290a1 | ||
|
|
9c77e91006 | ||
|
|
b74bc2478a | ||
|
|
58c48988f6 | ||
|
|
07cd873e9d | ||
|
|
4545473da9 | ||
|
|
849f0ed1ac | ||
|
|
d5e1eb4d93 | ||
|
|
3a4b76124c | ||
|
|
6eaebaaa2f | ||
|
|
e24722b8fc | ||
|
|
c57ef6e916 | ||
|
|
24c08365c4 | ||
|
|
8f77ede167 | ||
|
|
3a8ab1d5c3 | ||
|
|
5887505185 | ||
|
|
beebb0faa7 | ||
|
|
49c8094b53 | ||
|
|
4346e65bd3 | ||
|
|
d144e0310c | ||
|
|
6e36e7730c | ||
|
|
abe5e9e72f | ||
|
|
488ec68854 | ||
|
|
b698445ead | ||
|
|
504e7807e6 | ||
|
|
6c80bf2d99 | ||
|
|
8742575c33 | ||
|
|
b294b76fb5 | ||
|
|
823ec3d840 | ||
|
|
6ab8b51e6c | ||
|
|
881657b336 | ||
|
|
911fc2f561 | ||
|
|
f488f5350b | ||
|
|
e72220e748 | ||
|
|
b77c0e793a | ||
|
|
ebaa6f2136 | ||
|
|
d054adb37c | ||
|
|
4a9b1dae3d | ||
|
|
6d385221d0 | ||
|
|
3d15ce3b07 | ||
|
|
51338ac5bb | ||
|
|
5ada75e08d | ||
|
|
c7d9944f7d | ||
|
|
3963e358cd | ||
|
|
3b26731b02 | ||
|
|
070a9fb0bd | ||
|
|
8f096629ec | ||
|
|
25768c6b80 | ||
|
|
4ae4207349 | ||
|
|
994c1c7ae6 | ||
|
|
d38f8f13c9 | ||
|
|
cc7bcb8b73 | ||
|
|
8e9f72ae57 | ||
|
|
88af1a077c | ||
|
|
b66799f358 | ||
|
|
be5c3a35bf |
@@ -15,7 +15,7 @@ BreakBeforeBinaryOperators: true
|
|||||||
BreakBeforeTernaryOperators: true
|
BreakBeforeTernaryOperators: true
|
||||||
BreakConstructorInitializersBeforeComma: true
|
BreakConstructorInitializersBeforeComma: true
|
||||||
BinPackParameters: true
|
BinPackParameters: true
|
||||||
ColumnLimit: 0
|
ColumnLimit: 120
|
||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
DerivePointerAlignment: false
|
DerivePointerAlignment: false
|
||||||
ExperimentalAutoDetectBinPacking: false
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
|||||||
14
.github/workflows/main.yml
vendored
14
.github/workflows/main.yml
vendored
@@ -20,14 +20,12 @@ jobs:
|
|||||||
fail-fast: true
|
fail-fast: true
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest]
|
os: [ubuntu-22.04, ubuntu-latest]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
|
- uses: jwlawson/actions-setup-cmake@v2
|
||||||
with:
|
with:
|
||||||
submodules: 'recursive'
|
cmake-version: '3.10'
|
||||||
- uses: jwlawson/actions-setup-cmake@v1.0
|
|
||||||
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: |
|
||||||
@@ -36,6 +34,10 @@ 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
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
|
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)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
cmake_policy(VERSION 3.5)
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS False)
|
||||||
|
|
||||||
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/compiler.cmake")
|
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/compiler.cmake")
|
||||||
|
|
||||||
@@ -23,7 +27,8 @@ 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))
|
||||||
set(WITH_READLINE False CACHE FORCE)
|
message(STATUS "readline library not FOUND, disable it's usage")
|
||||||
|
set(WITH_READLINE False CACHE BOOL "Use readline library" FORCE)
|
||||||
endif ()
|
endif ()
|
||||||
endif (WITH_READLINE)
|
endif (WITH_READLINE)
|
||||||
|
|
||||||
@@ -78,11 +83,14 @@ 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
|
||||||
#
|
#
|
||||||
@@ -91,7 +99,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 "3")
|
set(CPACK_PACKAGE_VERSION_PATCH "5")
|
||||||
|
|
||||||
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}")
|
||||||
@@ -103,8 +111,10 @@ 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 ()
|
||||||
@@ -143,5 +153,7 @@ if (BUILD_TESTS)
|
|||||||
add_sdcv_shell_test(t_utf8input)
|
add_sdcv_shell_test(t_utf8input)
|
||||||
add_sdcv_shell_test(t_datadir)
|
add_sdcv_shell_test(t_datadir)
|
||||||
add_sdcv_shell_test(t_return_code)
|
add_sdcv_shell_test(t_return_code)
|
||||||
|
add_sdcv_shell_test(t_multiple_results)
|
||||||
|
add_sdcv_shell_test(t_newlines_in_ifo)
|
||||||
|
|
||||||
endif (BUILD_TESTS)
|
endif (BUILD_TESTS)
|
||||||
|
|||||||
10
NEWS
10
NEWS
@@ -1,3 +1,13 @@
|
|||||||
|
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
|
||||||
|
|||||||
23
README.org
23
README.org
@@ -1,6 +1,9 @@
|
|||||||
#+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
|
||||||
@@ -26,6 +29,26 @@ 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
|
||||||
|
|||||||
@@ -16,19 +16,6 @@ if (NOT DEFINED SDCV_COMPILER_IS_GCC_COMPATIBLE)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (MSVC AND (MSVC_VERSION LESS 1900))
|
|
||||||
message(FATAL_ERROR "MSVC version ${MSVC_VERSION} have no full c++11 support")
|
|
||||||
elseif (MSVC)
|
|
||||||
add_definitions(-DNOMINMAX)
|
|
||||||
elseif (NOT MSVC)
|
|
||||||
check_cxx_compiler_flag("-std=c++11" CXX_SUPPORTS_CXX11)
|
|
||||||
if (CXX_SUPPORTS_CXX11)
|
|
||||||
append("-std=c++11" CMAKE_CXX_FLAGS)
|
|
||||||
else ()
|
|
||||||
message(FATAL_ERROR "sdcv requires C++11 support but the '-std=c++11' flag isn't supported.")
|
|
||||||
endif()
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (SDCV_COMPILER_IS_GCC_COMPATIBLE)
|
if (SDCV_COMPILER_IS_GCC_COMPATIBLE)
|
||||||
append("-Wall" "-Wextra" "-Wformat-security" "-Wcast-align" "-Werror=format" "-Wcast-qual" CMAKE_C_FLAGS)
|
append("-Wall" "-Wextra" "-Wformat-security" "-Wcast-align" "-Werror=format" "-Wcast-qual" CMAKE_C_FLAGS)
|
||||||
append("-Wall" "-pedantic" "-Wextra" "-Wformat-security" "-Wcast-align" "-Werror=format" "-Wcast-qual" CMAKE_CXX_FLAGS)
|
append("-Wall" "-pedantic" "-Wextra" "-Wformat-security" "-Wcast-align" "-Werror=format" "-Wcast-qual" CMAKE_CXX_FLAGS)
|
||||||
|
|||||||
147
po/ka.po
Normal file
147
po/ka.po
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
# 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"
|
||||||
@@ -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 */
|
||||||
unsigned long size; /* size of mmap */
|
off_t 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;
|
||||||
unsigned long length;
|
off_t length;
|
||||||
unsigned long compressedLength;
|
unsigned long compressedLength;
|
||||||
DictCache cache[DICT_CACHE_SIZE];
|
DictCache cache[DICT_CACHE_SIZE];
|
||||||
MapFile mapfile;
|
MapFile mapfile;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <cstdio> //for popen
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -199,14 +200,18 @@ static std::string parse_data(const gchar *data, bool colorize_output)
|
|||||||
|
|
||||||
void Library::SimpleLookup(const std::string &str, TSearchResultList &res_list)
|
void Library::SimpleLookup(const std::string &str, TSearchResultList &res_list)
|
||||||
{
|
{
|
||||||
glong ind;
|
std::set<glong> wordIdxs;
|
||||||
res_list.reserve(ndicts());
|
res_list.reserve(ndicts());
|
||||||
for (gint idict = 0; idict < ndicts(); ++idict)
|
for (gint idict = 0; idict < ndicts(); ++idict) {
|
||||||
if (SimpleLookupWord(str.c_str(), ind, idict))
|
wordIdxs.clear();
|
||||||
|
if (SimpleLookupWord(str.c_str(), wordIdxs, idict))
|
||||||
|
for (auto &wordIdx : wordIdxs)
|
||||||
res_list.push_back(
|
res_list.push_back(
|
||||||
TSearchResult(dict_name(idict),
|
TSearchResult(dict_name(idict),
|
||||||
poGetWord(ind, idict),
|
poGetWord(wordIdx, idict),
|
||||||
parse_data(poGetWordData(ind, idict), colorize_output_)));
|
parse_data(poGetWordData(wordIdx, idict),
|
||||||
|
colorize_output_)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Library::LookupWithFuzzy(const std::string &str, TSearchResultList &res_list)
|
void Library::LookupWithFuzzy(const std::string &str, TSearchResultList &res_list)
|
||||||
@@ -411,10 +416,9 @@ 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;
|
||||||
choice_readline->read(_("Your choice[-1 to abort]: "), str_choise);
|
io.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;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#ifdef HAVE_MMAP
|
#ifdef HAVE_MMAP
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -21,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, unsigned long file_size);
|
bool open(const char *file_name, off_t 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;
|
||||||
@@ -35,25 +36,31 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool MapFile::open(const char *file_name, unsigned long file_size)
|
inline bool MapFile::open(const char *file_name, off_t 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);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
data = (gchar *)mmap(nullptr, file_size, PROT_READ, MAP_SHARED, mmap_fd, 0);
|
struct stat st;
|
||||||
|
if (fstat(mmap_fd, &st) == -1 || st.st_size < 0 || (st.st_size == 0 && S_ISREG(st.st_mode))
|
||||||
|
|| st.st_size != file_size) {
|
||||||
|
close(mmap_fd);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
size = static_cast<size_t>(st.st_size);
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
hFile = CreateFile(file_name, GENERIC_READ, 0, nullptr, OPEN_ALWAYS,
|
hFile = CreateFile(file_name, GENERIC_READ, 0, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||||
FILE_ATTRIBUTE_NORMAL, 0);
|
hFileMap = CreateFileMapping(hFile, nullptr, PAGE_READONLY, 0, file_size, nullptr);
|
||||||
hFileMap = CreateFileMapping(hFile, nullptr, PAGE_READONLY, 0,
|
|
||||||
file_size, nullptr);
|
|
||||||
data = (gchar *)MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, file_size);
|
data = (gchar *)MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, file_size);
|
||||||
#else
|
#else
|
||||||
gsize read_len;
|
gsize read_len;
|
||||||
|
|||||||
40
src/sdcv.cpp
40
src/sdcv.cpp
@@ -83,6 +83,7 @@ try {
|
|||||||
glib::CharStr opt_data_dir;
|
glib::CharStr opt_data_dir;
|
||||||
gboolean only_data_dir = FALSE;
|
gboolean only_data_dir = FALSE;
|
||||||
gboolean colorize = FALSE;
|
gboolean colorize = FALSE;
|
||||||
|
glib::StrArr word_list;
|
||||||
|
|
||||||
const GOptionEntry entries[] = {
|
const GOptionEntry entries[] = {
|
||||||
{ "version", 'v', 0, G_OPTION_ARG_NONE, &show_version,
|
{ "version", 'v', 0, G_OPTION_ARG_NONE, &show_version,
|
||||||
@@ -96,6 +97,8 @@ try {
|
|||||||
_("for use in scripts"), nullptr },
|
_("for use in scripts"), nullptr },
|
||||||
{ "json-output", 'j', 0, G_OPTION_ARG_NONE, &json_output,
|
{ "json-output", 'j', 0, G_OPTION_ARG_NONE, &json_output,
|
||||||
_("print the result formatted as JSON"), nullptr },
|
_("print the result formatted as JSON"), nullptr },
|
||||||
|
{ "json", 'j', 0, G_OPTION_ARG_NONE, &json_output,
|
||||||
|
_("print the result formatted as JSON"), nullptr },
|
||||||
{ "exact-search", 'e', 0, G_OPTION_ARG_NONE, &no_fuzzy,
|
{ "exact-search", 'e', 0, G_OPTION_ARG_NONE, &no_fuzzy,
|
||||||
_("do not fuzzy-search for similar words, only return exact matches"), nullptr },
|
_("do not fuzzy-search for similar words, only return exact matches"), nullptr },
|
||||||
{ "utf8-output", '0', 0, G_OPTION_ARG_NONE, &utf8_output,
|
{ "utf8-output", '0', 0, G_OPTION_ARG_NONE, &utf8_output,
|
||||||
@@ -109,11 +112,13 @@ try {
|
|||||||
_("only use the dictionaries in data-dir, do not search in user and system directories"), nullptr },
|
_("only use the dictionaries in data-dir, do not search in user and system directories"), nullptr },
|
||||||
{ "color", 'c', 0, G_OPTION_ARG_NONE, &colorize,
|
{ "color", 'c', 0, G_OPTION_ARG_NONE, &colorize,
|
||||||
_("colorize the output"), nullptr },
|
_("colorize the output"), nullptr },
|
||||||
|
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, get_addr(word_list),
|
||||||
|
_("search terms"), _(" words") },
|
||||||
{},
|
{},
|
||||||
};
|
};
|
||||||
|
|
||||||
glib::Error error;
|
glib::Error error;
|
||||||
GOptionContext *context = g_option_context_new(_(" words"));
|
GOptionContext *context = g_option_context_new(nullptr);
|
||||||
g_option_context_set_help_enabled(context, TRUE);
|
g_option_context_set_help_enabled(context, TRUE);
|
||||||
g_option_context_add_main_entries(context, entries, nullptr);
|
g_option_context_add_main_entries(context, entries, nullptr);
|
||||||
const gboolean parse_res = g_option_context_parse(context, &argc, &argv, get_addr(error));
|
const gboolean parse_res = g_option_context_parse(context, &argc, &argv, get_addr(error));
|
||||||
@@ -181,10 +186,13 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add bookname to list
|
// add bookname to list
|
||||||
gchar **p = get_impl(use_dict_list);
|
for (gchar **p = get_impl(use_dict_list); *p != nullptr; ++p) {
|
||||||
while (*p) {
|
auto it = bookname_to_ifo.find(*p);
|
||||||
order_list.push_back(bookname_to_ifo.at(*p));
|
if (it != bookname_to_ifo.end()) {
|
||||||
++p;
|
order_list.push_back(it->second);
|
||||||
|
} 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";
|
||||||
@@ -196,7 +204,12 @@ 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)) {
|
||||||
order_list.push_back(bookname_to_ifo.at(line));
|
auto it = bookname_to_ifo.find(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);
|
||||||
}
|
}
|
||||||
@@ -210,14 +223,19 @@ try {
|
|||||||
lib.load(dicts_dir_list, order_list, disable_list);
|
lib.load(dicts_dir_list, order_list, disable_list);
|
||||||
|
|
||||||
std::unique_ptr<IReadLine> io(create_readline_object());
|
std::unique_ptr<IReadLine> io(create_readline_object());
|
||||||
if (optind < argc) {
|
if (word_list != nullptr) {
|
||||||
search_result rval = SEARCH_SUCCESS;
|
search_result rval = SEARCH_SUCCESS;
|
||||||
for (int i = optind; i < argc; ++i)
|
gchar **p = get_impl(word_list);
|
||||||
if ((rval = lib.process_phrase(argv[i], *io, non_interactive)) != SEARCH_SUCCESS) {
|
while (*p) {
|
||||||
return rval;
|
search_result this_rval = lib.process_phrase(*p++, *io, non_interactive);
|
||||||
|
// If we encounter any error, save it but continue through the word
|
||||||
|
// list to check all requested words.
|
||||||
|
if (rval == SEARCH_SUCCESS)
|
||||||
|
rval = this_rval;
|
||||||
}
|
}
|
||||||
|
if (rval != SEARCH_SUCCESS)
|
||||||
|
return rval;
|
||||||
} else if (!non_interactive) {
|
} else if (!non_interactive) {
|
||||||
|
|
||||||
std::string phrase;
|
std::string phrase;
|
||||||
while (io->read(_("Enter word or phrase: "), phrase)) {
|
while (io->read(_("Enter word or phrase: "), phrase)) {
|
||||||
if (lib.process_phrase(phrase.c_str(), *io) == SEARCH_FAILURE)
|
if (lib.process_phrase(phrase.c_str(), *io) == SEARCH_FAILURE)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <map>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
@@ -78,108 +79,93 @@ bool DictInfo::load_from_ifo_file(const std::string &ifofilename,
|
|||||||
{
|
{
|
||||||
ifo_file_name = ifofilename;
|
ifo_file_name = ifofilename;
|
||||||
glib::CharStr buffer;
|
glib::CharStr buffer;
|
||||||
if (!g_file_get_contents(ifofilename.c_str(), get_addr(buffer), nullptr, nullptr))
|
gsize length = 0;
|
||||||
|
if (!g_file_get_contents(ifofilename.c_str(), get_addr(buffer), &length, nullptr)) {
|
||||||
|
fprintf(stderr, "Can not read from %s\n", ifofilename.c_str());
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static const char TREEDICT_MAGIC_DATA[] = "StarDict's treedict ifo file";
|
static const char TREEDICT_MAGIC_DATA[] = "StarDict's treedict ifo file";
|
||||||
static const char DICT_MAGIC_DATA[] = "StarDict's dict ifo file";
|
static const char DICT_MAGIC_DATA[] = "StarDict's dict ifo file";
|
||||||
|
|
||||||
const gchar *magic_data = istreedict ? TREEDICT_MAGIC_DATA : DICT_MAGIC_DATA;
|
const gchar *magic_data = istreedict ? TREEDICT_MAGIC_DATA : DICT_MAGIC_DATA;
|
||||||
static const unsigned char utf8_bom[] = { 0xEF, 0xBB, 0xBF, '\0' };
|
static const gchar utf8_bom[] = { (gchar)0xEF, (gchar)0xBB, (gchar)0xBF, '\0' };
|
||||||
if (!g_str_has_prefix(
|
|
||||||
g_str_has_prefix(get_impl(buffer), (const gchar *)(utf8_bom)) ? get_impl(buffer) + 3 : get_impl(buffer),
|
const gchar *p = get_impl(buffer);
|
||||||
magic_data)) {
|
const gchar *end = p + length;
|
||||||
|
|
||||||
|
if (g_str_has_prefix(p, utf8_bom)) {
|
||||||
|
p += strlen(utf8_bom);
|
||||||
|
}
|
||||||
|
if (!g_str_has_prefix(p, magic_data)) {
|
||||||
|
fprintf(stderr, "No magic header(%s) in ifo file\n", magic_data);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
p += strlen(magic_data);
|
||||||
|
|
||||||
gchar *p1 = get_impl(buffer) + strlen(magic_data) - 1;
|
std::map<std::string, std::string> key_value_map;
|
||||||
|
while (p != end) {
|
||||||
gchar *p2 = strstr(p1, "\nwordcount=");
|
auto key_it = std::find_if(p, end, [](gchar ch) { return !g_ascii_isspace(ch); });
|
||||||
if (p2 == nullptr)
|
if (key_it == end) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
auto eq_it = std::find(key_it, end, gchar('='));
|
||||||
|
if (eq_it == end) {
|
||||||
|
fprintf(stderr, "Invalid part of ifo (no '=') here: %s\n", key_it);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
auto val_it = std::find_if(eq_it + 1, end, [](gchar ch) { return !g_ascii_isspace(ch); });
|
||||||
|
if (val_it == end) {
|
||||||
|
key_value_map.insert(std::make_pair(std::string(key_it, eq_it), std::string()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
gchar *p3 = strchr(p2 + sizeof("\nwordcount=") - 1, '\n');
|
auto line_end_it = std::find_if(val_it, end, [](gchar ch) { return ch == '\r' || ch == '\n'; });
|
||||||
|
key_value_map.insert(std::make_pair(std::string(key_it, eq_it), std::string(val_it, line_end_it)));
|
||||||
|
if (line_end_it == end)
|
||||||
|
break;
|
||||||
|
p = line_end_it + 1;
|
||||||
|
}
|
||||||
|
|
||||||
wordcount = atol(std::string(p2 + sizeof("\nwordcount=") - 1, p3 - (p2 + sizeof("\nwordcount=") - 1)).c_str());
|
std::map<std::string, std::string>::const_iterator it;
|
||||||
|
#define FIND_KEY(_key_) \
|
||||||
|
it = key_value_map.find(_key_); \
|
||||||
|
if (it == key_value_map.end()) { \
|
||||||
|
fprintf(stderr, "Can not find '%s' in ifo file\n", _key_); \
|
||||||
|
return false; \
|
||||||
|
}
|
||||||
|
|
||||||
|
FIND_KEY("wordcount")
|
||||||
|
wordcount = atol(it->second.c_str());
|
||||||
|
|
||||||
if (istreedict) {
|
if (istreedict) {
|
||||||
p2 = strstr(p1, "\ntdxfilesize=");
|
FIND_KEY("tdxfilesize")
|
||||||
if (p2 == nullptr)
|
index_file_size = atol(it->second.c_str());
|
||||||
return false;
|
|
||||||
|
|
||||||
p3 = strchr(p2 + sizeof("\ntdxfilesize=") - 1, '\n');
|
|
||||||
|
|
||||||
index_file_size = atol(std::string(p2 + sizeof("\ntdxfilesize=") - 1, p3 - (p2 + sizeof("\ntdxfilesize=") - 1)).c_str());
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
FIND_KEY("idxfilesize")
|
||||||
|
index_file_size = atol(it->second.c_str());
|
||||||
|
}
|
||||||
|
FIND_KEY("bookname")
|
||||||
|
bookname = it->second;
|
||||||
|
|
||||||
p2 = strstr(p1, "\nidxfilesize=");
|
#define SET_IF_EXISTS(_key_) \
|
||||||
if (p2 == nullptr)
|
it = key_value_map.find(#_key_); \
|
||||||
return false;
|
if (it != key_value_map.end()) { \
|
||||||
|
_key_ = it->second; \
|
||||||
p3 = strchr(p2 + sizeof("\nidxfilesize=") - 1, '\n');
|
|
||||||
index_file_size = atol(std::string(p2 + sizeof("\nidxfilesize=") - 1, p3 - (p2 + sizeof("\nidxfilesize=") - 1)).c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p2 = strstr(p1, "\nbookname=");
|
SET_IF_EXISTS(author)
|
||||||
|
SET_IF_EXISTS(email)
|
||||||
if (p2 == nullptr)
|
SET_IF_EXISTS(website)
|
||||||
return false;
|
SET_IF_EXISTS(date)
|
||||||
|
SET_IF_EXISTS(description)
|
||||||
p2 = p2 + sizeof("\nbookname=") - 1;
|
SET_IF_EXISTS(sametypesequence)
|
||||||
p3 = strchr(p2, '\n');
|
|
||||||
bookname.assign(p2, p3 - p2);
|
|
||||||
|
|
||||||
p2 = strstr(p1, "\nauthor=");
|
|
||||||
if (p2) {
|
|
||||||
p2 = p2 + sizeof("\nauthor=") - 1;
|
|
||||||
p3 = strchr(p2, '\n');
|
|
||||||
author.assign(p2, p3 - p2);
|
|
||||||
}
|
|
||||||
|
|
||||||
p2 = strstr(p1, "\nemail=");
|
|
||||||
if (p2) {
|
|
||||||
p2 = p2 + sizeof("\nemail=") - 1;
|
|
||||||
p3 = strchr(p2, '\n');
|
|
||||||
email.assign(p2, p3 - p2);
|
|
||||||
}
|
|
||||||
|
|
||||||
p2 = strstr(p1, "\nwebsite=");
|
|
||||||
if (p2) {
|
|
||||||
p2 = p2 + sizeof("\nwebsite=") - 1;
|
|
||||||
p3 = strchr(p2, '\n');
|
|
||||||
website.assign(p2, p3 - p2);
|
|
||||||
}
|
|
||||||
|
|
||||||
p2 = strstr(p1, "\ndate=");
|
|
||||||
if (p2) {
|
|
||||||
p2 = p2 + sizeof("\ndate=") - 1;
|
|
||||||
p3 = strchr(p2, '\n');
|
|
||||||
date.assign(p2, p3 - p2);
|
|
||||||
}
|
|
||||||
|
|
||||||
p2 = strstr(p1, "\ndescription=");
|
|
||||||
if (p2) {
|
|
||||||
p2 = p2 + sizeof("\ndescription=") - 1;
|
|
||||||
p3 = strchr(p2, '\n');
|
|
||||||
description.assign(p2, p3 - p2);
|
|
||||||
}
|
|
||||||
|
|
||||||
p2 = strstr(p1, "\nsametypesequence=");
|
|
||||||
if (p2) {
|
|
||||||
p2 += sizeof("\nsametypesequence=") - 1;
|
|
||||||
p3 = strchr(p2, '\n');
|
|
||||||
sametypesequence.assign(p2, p3 - p2);
|
|
||||||
}
|
|
||||||
|
|
||||||
p2 = strstr(p1, "\nsynwordcount=");
|
|
||||||
syn_wordcount = 0;
|
syn_wordcount = 0;
|
||||||
if (p2) {
|
it = key_value_map.find("synwordcount");
|
||||||
p2 += sizeof("\nsynwordcount=") - 1;
|
if (it != key_value_map.end())
|
||||||
p3 = strchr(p2, '\n');
|
syn_wordcount = atol(it->second.c_str());
|
||||||
syn_wordcount = atol(std::string(p2, p3 - p2).c_str());
|
#undef FIND_KEY
|
||||||
}
|
#undef SET_IF_EXISTS
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,14 +429,14 @@ public:
|
|||||||
if (idxfile)
|
if (idxfile)
|
||||||
fclose(idxfile);
|
fclose(idxfile);
|
||||||
}
|
}
|
||||||
bool load(const std::string &url, gulong wc, gulong fsize, bool verbose) override;
|
bool load(const std::string &url, gulong wc, off_t 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
|
||||||
{
|
{
|
||||||
return get_key(idx);
|
return get_key(idx);
|
||||||
}
|
}
|
||||||
bool lookup(const char *str, glong &idx) override;
|
bool lookup(const char *str, std::set<glong> &idxs, glong &next_idx) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const gint ENTR_PER_PAGE = 32;
|
static const gint ENTR_PER_PAGE = 32;
|
||||||
@@ -503,7 +489,7 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
~WordListIndex() { g_free(idxdatabuf); }
|
~WordListIndex() { g_free(idxdatabuf); }
|
||||||
bool load(const std::string &url, gulong wc, gulong fsize, bool verbose) override;
|
bool load(const std::string &url, gulong wc, off_t 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
|
||||||
@@ -511,7 +497,7 @@ public:
|
|||||||
get_data(idx);
|
get_data(idx);
|
||||||
return get_key(idx);
|
return get_key(idx);
|
||||||
}
|
}
|
||||||
bool lookup(const char *str, glong &idx) override;
|
bool lookup(const char *str, std::set<glong> &idxs, glong &next_idx) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
gchar *idxdatabuf;
|
gchar *idxdatabuf;
|
||||||
@@ -629,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, gulong fsize, bool verbose)
|
bool OffsetIndex::load(const std::string &url, gulong wc, off_t fsize, bool verbose)
|
||||||
{
|
{
|
||||||
wordcount = wc;
|
wordcount = wc;
|
||||||
gulong npages = (wc - 1) / ENTR_PER_PAGE + 2;
|
gulong npages = (wc - 1) / ENTR_PER_PAGE + 2;
|
||||||
@@ -698,47 +684,52 @@ const gchar *OffsetIndex::get_key(glong idx)
|
|||||||
return page.entries[idx_in_page].keystr;
|
return page.entries[idx_in_page].keystr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OffsetIndex::lookup(const char *str, glong &idx)
|
bool OffsetIndex::lookup(const char *str, std::set<glong> &idxs, glong &next_idx)
|
||||||
{
|
{
|
||||||
bool bFound = false;
|
bool bFound = false;
|
||||||
glong iFrom;
|
|
||||||
glong iTo = wordoffset.size() - 2;
|
|
||||||
gint cmpint;
|
|
||||||
glong iThisIndex;
|
|
||||||
if (stardict_strcmp(str, first.keystr.c_str()) < 0) {
|
if (stardict_strcmp(str, first.keystr.c_str()) < 0) {
|
||||||
idx = 0;
|
next_idx = 0;
|
||||||
return false;
|
return false;
|
||||||
} else if (stardict_strcmp(str, real_last.keystr.c_str()) > 0) {
|
} else if (stardict_strcmp(str, real_last.keystr.c_str()) > 0) {
|
||||||
idx = INVALID_INDEX;
|
next_idx = INVALID_INDEX;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search for the first page where the word is likely to be located.
|
||||||
|
glong iFrom = 0, iTo = wordoffset.size() - 2;
|
||||||
|
glong iPage = 0, iThisIndex = 0;
|
||||||
|
while (iFrom <= iTo) {
|
||||||
|
iThisIndex = (iFrom + iTo) / 2;
|
||||||
|
glong cmpint = stardict_strcmp(str, get_first_on_page_key(iThisIndex));
|
||||||
|
if (cmpint > 0)
|
||||||
|
iFrom = iThisIndex + 1;
|
||||||
|
else if (cmpint < 0)
|
||||||
|
iTo = iThisIndex - 1;
|
||||||
|
else {
|
||||||
|
bFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bFound) {
|
||||||
|
// We can use this found index (even though it might not be the first)
|
||||||
|
// because we will search backwards later and catch any entries on
|
||||||
|
// previous pages.
|
||||||
|
iPage = iThisIndex;
|
||||||
|
iThisIndex = 0; // first item in the page
|
||||||
} else {
|
} else {
|
||||||
|
iPage = iTo; // prev
|
||||||
|
// Not found at the start of a page, so search within the page that
|
||||||
|
// should contain it. Binary search here is slightly overkill (we're
|
||||||
|
// searching at most ENTR_PER_PAGE = 32 elements) but this way next_idx
|
||||||
|
// is treated the same as other Lookup methods.
|
||||||
|
gulong netr = load_page(iPage);
|
||||||
iFrom = 0;
|
iFrom = 0;
|
||||||
iThisIndex = 0;
|
|
||||||
while (iFrom <= iTo) {
|
|
||||||
iThisIndex = (iFrom + iTo) / 2;
|
|
||||||
cmpint = stardict_strcmp(str, get_first_on_page_key(iThisIndex));
|
|
||||||
if (cmpint > 0)
|
|
||||||
iFrom = iThisIndex + 1;
|
|
||||||
else if (cmpint < 0)
|
|
||||||
iTo = iThisIndex - 1;
|
|
||||||
else {
|
|
||||||
bFound = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!bFound)
|
|
||||||
idx = iTo; //prev
|
|
||||||
else
|
|
||||||
idx = iThisIndex;
|
|
||||||
}
|
|
||||||
if (!bFound) {
|
|
||||||
gulong netr = load_page(idx);
|
|
||||||
iFrom = 1; // Needn't search the first word anymore.
|
|
||||||
iTo = netr - 1;
|
iTo = netr - 1;
|
||||||
iThisIndex = 0;
|
|
||||||
while (iFrom <= iTo) {
|
while (iFrom <= iTo) {
|
||||||
iThisIndex = (iFrom + iTo) / 2;
|
iThisIndex = (iFrom + iTo) / 2;
|
||||||
cmpint = stardict_strcmp(str, page.entries[iThisIndex].keystr);
|
glong cmpint = stardict_strcmp(str, page.entries[iThisIndex].keystr);
|
||||||
if (cmpint > 0)
|
if (cmpint > 0)
|
||||||
iFrom = iThisIndex + 1;
|
iFrom = iThisIndex + 1;
|
||||||
else if (cmpint < 0)
|
else if (cmpint < 0)
|
||||||
@@ -748,18 +739,26 @@ bool OffsetIndex::lookup(const char *str, glong &idx)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
idx *= ENTR_PER_PAGE;
|
}
|
||||||
|
|
||||||
if (!bFound)
|
if (!bFound)
|
||||||
idx += iFrom; //next
|
next_idx = iPage * ENTR_PER_PAGE + iFrom; // next
|
||||||
else
|
else {
|
||||||
idx += iThisIndex;
|
// Convert the found in-page index to the dict index.
|
||||||
} else {
|
iThisIndex = iPage * ENTR_PER_PAGE + iThisIndex;
|
||||||
idx *= ENTR_PER_PAGE;
|
// In order to return all idxs that match the search string, walk
|
||||||
|
// linearly behind and ahead of the found index.
|
||||||
|
glong iHeadIndex = iThisIndex - 1; // do not include iThisIndex
|
||||||
|
while (iHeadIndex >= 0 && stardict_strcmp(str, get_key(iHeadIndex)) == 0)
|
||||||
|
idxs.insert(iHeadIndex--);
|
||||||
|
do // no need to double-check iThisIndex -- we know it's a match already
|
||||||
|
idxs.insert(iThisIndex++);
|
||||||
|
while (iThisIndex <= real_last.idx && stardict_strcmp(str, get_key(iThisIndex)) == 0);
|
||||||
}
|
}
|
||||||
return bFound;
|
return bFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WordListIndex::load(const std::string &url, gulong wc, gulong fsize, bool)
|
bool WordListIndex::load(const std::string &url, gulong wc, off_t fsize, bool)
|
||||||
{
|
{
|
||||||
gzFile in = gzopen(url.c_str(), "rb");
|
gzFile in = gzopen(url.c_str(), "rb");
|
||||||
if (in == nullptr)
|
if (in == nullptr)
|
||||||
@@ -772,7 +771,7 @@ bool WordListIndex::load(const std::string &url, gulong wc, gulong fsize, bool)
|
|||||||
if (len < 0)
|
if (len < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (gulong(len) != fsize)
|
if (static_cast<off_t>(len) != fsize)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
wordlist.resize(wc + 1);
|
wordlist.resize(wc + 1);
|
||||||
@@ -795,18 +794,18 @@ void WordListIndex::get_data(glong idx)
|
|||||||
wordentry_size = g_ntohl(get_uint32(p1));
|
wordentry_size = g_ntohl(get_uint32(p1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WordListIndex::lookup(const char *str, glong &idx)
|
bool WordListIndex::lookup(const char *str, std::set<glong> &idxs, glong &next_idx)
|
||||||
{
|
{
|
||||||
bool bFound = false;
|
bool bFound = false;
|
||||||
glong iTo = wordlist.size() - 2;
|
glong iLast = wordlist.size() - 2;
|
||||||
|
|
||||||
if (stardict_strcmp(str, get_key(0)) < 0) {
|
if (stardict_strcmp(str, get_key(0)) < 0) {
|
||||||
idx = 0;
|
next_idx = 0;
|
||||||
} else if (stardict_strcmp(str, get_key(iTo)) > 0) {
|
} else if (stardict_strcmp(str, get_key(iLast)) > 0) {
|
||||||
idx = INVALID_INDEX;
|
next_idx = INVALID_INDEX;
|
||||||
} else {
|
} else {
|
||||||
glong iThisIndex = 0;
|
glong iThisIndex = 0;
|
||||||
glong iFrom = 0;
|
glong iFrom = 0, iTo = iLast;
|
||||||
gint cmpint;
|
gint cmpint;
|
||||||
while (iFrom <= iTo) {
|
while (iFrom <= iTo) {
|
||||||
iThisIndex = (iFrom + iTo) / 2;
|
iThisIndex = (iFrom + iTo) / 2;
|
||||||
@@ -821,9 +820,17 @@ bool WordListIndex::lookup(const char *str, glong &idx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!bFound)
|
if (!bFound)
|
||||||
idx = iFrom; //next
|
next_idx = iFrom; // next
|
||||||
else
|
else {
|
||||||
idx = iThisIndex;
|
// In order to return all idxs that match the search string, walk
|
||||||
|
// linearly behind and ahead of the found index.
|
||||||
|
glong iHeadIndex = iThisIndex - 1; // do not include iThisIndex
|
||||||
|
while (iHeadIndex >= 0 && stardict_strcmp(str, get_key(iHeadIndex)) == 0)
|
||||||
|
idxs.insert(iHeadIndex--);
|
||||||
|
do // no need to double-check iThisIndex -- we know it's a match already
|
||||||
|
idxs.insert(iThisIndex++);
|
||||||
|
while (iThisIndex <= iLast && stardict_strcmp(str, get_key(iThisIndex)) == 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return bFound;
|
return bFound;
|
||||||
}
|
}
|
||||||
@@ -833,46 +840,87 @@ bool SynFile::load(const std::string &url, gulong wc)
|
|||||||
{
|
{
|
||||||
struct stat stat_buf;
|
struct stat stat_buf;
|
||||||
if (!stat(url.c_str(), &stat_buf)) {
|
if (!stat(url.c_str(), &stat_buf)) {
|
||||||
MapFile syn;
|
|
||||||
if (!syn.open(url.c_str(), stat_buf.st_size))
|
if (!synfile.open(url.c_str(), stat_buf.st_size))
|
||||||
return false;
|
return false;
|
||||||
const gchar *current = syn.begin();
|
|
||||||
|
synlist.resize(wc + 1);
|
||||||
|
gchar *p1 = synfile.begin();
|
||||||
|
|
||||||
for (unsigned long i = 0; i < wc; i++) {
|
for (unsigned long i = 0; i < wc; i++) {
|
||||||
// each entry in a syn-file is:
|
// each entry in a syn-file is:
|
||||||
// - 0-terminated string
|
// - 0-terminated string
|
||||||
// 4-byte index into .dict file in network byte order
|
// 4-byte index into .dict file in network byte order
|
||||||
glib::CharStr lower_string{ g_utf8_casefold(current, -1) };
|
|
||||||
std::string synonym{ get_impl(lower_string) };
|
synlist[i] = p1;
|
||||||
current += synonym.length() + 1;
|
p1 += strlen(p1) + 1 + 4;
|
||||||
const guint32 idx = g_ntohl(get_uint32(current));
|
|
||||||
current += sizeof(idx);
|
|
||||||
synonyms[synonym] = idx;
|
|
||||||
}
|
}
|
||||||
|
synlist[wc] = p1;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SynFile::lookup(const char *str, glong &idx)
|
bool SynFile::lookup(const char *str, std::set<glong> &idxs, glong &next_idx)
|
||||||
{
|
{
|
||||||
glib::CharStr lower_string{ g_utf8_casefold(str, -1) };
|
bool bFound = false;
|
||||||
auto it = synonyms.find(get_impl(lower_string));
|
glong iLast = synlist.size() - 2;
|
||||||
if (it != synonyms.end()) {
|
if (iLast < 0)
|
||||||
idx = it->second;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (stardict_strcmp(str, get_key(0)) < 0) {
|
||||||
|
next_idx = 0;
|
||||||
|
} else if (stardict_strcmp(str, get_key(iLast)) > 0) {
|
||||||
|
next_idx = INVALID_INDEX;
|
||||||
|
} else {
|
||||||
|
glong iThisIndex = 0;
|
||||||
|
glong iFrom = 0, iTo = iLast;
|
||||||
|
gint cmpint;
|
||||||
|
while (iFrom <= iTo) {
|
||||||
|
iThisIndex = (iFrom + iTo) / 2;
|
||||||
|
cmpint = stardict_strcmp(str, get_key(iThisIndex));
|
||||||
|
if (cmpint > 0)
|
||||||
|
iFrom = iThisIndex + 1;
|
||||||
|
else if (cmpint < 0)
|
||||||
|
iTo = iThisIndex - 1;
|
||||||
|
else {
|
||||||
|
bFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!bFound)
|
||||||
|
next_idx = iFrom; // next
|
||||||
|
else {
|
||||||
|
// In order to return all idxs that match the search string, walk
|
||||||
|
// linearly behind and ahead of the found index.
|
||||||
|
glong iHeadIndex = iThisIndex - 1; // do not include iThisIndex
|
||||||
|
while (iHeadIndex >= 0 && stardict_strcmp(str, get_key(iHeadIndex)) == 0) {
|
||||||
|
const gchar *key = get_key(iHeadIndex--);
|
||||||
|
idxs.insert(g_ntohl(get_uint32(key + strlen(key) + 1)));
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
// no need to double-check iThisIndex -- we know it's a match already
|
||||||
|
const gchar *key = get_key(iThisIndex++);
|
||||||
|
idxs.insert(g_ntohl(get_uint32(key + strlen(key) + 1)));
|
||||||
|
} while (iThisIndex <= iLast && stardict_strcmp(str, get_key(iThisIndex)) == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Dict::Lookup(const char *str, glong &idx)
|
bool Dict::Lookup(const char *str, std::set<glong> &idxs, glong &next_idx)
|
||||||
{
|
{
|
||||||
return syn_file->lookup(str, idx) || idx_file->lookup(str, idx);
|
bool found = false;
|
||||||
|
found |= syn_file->lookup(str, idxs, next_idx);
|
||||||
|
found |= idx_file->lookup(str, idxs, next_idx);
|
||||||
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Dict::load(const std::string &ifofilename, bool verbose)
|
bool Dict::load(const std::string &ifofilename, bool verbose)
|
||||||
{
|
{
|
||||||
gulong idxfilesize;
|
off_t idxfilesize;
|
||||||
if (!load_ifofile(ifofilename, idxfilesize))
|
if (!load_ifofile(ifofilename, idxfilesize))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -916,7 +964,7 @@ bool Dict::load(const std::string &ifofilename, bool verbose)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Dict::load_ifofile(const std::string &ifofilename, gulong &idxfilesize)
|
bool Dict::load_ifofile(const std::string &ifofilename, off_t &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))
|
||||||
@@ -941,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_match_string(pspec, get_key(i)))
|
if (g_pattern_spec_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.
|
||||||
@@ -975,120 +1023,8 @@ void Libs::load(const std::list<std::string> &dicts_dirs,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const gchar *Libs::poGetCurrentWord(glong *iCurrent)
|
bool Libs::LookupSimilarWord(const gchar *sWord, std::set<glong> &iWordIndices, int iLib)
|
||||||
{
|
{
|
||||||
const gchar *poCurrentWord = nullptr;
|
|
||||||
const gchar *word;
|
|
||||||
for (std::vector<Dict *>::size_type iLib = 0; iLib < oLib.size(); iLib++) {
|
|
||||||
if (iCurrent[iLib] == INVALID_INDEX)
|
|
||||||
continue;
|
|
||||||
if (iCurrent[iLib] >= narticles(iLib) || iCurrent[iLib] < 0)
|
|
||||||
continue;
|
|
||||||
if (poCurrentWord == nullptr) {
|
|
||||||
poCurrentWord = poGetWord(iCurrent[iLib], iLib);
|
|
||||||
} else {
|
|
||||||
word = poGetWord(iCurrent[iLib], iLib);
|
|
||||||
|
|
||||||
if (stardict_strcmp(poCurrentWord, word) > 0)
|
|
||||||
poCurrentWord = word;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return poCurrentWord;
|
|
||||||
}
|
|
||||||
|
|
||||||
const gchar *Libs::poGetNextWord(const gchar *sWord, glong *iCurrent)
|
|
||||||
{
|
|
||||||
// the input can be:
|
|
||||||
// (word,iCurrent),read word,write iNext to iCurrent,and return next word. used by TopWin::NextCallback();
|
|
||||||
// (nullptr,iCurrent),read iCurrent,write iNext to iCurrent,and return next word. used by AppCore::ListWords();
|
|
||||||
const gchar *poCurrentWord = nullptr;
|
|
||||||
size_t iCurrentLib = 0;
|
|
||||||
const gchar *word;
|
|
||||||
|
|
||||||
for (size_t iLib = 0; iLib < oLib.size(); ++iLib) {
|
|
||||||
if (sWord)
|
|
||||||
oLib[iLib]->Lookup(sWord, iCurrent[iLib]);
|
|
||||||
if (iCurrent[iLib] == INVALID_INDEX)
|
|
||||||
continue;
|
|
||||||
if (iCurrent[iLib] >= narticles(iLib) || iCurrent[iLib] < 0)
|
|
||||||
continue;
|
|
||||||
if (poCurrentWord == nullptr) {
|
|
||||||
poCurrentWord = poGetWord(iCurrent[iLib], iLib);
|
|
||||||
iCurrentLib = iLib;
|
|
||||||
} else {
|
|
||||||
word = poGetWord(iCurrent[iLib], iLib);
|
|
||||||
|
|
||||||
if (stardict_strcmp(poCurrentWord, word) > 0) {
|
|
||||||
poCurrentWord = word;
|
|
||||||
iCurrentLib = iLib;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (poCurrentWord) {
|
|
||||||
iCurrent[iCurrentLib]++;
|
|
||||||
for (std::vector<Dict *>::size_type iLib = 0; iLib < oLib.size(); iLib++) {
|
|
||||||
if (iLib == iCurrentLib)
|
|
||||||
continue;
|
|
||||||
if (iCurrent[iLib] == INVALID_INDEX)
|
|
||||||
continue;
|
|
||||||
if (iCurrent[iLib] >= narticles(iLib) || iCurrent[iLib] < 0)
|
|
||||||
continue;
|
|
||||||
if (strcmp(poCurrentWord, poGetWord(iCurrent[iLib], iLib)) == 0)
|
|
||||||
iCurrent[iLib]++;
|
|
||||||
}
|
|
||||||
poCurrentWord = poGetCurrentWord(iCurrent);
|
|
||||||
}
|
|
||||||
return poCurrentWord;
|
|
||||||
}
|
|
||||||
|
|
||||||
const gchar *
|
|
||||||
Libs::poGetPreWord(glong *iCurrent)
|
|
||||||
{
|
|
||||||
// used by TopWin::PreviousCallback(); the iCurrent is cached by AppCore::TopWinWordChange();
|
|
||||||
const gchar *poCurrentWord = nullptr;
|
|
||||||
std::vector<Dict *>::size_type iCurrentLib = 0;
|
|
||||||
const gchar *word;
|
|
||||||
|
|
||||||
for (std::vector<Dict *>::size_type iLib = 0; iLib < oLib.size(); iLib++) {
|
|
||||||
if (iCurrent[iLib] == INVALID_INDEX)
|
|
||||||
iCurrent[iLib] = narticles(iLib);
|
|
||||||
else {
|
|
||||||
if (iCurrent[iLib] > narticles(iLib) || iCurrent[iLib] <= 0)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (poCurrentWord == nullptr) {
|
|
||||||
poCurrentWord = poGetWord(iCurrent[iLib] - 1, iLib);
|
|
||||||
iCurrentLib = iLib;
|
|
||||||
} else {
|
|
||||||
word = poGetWord(iCurrent[iLib] - 1, iLib);
|
|
||||||
if (stardict_strcmp(poCurrentWord, word) < 0) {
|
|
||||||
poCurrentWord = word;
|
|
||||||
iCurrentLib = iLib;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (poCurrentWord) {
|
|
||||||
iCurrent[iCurrentLib]--;
|
|
||||||
for (std::vector<Dict *>::size_type iLib = 0; iLib < oLib.size(); iLib++) {
|
|
||||||
if (iLib == iCurrentLib)
|
|
||||||
continue;
|
|
||||||
if (iCurrent[iLib] > narticles(iLib) || iCurrent[iLib] <= 0)
|
|
||||||
continue;
|
|
||||||
if (strcmp(poCurrentWord, poGetWord(iCurrent[iLib] - 1, iLib)) == 0) {
|
|
||||||
iCurrent[iLib]--;
|
|
||||||
} else {
|
|
||||||
if (iCurrent[iLib] == narticles(iLib))
|
|
||||||
iCurrent[iLib] = INVALID_INDEX;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return poCurrentWord;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|
||||||
{
|
|
||||||
glong iIndex;
|
|
||||||
bool bFound = false;
|
bool bFound = false;
|
||||||
gchar *casestr;
|
gchar *casestr;
|
||||||
|
|
||||||
@@ -1096,7 +1032,7 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
// to lower case.
|
// to lower case.
|
||||||
casestr = g_utf8_strdown(sWord, -1);
|
casestr = g_utf8_strdown(sWord, -1);
|
||||||
if (strcmp(casestr, sWord)) {
|
if (strcmp(casestr, sWord)) {
|
||||||
if (oLib[iLib]->Lookup(casestr, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
@@ -1104,21 +1040,21 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
if (!bFound) {
|
if (!bFound) {
|
||||||
casestr = g_utf8_strup(sWord, -1);
|
casestr = g_utf8_strup(sWord, -1);
|
||||||
if (strcmp(casestr, sWord)) {
|
if (strcmp(casestr, sWord)) {
|
||||||
if (oLib[iLib]->Lookup(casestr, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
}
|
}
|
||||||
// Upper the first character and lower others.
|
// Upper the first character and lower others.
|
||||||
if (!bFound) {
|
if (!bFound) {
|
||||||
gchar *nextchar = g_utf8_next_char(sWord);
|
const gchar *rest = g_utf8_next_char(sWord);
|
||||||
gchar *firstchar = g_utf8_strup(sWord, nextchar - sWord);
|
gchar *firstchar = g_utf8_strup(sWord, rest - sWord);
|
||||||
nextchar = g_utf8_strdown(nextchar, -1);
|
gchar *rest_lowercase = g_utf8_strdown(rest, -1);
|
||||||
casestr = g_strdup_printf("%s%s", firstchar, nextchar);
|
casestr = g_strconcat(firstchar, rest_lowercase, nullptr);
|
||||||
|
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, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
@@ -1138,12 +1074,12 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
if (isupcase || sWord[iWordLen - 1] == 's' || !strncmp(&sWord[iWordLen - 2], "ed", 2)) {
|
if (isupcase || sWord[iWordLen - 1] == 's' || !strncmp(&sWord[iWordLen - 2], "ed", 2)) {
|
||||||
strcpy(sNewWord, sWord);
|
strcpy(sNewWord, sWord);
|
||||||
sNewWord[iWordLen - 1] = '\0'; // cut "s" or "d"
|
sNewWord[iWordLen - 1] = '\0'; // cut "s" or "d"
|
||||||
if (oLib[iLib]->Lookup(sNewWord, iIndex))
|
if (oLib[iLib]->Lookup(sNewWord, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
||||||
casestr = g_ascii_strdown(sNewWord, -1);
|
casestr = g_ascii_strdown(sNewWord, -1);
|
||||||
if (strcmp(casestr, sNewWord)) {
|
if (strcmp(casestr, sNewWord)) {
|
||||||
if (oLib[iLib]->Lookup(casestr, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
@@ -1161,13 +1097,13 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
&& !bIsVowel(sNewWord[iWordLen - 4]) && bIsVowel(sNewWord[iWordLen - 5])) { // doubled
|
&& !bIsVowel(sNewWord[iWordLen - 4]) && bIsVowel(sNewWord[iWordLen - 5])) { // doubled
|
||||||
|
|
||||||
sNewWord[iWordLen - 3] = '\0';
|
sNewWord[iWordLen - 3] = '\0';
|
||||||
if (oLib[iLib]->Lookup(sNewWord, iIndex))
|
if (oLib[iLib]->Lookup(sNewWord, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
else {
|
else {
|
||||||
if (isupcase || g_ascii_isupper(sWord[0])) {
|
if (isupcase || g_ascii_isupper(sWord[0])) {
|
||||||
casestr = g_ascii_strdown(sNewWord, -1);
|
casestr = g_ascii_strdown(sNewWord, -1);
|
||||||
if (strcmp(casestr, sNewWord)) {
|
if (strcmp(casestr, sNewWord)) {
|
||||||
if (oLib[iLib]->Lookup(casestr, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
@@ -1177,12 +1113,12 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!bFound) {
|
if (!bFound) {
|
||||||
if (oLib[iLib]->Lookup(sNewWord, iIndex))
|
if (oLib[iLib]->Lookup(sNewWord, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
||||||
casestr = g_ascii_strdown(sNewWord, -1);
|
casestr = g_ascii_strdown(sNewWord, -1);
|
||||||
if (strcmp(casestr, sNewWord)) {
|
if (strcmp(casestr, sNewWord)) {
|
||||||
if (oLib[iLib]->Lookup(casestr, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
@@ -1200,13 +1136,13 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
if (iWordLen > 6 && (sNewWord[iWordLen - 4] == sNewWord[iWordLen - 5])
|
if (iWordLen > 6 && (sNewWord[iWordLen - 4] == sNewWord[iWordLen - 5])
|
||||||
&& !bIsVowel(sNewWord[iWordLen - 5]) && bIsVowel(sNewWord[iWordLen - 6])) { // doubled
|
&& !bIsVowel(sNewWord[iWordLen - 5]) && bIsVowel(sNewWord[iWordLen - 6])) { // doubled
|
||||||
sNewWord[iWordLen - 4] = '\0';
|
sNewWord[iWordLen - 4] = '\0';
|
||||||
if (oLib[iLib]->Lookup(sNewWord, iIndex))
|
if (oLib[iLib]->Lookup(sNewWord, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
else {
|
else {
|
||||||
if (isupcase || g_ascii_isupper(sWord[0])) {
|
if (isupcase || g_ascii_isupper(sWord[0])) {
|
||||||
casestr = g_ascii_strdown(sNewWord, -1);
|
casestr = g_ascii_strdown(sNewWord, -1);
|
||||||
if (strcmp(casestr, sNewWord)) {
|
if (strcmp(casestr, sNewWord)) {
|
||||||
if (oLib[iLib]->Lookup(casestr, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
@@ -1216,12 +1152,12 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!bFound) {
|
if (!bFound) {
|
||||||
if (oLib[iLib]->Lookup(sNewWord, iIndex))
|
if (oLib[iLib]->Lookup(sNewWord, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
||||||
casestr = g_ascii_strdown(sNewWord, -1);
|
casestr = g_ascii_strdown(sNewWord, -1);
|
||||||
if (strcmp(casestr, sNewWord)) {
|
if (strcmp(casestr, sNewWord)) {
|
||||||
if (oLib[iLib]->Lookup(casestr, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
@@ -1232,12 +1168,12 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
strcat(sNewWord, "E"); // add a char "E"
|
strcat(sNewWord, "E"); // add a char "E"
|
||||||
else
|
else
|
||||||
strcat(sNewWord, "e"); // add a char "e"
|
strcat(sNewWord, "e"); // add a char "e"
|
||||||
if (oLib[iLib]->Lookup(sNewWord, iIndex))
|
if (oLib[iLib]->Lookup(sNewWord, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
||||||
casestr = g_ascii_strdown(sNewWord, -1);
|
casestr = g_ascii_strdown(sNewWord, -1);
|
||||||
if (strcmp(casestr, sNewWord)) {
|
if (strcmp(casestr, sNewWord)) {
|
||||||
if (oLib[iLib]->Lookup(casestr, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
@@ -1252,12 +1188,12 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
if (isupcase || (!strncmp(&sWord[iWordLen - 2], "es", 2) && (sWord[iWordLen - 3] == 's' || sWord[iWordLen - 3] == 'x' || sWord[iWordLen - 3] == 'o' || (iWordLen > 4 && sWord[iWordLen - 3] == 'h' && (sWord[iWordLen - 4] == 'c' || sWord[iWordLen - 4] == 's'))))) {
|
if (isupcase || (!strncmp(&sWord[iWordLen - 2], "es", 2) && (sWord[iWordLen - 3] == 's' || sWord[iWordLen - 3] == 'x' || sWord[iWordLen - 3] == 'o' || (iWordLen > 4 && sWord[iWordLen - 3] == 'h' && (sWord[iWordLen - 4] == 'c' || sWord[iWordLen - 4] == 's'))))) {
|
||||||
strcpy(sNewWord, sWord);
|
strcpy(sNewWord, sWord);
|
||||||
sNewWord[iWordLen - 2] = '\0';
|
sNewWord[iWordLen - 2] = '\0';
|
||||||
if (oLib[iLib]->Lookup(sNewWord, iIndex))
|
if (oLib[iLib]->Lookup(sNewWord, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
||||||
casestr = g_ascii_strdown(sNewWord, -1);
|
casestr = g_ascii_strdown(sNewWord, -1);
|
||||||
if (strcmp(casestr, sNewWord)) {
|
if (strcmp(casestr, sNewWord)) {
|
||||||
if (oLib[iLib]->Lookup(casestr, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
@@ -1274,13 +1210,13 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
if (iWordLen > 5 && (sNewWord[iWordLen - 3] == sNewWord[iWordLen - 4])
|
if (iWordLen > 5 && (sNewWord[iWordLen - 3] == sNewWord[iWordLen - 4])
|
||||||
&& !bIsVowel(sNewWord[iWordLen - 4]) && bIsVowel(sNewWord[iWordLen - 5])) { // doubled
|
&& !bIsVowel(sNewWord[iWordLen - 4]) && bIsVowel(sNewWord[iWordLen - 5])) { // doubled
|
||||||
sNewWord[iWordLen - 3] = '\0';
|
sNewWord[iWordLen - 3] = '\0';
|
||||||
if (oLib[iLib]->Lookup(sNewWord, iIndex))
|
if (oLib[iLib]->Lookup(sNewWord, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
else {
|
else {
|
||||||
if (isupcase || g_ascii_isupper(sWord[0])) {
|
if (isupcase || g_ascii_isupper(sWord[0])) {
|
||||||
casestr = g_ascii_strdown(sNewWord, -1);
|
casestr = g_ascii_strdown(sNewWord, -1);
|
||||||
if (strcmp(casestr, sNewWord)) {
|
if (strcmp(casestr, sNewWord)) {
|
||||||
if (oLib[iLib]->Lookup(casestr, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
@@ -1290,12 +1226,12 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!bFound) {
|
if (!bFound) {
|
||||||
if (oLib[iLib]->Lookup(sNewWord, iIndex))
|
if (oLib[iLib]->Lookup(sNewWord, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
||||||
casestr = g_ascii_strdown(sNewWord, -1);
|
casestr = g_ascii_strdown(sNewWord, -1);
|
||||||
if (strcmp(casestr, sNewWord)) {
|
if (strcmp(casestr, sNewWord)) {
|
||||||
if (oLib[iLib]->Lookup(casestr, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
@@ -1314,12 +1250,12 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
strcat(sNewWord, "Y"); // add a char "Y"
|
strcat(sNewWord, "Y"); // add a char "Y"
|
||||||
else
|
else
|
||||||
strcat(sNewWord, "y"); // add a char "y"
|
strcat(sNewWord, "y"); // add a char "y"
|
||||||
if (oLib[iLib]->Lookup(sNewWord, iIndex))
|
if (oLib[iLib]->Lookup(sNewWord, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
||||||
casestr = g_ascii_strdown(sNewWord, -1);
|
casestr = g_ascii_strdown(sNewWord, -1);
|
||||||
if (strcmp(casestr, sNewWord)) {
|
if (strcmp(casestr, sNewWord)) {
|
||||||
if (oLib[iLib]->Lookup(casestr, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
@@ -1337,12 +1273,12 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
strcat(sNewWord, "Y"); // add a char "Y"
|
strcat(sNewWord, "Y"); // add a char "Y"
|
||||||
else
|
else
|
||||||
strcat(sNewWord, "y"); // add a char "y"
|
strcat(sNewWord, "y"); // add a char "y"
|
||||||
if (oLib[iLib]->Lookup(sNewWord, iIndex))
|
if (oLib[iLib]->Lookup(sNewWord, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
||||||
casestr = g_ascii_strdown(sNewWord, -1);
|
casestr = g_ascii_strdown(sNewWord, -1);
|
||||||
if (strcmp(casestr, sNewWord)) {
|
if (strcmp(casestr, sNewWord)) {
|
||||||
if (oLib[iLib]->Lookup(casestr, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
@@ -1356,12 +1292,12 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
if (isupcase || (!strncmp(&sWord[iWordLen - 2], "er", 2))) {
|
if (isupcase || (!strncmp(&sWord[iWordLen - 2], "er", 2))) {
|
||||||
strcpy(sNewWord, sWord);
|
strcpy(sNewWord, sWord);
|
||||||
sNewWord[iWordLen - 2] = '\0';
|
sNewWord[iWordLen - 2] = '\0';
|
||||||
if (oLib[iLib]->Lookup(sNewWord, iIndex))
|
if (oLib[iLib]->Lookup(sNewWord, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
||||||
casestr = g_ascii_strdown(sNewWord, -1);
|
casestr = g_ascii_strdown(sNewWord, -1);
|
||||||
if (strcmp(casestr, sNewWord)) {
|
if (strcmp(casestr, sNewWord)) {
|
||||||
if (oLib[iLib]->Lookup(casestr, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
@@ -1375,12 +1311,12 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
if (isupcase || (!strncmp(&sWord[iWordLen - 3], "est", 3))) {
|
if (isupcase || (!strncmp(&sWord[iWordLen - 3], "est", 3))) {
|
||||||
strcpy(sNewWord, sWord);
|
strcpy(sNewWord, sWord);
|
||||||
sNewWord[iWordLen - 3] = '\0';
|
sNewWord[iWordLen - 3] = '\0';
|
||||||
if (oLib[iLib]->Lookup(sNewWord, iIndex))
|
if (oLib[iLib]->Lookup(sNewWord, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
else if (isupcase || g_ascii_isupper(sWord[0])) {
|
||||||
casestr = g_ascii_strdown(sNewWord, -1);
|
casestr = g_ascii_strdown(sNewWord, -1);
|
||||||
if (strcmp(casestr, sNewWord)) {
|
if (strcmp(casestr, sNewWord)) {
|
||||||
if (oLib[iLib]->Lookup(casestr, iIndex))
|
if (oLib[iLib]->Lookup(casestr, iWordIndices))
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
g_free(casestr);
|
g_free(casestr);
|
||||||
@@ -1390,9 +1326,6 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
|
|
||||||
g_free(sNewWord);
|
g_free(sNewWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bFound)
|
|
||||||
iWordIndex = iIndex;
|
|
||||||
#if 0
|
#if 0
|
||||||
else {
|
else {
|
||||||
//don't change iWordIndex here.
|
//don't change iWordIndex here.
|
||||||
@@ -1403,11 +1336,11 @@ bool Libs::LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|||||||
return bFound;
|
return bFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Libs::SimpleLookupWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
bool Libs::SimpleLookupWord(const gchar *sWord, std::set<glong> &iWordIndices, int iLib)
|
||||||
{
|
{
|
||||||
bool bFound = oLib[iLib]->Lookup(sWord, iWordIndex);
|
bool bFound = oLib[iLib]->Lookup(sWord, iWordIndices);
|
||||||
if (!bFound && fuzzy_)
|
if (!bFound && fuzzy_)
|
||||||
bFound = LookupSimilarWord(sWord, iWordIndex, iLib);
|
bFound = LookupSimilarWord(sWord, iWordIndices, iLib);
|
||||||
return bFound;
|
return bFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -78,8 +77,8 @@ struct DictInfo {
|
|||||||
std::string website;
|
std::string website;
|
||||||
std::string date;
|
std::string date;
|
||||||
std::string description;
|
std::string description;
|
||||||
guint32 index_file_size;
|
off_t index_file_size;
|
||||||
guint32 syn_file_size;
|
off_t 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);
|
||||||
@@ -92,21 +91,31 @@ public:
|
|||||||
guint32 wordentry_size;
|
guint32 wordentry_size;
|
||||||
|
|
||||||
virtual ~IIndexFile() {}
|
virtual ~IIndexFile() {}
|
||||||
virtual bool load(const std::string &url, gulong wc, gulong fsize, bool verbose) = 0;
|
virtual bool load(const std::string &url, gulong wc, off_t 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;
|
||||||
virtual bool lookup(const char *str, glong &idx) = 0;
|
virtual bool lookup(const char *str, std::set<glong> &idxs, glong &next_idx) = 0;
|
||||||
|
virtual bool lookup(const char *str, std::set<glong> &idxs)
|
||||||
|
{
|
||||||
|
glong unused_next_idx;
|
||||||
|
return lookup(str, idxs, unused_next_idx);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
class SynFile
|
class SynFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
SynFile() {}
|
||||||
|
~SynFile() {}
|
||||||
bool load(const std::string &url, gulong wc);
|
bool load(const std::string &url, gulong wc);
|
||||||
bool lookup(const char *str, glong &idx);
|
bool lookup(const char *str, std::set<glong> &idxs, glong &next_idx);
|
||||||
|
bool lookup(const char *str, std::set<glong> &idxs);
|
||||||
|
const gchar *get_key(glong idx) { return synlist[idx]; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, gulong> synonyms;
|
MapFile synfile;
|
||||||
|
std::vector<gchar *> synlist;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Dict : public DictBase
|
class Dict : public DictBase
|
||||||
@@ -133,7 +142,12 @@ public:
|
|||||||
*offset = idx_file->wordentry_offset;
|
*offset = idx_file->wordentry_offset;
|
||||||
*size = idx_file->wordentry_size;
|
*size = idx_file->wordentry_size;
|
||||||
}
|
}
|
||||||
bool Lookup(const char *str, glong &idx);
|
bool Lookup(const char *str, std::set<glong> &idxs, glong &next_idx);
|
||||||
|
bool Lookup(const char *str, std::set<glong> &idxs)
|
||||||
|
{
|
||||||
|
glong unused_next_idx;
|
||||||
|
return Lookup(str, idxs, unused_next_idx);
|
||||||
|
}
|
||||||
|
|
||||||
bool LookupWithRule(GPatternSpec *pspec, glong *aIndex, int iBuffLen);
|
bool LookupWithRule(GPatternSpec *pspec, glong *aIndex, int iBuffLen);
|
||||||
|
|
||||||
@@ -146,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, gulong &idxfilesize);
|
bool load_ifofile(const std::string &ifofilename, off_t &idxfilesize);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Libs
|
class Libs
|
||||||
@@ -181,15 +195,12 @@ public:
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
return oLib[iLib]->get_data(iIndex);
|
return oLib[iLib]->get_data(iIndex);
|
||||||
}
|
}
|
||||||
const gchar *poGetCurrentWord(glong *iCurrent);
|
bool LookupWord(const gchar *sWord, std::set<glong> &iWordIndices, int iLib)
|
||||||
const gchar *poGetNextWord(const gchar *word, glong *iCurrent);
|
|
||||||
const gchar *poGetPreWord(glong *iCurrent);
|
|
||||||
bool LookupWord(const gchar *sWord, glong &iWordIndex, int iLib)
|
|
||||||
{
|
{
|
||||||
return oLib[iLib]->Lookup(sWord, iWordIndex);
|
return oLib[iLib]->Lookup(sWord, iWordIndices);
|
||||||
}
|
}
|
||||||
bool LookupSimilarWord(const gchar *sWord, glong &iWordIndex, int iLib);
|
bool LookupSimilarWord(const gchar *sWord, std::set<glong> &iWordIndices, int iLib);
|
||||||
bool SimpleLookupWord(const gchar *sWord, glong &iWordIndex, int iLib);
|
bool SimpleLookupWord(const gchar *sWord, std::set<glong> &iWordIndices, int iLib);
|
||||||
|
|
||||||
bool LookupWithFuzzy(const gchar *sWord, gchar *reslist[], gint reslist_size);
|
bool LookupWithFuzzy(const gchar *sWord, gchar *reslist[], gint reslist_size);
|
||||||
gint LookupWithRule(const gchar *sWord, gchar *reslist[]);
|
gint LookupWithRule(const gchar *sWord, gchar *reslist[]);
|
||||||
|
|||||||
0
tests/not-unix-newlines-ifo/russian/russian.dict
Normal file
0
tests/not-unix-newlines-ifo/russian/russian.dict
Normal file
0
tests/not-unix-newlines-ifo/russian/russian.idx
Normal file
0
tests/not-unix-newlines-ifo/russian/russian.idx
Normal file
9
tests/not-unix-newlines-ifo/russian/russian.ifo
Normal file
9
tests/not-unix-newlines-ifo/russian/russian.ifo
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
StarDict's dict ifo file
|
||||||
|
version=3.0.0
|
||||||
|
bookname=Russian-English Dictionary (ru-en)
|
||||||
|
wordcount=415144
|
||||||
|
idxfilesize=12344255
|
||||||
|
sametypesequence=h
|
||||||
|
synwordcount=1277580
|
||||||
|
author=Vuizur
|
||||||
|
description=
|
||||||
0
tests/not-unix-newlines-ifo/russian/russian.syn
Normal file
0
tests/not-unix-newlines-ifo/russian/russian.syn
Normal file
BIN
tests/stardict-test_multiple_results-2.4.2/test.dict
Normal file
BIN
tests/stardict-test_multiple_results-2.4.2/test.dict
Normal file
Binary file not shown.
BIN
tests/stardict-test_multiple_results-2.4.2/test.idx
Normal file
BIN
tests/stardict-test_multiple_results-2.4.2/test.idx
Normal file
Binary file not shown.
7
tests/stardict-test_multiple_results-2.4.2/test.ifo
Normal file
7
tests/stardict-test_multiple_results-2.4.2/test.ifo
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
StarDict's dict ifo file
|
||||||
|
version=3.0.0
|
||||||
|
bookname=Test multiple results
|
||||||
|
wordcount=246
|
||||||
|
idxfilesize=5977
|
||||||
|
synwordcount=124
|
||||||
|
description=
|
||||||
BIN
tests/stardict-test_multiple_results-2.4.2/test.syn
Normal file
BIN
tests/stardict-test_multiple_results-2.4.2/test.syn
Normal file
Binary file not shown.
@@ -18,8 +18,15 @@ test_json() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
test_json '[{"name": "Test synonyms", "wordcount": "2"},{"name": "Sample 1 test dictionary", "wordcount": "1"},{"name": "test_dict", "wordcount": "1"}]' -x -j -l -n --data-dir "$TEST_DIR"
|
test_json '[{"name": "Russian-English Dictionary (ru-en)", "wordcount": "415144"},
|
||||||
|
{"name": "Test synonyms", "wordcount": "2"},
|
||||||
|
{"name": "Test multiple results", "wordcount": "246"},
|
||||||
|
{"name": "Sample 1 test dictionary", "wordcount": "1"},
|
||||||
|
{"name": "test_dict", "wordcount": "1"}]' -x -j -l -n --data-dir "$TEST_DIR"
|
||||||
test_json '[{"dict": "Test synonyms","word":"test","definition":"\u000aresult of test"}]' -x -j -n --data-dir "$TEST_DIR" foo
|
test_json '[{"dict": "Test synonyms","word":"test","definition":"\u000aresult of test"}]' -x -j -n --data-dir "$TEST_DIR" foo
|
||||||
test_json '[]' -x -j -n --data-dir "$TEST_DIR" foobarbaaz
|
test_json '[]' -x -j -n --data-dir "$TEST_DIR" foobarbaaz
|
||||||
|
|
||||||
|
# Test multiple searches, with the first failing.
|
||||||
|
test_json '[][{"dict": "Test synonyms","word":"test","definition":"\u000aresult of test"}]' -x -j -n --data-dir "$TEST_DIR" foobarbaaz foo
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
67
tests/t_multiple_results
Executable file
67
tests/t_multiple_results
Executable file
@@ -0,0 +1,67 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SDCV="$1"
|
||||||
|
TEST_DIR="$2"
|
||||||
|
|
||||||
|
unset SDCV_PAGER
|
||||||
|
unset STARDICT_DATA_DIR
|
||||||
|
|
||||||
|
test_json() {
|
||||||
|
word="$1"
|
||||||
|
jq_cmp="$2"
|
||||||
|
result="$("$SDCV" --data-dir "$TEST_DIR" -exjn "$word" | sed 's|\\n|\\u000a|g')"
|
||||||
|
cmp_result="$(echo "$result" | jq "$jq_cmp")"
|
||||||
|
if [ "$cmp_result" != "true" ]; then
|
||||||
|
echo "expected '$jq_cmp' to return true, but $result didn't"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Basic two-result search for the same headword.
|
||||||
|
test_json bark \
|
||||||
|
'. == [
|
||||||
|
{"dict":"Test multiple results","word":"bark","definition":"\u000aThe harsh sound made by a dog."},
|
||||||
|
{"dict":"Test multiple results","word":"bark","definition":"\u000aThe tough outer covering of trees and other woody plants."}
|
||||||
|
]'
|
||||||
|
|
||||||
|
# Multi-result search where one word exists as both a synyonym and a separate
|
||||||
|
# headword. This ensures that if there is a matching synyonym we don't skip the
|
||||||
|
# regular search.
|
||||||
|
test_json cat \
|
||||||
|
'. == [
|
||||||
|
{"dict":"Test multiple results","word":"cat","definition":"\u000aA cute animal which (rarely) barks."},
|
||||||
|
{"dict":"Test multiple results","word":"lion","definition":"\u000aA larger cat which might bite your head off."},
|
||||||
|
{"dict":"Test multiple results","word":"panther","definition":"\u000aI know very little about panthers, sorry."}
|
||||||
|
]'
|
||||||
|
|
||||||
|
# Many-result search for a word that matches 120 distinct headwords.
|
||||||
|
test_json many_headwords 'length == 120'
|
||||||
|
test_json many_headwords 'all(.word == "many_headwords")'
|
||||||
|
test_json many_headwords \
|
||||||
|
'to_entries | map(.value.definition == "\u000aDefinition for [many_headwords] entry #\(.key+1) (same headword).") | all'
|
||||||
|
|
||||||
|
# Many-result search for 120 words that have the same synonym.
|
||||||
|
test_json many_synonyms 'length == 120'
|
||||||
|
test_json many_synonyms \
|
||||||
|
'to_entries | map(.value.word == "many_synonyms-\(.key+101)") | all'
|
||||||
|
test_json many_synonyms \
|
||||||
|
'to_entries | map(.value.definition == "\u000aDefinition for [many_synonyms-\(.key+101)] (same synonym).") | all'
|
||||||
|
|
||||||
|
# Ensure that we don't return more than one result even if a word can be
|
||||||
|
# resolved in more than one way.
|
||||||
|
#
|
||||||
|
# Most well-formed dictionaries don't have entries like this (it basically
|
||||||
|
# requires you to have a dictionary where there is a synonym that is identical
|
||||||
|
# to a word's headword or multiple identical synyonym entries).
|
||||||
|
#
|
||||||
|
# This entry was created by creating extra synonyms with different names then
|
||||||
|
# modifying the .syn file manually.
|
||||||
|
test_json many_resolution_paths \
|
||||||
|
'. == [
|
||||||
|
{"dict":"Test multiple results","word":"many_resolution_paths",
|
||||||
|
"definition":"\u000aDefinition for [many_resolution_paths] headword (same word, multiple synonym entries)."}
|
||||||
|
]'
|
||||||
|
|
||||||
|
exit 0
|
||||||
18
tests/t_newlines_in_ifo
Executable file
18
tests/t_newlines_in_ifo
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
PATH_TO_SDCV="$1"
|
||||||
|
TEST_DIR="$2"
|
||||||
|
|
||||||
|
unset SDCV_PAGER
|
||||||
|
unset STARDICT_DATA_DIR
|
||||||
|
|
||||||
|
RES=$("$PATH_TO_SDCV" -n -x --data-dir="$TEST_DIR/not-unix-newlines-ifo" -l | tail -n 1)
|
||||||
|
|
||||||
|
if [ "$RES" = "Russian-English Dictionary (ru-en) 415144" ]; then
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "test failed, unexpected result: $RES" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user