From 323b7dc90343f11febf9e87872d3e8ffded11849 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Sat, 7 May 2016 17:30:18 -0400 Subject: 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. --- src/basic/locale-util.c | 49 +++++++++++++++++++++++++------------------------ src/basic/locale-util.h | 24 ++++++++++++------------ 2 files changed, 37 insertions(+), 36 deletions(-) (limited to 'src/basic') diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index eaad25e65b..8134f61a73 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 b0f9679286..353b7845fd 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_; -- cgit v1.2.3-54-g00ecf From dff4bf93d449b9d9086123521f83d68e98cecd09 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Mon, 9 May 2016 11:24:08 -0400 Subject: locale-util: mark special_glyph() as _const_ _const_ means that the caller can assume that the function will return the same result every time (and will not modify global memory). special_glyph() meets this: even though it depends on global memory, that part of global memory is not expected to change. This allows the calls to special_glyph() to be optimized, even if -flto is not used. --- src/basic/locale-util.c | 2 +- src/basic/locale-util.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/basic') diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index 8134f61a73..ada0a28cd8 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -273,7 +273,7 @@ out: const char *special_glyph(SpecialGlyph code) { - static const char *draw_table[2][_SPECIAL_GLYPH_MAX] = { + static const char* const draw_table[2][_SPECIAL_GLYPH_MAX] = { /* ASCII fallback */ [false] = { [TREE_VERTICAL] = "| ", diff --git a/src/basic/locale-util.h b/src/basic/locale-util.h index 353b7845fd..0630a034ab 100644 --- a/src/basic/locale-util.h +++ b/src/basic/locale-util.h @@ -67,7 +67,7 @@ typedef enum { _SPECIAL_GLYPH_MAX } SpecialGlyph; -const char *special_glyph(SpecialGlyph code); +const char *special_glyph(SpecialGlyph code) _const_; const char* locale_variable_to_string(LocaleVariable i) _const_; LocaleVariable locale_variable_from_string(const char *s) _pure_; -- cgit v1.2.3-54-g00ecf