summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-05-07 17:30:18 -0400
committerSven Eden <yamakuzure@gmx.net>2017-06-16 10:12:58 +0200
commitbcd8aec4ff66a0f27b46d47df49e184da57a68b0 (patch)
treed551e99a6b6aba7074cf452381599f127b3a34d4 /src
parent5489ba3e334d21609a042d5dc1615323f2903181 (diff)
tree-wide: rename draw_special_char to special_glyph
That function doesn't draw anything on it's own, just returns a string, which sometimes is more than one character. Also remove "DRAW_" prefix from character names, TREE_* and ARROW and BLACK_CIRCLE are unambigous on their own, don't draw anything, and are always used as an argument to special_glyph(). Rename "DASH" to "MDASH", as there's more than one type of dash.
Diffstat (limited to 'src')
-rw-r--r--src/basic/locale-util.c49
-rw-r--r--src/basic/locale-util.h24
-rw-r--r--src/login/sysfs-show.c8
-rw-r--r--src/shared/bus-unit-util.c8
4 files changed, 45 insertions, 44 deletions
diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c
index eaad25e65..8134f61a7 100644
--- a/src/basic/locale-util.c
+++ b/src/basic/locale-util.c
@@ -271,34 +271,35 @@ out:
}
-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", /* – */
+const char *special_glyph(SpecialGlyph code) {
+
+ static const char *draw_table[2][_SPECIAL_GLYPH_MAX] = {
+ /* ASCII fallback */
+ [false] = {
+ [TREE_VERTICAL] = "| ",
+ [TREE_BRANCH] = "|-",
+ [TREE_RIGHT] = "`-",
+ [TREE_SPACE] = " ",
+ [TRIANGULAR_BULLET] = ">",
+ [BLACK_CIRCLE] = "*",
+ [ARROW] = "->",
+ [MDASH] = "-",
},
- /* ASCII fallback */ {
- [DRAW_TREE_VERTICAL] = "| ",
- [DRAW_TREE_BRANCH] = "|-",
- [DRAW_TREE_RIGHT] = "`-",
- [DRAW_TREE_SPACE] = " ",
- [DRAW_TRIANGULAR_BULLET] = ">",
- [DRAW_BLACK_CIRCLE] = "*",
- [DRAW_ARROW] = "->",
- [DRAW_DASH] = "-",
- }
+ /* UTF-8 */
+ [ true ] = {
+ [TREE_VERTICAL] = "\342\224\202 ", /* │ */
+ [TREE_BRANCH] = "\342\224\234\342\224\200", /* ├─ */
+ [TREE_RIGHT] = "\342\224\224\342\224\200", /* └─ */
+ [TREE_SPACE] = " ", /* */
+ [TRIANGULAR_BULLET] = "\342\200\243", /* ‣ */
+ [BLACK_CIRCLE] = "\342\227\217", /* ● */
+ [ARROW] = "\342\206\222", /* → */
+ [MDASH] = "\342\200\223", /* – */
+ },
};
- return draw_table[!is_locale_utf8()][ch];
+ return draw_table[is_locale_utf8()][code];
}
static const char * const locale_variable_table[_VARIABLE_LC_MAX] = {
diff --git a/src/basic/locale-util.h b/src/basic/locale-util.h
index b0f967928..353b7845f 100644
--- a/src/basic/locale-util.h
+++ b/src/basic/locale-util.h
@@ -55,19 +55,19 @@ 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;
+typedef enum {
+ TREE_VERTICAL,
+ TREE_BRANCH,
+ TREE_RIGHT,
+ TREE_SPACE,
+ TRIANGULAR_BULLET,
+ BLACK_CIRCLE,
+ ARROW,
+ MDASH,
+ _SPECIAL_GLYPH_MAX
+} SpecialGlyph;
-const char *draw_special_char(DrawSpecialChar ch);
+const char *special_glyph(SpecialGlyph code);
const char* locale_variable_to_string(LocaleVariable i) _const_;
LocaleVariable locale_variable_from_string(const char *s) _pure_;
diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c
index bd603e297..29785e2f1 100644
--- a/src/login/sysfs-show.c
+++ b/src/login/sysfs-show.c
@@ -110,7 +110,7 @@ static int show_sysfs_one(
if (!k)
return -ENOMEM;
- printf("%s%s%s\n", prefix, draw_special_char(lookahead ? DRAW_TREE_BRANCH : DRAW_TREE_RIGHT), k);
+ printf("%s%s%s\n", prefix, special_glyph(lookahead ? TREE_BRANCH : TREE_RIGHT), k);
if (asprintf(&l,
"%s%s:%s%s%s%s",
@@ -124,13 +124,13 @@ static int show_sysfs_one(
if (!k)
return -ENOMEM;
- printf("%s%s%s\n", prefix, lookahead ? draw_special_char(DRAW_TREE_VERTICAL) : " ", k);
+ printf("%s%s%s\n", prefix, lookahead ? special_glyph(TREE_VERTICAL) : " ", k);
*item = next;
if (*item) {
_cleanup_free_ char *p = NULL;
- p = strappend(prefix, lookahead ? draw_special_char(DRAW_TREE_VERTICAL) : " ");
+ p = strappend(prefix, lookahead ? special_glyph(TREE_VERTICAL) : " ");
if (!p)
return -ENOMEM;
@@ -183,7 +183,7 @@ int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) {
if (first)
show_sysfs_one(udev, seat, &first, "/", prefix, n_columns);
else
- printf("%s%s%s\n", prefix, draw_special_char(DRAW_TREE_RIGHT), "(none)");
+ printf("%s%s%s\n", prefix, special_glyph(TREE_RIGHT), "(none)");
return r;
}
diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c
index a4c228280..ff5dceaed 100644
--- a/src/shared/bus-unit-util.c
+++ b/src/shared/bus-unit-util.c
@@ -1088,7 +1088,7 @@ static int dump_processes(
}
more = i+1 < n || cg->children;
- special = draw_special_char(more ? DRAW_TREE_BRANCH : DRAW_TREE_RIGHT);
+ special = special_glyph(more ? TREE_BRANCH : TREE_RIGHT);
fprintf(stdout, "%s%s%*"PID_PRI" %s\n",
prefix,
@@ -1124,14 +1124,14 @@ static int dump_processes(
name++;
more = i+1 < n;
- special = draw_special_char(more ? DRAW_TREE_BRANCH : DRAW_TREE_RIGHT);
+ special = special_glyph(more ? TREE_BRANCH : TREE_RIGHT);
fputs(prefix, stdout);
fputs(special, stdout);
fputs(name, stdout);
fputc('\n', stdout);
- special = draw_special_char(more ? DRAW_TREE_VERTICAL : DRAW_TREE_SPACE);
+ special = special_glyph(more ? TREE_VERTICAL : TREE_SPACE);
pp = strappend(prefix, special);
if (!pp)
@@ -1215,7 +1215,7 @@ static int dump_extra_processes(
fprintf(stdout, "%s%s %*" PID_PRI " %s\n",
prefix,
- draw_special_char(DRAW_TRIANGULAR_BULLET),
+ special_glyph(TRIANGULAR_BULLET),
width, pids[k],
name);
}