aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorPascal Bellard <pascal.bellard@ads-lu.com>2010-06-28 15:50:22 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-06-28 15:51:01 +0200
commitff37799dfe0e6e8fb9b971a2aeb4076d8a3784ec (patch)
tree61705ab230d6ba9b0d625f6087c39bc2dea0a679 /miscutils
parent7d1201c5d7014365fb7e3d9da58f5e3fe0a1edc8 (diff)
downloadbusybox-w32-ff37799dfe0e6e8fb9b971a2aeb4076d8a3784ec.tar.gz
busybox-w32-ff37799dfe0e6e8fb9b971a2aeb4076d8a3784ec.tar.bz2
busybox-w32-ff37799dfe0e6e8fb9b971a2aeb4076d8a3784ec.zip
conspy: code shrink
function old new delta conspy_main 1446 1444 -2 screen_read_close 114 108 -6 screen_char 299 293 -6 Signed-off-by: Pascal Bellard <pascal.bellard@ads-lu.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/conspy.c123
1 files changed, 63 insertions, 60 deletions
diff --git a/miscutils/conspy.c b/miscutils/conspy.c
index 11105f0b8..6f2f0255c 100644
--- a/miscutils/conspy.c
+++ b/miscutils/conspy.c
@@ -56,31 +56,33 @@ struct globals {
56 int size; 56 int size;
57 int x, y; 57 int x, y;
58 int kbd_fd; 58 int kbd_fd;
59 unsigned width; 59 int vcsa_fd;
60 unsigned height;
61 unsigned col;
62 unsigned line;
63 int ioerror_count; 60 int ioerror_count;
64 int key_count; 61 int key_count;
65 int escape_count; 62 int escape_count;
66 int nokeys; 63 int nokeys;
67 int current; 64 int current;
68 int vcsa_fd; 65 // cached local tty parameters
69 uint16_t last_attr; 66 unsigned width;
70 uint8_t last_bold; 67 unsigned height;
71 uint8_t last_blink; 68 unsigned col;
72 uint8_t last_fg; 69 unsigned line;
73 uint8_t last_bg;
74 char attrbuf[sizeof("\033[0;1;5;30;40m")];
75 smallint curoff; 70 smallint curoff;
71 uint8_t last_attr;
72 uint8_t force_attr_change;
73 char attrbuf[sizeof("\033[0;1;5;30;40m")];
74 // remote console
76 struct screen_info remote; 75 struct screen_info remote;
76 // saved local tty terminfo
77 struct termios term_orig; 77 struct termios term_orig;
78}; 78};
79 79
80#define G (*ptr_to_globals) 80#define G (*ptr_to_globals)
81#define INIT_G() do { \ 81#define INIT_G() do { \
82 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 82 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
83 strcpy((char*)&G.last_attr, "\xff\xff\xff\xff\xff\xff" "\033["); \ 83 G.attrbuf[0] = '\033'; \
84 G.attrbuf[1] = '['; \
85 G.force_attr_change = 0xff; \
84} while (0) 86} while (0)
85 87
86enum { 88enum {
@@ -100,7 +102,6 @@ static void screen_read_close(void)
100 char *data = G.data + G.current; 102 char *data = G.data + G.current;
101 103
102 xread(G.vcsa_fd, data, G.size); 104 xread(G.vcsa_fd, data, G.size);
103 G.last_attr = 0;
104 for (i = 0; i < G.remote.lines; i++) { 105 for (i = 0; i < G.remote.lines; i++) {
105 for (j = 0; j < G.remote.cols; j++, NEXT(data)) { 106 for (j = 0; j < G.remote.cols; j++, NEXT(data)) {
106 unsigned x = j - G.x; // if will catch j < G.x too 107 unsigned x = j - G.x; // if will catch j < G.x too
@@ -117,9 +118,12 @@ static void screen_read_close(void)
117 118
118static void screen_char(char *data) 119static void screen_char(char *data)
119{ 120{
120 uint8_t attr = ATTR(data); 121 if (!BW) {
122 uint8_t attr = ATTR(data);
123 //uint8_t attr = ATTR(data) >> 1; // for framebuffer console
124 uint8_t attr_diff = (G.last_attr ^ attr) | G.force_attr_change;
121 125
122 if (!BW && G.last_attr != attr) { 126 if (attr_diff) {
123// Attribute layout for VGA compatible text videobuffer: 127// Attribute layout for VGA compatible text videobuffer:
124// blinking text 128// blinking text
125// |red bkgd 129// |red bkgd
@@ -143,51 +147,49 @@ static void screen_char(char *data)
143// green text 147// green text
144// blue text 148// blue text
145// text 8th bit 149// text 8th bit
146 // converting RGB color bit triad to BGR: 150 // converting RGB color bit triad to BGR:
147 static const char color[8] = "04261537"; 151 static const char color[8] = "04261537";
148 char *ptr; 152 const uint8_t fg_mask = 0x07, bold_mask = 0x08;
149 uint8_t fg, bold, bg, blink; 153 const uint8_t bg_mask = 0x70, blink_mask = 0x80;
150 154 char *ptr;
151 G.last_attr = attr; 155
152 156 ptr = G.attrbuf + 2; /* skip "ESC [" */
153 //attr >>= 1; // for framebuffer console 157
154 ptr = G.attrbuf + sizeof("\033[")-1; 158 // (G.last_attr & ~attr) has 1 only where
155 fg = (attr & 0x07); 159 // G.last_attr has 1 but attr has 0.
156 bold = (attr & 0x08); 160 // Here we check whether we have transition
157 bg = (attr & 0x70); 161 // bold->non-bold or blink->non-blink:
158 blink = (attr & 0x80); 162 if ((G.last_attr & ~attr) & (bold_mask | blink_mask)) {
159 if (G.last_bold > bold || G.last_blink > blink) { 163 *ptr++ = '0'; // "reset all attrs"
160 G.last_bold = G.last_blink = 0; 164 *ptr++ = ';';
161 G.last_bg = 0xff; 165 // must set fg & bg, maybe need to set bold or blink:
162 *ptr++ = '0'; 166 attr_diff = attr | ~(bold_mask | blink_mask);
163 *ptr++ = ';'; 167 }
164 } 168 G.force_attr_change = 0;
165 if (G.last_bold != bold) { 169 G.last_attr = attr;
166 G.last_bold = bold; 170 if (attr_diff & bold_mask) {
167 *ptr++ = '1'; 171 *ptr++ = '1';
168 *ptr++ = ';'; 172 *ptr++ = ';';
169 } 173 }
170 if (G.last_blink != blink) { 174 if (attr_diff & blink_mask) {
171 G.last_blink = blink; 175 *ptr++ = '5';
172 *ptr++ = '5'; 176 *ptr++ = ';';
173 *ptr++ = ';'; 177 }
174 } 178 if (attr_diff & fg_mask) {
175 if (G.last_fg != fg) { 179 *ptr++ = '3';
176 G.last_fg = fg; 180 *ptr++ = color[attr & fg_mask];
177 *ptr++ = '3'; 181 *ptr++ = ';';
178 *ptr++ = color[fg]; 182 }
179 *ptr++ = ';'; 183 if (attr_diff & bg_mask) {
180 } 184 *ptr++ = '4';
181 if (G.last_bg != bg) { 185 *ptr++ = color[(attr & bg_mask) >> 4];
182 G.last_bg = bg; 186 *ptr++ = ';';
183 *ptr++ = '4'; 187 }
184 *ptr++ = color[bg >> 4]; 188 if (ptr != G.attrbuf + 2) {
185 *ptr++ = ';'; 189 ptr[-1] = 'm';
186 } 190 *ptr = '\0';
187 if (ptr != G.attrbuf + sizeof("\033[")-1) { 191 fputs(G.attrbuf, stdout);
188 ptr[-1] = 'm'; 192 }
189 *ptr = '\0';
190 fputs(G.attrbuf, stdout);
191 } 193 }
192 } 194 }
193 putchar(CHAR(data)); 195 putchar(CHAR(data));
@@ -402,6 +404,7 @@ int conspy_main(int argc UNUSED_PARAM, char **argv)
402 termbuf.c_cc[VMIN] = 1; 404 termbuf.c_cc[VMIN] = 1;
403 termbuf.c_cc[VTIME] = 0; 405 termbuf.c_cc[VTIME] = 0;
404 tcsetattr(G.kbd_fd, TCSANOW, &termbuf); 406 tcsetattr(G.kbd_fd, TCSANOW, &termbuf);
407
405 poll_timeout_ms = 250; 408 poll_timeout_ms = 250;
406 while (1) { 409 while (1) {
407 struct pollfd pfd; 410 struct pollfd pfd;