mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-16 01:41:55 +00:00
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).
This commit is contained in:
@@ -332,17 +332,10 @@ search_result Library::process_phrase(const char *loc_str, IReadLine &io, bool f
|
|||||||
glib::Error err;
|
glib::Error err;
|
||||||
search_result rval = SEARCH_SUCCESS;
|
search_result rval = SEARCH_SUCCESS;
|
||||||
glib::CharStr str;
|
glib::CharStr str;
|
||||||
// Glib already runs CLI arguments through g_locale_to_utf8
|
if (!utf8_input_)
|
||||||
if (g_get_charset(nullptr)) {
|
str.reset(g_locale_to_utf8(loc_str, -1, &bytes_read, &bytes_written, get_addr(err)));
|
||||||
// Current locale is UTF-8
|
else
|
||||||
str.reset(g_strdup(loc_str));
|
str.reset(g_strdup(loc_str));
|
||||||
} else {
|
|
||||||
if (!utf8_input_) {
|
|
||||||
str.reset(g_strdup(loc_str));
|
|
||||||
} else {
|
|
||||||
str.reset(g_locale_from_utf8(loc_str, -1, &bytes_read, &bytes_written, get_addr(err)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nullptr == get_impl(str)) {
|
if (nullptr == get_impl(str)) {
|
||||||
fprintf(stderr, _("Can not convert %s to utf8.\n"), loc_str);
|
fprintf(stderr, _("Can not convert %s to utf8.\n"), loc_str);
|
||||||
|
|||||||
16
src/sdcv.cpp
16
src/sdcv.cpp
@@ -83,7 +83,6 @@ try {
|
|||||||
glib::CharStr opt_data_dir;
|
glib::CharStr opt_data_dir;
|
||||||
gboolean only_data_dir = FALSE;
|
gboolean only_data_dir = FALSE;
|
||||||
gboolean colorize = FALSE;
|
gboolean colorize = FALSE;
|
||||||
glib::StrArr word_list;
|
|
||||||
|
|
||||||
const GOptionEntry entries[] = {
|
const GOptionEntry entries[] = {
|
||||||
{ "version", 'v', 0, G_OPTION_ARG_NONE, &show_version,
|
{ "version", 'v', 0, G_OPTION_ARG_NONE, &show_version,
|
||||||
@@ -110,13 +109,11 @@ try {
|
|||||||
_("only use the dictionaries in data-dir, do not search in user and system directories"), nullptr },
|
_("only use the dictionaries in data-dir, do not search in user and system directories"), nullptr },
|
||||||
{ "color", 'c', 0, G_OPTION_ARG_NONE, &colorize,
|
{ "color", 'c', 0, G_OPTION_ARG_NONE, &colorize,
|
||||||
_("colorize the output"), nullptr },
|
_("colorize the output"), nullptr },
|
||||||
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, get_addr(word_list),
|
|
||||||
_("search terms"), _(" words") },
|
|
||||||
{},
|
{},
|
||||||
};
|
};
|
||||||
|
|
||||||
glib::Error error;
|
glib::Error error;
|
||||||
GOptionContext *context = g_option_context_new(nullptr);
|
GOptionContext *context = g_option_context_new(_(" words"));
|
||||||
g_option_context_set_help_enabled(context, TRUE);
|
g_option_context_set_help_enabled(context, TRUE);
|
||||||
g_option_context_add_main_entries(context, entries, nullptr);
|
g_option_context_add_main_entries(context, entries, nullptr);
|
||||||
const gboolean parse_res = g_option_context_parse(context, &argc, &argv, get_addr(error));
|
const gboolean parse_res = g_option_context_parse(context, &argc, &argv, get_addr(error));
|
||||||
@@ -213,11 +210,14 @@ try {
|
|||||||
lib.load(dicts_dir_list, order_list, disable_list);
|
lib.load(dicts_dir_list, order_list, disable_list);
|
||||||
|
|
||||||
std::unique_ptr<IReadLine> io(create_readline_object());
|
std::unique_ptr<IReadLine> io(create_readline_object());
|
||||||
if (word_list != nullptr) {
|
if (argc > 1) {
|
||||||
search_result rval = SEARCH_SUCCESS;
|
search_result rval = SEARCH_SUCCESS;
|
||||||
gchar **p = get_impl(word_list);
|
for (int i = 1; i < argc; i++) {
|
||||||
while (*p) {
|
// Skip the GNU "stop option parsing" token ("--"), because glib won't do it for us without G_OPTION_REMAINING
|
||||||
if ((rval = lib.process_phrase(*p++, *io, non_interactive)) != SEARCH_SUCCESS) {
|
if (strcmp(argv[i], "--") == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ((rval = lib.process_phrase(argv[i], *io, non_interactive)) != SEARCH_SUCCESS) {
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user