summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaro Koskinen2018-04-15 01:24:24 +0300
committerDenys Vlasenko2018-04-15 13:13:34 +0200
commit36941503bd8e28a1fac13edffc3ffc84346b32c5 (patch)
treead3c482f9747aba9b62aca9802235c33d36f486c
parent4b6091f92c1c5abfe4597af4f3f6fa266ac46a5a (diff)
downloadbusybox-36941503bd8e28a1fac13edffc3ffc84346b32c5.zip
busybox-36941503bd8e28a1fac13edffc3ffc84346b32c5.tar.gz
less: implement -F
Implement -F option: Exit if entire file fits on first screen. function old new delta buffer_print 622 633 +11 less_main 2446 2449 +3 buffer_fill_and_print 169 172 +3 packed_usage 32258 32236 -22 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 17/-22) Total: -5 bytes Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/less.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/miscutils/less.c b/miscutils/less.c
index 51ef2a5..3bce932 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -121,11 +121,12 @@
//kbuild:lib-$(CONFIG_LESS) += less.o
//usage:#define less_trivial_usage
-//usage: "[-E" IF_FEATURE_LESS_REGEXP("I")IF_FEATURE_LESS_FLAGS("Mm")
+//usage: "[-EF" IF_FEATURE_LESS_REGEXP("I")IF_FEATURE_LESS_FLAGS("Mm")
//usage: "N" IF_FEATURE_LESS_TRUNCATE("S") IF_FEATURE_LESS_RAW("R") "h~] [FILE]..."
//usage:#define less_full_usage "\n\n"
//usage: "View FILE (or stdin) one screenful at a time\n"
//usage: "\n -E Quit once the end of a file is reached"
+//usage: "\n -F Quit if entire file fits on first screen"
//usage: IF_FEATURE_LESS_REGEXP(
//usage: "\n -I Ignore case in all searches"
//usage: )
@@ -175,8 +176,9 @@ enum {
FLAG_N = 1 << 3,
FLAG_TILDE = 1 << 4,
FLAG_I = 1 << 5,
- FLAG_S = (1 << 6) * ENABLE_FEATURE_LESS_TRUNCATE,
- FLAG_R = (1 << 7) * ENABLE_FEATURE_LESS_RAW,
+ FLAG_F = 1 << 6,
+ FLAG_S = (1 << 7) * ENABLE_FEATURE_LESS_TRUNCATE,
+ FLAG_R = (1 << 8) * ENABLE_FEATURE_LESS_RAW,
/* hijack command line options variable for internal state vars */
LESS_STATE_MATCH_BACKWARDS = 1 << 15,
};
@@ -906,11 +908,12 @@ static void buffer_print(void)
else
print_ascii(buffer[i]);
}
- if ((option_mask32 & FLAG_E)
+ if ((option_mask32 & (FLAG_E|FLAG_F))
&& eof_error <= 0
- && (max_fline - cur_fline) <= max_displayed_line
) {
- less_exit(EXIT_SUCCESS);
+ i = option_mask32 & FLAG_F ? 0 : cur_fline;
+ if (max_fline - i <= max_displayed_line)
+ less_exit(EXIT_SUCCESS);
}
status_print();
}
@@ -1814,7 +1817,7 @@ int less_main(int argc, char **argv)
* -s: condense many empty lines to one
* (used by some setups for manpage display)
*/
- getopt32(argv, "EMmN~I"
+ getopt32(argv, "EMmN~IF"
IF_FEATURE_LESS_TRUNCATE("S")
IF_FEATURE_LESS_RAW("R")
/*ignored:*/"s"
@@ -1828,6 +1831,9 @@ int less_main(int argc, char **argv)
if (ENABLE_FEATURE_LESS_ENV) {
char *c = getenv("LESS");
if (c) while (*c) switch (*c++) {
+ case 'F':
+ option_mask32 |= FLAG_F;
+ break;
case 'M':
option_mask32 |= FLAG_M;
break;