diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-23 12:22:17 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-23 12:22:17 +0000 |
commit | d553faf5a53cf9d72e16fc789451a92a797f1b70 (patch) | |
tree | 41ea8707fd72529ccecfa0c1346d8c6d12b30d6d | |
parent | a7259b64e84cd669ae8be253d8621c7db48de4d2 (diff) | |
download | busybox-w32-d553faf5a53cf9d72e16fc789451a92a797f1b70.tar.gz busybox-w32-d553faf5a53cf9d72e16fc789451a92a797f1b70.tar.bz2 busybox-w32-d553faf5a53cf9d72e16fc789451a92a797f1b70.zip |
less: small shrink
-rw-r--r-- | miscutils/less.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 246cc6e9b..f3be2cfbf 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -172,12 +172,9 @@ static void set_tty_cooked(void) | |||
172 | /* Exit the program gracefully */ | 172 | /* Exit the program gracefully */ |
173 | static void less_exit(int code) | 173 | static void less_exit(int code) |
174 | { | 174 | { |
175 | /* TODO: We really should save the terminal state when we start, | ||
176 | * and restore it when we exit. Less does this with the | ||
177 | * "ti" and "te" termcap commands; can this be done with | ||
178 | * only termios.h? */ | ||
179 | bb_putchar('\n'); | 175 | bb_putchar('\n'); |
180 | fflush_stdout_and_exit(code); | 176 | set_tty_cooked(); |
177 | exit(code); /* TODO: "suicide mode" for code == -signal */ | ||
181 | } | 178 | } |
182 | 179 | ||
183 | /* Move the cursor to a position (x,y), where (0,0) is the | 180 | /* Move the cursor to a position (x,y), where (0,0) is the |
@@ -754,6 +751,7 @@ static char* less_gets(int sz) | |||
754 | less_gets_pos = sz + i; | 751 | less_gets_pos = sz + i; |
755 | getch_nowait(&c, 1); | 752 | getch_nowait(&c, 1); |
756 | if (c == 0x0d) { | 753 | if (c == 0x0d) { |
754 | result[i] = '\0'; | ||
757 | less_gets_pos = -1; | 755 | less_gets_pos = -1; |
758 | return result; | 756 | return result; |
759 | } | 757 | } |
@@ -762,7 +760,6 @@ static char* less_gets(int sz) | |||
762 | if (c == 8 && i) { | 760 | if (c == 8 && i) { |
763 | printf("\x8 \x8"); | 761 | printf("\x8 \x8"); |
764 | i--; | 762 | i--; |
765 | result[i] = '\0'; | ||
766 | } | 763 | } |
767 | if (c < ' ') | 764 | if (c < ' ') |
768 | continue; | 765 | continue; |
@@ -771,7 +768,6 @@ static char* less_gets(int sz) | |||
771 | bb_putchar(c); | 768 | bb_putchar(c); |
772 | result[i++] = c; | 769 | result[i++] = c; |
773 | result = xrealloc(result, i+1); | 770 | result = xrealloc(result, i+1); |
774 | result[i] = '\0'; | ||
775 | } | 771 | } |
776 | } | 772 | } |
777 | 773 | ||
@@ -1334,8 +1330,7 @@ static void keypress_process(int keypress) | |||
1334 | 1330 | ||
1335 | static void sig_catcher(int sig ATTRIBUTE_UNUSED) | 1331 | static void sig_catcher(int sig ATTRIBUTE_UNUSED) |
1336 | { | 1332 | { |
1337 | set_tty_cooked(); | 1333 | less_exit(1) /* TODO: "suicide mode" for code == -signal */ |
1338 | exit(1); | ||
1339 | } | 1334 | } |
1340 | 1335 | ||
1341 | int less_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 1336 | int less_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
@@ -1382,8 +1377,6 @@ int less_main(int argc, char **argv) | |||
1382 | if (option_mask32 & FLAG_TILDE) | 1377 | if (option_mask32 & FLAG_TILDE) |
1383 | empty_line_marker = ""; | 1378 | empty_line_marker = ""; |
1384 | 1379 | ||
1385 | bb_signals(BB_SIGS_FATAL, sig_catcher); | ||
1386 | |||
1387 | tcgetattr(kbd_fd, &term_orig); | 1380 | tcgetattr(kbd_fd, &term_orig); |
1388 | term_less = term_orig; | 1381 | term_less = term_orig; |
1389 | term_less.c_lflag &= ~(ICANON | ECHO); | 1382 | term_less.c_lflag &= ~(ICANON | ECHO); |
@@ -1392,6 +1385,9 @@ int less_main(int argc, char **argv) | |||
1392 | term_less.c_cc[VMIN] = 1; | 1385 | term_less.c_cc[VMIN] = 1; |
1393 | term_less.c_cc[VTIME] = 0; | 1386 | term_less.c_cc[VTIME] = 0; |
1394 | 1387 | ||
1388 | /* We want to restore term_orig on exit */ | ||
1389 | bb_signals(BB_SIGS_FATAL, sig_catcher); | ||
1390 | |||
1395 | reinitialize(); | 1391 | reinitialize(); |
1396 | while (1) { | 1392 | while (1) { |
1397 | keypress = less_getch(-1); /* -1: do not position cursor */ | 1393 | keypress = less_getch(-1); /* -1: do not position cursor */ |