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>
This commit is contained in:
parent
4b6091f92c
commit
36941503bd
@ -121,11 +121,12 @@
|
|||||||
//kbuild:lib-$(CONFIG_LESS) += less.o
|
//kbuild:lib-$(CONFIG_LESS) += less.o
|
||||||
|
|
||||||
//usage:#define less_trivial_usage
|
//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: "N" IF_FEATURE_LESS_TRUNCATE("S") IF_FEATURE_LESS_RAW("R") "h~] [FILE]..."
|
||||||
//usage:#define less_full_usage "\n\n"
|
//usage:#define less_full_usage "\n\n"
|
||||||
//usage: "View FILE (or stdin) one screenful at a time\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 -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: IF_FEATURE_LESS_REGEXP(
|
||||||
//usage: "\n -I Ignore case in all searches"
|
//usage: "\n -I Ignore case in all searches"
|
||||||
//usage: )
|
//usage: )
|
||||||
@ -175,8 +176,9 @@ enum {
|
|||||||
FLAG_N = 1 << 3,
|
FLAG_N = 1 << 3,
|
||||||
FLAG_TILDE = 1 << 4,
|
FLAG_TILDE = 1 << 4,
|
||||||
FLAG_I = 1 << 5,
|
FLAG_I = 1 << 5,
|
||||||
FLAG_S = (1 << 6) * ENABLE_FEATURE_LESS_TRUNCATE,
|
FLAG_F = 1 << 6,
|
||||||
FLAG_R = (1 << 7) * ENABLE_FEATURE_LESS_RAW,
|
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 */
|
/* hijack command line options variable for internal state vars */
|
||||||
LESS_STATE_MATCH_BACKWARDS = 1 << 15,
|
LESS_STATE_MATCH_BACKWARDS = 1 << 15,
|
||||||
};
|
};
|
||||||
@ -906,11 +908,12 @@ static void buffer_print(void)
|
|||||||
else
|
else
|
||||||
print_ascii(buffer[i]);
|
print_ascii(buffer[i]);
|
||||||
}
|
}
|
||||||
if ((option_mask32 & FLAG_E)
|
if ((option_mask32 & (FLAG_E|FLAG_F))
|
||||||
&& eof_error <= 0
|
&& 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();
|
status_print();
|
||||||
}
|
}
|
||||||
@ -1814,7 +1817,7 @@ int less_main(int argc, char **argv)
|
|||||||
* -s: condense many empty lines to one
|
* -s: condense many empty lines to one
|
||||||
* (used by some setups for manpage display)
|
* (used by some setups for manpage display)
|
||||||
*/
|
*/
|
||||||
getopt32(argv, "EMmN~I"
|
getopt32(argv, "EMmN~IF"
|
||||||
IF_FEATURE_LESS_TRUNCATE("S")
|
IF_FEATURE_LESS_TRUNCATE("S")
|
||||||
IF_FEATURE_LESS_RAW("R")
|
IF_FEATURE_LESS_RAW("R")
|
||||||
/*ignored:*/"s"
|
/*ignored:*/"s"
|
||||||
@ -1828,6 +1831,9 @@ int less_main(int argc, char **argv)
|
|||||||
if (ENABLE_FEATURE_LESS_ENV) {
|
if (ENABLE_FEATURE_LESS_ENV) {
|
||||||
char *c = getenv("LESS");
|
char *c = getenv("LESS");
|
||||||
if (c) while (*c) switch (*c++) {
|
if (c) while (*c) switch (*c++) {
|
||||||
|
case 'F':
|
||||||
|
option_mask32 |= FLAG_F;
|
||||||
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
option_mask32 |= FLAG_M;
|
option_mask32 |= FLAG_M;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user