*: use ESC define instead of "\033"; use ESC[m instead of ESC[0m
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 13 Sep 2017 20:48:30 +0000 (22:48 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 13 Sep 2017 20:48:30 +0000 (22:48 +0200)
   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>
console-tools/clear.c
console-tools/reset.c
coreutils/ls.c
editors/vi.c
libbb/lineedit.c
miscutils/fbsplash.c
miscutils/less.c
procps/powertop.c
procps/top.c
procps/watch.c

index 3cc16257ba3d81f0883041b21d274e1f26c68ee3..09ef1ea68265bd291bbdb3e8dddea37d115d20fb 100644 (file)
 
 #include "libbb.h"
 
+#define ESC "\033"
+
 int clear_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int clear_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
 {
        /* home; clear to the end of screen */
-       return full_write1_str("\033[H""\033[J") != 6;
+       return full_write1_str(ESC"[H" ESC"[J") != 6;
 }
index f2b900ddb709eca9b2a54a5723c1aed1b7f89d20..471ef9158cee9f5cd585838f7204290b9d5dafcb 100644 (file)
@@ -46,11 +46,11 @@ int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
                /* See 'man 4 console_codes' for details:
                 * "ESC c"        -- Reset
                 * "ESC ( B"      -- Select G0 Character Set (B = US)
-                * "ESC [ 0 m"    -- Reset all display attributes
+                * "ESC [ m"      -- Reset all display attributes
                 * "ESC [ J"      -- Erase to the end of screen
                 * "ESC [ ? 25 h" -- Make cursor visible
                 */
-               printf(ESC"c" ESC"(B" ESC"[0m" ESC"[J" ESC"[?25h");
+               printf(ESC"c" ESC"(B" ESC"[m" ESC"[J" ESC"[?25h");
                /* http://bugs.busybox.net/view.php?id=1414:
                 * people want it to reset echo etc: */
 #if ENABLE_STTY
index af5e6cb5195cc0149585dbca9c34cf4fb62fecb6..a4e324b00e4ec442663b18351c0de2bd4b93bc0f 100644 (file)
@@ -347,6 +347,8 @@ struct globals {
        IF_FEATURE_LS_TIMESTAMPS(time(&G.current_time_t);) \
 } while (0)
 
+#define ESC "\033"
+
 
 /*** Output code ***/
 
@@ -586,12 +588,12 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
                if (!mode)
                        if (lstat(dn->fullname, &statbuf) == 0)
                                mode = statbuf.st_mode;
-               printf("\033[%u;%um", bold(mode), fgcolor(mode));
+               printf(ESC"[%u;%um", bold(mode), fgcolor(mode));
        }
 #endif
        column += print_name(dn->name);
        if (G_show_color) {
-               printf("\033[0m");
+               printf(ESC"[m");
        }
 
        if (lpath) {
@@ -609,7 +611,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
 # endif
 # if ENABLE_FEATURE_LS_COLOR
                        if (G_show_color) {
-                               printf("\033[%u;%um", bold(mode), fgcolor(mode));
+                               printf(ESC"[%u;%um", bold(mode), fgcolor(mode));
                        }
 # endif
                }
@@ -617,7 +619,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
                column += print_name(lpath) + 4;
                free(lpath);
                if (G_show_color) {
-                       printf("\033[0m");
+                       printf(ESC"[m");
                }
        }
 #if ENABLE_FEATURE_LS_FILETYPES
index 116022c930fc98f5bbeea481da47f8e35dfce487..c010f79995681737ec48adeb8a8194790bd58750 100644 (file)
@@ -224,24 +224,25 @@ enum {
  * See "Xterm Control Sequences"
  * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
  */
+#define ESC "\033"
 /* Inverse/Normal text */
-#define ESC_BOLD_TEXT "\033[7m"
-#define ESC_NORM_TEXT "\033[0m"
+#define ESC_BOLD_TEXT ESC"[7m"
+#define ESC_NORM_TEXT ESC"[m"
 /* Bell */
 #define ESC_BELL "\007"
 /* Clear-to-end-of-line */
-#define ESC_CLEAR2EOL "\033[K"
+#define ESC_CLEAR2EOL ESC"[K"
 /* Clear-to-end-of-screen.
  * (We use default param here.
  * Full sequence is "ESC [ <num> J",
  * <num> is 0/1/2 = "erase below/above/all".)
  */
-#define ESC_CLEAR2EOS "\033[J"
+#define ESC_CLEAR2EOS ESC"[J"
 /* Cursor to given coordinate (1,1: top left) */
-#define ESC_SET_CURSOR_POS "\033[%u;%uH"
+#define ESC_SET_CURSOR_POS ESC"[%u;%uH"
 //UNUSED
 ///* Cursor up and down */
-//#define ESC_CURSOR_UP "\033[A"
+//#define ESC_CURSOR_UP   ESC"[A"
 //#define ESC_CURSOR_DOWN "\n"
 
 #if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK
@@ -696,14 +697,14 @@ int vi_main(int argc, char **argv)
        save_argc = argc;
        optind = 0;
        // "Save cursor, use alternate screen buffer, clear screen"
-       write1("\033[?1049h");
+       write1(ESC"[?1049h");
        while (1) {
                edit_file(argv[optind]); /* param might be NULL */
                if (++optind >= argc)
                        break;
        }
        // "Use normal screen buffer, restore cursor"
-       write1("\033[?1049l");
+       write1(ESC"[?1049l");
        //-----------------------------------------------------------
 
        return 0;
@@ -772,7 +773,7 @@ static void edit_file(char *fn)
 #if ENABLE_FEATURE_VI_ASK_TERMINAL
        if (G.get_rowcol_error /* TODO? && no input on stdin */) {
                uint64_t k;
-               write1("\033[999;999H" "\033[6n");
+               write1(ESC"[999;999H" ESC"[6n");
                fflush_all();
                k = read_key(STDIN_FILENO, readbuffer, /*timeout_ms:*/ 100);
                if ((int32_t)k == KEYCODE_CURSOR_POS) {
@@ -4454,7 +4455,7 @@ static void crash_dummy()
                                sleeptime = 0;  // how fast to type
                        }
                }
-               strcat(readbuffer, "\033");
+               strcat(readbuffer, ESC);
        }
        readbuffer[0] = strlen(readbuffer + 1);
  cd1:
index 0106093a151417a80e50cb5575c59e72e549bee8..17766a12640726d04282e800718fdf60e24d9ed2 100644 (file)
@@ -2868,7 +2868,7 @@ int main(int argc, char **argv)
 #if ENABLE_FEATURE_EDITING_FANCY_PROMPT
                "\\[\\033[32;1m\\]\\u@\\[\\x1b[33;1m\\]\\h:"
                "\\[\\033[34;1m\\]\\w\\[\\033[35;1m\\] "
-               "\\!\\[\\e[36;1m\\]\\$ \\[\\E[0m\\]";
+               "\\!\\[\\e[36;1m\\]\\$ \\[\\E[m\\]";
 #else
                "% ";
 #endif
index 9ac91e01e1a81072cd80e619b38eae3638565eff..5b2e5ac56f4e88a8dc83baf3fdc649bc32b5f0e6 100644 (file)
@@ -65,6 +65,8 @@
 /* If you want logging messages on /tmp/fbsplash.log... */
 #define DEBUG 0
 
+#define ESC "\033"
+
 struct globals {
 #if DEBUG
        bool bdebug_messages;   // enable/disable logging
@@ -514,7 +516,7 @@ int fbsplash_main(int argc UNUSED_PARAM, char **argv)
 
        if (fifo_filename && bCursorOff) {
                // hide cursor (BEFORE any fb ops)
-               full_write(STDOUT_FILENO, "\033[?25l", 6);
+               full_write(STDOUT_FILENO, ESC"[?25l", 6);
        }
 
        fb_drawimage();
@@ -559,7 +561,7 @@ int fbsplash_main(int argc UNUSED_PARAM, char **argv)
        }
 
        if (bCursorOff) // restore cursor
-               full_write(STDOUT_FILENO, "\033[?25h", 6);
+               full_write(STDOUT_FILENO, ESC"[?25h", 6);
 
        return EXIT_SUCCESS;
 }
