less: document -S flag and make it independently configurable

The -S flag, to cause long lines to be truncated, was enabled by
FEATURE_LESS_DASHCMD.  This is non-obvious and -S is useful even
if the '-' command isn't enabled.

function                                             old     new   delta
.rodata                                           156045  156077     +32
packed_usage                                       30223   30244     +21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 53/0)               Total: 53 bytes

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Ron Yorston 2015-07-19 11:12:29 +01:00 committed by Denys Vlasenko
parent 072fc60f29
commit 51aa861843

View File

@ -48,6 +48,14 @@
//config: help //config: help
//config: The -M/-m flag enables a more sophisticated status line. //config: The -M/-m flag enables a more sophisticated status line.
//config: //config:
//config:config FEATURE_LESS_TRUNCATE
//config: bool "Enable -S"
//config: default y
//config: depends on LESS
//config: help
//config: The -S flag causes long lines to be truncated rather than
//config: wrapped.
//config:
//config:config FEATURE_LESS_MARKS //config:config FEATURE_LESS_MARKS
//config: bool "Enable marks" //config: bool "Enable marks"
//config: default y //config: default y
@ -98,7 +106,8 @@
//config: Enables "-N" command. //config: Enables "-N" command.
//usage:#define less_trivial_usage //usage:#define less_trivial_usage
//usage: "[-E" IF_FEATURE_LESS_REGEXP("I")IF_FEATURE_LESS_FLAGS("Mm") "Nh~] [FILE]..." //usage: "[-E" IF_FEATURE_LESS_REGEXP("I")IF_FEATURE_LESS_FLAGS("Mm")
//usage: "N" IF_FEATURE_LESS_TRUNCATE("S") "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"
@ -110,6 +119,9 @@
//usage: "\n and percentage through the file" //usage: "\n and percentage through the file"
//usage: ) //usage: )
//usage: "\n -N Prefix line number to each line" //usage: "\n -N Prefix line number to each line"
//usage: IF_FEATURE_LESS_TRUNCATE(
//usage: "\n -S Truncate long lines"
//usage: )
//usage: "\n -~ Suppress ~s displayed past EOF" //usage: "\n -~ Suppress ~s displayed past EOF"
#include <sched.h> /* sched_yield() */ #include <sched.h> /* sched_yield() */
@ -144,7 +156,7 @@ 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_DASHCMD, FLAG_S = (1 << 6) * ENABLE_FEATURE_LESS_TRUNCATE,
/* 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,
}; };
@ -820,7 +832,7 @@ static void buffer_print(void)
static void buffer_fill_and_print(void) static void buffer_fill_and_print(void)
{ {
unsigned i; unsigned i;
#if ENABLE_FEATURE_LESS_DASHCMD #if ENABLE_FEATURE_LESS_TRUNCATE
int fpos = cur_fline; int fpos = cur_fline;
if (option_mask32 & FLAG_S) { if (option_mask32 & FLAG_S) {
@ -1330,10 +1342,12 @@ static void flag_change(void)
case '~': case '~':
option_mask32 ^= FLAG_TILDE; option_mask32 ^= FLAG_TILDE;
break; break;
#if ENABLE_FEATURE_LESS_TRUNCATE
case 'S': case 'S':
option_mask32 ^= FLAG_S; option_mask32 ^= FLAG_S;
buffer_fill_and_print(); buffer_fill_and_print();
break; break;
#endif
#if ENABLE_FEATURE_LESS_LINENUMS #if ENABLE_FEATURE_LESS_LINENUMS
case 'N': case 'N':
option_mask32 ^= FLAG_N; option_mask32 ^= FLAG_N;
@ -1638,7 +1652,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" IF_FEATURE_LESS_DASHCMD("S") /*ignored:*/"s"); getopt32(argv, "EMmN~I" IF_FEATURE_LESS_TRUNCATE("S") /*ignored:*/"s");
argc -= optind; argc -= optind;
argv += optind; argv += optind;
num_files = argc; num_files = argc;