diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-23 01:44:22 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-23 01:44:22 +0200 |
| commit | 641caaec3d495f3a92f652f12ab70b02ba9312ac (patch) | |
| tree | 2a1aeb78c4344d1cd4423cdd96b581a797392b58 /libbb | |
| parent | a96074874857b31361d02ead97a1152164568918 (diff) | |
| download | busybox-w32-641caaec3d495f3a92f652f12ab70b02ba9312ac.tar.gz busybox-w32-641caaec3d495f3a92f652f12ab70b02ba9312ac.tar.bz2 busybox-w32-641caaec3d495f3a92f652f12ab70b02ba9312ac.zip | |
libbb: factor out code which queries screen width
function old new delta
get_terminal_width - 17 +17
stty_main 1196 1197 +1
pstree_main 321 319 -2
ls_main 735 731 -4
watch_main 232 225 -7
bb_progress_update 714 706 -8
ps_main 555 543 -12
run_applet_and_exit 708 695 -13
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/6 up/down: 18/-46) Total: -28 byte
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/appletlib.c | 2 | ||||
| -rw-r--r-- | libbb/progress.c | 9 | ||||
| -rw-r--r-- | libbb/xfuncs.c | 6 |
3 files changed, 8 insertions, 9 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 0f83eda4b..58bb2f1a0 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
| @@ -623,7 +623,7 @@ static int busybox_main(char **argv) | |||
| 623 | output_width = 80; | 623 | output_width = 80; |
| 624 | if (ENABLE_FEATURE_AUTOWIDTH) { | 624 | if (ENABLE_FEATURE_AUTOWIDTH) { |
| 625 | /* Obtain the terminal width */ | 625 | /* Obtain the terminal width */ |
| 626 | get_terminal_width_height(0, &output_width, NULL); | 626 | output_width = get_terminal_width(2); |
| 627 | } | 627 | } |
| 628 | 628 | ||
| 629 | dup2(1, 2); | 629 | dup2(1, 2); |
diff --git a/libbb/progress.c b/libbb/progress.c index 372feb0c2..6154dca17 100644 --- a/libbb/progress.c +++ b/libbb/progress.c | |||
| @@ -45,13 +45,6 @@ enum { | |||
| 45 | STALLTIME = 5 | 45 | STALLTIME = 5 |
| 46 | }; | 46 | }; |
| 47 | 47 | ||
| 48 | static unsigned int get_tty2_width(void) | ||
| 49 | { | ||
| 50 | unsigned width; | ||
| 51 | get_terminal_width_height(2, &width, NULL); | ||
| 52 | return width; | ||
| 53 | } | ||
| 54 | |||
| 55 | void FAST_FUNC bb_progress_init(bb_progress_t *p, const char *curfile) | 48 | void FAST_FUNC bb_progress_init(bb_progress_t *p, const char *curfile) |
| 56 | { | 49 | { |
| 57 | #if ENABLE_UNICODE_SUPPORT | 50 | #if ENABLE_UNICODE_SUPPORT |
| @@ -148,7 +141,7 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p, | |||
| 148 | unsigned ratio = 100 * beg_and_transferred / totalsize; | 141 | unsigned ratio = 100 * beg_and_transferred / totalsize; |
| 149 | fprintf(stderr, "%4u%%", ratio); | 142 | fprintf(stderr, "%4u%%", ratio); |
| 150 | 143 | ||
| 151 | barlength = get_tty2_width() - 49; | 144 | barlength = get_terminal_width(2) - 49; |
| 152 | if (barlength > 0) { | 145 | if (barlength > 0) { |
| 153 | /* god bless gcc for variable arrays :) */ | 146 | /* god bless gcc for variable arrays :) */ |
| 154 | char buf[barlength + 1]; | 147 | char buf[barlength + 1]; |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 0c9969640..206edb4a0 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
| @@ -270,6 +270,12 @@ int FAST_FUNC get_terminal_width_height(int fd, unsigned *width, unsigned *heigh | |||
| 270 | *width = wh_helper(win.ws_col, 80, "COLUMNS", &err); | 270 | *width = wh_helper(win.ws_col, 80, "COLUMNS", &err); |
| 271 | return err; | 271 | return err; |
| 272 | } | 272 | } |
| 273 | int FAST_FUNC get_terminal_width(int fd) | ||
| 274 | { | ||
| 275 | unsigned width; | ||
| 276 | get_terminal_width_height(fd, &width, NULL); | ||
| 277 | return width; | ||
| 278 | } | ||
| 273 | 279 | ||
| 274 | int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp) | 280 | int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp) |
| 275 | { | 281 | { |
