From 5f6aaf39cff31f5f679fe07449a9e363dd474216 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sat, 25 Oct 2008 23:27:29 +0000 Subject: less: reuse former vi's key reading code. Improve SIGWINCH handling. function old new delta less_main 2056 2097 +41 getch_nowait 248 273 +25 read_key 310 321 +11 static.esccmds 61 69 +8 count_lines 72 74 +2 less_gets 166 142 -24 less_getch 172 43 -129 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 6/5 up/down: 91/-170) Total: -79 bytes text data bss dec hex filename --- libbb/read_key.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'libbb/read_key.c') diff --git a/libbb/read_key.c b/libbb/read_key.c index 598bd94f5..614e2f9e0 100644 --- a/libbb/read_key.c +++ b/libbb/read_key.c @@ -33,14 +33,16 @@ int FAST_FUNC read_key(int fd, smalluint *nbuffered, char *buffer) '[','B' |0x80,KEYCODE_DOWN , '[','C' |0x80,KEYCODE_RIGHT , '[','D' |0x80,KEYCODE_LEFT , - '[','H' |0x80,KEYCODE_HOME , - '[','F' |0x80,KEYCODE_END , - '[','1','~' |0x80,KEYCODE_HOME , + '[','H' |0x80,KEYCODE_HOME , /* xterm */ + '[','F' |0x80,KEYCODE_END , /* xterm */ + '[','1','~' |0x80,KEYCODE_HOME , /* vt100? linux vt? or what? */ '[','2','~' |0x80,KEYCODE_INSERT , '[','3','~' |0x80,KEYCODE_DELETE , - '[','4','~' |0x80,KEYCODE_END , + '[','4','~' |0x80,KEYCODE_END , /* vt100? linux vt? or what? */ '[','5','~' |0x80,KEYCODE_PAGEUP , '[','6','~' |0x80,KEYCODE_PAGEDOWN, + '[','7','~' |0x80,KEYCODE_HOME , /* vt100? linux vt? or what? */ + '[','8','~' |0x80,KEYCODE_END , /* vt100? linux vt? or what? */ #if 0 '[','1','1','~'|0x80,KEYCODE_FUN1 , '[','1','2','~'|0x80,KEYCODE_FUN2 , @@ -58,7 +60,9 @@ int FAST_FUNC read_key(int fd, smalluint *nbuffered, char *buffer) 0 }; - n = *nbuffered; + n = 0; + if (nbuffered) + n = *nbuffered; if (n == 0) { /* If no data, block waiting for input. If we read more * than the minimal ESC sequence size, the "n=0" below @@ -141,6 +145,7 @@ int FAST_FUNC read_key(int fd, smalluint *nbuffered, char *buffer) * by now. */ ret: - *nbuffered = n; + if (nbuffered) + *nbuffered = n; return c; } -- cgit v1.2.3