aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorMarek Polacek <mmpolacek@gmail.com>2010-10-28 21:34:56 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-10-28 21:34:56 +0200
commit7b18107384d950358e146d42bf02b391fab5ffd6 (patch)
tree9994e2bcaa038c3128ed8b3bca99486e22f660fb /miscutils
parent02788ac7e2a44eee889aa1005e89076f928e964a (diff)
downloadbusybox-w32-7b18107384d950358e146d42bf02b391fab5ffd6.tar.gz
busybox-w32-7b18107384d950358e146d42bf02b391fab5ffd6.tar.bz2
busybox-w32-7b18107384d950358e146d42bf02b391fab5ffd6.zip
*: use _exit() in sighandlers; showkey: do not use exit-thru-sighandler
While at it, make ESC sequences more readable; and removed check for isatty(stdin) in reset. Code shrink: text data bss dec hex filename 884771 936 17216 902923 dc70b busybox_old 884723 936 17216 902875 dc6db busybox_unstripped Signed-off-by: Marek Polacek <mmpolacek@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/conspy.c13
-rw-r--r--miscutils/less.c14
-rw-r--r--miscutils/watchdog.c2
3 files changed, 17 insertions, 12 deletions
diff --git a/miscutils/conspy.c b/miscutils/conspy.c
index 01928b35f..040fa86f3 100644
--- a/miscutils/conspy.c
+++ b/miscutils/conspy.c
@@ -43,6 +43,9 @@
43#include "libbb.h" 43#include "libbb.h"
44#include <sys/kd.h> 44#include <sys/kd.h>
45 45
46
47#define ESC "\033"
48
46struct screen_info { 49struct screen_info {
47 unsigned char lines, cols, cursor_x, cursor_y; 50 unsigned char lines, cols, cursor_x, cursor_y;
48}; 51};
@@ -70,7 +73,7 @@ struct globals {
70 unsigned col; 73 unsigned col;
71 unsigned line; 74 unsigned line;
72 smallint curoff; // unknown:0 cursor on:-1 cursor off:1 75 smallint curoff; // unknown:0 cursor on:-1 cursor off:1
73 char attrbuf[sizeof("\033[0;1;5;30;40m")]; 76 char attrbuf[sizeof(ESC"[0;1;5;30;40m")];
74 // remote console 77 // remote console
75 struct screen_info remote; 78 struct screen_info remote;
76 // saved local tty terminfo 79 // saved local tty terminfo
@@ -101,7 +104,7 @@ enum {
101static void clrscr(void) 104static void clrscr(void)
102{ 105{
103 // Home, clear till end of screen 106 // Home, clear till end of screen
104 fputs("\033[1;1H" "\033[J", stdout); 107 fputs(ESC"[1;1H" ESC"[J", stdout);
105 G.col = G.line = 0; 108 G.col = G.line = 0;
106} 109}
107 110
@@ -109,7 +112,7 @@ static void set_cursor(int state)
109{ 112{
110 if (G.curoff != state) { 113 if (G.curoff != state) {
111 G.curoff = state; 114 G.curoff = state;
112 fputs("\033[?25", stdout); 115 fputs(ESC"[?25", stdout);
113 bb_putchar("h?l"[1 + state]); 116 bb_putchar("h?l"[1 + state]);
114 } 117 }
115} 118}
@@ -119,7 +122,7 @@ static void gotoxy(int col, int line)
119 if (G.col != col || G.line != line) { 122 if (G.col != col || G.line != line) {
120 G.col = col; 123 G.col = col;
121 G.line = line; 124 G.line = line;
122 printf("\033[%u;%uH", line + 1, col + 1); 125 printf(ESC"[%u;%uH", line + 1, col + 1);
123 } 126 }
124} 127}
125 128
@@ -132,7 +135,7 @@ static void cleanup(int code)
132 } 135 }
133 // Reset attributes 136 // Reset attributes
134 if (!BW) 137 if (!BW)
135 fputs("\033[0m", stdout); 138 fputs(ESC"[0m", stdout);
136 bb_putchar('\n'); 139 bb_putchar('\n');
137 if (code > 1) 140 if (code > 1)
138 kill_myself_with_sig(code); 141 kill_myself_with_sig(code);
diff --git a/miscutils/less.c b/miscutils/less.c
index 500059d2a..9e12c11a7 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -28,13 +28,15 @@
28#include "xregex.h" 28#include "xregex.h"
29#endif 29#endif
30 30
31
32#define ESC "\033"
31/* The escape codes for highlighted and normal text */ 33/* The escape codes for highlighted and normal text */
32#define HIGHLIGHT "\033[7m" 34#define HIGHLIGHT ESC"[7m"
33#define NORMAL "\033[0m" 35#define NORMAL ESC"[0m"
34/* The escape code to home and clear to the end of screen */ 36/* The escape code to home and clear to the end of screen */
35#define CLEAR "\033[H\033[J" 37#define CLEAR ESC"[H\033[J"
36/* The escape code to clear to the end of line */ 38/* The escape code to clear to the end of line */
37#define CLEAR_2_EOL "\033[K" 39#define CLEAR_2_EOL ESC"[K"
38 40
39enum { 41enum {
40/* Absolute max of lines eaten */ 42/* Absolute max of lines eaten */
@@ -165,12 +167,12 @@ static void set_tty_cooked(void)
165 top-left corner of the console */ 167 top-left corner of the console */
166static void move_cursor(int line, int row) 168static void move_cursor(int line, int row)
167{ 169{
168 printf("\033[%u;%uH", line, row); 170 printf(ESC"[%u;%uH", line, row);
169} 171}
170 172
171static void clear_line(void) 173static void clear_line(void)
172{ 174{
173 printf("\033[%u;0H" CLEAR_2_EOL, max_displayed_line + 2); 175 printf(ESC"[%u;0H" CLEAR_2_EOL, max_displayed_line + 2);
174} 176}
175 177
176static void print_hilite(const char *str) 178static void print_hilite(const char *str)
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c
index 36902a214..630782660 100644
--- a/miscutils/watchdog.c
+++ b/miscutils/watchdog.c
@@ -24,7 +24,7 @@ static void watchdog_shutdown(int sig UNUSED_PARAM)
24 write(3, &V, 1); /* Magic, see watchdog-api.txt in kernel */ 24 write(3, &V, 1); /* Magic, see watchdog-api.txt in kernel */
25 if (ENABLE_FEATURE_CLEAN_UP) 25 if (ENABLE_FEATURE_CLEAN_UP)
26 close(3); 26 close(3);
27 exit(EXIT_SUCCESS); 27 _exit(EXIT_SUCCESS);
28} 28}
29 29
30int watchdog_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 30int watchdog_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;