mirror of
https://github.com/sheumann/hush.git
synced 2024-12-21 23:29:34 +00:00
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:
parent
eff6d59343
commit
51fa147c9b
@ -9,7 +9,7 @@
|
|||||||
*
|
*
|
||||||
* Licensed under GPLv2 or later, see file License in this tarball for details.
|
* Licensed under GPLv2 or later, see file License in this tarball for details.
|
||||||
*
|
*
|
||||||
* example : conspy num shared access to console num
|
* example: conspy num shared access to console num
|
||||||
* or conspy -d num screenshot of console num
|
* or conspy -d num screenshot of console num
|
||||||
* or conspy -cs num poor man's GNU screen like
|
* or conspy -cs num poor man's GNU screen like
|
||||||
*/
|
*/
|
||||||
@ -50,10 +50,10 @@ struct screen_info {
|
|||||||
unsigned char lines, rows, cursor_x, cursor_y;
|
unsigned char lines, rows, cursor_x, cursor_y;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CHAR(x) ((x)[0])
|
#define CHAR(x) ((uint8_t)((x)[0]))
|
||||||
#define ATTR(x) ((x)[1])
|
#define ATTR(x) ((uint8_t)((x)[1]))
|
||||||
#define NEXT(x) ((x)+=2)
|
#define NEXT(x) ((x)+=2)
|
||||||
#define DATA(x) (* (short *) (x))
|
#define DATA(x) (*(uint16_t*)(x))
|
||||||
|
|
||||||
struct globals {
|
struct globals {
|
||||||
char* data;
|
char* data;
|
||||||
@ -102,7 +102,7 @@ static void screen_read_close(void)
|
|||||||
unsigned y = i - G.y; // if will catch i < G.y too
|
unsigned y = i - G.y; // if will catch i < G.y too
|
||||||
|
|
||||||
if (CHAR(data) < ' ')
|
if (CHAR(data) < ' ')
|
||||||
CHAR(data) = ' ';
|
*data = ' '; // CHAR(data) = ' ';
|
||||||
if (y >= G.height || x >= G.width)
|
if (y >= G.height || x >= G.width)
|
||||||
DATA(data) = 0;
|
DATA(data) = 0;
|
||||||
}
|
}
|
||||||
@ -151,8 +151,15 @@ static void screen_char(char *data)
|
|||||||
putchar(CHAR(data));
|
putchar(CHAR(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define clrscr() printf("\033[1;1H" "\033[0J")
|
static void clrscr(void)
|
||||||
#define curoff() printf("\033[?25l")
|
{
|
||||||
|
printf("\033[1;1H" "\033[0J");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void curoff(void)
|
||||||
|
{
|
||||||
|
printf("\033[?25l");
|
||||||
|
}
|
||||||
|
|
||||||
static void curon(void)
|
static void curon(void)
|
||||||
{
|
{
|
||||||
@ -180,10 +187,10 @@ static void screen_dump(void)
|
|||||||
if (tty_row >= G.width)
|
if (tty_row >= G.width)
|
||||||
continue;
|
continue;
|
||||||
space_cnt++;
|
space_cnt++;
|
||||||
if (BW && (CHAR(data) | ' ') == ' ')
|
if (BW && CHAR(data) == ' ')
|
||||||
continue;
|
continue;
|
||||||
while (linefeed_cnt != 0) {
|
while (linefeed_cnt != 0) {
|
||||||
bb_putchar('\r');
|
//bb_putchar('\r'); - tty driver does it for us
|
||||||
bb_putchar('\n');
|
bb_putchar('\n');
|
||||||
linefeed_cnt--;
|
linefeed_cnt--;
|
||||||
}
|
}
|
||||||
@ -229,12 +236,11 @@ static void cleanup(int code)
|
|||||||
|
|
||||||
static void get_initial_data(const char* vcsa_name)
|
static void get_initial_data(const char* vcsa_name)
|
||||||
{
|
{
|
||||||
int size;
|
|
||||||
G.vcsa_fd = xopen(vcsa_name, O_RDONLY);
|
G.vcsa_fd = xopen(vcsa_name, O_RDONLY);
|
||||||
xread(G.vcsa_fd, &G.info, 4);
|
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.width = G.height = UINT_MAX;
|
||||||
G.data = xzalloc(2 * size);
|
G.data = xzalloc(2 * G.size);
|
||||||
screen_read_close();
|
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)
|
int conspy_main(int argc UNUSED_PARAM, char **argv)
|
||||||
{
|
{
|
||||||
char vcsa_name[sizeof("/dev/vcsa") + 2];
|
char vcsa_name[sizeof("/dev/vcsaNN")];
|
||||||
char tty_name[sizeof("/dev/tty") + 2];
|
char tty_name[sizeof("/dev/ttyNN")];
|
||||||
#define keybuf bb_common_bufsiz1
|
#define keybuf bb_common_bufsiz1
|
||||||
struct termios termbuf;
|
struct termios termbuf;
|
||||||
unsigned opts;
|
unsigned opts;
|
||||||
@ -339,7 +345,7 @@ int conspy_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
tcgetattr(G.kbd_fd, &G.term_orig);
|
tcgetattr(G.kbd_fd, &G.term_orig);
|
||||||
termbuf = G.term_orig;
|
termbuf = G.term_orig;
|
||||||
termbuf.c_iflag &= ~(BRKINT|INLCR|ICRNL|IXON|IXOFF|IUCLC|IXANY|IMAXBEL);
|
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_lflag &= ~(ISIG|ICANON|ECHO);
|
||||||
termbuf.c_cc[VMIN] = 1;
|
termbuf.c_cc[VMIN] = 1;
|
||||||
termbuf.c_cc[VTIME] = 0;
|
termbuf.c_cc[VTIME] = 0;
|
||||||
@ -448,7 +454,8 @@ int conspy_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|
|
||||||
// Do exit processing
|
// Do exit processing
|
||||||
for (i = 0; i < bytes_read; i++) {
|
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)
|
else if (++G.escape_count >= 3)
|
||||||
cleanup(0);
|
cleanup(0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user