aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaro Koskinen <aaro.koskinen@iki.fi>2018-04-15 01:24:24 +0300
committerDenys Vlasenko <vda.linux@googlemail.com>2018-04-15 13:13:34 +0200
commit36941503bd8e28a1fac13edffc3ffc84346b32c5 (patch)
treead3c482f9747aba9b62aca9802235c33d36f486c
parent4b6091f92c1c5abfe4597af4f3f6fa266ac46a5a (diff)
downloadbusybox-w32-36941503bd8e28a1fac13edffc3ffc84346b32c5.tar.gz
busybox-w32-36941503bd8e28a1fac13edffc3ffc84346b32c5.tar.bz2
busybox-w32-36941503bd8e28a1fac13edffc3ffc84346b32c5.zip
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 51ef2a59d..3bce93247 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -121,11 +121,12 @@
121//kbuild:lib-$(CONFIG_LESS) += less.o 121//kbuild:lib-$(CONFIG_LESS) += less.o
122 122
123//usage:#define less_trivial_usage 123//usage:#define less_trivial_usage
124//usage: "[-E" IF_FEATURE_LESS_REGEXP("I")IF_FEATURE_LESS_FLAGS("Mm") 124//usage: "[-EF" IF_FEATURE_LESS_REGEXP("I")IF_FEATURE_LESS_FLAGS("Mm")
125//usage: "N" IF_FEATURE_LESS_TRUNCATE("S") IF_FEATURE_LESS_RAW("R") "h~] [FILE]..." 125//usage: "N" IF_FEATURE_LESS_TRUNCATE("S") IF_FEATURE_LESS_RAW("R") "h~] [FILE]..."
126//usage:#define less_full_usage "\n\n" 126//usage:#define less_full_usage "\n\n"
127//usage: "View FILE (or stdin) one screenful at a time\n" 127//usage: "View FILE (or stdin) one screenful at a time\n"
128//usage: "\n -E Quit once the end of a file is reached" 128//usage: "\n -E Quit once the end of a file is reached"
129//usage: "\n -F Quit if entire file fits on first screen"
129//usage: IF_FEATURE_LESS_REGEXP( 130//usage: IF_FEATURE_LESS_REGEXP(
130//usage: "\n -I Ignore case in all searches" 131//usage: "\n -I Ignore case in all searches"
131//usage: ) 132//usage: )
@@ -175,8 +176,9 @@ enum {
175 FLAG_N = 1 << 3, 176 FLAG_N = 1 << 3,
176 FLAG_TILDE = 1 << 4, 177 FLAG_TILDE = 1 << 4,
177 FLAG_I = 1 << 5, 178 FLAG_I = 1 << 5,
178 FLAG_S = (1 << 6) * ENABLE_FEATURE_LESS_TRUNCATE, 179 FLAG_F = 1 << 6,
179 FLAG_R = (1 << 7) * ENABLE_FEATURE_LESS_RAW, 180 FLAG_S = (1 << 7) * ENABLE_FEATURE_LESS_TRUNCATE,
181 FLAG_R = (1 << 8) * ENABLE_FEATURE_LESS_RAW,
180/* hijack command line options variable for internal state vars */ 182/* hijack command line options variable for internal state vars */
181 LESS_STATE_MATCH_BACKWARDS = 1 << 15, 183 LESS_STATE_MATCH_BACKWARDS = 1 << 15,
182}; 184};
@@ -906,11 +908,12 @@ static void buffer_print(void)
906 else 908 else
907 print_ascii(buffer[i]); 909 print_ascii(buffer[i]);
908 } 910 }
909 if ((option_mask32 & FLAG_E) 911 if ((option_mask32 & (FLAG_E|FLAG_F))
910 && eof_error <= 0 912 && eof_error <= 0
911 && (max_fline - cur_fline) <= max_displayed_line
912 ) { 913 ) {
913 less_exit(EXIT_SUCCESS); 914 i = option_mask32 & FLAG_F ? 0 : cur_fline;
915 if (max_fline - i <= max_displayed_line)
916 less_exit(EXIT_SUCCESS);
914 } 917 }
915 status_print(); 918 status_print();
916} 919}
@@ -1814,7 +1817,7 @@ int less_main(int argc, char **argv)
1814 * -s: condense many empty lines to one 1817 * -s: condense many empty lines to one
1815 * (used by some setups for manpage display) 1818 * (used by some setups for manpage display)
1816 */ 1819 */
1817 getopt32(argv, "EMmN~I" 1820 getopt32(argv, "EMmN~IF"
1818 IF_FEATURE_LESS_TRUNCATE("S") 1821 IF_FEATURE_LESS_TRUNCATE("S")
1819 IF_FEATURE_LESS_RAW("R") 1822 IF_FEATURE_LESS_RAW("R")
1820 /*ignored:*/"s" 1823 /*ignored:*/"s"
@@ -1828,6 +1831,9 @@ int less_main(int argc, char **argv)
1828 if (ENABLE_FEATURE_LESS_ENV) { 1831 if (ENABLE_FEATURE_LESS_ENV) {
1829 char *c = getenv("LESS"); 1832 char *c = getenv("LESS");
1830 if (c) while (*c) switch (*c++) { 1833 if (c) while (*c) switch (*c++) {
1834 case 'F':
1835 option_mask32 |= FLAG_F;
1836 break;
1831 case 'M': 1837 case 'M':
1832 option_mask32 |= FLAG_M; 1838 option_mask32 |= FLAG_M;
1833 break; 1839 break;