97 Commits

Author SHA1 Message Date
Evgeniy A. Dushistov
49c8094b53 version 0.5.5 2023-04-18 21:47:55 +03:00
Evgeniy A. Dushistov
4346e65bd3 fix CI build: ubuntu-18.04 not supported by github actions anymore 2023-04-18 21:44:18 +03:00
Evgeniy A. Dushistov
d144e0310c fix CI build 2023-01-16 16:44:09 +03:00
NiLuJe
6e36e7730c Warn on unknown dicts 2022-09-16 18:48:08 +03:00
NiLuJe
abe5e9e72f Check accesses to the bookname_to_ifo std::map
Avoid crashes when passing unknown dicts to the -u flag

Fix #87
2022-09-16 18:48:08 +03:00
NiLuJe
488ec68854 Use off_t for stuff mainly assigned to a stat.st_size value
Allows simplifying the mmap sanity checks in mapfile, and actually
ensuring they won't break when -D_FILE_OFFSET_BITS=64
2022-09-14 22:12:29 +03:00
Marcelino Alberdi Pereira
b698445ead Add a small summary of the project to the README 2022-09-07 17:51:13 +03:00
Evgeniy A. Dushistov
504e7807e6 add information about 0.5.4 into NEWS 2022-06-24 21:49:00 +03:00
Evgeniy A. Dushistov
6c80bf2d99 t_json: add data about new dictionary 2022-06-24 21:34:47 +03:00
Evgeniy A. Dushistov
8742575c33 fix bash syntax error 2022-06-24 21:34:47 +03:00
Evgeniy A. Dushistov
b294b76fb5 check file size before mapping on linux 2022-06-24 21:34:47 +03:00
Evgeniy A. Dushistov
823ec3d840 clang-format for mapfile 2022-06-24 21:34:47 +03:00
Evgeniy A. Dushistov
6ab8b51e6c version 0.5.4 2022-06-24 21:34:47 +03:00
Evgeniy A. Dushistov
881657b336 Revert "replace deprecated g_pattern_match_string function"
This reverts commit 452a4e07fb.
2022-06-24 21:34:47 +03:00
Evgeniy A. Dushistov
911fc2f561 more robust parsing of ifo file
fixes #79 fixes #81
2022-06-24 21:34:47 +03:00
Evgeniy A. Dushistov
f488f5350b stardict_lib.hpp: remove unused headers plus clang-format 2022-06-24 21:34:47 +03:00
Evgeniy A. Dushistov
e72220e748 use cmake to check if compiler supports c++11 2022-06-24 21:34:47 +03:00
Evgeniy A. Dushistov
b77c0e793a replace deprecated g_pattern_match_string function 2022-06-24 21:34:47 +03:00
Evgeniy A. Dushistov
ebaa6f2136 clang-format for stardict_lib.cpp 2022-06-24 21:34:47 +03:00
Aleksa Sarai
d054adb37c tests: add multiple results integration test
Make sure we return all of the relevant results, even in cases with
lots of results (larger than ENTR_PER_PAGE in the offset index) and
where you have a synyonym and headword present for the same word.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-11-14 22:38:26 +03:00
Aleksa Sarai
4a9b1dae3d stardict_lib: remove dead poGet{Current,Next,Pre}Word iterators
They aren't used at all by scdv, and thus aren't tested (meaning that
adaptions to the core lookup algorithms can be complicated because these
methods use them but aren't tested so there's no real way of knowing if
a change has broken the methods or not).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-11-14 22:38:26 +03:00
Aleksa Sarai
6d385221d0 lookup: return all matching entries found during lookup
Previously, we would just return the first entry we found that matched
the requested word. This causes issues with dictionaries that have lots
of entries which can be found using the same search string. In these
cases, the user got a completely arbitrary word returned to them rather
than the full set.

While this may seem strange, this is incredibly commonplace in Japanese
and likely several other languages. In Japanese:

 * When written using kanji, the same string of characters could refer
   to more than one word which may have a completely different meaning.
   Examples include 潜る (くぐる、もぐる) and 辛い (からい、つらい).

 * When written in kana, the same string of characters can also refer to
   more than one word which is written using completely different kanji,
   and has a completely different meaning. Examples include きく
   (聞く、効く、菊) and たつ (立つ、建つ、絶つ).

In both cases, these are different words in every sense of the word, and
have separate headwords for each in the dictionary. Thus in order to be
completely useful for such dictionaries, sdcv needs to be able to return
every matching word in the dictionary.

The solution is conceptually simple -- return a set containing the
indices rather than just a single index. Since every list we search is
sorted (to allow binary searching), once we find one match we can just
walk backwards and forwards from the match point to find the entire
block of matching terms and add them to the set in linear time. A
std::set is used so that we don't return duplicate results needlessly.

This solution was in practice a bit more complicated because .otf cache
files require a bit more fiddling, and also the ->lookup methods are
used by some callers to find the next entry if no entry was found. But
on the whole it's not too drastic of a change from the previous setup.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-11-14 22:38:26 +03:00
Evgeniy Dushistov
3d15ce3b07 Merge pull request #77 from cyphar/multi-word-lookups
lookup: do not bail on first failed lookup with a word list
2021-10-17 21:03:14 +03:00
Aleksa Sarai
51338ac5bb lookup: do not bail on first failed lookup with a word list
Due to the lack of deinflection support in StarDict, users might want to
be able to create a list of possible deinflections and search each one
to see if there is a dictionary entry for that deinflection.

Being able to do this in one sdcv invocation is far more preferable to
calling sdcv once for each candidate due to the performance cost of
doing so. The most obvious language that would benefit from this is
Japanese, but I'm sure other folks would prefer this.

In order to make this use-case better supported -- try to look up every
word in the provided list of words before existing with an error if any
one of the words failed to be looked up.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-09-29 03:28:44 +10:00
Evgeniy Dushistov
5ada75e08d Merge pull request #73 from 258204/json
Added --json (same as --json-output) to match man
2021-06-21 12:45:09 +03:00
258204
c7d9944f7d Added --json (same as --json-output) to match man 2021-06-19 19:19:31 -06:00
Evgeniy Dushistov
3963e358cd Merge pull request #68 from NiLuJe/glib-getopt
Handle "rest" arguments the glib way
2021-01-27 16:33:36 +03:00
NiLuJe
3b26731b02 Making glib thinks it's a filename instead of a string prevents the
initial UTF-8 conversion

At least on POSIX.

Windows is another kettle of fish. But then it was probably already
broken there.
2021-01-14 19:26:06 +01:00
NiLuJe
070a9fb0bd Oh, well, dirty hackery it is, then.
the previous approachonly works as long as locales are actually sane
(i.e., the test only passes if you *actually* have the ru_RU.KOI8-R
locale built, which the CI doesn't).
2021-01-12 04:37:07 +01:00
NiLuJe
8f096629ec Unbreak tests
glib already runs the argument through g_locale_to_utf8 with
G_OPTION_REMAINING
2021-01-12 04:16:03 +01:00
NiLuJe
25768c6b80 Handle "rest" arguments the glib way
Ensures the "stop parsing" token (--) is handled properly.
2021-01-12 03:35:55 +01:00
Evgeniy Dushistov
4ae4207349 Merge pull request #67 from doozan/master
Use binary search for synonyms, fixes #31
2020-12-23 04:30:13 +03:00
Jeff Doozan
994c1c7ae6 Use mapfile directly instead of buffer 2020-12-21 17:10:37 -05:00
Jeff Doozan
d38f8f13c9 Synonyms: Use MapFile 2020-12-21 08:53:29 -05:00
Jeff Doozan
cc7bcb8b73 Fix crash if dictionary has no synonyms 2020-12-19 18:37:15 -05:00
Jeff Doozan
8e9f72ae57 Synonyms lookup: return correct offset 2020-12-19 18:01:21 -05:00
Jeff Doozan
88af1a077c Use binary search for synonyms, fixes #31 2020-12-19 15:10:39 -05:00
Evgeniy Dushistov
b66799f358 Merge pull request #66 from Dushistov/fix-ci
fix ci: github changed API for path/env
2020-12-10 00:42:34 +03:00
Evgeniy A. Dushistov
be5c3a35bf fix ci: github changed API for path/env 2020-12-10 00:40:14 +03:00
Evgeniy A. Dushistov
e73388c726 release 0.5.3 2020-08-14 13:06:51 +03:00
Evgeniy A. Dushistov
7e8fee5e78 update translation and readme 2020-08-14 13:01:18 +03:00
Evgeniy Dushistov
bc890621a9 Merge pull request #64 from Dushistov/to-release
To release
2020-08-14 12:56:08 +03:00
Evgeniy A. Dushistov
0836551bb4 require cmake at least 3.5, and glib 2.36
this should be fine to support ubuntu 16.04 lts
2020-08-14 12:52:37 +03:00
Evgeniy A. Dushistov
824764ab50 handle possibly invalid data: origin_data == nullptr 2020-08-14 12:46:42 +03:00
Evgeniy A. Dushistov
431a5774ba fix warning 2020-08-14 12:37:21 +03:00
Evgeniy A. Dushistov
7facbe215e refactoring: run clang-format against code 2020-08-14 12:36:02 +03:00
Evgeniy Dushistov
79773d6af9 Merge pull request #63 from Dushistov/github-actions
migrate to github actions
2020-08-14 12:30:22 +03:00
Evgeniy A. Dushistov
373bd786d7 CI: remove travis and update link to README 2020-08-14 12:28:01 +03:00
Evgeniy Dushistov
cef6eb5447 Create main.yml 2020-08-14 12:22:10 +03:00
Evgeniy Dushistov
995bdc5bdb Merge pull request #61 from pavelbykov/patch-1
corrected word version
2020-07-04 22:45:27 +03:00
Pavel Bykov
581c2d2b5c corrected word version 2020-07-04 12:30:25 +02:00
Evgeniy Dushistov
958ec353ca Merge pull request #59 from guidocella/xdg
Comply with the XDG Base Directory Specification
2020-05-11 17:19:06 +03:00
Guido Cella
2fd47ba0d0 Keep searching in $HOME 2020-05-10 12:48:32 +02:00
Evgeniy Dushistov
357ca4d453 Merge pull request #60 from guidocella/typo
Typo
2020-05-10 11:40:29 +03:00
Guido Cella
3736ef0060 Typo 2020-05-10 07:19:34 +02:00
Guido Cella
3413d847c5 Comply with the XDG Base Directory Specification 2020-05-10 07:01:31 +02:00
Evgeniy A. Dushistov
780b7dd214 infra: add t_return_code to tests list 2020-03-17 17:13:25 +03:00
Evgeniy Dushistov
08461acab8 Merge pull request #57 from alcah/master
Return exit code 2 if search term not found
2020-03-17 17:09:42 +03:00
alcah
2d1a454026 add return code test 2020-03-17 23:43:16 +10:30
alcah
021e467b37 return exit code 2 if search term not found 2020-03-17 22:15:16 +10:30
Evgeniy Dushistov
a500176661 Merge pull request #44 from nickeb96/master
Added $SDCV_HISTFILE to set history file
2018-05-08 03:21:18 +03:00
nickeb96
7341675088 Moved history file path code to helper function 2018-05-07 20:08:47 -04:00
nickeb96
51f808d96c Updated man page 2018-05-07 18:02:42 -04:00
nickeb96
7719111c57 Added support for 2018-05-07 17:45:07 -04:00
Evgeniy Dushistov
51db56f7e5 Merge pull request #38 from nijel/master
Store integer magic in cache file
2017-11-14 18:52:06 +03:00
Michal Čihař
0f83f0aa0b Store integer magic in cache file
This allows to detect different endianity of machines to avoid
loading caches created with different endianity.

Fixes #36

Signed-off-by: Michal Čihař <michal@cihar.com>
2017-11-14 16:39:57 +01:00
Evgeniy Dushistov
a7432338ee Merge pull request #37 from nijel/test
Use single quotes around JSON data to reduce need for escaping
2017-11-09 18:39:34 +03:00
Michal Čihař
69fe19d269 Use single quotes around JSON data to reduce need for escaping
Also use unicode escape sequence for newline to avoid problems with some
shells decoding \n even when they probably should not.
2017-11-08 22:51:23 +01:00
Evgeniy Dushistov
b9a1fba5bb Merge pull request #35 from nijel/test
Pass parameters individually to the test
2017-11-09 00:32:26 +03:00
Michal Čihař
ac2acfdcd2 Pass parameters individually to the test
This way we can properly quote path.
2017-11-08 15:38:10 +01:00
Evgeniy Dushistov
925a4bc163 Merge pull request #34 from nijel/test
Fix test execution on Debian
2017-11-08 16:59:34 +03:00
Michal Čihař
4b6486c58e Fix test execution on Debian
The default /bin/sh is probably more picky than bash.

Fixes #33
2017-11-08 14:30:37 +01:00
Evgeniy A. Dushistov
0cd29823cf ready for 0.5.2 release 2017-08-16 10:14:23 +03:00
Evgeniy A. Dushistov
8f16ceae59 refactoring: apply clang-format rules 2017-08-09 07:46:27 +03:00
Evgeniy A. Dushistov
d0c0a0837f fix: do not give interactive menu via pager
fixes #28
2017-08-09 07:41:33 +03:00
Evgeniy Dushistov
d5698bdf33 Merge pull request #26 from ecraven/no-fuzzy-option
Add -e for exact searches (no fuzzy matches).
2017-07-31 21:16:31 +03:00
Peter
7518be74f9 Regenerate translations in po/
Run xgettext -k_ src/*.cpp and merge with msgmerge.
2017-07-31 19:27:12 +02:00
Peter
59a821c8f9 Update man page, add -x, -j and -e.
Also fix a few typos.
2017-07-31 19:10:02 +02:00
Evgeniy A. Dushistov
c9a55c90bd update NEWS 2017-07-29 23:32:59 +03:00
Peter
e85927e562 Add -e for exact searches (no fuzzy matches).
Only exact matches (or synonyms) are returned for simple searches.
2017-07-28 11:39:34 +02:00
Evgeniy Dushistov
586215fda7 Merge pull request #25 from ecraven/add-content-types
Add additional type identifiers h,w,k
2017-07-28 00:09:29 +03:00
Peter
835dffcaf8 Add additional type identifiers h,w,k
Like for xdxf, no processing is done, the raw content is shown.
2017-07-27 08:15:45 +02:00
Evgeniy Dushistov
af6362f5df Merge pull request #23 from sleep-walker/master
fix FSF address in LICENSE
2017-07-27 00:30:30 +03:00
Evgeniy Dushistov
25dd4c8264 Merge pull request #22 from ecraven/json
Add json output, fix #6
2017-07-26 23:55:59 +03:00
Tomáš Čech
98e98d0746 fix FSF address 2017-07-26 22:39:28 +02:00
Peter
3105823e8b Add option --json-output (-j)
If given -j, format the output of -l and of searches as JSON.
2017-07-26 22:07:23 +02:00
Evgeniy A. Dushistov
edf73656aa update manpage about $(HOME)/.sdcv_ordering
This should close #5
2017-07-13 00:15:30 +03:00
Peter
5f0f6e036f Add option --only-data-dir (-x)
Only use the dictionaries in data-dir, do not search in user and system directories

This makes testing much easier
2017-07-07 08:39:26 +02:00
Evgeniy A. Dushistov
6c01e22961 add note in NEWS about fixing #8 2017-07-07 00:20:41 +03:00
Evgeniy A. Dushistov
214fbbf91e fix portability issue in PR #20 , plus simplify code 2017-07-07 00:19:50 +03:00
Evgeniy Dushistov
f510300f59 Merge pull request #20 from ecraven/master
Add support for .syn synonym files.
2017-07-06 23:57:19 +03:00
Peter
aa42132243 Add tests for synonyms 2017-07-06 19:54:36 +02:00
Peter
4b52181898 Add support for .syn synonym files.
Fixes #8.
2017-07-06 19:46:15 +02:00
Evgeniy A. Dushistov
72a15b70a7 simplify parsing of integers in ifo file 2017-07-06 13:11:02 +03:00
Evgeniy A. Dushistov
4c367fc12c fix build with clang 3.4.1 #19 2017-07-06 11:41:58 +03:00
Evgeniy A. Dushistov
b2ced870ab fix potential undefined behaviour
fix #19
2017-07-04 22:33:14 +03:00
Evgeniy A. Dushistov
b4fc882f25 update NEWS for 0.5.1 2017-04-25 09:52:36 +03:00
58 changed files with 4020 additions and 3362 deletions

View File

@@ -15,7 +15,7 @@ BreakBeforeBinaryOperators: true
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BinPackParameters: true
ColumnLimit: 0
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: false
DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: false

49
.github/workflows/main.yml vendored Normal file
View File

@@ -0,0 +1,49 @@
name: CI
on:
push:
branches:
- master
pull_request:
branches:
- master
schedule:
- cron: '00 02 */4 * *'
env:
RUST_BACKTRACE: 1
jobs:
tests:
name: Run tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-20.04, ubuntu-latest]
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- uses: jwlawson/actions-setup-cmake@v1.4
if: matrix.os != 'ubuntu-latest'
with:
cmake-version: '3.5.1'
github-api-token: ${{ secrets.GITHUB_TOKEN }}
- name: Check versions
run: |
set -e
cmake --version
gcc --version
echo "end of versions checking"
shell: bash
- name: Run tests
run: |
set -e
cd $GITHUB_WORKSPACE
mkdir build
cd build
cmake -DBUILD_TESTS=True ..
make -k -j2 VERBOSE=1
ctest --output-on-failure
shell: bash

View File

