conspy: code shrink

function                                             old     new   delta
conspy_main                                         1385    1380      -5
screen_dump                                          215     202     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2010-06-25 00:57:57 +02:00
parent eff6d59343
commit 51fa147c9b

View File

@ -50,10 +50,10 @@ struct screen_info {
unsigned char lines, rows, cursor_x, cursor_y;
};
#define CHAR(x) ((x)[0])
#define ATTR(x) ((x)[1])
#define CHAR(x) ((uint8_t)((x)[0]))
#define ATTR(x) ((uint8_t)((x)[1]))
#define NEXT(x) ((x)+=2)
#define DATA(x) (* (short *) (x))
#define DATA(x) (*(uint16_t*)(x))
struct globals {
char* data;
@ -102,7 +102,7 @@ static void screen_read_close(void)
unsigned y = i - G.y; // if will catch i < G.y too
if (CHAR(data) < ' ')
CHAR(data) = ' ';
*data = ' '; // CHAR(data) = ' ';
if (y >= G.height || x >= G.width)
DATA(data) = 0;
}
@ -151,8 +151,15 @@ static void screen_char(char *data)
putchar(CHAR(data));
}
#define clrscr() printf("\033[1;1H" "\033[0J")
#define curoff() printf("\033[?25l")
static void clrscr(void)
{
printf("\033[1;1H" "\033[0J");
}
static void curoff(void)
{
printf("\033[?25l");
}
static void curon(void)
{
@ -180,10 +187,10 @@ static void screen_dump(void)
if (tty_row >= G.width)
continue;
space_cnt++;
if (BW && (CHAR(data) | ' ') == ' ')
if (BW && CHAR(data) == ' ')
continue;
while (linefeed_cnt != 0) {
bb_putchar('\r');
//bb_putchar('\r'); - tty driver does it for us
bb_putchar('\n');
linefeed_cnt--;
}
@ -229,12 +236,11 @@ static void cleanup(int code)
static void get_initial_data(const char* vcsa_name)
{
int size;
G.vcsa_fd = xopen(vcsa_name, O_RDONLY);
xread(G.vcsa_fd, &G.info, 4);
G.size = size = G.info.rows * G.info.lines * 2;
G.size = G.info.rows * G.info.lines * 2;
G.width = G.height = UINT_MAX;
G.data = xzalloc(2 * size);
G.data = xzalloc(2 * G.size);
screen_read_close();
}
@ -280,11 +286,11 @@ static NOINLINE void start_shell_in_child(const char* tty_name)
}
}
int conspy_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE;
int conspy_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int conspy_main(int argc UNUSED_PARAM, char **argv)
{
char vcsa_name[sizeof("/dev/vcsa") + 2];
char tty_name[sizeof("/dev/tty") + 2];
char vcsa_name[sizeof("/dev/vcsaNN")];
char tty_name[sizeof("/dev/ttyNN")];
#define keybuf bb_common_bufsiz1
struct termios termbuf;
unsigned opts;
@ -339,7 +345,7 @@ int conspy_main(int argc UNUSED_PARAM, char **argv)
tcgetattr(G.kbd_fd, &G.term_orig);
termbuf = G.term_orig;
termbuf.c_iflag &= ~(BRKINT|INLCR|ICRNL|IXON|IXOFF|IUCLC|IXANY|IMAXBEL);
termbuf.c_oflag &= ~(OPOST);
//termbuf.c_oflag &= ~(OPOST); - no, we still want \n -> \r\n
termbuf.c_lflag &= ~(ISIG|ICANON|ECHO);
termbuf.c_cc[VMIN] = 1;
termbuf.c_cc[VTIME] = 0;
@ -448,7 +454,8 @@ int conspy_main(int argc UNUSED_PARAM, char **argv)
// Do exit processing
for (i = 0; i < bytes_read; i++) {
if (k[i] != '\033') G.escape_count = 0;
if (k[i] != '\033')
G.escape_count = 0;
else if (++G.escape_count >= 3)
cleanup(0);
}