diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2022-08-26 14:41:42 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2022-08-26 14:41:42 +0200 |
| commit | b30d345cfd995f111797f3377a3caaa263616081 (patch) | |
| tree | d0b3a19b0fad8391d7879d4609c93a7e3351808b /miscutils | |
| parent | 5eceafb1f812ec4dca7fdf6896cfcea6783a78b9 (diff) | |
| download | busybox-w32-b30d345cfd995f111797f3377a3caaa263616081.tar.gz busybox-w32-b30d345cfd995f111797f3377a3caaa263616081.tar.bz2 busybox-w32-b30d345cfd995f111797f3377a3caaa263616081.zip | |
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.c | 19 |
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 @@ | |||
| 19 | 19 | ||
| 20 | #include "libbb.h" | 20 | #include "libbb.h" |
| 21 | #include "common_bufsiz.h" | 21 | #include "common_bufsiz.h" |
| 22 | #include "unicode.h" | ||
| 22 | 23 | ||
| 23 | #define prefix_buf bb_common_bufsiz1 | 24 | #define prefix_buf bb_common_bufsiz1 |
| 24 | 25 | ||
| @@ -26,6 +27,17 @@ static void tree_print(unsigned count[2], const char* directory_name, char* pref | |||
| 26 | { | 27 | { |
| 27 | struct dirent **entries; | 28 | struct dirent **entries; |
| 28 | int index, size; | 29 | int index, size; |
| 30 | const char *bar = "| "; | ||
| 31 | const char *mid = "|-- "; | ||
| 32 | const char *end = "`-- "; | ||
| 33 | |||
| 34 | #if ENABLE_UNICODE_SUPPORT | ||
| 35 | if (unicode_status == UNICODE_ON) { | ||
| 36 | bar = "│ "; | ||
| 37 | mid = "├── "; | ||
| 38 | end = "└── "; | ||
| 39 | } | ||
| 40 | #endif | ||
| 29 | 41 | ||
| 30 | // read directory entries | 42 | // read directory entries |
| 31 | size = scandir(directory_name, &entries, NULL, alphasort); | 43 | size = scandir(directory_name, &entries, NULL, alphasort); |
| @@ -55,9 +67,9 @@ static void tree_print(unsigned count[2], const char* directory_name, char* pref | |||
| 55 | status = lstat(dirent->d_name, &statBuf); | 67 | status = lstat(dirent->d_name, &statBuf); |
| 56 | 68 | ||
| 57 | if (index == size) { | 69 | if (index == size) { |
| 58 | strcpy(prefix_pos, "└── "); | 70 | strcpy(prefix_pos, end); |
| 59 | } else { | 71 | } else { |
| 60 | strcpy(prefix_pos, "├── "); | 72 | strcpy(prefix_pos, mid); |
| 61 | } | 73 | } |
| 62 | fputs_stdout(prefix_buf); | 74 | fputs_stdout(prefix_buf); |
| 63 | 75 | ||
| @@ -75,7 +87,7 @@ static void tree_print(unsigned count[2], const char* directory_name, char* pref | |||
| 75 | if (index == size) { | 87 | if (index == size) { |
| 76 | pos = stpcpy(prefix_pos, " "); | 88 | pos = stpcpy(prefix_pos, " "); |
| 77 | } else { | 89 | } else { |
| 78 | pos = stpcpy(prefix_pos, "│ "); | 90 | pos = stpcpy(prefix_pos, bar); |
| 79 | } | 91 | } |
| 80 | tree_print(count, dirent->d_name, pos); | 92 | tree_print(count, dirent->d_name, pos); |
| 81 | count[0]++; | 93 | count[0]++; |
| @@ -103,6 +115,7 @@ int tree_main(int argc UNUSED_PARAM, char **argv) | |||
| 103 | unsigned count[2] = { 0, 0 }; | 115 | unsigned count[2] = { 0, 0 }; |
| 104 | 116 | ||
| 105 | setup_common_bufsiz(); | 117 | setup_common_bufsiz(); |
| 118 | init_unicode(); | ||
| 106 | 119 | ||
| 107 | if (!argv[1]) | 120 | if (!argv[1]) |
| 108 | *argv-- = (char*)"."; | 121 | *argv-- = (char*)"."; |