index f37c80ad82191875ceefb7166075928cda72fa47..241f7f8ba1fbb68e4a70993b437edb0e24683a04 100644 (file)
 #define ESC "\033"
 /* The escape codes for highlighted and normal text */
 #define HIGHLIGHT   ESC"[7m"
-#define NORMAL      ESC"[0m"
+#define NORMAL      ESC"[m"
 /* The escape code to home and clear to the end of screen */
 #define CLEAR       ESC"[H"ESC"[J"
 /* The escape code to clear to the end of line */
@@ -1042,7 +1042,7 @@ static void reinitialize(void)
        open_file_and_read_lines();
 #if ENABLE_FEATURE_LESS_ASK_TERMINAL
        if (G.winsize_err)
-               printf("\033[999;999H" "\033[6n");
+               printf(ESC"[999;999H" ESC"[6n");
 #endif
        buffer_fill_and_print();
 }
index 5d522bf918c23197d6c9dc07da844db402491f57..2872035cfcfaf1cc33d06dda94e0a2cf2caaebe2 100644 (file)
@@ -51,6 +51,8 @@
 /* Max filename length of entry in /sys/devices subsystem */
 #define BIG_SYSNAME_LEN    16
 
+#define ESC "\033"
+
 typedef unsigned long long ullong;
 
 struct line {
@@ -776,8 +778,8 @@ int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
                        }
                }
 
