diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-25 00:57:57 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-25 00:57:57 +0200 |
| commit | 51fa147c9bab41cc1f7bf5b2e3bbeddf0fdaf5ca (patch) | |
| tree | 20caa3f26c0a3858b36a345a33ad7865a399ec73 | |
| parent | eff6d593437afa91f7fb7c418e13dfb2ddb6886b (diff) | |
| download | busybox-w32-51fa147c9bab41cc1f7bf5b2e3bbeddf0fdaf5ca.tar.gz busybox-w32-51fa147c9bab41cc1f7bf5b2e3bbeddf0fdaf5ca.tar.bz2 busybox-w32-51fa147c9bab41cc1f7bf5b2e3bbeddf0fdaf5ca.zip | |
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>
| -rw-r--r-- | miscutils/conspy.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/miscutils/conspy.c b/miscutils/conspy.c index b443c9133..b5adce930 100644 --- a/miscutils/conspy.c +++ b/miscutils/conspy.c | |||
| @@ -9,9 +9,9 @@ | |||
| 9 | * | 9 | * |
| 10 | * Licensed under GPLv2 or later, see file License in this tarball for details. | 10 | * Licensed under GPLv2 or later, see file License in this tarball for details. |
| 11 | * | 11 | * |
| 12 | * example : conspy num shared access to console num | 12 | * example: conspy num shared access to console num |
| 13 | * or conspy -d num screenshot of console num | 13 | * or conspy -d num screenshot of console num |
| 14 | * or conspy -cs num poor man's GNU screen like | 14 | * or conspy -cs num poor man's GNU screen like |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | //applet:IF_CONSPY(APPLET(conspy, _BB_DIR_BIN, _BB_SUID_DROP)) | 17 | //applet:IF_CONSPY(APPLET(conspy, _BB_DIR_BIN, _BB_SUID_DROP)) |
| @@ -28,7 +28,7 @@ | |||
| 28 | //config: or conspy -cs num poor man's GNU screen like | 28 | //config: or conspy -cs num poor man's GNU screen like |
| 29 | 29 | ||
| 30 | //usage:#define conspy_trivial_usage | 30 | //usage:#define conspy_trivial_usage |
| 31 | //usage: "[-vcsndf] [-x ROW] [-y LINE] [CONSOLE_NO]" | 31 | //usage: "[-vcsndf] [-x ROW] [-y LINE] [CONSOLE_NO]" |
| 32 | //usage:#define conspy_full_usage "\n\n" | 32 | //usage:#define conspy_full_usage "\n\n" |
| 33 | //usage: "A text-mode VNC like program for Linux virtual consoles." | 33 | //usage: "A text-mode VNC like program for Linux virtual consoles." |
| 34 | //usage: "\nTo exit, quickly press ESC 3 times." | 34 | //usage: "\nTo exit, quickly press ESC 3 times." |
| @@ -50,10 +50,10 @@ struct screen_info { | |||
| 50 | unsigned char lines, rows, cursor_x, cursor_y; | 50 | unsigned char lines, rows, cursor_x, cursor_y; |
| 51 | }; | 51 | }; |
| 52 | 52 | ||
| 53 | #define CHAR(x) ((x)[0]) | 53 | #define CHAR(x) ((uint8_t)((x)[0])) |
| 54 | #define ATTR(x) ((x)[1]) | 54 | #define ATTR(x) ((uint8_t)((x)[1])) |
| 55 | #define NEXT(x) ((x)+=2) | 55 | #define NEXT(x) ((x)+=2) |
| 56 | #define DATA(x) (* (short *) (x)) | 56 | #define DATA(x) (*(uint16_t*)(x)) |
| 57 | 57 | ||
| 58 | struct globals { | 58 | struct globals { |
| 59 | char* data; | 59 | char* data; |
| @@ -102,7 +102,7 @@ static void screen_read_close(void) | |||
| 102 | unsigned y = i - G.y; // if will catch i < G.y too | 102 | unsigned y = i - G.y; // if will catch i < G.y too |
| 103 | 103 | ||
| 104 | if (CHAR(data) < ' ') | 104 | if (CHAR(data) < ' ') |
| 105 | CHAR(data) = ' '; | 105 | *data = ' '; // CHAR(data) = ' '; |
| 106 | if (y >= G.height || x >= G.width) | 106 | if (y >= G.height || x >= G.width) |
| 107 | DATA(data) = 0; | 107 | DATA(data) = 0; |
| 108 | } | 108 | } |
| @@ -151,8 +151,15 @@ static void screen_char(char *data) | |||
| 151 | putchar(CHAR(data)); | 151 | putchar(CHAR(data)); |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | #define clrscr() printf("\033[1;1H" "\033[0J") | 154 | static void clrscr(void) |
| 155 | #define curoff() printf("\033[?25l") | 155 | { |
| 156 | printf("\033[1;1H" "\033[0J"); | ||
| 157 | } | ||
| 158 | |||
| 159 | static void curoff(void) | ||
| 160 | { | ||
| 161 | printf("\033[?25l"); | ||
| 162 | } | ||
| 156 | 163 | ||
| 157 | static void curon(void) | 164 | static void curon(void) |
| 158 | { | 165 | { |
| @@ -180,10 +187,10 @@ static void screen_dump(void) | |||
| 180 | if (tty_row >= G.width) | 187 | if (tty_row >= G.width) |
| 181 | continue; | 188 | continue; |
| 182 | space_cnt++; | 189 | space_cnt++; |
| 183 | if (BW && (CHAR(data) | ' ') == ' ') | 190 | if (BW && CHAR(data) == ' ') |
| 184 | continue; | 191 | continue; |
| 185 | while (linefeed_cnt != 0) { | 192 | while (linefeed_cnt != 0) { |
| 186 | bb_putchar('\r'); | 193 | //bb_putchar('\r'); - tty driver does it for us |
| 187 | bb_putchar('\n'); | 194 | bb_putchar('\n'); |
| 188 | linefeed_cnt--; | 195 | linefeed_cnt--; |
| 189 | } | 196 | } |
| @@ -229,12 +236,11 @@ static void cleanup(int code) | |||
| 229 | 236 | ||
| 230 | static void get_initial_data(const char* vcsa_name) | 237 | static void get_initial_data(const char* vcsa_name) |
| 231 | { | 238 | { |
| 232 | int size; | ||
| 233 | G.vcsa_fd = xopen(vcsa_name, O_RDONLY); | 239 | G.vcsa_fd = xopen(vcsa_name, O_RDONLY); |
| 234 | xread(G.vcsa_fd, &G.info, 4); | 240 | xread(G.vcsa_fd, &G.info, 4); |
| 235 | G.size = size = G.info.rows * G.info.lines * 2; | 241 | G.size = G.info.rows * G.info.lines * 2; |
| 236 | G.width = G.height = UINT_MAX; | 242 | G.width = G.height = UINT_MAX; |
| 237 | G.data = xzalloc(2 * size); | 243 | G.data = xzalloc(2 * G.size); |
| 238 | screen_read_close(); | 244 | screen_read_close(); |
| 239 | } | 245 | } |
| 240 | 246 | ||
| @@ -280,11 +286,11 @@ static NOINLINE void start_shell_in_child(const char* tty_name) | |||
| 280 | } | 286 | } |
| 281 | } | 287 | } |
| 282 | 288 | ||
| 283 | int conspy_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE; | 289 | int conspy_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 284 | int conspy_main(int argc UNUSED_PARAM, char **argv) | 290 | int conspy_main(int argc UNUSED_PARAM, char **argv) |
| 285 | { | 291 | { |
| 286 | char vcsa_name[sizeof("/dev/vcsa") + 2]; | 292 | char vcsa_name[sizeof("/dev/vcsaNN")]; |
| 287 | char tty_name[sizeof("/dev/tty") + 2]; | 293 | char tty_name[sizeof("/dev/ttyNN")]; |
| 288 | #define keybuf bb_common_bufsiz1 | 294 | #define keybuf bb_common_bufsiz1 |
| 289 | struct termios termbuf; | 295 | struct termios termbuf; |
| 290 | unsigned opts; | 296 | unsigned opts; |
| @@ -339,7 +345,7 @@ int conspy_main(int argc UNUSED_PARAM, char **argv) | |||
| 339 | tcgetattr(G.kbd_fd, &G.term_orig); | 345 | tcgetattr(G.kbd_fd, &G.term_orig); |
| 340 | termbuf = G.term_orig; | 346 | termbuf = G.term_orig; |
| 341 | termbuf.c_iflag &= ~(BRKINT|INLCR|ICRNL|IXON|IXOFF|IUCLC|IXANY|IMAXBEL); | 347 | termbuf.c_iflag &= ~(BRKINT|INLCR|ICRNL|IXON|IXOFF|IUCLC|IXANY|IMAXBEL); |
| 342 | termbuf.c_oflag &= ~(OPOST); | 348 | //termbuf.c_oflag &= ~(OPOST); - no, we still want \n -> \r\n |
| 343 | termbuf.c_lflag &= ~(ISIG|ICANON|ECHO); | 349 | termbuf.c_lflag &= ~(ISIG|ICANON|ECHO); |
| 344 | termbuf.c_cc[VMIN] = 1; | 350 | termbuf.c_cc[VMIN] = 1; |
| 345 | termbuf.c_cc[VTIME] = 0; | 351 | termbuf.c_cc[VTIME] = 0; |
| @@ -354,7 +360,7 @@ int conspy_main(int argc UNUSED_PARAM, char **argv) | |||
| 354 | old = G.data + G.current; | 360 | old = G.data + G.current; |
| 355 | G.current = G.size - G.current; | 361 | G.current = G.size - G.current; |
| 356 | data = G.data + G.current; | 362 | data = G.data + G.current; |
| 357 | 363 | ||
| 358 | // Close & re-open vcsa in case they have | 364 | // Close & re-open vcsa in case they have |
| 359 | // swapped virtual consoles | 365 | // swapped virtual consoles |
| 360 | G.vcsa_fd = xopen(vcsa_name, O_RDONLY); | 366 | G.vcsa_fd = xopen(vcsa_name, O_RDONLY); |
| @@ -448,7 +454,8 @@ int conspy_main(int argc UNUSED_PARAM, char **argv) | |||
| 448 | 454 | ||
| 449 | // Do exit processing | 455 | // Do exit processing |
| 450 | for (i = 0; i < bytes_read; i++) { | 456 | for (i = 0; i < bytes_read; i++) { |
| 451 | if (k[i] != '\033') G.escape_count = 0; | 457 | if (k[i] != '\033') |
| 458 | G.escape_count = 0; | ||
| 452 | else if (++G.escape_count >= 3) | 459 | else if (++G.escape_count >= 3) |
| 453 | cleanup(0); | 460 | cleanup(0); |
| 454 | } | 461 | } |
