Add a "can_display_utf8" flag based on the current locale, for future use.

This commit is contained in:
Andrew Wood
2024-12-09 23:23:07 +00:00
parent 06eca8cefa
commit 51a5de71c1
14 changed files with 63 additions and 41 deletions
+13 -1
View File
@@ -19,7 +19,9 @@
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_LANGINFO_H
#include <langinfo.h>
#endif
int pv_remote_set(opts_t, pvstate_t);
void pv_remote_init(void);
@@ -279,6 +281,7 @@ int main(int argc, char **argv)
/*@only@ */ pvstate_t state = NULL;
int retcode = 0;
bool can_have_eta = true;
bool can_display_utf8 = false;
#if ! HAVE_SETPROCTITLE
initproctitle(argc, argv);
@@ -289,6 +292,12 @@ int main(int argc, char **argv)
(void) setlocale(LC_ALL, "");
(void) bindtextdomain(PACKAGE, LOCALEDIR);
(void) textdomain(PACKAGE);
#ifdef HAVE_LANGINFO_H
/*@-mustfreefresh@ *//* splint thinks nl_langinfo() leaks memory */
if (0 == strcmp(nl_langinfo(CODESET), "UTF-8"))
can_display_utf8 = true;
/*@+mustfreefresh@ */
#endif
#endif
/* Parse the command line arguments. */
@@ -503,6 +512,9 @@ int main(int argc, char **argv)
can_have_eta ? opts->fineta : false, opts->rate, opts->average_rate,
opts->bytes, opts->bufpercent, opts->lastwritten, opts->name);
debug("%s: %s", "can_display_utf8", can_display_utf8 ? "true" : "false");
pv_state_set_can_display_utf8(state, can_display_utf8);
/* Initialise the signal handling. */
pv_sig_init(state);