Fixed: UTF8 set LANG and LC_ALL to empty before UTF8 search and fixed empty error msg on exit before signal handler init

This commit is contained in:
aristocratos 2021-09-29 08:16:49 +02:00
parent ab013b989b
commit c70667e9e5

View file

@ -712,20 +712,20 @@ int main(int argc, char **argv) {
} }
//? Try to find and set a UTF-8 locale //? Try to find and set a UTF-8 locale
if (bool found = false; std::setlocale(LC_ALL, NULL) == NULL or not str_to_upper(s_replace((string)std::setlocale(LC_ALL, NULL), "-", "")).ends_with("UTF8")) { if (bool found = false; std::setlocale(LC_ALL, "") == NULL or not str_to_upper(s_replace((string)std::setlocale(LC_ALL, ""), "-", "")).ends_with("UTF8")) {
if (std::getenv("LANG") != NULL and str_to_upper(s_replace((string)std::getenv("LANG"), "-", "")).ends_with("UTF8") and std::setlocale(LC_ALL, std::getenv("LANG")) != NULL) { if (std::getenv("LANG") != NULL and str_to_upper(s_replace((string)std::getenv("LANG"), "-", "")).ends_with("UTF8") and std::setlocale(LC_ALL, std::getenv("LANG")) != NULL) {
found = true; found = true;
} }
else { else {
if (setenv("LANG", "", 1) == 0) { if (setenv("LC_ALL", "", 1) == 0 and setenv("LANG", "", 1) == 0) {
try { try {
if (const auto loc = std::locale("").name(); not loc.empty() and loc != "*") { if (const auto loc = std::locale("").name(); not loc.empty() and loc != "*") {
for (auto& l : ssplit(loc, ';')) { for (auto& l : ssplit(loc, ';')) {
if (str_to_upper(s_replace(l, "-", "")).ends_with("UTF8")) { if (str_to_upper(s_replace(l, "-", "")).ends_with("UTF8")) {
if (std::setlocale(LC_ALL, l.substr(l.find('=') + 1).c_str()) != NULL) { if (std::setlocale(LC_ALL, l.substr(l.find('=') + 1).c_str()) != NULL) {
found = true; found = true;
break;
} }
break;
} }
} }
} }
@ -738,16 +738,16 @@ int main(int argc, char **argv) {
Logger::warning("No UTF-8 locale detected! Forcing start with --utf-force argument."); Logger::warning("No UTF-8 locale detected! Forcing start with --utf-force argument.");
else if (not found) { else if (not found) {
Global::exit_error_msg = "No UTF-8 locale detected!\nUse --utf-force argument to force start if you're sure your terminal can handle it."; Global::exit_error_msg = "No UTF-8 locale detected!\nUse --utf-force argument to force start if you're sure your terminal can handle it.";
exit(1); clean_quit(1);
} }
else else
Logger::debug("Setting LC_ALL=" + (string)std::setlocale(LC_ALL, NULL)); Logger::debug("Setting LC_ALL=" + (string)std::setlocale(LC_ALL, ""));
} }
//? Initialize terminal and set options //? Initialize terminal and set options
if (not Term::init()) { if (not Term::init()) {
Global::exit_error_msg = "No tty detected!\nbtop++ needs an interactive shell to run."; Global::exit_error_msg = "No tty detected!\nbtop++ needs an interactive shell to run.";
exit(1); clean_quit(1);
} }
if (Term::current_tty != "unknown") Logger::info("Running on " + Term::current_tty); if (Term::current_tty != "unknown") Logger::info("Running on " + Term::current_tty);
@ -768,7 +768,7 @@ int main(int argc, char **argv) {
Term::refresh(); Term::refresh();
if (++t_count == 100) { if (++t_count == 100) {
Global::exit_error_msg = "Failed to get size of terminal!"; Global::exit_error_msg = "Failed to get size of terminal!";
exit(1); clean_quit(1);
} }
} }
} }
@ -779,7 +779,7 @@ int main(int argc, char **argv) {
} }
catch (const std::exception& e) { catch (const std::exception& e) {
Global::exit_error_msg = "Exception in Shared::init() -> " + (string)e.what(); Global::exit_error_msg = "Exception in Shared::init() -> " + (string)e.what();
exit(1); clean_quit(1);
} }
//? Update list of available themes and generate the selected theme //? Update list of available themes and generate the selected theme