fix errors in detecting non-modified areas

function                                             old     new   delta
screen_char                                          100     102      +2
cleanup                                               84      86      +2
screen_dump                                          215     210      -5
conspy_main                                         1503    1491     -12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2010-06-21 04:00:16 +02:00
parent a8b594fda7
commit 05a550b48a

View File

@ -62,7 +62,6 @@ struct globals {
int kbd_fd; int kbd_fd;
unsigned width; unsigned width;
unsigned height; unsigned height;
char mask;
char last_attr; char last_attr;
struct screen_info info; struct screen_info info;
struct termios term_orig; struct termios term_orig;
@ -73,6 +72,17 @@ struct globals {
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
} while (0) } while (0)
enum {
FLAG_v, // view only
FLAG_c, // create device if need
FLAG_s, // session
FLAG_n, // no colors
FLAG_d, // dump screen
FLAG_f, // follow cursor
};
#define FLAG(x) (1 << FLAG_##x)
#define BW (option_mask32 & FLAG(n))
static void screen_read_close(int fd, char *data) static void screen_read_close(int fd, char *data)
{ {
unsigned i, j; unsigned i, j;
@ -95,7 +105,7 @@ static void screen_read_close(int fd, char *data)
static void screen_char(char *data) static void screen_char(char *data)
{ {
if (((G.last_attr - ATTR(data)) & G.mask) != 0) { if (!BW && G.last_attr != ATTR(data)) {
// BLGCRMOW // BLGCRMOW
static const char color[8] = "04261537"; static const char color[8] = "04261537";
@ -123,29 +133,32 @@ static void gotoxy(int row, int line)
static void screen_dump(char *data) static void screen_dump(char *data)
{ {
int space, linefeed, line, row; int linefeed_cnt;
int line, row;
int linecnt = G.info.lines - G.y; int linecnt = G.info.lines - G.y;
data += 2 * G.y * G.info.rows; data += 2 * G.y * G.info.rows;
for (linefeed = line = 0; line < linecnt && line < G.height; line++) { linefeed_cnt = 0;
for (space = row = 0; row < G.info.rows; row++, NEXT(data)) { for (line = 0; line < linecnt && line < G.height; line++) {
int space_cnt = 0;
for (row = 0; row < G.info.rows; row++, NEXT(data)) {
unsigned tty_row = row - G.x; // if will catch row < G.x too unsigned tty_row = row - G.x; // if will catch row < G.x too
if (tty_row >= G.width) if (tty_row >= G.width)
continue; continue;
space++; space_cnt++;
if (((G.last_attr - ATTR(data)) & G.mask) && CHAR(data) == ' ') if (BW && (CHAR(data) | ' ') == ' ')
continue; continue;
while (linefeed != 0) { while (linefeed_cnt != 0) {
bb_putchar('\r'); bb_putchar('\r');
bb_putchar('\n'); bb_putchar('\n');
linefeed--; linefeed_cnt--;
} }
while (--space) while (--space_cnt)
bb_putchar(' '); bb_putchar(' ');
screen_char(data); screen_char(data);
} }
linefeed++; linefeed_cnt++;
} }
} }
@ -173,7 +186,7 @@ static void cleanup(int code)
close(G.kbd_fd); close(G.kbd_fd);
} }
// Reset attributes // Reset attributes
if (G.mask != 0) if (!BW)
printf("\033[0m"); printf("\033[0m");
bb_putchar('\n'); bb_putchar('\n');
if (code > 1) if (code > 1)
@ -234,16 +247,6 @@ static NOINLINE void start_shell_in_child(const char* tty_name)
} }
} }
enum {
FLAG_v, // view only
FLAG_c, // create device if need
FLAG_s, // session
FLAG_n, // no colors
FLAG_d, // dump screen
FLAG_f, // follow cursor
};
#define FLAG(x) (1 << FLAG_##x)
int conspy_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE; int conspy_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE;
int conspy_main(int argc UNUSED_PARAM, char **argv) int conspy_main(int argc UNUSED_PARAM, char **argv)
{ {
@ -284,8 +287,6 @@ int conspy_main(int argc UNUSED_PARAM, char **argv)
sprintf(vcsa_name + sizeof("/dev/vcsa")-1, "%u", ttynum); sprintf(vcsa_name + sizeof("/dev/vcsa")-1, "%u", ttynum);
} }
sprintf(tty_name, "%s%u", "/dev/tty", ttynum); sprintf(tty_name, "%s%u", "/dev/tty", ttynum);
if (!(opts & FLAG(n)))
G.mask = 0xff;
if (opts & FLAG(c)) { if (opts & FLAG(c)) {
if ((opts & (FLAG(s)|FLAG(v))) != FLAG(v)) if ((opts & (FLAG(s)|FLAG(v))) != FLAG(v))
create_cdev_if_doesnt_exist(tty_name, makedev(4, ttynum)); create_cdev_if_doesnt_exist(tty_name, makedev(4, ttynum));