svn commit: trunk/busybox/miscutils

vda at busybox.net vda at busybox.net
Sat Feb 23 12:22:17 UTC 2008


Author: vda
Date: 2008-02-23 04:22:17 -0800 (Sat, 23 Feb 2008)
New Revision: 21094

Log:
less: small shrink



Modified:
   trunk/busybox/miscutils/less.c


Changeset:
Modified: trunk/busybox/miscutils/less.c
===================================================================
--- trunk/busybox/miscutils/less.c	2008-02-23 12:08:36 UTC (rev 21093)
+++ trunk/busybox/miscutils/less.c	2008-02-23 12:22:17 UTC (rev 21094)
@@ -172,12 +172,9 @@
 /* Exit the program gracefully */
 static void less_exit(int code)
 {
-	/* TODO: We really should save the terminal state when we start,
-	 * and restore it when we exit. Less does this with the
-	 * "ti" and "te" termcap commands; can this be done with
-	 * only termios.h? */
 	bb_putchar('\n');
-	fflush_stdout_and_exit(code);
+	set_tty_cooked();
+	exit(code); /* TODO: "suicide mode" for code == -signal */
 }
 
 /* Move the cursor to a position (x,y), where (0,0) is the
@@ -754,6 +751,7 @@
 		less_gets_pos = sz + i;
 		getch_nowait(&c, 1);
 		if (c == 0x0d) {
+			result[i] = '\0';
 			less_gets_pos = -1;
 			return result;
 		}
@@ -762,7 +760,6 @@
 		if (c == 8 && i) {
 			printf("\x8 \x8");
 			i--;
-			result[i] = '\0';
 		}
 		if (c < ' ')
 			continue;
@@ -771,7 +768,6 @@
 		bb_putchar(c);
 		result[i++] = c;
 		result = xrealloc(result, i+1);
-		result[i] = '\0';
 	}
 }
 
@@ -1334,8 +1330,7 @@
 
 static void sig_catcher(int sig ATTRIBUTE_UNUSED)
 {
-	set_tty_cooked();
-	exit(1);
+	less_exit(1) /* TODO: "suicide mode" for code == -signal */
 }
 
 int less_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -1382,8 +1377,6 @@
 	if (option_mask32 & FLAG_TILDE)
 		empty_line_marker = "";
 
-	bb_signals(BB_SIGS_FATAL, sig_catcher);
-
 	tcgetattr(kbd_fd, &term_orig);
 	term_less = term_orig;
 	term_less.c_lflag &= ~(ICANON | ECHO);
@@ -1392,6 +1385,9 @@
 	term_less.c_cc[VMIN] = 1;
 	term_less.c_cc[VTIME] = 0;
 
+	/* We want to restore term_orig on exit */
+	bb_signals(BB_SIGS_FATAL, sig_catcher);
+
 	reinitialize();
 	while (1) {
 		keypress = less_getch(-1); /* -1: do not position cursor */




More information about the busybox-cvs mailing list