Browse Source

Load locales so that we get proper digit separators when LANG is set

default_compile_flags
vector-of-bool 3 years ago
parent
commit
a8913f3ca7
2 changed files with 17 additions and 2 deletions
  1. +17
    -1
      src/dds.main.cpp
  2. +0
    -1
      src/dds/cli/dispatch_main.cpp

+ 17
- 1
src/dds.main.cpp View File



#include <filesystem> #include <filesystem>
#include <iostream> #include <iostream>
#include <locale>

static void load_locale() {
auto lang = std::getenv("LANG");
if (!lang) {
return;
}
try {
std::locale::global(std::locale(lang));
} catch (const std::runtime_error& e) {
// No locale with the given name
return;
}
}


int main_fn(std::string_view program_name, const std::vector<std::string>& argv) { int main_fn(std::string_view program_name, const std::vector<std::string>& argv) {
dds::log::init_logger(); dds::log::init_logger();
auto log_subscr = neo::subscribe(&dds::log::ev_log::print); auto log_subscr = neo::subscribe(&dds::log::ev_log::print);
load_locale();
std::setlocale(LC_CTYPE, ".utf8");


dds::install_signal_handlers(); dds::install_signal_handlers();


// Non-null result from argument parsing, return that value immediately. // Non-null result from argument parsing, return that value immediately.
return *result; return *result;
} }
dds::log::current_log_level = opts.log_level;
return dds::cli::dispatch_main(opts); return dds::cli::dispatch_main(opts);
} }




int wmain(int argc, wchar_t** argv) { int wmain(int argc, wchar_t** argv) {
std::vector<std::string> u8_argv; std::vector<std::string> u8_argv;
::setlocale(LC_ALL, ".utf8");
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
u8_argv.emplace_back(wstr_to_u8str(argv[i])); u8_argv.emplace_back(wstr_to_u8str(argv[i]));
} }

+ 0
- 1
src/dds/cli/dispatch_main.cpp View File

} // namespace cmd } // namespace cmd


int dispatch_main(const options& opts) noexcept { int dispatch_main(const options& opts) noexcept {
dds::log::current_log_level = opts.log_level;
return dds::handle_cli_errors([&] { return dds::handle_cli_errors([&] {
DDS_E_SCOPE(opts.subcommand); DDS_E_SCOPE(opts.subcommand);
switch (opts.subcommand) { switch (opts.subcommand) {

Loading…
Cancel
Save