Commit Graph

171 Commits

Author SHA1 Message Date
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 v0.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