Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.busybox.net/busybox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2022-08-26 15:41:42 +0300
committerDenys Vlasenko <vda.linux@googlemail.com>2022-08-26 15:41:42 +0300
commitb30d345cfd995f111797f3377a3caaa263616081 (patch)
treed0b3a19b0fad8391d7879d4609c93a7e3351808b /miscutils
parent5eceafb1f812ec4dca7fdf6896cfcea6783a78b9 (diff)
tree: make it unicode-aware
function old new delta tree_print 396 420 +24 .rodata 105251 105266 +15 tree_main 86 91 +5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 44/0) Total: 44 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/tree.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/miscutils/tree.c b/miscutils/tree.c
index 8b16c5383..10e5481c4 100644
--- a/miscutils/tree.c
+++ b/miscutils/tree.c
@@ -19,6 +19,7 @@
#include "libbb.h"
#include "common_bufsiz.h"
+#include "unicode.h"
#define prefix_buf bb_common_bufsiz1
@@ -26,6 +27,17 @@ static void tree_print(unsigned count[2], const char* directory_name, char* pref
{
struct dirent **entries;
int index, size;
+ const char *bar = "| ";
+ const char *mid = "|-- ";
+ const char *end = "`-- ";
+
+#if ENABLE_UNICODE_SUPPORT
+ if (unicode_status == UNICODE_ON) {
+ bar = "│   ";
+ mid = "├── ";
+ end = "└── ";
+ }
+#endif
// read directory entries
size = scandir(directory_name, &entries, NULL, alphasort);
@@ -55,9 +67,9 @@ static void tree_print(unsigned count[2], const char* directory_name, char* pref
status = lstat(dirent->d_name, &statBuf);
if (index == size) {
- strcpy(prefix_pos, "└── ");
+ strcpy(prefix_pos, end);
} else {
- strcpy(prefix_pos, "├── ");
+ strcpy(prefix_pos, mid);
}
fputs_stdout(prefix_buf);
@@ -75,7 +87,7 @@ static void tree_print(unsigned count[2], const char* directory_name, char* pref
if (index == size) {
pos = stpcpy(prefix_pos, " ");
} else {
- pos = stpcpy(prefix_pos, "│   ");
+ pos = stpcpy(prefix_pos, bar);
}
tree_print(count, dirent->d_name, pos);
count[0]++;
@@ -103,6 +115,7 @@ int tree_main(int argc UNUSED_PARAM, char **argv)
unsigned count[2] = { 0, 0 };
setup_common_bufsiz();
+ init_unicode();
if (!argv[1])
*argv-- = (char*)".";