diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-21 04:00:16 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-21 04:00:16 +0200 |
commit | 05a550b48abe8490264cacf14b68534c2f8ac3ed (patch) | |
tree | 9613d48ed2d301ed2b80ff5f942a95557b7cadc9 | |
parent | a8b594fda7cbfcc2aadf9779ee40b264eeec86b2 (diff) | |
download | busybox-w32-05a550b48abe8490264cacf14b68534c2f8ac3ed.tar.gz busybox-w32-05a550b48abe8490264cacf14b68534c2f8ac3ed.tar.bz2 busybox-w32-05a550b48abe8490264cacf14b68534c2f8ac3ed.zip |
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>
-rw-r--r-- | miscutils/conspy.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/miscutils/conspy.c b/miscutils/conspy.c index 7ba7959a2..ae471a3fa 100644 --- a/miscutils/conspy.c +++ b/miscutils/conspy.c | |||
@@ -62,7 +62,6 @@ struct globals { | |||
62 | int kbd_fd; | 62 | int kbd_fd; |
63 | unsigned width; | 63 | unsigned width; |
64 | unsigned height; | 64 | unsigned height; |
65 | char mask; | ||
66 | char last_attr; | 65 | char last_attr; |
67 | struct screen_info info; | 66 | struct screen_info info; |
68 | struct termios term_orig; | 67 | struct termios term_orig; |
@@ -73,6 +72,17 @@ struct globals { | |||
73 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ | 72 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
74 | } while (0) | 73 | } while (0) |
75 | 74 | ||
75 | enum { | ||
76 | FLAG_v, // view only | ||
77 | FLAG_c, // create device if need | ||
78 | FLAG_s, // session | ||
79 | FLAG_n, // no colors | ||
80 | FLAG_d, // dump screen | ||
81 | FLAG_f, // follow cursor | ||
82 | }; | ||
83 | #define FLAG(x) (1 << FLAG_##x) | ||
84 | #define BW (option_mask32 & FLAG(n)) | ||
85 | |||
76 | static void screen_read_close(int fd, char *data) | 86 | static void screen_read_close(int fd, char *data) |
77 | { | 87 | { |
78 | unsigned i, j; | 88 | unsigned i, j; |
@@ -95,7 +105,7 @@ static void screen_read_close(int fd, char *data) | |||
95 | 105 | ||
96 | static void screen_char(char *data) | 106 | static void screen_char(char *data) |
97 | { | 107 | { |
98 | if (((G.last_attr - ATTR(data)) & G.mask) != 0) { | 108 | if (!BW && G.last_attr != ATTR(data)) { |
99 | // BLGCRMOW | 109 | // BLGCRMOW |
100 | static const char color[8] = "04261537"; | 110 | static const char color[8] = "04261537"; |
101 | 111 | ||
@@ -123,29 +133,32 @@ static void gotoxy(int row, int line) | |||
123 | 133 | ||
124 | static void screen_dump(char *data) | 134 | static void screen_dump(char *data) |
125 | { | 135 | { |
126 | int space, linefeed, line, row; | 136 | int linefeed_cnt; |
137 | int line, row; | ||
127 | int linecnt = G.info.lines - G.y; | 138 | int linecnt = G.info.lines - G.y; |
128 | 139 | ||
129 | data += 2 * G.y * G.info.rows; | 140 | data += 2 * G.y * G.info.rows; |
130 | for (linefeed = line = 0; line < linecnt && line < G.height; line++) { | 141 | linefeed_cnt = 0; |
131 | for (space = row = 0; row < G.info.rows; row++, NEXT(data)) { | 142 | for (line = 0; line < linecnt && line < G.height; line++) { |
143 | int space_cnt = 0; | ||
144 | for (row = 0; row < G.info.rows; row++, NEXT(data)) { | ||
132 | unsigned tty_row = row - G.x; // if will catch row < G.x too | 145 | unsigned tty_row = row - G.x; // if will catch row < G.x too |
133 | 146 | ||
134 | if (tty_row >= G.width) | 147 | if (tty_row >= G.width) |
135 | continue; | 148 | continue; |
136 | space++; | 149 | space_cnt++; |
137 | if (((G.last_attr - ATTR(data)) & G.mask) && CHAR(data) == ' ') | 150 | if (BW && (CHAR(data) | ' ') == ' ') |
138 | continue; | 151 | continue; |
139 | while (linefeed != 0) { | 152 | while (linefeed_cnt != 0) { |
140 | bb_putchar('\r'); | 153 | bb_putchar('\r'); |
141 | bb_putchar('\n'); | 154 | bb_putchar('\n'); |
142 | linefeed--; | 155 | linefeed_cnt--; |
143 | } | 156 | } |
144 | while (--space) | 157 | while (--space_cnt) |
145 | bb_putchar(' '); | 158 | bb_putchar(' '); |
146 | screen_char(data); | 159 | screen_char(data); |
147 | } | 160 | } |
148 | linefeed++; | 161 | linefeed_cnt++; |
149 | } | 162 | } |
150 | } | 163 | } |
151 | 164 | ||
@@ -173,7 +186,7 @@ static void cleanup(int code) | |||
173 | close(G.kbd_fd); | 186 | close(G.kbd_fd); |
174 | } | 187 | } |
175 | // Reset attributes | 188 | // Reset attributes |
176 | if (G.mask != 0) | 189 | if (!BW) |
177 | printf("\033[0m"); | 190 | printf("\033[0m"); |
178 | bb_putchar('\n'); | 191 | bb_putchar('\n'); |
179 | if (code > 1) | 192 | if (code > 1) |
@@ -234,16 +247,6 @@ static NOINLINE void start_shell_in_child(const char* tty_name) | |||
234 | } | 247 | } |
235 | } | 248 | } |
236 | 249 | ||
237 | enum { | ||
238 | FLAG_v, // view only | ||
239 | FLAG_c, // create device if need | ||
240 | FLAG_s, // session | ||
241 | FLAG_n, // no colors | ||
242 | FLAG_d, // dump screen | ||
243 | FLAG_f, // follow cursor | ||
244 | }; | ||
245 | #define FLAG(x) (1 << FLAG_##x) | ||
246 | |||
247 | int conspy_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE; | 250 | int conspy_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE; |
248 | int conspy_main(int argc UNUSED_PARAM, char **argv) | 251 | int conspy_main(int argc UNUSED_PARAM, char **argv) |
249 | { | 252 | { |
@@ -284,8 +287,6 @@ int conspy_main(int argc UNUSED_PARAM, char **argv) | |||
284 | sprintf(vcsa_name + sizeof("/dev/vcsa")-1, "%u", ttynum); | 287 | sprintf(vcsa_name + sizeof("/dev/vcsa")-1, "%u", ttynum); |
285 | } | 288 | } |
286 | sprintf(tty_name, "%s%u", "/dev/tty", ttynum); | 289 | sprintf(tty_name, "%s%u", "/dev/tty", ttynum); |
287 | if (!(opts & FLAG(n))) | ||
288 | G.mask = 0xff; | ||
289 | if (opts & FLAG(c)) { | 290 | if (opts & FLAG(c)) { |
290 | if ((opts & (FLAG(s)|FLAG(v))) != FLAG(v)) | 291 | if ((opts & (FLAG(s)|FLAG(v))) != FLAG(v)) |
291 | create_cdev_if_doesnt_exist(tty_name, makedev(4, ttynum)); | 292 | create_cdev_if_doesnt_exist(tty_name, makedev(4, ttynum)); |