-               /* Clear the screen */
-               printf("\033[H\033[J");
+               /* Home; clear screen */
+               printf(ESC"[H" ESC"[J");
 
                /* Clear C-state lines */
                memset(&cstate_lines, 0, sizeof(cstate_lines));
index f97ded5d6e47080c1958a1fc7cb1bf15f404a1af..b777c494ea0041b60aaca79457ed3d26c82eb71b 100644 (file)
 
 #include "libbb.h"
 
+#define ESC "\033"
 
 typedef struct top_status_t {
        unsigned long vsz;
@@ -580,7 +581,7 @@ static unsigned long display_header(int scr_width, int *lines_rem_p)
                meminfo[MI_BUFFERS],
                meminfo[MI_CACHED]);
        /* Go to top & clear to the end of screen */
-       printf(OPT_BATCH_MODE ? "%s\n" : "\033[H\033[J%s\n", scrbuf);
+       printf(OPT_BATCH_MODE ? "%s\n" : ESC"[H" ESC"[J" "%s\n", scrbuf);
        (*lines_rem_p)--;
 
        /* 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)
 #endif
 
        /* what info of the processes is shown */
-       printf(OPT_BATCH_MODE ? "%.*s" : "\033[7m%.*s\033[0m", scr_width,
+       printf(OPT_BATCH_MODE ? "%.*s" : ESC"[7m" "%.*s" ESC"[m", scr_width,
                "  PID  PPID USER     STAT   VSZ %VSZ"
                IF_FEATURE_TOP_SMP_PROCESS(" CPU")
                IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(" %CPU")
@@ -802,7 +803,7 @@ static void display_topmem_header(int scr_width, int *lines_rem_p)
                meminfo[MI_ANONPAGES],
                meminfo[MI_MAPPED],
                meminfo[MI_MEMFREE]);
-       printf(OPT_BATCH_MODE ? "%.*s\n" : "\033[H\033[J%.*s\n", scr_width, line_buf);
+       printf(OPT_BATCH_MODE ? "%.*s\n" : ESC"[H" ESC"[J" "%.*s\n", scr_width, line_buf);
 
        snprintf(line_buf, LINE_BUF_SIZE,
                " 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)
        cp[6] = ch;
        do *cp++ = ch; while (*cp == ' ');
 
-       printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, line_buf);
+       printf(OPT_BATCH_MODE ? "%.*s" : ESC"[7m" "%.*s" ESC"[m", scr_width, line_buf);
        lines_rem--;
 
        if (lines_rem > ntop - G_scroll_ofs)
index 6fc9f7db7794b1e0b9aec6d6b90ffc02b6ce67d1..e58fd1f110a31484818766c8fc11ecee9b559aec 100644 (file)
@@ -37,6 +37,8 @@
 
 #include "libbb.h"
 
+#define ESC "\033"
+
 // procps 2.0.18:
 // watch [-d] [-n seconds]
 //   [--differences[=cumulative]] [--interval=seconds] command
@@ -77,7 +79,7 @@ int watch_main(int argc UNUSED_PARAM, char **argv)
        header = NULL;
        while (1) {
                /* home; clear to the end of screen */
-               printf("\033[H""\033[J");
+               printf(ESC"[H" ESC"[J");
                if (!(opt & 0x2)) { // no -t
                        const unsigned time_len = sizeof("1234-67-90 23:56:89");