]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util-lib: move more locale-related calls to locale-util.[ch]
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Oct 2015 22:01:30 +0000 (23:01 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 12:25:56 +0000 (13:25 +0100)
19 files changed:
src/analyze/analyze.c
src/basic/locale-util.c
src/basic/locale-util.h
src/basic/util.c
src/basic/util.h
src/boot/bootctl.c
src/bus-proxyd/bus-xml-policy.c
src/core/dbus-unit.c
src/delta/delta.c
src/journal/journalctl.c
src/libsystemd/sd-bus/bus-dump.c
src/libsystemd/sd-bus/busctl.c
src/login/sysfs-show.c
src/network/networkctl.c
src/resolve/resolved-dns-transaction.c
src/shared/cgroup-show.c
src/shared/pager.c
src/systemctl/systemctl.c
src/vconsole/vconsole-setup.c

index 6ba16d8b65ef45f2531e1dd4469bad18203fc167..a165152cb2c92d13f34cbd94c52e25a2a816e31a 100644 (file)
@@ -31,6 +31,7 @@
 #include "bus-error.h"
 #include "bus-util.h"
 #include "hashmap.h"
+#include "locale-util.h"
 #include "log.h"
 #include "pager.h"
 #include "parse-util.h"
index 9db906316b7d2596f5671ddabce2ded7edceac40..b87fd7670bf410a58aa1bff5a2805821e37e1026 100644 (file)
@@ -19,6 +19,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <langinfo.h>
+#include <locale.h>
 #include <sys/mman.h>
 
 #include "dirent-util.h"
@@ -208,6 +210,88 @@ bool locale_is_valid(const char *name) {
         return true;
 }
 
+void init_gettext(void) {
+        setlocale(LC_ALL, "");
+        textdomain(GETTEXT_PACKAGE);
+}
+
+bool is_locale_utf8(void) {
+        const char *set;
+        static int cached_answer = -1;
+
+        /* Note that we default to 'true' here, since today UTF8 is
+         * pretty much supported everywhere. */
+
+        if (cached_answer >= 0)
+                goto out;
+
+        if (!setlocale(LC_ALL, "")) {
+                cached_answer = true;
+                goto out;
+        }
+
+        set = nl_langinfo(CODESET);
+        if (!set) {
+                cached_answer = true;
+                goto out;
+        }
+
+        if (streq(set, "UTF-8")) {
+                cached_answer = true;
+                goto out;
+        }
+
+        /* For LC_CTYPE=="C" return true, because CTYPE is effectly
+         * unset and everything can do to UTF-8 nowadays. */
+        set = setlocale(LC_CTYPE, NULL);
+        if (!set) {
+                cached_answer = true;
+                goto out;
+        }
+
+        /* Check result, but ignore the result if C was set
+         * explicitly. */
+        cached_answer =
+                STR_IN_SET(set, "C", "POSIX") &&
+                !getenv("LC_ALL") &&
+                !getenv("LC_CTYPE") &&
+                !getenv("LANG");
+
+out:
+        return (bool) cached_answer;
+}
+
+
+const char *draw_special_char(DrawSpecialChar ch) {
+
+        static const char *draw_table[2][_DRAW_SPECIAL_CHAR_MAX] = {
+
+                /* UTF-8 */ {
+                        [DRAW_TREE_VERTICAL]      = "\342\224\202 ",            /* │  */
+                        [DRAW_TREE_BRANCH]        = "\342\224\234\342\224\200", /* ├─ */
+                        [DRAW_TREE_RIGHT]         = "\342\224\224\342\224\200", /* └─ */
+                        [DRAW_TREE_SPACE]         = "  ",                       /*    */
+                        [DRAW_TRIANGULAR_BULLET]  = "\342\200\243",             /* ‣ */
+                        [DRAW_BLACK_CIRCLE]       = "\342\227\217",             /* ● */
+                        [DRAW_ARROW]              = "\342\206\222",             /* → */
+                        [DRAW_DASH]               = "\342\200\223",             /* – */
+                },
+
+                /* ASCII fallback */ {
+                        [DRAW_TREE_VERTICAL]      = "| ",
+                        [DRAW_TREE_BRANCH]        = "|-",
+                        [DRAW_TREE_RIGHT]         = "`-",
+                        [DRAW_TREE_SPACE]         = "  ",
+                        [DRAW_TRIANGULAR_BULLET]  = ">",
+                        [DRAW_BLACK_CIRCLE]       = "*",
+                        [DRAW_ARROW]              = "->",
+                        [DRAW_DASH]               = "-",
+                }
+        };
+
+        return draw_table[!is_locale_utf8()][ch];
+}
+
 static const char * const locale_variable_table[_VARIABLE_LC_MAX] = {
         [VARIABLE_LANG] = "LANG",
         [VARIABLE_LANGUAGE] = "LANGUAGE",
index e48aa3d9af04c1c13cba5e849f45bc7afd3d6fad..c71d145139d06fc75866cd7179e3c983bb38b100 100644 (file)
@@ -21,6 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <libintl.h>
 #include <stdbool.h>
 
 #include "macro.h"
@@ -50,5 +51,25 @@ typedef enum LocaleVariable {
 int get_locales(char ***l);
 bool locale_is_valid(const char *name);
 
+#define _(String) gettext(String)
+#define N_(String) String
+void init_gettext(void);
+
+bool is_locale_utf8(void);
+
+typedef enum DrawSpecialChar {
+        DRAW_TREE_VERTICAL,
+        DRAW_TREE_BRANCH,
+        DRAW_TREE_RIGHT,
+        DRAW_TREE_SPACE,
+        DRAW_TRIANGULAR_BULLET,
+        DRAW_BLACK_CIRCLE,
+        DRAW_ARROW,
+        DRAW_DASH,
+        _DRAW_SPECIAL_CHAR_MAX
+} DrawSpecialChar;
+
+const char *draw_special_char(DrawSpecialChar ch);
+
 const char* locale_variable_to_string(LocaleVariable i) _const_;
 LocaleVariable locale_variable_from_string(const char *s) _pure_;
index 0878adbfac67a182702d494da7c517e6d37be8ea..b079e8af169ae8162490ff9fc3adf11132468a32 100644 (file)
@@ -810,83 +810,6 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
         return NULL;
 }
 
-void init_gettext(void) {
-        setlocale(LC_ALL, "");
-        textdomain(GETTEXT_PACKAGE);
-}
-
-bool is_locale_utf8(void) {
-        const char *set;
-        static int cached_answer = -1;
-
-        if (cached_answer >= 0)
-                goto out;
-
-        if (!setlocale(LC_ALL, "")) {
-                cached_answer = true;
-                goto out;
-        }
-
-        set = nl_langinfo(CODESET);
-        if (!set) {
-                cached_answer = true;
-                goto out;
-        }
-
-        if (streq(set, "UTF-8")) {
-                cached_answer = true;
-                goto out;
-        }
-
-        /* For LC_CTYPE=="C" return true, because CTYPE is effectly
-         * unset and everything can do to UTF-8 nowadays. */
-        set = setlocale(LC_CTYPE, NULL);
-        if (!set) {
-                cached_answer = true;
-                goto out;
-        }
-
-        /* Check result, but ignore the result if C was set
-         * explicitly. */
-        cached_answer =
-                STR_IN_SET(set, "C", "POSIX") &&
-                !getenv("LC_ALL") &&
-                !getenv("LC_CTYPE") &&
-                !getenv("LANG");
-
-out:
-        return (bool) cached_answer;
-}
-
-const char *draw_special_char(DrawSpecialChar ch) {
-        static const char *draw_table[2][_DRAW_SPECIAL_CHAR_MAX] = {
-
-                /* UTF-8 */ {
-                        [DRAW_TREE_VERTICAL]      = "\342\224\202 ",            /* │  */
-                        [DRAW_TREE_BRANCH]        = "\342\224\234\342\224\200", /* ├─ */
-                        [DRAW_TREE_RIGHT]         = "\342\224\224\342\224\200", /* └─ */
-                        [DRAW_TREE_SPACE]         = "  ",                       /*    */
-                        [DRAW_TRIANGULAR_BULLET]  = "\342\200\243",             /* ‣ */
-                        [DRAW_BLACK_CIRCLE]       = "\342\227\217",             /* ● */
-                        [DRAW_ARROW]              = "\342\206\222",             /* → */
-                        [DRAW_DASH]               = "\342\200\223",             /* – */
-                },
-
-                /* ASCII fallback */ {
-                        [DRAW_TREE_VERTICAL]      = "| ",
-                        [DRAW_TREE_BRANCH]        = "|-",
-                        [DRAW_TREE_RIGHT]         = "`-",
-                        [DRAW_TREE_SPACE]         = "  ",
-                        [DRAW_TRIANGULAR_BULLET]  = ">",
-                        [DRAW_BLACK_CIRCLE]       = "*",
-                        [DRAW_ARROW]              = "->",
-                        [DRAW_DASH]               = "-",
-                }
-        };
-
-        return draw_table[!is_locale_utf8()][ch];
-}
-
 int on_ac_power(void) {
         bool found_offline = false, found_online = false;
         _cleanup_closedir_ DIR *d = NULL;
index d18b151d887854c075dda1ae0b8e27b0bb3f36cd..680317909d50ebcf426e487f194230e490874cc6 100644 (file)
@@ -192,25 +192,6 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
                  int (*compar) (const void *, const void *, void *),
                  void *arg);
 
-#define _(String) gettext (String)
-#define N_(String) String
-void init_gettext(void);
-bool is_locale_utf8(void);
-
-typedef enum DrawSpecialChar {
-        DRAW_TREE_VERTICAL,
-        DRAW_TREE_BRANCH,
-        DRAW_TREE_RIGHT,
-        DRAW_TREE_SPACE,
-        DRAW_TRIANGULAR_BULLET,
-        DRAW_BLACK_CIRCLE,
-        DRAW_ARROW,
-        DRAW_DASH,
-        _DRAW_SPECIAL_CHAR_MAX
-} DrawSpecialChar;
-
-const char *draw_special_char(DrawSpecialChar ch);
-
 int on_ac_power(void);
 
 static inline void *mempset(void *s, int c, size_t n) {
index 7e06abd3bf2b85abb769bbf7a1cd824281592c86..332bb335455cb442bea1fad97b88859461a338eb 100644 (file)
@@ -41,6 +41,7 @@
 #include "efivars.h"
 #include "fd-util.h"
 #include "fileio.h"
+#include "locale-util.h"
 #include "rm-rf.h"
 #include "string-util.h"
 #include "util.h"
index cf922ef02f37df1eaa569ef85e01e5f842db15a2..1b9fdedca3747c91bea728b49e8a29936398c426 100644 (file)
@@ -26,6 +26,7 @@
 #include "conf-files.h"
 #include "fileio.h"
 #include "formats-util.h"
+#include "locale-util.h"
 #include "set.h"
 #include "string-table.h"
 #include "string-util.h"
index 7220fe688f42e718d37187c9dcf8eb8d83969b15..62086a7fde39902a29f87b6ec57bff913fb2cefd 100644 (file)
 
 #include "bus-common-errors.h"
 #include "cgroup-util.h"
+#include "dbus-unit.h"
 #include "dbus.h"
+#include "locale-util.h"
 #include "log.h"
 #include "selinux-access.h"
 #include "special.h"
 #include "string-util.h"
 #include "strv.h"
-#include "dbus-unit.h"
 
 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_load_state, unit_load_state, UnitLoadState);
 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_job_mode, job_mode, JobMode);
index e5e0be476f397b3210cf863152917bb1a4e4ed4a..4ade23ffabc33f9b3ee3c9c3fbb4b740c5c50c23 100644 (file)
@@ -30,6 +30,7 @@
 #include "fd-util.h"
 #include "fs-util.h"
 #include "hashmap.h"
+#include "locale-util.h"
 #include "log.h"
 #include "pager.h"
 #include "parse-util.h"
index 61d502f0a1465ebdbca8ad86ac8be1bc527a495e..8b8c50b4369e74e27f45582d9000416ea72bd22d 100644 (file)
@@ -54,6 +54,7 @@
 #include "journal-qrcode.h"
 #include "journal-vacuum.h"
 #include "journal-verify.h"
+#include "locale-util.h"
 #include "log.h"
 #include "logs-show.h"
 #include "mkdir.h"
index 9ddd059072b6aec6881227b6e9abad153c94a16d..02c9ff8f2f8d5ef55fc628889202502ae6f6f7fc 100644 (file)
@@ -27,6 +27,7 @@
 #include "capability.h"
 #include "fileio.h"
 #include "formats-util.h"
+#include "locale-util.h"
 #include "macro.h"
 #include "string-util.h"
 #include "strv.h"
index 4b121e849ab3a2940e4a60b903b82535ca16ceb2..4fa60bb18599488a3d13d08ed4356171a06da388 100644 (file)
@@ -31,6 +31,7 @@
 #include "busctl-introspect.h"
 #include "escape.h"
 #include "fd-util.h"
+#include "locale-util.h"
 #include "log.h"
 #include "pager.h"
 #include "parse-util.h"
index 32e53c0a11c1fc7d941df6baf9fd73d245de813a..0f671ac90ebcf7be63fb6e0ef0a551e4e27b8590 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "libudev.h"
 
+#include "locale-util.h"
 #include "path-util.h"
 #include "string-util.h"
 #include "sysfs-show.h"
index 6ea9563fcfd4cfe417de642ac47af8320ab50e43..d0d7669c8739f17718bb0aa7c4d240eb382cafee 100644 (file)
 #include "hwdb-util.h"
 #include "lldp.h"
 #include "local-addresses.h"
+#include "locale-util.h"
+#include "locale-util.h"
 #include "netlink-util.h"
 #include "pager.h"
 #include "parse-util.h"
 #include "socket-util.h"
-#include "string-util.h"
 #include "string-table.h"
+#include "string-util.h"
 #include "strv.h"
 #include "terminal-util.h"
 #include "util.h"
index 1e38547e23eecfcaf9557385282bfe191873507d..c60197cf8db58089e449113ba7d87c0098534b6d 100644 (file)
@@ -20,7 +20,6 @@
 ***/
 
 #include "af-list.h"
-
 #include "dns-domain.h"
 #include "fd-util.h"
 #include "random-util.h"
index 395e41930c8cc980ec6590d62637d28a64ea075c..9e70713ce8db36ef90a9f32269f657bbd3582267 100644 (file)
@@ -28,6 +28,7 @@
 #include "cgroup-util.h"
 #include "fd-util.h"
 #include "formats-util.h"
+#include "locale-util.h"
 #include "macro.h"
 #include "path-util.h"
 #include "process-util.h"
index 7029d6b2e229ad7486769572fd850befb830b4de..d149bc1722d5ded57abe0ba202c82b2ab9adb6a0 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "copy.h"
 #include "fd-util.h"
+#include "locale-util.h"
 #include "macro.h"
 #include "pager.h"
 #include "process-util.h"
index 91567600276c3c1c73350550ecdd47e179a19646..48d17cb52a61822561d10a4bb0a445b8b6d71088 100644 (file)
@@ -57,6 +57,7 @@
 #include "install.h"
 #include "io-util.h"
 #include "list.h"
+#include "locale-util.h"
 #include "log.h"
 #include "logs-show.h"
 #include "macro.h"
index 49523a0a677bde5091e4fe054dd243b79b0040b3..2da28f8be0685ff40d03492a00e915885bcc04cc 100644 (file)
@@ -34,6 +34,7 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "io-util.h"
+#include "locale-util.h"
 #include "log.h"
 #include "process-util.h"
 #include "signal-util.h"