19 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
9 changed files with 51 additions and 28 deletions

View File

@@ -20,12 +20,13 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
os: [ubuntu-20.04, ubuntu-latest]
steps:
- uses: actions/checkout@v2
- 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 }}

View File

@@ -95,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 "4")
set(CPACK_PACKAGE_VERSION_PATCH "5")
set(sdcv_VERSION
"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")

12
NEWS
View File

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

View File

@@ -1,6 +1,9 @@
#+OPTIONS: ^:nil
[[https://github.com/Dushistov/sdcv/actions?query=workflow%3ACI+branch%3Amaster][https://github.com/Dushistov/sdcv/workflows/CI/badge.svg]]
[[https://github.com/Dushistov/sdcv/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

View File

@@ -27,7 +27,7 @@ public:
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;
@@ -47,7 +47,7 @@ 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;

View File

@@ -22,13 +22,13 @@ public:
~MapFile();
MapFile(const MapFile &) = delete;
MapFile &operator=(const MapFile &) = delete;
bool open(const char *file_name, unsigned long file_size);
bool open(const char *file_name, off_t file_size);
gchar *begin() { return data; }
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;
@@ -36,9 +36,8 @@ 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);
@@ -46,14 +45,16 @@ inline bool MapFile::open(const char *file_name, unsigned long file_size)
}
struct stat st;
if (fstat(mmap_fd, &st) == -1 || st.st_size < 0 || (st.st_size == 0 && S_ISREG(st.st_mode))
|| sizeof(st.st_size) > sizeof(file_size) || static_cast<unsigned long>(st.st_size) != file_size) {
|| st.st_size != file_size) {
close(mmap_fd);
return false;
}
data = (gchar *)mmap(nullptr, file_size, PROT_READ, MAP_SHARED, mmap_fd, 0);
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);
size = 0u;
data = nullptr;
return false;
}

View File

@@ -186,10 +186,13 @@ 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 {
std::string ordering_cfg_file = std::string(g_get_user_config_dir()) + G_DIR_SEPARATOR_S "sdcv_ordering";
@@ -201,7 +204,12 @@ try {
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);
}

View File

@@ -429,7 +429,7 @@ public:
if (idxfile)
fclose(idxfile);
}
bool load(const std::string &url, gulong wc, gulong fsize, bool verbose) override;
bool load(const std::string &url, gulong wc, off_t fsize, bool verbose) override;
const gchar *get_key(glong idx) override;
void get_data(glong idx) override { get_key(idx); }
const gchar *get_key_and_data(glong idx) override
@@ -489,7 +489,7 @@ public:
{
}
~WordListIndex() { g_free(idxdatabuf); }
bool load(const std::string &url, gulong wc, gulong fsize, bool verbose) override;
bool load(const std::string &url, gulong wc, off_t fsize, bool verbose) override;
const gchar *get_key(glong idx) override { return wordlist[idx]; }
void get_data(glong idx) override;
const gchar *get_key_and_data(glong idx) override
@@ -615,7 +615,7 @@ bool OffsetIndex::save_cache(const std::string &url, bool verbose)
return false;
}
bool OffsetIndex::load(const std::string &url, gulong wc, gulong fsize, bool verbose)
bool OffsetIndex::load(const std::string &url, gulong wc, off_t fsize, bool verbose)
{
wordcount = wc;
gulong npages = (wc - 1) / ENTR_PER_PAGE + 2;
@@ -758,7 +758,7 @@ bool OffsetIndex::lookup(const char *str, std::set<glong> &idxs, glong &next_idx
return bFound;
}
bool WordListIndex::load(const std::string &url, gulong wc, gulong fsize, bool)
bool WordListIndex::load(const std::string &url, gulong wc, off_t fsize, bool)
{
gzFile in = gzopen(url.c_str(), "rb");
if (in == nullptr)
@@ -771,7 +771,7 @@ bool WordListIndex::load(const std::string &url, gulong wc, gulong fsize, bool)
if (len < 0)
return false;
if (gulong(len) != fsize)
if (static_cast<off_t>(len) != fsize)
return false;
wordlist.resize(wc + 1);
@@ -920,7 +920,7 @@ bool Dict::Lookup(const char *str, std::set<glong> &idxs, glong &next_idx)
bool Dict::load(const std::string &ifofilename, bool verbose)
{
gulong idxfilesize;
off_t idxfilesize;
if (!load_ifofile(ifofilename, idxfilesize))
return false;
@@ -964,7 +964,7 @@ bool Dict::load(const std::string &ifofilename, bool verbose)
return true;
}
bool Dict::load_ifofile(const std::string &ifofilename, gulong &idxfilesize)
bool Dict::load_ifofile(const std::string &ifofilename, off_t &idxfilesize)
{
DictInfo dict_info;
if (!dict_info.load_from_ifo_file(ifofilename, false))

View File

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