*: 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>
This commit is contained in:
Marek Polacek
2010-10-28 21:34:56 +02:00
committed by Denys Vlasenko
parent 02788ac7e2
commit 7b18107384
8 changed files with 78 additions and 72 deletions

View File

@@ -43,6 +43,9 @@
#include "libbb.h"
#include <sys/kd.h>
#define ESC "\033"
struct screen_info {
unsigned char lines, cols, cursor_x, cursor_y;
};
@@ -70,7 +73,7 @@ struct globals {
unsigned col;
unsigned line;
smallint curoff; // unknown:0 cursor on:-1 cursor off:1
char attrbuf[sizeof("\033[0;1;5;30;40m")];
char attrbuf[sizeof(ESC"[0;1;5;30;40m")];
// remote console
struct screen_info remote;
// saved local tty terminfo
@@ -101,7 +104,7 @@ enum {
static void clrscr(void)
{
// Home, clear till end of screen
fputs("\033[1;1H" "\033[J", stdout);
fputs(ESC"[1;1H" ESC"[J", stdout);
G.col = G.line = 0;
}
@@ -109,7 +112,7 @@ static void set_cursor(int state)
{
if (G.curoff != state) {
G.curoff = state;
fputs("\033[?25", stdout);
fputs(ESC"[?25", stdout);
bb_putchar("h?l"[1 + state]);
}
}
@@ -119,7 +122,7 @@ static void gotoxy(int col, int line)
if (G.col != col || G.line != line) {
G.col = col;
G.line = line;
printf("\033[%u;%uH", line + 1, col + 1);
printf(ESC"[%u;%uH", line + 1, col + 1);
}
}
@@ -132,7 +135,7 @@ static void cleanup(int code)
}
// Reset attributes
if (!BW)
fputs("\033[0m", stdout);
fputs(ESC"[0m", stdout);
bb_putchar('\n');
if (code > 1)
kill_myself_with_sig(code);

View File

@@ -28,13 +28,15 @@
#include "xregex.h"
#endif
#define ESC "\033"
/* The escape codes for highlighted and normal text */
#define HIGHLIGHT "\033[7m"
#define NORMAL "\033[0m"
#define HIGHLIGHT ESC"[7m"
#define NORMAL ESC"[0m"
/* The escape code to home and clear to the end of screen */
#define CLEAR "\033[H\033[J"
#define CLEAR ESC"[H\033[J"
/* The escape code to clear to the end of line */
#define CLEAR_2_EOL "\033[K"
#define CLEAR_2_EOL ESC"[K"
enum {
/* Absolute max of lines eaten */
@@ -165,12 +167,12 @@ static void set_tty_cooked(void)
top-left corner of the console */
static void move_cursor(int line, int row)
{
printf("\033[%u;%uH", line, row);
printf(ESC"[%u;%uH", line, row);
}
static void clear_line(void)
{
printf("\033[%u;0H" CLEAR_2_EOL, max_displayed_line + 2);
printf(ESC"[%u;0H" CLEAR_2_EOL, max_displayed_line + 2);
}
static void print_hilite(const char *str)

View File

@@ -24,7 +24,7 @@ static void watchdog_shutdown(int sig UNUSED_PARAM)
write(3, &V, 1); /* Magic, see watchdog-api.txt in kernel */
if (ENABLE_FEATURE_CLEAN_UP)
close(3);
exit(EXIT_SUCCESS);
_exit(EXIT_SUCCESS);
}
int watchdog_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;