@@ -1,48 +0,0 @@
#
# Available repositories are listed here:
# https://github.com/travis-ci/apt-source-whitelist/blob/master/ubuntu.json
#
sudo: false
language: cpp
matrix:
include:
- env: COMPILER_VERSION=4.8
os: linux
compiler: g++
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- kalakris-cmake
- ubuntu-sdk-team
packages:
- g++-4.8
- cmake
- libglib2.0-dev
# - env: COMPILER_VERSION=3.5
# os: linux
# compiler: clang++
# addons:
# apt:
# sources:
# - ubuntu-toolchain-r-test
# - llvm-toolchain-precise-3.5
# packages:
# - clang-3.5
# - cmake
# - libglib2.0-dev
before_script:
- mkdir build
- cd build
- CC=$CC-${COMPILER_VERSION} CXX=$CXX-${COMPILER_VERSION} cmake -DBUILD_TESTS=True ..
- cd ..
script:
- cd build
- make -k -j2 VERBOSE=1
- ctest --output-on-failure

View File

@@ -1,24 +1,18 @@
project(sdcv)
# Older versions have a different signature for CMAKE_MINIMUM_REQUIRED,
# check it manually just to make sure
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.8)
message(FATAL_ERROR "${PROJECT_NAME} requires at least CMake v2.8."
" You are running v${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}."
" Please upgrade." )
endif(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.8)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
cmake_policy(VERSION 3.5)
# If we get this far, use the modern signature. This will also cause newer
# CMake versions to try to be backwards-compatible with the desired version
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
cmake_policy(VERSION 2.8)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS False)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/compiler.cmake")
set(ZLIB_FIND_REQUIRED True)
include(FindZLIB)
set(GLIB2_REQ "'glib-2.0 >= 2.6.1'")
set(GLIB2_REQ "'glib-2.0 >= 2.36'")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindGLIB2.cmake")
@@ -101,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_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "5")
set(CPACK_PACKAGE_VERSION_PATCH "1")
set(CPACK_PACKAGE_VERSION_PATCH "5")
set(sdcv_VERSION
"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
@@ -144,9 +138,16 @@ if (BUILD_TESTS)
add_sdcv_shell_test(t_list)
add_sdcv_shell_test(t_use)
add_sdcv_shell_test(t_only_data_dir)
add_sdcv_shell_test(t_synonyms)
add_sdcv_shell_test(t_json)
add_sdcv_shell_test(t_exact)
add_sdcv_shell_test(t_interactive)
add_sdcv_shell_test(t_utf8output)
add_sdcv_shell_test(t_utf8input)
add_sdcv_shell_test(t_datadir)
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)

11
LICENSE
View File

@@ -1,10 +1,11 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
@@ -305,7 +306,7 @@ the "copyright" line and a pointer to where the full notice is found.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.

28
NEWS
View File

@@ -1,3 +1,31 @@
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
- Use single quotes around JSON data to reduce need for escaping
- Store integer magic in cache file
- Added $SDCV_HISTFILE to set history file
- return exit code 2 if search term not found
- Comply with the XDG Base Directory Specification
Version 0.5.2
- Synonyms index support (.syn files) by Peter <craven@gmx.net>
- Add support of json output by Peter <craven@gmx.net> (--json-output)
- Add -e for exact searches (no fuzzy matches) by Peter <craven@gmx.net>
- Fix build with clang 3.4.1
- fix FSF address in license by Tomáš Čech <sleep_walker@suse.com>
Version 0.5.1
Fix usage of SDCV_PAGER by Anton Yuzhaninov
Fix build without readline<
specify dictionary order by -u switches or ~/.sdcv_ordering by Cong Gu
Version 0.5
- add option to colorize output
- Roman Imankulov's patch to better use of readline

View File

