mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-15 17:31:56 +00:00
Compare commits
11 Commits
sdcv_on_ru
...
v0.5.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82a06b8e69 | ||
|
|
73d6098010 | ||
|
|
5c1357840c | ||
|
|
1667de0650 | ||
|
|
97b13e6702 | ||
|
|
d9f273b858 | ||
|
|
84367a5744 | ||
|
|
7df514e117 | ||
|
|
a1a614b81f | ||
|
|
913fd0a312 | ||
|
|
2d95bd0b12 |
@@ -27,11 +27,15 @@ if (NOT GLIB2_FOUND)
|
||||
"make sure that you install it")
|
||||
endif()
|
||||
|
||||
find_path(READLINE_INCLUDE_DIR readline/readline.h)
|
||||
find_library(READLINE_LIBRARY NAMES readline)
|
||||
if (READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
|
||||
set(WITH_READLINE True)
|
||||
endif ()
|
||||
set(WITH_READLINE True CACHE BOOL "Use readline library")
|
||||
|
||||
if (WITH_READLINE)
|
||||
find_path(READLINE_INCLUDE_DIR readline/readline.h)
|
||||
find_library(READLINE_LIBRARY NAMES readline)
|
||||
if (NOT (READLINE_INCLUDE_DIR AND READLINE_LIBRARY))
|
||||
set(WITH_READLINE False CACHE FORCE)
|
||||
endif ()
|
||||
endif (WITH_READLINE)
|
||||
|
||||
option(ENABLE_NLS "Enable NLS support" True)
|
||||
|
||||
@@ -84,6 +88,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake
|
||||
include_directories(
|
||||
${ZLIB_INCLUDE_DIR}
|
||||
${GLIB2_INCLUDE_DIRS}
|
||||
${READLINE_INCLUDE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/lib
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
@@ -96,7 +101,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 "0-beta4")
|
||||
set(CPACK_PACKAGE_VERSION_PATCH "1")
|
||||
|
||||
set(sdcv_VERSION
|
||||
"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
|
||||
|
||||
4
po/ru.po
4
po/ru.po
@@ -19,11 +19,11 @@ 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:80
|
||||
#: src/sdcv.cpp:76
|
||||
msgid "display version information and exit"
|
||||
msgstr "показать номер версии и завершить работу"
|
||||
|
||||
#: src/sdcv.cpp:82
|
||||
#: src/sdcv.cpp:78
|
||||
msgid "display list of available dictionaries and exit"
|
||||
msgstr "показать список доступных словарей и завершить работу"
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ namespace {
|
||||
sdcv_pager& operator=(const sdcv_pager&) = delete;
|
||||
~sdcv_pager() {
|
||||
if (output != stdout)
|
||||
fclose(output);
|
||||
pclose(output);
|
||||
}
|
||||
FILE *get_stream() { return output; }
|
||||
private:
|
||||
|
||||
@@ -34,21 +34,22 @@
|
||||
|
||||
#include "readline.hpp"
|
||||
|
||||
bool stdio_getline(FILE *in, std::string & str)
|
||||
{
|
||||
assert(in != nullptr);
|
||||
str.clear();
|
||||
int ch;
|
||||
while ((ch=fgetc(in)) != EOF && ch != '\n')
|
||||
str += ch;
|
||||
|
||||
return EOF != ch;
|
||||
}
|
||||
|
||||
#ifndef WITH_READLINE
|
||||
namespace {
|
||||
static bool stdio_getline(FILE *in, std::string & str)
|
||||
{
|
||||
str.clear();
|
||||
int ch;
|
||||
while ((ch=fgetc(in)) != EOF && ch != '\n')
|
||||
str += ch;
|
||||
|
||||
return EOF != ch;
|
||||
}
|
||||
|
||||
class dummy_readline : public IReadLine {
|
||||
public:
|
||||
bool read(const string& banner, string& line) override {
|
||||
bool read(const std::string &banner, std::string &line) override {
|
||||
printf("%s", banner.c_str());
|
||||
return stdio_getline(stdin, line);
|
||||
}
|
||||
|
||||
@@ -11,4 +11,4 @@ public:
|
||||
|
||||
extern std::string sdcv_readline;
|
||||
extern IReadLine *create_readline_object();
|
||||
|
||||
extern bool stdio_getline(FILE *in, std::string &str);
|
||||
|
||||
96
src/sdcv.cpp
96
src/sdcv.cpp
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* This file part of sdcv - console version of Stardict program
|
||||
* http://sdcv.sourceforge.net
|
||||
* Copyright (C) 2003-2006 Evgeniy <dushistov@mail.ru>
|
||||
@@ -30,6 +30,8 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
@@ -54,9 +56,11 @@ static void free_str_array(gchar **arr)
|
||||
}
|
||||
namespace glib
|
||||
{
|
||||
typedef ResourceWrapper<gchar *, gchar *, free_str_array> StrArr;
|
||||
using StrArr = ResourceWrapper<gchar *, gchar *, free_str_array>;
|
||||
}
|
||||
|
||||
static void list_dicts(const std::list<std::string> &dicts_dir_list);
|
||||
|
||||
int main(int argc, char *argv[]) try {
|
||||
setlocale(LC_ALL, "");
|
||||
#if ENABLE_NLS
|
||||
@@ -95,7 +99,7 @@ int main(int argc, char *argv[]) try {
|
||||
_("path/to/dir") },
|
||||
{ "color", 'c', 0, G_OPTION_ARG_NONE, &colorize,
|
||||
_("colorize the output"), nullptr },
|
||||
{ nullptr },
|
||||
{},
|
||||
};
|
||||
|
||||
glib::Error error;
|
||||
@@ -136,52 +140,67 @@ int main(int argc, char *argv[]) try {
|
||||
};
|
||||
|
||||
if (show_list_dicts) {
|
||||
printf(_("Dictionary's name Word count\n"));
|
||||
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 {
|
||||
DictInfo dict_info;
|
||||
if (dict_info.load_from_ifo_file(filename, false)) {
|
||||
const std::string bookname = utf8_to_locale_ign_err(dict_info.bookname);
|
||||
printf("%s %d\n", bookname.c_str(), dict_info.wordcount);
|
||||
}
|
||||
});
|
||||
|
||||
list_dicts(dicts_dir_list);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
std::list<std::string> disable_list;
|
||||
|
||||
std::map<std::string, std::string> bookname_to_ifo;
|
||||
for_each_file(dicts_dir_list, ".ifo", std::list<std::string>(), std::list<std::string>(),
|
||||
[&bookname_to_ifo](const std::string &fname, bool) {
|
||||
DictInfo dict_info;
|
||||
const bool load_ok = dict_info.load_from_ifo_file(fname, false);
|
||||
if (!load_ok)
|
||||
return;
|
||||
bookname_to_ifo[dict_info.bookname] = dict_info.ifo_file_name;
|
||||
});
|
||||
|
||||
std::list<std::string> order_list;
|
||||
if (use_dict_list) {
|
||||
std::list<std::string> empty_list;
|
||||
for (auto &&x : bookname_to_ifo) {
|
||||
gchar **p = get_impl(use_dict_list);
|
||||
for (; *p != nullptr; ++p)
|
||||
if (x.first.compare(*p) == 0) {
|
||||
break;
|
||||
}
|
||||
if (*p == nullptr) {
|
||||
disable_list.push_back(x.second);
|
||||
}
|
||||
}
|
||||
|
||||
for_each_file(dicts_dir_list, ".ifo", empty_list, empty_list,
|
||||
[&disable_list, &use_dict_list](const std::string &filename, bool) -> void {
|
||||
DictInfo dict_info;
|
||||
const bool load_ok = dict_info.load_from_ifo_file(filename, false);
|
||||
if (!load_ok)
|
||||
return;
|
||||
|
||||
for (gchar **p = get_impl(use_dict_list); *p != nullptr; ++p)
|
||||
if (strcmp(*p, dict_info.bookname.c_str()) == 0)
|
||||
return;
|
||||
disable_list.push_back(dict_info.ifo_file_name);
|
||||
});
|
||||
// add bookname to list
|
||||
gchar **p = get_impl(use_dict_list);
|
||||
while (*p) {
|
||||
order_list.push_back(bookname_to_ifo.at(*p));
|
||||
++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");
|
||||
if (ordering_file != nullptr) {
|
||||
std::string line;
|
||||
while (stdio_getline(ordering_file, line)) {
|
||||
order_list.push_back(bookname_to_ifo.at(line));
|
||||
}
|
||||
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)
|
||||
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);
|
||||
std::list<std::string> empty_list;
|
||||
lib.load(dicts_dir_list, empty_list, disable_list);
|
||||
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))
|
||||
if (!lib.process_phrase(argv[i], *io, non_interactive)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
} else if (!non_interactive) {
|
||||
|
||||
std::string phrase;
|
||||
@@ -200,3 +219,18 @@ int main(int argc, char *argv[]) try {
|
||||
fprintf(stderr, "Internal error: %s\n", ex.what());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void list_dicts(const std::list<std::string> &dicts_dir_list)
|
||||
{
|
||||
printf(_("Dictionary's name Word count\n"));
|
||||
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 {
|
||||
DictInfo dict_info;
|
||||
if (dict_info.load_from_ifo_file(filename, false)) {
|
||||
const std::string bookname = utf8_to_locale_ign_err(dict_info.bookname);
|
||||
printf("%s %d\n", bookname.c_str(), dict_info.wordcount);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -909,33 +909,6 @@ void Libs::load(const std::list<std::string>& dicts_dirs,
|
||||
});
|
||||
}
|
||||
|
||||
void Libs::reload(const std::list<std::string>& dicts_dirs,
|
||||
const std::list<std::string>& order_list,
|
||||
const std::list<std::string>& disable_list)
|
||||
{
|
||||
std::vector<Dict *> prev(oLib);
|
||||
oLib.clear();
|
||||
|
||||
for_each_file(dicts_dirs, ".ifo", order_list, disable_list,
|
||||
[&prev, this](const std::string& url, bool disable) -> void {
|
||||
if (!disable) {
|
||||
auto it = prev.begin();
|
||||
for (; it != prev.end(); ++it)
|
||||
if ((*it)->ifofilename() == url)
|
||||
break;
|
||||
if (it != prev.end()) {
|
||||
Dict *res = *it;
|
||||
prev.erase(it);
|
||||
oLib.push_back(res);
|
||||
} else
|
||||
load_dict(url);
|
||||
}
|
||||
});
|
||||
|
||||
for (Dict *p : prev)
|
||||
delete p;
|
||||
}
|
||||
|
||||
const gchar *Libs::poGetCurrentWord(glong * iCurrent)
|
||||
{
|
||||
const gchar *poCurrentWord = nullptr;
|
||||
|
||||
@@ -139,10 +139,6 @@ public:
|
||||
void load(const std::list<std::string>& dicts_dirs,
|
||||
const std::list<std::string>& order_list,
|
||||
const std::list<std::string>& disable_list);
|
||||
void reload(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(); }
|
||||
gint ndicts() const { return oLib.size(); }
|
||||
|
||||
Reference in New Issue
Block a user