aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-09-13 22:48:30 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-09-13 22:48:30 +0200
commit8187e0143874e1bf0412263e716cf8c782a5aa16 (patch)
tree289b592b43a7226bbd355728798930c9ead45893
parent136946c3ea6a14d391b5045b5eb71fa8ec207077 (diff)
downloadbusybox-w32-8187e0143874e1bf0412263e716cf8c782a5aa16.tar.gz
busybox-w32-8187e0143874e1bf0412263e716cf8c782a5aa16.tar.bz2
busybox-w32-8187e0143874e1bf0412263e716cf8c782a5aa16.zip
*: use ESC define instead of "\033"; use ESC[m instead of ESC[0m
text data bss dec hex filename 922535 481 6832 929848 e3038 busybox_old 922534 481 6832 929847 e3037 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--console-tools/clear.c4
-rw-r--r--console-tools/reset.c4
-rw-r--r--coreutils/ls.c10
-rw-r--r--editors/vi.c21
-rw-r--r--libbb/lineedit.c2
-rw-r--r--miscutils/fbsplash.c6
-rw-r--r--miscutils/less.c4
-rw-r--r--procps/powertop.c6
-rw-r--r--procps/top.c9
-rw-r--r--procps/watch.c4
10 files changed, 41 insertions, 29 deletions
diff --git a/console-tools/clear.c b/console-tools/clear.c
index 3cc16257b..09ef1ea68 100644
--- a/console-tools/clear.c
+++ b/console-tools/clear.c
@@ -23,9 +23,11 @@
23 23
24#include "libbb.h" 24#include "libbb.h"
25 25
26#define ESC "\033"
27
26int clear_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 28int clear_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
27int clear_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) 29int clear_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
28{ 30{
29 /* home; clear to the end of screen */ 31 /* home; clear to the end of screen */
30 return full_write1_str("\033[H""\033[J") != 6; 32 return full_write1_str(ESC"[H" ESC"[J") != 6;
31} 33}
diff --git a/console-tools/reset.c b/console-tools/reset.c
index f2b900ddb..471ef9158 100644
--- a/console-tools/reset.c
+++ b/console-tools/reset.c
@@ -46,11 +46,11 @@ int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
46 /* See 'man 4 console_codes' for details: 46 /* See 'man 4 console_codes' for details:
47 * "ESC c" -- Reset 47 * "ESC c" -- Reset
48 * "ESC ( B" -- Select G0 Character Set (B = US) 48 * "ESC ( B" -- Select G0 Character Set (B = US)
49 * "ESC [ 0 m" -- Reset all display attributes 49 * "ESC [ m" -- Reset all display attributes
50 * "ESC [ J" -- Erase to the end of screen 50 * "ESC [ J" -- Erase to the end of screen
51 * "ESC [ ? 25 h" -- Make cursor visible 51 * "ESC [ ? 25 h" -- Make cursor visible
52 */ 52 */
53 printf(ESC"c" ESC"(B" ESC"[0m" ESC"[J" ESC"[?25h"); 53 printf(ESC"c" ESC"(B" ESC"[m" ESC"[J" ESC"[?25h");
54 /* http://bugs.busybox.net/view.php?id=1414: 54 /* http://bugs.busybox.net/view.php?id=1414:
55 * people want it to reset echo etc: */ 55 * people want it to reset echo etc: */
56#if ENABLE_STTY 56#if ENABLE_STTY
diff --git a/coreutils/ls.c b/coreutils/ls.c
index af5e6cb51..a4e324b00 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -347,6 +347,8 @@ struct globals {
347 IF_FEATURE_LS_TIMESTAMPS(time(&G.current_time_t);) \ 347 IF_FEATURE_LS_TIMESTAMPS(time(&G.current_time_t);) \
348} while (0) 348} while (0)
349 349
350#define ESC "\033"
351
350 352
351/*** Output code ***/ 353/*** Output code ***/
352 354
@@ -586,12 +588,12 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
586 if (!mode) 588 if (!mode)
587 if (lstat(dn->fullname, &statbuf) == 0) 589 if (lstat(dn->fullname, &statbuf) == 0)
588 mode = statbuf.st_mode; 590 mode = statbuf.st_mode;
589 printf("\033[%u;%um", bold(mode), fgcolor(mode)); 591 printf(ESC"[%u;%um", bold(mode), fgcolor(mode));
590 } 592 }
591#endif 593#endif
592 column += print_name(dn->name); 594 column += print_name(dn->name);
593 if (G_show_color) { 595 if (G_show_color) {
594 printf("\033[0m"); 596 printf(ESC"[m");
595 } 597 }
596 598
597 if (lpath) { 599 if (lpath) {
@@ -609,7 +611,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
609# endif 611# endif
610# if ENABLE_FEATURE_LS_COLOR 612# if ENABLE_FEATURE_LS_COLOR
611 if (G_show_color) { 613 if (G_show_color) {
612 printf("\033[%u;%um", bold(mode), fgcolor(mode)); 614 printf(ESC"[%u;%um", bold(mode), fgcolor(mode));
613 } 615 }
614# endif 616# endif
615 } 617 }
@@ -617,7 +619,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
617 column += print_name(lpath) + 4; 619 column += print_name(lpath) + 4;
618 free(lpath); 620 free(lpath);
619 if (G_show_color) { 621 if (G_show_color) {
620 printf("\033[0m"); 622 printf(ESC"[m");
621 } 623 }
622 } 624 }
623#if ENABLE_FEATURE_LS_FILETYPES 625#if ENABLE_FEATURE_LS_FILETYPES
diff --git a/editors/vi.c b/editors/vi.c
index 116022c93..c010f7999 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -224,24 +224,25 @@ enum {
224 * See "Xterm Control Sequences" 224 * See "Xterm Control Sequences"
225 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html 225 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
226 */ 226 */
227#define ESC "\033"
227/* Inverse/Normal text */ 228/* Inverse/Normal text */
228#define ESC_BOLD_TEXT "\033[7m" 229#define ESC_BOLD_TEXT ESC"[7m"
229#define ESC_NORM_TEXT "\033[0m" 230#define ESC_NORM_TEXT ESC"[m"
230/* Bell */ 231/* Bell */
231#define ESC_BELL "\007" 232#define ESC_BELL "\007"
232/* Clear-to-end-of-line */ 233/* Clear-to-end-of-line */
233#define ESC_CLEAR2EOL "\033[K" 234#define ESC_CLEAR2EOL ESC"[K"
234/* Clear-to-end-of-screen. 235/* Clear-to-end-of-screen.
235 * (We use default param here. 236 * (We use default param here.
236 * Full sequence is "ESC [ <num> J", 237 * Full sequence is "ESC [ <num> J",
237 * <num> is 0/1/2 = "erase below/above/all".) 238 * <num> is 0/1/2 = "erase below/above/all".)
238 */ 239 */
239#define ESC_CLEAR2EOS "\033[J" 240#define ESC_CLEAR2EOS ESC"[J"
240/* Cursor to given coordinate (1,1: top left) */ 241/* Cursor to given coordinate (1,1: top left) */
241#define ESC_SET_CURSOR_POS "\033[%u;%uH" 242#define ESC_SET_CURSOR_POS ESC"[%u;%uH"
242//UNUSED 243//UNUSED
243///* Cursor up and down */ 244///* Cursor up and down */
244//#define ESC_CURSOR_UP "\033[A" 245//#define ESC_CURSOR_UP ESC"[A"
245//#define ESC_CURSOR_DOWN "\n" 246//#define ESC_CURSOR_DOWN "\n"
246 247
247#if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK 248#if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK
@@ -696,14 +697,14 @@ int vi_main(int argc, char **argv)
696 save_argc = argc; 697 save_argc = argc;
697 optind = 0; 698 optind = 0;
698 // "Save cursor, use alternate screen buffer, clear screen" 699 // "Save cursor, use alternate screen buffer, clear screen"
699 write1("\033[?1049h"); 700 write1(ESC"[?1049h");
700 while (1) { 701 while (1) {
701 edit_file(argv[optind]); /* param might be NULL */ 702 edit_file(argv[optind]); /* param might be NULL */
702 if (++optind >= argc) 703 if (++optind >= argc)
703 break; 704 break;
704 } 705 }
705 // "Use normal screen buffer, restore cursor" 706 // "Use normal screen buffer, restore cursor"
706 write1("\033[?1049l"); 707 write1(ESC"[?1049l");
707 //----------------------------------------------------------- 708 //-----------------------------------------------------------
708 709
709 return 0; 710 return 0;
@@ -772,7 +773,7 @@ static void edit_file(char *fn)
772#if ENABLE_FEATURE_VI_ASK_TERMINAL 773#if ENABLE_FEATURE_VI_ASK_TERMINAL
773 if (G.get_rowcol_error /* TODO? && no input on stdin */) { 774 if (G.get_rowcol_error /* TODO? && no input on stdin */) {
774 uint64_t k; 775 uint64_t k;
775 write1("\033[999;999H" "\033[6n"); 776 write1(ESC"[999;999H" ESC"[6n");
776 fflush_all(); 777 fflush_all();
777 k = read_key(STDIN_FILENO, readbuffer, /*timeout_ms:*/ 100); 778 k = read_key(STDIN_FILENO, readbuffer, /*timeout_ms:*/ 100);
778 if ((int32_t)k == KEYCODE_CURSOR_POS) { 779 if ((int32_t)k == KEYCODE_CURSOR_POS) {
@@ -4454,7 +4455,7 @@ static void crash_dummy()
4454 sleeptime = 0; // how fast to type 4455 sleeptime = 0; // how fast to type
4455 } 4456 }
4456 } 4457 }
4457 strcat(readbuffer, "\033"); 4458 strcat(readbuffer, ESC);
4458 } 4459 }
4459 readbuffer[0] = strlen(readbuffer + 1); 4460 readbuffer[0] = strlen(readbuffer + 1);
4460 cd1: 4461 cd1:
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 0106093a1..17766a126 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -2868,7 +2868,7 @@ int main(int argc, char **argv)
2868#if ENABLE_FEATURE_EDITING_FANCY_PROMPT 2868#if ENABLE_FEATURE_EDITING_FANCY_PROMPT
2869 "\\[\\033[32;1m\\]\\u@\\[\\x1b[33;1m\\]\\h:" 2869 "\\[\\033[32;1m\\]\\u@\\[\\x1b[33;1m\\]\\h:"
2870 "\\[\\033[34;1m\\]\\w\\[\\033[35;1m\\] " 2870 "\\[\\033[34;1m\\]\\w\\[\\033[35;1m\\] "
2871 "\\!\\[\\e[36;1m\\]\\$ \\[\\E[0m\\]"; 2871 "\\!\\[\\e[36;1m\\]\\$ \\[\\E[m\\]";
2872#else 2872#else
2873 "% "; 2873 "% ";
2874#endif 2874#endif
diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c
index 9ac91e01e..5b2e5ac56 100644
--- a/miscutils/fbsplash.c
+++ b/miscutils/fbsplash.c
@@ -65,6 +65,8 @@
65/* If you want logging messages on /tmp/fbsplash.log... */ 65/* If you want logging messages on /tmp/fbsplash.log... */
66#define DEBUG 0 66#define DEBUG 0
67 67
68#define ESC "\033"
69
68struct globals { 70struct globals {
69#if DEBUG 71#if DEBUG
70 bool bdebug_messages; // enable/disable logging 72 bool bdebug_messages; // enable/disable logging
@@ -514,7 +516,7 @@ int fbsplash_main(int argc UNUSED_PARAM, char **argv)
514 516
515 if (fifo_filename && bCursorOff) { 517 if (fifo_filename && bCursorOff) {
516 // hide cursor (BEFORE any fb ops) 518 // hide cursor (BEFORE any fb ops)
517 full_write(STDOUT_FILENO, "\033[?25l", 6); 519 full_write(STDOUT_FILENO, ESC"[?25l", 6);
518 } 520 }
519 521
520 fb_drawimage(); 522 fb_drawimage();
@@ -559,7 +561,7 @@ int fbsplash_main(int argc UNUSED_PARAM, char **argv)
559 } 561 }
560 562
561 if (bCursorOff) // restore cursor 563 if (bCursorOff) // restore cursor
562 full_write(STDOUT_FILENO, "\033[?25h", 6); 564 full_write(STDOUT_FILENO, ESC"[?25h", 6);
563 565
564 return EXIT_SUCCESS; 566 return EXIT_SUCCESS;
565} 567}
diff --git a/miscutils/less.c b/miscutils/less.c
index f37c80ad8..241f7f8ba 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -137,7 +137,7 @@
137#define ESC "\033" 137#define ESC "\033"
138/* The escape codes for highlighted and normal text */ 138/* The escape codes for highlighted and normal text */
139#define HIGHLIGHT ESC"[7m" 139#define HIGHLIGHT ESC"[7m"
140#define NORMAL ESC"[0m" 140#define NORMAL ESC"[m"
141/* The escape code to home and clear to the end of screen */ 141/* The escape code to home and clear to the end of screen */
142#define CLEAR ESC"[H"ESC"[J" 142#define CLEAR ESC"[H"ESC"[J"
143/* The escape code to clear to the end of line */ 143/* The escape code to clear to the end of line */
@@ -1042,7 +1042,7 @@ static void reinitialize(void)
1042 open_file_and_read_lines(); 1042 open_file_and_read_lines();
1043#if ENABLE_FEATURE_LESS_ASK_TERMINAL 1043#if ENABLE_FEATURE_LESS_ASK_TERMINAL
1044 if (G.winsize_err) 1044 if (G.winsize_err)
1045 printf("\033[999;999H" "\033[6n"); 1045 printf(ESC"[999;999H" ESC"[6n");
1046#endif 1046#endif
1047 buffer_fill_and_print(); 1047 buffer_fill_and_print();
1048} 1048}
diff --git a/procps/powertop.c b/procps/powertop.c
index 5d522bf91..2872035cf 100644
--- a/procps/powertop.c
+++ b/procps/powertop.c
@@ -51,6 +51,8 @@
51/* Max filename length of entry in /sys/devices subsystem */ 51/* Max filename length of entry in /sys/devices subsystem */
52#define BIG_SYSNAME_LEN 16 52#define BIG_SYSNAME_LEN 16
53 53
54#define ESC "\033"
55
54typedef unsigned long long ullong; 56typedef unsigned long long ullong;
55 57
56struct line { 58struct line {
@@ -776,8 +778,8 @@ int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
776 } 778 }
777 } 779 }
778 780
779 /* Clear the screen */ 781 /* Home; clear screen */
780 printf("\033[H\033[J"); 782 printf(ESC"[H" ESC"[J");
781 783
782 /* Clear C-state lines */ 784 /* Clear C-state lines */
783 memset(&cstate_lines, 0, sizeof(cstate_lines)); 785 memset(&cstate_lines, 0, sizeof(cstate_lines));
diff --git a/procps/top.c b/procps/top.c
index f97ded5d6..b777c494e 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -117,6 +117,7 @@
117 117
118#include "libbb.h" 118#include "libbb.h"
119 119
120#define ESC "\033"
120 121
121typedef struct top_status_t { 122typedef struct top_status_t {
122 unsigned long vsz; 123 unsigned long vsz;
@@ -580,7 +581,7 @@ static unsigned long display_header(int scr_width, int *lines_rem_p)
580 meminfo[MI_BUFFERS], 581 meminfo[MI_BUFFERS],
581 meminfo[MI_CACHED]); 582 meminfo[MI_CACHED]);
582 /* Go to top & clear to the end of screen */ 583 /* Go to top & clear to the end of screen */
583 printf(OPT_BATCH_MODE ? "%s\n" : "\033[H\033[J%s\n", scrbuf); 584 printf(OPT_BATCH_MODE ? "%s\n" : ESC"[H" ESC"[J" "%s\n", scrbuf);
584 (*lines_rem_p)--; 585 (*lines_rem_p)--;
585 586
586 /* Display CPU time split as percentage of total time. 587 /* Display CPU time split as percentage of total time.
@@ -618,7 +619,7 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
618#endif 619#endif
619 620
620 /* what info of the processes is shown */ 621 /* what info of the processes is shown */
621 printf(OPT_BATCH_MODE ? "%.*s" : "\033[7m%.*s\033[0m", scr_width, 622 printf(OPT_BATCH_MODE ? "%.*s" : ESC"[7m" "%.*s" ESC"[m", scr_width,
622 " PID PPID USER STAT VSZ %VSZ" 623 " PID PPID USER STAT VSZ %VSZ"
623 IF_FEATURE_TOP_SMP_PROCESS(" CPU") 624 IF_FEATURE_TOP_SMP_PROCESS(" CPU")
624 IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(" %CPU") 625 IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(" %CPU")
@@ -802,7 +803,7 @@ static void display_topmem_header(int scr_width, int *lines_rem_p)
802 meminfo[MI_ANONPAGES], 803 meminfo[MI_ANONPAGES],
803 meminfo[MI_MAPPED], 804 meminfo[MI_MAPPED],
804 meminfo[MI_MEMFREE]); 805 meminfo[MI_MEMFREE]);
805 printf(OPT_BATCH_MODE ? "%.*s\n" : "\033[H\033[J%.*s\n", scr_width, line_buf); 806 printf(OPT_BATCH_MODE ? "%.*s\n" : ESC"[H" ESC"[J" "%.*s\n", scr_width, line_buf);
806 807
807 snprintf(line_buf, LINE_BUF_SIZE, 808 snprintf(line_buf, LINE_BUF_SIZE,
808 " slab:%lu buf:%lu cache:%lu dirty:%lu write:%lu", 809 " slab:%lu buf:%lu cache:%lu dirty:%lu write:%lu",
@@ -844,7 +845,7 @@ static NOINLINE void display_topmem_process_list(int lines_rem, int scr_width)
844 cp[6] = ch; 845 cp[6] = ch;
845 do *cp++ = ch; while (*cp == ' '); 846 do *cp++ = ch; while (*cp == ' ');
846 847
847 printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, line_buf); 848 printf(OPT_BATCH_MODE ? "%.*s" : ESC"[7m" "%.*s" ESC"[m", scr_width, line_buf);
848 lines_rem--; 849 lines_rem--;
849 850
850 if (lines_rem > ntop - G_scroll_ofs) 851 if (lines_rem > ntop - G_scroll_ofs)
diff --git a/procps/watch.c b/procps/watch.c
index 6fc9f7db7..e58fd1f11 100644
--- a/procps/watch.c
+++ b/procps/watch.c
@@ -37,6 +37,8 @@
37 37
38#include "libbb.h" 38#include "libbb.h"
39 39
40#define ESC "\033"
41
40// procps 2.0.18: 42// procps 2.0.18:
41// watch [-d] [-n seconds] 43// watch [-d] [-n seconds]
42// [--differences[=cumulative]] [--interval=seconds] command 44// [--differences[=cumulative]] [--interval=seconds] command
@@ -77,7 +79,7 @@ int watch_main(int argc UNUSED_PARAM, char **argv)
77 header = NULL; 79 header = NULL;
78 while (1) { 80 while (1) {
79 /* home; clear to the end of screen */ 81 /* home; clear to the end of screen */
80 printf("\033[H""\033[J"); 82 printf(ESC"[H" ESC"[J");
81 if (!(opt & 0x2)) { // no -t 83 if (!(opt & 0x2)) { // no -t
82 const unsigned time_len = sizeof("1234-67-90 23:56:89"); 84 const unsigned time_len = sizeof("1234-67-90 23:56:89");
83 85