@@ -1,6 +1,9 @@
#+OPTIONS: ^:nil
[[https://travis-ci.org/Dushistov/sdcv][https://travis-ci.org/Dushistov/sdcv.svg?branch=master]]
[[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]]
* 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
#+BEGIN_SRC sh
mkdir /tmp/build-sdcv
@@ -22,12 +25,20 @@ you can use "DESTDIR" variable to change installation path
See sdcv man page for usage description.
* Bugs
If you find bug reports it via email to dushistov at mail dot ru.
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.
Be sure to include the word "sdcv" somewhere in the "Subject:" field.
* Notes to developer
** make source code release
#+BEGIN_SRC sh
make package_source
#+END_SRC
** update translation
#+BEGIN_SRC sh
cd po
xgettext -k_ ../src/*.cpp -o new.pot
msgmerge -U sdcv.pot new.pot
rm new.pot
for i in `ls *.po`; do msgmerge -U $i sdcv.pot; done
#+END_SRC

View File

@@ -16,19 +16,6 @@ if (NOT DEFINED SDCV_COMPILER_IS_GCC_COMPATIBLE)
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)
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)

View File

@@ -9,78 +9,95 @@ sdcv \- console version of StarDict program
[list of words]
.SH DESCRIPTION
.I sdcv
is simple, cross-platform text-base utility
for work with dictionaries in StarDict's format.
The word from "list of words" may be string
with leading '/' for using Fuzzy search algorithm,
with leading '|' for using full-text search,
string may contain '?' and '*' for using regexp search.
It work in interactive and not interactive mode.
is a simple, cross-platform text-based utility
for working with dictionaries in StarDict format.
Each word from "list of words" may be a string
with a leading '/' for using a Fuzzy search algorithm,
with a leading '|' for using full-text search,
and the string may contain '?' and '*' for regexp search.
It works in interactive and non-interactive mode.
To exit from interactive mode press Ctrl+D.
In interactive mode,
if sdcv was compiled with readline library support,
you can use UP and DOWN keys to work through history.
you can use the UP and DOWN keys to cycle through history.
.SH OPTIONS
.TP 8
.B "\-h \-\-help"
display help message and exit
Display help message and exit
.TP 8
.B "\-v \-\-verbose"
display version and exit
.B "\-v \-\-version"
Display version and exit
.TP 8
.B "\-l \-\-list\-dicts"
display list of available dictionaries and exit
Display list of available dictionaries and exit
.TP 8
.B "\-u \-\-use\-dict filename"
for search use only dictionary with this bookname
For search use only dictionary with this bookname
.TP 8
.B "\-n \-\-non\-interactive"
for use in scripts
For use in scripts
.TP 8
.B "\-x \-\-only\-data\-dir"
For use in scripts: only use the dictionaries in data-dir, do not search in user and system directories
.TP 8
.B "\-e \-\-exact\-search"
Do not fuzzy-search for similar words, only return exact matches
.TP 8
.B "\-j \-\-json"
Print the results of list-dicts and searches as json, not as plain text.
For use in automatically processing the results of a dictionary lookup.
.TP 8
.B "\-\-utf8\-output"
Force sdcv not use conversation to locale charset, output in utf8
Force sdcv to not convert to locale charset, output in utf8
.TP 8
.B "\-\-utf8\-input"
Force sdcv not use conversation from locale charset, suppose that
input in utf8
Force sdcv to not convert from locale charset, assume that
input is in utf8
.TP 8
.B "\-\-data\-dir path/to/directory"
Use this directory as path to stardict data directory. This is mean that
sdcv search dictionaries in data-dir/dic directory.
Use this directory as the path to the stardict data directory. This means that
sdcv searches for dictionaries in data-dir/dic directory.
.TP 8
.B "\-\-color"
Use ANSI escape code for colorize sdcv output
Use ANSI escape codes for colorizing sdcv output (does not work with json output).
.SH FILES
.TP
/usr/share/stardict/dic
.TP
$(HOME)/.stardict/dic
$(XDG_DATA_HOME)/stardict/dic
Place, where sdcv expect to find dictionaries.
Instead of /usr/share/stardict/dic you can use everything
that you want, just set STARDICT_DATA_DIR environment variable.
Place where sdcv expects to find dictionaries.
Instead of /usr/share/stardict/dic you can use any directory
you want, just set the STARDICT_DATA_DIR environment variable.
For example, if you have dictionaries in /mnt/data/stardict-dicts/dic,
set STARDICT_DATA_DIR to /mnt/data/stardict-dicts.
.TP
$(HOME)/.sdcv_history
$(XDG_DATA_HOME)/sdcv_history
This file include last $(SDCV_HISTSIZE) words, which you seek with sdcv.
SDCV use this file only if it was compiled with readline library support.
This file includes the last $(SDCV_HISTSIZE) words, which you sought with sdcv.
SDCV uses this file only if it was compiled with readline library support.
.TP
$(XDG_CONFIG_HOME)/sdcv_ordering
This is a text file containing one dictionary bookname per line.
It specifies in which order the results of a search should be shown.
.SH ENVIRONMENT
Environment Variables Used By \fIsdcv\fR:
.TP 20
.B STARDICT_DATA_DIR
If set, sdcv use this variable as data directory, this is mean that sdcv
search dictionaries in $\fBSTARDICT_DATA_DIR\fR\\dic
If set, sdcv uses this variable as the data directory, this means that sdcv
searches dictionaries in $\fBSTARDICT_DATA_DIR\fR/dic
.TP 20
.B SDCV_HISTSIZE
If set, sdcv wrote in $(HOME)/.sdcv_history only last $(SDCV_HISTSIZE) words,
which you seek using sdcv. If it is not set, then last 2000 words saved in $(HOME)/.sdcv_history.
If set, sdcv writes in $(XDG_DATA_HOME)/sdcv_history (or $(SDCV_HISTFILE)) the last $(SDCV_HISTSIZE) words,
which you look up using sdcv. If it is not set, then the last 2000 words are saved in $(XDG_DATA_HOME)/sdcv_history.
.TP 20
.B SDCV_HISTFILE
If set, sdcv writes it's history to $(SDCV_HISTFILE). If it is not set, then the default $(XDG_DATA_HOME)/sdcv_history path will be used.
.TP 20
.B SDCV_PAGER
If SDCV_PAGER is set, its value is used as the name of the program
to use to display the dictionary's article.
to use to display the dictionary article.
.SH BUGS
Email bug reports to dushistov at mail dot ru. Be sure to include the word
"sdcv" somewhere in the "Subject:" field.

View File

@@ -50,7 +50,7 @@ sdcv проста, міжплатформена текстова утиліта
.TP
/usr/share/stardict/dic
.TP
$(HOME)/.stardict/dic
$(XDG_DATA_HOME)/stardict/dic
Місце, де sdcv очікує знайти словники.
Замість шляху /usr/share/stardict/dic Ви можете використовувати все,
@@ -58,7 +58,7 @@ $(HOME)/.stardict/dic
Наприклад, якщо Ви маєте словники у теці /mnt/data/stardict-dicts/dic,
встановіть STARDICT_DATA_DIR у /mnt/data/stardict-dicts.
.TP
$(HOME)/.sdcv_history
$(XDG_DATA_HOME)/sdcv_history
Цей файл містить останні $(SDCV_HISTSIZE) слова, які Ви шукали з sdcv.
SDCV використовує цей файл при умові, якщо sdcv був скомпільований
@@ -69,12 +69,12 @@ SDCV використовує цей файл при умові, якщо sdcv
.TP 20
.B STARDICT_DATA_DIR
Якщо встановлена, sdcv використає цю змінну як теку даних, це означає,
що sdcv шукатиме словники у $\fBSTARDICT_DATA_DIR\fR\dic
що sdcv шукатиме словники у $\fBSTARDICT_DATA_DIR\fR/dic
.TP 20
.B SDCV_HISTSIZE
Якщо встановлена, sdcv писатиме у $(HOME)/.sdcv_history лише
Якщо встановлена, sdcv писатиме у $(XDG_DATA_HOME)/sdcv_history лише
останні $(SDCV_HISTSIZE) слова, які Ви шукали з sdcv. Якщо не встановлена,
то збірігатиметься останніх 2000 слів у $(HOME)/.sdcv_history.
то збірігатиметься останніх 2000 слів у $(XDG_DATA_HOME)/sdcv_history.
.SH BUGS
Звіти про помилки висилайте на адресу dushistov на mail крапка ru.
Не забувайте включати слово "sdcv" десь у полі "Тема:".

188
po/cs.po
View File

@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: sdcv 0.4.2\n"
"Report-Msgid-Bugs-To: dushistov@mail.ru\n"
"POT-Creation-Date: 2008-09-24 10:54+0200\n"
"POT-Creation-Date: 2020-08-14 12:58+0300\n"
"PO-Revision-Date: 2008-09-24 10:42+0200\n"
"Last-Translator: Michal Čihař <michal@cihar.com>\n"
"Language-Team: Czech <cs@li.org>\n"
@@ -16,102 +16,25 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
#: src/sdcv.cpp:108
#, fuzzy
msgid "display version information and exit"
msgstr "-v, --version zobrazí informace o verzi a skončí\n"
#: src/sdcv.cpp:110
#, fuzzy
msgid "display list of available dictionaries and exit"
msgstr "-l, --list-dicts zobrazí seznam dostupných slovníků a skončí\n"
#: src/sdcv.cpp:112
#, fuzzy
msgid "for search use only dictionary with this bookname"
msgstr "-u, --use-dict jméno vyhledávat jen v zadaném slovníku\n"
#: src/sdcv.cpp:113
msgid "bookname"
msgstr ""
#: src/sdcv.cpp:115
msgid "for use in scripts"
msgstr ""
#: src/sdcv.cpp:117
#, fuzzy
msgid "output must be in utf8"
msgstr "--utf8-output výstup musí být v utf8\n"
#: src/sdcv.cpp:119
#, fuzzy
msgid "input of sdcv in utf8"
msgstr "--utf8-input vstup musí být v utf8\n"
#: src/sdcv.cpp:121
#, fuzzy
msgid "use this directory as path to stardict data directory"
msgstr ""
"--data-dir cesta/někam použít tento adresář jako cestu ke slovníkům "
"stardict\n"
#: src/sdcv.cpp:122
msgid "path/to/dir"
msgstr ""
#: src/sdcv.cpp:129
msgid " words"
msgstr ""
#: src/sdcv.cpp:135
#, c-format
msgid "Invalid command line arguments: %s\n"
msgstr ""
#: src/sdcv.cpp:141
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr "Konzolová verze Stardictu, verze %s\n"
#: src/sdcv.cpp:170
#, c-format
msgid "Dictionary's name Word count\n"
msgstr "Jméno slovníku Počet slov\n"
#: src/sdcv.cpp:192
#, c-format
msgid "g_mkdir failed: %s\n"
msgstr "g_mkdir selhalo: %s\n"
#: src/sdcv.cpp:208
msgid "Enter word or phrase: "
msgstr "Zadejte slovo nebo frázi: "
#: src/sdcv.cpp:216
#, c-format
msgid "There are no words/phrases to translate.\n"
msgstr "Nebyla zadáno nic k přeložení.\n"
#: src/libwrapper.cpp:248
#: ../src/libwrapper.cpp:300
msgid "popen failed"
msgstr "popen selhalo"
#: src/libwrapper.cpp:285 src/utils.cpp:67
#: ../src/libwrapper.cpp:341
#, c-format
msgid "Can not convert %s to utf8.\n"
msgstr "Nepodařilo se převést %s do utf8.\n"
#: src/libwrapper.cpp:342 src/libwrapper.cpp:370
#: ../src/libwrapper.cpp:399 ../src/libwrapper.cpp:433
#, fuzzy, c-format
msgid "Found %zu items, similar to %s.\n"
msgstr "Nalezeno %d záznamů podobných %s.\n"
#: src/libwrapper.cpp:356
#: ../src/libwrapper.cpp:417
msgid "Your choice[-1 to abort]: "
msgstr "Vaše volba [-1 pro ukončení]: "
#: src/libwrapper.cpp:365
#: ../src/libwrapper.cpp:427
#, fuzzy, c-format
msgid ""
"Invalid choice.\n"
@@ -120,12 +43,107 @@ msgstr ""
"Chybná volba.\n"
"Musí být mezi 0 a %d nebo -1.\n"
#: src/libwrapper.cpp:381
#: ../src/libwrapper.cpp:446
#, c-format
msgid "Nothing similar to %s, sorry :(\n"
msgstr "Nic podobného %s nenalezeno, promiň :(\n"
#: src/utils.cpp:45
#: ../src/sdcv.cpp:89
#, fuzzy
msgid "display version information and exit"
msgstr "-v, --version zobrazí informace o verzi a skončí\n"
#: ../src/sdcv.cpp:91
#, fuzzy
msgid "display list of available dictionaries and exit"
msgstr "-l, --list-dicts zobrazí seznam dostupných slovníků a skončí\n"
#: ../src/sdcv.cpp:93
#, fuzzy
msgid "for search use only dictionary with this bookname"
msgstr "-u, --use-dict jméno vyhledávat jen v zadaném slovníku\n"
#: ../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 ""
#: ../src/sdcv.cpp:100
msgid "do not fuzzy-search for similar words, only return exact matches"
msgstr ""
#: ../src/sdcv.cpp:102
#, fuzzy
msgid "output must be in utf8"
msgstr "--utf8-output výstup musí být v utf8\n"
#: ../src/sdcv.cpp:104
#, fuzzy
msgid "input of sdcv in utf8"
msgstr "--utf8-input vstup musí být v utf8\n"
#: ../src/sdcv.cpp:106
#, fuzzy
msgid "use this directory as path to stardict data directory"
msgstr ""
"--data-dir cesta/někam použít tento adresář jako cestu ke slovníkům "
"stardict\n"
#: ../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 ""
#: ../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 ""
#: ../src/sdcv.cpp:128
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr "Konzolová verze Stardictu, verze %s\n"
#: ../src/sdcv.cpp:206
#, c-format
msgid "g_mkdir failed: %s\n"
msgstr "g_mkdir selhalo: %s\n"
#: ../src/sdcv.cpp:222
msgid "Enter word or phrase: "
msgstr "Zadejte slovo nebo frázi: "
#: ../src/sdcv.cpp:230
#, c-format
msgid "There are no words/phrases to translate.\n"
msgstr "Nebyla zadáno nic k přeložení.\n"
#: ../src/sdcv.cpp:242
#, c-format
msgid "Dictionary's name Word count\n"
msgstr "Jméno slovníku Počet slov\n"
#: ../src/utils.cpp:48
#, fuzzy, c-format
msgid "Can not convert %s to current locale.\n"
msgstr "Nepodařilo se převést %s do utf8.\n"

198
po/fr.po
View File

@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: sdcv 0.4.2\n"
"Report-Msgid-Bugs-To: dushistov@mail.ru\n"
"POT-Creation-Date: 2008-09-24 10:54+0200\n"
"POT-Creation-Date: 2020-08-14 12:58+0300\n"
"PO-Revision-Date: 2009-06-15 23:20+0800\n"
"Language-Team: Vincent Petry <PVince81@yahoo.fr>\n"
"Language: \n"
@@ -18,107 +18,25 @@ msgstr ""
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
#: src/sdcv.cpp:108
#, fuzzy
msgid "display version information and exit"
msgstr ""
"-v, --version afficher les informations de version et sortir\n"
#: src/sdcv.cpp:110
#, fuzzy
msgid "display list of available dictionaries and exit"
msgstr ""
"-l, --list-dicts afficher la liste des dictionnaires disponibles et "
"sortir\n"
#: src/sdcv.cpp:112
#, fuzzy
msgid "for search use only dictionary with this bookname"
msgstr ""
"-u, --use-dict nom_dict pour chercher seulement en utilisant le "
"dictionnaire spécifié\n"
#: src/sdcv.cpp:113
msgid "bookname"
msgstr ""
#: src/sdcv.cpp:115
msgid "for use in scripts"
msgstr ""
#: src/sdcv.cpp:117
#, fuzzy
msgid "output must be in utf8"
msgstr "--utf8-output force la sortie au format utf8\n"
#: src/sdcv.cpp:119
#, fuzzy
msgid "input of sdcv in utf8"
msgstr "--utf8-input force l'entrée de sdcv au format utf8\n"
#: src/sdcv.cpp:121
#, fuzzy
msgid "use this directory as path to stardict data directory"
msgstr ""
"--data-dir chemin utiliser ce chemin pour trouver les données de "
"stardict\n"
#: src/sdcv.cpp:122
msgid "path/to/dir"
msgstr ""
#: src/sdcv.cpp:129
msgid " words"
msgstr ""
#: src/sdcv.cpp:135
#, c-format
msgid "Invalid command line arguments: %s\n"
msgstr ""
#: src/sdcv.cpp:141
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr "Version console de Stardict, version %s\n"
#: src/sdcv.cpp:170
#, c-format
msgid "Dictionary's name Word count\n"
msgstr "Nom dictionnaire Nombre de mots\n"
#: src/sdcv.cpp:192
#, c-format
msgid "g_mkdir failed: %s\n"
msgstr "Échec de g_mkdir : %s\n"
#: src/sdcv.cpp:208
msgid "Enter word or phrase: "
msgstr "Entrez un mot ou une phrase: "
#: src/sdcv.cpp:216
#, c-format
msgid "There are no words/phrases to translate.\n"
msgstr "Il n'y a pas de mots/phrases à traduire.\n"
#: src/libwrapper.cpp:248
#: ../src/libwrapper.cpp:300
msgid "popen failed"
msgstr "Échec de popen"
#: src/libwrapper.cpp:285 src/utils.cpp:67
#: ../src/libwrapper.cpp:341
#, c-format
msgid "Can not convert %s to utf8.\n"
msgstr "Ne peut convertir %s au format utf8.\n"
#: src/libwrapper.cpp:342 src/libwrapper.cpp:370
#: ../src/libwrapper.cpp:399 ../src/libwrapper.cpp:433
#, fuzzy, c-format
msgid "Found %zu items, similar to %s.\n"
msgstr "Trouvé %d éléments similaires à %s.\n"
#: src/libwrapper.cpp:356
#: ../src/libwrapper.cpp:417
msgid "Your choice[-1 to abort]: "
msgstr "Votre choix[-1 pour abandonner] : "
#: src/libwrapper.cpp:365
#: ../src/libwrapper.cpp:427
#, fuzzy, c-format
msgid ""
"Invalid choice.\n"
@@ -127,12 +45,112 @@ msgstr ""
"Selection invalide.\n"
"Veuillez choisir un nombre entre 0 et %d, ou -1.\n"
#: src/libwrapper.cpp:381
#: ../src/libwrapper.cpp:446
#, c-format
msgid "Nothing similar to %s, sorry :(\n"
msgstr "Aucun mot/phrase similaire à %s, désolé :(\n"
#: src/utils.cpp:45
#: ../src/sdcv.cpp:89
#, fuzzy
msgid "display version information and exit"
msgstr ""
"-v, --version afficher les informations de version et sortir\n"
#: ../src/sdcv.cpp:91
#, fuzzy
msgid "display list of available dictionaries and exit"
msgstr ""
"-l, --list-dicts afficher la liste des dictionnaires disponibles et "
"sortir\n"
#: ../src/sdcv.cpp:93
#, fuzzy
msgid "for search use only dictionary with this bookname"
msgstr ""
"-u, --use-dict nom_dict pour chercher seulement en utilisant le "
"dictionnaire spécifié\n"
#: ../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 ""
#: ../src/sdcv.cpp:100
msgid "do not fuzzy-search for similar words, only return exact matches"
msgstr ""
#: ../src/sdcv.cpp:102
#, fuzzy
msgid "output must be in utf8"
msgstr "--utf8-output force la sortie au format utf8\n"
#: ../src/sdcv.cpp:104
#, fuzzy
msgid "input of sdcv in utf8"
msgstr "--utf8-input force l'entrée de sdcv au format utf8\n"
#: ../src/sdcv.cpp:106
#, fuzzy
msgid "use this directory as path to stardict data directory"
msgstr ""
"--data-dir chemin utiliser ce chemin pour trouver les données de "
"stardict\n"
#: ../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 ""
#: ../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 ""
#: ../src/sdcv.cpp:128
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr "Version console de Stardict, version %s\n"
#: ../src/sdcv.cpp:206
#, c-format
msgid "g_mkdir failed: %s\n"
msgstr "Échec de g_mkdir : %s\n"
#: ../src/sdcv.cpp:222
msgid "Enter word or phrase: "
msgstr "Entrez un mot ou une phrase: "
#: ../src/sdcv.cpp:230
#, c-format
msgid "There are no words/phrases to translate.\n"
msgstr "Il n'y a pas de mots/phrases à traduire.\n"
#: ../src/sdcv.cpp:242
#, c-format
msgid "Dictionary's name Word count\n"
msgstr "Nom dictionnaire Nombre de mots\n"
#: ../src/utils.cpp:48
#, c-format
msgid "Can not convert %s to current locale.\n"
msgstr "Ne peut pas convertir %s dans la locale courante.\n"

183
po/ru.po
View File

@@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: sdcv 0.5\n"
"Report-Msgid-Bugs-To: dushistov@mail.ru\n"
"POT-Creation-Date: 2008-09-24 10:54+0200\n"
"PO-Revision-Date: 2013-07-07 18:49+0400\n"
"POT-Creation-Date: 2020-08-14 12:58+0300\n"
"PO-Revision-Date: 2017-08-16 10:05+0300\n"
"Last-Translator: Evgeniy Dushistov <dushistov@mail.ru>\n"
"Language-Team: Russian <ru@li.org>\n"
"Language: ru\n"
@@ -19,99 +19,25 @@ msgstr ""
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
#: src/sdcv.cpp:76
msgid "display version information and exit"
msgstr "показать номер версии и завершить работу"
#: src/sdcv.cpp:78
msgid "display list of available dictionaries and exit"
msgstr "показать список доступных словарей и завершить работу"
#: src/sdcv.cpp:84
msgid "for search use only dictionary with this bookname"
msgstr "для поиска использовать только этот словарь с таким именем"
#: src/sdcv.cpp:85
msgid "bookname"
msgstr "имя_словаря"
#: src/sdcv.cpp:87
msgid "for use in scripts"
msgstr "для использования в скриптах"
#: src/sdcv.cpp:89
msgid "output must be in utf8"
msgstr "вывод программы должен быть в utf8"
#: src/sdcv.cpp:91
msgid "input of sdcv in utf8"
msgstr "ввод программы в utf8"
#: src/sdcv.cpp:93
msgid "use this directory as path to stardict data directory"
msgstr ""
"использовать эту директорию в качестве пути к \"stardict data\" директории"
#: src/sdcv.cpp:94
msgid "path/to/dir"
msgstr "путь/до/директории"
#: src/sdcv.cpp:96
msgid "colorize the output"
msgstr "раскрашивать вывод в разные цвета"
#: src/sdcv.cpp:101
msgid " words"
msgstr "слова"
#: src/sdcv.cpp:107
#, c-format
msgid "Invalid command line arguments: %s\n"
msgstr "Неправильный аргумент командой строки: %s\n"
#: src/sdcv.cpp:113
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr "Консольная версия StarDict, версия %s\n"
#: src/sdcv.cpp:139
#, c-format
msgid "Dictionary's name Word count\n"
msgstr "Название словаря Количество слов\n"
#: src/sdcv.cpp:174
#, c-format
msgid "g_mkdir failed: %s\n"
msgstr "g_mkdir завершился с ошибкой: %s\n"
#: src/sdcv.cpp:189
msgid "Enter word or phrase: "
msgstr "Введите слово или фразу: "
#: src/sdcv.cpp:197
#, c-format
msgid "There are no words/phrases to translate.\n"
msgstr "Не задано слова/фразы для перевода.\n"
#: src/libwrapper.cpp:280
#: ../src/libwrapper.cpp:300
msgid "popen failed"
msgstr "функция popen завершилась с ошибкой"
#: src/libwrapper.cpp:317 src/utils.cpp:67
#: ../src/libwrapper.cpp:341
#, c-format
msgid "Can not convert %s to utf8.\n"
msgstr "Не могу преобразовать %s в utf8.\n"
#: src/libwrapper.cpp:371 src/libwrapper.cpp:402
#: ../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:388
#: ../src/libwrapper.cpp:417
msgid "Your choice[-1 to abort]: "
msgstr "Ваш выбор[-1 - отмена]: "
#: src/libwrapper.cpp:397
#: ../src/libwrapper.cpp:427
#, c-format
msgid ""
"Invalid choice.\n"
@@ -120,12 +46,103 @@ msgstr ""
"Неправильный выбор.\n"
"Должно быть от 0 до %zu или -1.\n"
#: src/libwrapper.cpp:413
#: ../src/libwrapper.cpp:446
#, c-format
msgid "Nothing similar to %s, sorry :(\n"
msgstr "Ничего похожего на %s, извините :(\n"
#: src/utils.cpp:45
#: ../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 data\" директории"
#: ../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 "Консольная версия StarDict, версия %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

@@ -7,118 +7,133 @@ msgid ""
msgstr ""
"Project-Id-Version: sdcv 0.5\n"
"Report-Msgid-Bugs-To: dushistov@mail.ru\n"
"POT-Creation-Date: 2008-09-24 10:54+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"POT-Creation-Date: 2020-08-14 12:58+0300\n"
"PO-Revision-Date: 2017-08-16 10:01+0300\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: src/sdcv.cpp:76
msgid "display version information and exit"
msgstr ""
#: src/sdcv.cpp:78
msgid "display list of available dictionaries and exit"
msgstr ""
#: src/sdcv.cpp:84
msgid "for search use only dictionary with this bookname"
msgstr ""
#: src/sdcv.cpp:85
msgid "bookname"
msgstr ""
#: src/sdcv.cpp:87
msgid "for use in scripts"
msgstr ""
#: src/sdcv.cpp:89
msgid "output must be in utf8"
msgstr ""
#: src/sdcv.cpp:91
msgid "input of sdcv in utf8"
msgstr ""
#: src/sdcv.cpp:93
msgid "use this directory as path to stardict data directory"
msgstr ""
#: src/sdcv.cpp:94
msgid "path/to/dir"
msgstr ""
#: src/sdcv.cpp:96
msgid "colorize the output"
msgstr ""
#: src/sdcv.cpp:101
msgid " words"
msgstr ""
#: src/sdcv.cpp:107
#, c-format
msgid "Invalid command line arguments: %s\n"
msgstr ""
#: src/sdcv.cpp:113
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr ""
#: src/sdcv.cpp:139
#, c-format
msgid "Dictionary's name Word count\n"
msgstr ""
#: src/sdcv.cpp:174
#, c-format
msgid "g_mkdir failed: %s\n"
msgstr ""
#: src/sdcv.cpp:189
msgid "Enter word or phrase: "
msgstr ""
#: src/sdcv.cpp:197
#, c-format
msgid "There are no words/phrases to translate.\n"
msgstr ""
#: src/libwrapper.cpp:280
#: ../src/libwrapper.cpp:300
msgid "popen failed"
msgstr ""
#: src/libwrapper.cpp:317 src/utils.cpp:67
#: ../src/libwrapper.cpp:341
#, c-format
msgid "Can not convert %s to utf8.\n"
msgstr ""
#: src/libwrapper.cpp:371 src/libwrapper.cpp:402
#: ../src/libwrapper.cpp:399 ../src/libwrapper.cpp:433
#, c-format
msgid "Found %zu items, similar to %s.\n"
msgstr ""
#: src/libwrapper.cpp:388
#: ../src/libwrapper.cpp:417
msgid "Your choice[-1 to abort]: "
msgstr ""
#: src/libwrapper.cpp:397
#: ../src/libwrapper.cpp:427
#, c-format
msgid ""
"Invalid choice.\n"
"It must be from 0 to %zu or -1.\n"
msgstr ""
#: src/libwrapper.cpp:413
#: ../src/libwrapper.cpp:446
#, c-format
msgid "Nothing similar to %s, sorry :(\n"
msgstr ""
#: src/utils.cpp:45
#: ../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 ""
#: ../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 ""
#: ../src/sdcv.cpp:104
msgid "input of sdcv in utf8"
msgstr ""
#: ../src/sdcv.cpp:106
msgid "use this directory as path to stardict data directory"
msgstr ""
#: ../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 ""
#: ../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 ""
#: ../src/sdcv.cpp:128
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr ""
#: ../src/sdcv.cpp:206
#, c-format
msgid "g_mkdir failed: %s\n"
msgstr ""
#: ../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 ""
#: ../src/sdcv.cpp:242
#, c-format
msgid "Dictionary's name Word count\n"
msgstr ""
#: ../src/utils.cpp:48
#, c-format
msgid "Can not convert %s to current locale.\n"
msgstr ""

190
po/sk.po
View File

@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: sdcv 0.3.2\n"
"Report-Msgid-Bugs-To: dushistov@mail.ru\n"
"POT-Creation-Date: 2008-09-24 10:54+0200\n"
"POT-Creation-Date: 2020-08-14 12:58+0300\n"
"PO-Revision-Date: 2007-09-11 00:22+0100\n"
"Last-Translator: Ivan Masár <helix84@centrum.sk>\n"
"Language-Team: Slovak <sk-i18n@lists.linux.sk>\n"
@@ -18,104 +18,26 @@ msgstr ""
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
#: src/sdcv.cpp:108
#, fuzzy
msgid "display version information and exit"
msgstr "-v, --version zobrazí informácie o verzii a skončí\n"
#: src/sdcv.cpp:110
#, fuzzy
msgid "display list of available dictionaries and exit"
msgstr ""
"-l, --list-dicts zobrazí zoznam dostupných slovníkov a skončí\n"
#: src/sdcv.cpp:112
#, fuzzy
msgid "for search use only dictionary with this bookname"
msgstr "-u, --use-dict názov použiť pre hľadanie iba zvolený slovník\n"
#: src/sdcv.cpp:113
msgid "bookname"
msgstr ""
#: src/sdcv.cpp:115
msgid "for use in scripts"
msgstr ""
#: src/sdcv.cpp:117
#, fuzzy
msgid "output must be in utf8"
msgstr "--utf8-output výstup musí byť v utf8\n"
#: src/sdcv.cpp:119
#, fuzzy
msgid "input of sdcv in utf8"
msgstr "--utf8-input vstup pre sdcv je v utf8\n"
#: src/sdcv.cpp:121
#, fuzzy
msgid "use this directory as path to stardict data directory"
msgstr ""
"--data-dir path/to/dir použiť tento priečinok ako cestu pre stardict "
"dátový priečinok\n"
#: src/sdcv.cpp:122
msgid "path/to/dir"
msgstr ""
#: src/sdcv.cpp:129
msgid " words"
msgstr ""
#: src/sdcv.cpp:135
#, c-format
msgid "Invalid command line arguments: %s\n"
msgstr ""
#: src/sdcv.cpp:141
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr "Konzolová verzia StarDict, verzia %s\n"
#: src/sdcv.cpp:170
#, c-format
msgid "Dictionary's name Word count\n"
msgstr "názov slovníka počet slov\n"
#: src/sdcv.cpp:192
#, c-format
msgid "g_mkdir failed: %s\n"
msgstr "g_mkdir zlyhalo: %s\n"
#: src/sdcv.cpp:208
msgid "Enter word or phrase: "
msgstr "Vložte slovo alebo frázu: "
#: src/sdcv.cpp:216
#, c-format
msgid "There are no words/phrases to translate.\n"
msgstr "Nie je čo preložiť.\n"
#: src/libwrapper.cpp:248
#: ../src/libwrapper.cpp:300
msgid "popen failed"
msgstr "popen zlyhalo"
#: src/libwrapper.cpp:285 src/utils.cpp:67
#: ../src/libwrapper.cpp:341
#, c-format
msgid "Can not convert %s to utf8.\n"
msgstr "nie je možné konvertovať %s na utf8.\n"
#: src/libwrapper.cpp:342 src/libwrapper.cpp:370
#: ../src/libwrapper.cpp:399 ../src/libwrapper.cpp:433
#, fuzzy, c-format
msgid "Found %zu items, similar to %s.\n"
msgstr "Nájdené %d položiek, podobných %s,\n"
#: src/libwrapper.cpp:356
#: ../src/libwrapper.cpp:417
#, fuzzy
msgid "Your choice[-1 to abort]: "
msgstr "Vaša voľba[-1 zruší]: "
#: src/libwrapper.cpp:365
#: ../src/libwrapper.cpp:427
#, fuzzy, c-format
msgid ""
"Invalid choice.\n"
@@ -124,12 +46,108 @@ msgstr ""
"Neplatná voľba.\n"
"Musí byť od 0 do %d alebo -1.\n"
#: src/libwrapper.cpp:381
#: ../src/libwrapper.cpp:446
#, c-format
msgid "Nothing similar to %s, sorry :(\n"
msgstr "Ľutujem, nič sa nepodobá na %s :(\n"
#: src/utils.cpp:45
#: ../src/sdcv.cpp:89
#, fuzzy
msgid "display version information and exit"
msgstr "-v, --version zobrazí informácie o verzii a skončí\n"
#: ../src/sdcv.cpp:91
#, fuzzy
msgid "display list of available dictionaries and exit"
msgstr ""
"-l, --list-dicts zobrazí zoznam dostupných slovníkov a skončí\n"
#: ../src/sdcv.cpp:93
#, fuzzy
msgid "for search use only dictionary with this bookname"
msgstr "-u, --use-dict názov použiť pre hľadanie iba zvolený slovník\n"
#: ../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 ""
#: ../src/sdcv.cpp:100
msgid "do not fuzzy-search for similar words, only return exact matches"
msgstr ""
#: ../src/sdcv.cpp:102
#, fuzzy
msgid "output must be in utf8"
msgstr "--utf8-output výstup musí byť v utf8\n"
#: ../src/sdcv.cpp:104
#, fuzzy
msgid "input of sdcv in utf8"
msgstr "--utf8-input vstup pre sdcv je v utf8\n"
#: ../src/sdcv.cpp:106
#, fuzzy
msgid "use this directory as path to stardict data directory"
msgstr ""
"--data-dir path/to/dir použiť tento priečinok ako cestu pre stardict "
"dátový priečinok\n"
#: ../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 ""
#: ../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 ""
#: ../src/sdcv.cpp:128
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr "Konzolová verzia StarDict, verzia %s\n"
#: ../src/sdcv.cpp:206
#, c-format
msgid "g_mkdir failed: %s\n"
msgstr "g_mkdir zlyhalo: %s\n"
#: ../src/sdcv.cpp:222
msgid "Enter word or phrase: "
msgstr "Vložte slovo alebo frázu: "
#: ../src/sdcv.cpp:230
#, c-format
msgid "There are no words/phrases to translate.\n"
msgstr "Nie je čo preložiť.\n"
#: ../src/sdcv.cpp:242
#, c-format
msgid "Dictionary's name Word count\n"
msgstr "názov slovníka počet slov\n"
#: ../src/utils.cpp:48
#, c-format
msgid "Can not convert %s to current locale.\n"
msgstr "Nie je možné konvertovať %s na aktuálne locale.\n"

194
po/uk.po
View File

@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: sdcv 0.3\n"
"Report-Msgid-Bugs-To: dushistov@mail.ru\n"
"POT-Creation-Date: 2008-09-24 10:54+0200\n"
"POT-Creation-Date: 2020-08-14 12:58+0300\n"
"PO-Revision-Date: 2004-12-14 17:54+0300\n"
"Last-Translator: <dubyk@lsl.lviv.ua>\n"
"Language-Team: Ukrainian <dubyk@lsl.lviv.ua>\n"
@@ -19,106 +19,26 @@ msgstr ""
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
#: src/sdcv.cpp:108
#, fuzzy
msgid "display version information and exit"
msgstr "-v, --version показати номер версії і завершити роботу\n"
#: src/sdcv.cpp:110
#, fuzzy
msgid "display list of available dictionaries and exit"
msgstr ""
"-l, --list-dicts показати список доступних словників і завершити "
"роботу\n"
#: src/sdcv.cpp:112
#, fuzzy
msgid "for search use only dictionary with this bookname"
msgstr ""
"-u, --use-dict ім`я словника для пошуку використовувати лише цей словник\n"
#: src/sdcv.cpp:113
msgid "bookname"
msgstr ""
#: src/sdcv.cpp:115
msgid "for use in scripts"
msgstr ""
#: src/sdcv.cpp:117
#, fuzzy
msgid "output must be in utf8"
msgstr "--utf8-output вивід програми повинен бути в utf8\n"
#: src/sdcv.cpp:119
#, fuzzy
msgid "input of sdcv in utf8"
msgstr "--utf8-input ввід програми в utf8\n"
#: src/sdcv.cpp:121
#, fuzzy
msgid "use this directory as path to stardict data directory"
msgstr ""
"--data-dir тека використовувати цю теку як шлях до stardict data "
"directory\n"
#: src/sdcv.cpp:122
msgid "path/to/dir"
msgstr ""
#: src/sdcv.cpp:129
msgid " words"
msgstr ""
#: src/sdcv.cpp:135
#, c-format
msgid "Invalid command line arguments: %s\n"
msgstr ""
#: src/sdcv.cpp:141
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr "Консольна версія Зоряного словника [Stardict], номер версії %s\n"
#: src/sdcv.cpp:170
#, fuzzy, c-format
msgid "Dictionary's name Word count\n"
msgstr "назва словника кількість слів\n"
#: src/sdcv.cpp:192
#, c-format
msgid "g_mkdir failed: %s\n"
msgstr ""
#: src/sdcv.cpp:208
msgid "Enter word or phrase: "
msgstr "ВведЁть слово або фразу: "
#: src/sdcv.cpp:216
#, c-format
msgid "There are no words/phrases to translate.\n"
msgstr "Не задано слова/фрази для перекладу.\n"
#: src/libwrapper.cpp:248
#: ../src/libwrapper.cpp:300
msgid "popen failed"
msgstr ""
#: src/libwrapper.cpp:285 src/utils.cpp:67
#: ../src/libwrapper.cpp:341
#, c-format
msgid "Can not convert %s to utf8.\n"
msgstr "Не можу перетворити %s у utf8.\n"
#: src/libwrapper.cpp:342 src/libwrapper.cpp:370
#: ../src/libwrapper.cpp:399 ../src/libwrapper.cpp:433
#, fuzzy, c-format
msgid "Found %zu items, similar to %s.\n"
msgstr "Знайдено %d слів, схожих на %s.\n"
#: src/libwrapper.cpp:356
#: ../src/libwrapper.cpp:417
#, fuzzy
msgid "Your choice[-1 to abort]: "
msgstr "Ваш вибір: "
#: src/libwrapper.cpp:365
#: ../src/libwrapper.cpp:427
#, fuzzy, c-format
msgid ""
"Invalid choice.\n"
@@ -127,12 +47,110 @@ msgstr ""
"Неправильний вибір.\n"
"Повинно бути від 0 до %d.\n"
#: src/libwrapper.cpp:381
#: ../src/libwrapper.cpp:446
#, c-format
msgid "Nothing similar to %s, sorry :(\n"
msgstr "Нічого схожого на %s, даруйте :(\n"
#: src/utils.cpp:45
#: ../src/sdcv.cpp:89
#, fuzzy
msgid "display version information and exit"
msgstr "-v, --version показати номер версії і завершити роботу\n"
#: ../src/sdcv.cpp:91
#, fuzzy
msgid "display list of available dictionaries and exit"
msgstr ""
"-l, --list-dicts показати список доступних словників і завершити "
"роботу\n"
#: ../src/sdcv.cpp:93
#, fuzzy
msgid "for search use only dictionary with this bookname"
msgstr ""
"-u, --use-dict ім`я словника для пошуку використовувати лише цей словник\n"
#: ../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 ""
#: ../src/sdcv.cpp:100
msgid "do not fuzzy-search for similar words, only return exact matches"
msgstr ""
#: ../src/sdcv.cpp:102
#, fuzzy
msgid "output must be in utf8"
msgstr "--utf8-output вивід програми повинен бути в utf8\n"
#: ../src/sdcv.cpp:104
#, fuzzy
msgid "input of sdcv in utf8"
msgstr "--utf8-input ввід програми в utf8\n"
#: ../src/sdcv.cpp:106
#, fuzzy
msgid "use this directory as path to stardict data directory"
msgstr ""
"--data-dir тека використовувати цю теку як шлях до stardict data "
"directory\n"
#: ../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 ""
#: ../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 ""
#: ../src/sdcv.cpp:128
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr "Консольна версія Зоряного словника [Stardict], номер версії %s\n"
#: ../src/sdcv.cpp:206
#, c-format
msgid "g_mkdir failed: %s\n"
msgstr ""
#: ../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
#, fuzzy, 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

@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: sdcv 0.3\n"
"Report-Msgid-Bugs-To: dushistov@mail.ru\n"
"POT-Creation-Date: 2008-09-24 10:54+0200\n"
"POT-Creation-Date: 2020-08-14 12:58+0300\n"
"PO-Revision-Date: 2005-1-17 00:58+0800\n"
"Last-Translator: Cai Qian <caiqian@gnome.org>\n"
"Language-Team: Simplified Chinese\n"
@@ -15,101 +15,26 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: src/sdcv.cpp:108
#, fuzzy
msgid "display version information and exit"
msgstr "-v, --version 显示版本信息并退出\n"
#: src/sdcv.cpp:110
#, fuzzy
msgid "display list of available dictionaries and exit"
msgstr "-l, --list-dicts 显示可用的字典列表并退出\n"
#: src/sdcv.cpp:112
#, fuzzy
msgid "for search use only dictionary with this bookname"
msgstr "-u, --use-dict 字典名 只使用指定的字典进行单词搜索\n"
#: src/sdcv.cpp:113
msgid "bookname"
msgstr ""
#: src/sdcv.cpp:115
msgid "for use in scripts"
msgstr ""
#: src/sdcv.cpp:117
#, fuzzy
msgid "output must be in utf8"
msgstr "--utf8-output 输出必须是 UTF-8\n"
#: src/sdcv.cpp:119
#, fuzzy
msgid "input of sdcv in utf8"
msgstr "--utf8-input sdcv 的输入为 UTF-8\n"
#: src/sdcv.cpp:121
#, fuzzy
msgid "use this directory as path to stardict data directory"
msgstr "--data-dir 目录路径 指定 Stardict 数据所在目录的路径\n"
#: src/sdcv.cpp:122
msgid "path/to/dir"
msgstr ""
#: src/sdcv.cpp:129
msgid " words"
msgstr ""
#: src/sdcv.cpp:135
#, c-format
msgid "Invalid command line arguments: %s\n"
msgstr ""
#: src/sdcv.cpp:141
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr "Stardict 的控制台版本,版本为 %s\n"
#: src/sdcv.cpp:170
#, fuzzy, c-format
msgid "Dictionary's name Word count\n"
msgstr "字典名 单词量\n"
#: src/sdcv.cpp:192
#, c-format
msgid "g_mkdir failed: %s\n"
msgstr ""
#: src/sdcv.cpp:208
msgid "Enter word or phrase: "
msgstr "请输入单词或短语:"
#: src/sdcv.cpp:216
#, c-format
msgid "There are no words/phrases to translate.\n"
msgstr "没有供翻译的单词或短语。\n"
#: src/libwrapper.cpp:248
#: ../src/libwrapper.cpp:300
msgid "popen failed"
msgstr ""
#: src/libwrapper.cpp:285 src/utils.cpp:67
#: ../src/libwrapper.cpp:341
#, c-format
msgid "Can not convert %s to utf8.\n"
msgstr "无法将 %s 转换为 UTF-8。\n"
#: src/libwrapper.cpp:342 src/libwrapper.cpp:370
#: ../src/libwrapper.cpp:399 ../src/libwrapper.cpp:433
#, fuzzy, c-format
msgid "Found %zu items, similar to %s.\n"
msgstr "发现 %d 条记录和 %s 相似。\n"
#: src/libwrapper.cpp:356
#: ../src/libwrapper.cpp:417
#, fuzzy
msgid "Your choice[-1 to abort]: "
msgstr "您的选择为:"
#: src/libwrapper.cpp:365
#: ../src/libwrapper.cpp:427
#, fuzzy, c-format
msgid ""
"Invalid choice.\n"
@@ -118,12 +43,105 @@ msgstr ""
"无效的选择。\n"
"必须是 0 到 %d。\n"
#: src/libwrapper.cpp:381
#: ../src/libwrapper.cpp:446
#, c-format
msgid "Nothing similar to %s, sorry :(\n"
msgstr "对不起,没有发现和 %s 相似的 :(\n"
#: src/utils.cpp:45
#: ../src/sdcv.cpp:89
#, fuzzy
msgid "display version information and exit"
msgstr "-v, --version 显示版本信息并退出\n"
#: ../src/sdcv.cpp:91
#, fuzzy
msgid "display list of available dictionaries and exit"
msgstr "-l, --list-dicts 显示可用的字典列表并退出\n"
#: ../src/sdcv.cpp:93
#, fuzzy
msgid "for search use only dictionary with this bookname"
msgstr "-u, --use-dict 字典名 只使用指定的字典进行单词搜索\n"
#: ../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 ""
#: ../src/sdcv.cpp:100
msgid "do not fuzzy-search for similar words, only return exact matches"
msgstr ""
#: ../src/sdcv.cpp:102
#, fuzzy
msgid "output must be in utf8"
msgstr "--utf8-output 输出必须是 UTF-8\n"
#: ../src/sdcv.cpp:104
#, fuzzy
msgid "input of sdcv in utf8"
msgstr "--utf8-input sdcv 的输入为 UTF-8\n"
#: ../src/sdcv.cpp:106
#, fuzzy
msgid "use this directory as path to stardict data directory"
msgstr "--data-dir 目录路径 指定 Stardict 数据所在目录的路径\n"
#: ../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 ""
#: ../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 ""
#: ../src/sdcv.cpp:128
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr "Stardict 的控制台版本,版本为 %s\n"
#: ../src/sdcv.cpp:206
#, c-format
msgid "g_mkdir failed: %s\n"
msgstr ""
#: ../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
#, fuzzy, 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 转换为当前 Locale。\n"

View File

@@ -8,122 +8,158 @@ msgid ""
msgstr ""
"Project-Id-Version: sdcv 0.4.2\n"
"Report-Msgid-Bugs-To: dushistov@mail.ru\n"
"POT-Creation-Date: 2006-04-24 15:18+0400\n"
"POT-Creation-Date: 2020-08-14 12:58+0300\n"
"PO-Revision-Date: 2013-06-12 14:11+0800\n"
"Last-Translator: Wei-Lun Chao <bluebat@member.fsf.org>\n"
"Language-Team: Chinese (traditional) <zh-l10n@linux.org.tw>\n"
"Language: zh_TW\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: src/sdcv.cpp:127
#, c-format
msgid ""
"Unknown option.\n"
"Try '%s --help' for more information.\n"
msgstr ""
"不明選項。\n"
"更多資訊請看 '%s --help'。\n"
#: src/sdcv.cpp:134
#, c-format
msgid "Usage: %s [OPTIONS] words\n"
msgstr "用法:%s [選項] 單字…\n"
#: src/sdcv.cpp:135
#, c-format
msgid "-h, --help display this help and exit\n"
msgstr "-h, --help 顯示本輔助並離開\n"
#: src/sdcv.cpp:136
#, c-format
msgid "-v, --version display version information and exit\n"
msgstr "-v, --version 顯示版本資訊並離開\n"
#: src/sdcv.cpp:137
#, c-format
msgid "-l, --list-dicts display list of available dictionaries and exit\n"
msgstr "-l, --list-dicts 顯示可用的字典清單並離開\n"
#: src/sdcv.cpp:138
#, c-format
msgid "-u, --use-dict bookname for search use only dictionary with this bookname\n"
msgstr "-u, --use-dict 字典名 只使用指定的字典進行單字搜尋\n"
#: src/sdcv.cpp:139
#, c-format
msgid "-n, --non-interactive for use in scripts\n"
msgstr "-n, --non-interactive 在指令稿中使用\n"
#: src/sdcv.cpp:140
#, c-format
msgid "--utf8-output output must be in utf8\n"
msgstr "--utf8-output 輸出必須是 UTF-8\n"
#: src/sdcv.cpp:141
#, c-format
msgid "--utf8-input input of sdcv in utf8\n"
msgstr "--utf8-input sdcv 的輸入為 UTF-8\n"
#: src/sdcv.cpp:142
#, c-format
msgid "--data-dir path/to/dir use this directory as path to stardict data directory\n"
msgstr "--data-dir 目錄路徑 指定 Stardict 資料所在目錄的路徑\n"
#: src/sdcv.cpp:148
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr "Stardict 的主控臺版本,版本為 %s\n"
#: src/sdcv.cpp:169
#, c-format
msgid "Dictionary's name Word count\n"
msgstr "字典名稱 單字數量\n"
#: src/sdcv.cpp:191
#, c-format
msgid "g_mkdir failed: %s\n"
msgstr "g_mkdir 失敗:%s\n"
#: src/sdcv.cpp:207
msgid "Enter word or phrase: "
msgstr "請輸入單字或片語:"
#: src/sdcv.cpp:215
#, c-format
msgid "There are no words/phrases to translate.\n"
msgstr "沒有可供翻譯的單字或片語。\n"
#: src/libwrapper.cpp:245
#: ../src/libwrapper.cpp:300
msgid "popen failed"
msgstr "popen 失敗"
#: src/libwrapper.cpp:282
#: ../src/libwrapper.cpp:341
#, c-format
msgid "Can not convert %s to utf8.\n"
msgstr "無法將 %s 轉換為 UTF-8。\n"
#: src/libwrapper.cpp:339 src/libwrapper.cpp:371
#, c-format
msgid "Found %d items, similar to %s.\n"
#: ../src/libwrapper.cpp:399 ../src/libwrapper.cpp:433
#, fuzzy, c-format
msgid "Found %zu items, similar to %s.\n"
msgstr "找到 %d 項紀錄和 %s 相似。\n"
#: src/libwrapper.cpp:352
#, c-format
#: ../src/libwrapper.cpp:417
msgid "Your choice[-1 to abort]: "
msgstr "您的選擇是[-1 表示放棄]"
#: src/libwrapper.cpp:366
#, c-format
#: ../src/libwrapper.cpp:427
#, fuzzy, c-format
msgid ""
"Invalid choise.\n"
"It must be from 0 to %d or -1.\n"
"Invalid choice.\n"
"It must be from 0 to %zu or -1.\n"
msgstr ""
"無效的選擇。\n"
"必須是 0 到 %d 之間或 -1。\n"
#: src/libwrapper.cpp:382
#: ../src/libwrapper.cpp:446
#, c-format
msgid "Nothing similar to %s, sorry :(\n"
msgstr "抱歉,沒有和 %s 相似者 :(\n"
#: ../src/sdcv.cpp:89
#, fuzzy
msgid "display version information and exit"
msgstr "-v, --version 顯示版本資訊並離開\n"
#: ../src/sdcv.cpp:91
#, fuzzy
msgid "display list of available dictionaries and exit"
msgstr "-l, --list-dicts 顯示可用的字典清單並離開\n"
#: ../src/sdcv.cpp:93
#, fuzzy
msgid "for search use only dictionary with this bookname"
msgstr "-u, --use-dict 字典名 只使用指定的字典進行單字搜尋\n"
#: ../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 ""
#: ../src/sdcv.cpp:100
msgid "do not fuzzy-search for similar words, only return exact matches"
msgstr ""
#: ../src/sdcv.cpp:102
#, fuzzy
msgid "output must be in utf8"
msgstr "--utf8-output 輸出必須是 UTF-8\n"
#: ../src/sdcv.cpp:104
#, fuzzy
msgid "input of sdcv in utf8"
msgstr "--utf8-input sdcv 的輸入為 UTF-8\n"
#: ../src/sdcv.cpp:106
#, fuzzy
msgid "use this directory as path to stardict data directory"
msgstr "--data-dir 目錄路徑 指定 Stardict 資料所在目錄的路徑\n"
#: ../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 ""
#: ../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 ""
#: ../src/sdcv.cpp:128
#, c-format
msgid "Console version of Stardict, version %s\n"
msgstr "Stardict 的主控臺版本,版本為 %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
#, fuzzy, c-format
msgid "Can not convert %s to current locale.\n"
msgstr "無法將 %s 轉換為 UTF-8。\n"
#~ msgid ""
#~ "Unknown option.\n"
#~ "Try '%s --help' for more information.\n"
#~ msgstr ""
#~ "不明選項。\n"
#~ "更多資訊請看 '%s --help'。\n"
#~ msgid "Usage: %s [OPTIONS] words\n"
#~ msgstr "用法:%s [選項] 單字…\n"
#~ msgid "-h, --help display this help and exit\n"
#~ msgstr "-h, --help 顯示本輔助並離開\n"
#~ msgid "-n, --non-interactive for use in scripts\n"
#~ msgstr "-n, --non-interactive 在指令稿中使用\n"

View File

@@ -21,25 +21,24 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
//#define HAVE_MMAP //it will defined in config.h. this can be done by configure.in with a AC_FUNC_MMAP.
#ifdef HAVE_CONFIG_H
# include "config.h"
#include "config.h"
#endif
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <limits.h>
#include <fcntl.h>
#include <limits.h>
#include <unistd.h>
#include <sys/stat.h>
#include "dictziplib.hpp"
#define USE_CACHE 1
@@ -57,11 +56,11 @@
/* For gzip-compatible header, as defined in RFC 1952 */
/* Magic for GZIP (rfc1952) */
/* Magic for GZIP (rfc1952) */
#define GZ_MAGIC1 0x1f /* First magic byte */
#define GZ_MAGIC2 0x8b /* Second magic byte */
/* FLaGs (bitmapped), from rfc1952 */
/* FLaGs (bitmapped), from rfc1952 */
#define GZ_FTEXT 0x01 /* Set for ASCII text */
#define GZ_FHCRC 0x02 /* Header CRC16 */
#define GZ_FEXTRA 0x04 /* Optional field (random access index) */
@@ -70,7 +69,7 @@
#define GZ_MAX 2 /* Maximum compression */
#define GZ_FAST 4 /* Fasted compression */
/* These are from rfc1952 */
/* These are from rfc1952 */
#define GZ_OS_FAT 0 /* FAT filesystem (MS-DOS, OS/2, NT/Win32) */
#define GZ_OS_AMIGA 1 /* Amiga */
#define GZ_OS_VMS 2 /* VMS (or OpenVMS) */
@@ -112,7 +111,6 @@
#define DICT_GZIP 2
#define DICT_DZIP 3
int DictData::read_header(const std::string &fname, int computeCRC)
{
FILE *str;
@@ -123,7 +121,7 @@ int DictData::read_header(const std::string &fname, int computeCRC)
char *pt;
int c;
struct stat sb;
unsigned long crc = crc32( 0L, Z_NULL, 0 );
unsigned long crc = crc32(0L, Z_NULL, 0);
int count;
unsigned long offset;
@@ -136,50 +134,50 @@ int DictData::read_header(const std::string &fname, int computeCRC)
this->headerLength = GZ_XLEN - 1;
this->type = DICT_UNKNOWN;
id1 = getc( str );
id2 = getc( str );
id1 = getc(str);
id2 = getc(str);
if (id1 != GZ_MAGIC1 || id2 != GZ_MAGIC2) {
this->type = DICT_TEXT;
fstat( fileno( str ), &sb );
fstat(fileno(str), &sb);
this->compressedLength = this->length = sb.st_size;
this->origFilename = fname;
this->mtime = sb.st_mtime;
if (computeCRC) {
rewind( str );
while (!feof( str )) {
if ((count = fread( buffer, 1, BUFFERSIZE, str ))) {
rewind(str);
while (!feof(str)) {
if ((count = fread(buffer, 1, BUFFERSIZE, str))) {
crc = crc32(crc, (Bytef *)buffer, count);
}
}
}
this->crc = crc;
fclose( str );
fclose(str);
return 0;
}
this->type = DICT_GZIP;
this->method = getc( str );
this->flags = getc( str );
this->mtime = getc( str ) << 0;
this->mtime |= getc( str ) << 8;
this->mtime |= getc( str ) << 16;
this->mtime |= getc( str ) << 24;
this->extraFlags = getc( str );
this->os = getc( str );
this->method = getc(str);
this->flags = getc(str);
this->mtime = getc(str) << 0;
this->mtime |= getc(str) << 8;
this->mtime |= getc(str) << 16;
this->mtime |= getc(str) << 24;
this->extraFlags = getc(str);
this->os = getc(str);
if (this->flags & GZ_FEXTRA) {
extraLength = getc( str ) << 0;
extraLength |= getc( str ) << 8;
extraLength = getc(str) << 0;
extraLength |= getc(str) << 8;
this->headerLength += extraLength + 2;
si1 = getc( str );
si2 = getc( str );
si1 = getc(str);
si2 = getc(str);
if (si1 == GZ_RND_S1 || si2 == GZ_RND_S2) {
subLength = getc( str ) << 0;
subLength |= getc( str ) << 8;
this->version = getc( str ) << 0;
this->version |= getc( str ) << 8;
subLength = getc(str) << 0;
subLength |= getc(str) << 8;
this->version = getc(str) << 0;
this->version |= getc(str) << 8;
if (this->version != 1) {
//err_internal( __FUNCTION__,
@@ -187,30 +185,30 @@ int DictData::read_header(const std::string &fname, int computeCRC)
// this->version );
}
this->chunkLength = getc( str ) << 0;
this->chunkLength |= getc( str ) << 8;
this->chunkCount = getc( str ) << 0;
this->chunkCount |= getc( str ) << 8;
this->chunkLength = getc(str) << 0;
this->chunkLength |= getc(str) << 8;
this->chunkCount = getc(str) << 0;
this->chunkCount |= getc(str) << 8;
if (this->chunkCount <= 0) {
fclose( str );
fclose(str);
return 5;
}
this->chunks = (int *)malloc(sizeof( this->chunks[0] )
* this->chunkCount );
this->chunks = (int *)malloc(sizeof(this->chunks[0])
* this->chunkCount);
for (i = 0; i < this->chunkCount; i++) {
this->chunks[i] = getc( str ) << 0;
this->chunks[i] |= getc( str ) << 8;
this->chunks[i] = getc(str) << 0;
this->chunks[i] |= getc(str) << 8;
}
this->type = DICT_DZIP;
} else {
fseek( str, this->headerLength, SEEK_SET );
fseek(str, this->headerLength, SEEK_SET);
}
}
if (this->flags & GZ_FNAME) { /* FIXME! Add checking against header len */
pt = buffer;
while ((c = getc( str )) && c != EOF)
while ((c = getc(str)) && c != EOF)
*pt++ = c;
*pt = '\0';
@@ -222,41 +220,41 @@ int DictData::read_header(const std::string &fname, int computeCRC)
if (this->flags & GZ_COMMENT) { /* FIXME! Add checking for header len */
pt = buffer;
while ((c = getc( str )) && c != EOF)
while ((c = getc(str)) && c != EOF)
*pt++ = c;
*pt = '\0';
comment = buffer;
headerLength += comment.length()+1;
headerLength += comment.length() + 1;
} else {
comment = "";
}
if (this->flags & GZ_FHCRC) {
getc( str );
getc( str );
getc(str);
getc(str);
this->headerLength += 2;
}
if (ftell( str ) != this->headerLength + 1) {
if (ftell(str) != this->headerLength + 1) {
//err_internal( __FUNCTION__,
// "File position (%lu) != header length + 1 (%d)\n",
// ftell( str ), this->headerLength + 1 );
}
fseek( str, -8, SEEK_END );
this->crc = getc( str ) << 0;
this->crc |= getc( str ) << 8;
this->crc |= getc( str ) << 16;
this->crc |= getc( str ) << 24;
this->length = getc( str ) << 0;
this->length |= getc( str ) << 8;
this->length |= getc( str ) << 16;
this->length |= getc( str ) << 24;
this->compressedLength = ftell( str );
fseek(str, -8, SEEK_END);
this->crc = getc(str) << 0;
this->crc |= getc(str) << 8;
this->crc |= getc(str) << 16;
this->crc |= getc(str) << 24;
this->length = getc(str) << 0;
this->length |= getc(str) << 8;
this->length |= getc(str) << 16;
this->length |= getc(str) << 24;
this->compressedLength = ftell(str);
/* Compute offsets */
this->offsets = (unsigned long *)malloc( sizeof( this->offsets[0] )
* this->chunkCount );
this->offsets = (unsigned long *)malloc(sizeof(this->offsets[0])
* this->chunkCount);
for (offset = this->headerLength + 1, i = 0;
i < this->chunkCount;
i++) {
@@ -264,11 +262,11 @@ int DictData::read_header(const std::string &fname, int computeCRC)
offset += this->chunks[i];
}
fclose( str );
fclose(str);
return 0;
}
bool DictData::open(const std::string& fname, int computeCRC)
bool DictData::open(const std::string &fname, int computeCRC)
{
struct stat sb;
int fd;
@@ -287,7 +285,7 @@ bool DictData::open(const std::string& fname, int computeCRC)
return false;
}
if ((fd = ::open(fname.c_str(), O_RDONLY )) < 0) {
if ((fd = ::open(fname.c_str(), O_RDONLY)) < 0) {
//err_fatal_errno( __FUNCTION__,
// "Cannot open data file \"%s\"\n", fname );
return false;
@@ -303,7 +301,7 @@ bool DictData::open(const std::string& fname, int computeCRC)
if (!mapfile.open(fname.c_str(), size))
return false;
this->start=mapfile.begin();
this->start = mapfile.begin();
this->end = this->start + this->size;
for (size_t j = 0; j < DICT_CACHE_SIZE; j++) {
@@ -324,16 +322,16 @@ void DictData::close()
free(this->offsets);
if (this->initialized) {
if (inflateEnd( &this->zStream )) {
if (inflateEnd(&this->zStream)) {
//err_internal( __FUNCTION__,
// "Cannot shut down inflation engine: %s\n",
// this->zStream.msg );
}
}
for (size_t i = 0; i < DICT_CACHE_SIZE; ++i){
if (this -> cache [i].inBuffer)
free (this -> cache [i].inBuffer);
for (size_t i = 0; i < DICT_CACHE_SIZE; ++i) {
if (this->cache[i].inBuffer)
free(this->cache[i].inBuffer);
}
}
@@ -358,7 +356,6 @@ void DictData::read(char *buffer, unsigned long start, unsigned long size)
// ("dict_data_read( %p, %lu, %lu )\n",
//h, start, size ));
switch (this->type) {
case DICT_GZIP:
//err_fatal( __FUNCTION__,
@@ -367,7 +364,7 @@ void DictData::read(char *buffer, unsigned long start, unsigned long size)
// " or dzip format (for space savings).\n" );
break;
case DICT_TEXT:
memcpy( buffer, this->start + start, size );
memcpy(buffer, this->start + start, size);
//buffer[size] = '\0';
break;
case DICT_DZIP:
@@ -380,7 +377,7 @@ void DictData::read(char *buffer, unsigned long start, unsigned long size)
this->zStream.avail_in = 0;
this->zStream.next_out = nullptr;
this->zStream.avail_out = 0;
if (inflateInit2( &this->zStream, -15 ) != Z_OK) {
if (inflateInit2(&this->zStream, -15) != Z_OK) {
//err_internal( __FUNCTION__,
// "Cannot initialize inflation engine: %s\n",
//this->zStream.msg );
@@ -422,21 +419,21 @@ void DictData::read(char *buffer, unsigned long start, unsigned long size)
} else {
this->cache[target].chunk = i;
if (!this->cache[target].inBuffer)
this->cache[target].inBuffer = (char *)malloc( IN_BUFFER_SIZE );
this->cache[target].inBuffer = (char *)malloc(IN_BUFFER_SIZE);
inBuffer = this->cache[target].inBuffer;
if (this->chunks[i] >= OUT_BUFFER_SIZE ) {
if (this->chunks[i] >= OUT_BUFFER_SIZE) {
//err_internal( __FUNCTION__,
// "this->chunks[%d] = %d >= %ld (OUT_BUFFER_SIZE)\n",
// i, this->chunks[i], OUT_BUFFER_SIZE );
}
memcpy( outBuffer, this->start + this->offsets[i], this->chunks[i] );
memcpy(outBuffer, this->start + this->offsets[i], this->chunks[i]);
this->zStream.next_in = (Bytef *)outBuffer;
this->zStream.avail_in = this->chunks[i];
this->zStream.next_out = (Bytef *)inBuffer;
this->zStream.avail_out = IN_BUFFER_SIZE;
if (inflate( &this->zStream, Z_PARTIAL_FLUSH ) != Z_OK) {
if (inflate(&this->zStream, Z_PARTIAL_FLUSH) != Z_OK) {
//err_fatal( __FUNCTION__, "inflate: %s\n", this->zStream.msg );
}
if (this->zStream.avail_in) {
@@ -452,24 +449,24 @@ void DictData::read(char *buffer, unsigned long start, unsigned long size)
if (i == firstChunk) {
if (i == lastChunk) {
memcpy( pt, inBuffer + firstOffset, lastOffset-firstOffset);
memcpy(pt, inBuffer + firstOffset, lastOffset - firstOffset);
pt += lastOffset - firstOffset;
} else {
if (count != this->chunkLength ) {
if (count != this->chunkLength) {
//err_internal( __FUNCTION__,
// "Length = %d instead of %d\n",
//count, this->chunkLength );
}
memcpy( pt, inBuffer + firstOffset,
this->chunkLength - firstOffset );
memcpy(pt, inBuffer + firstOffset,
this->chunkLength - firstOffset);
pt += this->chunkLength - firstOffset;
}
} else if (i == lastChunk) {
memcpy( pt, inBuffer, lastOffset );
memcpy(pt, inBuffer, lastOffset);
pt += lastOffset;
} else {
assert( count == this->chunkLength );
memcpy( pt, inBuffer, this->chunkLength );
assert(count == this->chunkLength);
memcpy(pt, inBuffer, this->chunkLength);
pt += this->chunkLength;
}
}

View File

@@ -13,19 +13,21 @@ struct DictCache {
int count;
};
class DictData {
class DictData
{
public:
static const size_t DICT_CACHE_SIZE = 5;
DictData() {}
~DictData() { close(); }
bool open(const std::string& filename, int computeCRC);
bool open(const std::string &filename, int computeCRC);
void close();
void read(char *buffer, unsigned long start, unsigned long size);
private:
const char *start; /* start 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;
z_stream zStream;
@@ -45,11 +47,10 @@ private:
std::string origFilename;
std::string comment;
unsigned long crc;
unsigned long length;
off_t length;
unsigned long compressedLength;
DictCache cache[DICT_CACHE_SIZE];
MapFile mapfile;
int read_header(const std::string &filename, int computeCRC);
};

View File

@@ -33,7 +33,6 @@ The Levenshtein distance algorithm has been used in:
* Plagiarism detection
*/
#include <cstdlib>
#include <cstring>
@@ -56,43 +55,39 @@ Enhanced Dynamic Programming ASM Algorithm"
static inline int minimum(const int a, const int b, const int c)
{
int min = a;
if ( b < min )
if (b < min)
min = b;
if ( c < min )
if (c < min)
min = c;
return min;
}
int EditDistance::CalEditDistance(const gunichar *s,const gunichar *t,const int limit)
int EditDistance::CalEditDistance(const gunichar *s, const gunichar *t, const int limit)
/*Compute levenshtein distance between s and t, this is using QUICK algorithm*/
{
int n=0,m=0,iLenDif,k,i,j,cost;
int n = 0, m = 0, iLenDif, k, i, j, cost;
// Remove leftmost matching portion of strings
while ( *s && (*s==*t) )
{
while (*s && (*s == *t)) {
s++;
t++;
}
while (s[n])
{
while (s[n]) {
n++;
}
while (t[m])
{
while (t[m]) {
m++;
}
// Remove rightmost matching portion of strings by decrement n and m.
while ( n && m && (*(s+n-1)==*(t+m-1)) )
{
n--;m--;
while (n && m && (*(s + n - 1) == *(t + m - 1))) {
n--;
m--;
}
if ( m==0 || n==0 || d==nullptr )
return (m+n);
if ( m < n )
{
const gunichar * temp = s;
if (m == 0 || n == 0 || d == nullptr)
return (m + n);
if (m < n) {
const gunichar *temp = s;
int itemp = n;
s = t;
t = temp;
@@ -100,55 +95,51 @@ int EditDistance::CalEditDistance(const gunichar *s,const gunichar *t,const int
m = itemp;
}
iLenDif = m - n;
if ( iLenDif >= limit )
if (iLenDif >= limit)
return iLenDif;
// step 1
n++;m++;
// d=(int*)malloc(sizeof(int)*m*n);
if ( m*n > currentelements )
{
currentelements = m*n*2; // double the request
d = static_cast<int*>(realloc(d, sizeof(int) * currentelements));
if ( nullptr == d )
return (m+n);
n++;
m++;
// d=(int*)malloc(sizeof(int)*m*n);
if (m * n > currentelements) {
currentelements = m * n * 2; // double the request
d = static_cast<int *>(realloc(d, sizeof(int) * currentelements));
if (nullptr == d)
return (m + n);
}
// step 2, init matrix
for (k=0;k<n;k++)
for (k = 0; k < n; k++)
d[k] = k;
for (k=1;k<m;k++)
d[k*n] = k;
for (k = 1; k < m; k++)
d[k * n] = k;
// step 3
for (i=1;i<n;i++)
{
for (i = 1; i < n; i++) {
// first calculate column, d(i,j)
for ( j=1;j<iLenDif+i;j++ )
{
cost = s[i-1]==t[j-1]?0:1;
d[j*n+i] = minimum(d[(j-1)*n+i]+1,d[j*n+i-1]+1,d[(j-1)*n+i-1]+cost);
for (j = 1; j < iLenDif + i; j++) {
cost = s[i - 1] == t[j - 1] ? 0 : 1;
d[j * n + i] = minimum(d[(j - 1) * n + i] + 1, d[j * n + i - 1] + 1, d[(j - 1) * n + i - 1] + cost);
#ifdef COVER_TRANSPOSITION
if ( i>=2 && j>=2 && (d[j*n+i]-d[(j-2)*n+i-2]==2)
&& (s[i-2]==t[j-1]) && (s[i-1]==t[j-2]) )
d[j*n+i]--;
if (i >= 2 && j >= 2 && (d[j * n + i] - d[(j - 2) * n + i - 2] == 2)
&& (s[i - 2] == t[j - 1]) && (s[i - 1] == t[j - 2]))
d[j * n + i]--;
#endif
}
// second calculate row, d(k,j)
// now j==iLenDif+i;
for ( k=1;k<=i;k++ )
{
cost = s[k-1]==t[j-1]?0:1;
d[j*n+k] = minimum(d[(j-1)*n+k]+1,d[j*n+k-1]+1,d[(j-1)*n+k-1]+cost);
for (k = 1; k <= i; k++) {
cost = s[k - 1] == t[j - 1] ? 0 : 1;
d[j * n + k] = minimum(d[(j - 1) * n + k] + 1, d[j * n + k - 1] + 1, d[(j - 1) * n + k - 1] + cost);
#ifdef COVER_TRANSPOSITION
if ( k>=2 && j>=2 && (d[j*n+k]-d[(j-2)*n+k-2]==2)
&& (s[k-2]==t[j-1]) && (s[k-1]==t[j-2]) )
d[j*n+k]--;
if (k >= 2 && j >= 2 && (d[j * n + k] - d[(j - 2) * n + k - 2] == 2)
&& (s[k - 2] == t[j - 1]) && (s[k - 1] == t[j - 2]))
d[j * n + k]--;
#endif
}
// test if d(i,j) limit gets equal or exceed
if ( d[j*n+i] >= limit )
{
return d[j*n+i];
if (d[j * n + i] >= limit) {
return d[j * n + i];
}
}
// d(n-1,m-1)
return d[n*m-1];
return d[n * m - 1];
}

View File

@@ -3,21 +3,24 @@
#include <cstdlib>
#include <glib.h>
class EditDistance {
class EditDistance
{
public:
EditDistance() {
EditDistance()
{
currentelements = 2500; // It's enough for most conditions :-)
d = static_cast<int *>(malloc(sizeof(int)*currentelements));
d = static_cast<int *>(malloc(sizeof(int) * currentelements));
}
~EditDistance() {
~EditDistance()
{
if (d != nullptr)
free(d);
}
EditDistance(const EditDistance&) = delete;
EditDistance& operator=(const EditDistance&) = delete;
int CalEditDistance( const gunichar *s, const gunichar *t, const int limit );
EditDistance(const EditDistance &) = delete;
EditDistance &operator=(const EditDistance &) = delete;
int CalEditDistance(const gunichar *s, const gunichar *t, const int limit);
private:
int *d;
int currentelements;
};

View File

@@ -15,11 +15,11 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#include "config.h"
#endif
#include <cstring>
@@ -75,11 +75,11 @@ static std::string xdxf2text(const char *p, bool colorize_output)
if (!next)
continue;
const std::string name(p+1, next-p-1);
const std::string name(p + 1, next - p - 1);
if (name == "abr")
res += colorize_output ? ABR_VISFMT : "";
else if (name=="/abr")
else if (name == "/abr")
res += colorize_output ? ESC_END : "";
else if (name == "k") {
const char *begin = next;
@@ -93,7 +93,7 @@ static std::string xdxf2text(const char *p, bool colorize_output)
res += colorize_output ? ESC_END : "";
} else if (name == "b")
res += colorize_output ? ESC_BOLD : "";
else if (name=="/b")
else if (name == "/b")
res += colorize_output ? ESC_END : "";
else if (name == "i")
res += colorize_output ? ESC_ITALIC : "";
@@ -140,33 +140,35 @@ static std::string parse_data(const gchar *data, bool colorize_output)
const gchar *p = data;
data_size = get_uint32(p);
p += sizeof(guint32);
while (guint32(p - data)<data_size) {
while (guint32(p - data) < data_size) {
switch (*p++) {
case 'm':
case 'l': //need more work...
case 'h': // HTML data
case 'w': // WikiMedia markup data
case 'm': // plain text, utf-8
case 'l': // not utf-8, some other locale encoding, discouraged, need more work...
sec_size = strlen(p);
if (sec_size) {
res+="\n";
res += "\n";
m_str = g_strndup(p, sec_size);
res += m_str;
g_free(m_str);
}
sec_size++;
break;
case 'g':
case 'x':
case 'g': // pango markup data
case 'x': // xdxf
sec_size = strlen(p);
if (sec_size) {
res+="\n";
res += "\n";
m_str = g_strndup(p, sec_size);
res += xdxf2text(m_str, colorize_output);
g_free(m_str);
}
sec_size++;
break;
case 't':
case 't': // english phonetic string
sec_size = strlen(p);
if(sec_size){
if (sec_size) {
res += "\n";
if (colorize_output)
res += TRANSCRIPTION_VISFMT;
@@ -176,15 +178,15 @@ static std::string parse_data(const gchar *data, bool colorize_output)
}
sec_size++;
break;
case 'k':
case 'y':
case 'k': // KingSoft PowerWord data
case 'y': // chinese YinBiao or japanese kana, utf-8
sec_size = strlen(p);
if (sec_size)
res += std::string(p, sec_size);
sec_size++;
break;
case 'W':
case 'P':
case 'W': // wav file
case 'P': // picture data
sec_size = get_uint32(p);
sec_size += sizeof(guint32);
break;
@@ -192,25 +194,28 @@ static std::string parse_data(const gchar *data, bool colorize_output)
p += sec_size;
}
return res;
}
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());
for (gint idict = 0; idict < ndicts(); ++idict)
if (SimpleLookupWord(str.c_str(), ind, idict))
for (gint idict = 0; idict < ndicts(); ++idict) {
wordIdxs.clear();
if (SimpleLookupWord(str.c_str(), wordIdxs, idict))
for (auto &wordIdx : wordIdxs)
res_list.push_back(
TSearchResult(dict_name(idict),
poGetWord(ind, idict),
parse_data(poGetWordData(ind, idict), colorize_output_)));
poGetWord(wordIdx, idict),
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)
{
static const int MAXFUZZY=10;
static const int MAXFUZZY = 10;
gchar *fuzzy_res[MAXFUZZY];
if (!Libs::LookupWithFuzzy(str.c_str(), fuzzy_res, MAXFUZZY))
@@ -222,9 +227,9 @@ void Library::LookupWithFuzzy(const std::string &str, TSearchResultList& res_lis
}
}
void Library::LookupWithRule(const std::string &str, TSearchResultList& res_list)
void Library::LookupWithRule(const std::string &str, TSearchResultList &res_list)
{
std::vector<gchar *> match_res((MAX_MATCH_ITEM_PER_LIB) * ndicts());
std::vector<gchar *> match_res((MAX_MATCH_ITEM_PER_LIB)*ndicts());
const gint nfound = Libs::LookupWithRule(str.c_str(), &match_res[0]);
if (nfound == 0)
@@ -236,9 +241,9 @@ void Library::LookupWithRule(const std::string &str, TSearchResultList& res_list
}
}
void Library::LookupData(const std::string &str, TSearchResultList& res_list)
void Library::LookupData(const std::string &str, TSearchResultList &res_list)
{
std::vector<std::vector<gchar *> > drl(ndicts());
std::vector<std::vector<gchar *>> drl(ndicts());
if (!Libs::LookupData(str.c_str(), &drl[0]))
return;
for (int idict = 0; idict < ndicts(); ++idict)
@@ -248,16 +253,27 @@ void Library::LookupData(const std::string &str, TSearchResultList& res_list)
}
}
void Library::print_search_result(FILE *out, const TSearchResult & res)
void Library::print_search_result(FILE *out, const TSearchResult &res, bool &first_result)
{
std::string loc_bookname, loc_def, loc_exp;
if (!utf8_output_){
if (!utf8_output_) {
loc_bookname = utf8_to_locale_ign_err(res.bookname);
loc_def = utf8_to_locale_ign_err(res.def);
loc_exp = utf8_to_locale_ign_err(res.exp);
}
if (json_) {
if (!first_result) {
fputs(",", out);
} else {
first_result = false;
}
fprintf(out, "{\"dict\": \"%s\",\"word\":\"%s\",\"definition\":\"%s\"}",
json_escape_string(res.bookname).c_str(),
json_escape_string(res.def).c_str(),
json_escape_string(res.exp).c_str());
} else {
fprintf(out,
"-->%s%s%s\n"
"-->%s%s%s\n"
@@ -269,37 +285,45 @@ void Library::print_search_result(FILE *out, const TSearchResult & res)
utf8_output_ ? res.def.c_str() : loc_def.c_str(),
colorize_output_ ? ESC_END : "",
utf8_output_ ? res.exp.c_str() : loc_exp.c_str());
}
}
namespace {
class sdcv_pager {
public:
sdcv_pager(bool ignore_env = false) {
namespace
{
class sdcv_pager final
{
public:
explicit sdcv_pager(bool ignore_env = false)
{
output = stdout;
if (ignore_env)
if (ignore_env) {
return;
}
const gchar *pager = g_getenv("SDCV_PAGER");
if (pager && (output = popen(pager, "w")) == nullptr) {
perror(_("popen failed"));
output = stdout;
}
}
sdcv_pager(const sdcv_pager&) = delete;
sdcv_pager& operator=(const sdcv_pager&) = delete;
~sdcv_pager() {
if (output != stdout)
sdcv_pager(const sdcv_pager &) = delete;
sdcv_pager &operator=(const sdcv_pager &) = delete;
~sdcv_pager()
{
if (output != stdout) {
pclose(output);
}
}
FILE *get_stream() { return output; }
private:
FILE *output;
};
}
bool Library::process_phrase(const char *loc_str, IReadLine &io, bool force)
private:
FILE *output;
};
} // namespace
search_result Library::process_phrase(const char *loc_str, IReadLine &io, bool force)
{
if (nullptr == loc_str)
return true;
return SEARCH_SUCCESS;
std::string query;
@@ -310,6 +334,7 @@ bool Library::process_phrase(const char *loc_str, IReadLine &io, bool force)
gsize bytes_read;
gsize bytes_written;
glib::Error err;
search_result rval = SEARCH_SUCCESS;
glib::CharStr str;
if (!utf8_input_)
str.reset(g_locale_to_utf8(loc_str, -1, &bytes_read, &bytes_written, get_addr(err)));
@@ -319,11 +344,11 @@ bool Library::process_phrase(const char *loc_str, IReadLine &io, bool force)
if (nullptr == get_impl(str)) {
fprintf(stderr, _("Can not convert %s to utf8.\n"), loc_str);
fprintf(stderr, "%s\n", err->message);
return false;
return SEARCH_FAILURE;
}
if (str[0] == '\0')
return true;
return SEARCH_SUCCESS;
TSearchResultList res_list;
@@ -336,7 +361,7 @@ bool Library::process_phrase(const char *loc_str, IReadLine &io, bool force)
break;
case qtSIMPLE:
SimpleLookup(get_impl(str), res_list);
if (res_list.empty())
if (res_list.empty() && fuzzy_)
LookupWithFuzzy(get_impl(str), res_list);
break;
case qtDATA:
@@ -346,15 +371,19 @@ bool Library::process_phrase(const char *loc_str, IReadLine &io, bool force)
/*nothing*/;
}
bool first_result = true;
if (json_) {
fputc('[', stdout);
}
if (!res_list.empty()) {
/* try to be more clever, if there are
one or zero results per dictionary show all
*/
bool show_all_results = true;
typedef std::map< std::string, int, std::less<std::string> > DictResMap;
typedef std::map<std::string, int, std::less<std::string>> DictResMap;
if (!force) {
DictResMap res_per_dict;
for (const TSearchResult& search_res : res_list) {
for (const TSearchResult &search_res : res_list) {
auto r = res_per_dict.equal_range(search_res.bookname);
DictResMap tmp(r.first, r.second);
if (tmp.empty()) //there are no yet such bookname in map
@@ -367,11 +396,13 @@ bool Library::process_phrase(const char *loc_str, IReadLine &io, bool force)
}
}
}
}//if (!force)
} //if (!force)
if (!show_all_results && !force) {
if (!json_) {
printf(_("Found %zu items, similar to %s.\n"), res_list.size(),
utf8_output_ ? get_impl(str) : utf8_to_locale_ign_err(get_impl(str)).c_str());
}
for (size_t i = 0; i < res_list.size(); ++i) {
const std::string loc_bookname = utf8_to_locale_ign_err(res_list[i].bookname);
const std::string loc_def = utf8_to_locale_ign_err(res_list[i].def);
@@ -392,29 +423,36 @@ bool Library::process_phrase(const char *loc_str, IReadLine &io, bool force)
if (choise >= 0 && choise < int(res_list.size())) {
sdcv_pager pager;
io.add_to_history(res_list[choise].def.c_str());
print_search_result(pager.get_stream(), res_list[choise]);
print_search_result(pager.get_stream(), res_list[choise], first_result);
break;
} else if (choise == -1){
} else if (choise == -1) {
break;
} else
printf(_("Invalid choice.\nIt must be from 0 to %zu or -1.\n"),
res_list.size()-1);
res_list.size() - 1);
}
} else {
sdcv_pager pager(force);
sdcv_pager pager(force || json_);
if (!json_) {
fprintf(pager.get_stream(), _("Found %zu items, similar to %s.\n"),
res_list.size(), utf8_output_ ? get_impl(str) : utf8_to_locale_ign_err(get_impl(str)).c_str());
for (const TSearchResult& search_res : res_list)
print_search_result(pager.get_stream(), search_res);
}
for (const TSearchResult &search_res : res_list) {
print_search_result(pager.get_stream(), search_res, first_result);
}
}
} else {
std::string loc_str;
if (!utf8_output_)
loc_str = utf8_to_locale_ign_err(get_impl(str));
if (!json_)
printf(_("Nothing similar to %s, sorry :(\n"), utf8_output_ ? get_impl(str) : loc_str.c_str());
rval = SEARCH_NO_RESULT;
}
return true;
if (json_) {
fputs("]\n", stdout);
}
return rval;
}

View File

@@ -3,8 +3,8 @@
#include <string>
#include <vector>
#include "stardict_lib.hpp"
#include "readline.hpp"
#include "stardict_lib.hpp"
//this structure is wrapper and it need for unification
//results of search whith return Dicts class
@@ -13,31 +13,49 @@ struct TSearchResult {
std::string def;
std::string exp;
TSearchResult(const std::string& bookname_, const std::string& def_, const std::string& exp_)
: bookname(bookname_), def(def_), exp(exp_)
TSearchResult(const std::string &bookname_, const std::string &def_, const std::string &exp_)
: bookname(bookname_)
, def(def_)
, exp(exp_)
{
}
};
typedef std::vector<TSearchResult> TSearchResultList;
//possible return values for Library.process_phase()
enum search_result {
SEARCH_SUCCESS = 0,
SEARCH_FAILURE,
SEARCH_NO_RESULT
};
//this class is wrapper around Dicts class for easy use
//of it
class Library : public Libs {
class Library : public Libs
{
public:
Library(bool uinput, bool uoutput, bool colorize_output):
utf8_input_(uinput), utf8_output_(uoutput), colorize_output_(colorize_output) {}
Library(bool uinput, bool uoutput, bool colorize_output, bool use_json, bool no_fuzzy)
: utf8_input_(uinput)
, utf8_output_(uoutput)
, colorize_output_(colorize_output)
, json_(use_json)
{
setVerbose(!use_json);
setFuzzy(!no_fuzzy);
}
search_result process_phrase(const char *loc_str, IReadLine &io, bool force = false);
bool process_phrase(const char *loc_str, IReadLine &io, bool force = false);
private:
bool utf8_input_;
bool utf8_output_;
bool colorize_output_;
bool json_;
void SimpleLookup(const std::string &str, TSearchResultList& res_list);
void LookupWithFuzzy(const std::string &str, TSearchResultList& res_list);
void LookupWithRule(const std::string &str, TSearchResultList& res_lsit);
void LookupData(const std::string &str, TSearchResultList& res_list);
void print_search_result(FILE *out, const TSearchResult & res);
void SimpleLookup(const std::string &str, TSearchResultList &res_list);
void LookupWithFuzzy(const std::string &str, TSearchResultList &res_list);
void LookupWithRule(const std::string &str, TSearchResultList &res_lsit);
void LookupData(const std::string &str, TSearchResultList &res_list);
void print_search_result(FILE *out, const TSearchResult &res, bool &first_result);
};

View File

@@ -1,31 +1,34 @@
#pragma once
#ifdef HAVE_CONFIG_H
# include "config.h"
#include "config.h"
#endif
#ifdef HAVE_MMAP
# include <sys/types.h>
# include <fcntl.h>
# include <sys/mman.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#endif
#ifdef _WIN32
# include <windows.h>
#include <windows.h>
#endif
#include <glib.h>
class MapFile {
class MapFile
{
public:
MapFile() {}
~MapFile();
MapFile(const MapFile&) = delete;
MapFile& operator=(const MapFile&) = delete;
bool open(const char *file_name, unsigned long file_size);
MapFile(const MapFile &) = delete;
MapFile &operator=(const MapFile &) = delete;
bool open(const char *file_name, off_t file_size);
gchar *begin() { return data; }
private:
char *data = nullptr;
unsigned long size = 0ul;
#ifdef HAVE_MMAP
size_t size = 0u;
int mmap_fd = -1;
#elif defined(_WIN32)
HANDLE hFile = 0;
@@ -33,25 +36,31 @@ private:
#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
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;
}
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)) {
//g_print("mmap file %s failed!\n",idxfilename);
data=nullptr;
// g_print("mmap file %s failed!\n",idxfilename);
size = 0u;
data = nullptr;
return false;
}
#elif defined( _WIN32)
hFile = CreateFile(file_name, GENERIC_READ, 0, nullptr, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, 0);
hFileMap = CreateFileMapping(hFile, nullptr, PAGE_READONLY, 0,
file_size, nullptr);
#elif defined(_WIN32)
hFile = CreateFile(file_name, GENERIC_READ, 0, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
hFileMap = CreateFileMapping(hFile, nullptr, PAGE_READONLY, 0, file_size, nullptr);
data = (gchar *)MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, file_size);
#else
gsize read_len;
@@ -73,13 +82,12 @@ inline MapFile::~MapFile()
munmap(data, size);
close(mmap_fd);
#else
# ifdef _WIN32
#ifdef _WIN32
UnmapViewOfFile(data);
CloseHandle(hFileMap);
CloseHandle(hFile);
# else
#else
g_free(data);
# endif
#endif
#endif
}

View File

@@ -15,18 +15,18 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#include "config.h"
#endif
#include <cstdio>
#include <cstdlib>
#ifdef WITH_READLINE
# include <readline/readline.h>
# include <readline/history.h>
#include <readline/history.h>
#include <readline/readline.h>
#endif
#include <glib.h>
@@ -34,51 +34,73 @@
#include "readline.hpp"
bool stdio_getline(FILE *in, std::string & str)
bool stdio_getline(FILE *in, std::string &str)
{
assert(in != nullptr);
str.clear();
int ch;
while ((ch=fgetc(in)) != EOF && ch != '\n')
while ((ch = fgetc(in)) != EOF && ch != '\n')
str += ch;
return EOF != ch;
}
#ifndef WITH_READLINE
namespace {
class dummy_readline : public IReadLine {
public:
bool read(const std::string &banner, std::string &line) override {
namespace
{
class dummy_readline : public IReadLine
{
public:
bool read(const std::string &banner, std::string &line) override
{
printf("%s", banner.c_str());
return stdio_getline(stdin, line);
}
};
}
};
} // namespace
#else
namespace {
class real_readline : public IReadLine {
namespace
{
std::string get_hist_file_path()
{
const gchar *hist_file_str = g_getenv("SDCV_HISTFILE");
public:
real_readline() {
if (hist_file_str != nullptr)
return std::string(hist_file_str);
const std::string hist_file_path = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history";
if (g_file_test(hist_file_path.c_str(), G_FILE_TEST_IS_REGULAR))
return hist_file_path;
return std::string(g_get_user_data_dir()) + G_DIR_SEPARATOR + "sdcv_history";
}
class real_readline : public IReadLine
{
public:
real_readline()
{
rl_readline_name = "sdcv";
using_history();
const std::string histname = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history";
const std::string histname = get_hist_file_path();
read_history(histname.c_str());
}
~real_readline() {
const std::string histname = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history";
~real_readline()
{
const std::string histname = get_hist_file_path();
write_history(histname.c_str());
const gchar *hist_size_str=g_getenv("SDCV_HISTSIZE");
const gchar *hist_size_str = g_getenv("SDCV_HISTSIZE");
int hist_size;
if (!hist_size_str || sscanf(hist_size_str, "%d", &hist_size)<1)
if (!hist_size_str || sscanf(hist_size_str, "%d", &hist_size) < 1)
hist_size = 2000;
history_truncate_file(histname.c_str(), hist_size);
}
bool read(const std::string &banner, std::string& line) override {
bool read(const std::string &banner, std::string &line) override
{
char *phrase = nullptr;
phrase = readline(banner.c_str());
if (phrase) {
@@ -89,12 +111,13 @@ namespace {
return false;
}
void add_to_history(const std::string& phrase) override {
void add_to_history(const std::string &phrase) override
{
add_history(phrase.c_str());
}
};
}
#endif//WITH_READLINE
};
} // namespace
#endif //WITH_READLINE
IReadLine *create_readline_object()
{

View File

@@ -2,11 +2,12 @@
#include <string>
class IReadLine {
class IReadLine
{
public:
virtual ~IReadLine() {}
virtual bool read(const std::string &banner, std::string& line) = 0;
virtual void add_to_history(const std::string&) {}
virtual bool read(const std::string &banner, std::string &line) = 0;
virtual void add_to_history(const std::string &) {}
};
extern std::string sdcv_readline;

View File

@@ -15,23 +15,23 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <algorithm>
#include <cerrno>
#include <clocale>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <glib.h>
#include <glib/gi18n.h>
@@ -53,15 +53,16 @@ static void free_str_array(gchar **arr)
g_free(*p);
g_free(arr);
}
}
} // namespace
namespace glib
{
using StrArr = ResourceWrapper<gchar *, gchar *, free_str_array>;
using StrArr = ResourceWrapper<gchar *, gchar *, free_str_array>;
}
static void list_dicts(const std::list<std::string> &dicts_dir_list);
static void list_dicts(const std::list<std::string> &dicts_dir_list, bool use_json);
int main(int argc, char *argv[]) try {
int main(int argc, char *argv[])
try {
setlocale(LC_ALL, "");
#if ENABLE_NLS
bindtextdomain("sdcv",
@@ -75,10 +76,14 @@ int main(int argc, char *argv[]) try {
gboolean show_list_dicts = FALSE;
glib::StrArr use_dict_list;
gboolean non_interactive = FALSE;
gboolean json_output = FALSE;
gboolean no_fuzzy = FALSE;
gboolean utf8_output = FALSE;
gboolean utf8_input = FALSE;
glib::CharStr opt_data_dir;
gboolean only_data_dir = FALSE;
gboolean colorize = FALSE;
glib::StrArr word_list;
const GOptionEntry entries[] = {
{ "version", 'v', 0, G_OPTION_ARG_NONE, &show_version,
@@ -90,6 +95,12 @@ int main(int argc, char *argv[]) try {
_("bookname") },
{ "non-interactive", 'n', 0, G_OPTION_ARG_NONE, &non_interactive,
_("for use in scripts"), nullptr },
{ "json-output", 'j', 0, G_OPTION_ARG_NONE, &json_output,
_("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,
_("do not fuzzy-search for similar words, only return exact matches"), nullptr },
{ "utf8-output", '0', 0, G_OPTION_ARG_NONE, &utf8_output,
_("output must be in utf8"), nullptr },
{ "utf8-input", '1', 0, G_OPTION_ARG_NONE, &utf8_input,
@@ -97,13 +108,17 @@ int main(int argc, char *argv[]) try {
{ "data-dir", '2', 0, G_OPTION_ARG_STRING, get_addr(opt_data_dir),
_("use this directory as path to stardict data directory"),
_("path/to/dir") },
{ "only-data-dir", 'x', 0, G_OPTION_ARG_NONE, &only_data_dir,
_("only use the dictionaries in data-dir, do not search in user and system directories"), nullptr },
{ "color", 'c', 0, G_OPTION_ARG_NONE, &colorize,
_("colorize the output"), nullptr },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, get_addr(word_list),
_("search terms"), _(" words") },
{},
};
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_add_main_entries(context, entries, nullptr);
const gboolean parse_res = g_option_context_parse(context, &argc, &argv, get_addr(error));
@@ -122,25 +137,26 @@ int main(int argc, char *argv[]) try {
const gchar *stardict_data_dir = g_getenv("STARDICT_DATA_DIR");
std::string data_dir;
if (!opt_data_dir) {
if (!only_data_dir) {
if (stardict_data_dir)
data_dir = stardict_data_dir;
else
data_dir = "/usr/share/stardict/dic";
}
} else {
data_dir = get_impl(opt_data_dir);
}
const char *homedir = g_getenv("HOME");
if (!homedir)
homedir = g_get_home_dir();
const std::list<std::string> dicts_dir_list = {
std::string(homedir) + G_DIR_SEPARATOR + ".stardict" + G_DIR_SEPARATOR + "dic",
data_dir
};
std::string conf_dir = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".stardict";
if (!g_file_test(conf_dir.c_str(), G_FILE_TEST_IS_DIR))
conf_dir = std::string(g_get_user_data_dir()) + G_DIR_SEPARATOR + "stardict";
std::list<std::string> dicts_dir_list;
if (!only_data_dir)
dicts_dir_list.push_back(conf_dir + G_DIR_SEPARATOR + "dic");
dicts_dir_list.push_back(data_dir);
if (show_list_dicts) {
list_dicts(dicts_dir_list);
list_dicts(dicts_dir_list, json_output);
return EXIT_SUCCESS;
}
@@ -157,7 +173,7 @@ int main(int argc, char *argv[]) try {
});
std::list<std::string> order_list;
if (use_dict_list) {
if (use_dict_list != nullptr) {
for (auto &&x : bookname_to_ifo) {
gchar **p = get_impl(use_dict_list);
for (; *p != nullptr; ++p)
@@ -170,42 +186,59 @@ int main(int argc, char *argv[]) try {
}
// add bookname to list
gchar **p = get_impl(use_dict_list);
while (*p) {
order_list.push_back(bookname_to_ifo.at(*p));
++p;
for (gchar **p = get_impl(use_dict_list); *p != nullptr; ++p) {
auto it = bookname_to_ifo.find(*p);
if (it != bookname_to_ifo.end()) {
order_list.push_back(it->second);
} else {
fprintf(stderr, _("Unknown dictionary: %s\n"), *p);
}
}
} else {
const std::string odering_cfg_file = std::string(homedir) + G_DIR_SEPARATOR_S ".sdcv_ordering";
FILE *ordering_file = fopen(odering_cfg_file.c_str(), "r");
std::string ordering_cfg_file = std::string(g_get_user_config_dir()) + G_DIR_SEPARATOR_S "sdcv_ordering";
FILE *ordering_file = fopen(ordering_cfg_file.c_str(), "r");
if (ordering_file == nullptr) {
ordering_cfg_file = std::string(g_get_home_dir()) + G_DIR_SEPARATOR_S ".sdcv_ordering";
ordering_file = fopen(ordering_cfg_file.c_str(), "r");
}
if (ordering_file != nullptr) {
std::string 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);
}
}
const std::string conf_dir = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".stardict";
if (g_mkdir(conf_dir.c_str(), S_IRWXU) == -1 && errno != EEXIST) {
fprintf(stderr, _("g_mkdir failed: %s\n"), strerror(errno));
}
Library lib(utf8_input, utf8_output, colorize);
Library lib(utf8_input, utf8_output, colorize, json_output, no_fuzzy);
lib.load(dicts_dir_list, order_list, disable_list);
std::unique_ptr<IReadLine> io(create_readline_object());
if (optind < argc) {
for (int i = optind; i < argc; ++i)
if (!lib.process_phrase(argv[i], *io, non_interactive)) {
return EXIT_FAILURE;
if (word_list != nullptr) {
search_result rval = SEARCH_SUCCESS;
gchar **p = get_impl(word_list);
while (*p) {
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) {
std::string phrase;
while (io->read(_("Enter word or phrase: "), phrase)) {
if (!lib.process_phrase(phrase.c_str(), *io))
if (lib.process_phrase(phrase.c_str(), *io) == SEARCH_FAILURE)
return EXIT_FAILURE;
phrase.clear();
}
@@ -220,17 +253,31 @@ int main(int argc, char *argv[]) try {
exit(EXIT_FAILURE);
}
static void list_dicts(const std::list<std::string> &dicts_dir_list)
static void list_dicts(const std::list<std::string> &dicts_dir_list, bool use_json)
{
bool first_entry = true;
if (!use_json)
printf(_("Dictionary's name Word count\n"));
else
fputc('[', stdout);
std::list<std::string> order_list, disable_list;
for_each_file(dicts_dir_list, ".ifo", order_list,
disable_list, [](const std::string &filename, bool) -> void {
disable_list, [use_json, &first_entry](const std::string &filename, bool) -> void {
DictInfo dict_info;
if (dict_info.load_from_ifo_file(filename, false)) {
const std::string bookname = utf8_to_locale_ign_err(dict_info.bookname);
if (use_json) {
if (first_entry) {
first_entry = false;
} else {
fputc(',', stdout); // comma between entries
}
printf("{\"name\": \"%s\", \"wordcount\": \"%d\"}", json_escape_string(bookname).c_str(), dict_info.wordcount);
} else {
printf("%s %d\n", bookname.c_str(), dict_info.wordcount);
}
}
});
if (use_json)
fputs("]\n", stdout);
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,17 +1,17 @@
#pragma once
#include <cstdio>
#include <cstring>
#include <functional>
#include <list>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include <functional>
#include "dictziplib.hpp"
const int MAX_MATCH_ITEM_PER_LIB=100;
const int MAX_FUZZY_DISTANCE= 3; // at most MAX_FUZZY_DISTANCE-1 differences allowed when find similar words
const int MAX_MATCH_ITEM_PER_LIB = 100;
const int MAX_FUZZY_DISTANCE = 3; // at most MAX_FUZZY_DISTANCE-1 differences allowed when find similar words
inline guint32 get_uint32(const gchar *addr)
{
@@ -25,155 +25,202 @@ inline void set_uint32(gchar *addr, guint32 val)
memcpy(addr, &val, sizeof(guint32));
}
struct cacheItem {
guint32 offset;
gchar *data;
//write code here to make it inline
cacheItem() { data = nullptr;}
// write code here to make it inline
cacheItem() { data = nullptr; }
~cacheItem() { g_free(data); }
};
const int WORDDATA_CACHE_NUM = 10;
const int INVALID_INDEX=-100;
const int INVALID_INDEX = -100;
class DictBase {
class DictBase
{
public:
DictBase() {}
~DictBase() {
~DictBase()
{
if (dictfile)
fclose(dictfile);
}
DictBase(const DictBase&) = delete;
DictBase& operator=(const DictBase&) = delete;
gchar * GetWordData(guint32 idxitem_offset, guint32 idxitem_size);
bool containSearchData() const {
DictBase(const DictBase &) = delete;
DictBase &operator=(const DictBase &) = delete;
gchar *GetWordData(guint32 idxitem_offset, guint32 idxitem_size);
bool containSearchData() const
{
if (sametypesequence.empty())
return true;
return sametypesequence.find_first_of("mlgxty") != std::string::npos;
}
bool SearchData(std::vector<std::string> &SearchWords, guint32 idxitem_offset, guint32 idxitem_size, gchar *origin_data);
protected:
std::string sametypesequence;
FILE *dictfile = nullptr;
std::unique_ptr<DictData> dictdzfile;
private:
cacheItem cache[WORDDATA_CACHE_NUM];
gint cache_cur = 0;
};
//this structure contain all information about dictionary
// this structure contain all information about dictionary
struct DictInfo {
std::string ifo_file_name;
guint32 wordcount;
guint32 syn_wordcount;
std::string bookname;
std::string author;
std::string email;
std::string website;
std::string date;
std::string description;
guint32 index_file_size;
off_t index_file_size;
off_t syn_file_size;
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);
};
class IIndexFile {
class IIndexFile
{
public:
guint32 wordentry_offset;
guint32 wordentry_size;
virtual ~IIndexFile() {}
virtual bool load(const std::string& url, gulong wc, gulong fsize) = 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 void get_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 Dict : public DictBase {
class SynFile
{
public:
SynFile() {}
~SynFile() {}
bool load(const std::string &url, gulong wc);
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:
MapFile synfile;
std::vector<gchar *> synlist;
};
class Dict : public DictBase
{
public:
Dict() {}
Dict(const Dict&) = delete;
Dict& operator=(const Dict&) = delete;
bool load(const std::string& ifofilename);
Dict(const Dict &) = delete;
Dict &operator=(const Dict &) = delete;
bool load(const std::string &ifofilename, bool verbose);
gulong narticles() const { return wordcount; }
const std::string& dict_name() const { return bookname; }
const std::string& ifofilename() const { return ifo_file_name; }
const std::string &dict_name() const { return bookname; }
const std::string &ifofilename() const { return ifo_file_name; }
const gchar *get_key(glong index) { return idx_file->get_key(index); }
gchar *get_data(glong index) {
gchar *get_data(glong index)
{
idx_file->get_data(index);
return DictBase::GetWordData(idx_file->wordentry_offset, idx_file->wordentry_size);
}
void get_key_and_data(glong index, const gchar **key, guint32 *offset, guint32 *size) {
void get_key_and_data(glong index, const gchar **key, guint32 *offset, guint32 *size)
{
*key = idx_file->get_key_and_data(index);
*offset = idx_file->wordentry_offset;
*size = idx_file->wordentry_size;
}
bool Lookup(const char *str, glong &idx) { return idx_file->lookup(str, 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);
private:
std::string ifo_file_name;
gulong wordcount;
gulong syn_wordcount;
std::string bookname;
std::unique_ptr<IIndexFile> idx_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
{
public:
Libs(std::function<void(void)> f = std::function<void(void)>()) {
Libs(std::function<void(void)> f = std::function<void(void)>())
{
progress_func = f;
iMaxFuzzyDistance = MAX_FUZZY_DISTANCE; //need to read from cfg.
iMaxFuzzyDistance = MAX_FUZZY_DISTANCE; // need to read from cfg.
}
void setVerbose(bool verbose) { verbose_ = verbose; }
void setFuzzy(bool fuzzy) { fuzzy_ = fuzzy; }
~Libs();
Libs(const Libs&) = delete;
Libs& operator=(const Libs&) = delete;
Libs(const Libs &) = delete;
Libs &operator=(const Libs &) = delete;
void load_dict(const std::string& url);
void load(const std::list<std::string>& dicts_dirs,
const std::list<std::string>& order_list,
const std::list<std::string>& disable_list);
void load_dict(const std::string &url);
void load(const std::list<std::string> &dicts_dirs,
const std::list<std::string> &order_list,
const std::list<std::string> &disable_list);
glong narticles(int idict) const { return oLib[idict]->narticles(); }
const std::string& dict_name(int idict) const { return oLib[idict]->dict_name(); }
const std::string &dict_name(int idict) const { return oLib[idict]->dict_name(); }
gint ndicts() const { return oLib.size(); }
const gchar *poGetWord(glong iIndex, int iLib) {
const gchar *poGetWord(glong iIndex, int iLib)
{
return oLib[iLib]->get_key(iIndex);
}
gchar * poGetWordData(glong iIndex,int iLib) {
gchar *poGetWordData(glong iIndex, int iLib)
{
if (iIndex == INVALID_INDEX)
return nullptr;
return oLib[iLib]->get_data(iIndex);
}
const gchar *poGetCurrentWord(glong *iCurrent);
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);
bool LookupWord(const gchar *sWord, std::set<glong> &iWordIndices, int iLib)
{
return oLib[iLib]->Lookup(sWord, iWordIndices);
}
bool LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib);
bool SimpleLookupWord(const gchar* sWord, glong & iWordIndex, int iLib);
bool LookupSimilarWord(const gchar *sWord, std::set<glong> &iWordIndices, int iLib);
bool SimpleLookupWord(const gchar *sWord, std::set<glong> &iWordIndices, int iLib);
bool LookupWithFuzzy(const gchar *sWord, gchar *reslist[], gint reslist_size);
gint LookupWithRule(const gchar *sWord, gchar *reslist[]);
bool LookupData(const gchar *sWord, std::vector<gchar *> *reslist);
protected:
bool fuzzy_;
private:
std::vector<Dict *> oLib; // word Libs.
int iMaxFuzzyDistance;
std::function<void(void)> progress_func;
bool verbose_;
};
enum query_t {
qtSIMPLE, qtREGEXP, qtFUZZY, qtDATA
qtSIMPLE,
qtREGEXP,
qtFUZZY,
qtDATA
};
extern query_t analyze_query(const char *s, std::string& res);
extern query_t analyze_query(const char *s, std::string &res);

View File

@@ -15,22 +15,24 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#include "config.h"
#endif
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <glib.h>
#include <glib/gi18n.h>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include "utils.hpp"
std::string utf8_to_locale_ign_err(const std::string& utf8_str)
std::string utf8_to_locale_ign_err(const std::string &utf8_str)
{
std::string res;
@@ -42,7 +44,7 @@ std::string utf8_to_locale_ign_err(const std::string& utf8_str)
glib::Error err;
glib::CharStr tmp(g_convert_with_fallback(utf8_str.c_str(), -1, charset, "UTF-8", nullptr,
&bytes_read, &bytes_written, get_addr(err)));
if (nullptr == get_impl(tmp)){
if (nullptr == get_impl(tmp)) {
fprintf(stderr, _("Can not convert %s to current locale.\n"), utf8_str.c_str());
fprintf(stderr, "%s\n", err->message);
exit(EXIT_FAILURE);
@@ -53,24 +55,23 @@ std::string utf8_to_locale_ign_err(const std::string& utf8_str)
return res;
}
static void __for_each_file(const std::string& dirname, const std::string& suff,
const std::list<std::string>& order_list, const std::list<std::string>& disable_list,
const std::function<void (const std::string&, bool)>& f)
static void __for_each_file(const std::string &dirname, const std::string &suff,
const std::list<std::string> &order_list, const std::list<std::string> &disable_list,
const std::function<void(const std::string &, bool)> &f)
{
GDir *dir = g_dir_open(dirname.c_str(), 0, nullptr);
if (dir) {
const gchar *filename;
while ((filename = g_dir_read_name(dir))!=nullptr) {
const std::string fullfilename(dirname+G_DIR_SEPARATOR_S+filename);
while ((filename = g_dir_read_name(dir)) != nullptr) {
const std::string fullfilename(dirname + G_DIR_SEPARATOR_S + filename);
if (g_file_test(fullfilename.c_str(), G_FILE_TEST_IS_DIR))
__for_each_file(fullfilename, suff, order_list, disable_list, f);
else if (g_str_has_suffix(filename, suff.c_str()) &&
std::find(order_list.begin(), order_list.end(),
fullfilename)==order_list.end()) {
else if (g_str_has_suffix(filename, suff.c_str()) && std::find(order_list.begin(), order_list.end(), fullfilename) == order_list.end()) {
const bool disable = std::find(disable_list.begin(),
disable_list.end(),
fullfilename)!=disable_list.end();
fullfilename)
!= disable_list.end();
f(fullfilename, disable);
}
}
@@ -78,15 +79,53 @@ static void __for_each_file(const std::string& dirname, const std::string& suff,
}
}
void for_each_file(const std::list<std::string>& dirs_list, const std::string& suff,
const std::list<std::string>& order_list, const std::list<std::string>& disable_list,
const std::function<void (const std::string&, bool)>& f)
void for_each_file(const std::list<std::string> &dirs_list, const std::string &suff,
const std::list<std::string> &order_list, const std::list<std::string> &disable_list,
const std::function<void(const std::string &, bool)> &f)
{
for (const std::string & item : order_list) {
for (const std::string &item : order_list) {
const bool disable = std::find(disable_list.begin(), disable_list.end(), item) != disable_list.end();
f(item, disable);
}
for (const std::string& item : dirs_list)
for (const std::string &item : dirs_list)
__for_each_file(item, suff, order_list, disable_list, f);
}
// based on https://stackoverflow.com/questions/7724448/simple-json-string-escape-for-c/33799784#33799784
std::string json_escape_string(const std::string &s)
{
std::ostringstream o;
for (auto c = s.cbegin(); c != s.cend(); c++) {
switch (*c) {
case '"':
o << "\\\"";
break;
case '\\':
o << "\\\\";
break;
case '\b':
o << "\\b";
break;
case '\f':
o << "\\f";
break;
case '\n':
o << "\\n";
break;
case '\r':
o << "\\r";
break;
case '\t':
o << "\\t";
break;
default:
if ('\x00' <= *c && *c <= '\x1f') {
o << "\\u"
<< std::hex << std::setw(4) << std::setfill('0') << (int)*c;
} else {
o << *c;
}
}
}
return o.str();
}

View File

@@ -1,68 +1,78 @@
#pragma once
#include <glib.h>
#include <cassert>
#include <string>
#include <list>
#include <cstddef>
#include <functional>
#include <glib.h>
#include <list>
#include <string>
template <typename T, typename unref_res_t, void (*unref_res)(unref_res_t *)>
class ResourceWrapper {
class ResourceWrapper
{
public:
ResourceWrapper(T *p = nullptr) : p_(p) {}
ResourceWrapper(T *p = nullptr)
: p_(p)
{
}
~ResourceWrapper() { free_resource(); }
ResourceWrapper(const ResourceWrapper&) = delete;
ResourceWrapper& operator=(const ResourceWrapper&) = delete;
ResourceWrapper(const ResourceWrapper &) = delete;
ResourceWrapper &operator=(const ResourceWrapper &) = delete;
T *operator->() const { return p_; }
bool operator!() const { return p_ == nullptr; }
const T& operator[](size_t idx) const {
const T &operator[](size_t idx) const
{
assert(p_ != nullptr);
return p_[idx];
}
void reset(T *newp) {
void reset(T *newp)
{
if (p_ != newp) {
free_resource();
p_ = newp;
}
}
friend inline T *get_impl(const ResourceWrapper& rw) {
friend inline bool operator==(const ResourceWrapper &lhs, std::nullptr_t) noexcept
{
return !lhs.p_;
}
friend inline bool operator!=(const ResourceWrapper &lhs, std::nullptr_t) noexcept
{
return !!lhs.p_;
}
friend inline T *get_impl(const ResourceWrapper &rw)
{
return rw.p_;
}
friend inline T **get_addr(ResourceWrapper& rw) {
friend inline T **get_addr(ResourceWrapper &rw)
{
return &rw.p_;
}
private:
T *p_;
void free_resource() { if (p_) unref_res(p_); }
// Helper for enabling 'if (sp)'
struct Tester {
Tester() {}
private:
void operator delete(void*);
};
public:
// enable 'if (sp)'
operator Tester*() const {
if (!*this)
return 0;
static Tester t;
return &t;
void free_resource()
{
if (p_)
unref_res(p_);
}
};
namespace glib {
typedef ResourceWrapper<gchar, void, g_free> CharStr;
typedef ResourceWrapper<GError, GError, g_error_free> Error;
}
namespace glib
{
typedef ResourceWrapper<gchar, void, g_free> CharStr;
typedef ResourceWrapper<GError, GError, g_error_free> Error;
} // namespace glib
extern std::string utf8_to_locale_ign_err(const std::string& utf8_str);
extern std::string utf8_to_locale_ign_err(const std::string &utf8_str);
extern void for_each_file(const std::list<std::string>& dirs_list, const std::string& suff,
const std::list<std::string>& order_list, const std::list<std::string>& disable_list,
const std::function<void (const std::string&, bool)>& f);
extern void for_each_file(const std::list<std::string> &dirs_list, const std::string &suff,
const std::list<std::string> &order_list, const std::list<std::string> &disable_list,
const std::function<void(const std::string &, bool)> &f);
extern std::string json_escape_string(const std::string &str);

View 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=

Binary file not shown.

Binary file not shown.

View 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=

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,7 @@
StarDict's dict ifo file
version=2.4.2
bookname=Test synonyms
wordcount=2
synwordcount=2
idxfilesize=32
sametypesequence=m

Binary file not shown.

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<stardict xmlns:xi="http://www.w3.org/2003/XInclude">
<info>
<version>2.4.2</version>
<bookname>Test synonyms</bookname>
<author></author>
<email></email>
<website></website>
<description></description>
<date></date>
<dicttype></dicttype>
</info>
<article><key>test</key><synonym>foo</synonym><synonym>bar</synonym>
<definition type="m">
<![CDATA[result of test]]>
</definition>
</article>
<article><key>testawordy</key>
<definition type="m">
<![CDATA[word that ends in y to test with fuzzy search in -ied]]>
</definition>
</article>
</stardict>

View File

@@ -6,7 +6,7 @@ unset SDCV_PAGER
have=`"$PATH_TO_SDCV" --data-dir /tmp/bugagaga -l | wc -l`
#do not count header
have=$(($have-1))
ndicts=`find "${HOME}"/.stardict/dic -name "*.ifo" -print | wc -l`
ndicts=`find "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic -name "*.ifo" -print | wc -l`
#ndicts=$(($ndicts+1))
if [ $have -ne $ndicts ]; then
ndicts=$(($ndicts-1))

24
tests/t_exact Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/sh
set -e
SDCV="$1"
TEST_DIR="$2"
unset SDCV_PAGER
test_word() {
WORD=$1
EXPECTED=$2
TAG=$3
RES=$($SDCV -e -n --data-dir "$TEST_DIR" -u "Test synonyms" $WORD | grep "$TAG")
if [ "$EXPECTED" != "$RES" ]; then
echo "synonym for $WORD should be '$EXPECTED' but was '$RES'"
exit 1
fi
}
test_word testawordies "Nothing similar to testawordies, sorry :(" "Nothing similar"
test_word testawordy "word that ends in y to test with fuzzy search in -ied" "fuzzy"
exit 0

32
tests/t_json Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/sh
set -e
SDCV="$1"
TEST_DIR="$2"
unset SDCV_PAGER
unset STARDICT_DATA_DIR
test_json() {
EXPECTED=$(echo "$1" | jq 'sort')
shift
RESULT=$($SDCV "$@" | jq 'sort')
if [ "$EXPECTED" != "$RESULT" ]; then
echo "expected $EXPECTED but got $RESULT"
exit 1
fi
}
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 '[]' -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

View File

@@ -4,7 +4,7 @@ PATH_TO_SDCV="$1"
ndicts=`"$PATH_TO_SDCV" -l | wc -l`
ndicts=$(($ndicts-1))
ncom=`find /usr/share/stardict/dic -name "*.ifo" | wc -l`
nspe=`find "${HOME}"/.stardict/dic -name "*.ifo" | wc -l`
nspe=`find "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic -name "*.ifo" | wc -l`
nmy=$(($ncom+$nspe))
if [ $nmy -ne $ndicts ]; then

67
tests/t_multiple_results Executable file
View 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
View 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

19
tests/t_only_data_dir Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/sh
set -e
SDCV="$1"
TEST_DIR="$2"
unset SDCV_PAGER
unset STARDICT_DATA_DIR
DICTS=$($SDCV -x -n -l --data-dir "$TEST_DIR" | tail -n +2 | wc -l)
# the expected result:
ACTUAL_DICTS=$(find "$TEST_DIR" -name "*.ifo" | wc -l)
if [ $DICTS -ne $ACTUAL_DICTS ]; then
echo "number of dictionaries in $TEST_DIR should be $ACTUAL_DICTS but was $DICTS according to sdcv"
exit 1
fi
exit 0

22
tests/t_return_code Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/sh
SDCV="$1"
TEST_DIR="$2"
unset SDCV_PAGER
test_return_code() {
WORD=$1
EXPECTED=$2
$SDCV -e -n --data-dir "$TEST_DIR" -u "Test synonyms" $WORD > /dev/null
RC=$?
if [ $RC -ne $EXPECTED ]; then
echo "Return code for $WORD should be '$EXPECTED' but was '$RC'"
exit 1
fi
}
test_return_code testawordy 0
test_return_code testawordies 2
exit 0

22
tests/t_synonyms Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/sh
set -e
SDCV="$1"
TEST_DIR="$2"
unset SDCV_PAGER
test_word() {
WORD=$1
RES=$($SDCV -n --data-dir "$TEST_DIR" -u "Test synonyms" $WORD | grep result)
if [ "result of test" != "$RES" ]; then
echo "synonym for $WORD should be 'result of test' but was '$RES'"
exit 1
fi
}
test_word foo
test_word bar
test_word test
exit 0

View File

@@ -5,8 +5,8 @@ set -e
PATH_TO_SDCV="$1"
TESTS_DIR="$2"
mkdir -p "${HOME}"/.stardict/dic
cp -R "${TESTS_DIR}/stardict-test_dict-2.4.2" "${HOME}"/.stardict/dic
mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic
cp -R "${TESTS_DIR}/stardict-test_dict-2.4.2" "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic
unset SDCV_PAGER
RES=`"$PATH_TO_SDCV" -n -u test_dict test | grep "test passed"`
@@ -15,6 +15,6 @@ if [ -z "$RES" ]; then
exit 1
fi
rm -fr "${HOME}"/.stardict/dic/stardict-test_dict-2.4.2
rm -fr "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic/stardict-test_dict-2.4.2
exit 0

View File

@@ -4,9 +4,8 @@ set -e
PATH_TO_SDCV="$1"
TESTS_DIR="$2"
mkdir -p "${HOME}"/.stardict/dic
cp -R "${TESTS_DIR}/rus-eng-stardict-2.4.2" "${HOME}"/.stardict/dic/
mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic
cp -R "${TESTS_DIR}/rus-eng-stardict-2.4.2" "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic/
unset SDCV_PAGER
export LANG=ru_RU.KOI8-R