svn commit: trunk/busybox/miscutils

vda at busybox.net vda at busybox.net
Sun Feb 24 19:18:23 UTC 2008


Author: vda
Date: 2008-02-24 11:18:18 -0800 (Sun, 24 Feb 2008)
New Revision: 21099

Log:
less: shrink



Modified:
   trunk/busybox/miscutils/less.c


Changeset:
Modified: trunk/busybox/miscutils/less.c
===================================================================
--- trunk/busybox/miscutils/less.c	2008-02-24 18:44:20 UTC (rev 21098)
+++ trunk/busybox/miscutils/less.c	2008-02-24 19:18:18 UTC (rev 21099)
@@ -1175,41 +1175,40 @@
 static char opp_bracket(char bracket)
 {
 	switch (bracket) {
-	case '{': case '[':
-		return bracket + 2;
-	case '(':
-		return ')';
-	case '}': case ']':
-		return bracket - 2;
-	case ')':
-		return '(';
-	}
-	return 0;
+		case '{': case '[': /* '}' == '{' + 2. Same for '[' */
+			bracket++;
+		case '(':           /* ')' == '(' + 1 */
+			bracket++;
+			break;
+		case '}': case ']':
+			bracket--;
+		case ')':
+			bracket--;
+			break;
+	};
+	return bracket;
 }
 
 static void match_right_bracket(char bracket)
 {
-	int bracket_line = -1;
 	int i;
 
 	if (strchr(flines[cur_fline], bracket) == NULL) {
 		print_statusline("No bracket in top line");
 		return;
 	}
+	bracket = opp_bracket(bracket);
 	for (i = cur_fline + 1; i < max_fline; i++) {
-		if (strchr(flines[i], opp_bracket(bracket)) != NULL) {
-			bracket_line = i;
-			break;
+		if (strchr(flines[i], bracket) != NULL) {
+			buffer_line(i);
+			return;
 		}
 	}
-	if (bracket_line == -1)
-		print_statusline("No matching bracket found");
-	buffer_line(bracket_line - max_displayed_line);
+	print_statusline("No matching bracket found");
 }
 
 static void match_left_bracket(char bracket)
 {
-	int bracket_line = -1;
 	int i;
 
 	if (strchr(flines[cur_fline + max_displayed_line], bracket) == NULL) {
@@ -1217,15 +1216,14 @@
 		return;
 	}
 
+	bracket = opp_bracket(bracket);
 	for (i = cur_fline + max_displayed_line; i >= 0; i--) {
-		if (strchr(flines[i], opp_bracket(bracket)) != NULL) {
-			bracket_line = i;
-			break;
+		if (strchr(flines[i], bracket) != NULL) {
+			buffer_line(i);
+			return;
 		}
 	}
-	if (bracket_line == -1)
-		print_statusline("No matching bracket found");
-	buffer_line(bracket_line);
+	print_statusline("No matching bracket found");
 }
 #endif  /* FEATURE_LESS_BRACKETS */
 




More information about the busybox-cvs mailing list