1 /* vi: set sw=4 ts=4: */
3 * Mini less implementation for busybox
5 * Copyright (C) 2005 by Rob Sullivan <cogito.ergo.cogito@gmail.com>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
12 * - Add more regular expression support - search modifiers, certain matches, etc.
13 * - Add more complex bracket searching - currently, nested brackets are
15 * - Add support for "F" as an input. This causes less to act in
16 * a similar way to tail -f.
17 * - Allow horizontal scrolling.
20 * - the inp file pointer is used so that keyboard input works after
21 * redirected input has been read from stdin
28 //config: 'less' is a pager, meaning that it displays text files. It possesses
29 //config: a wide array of features, and is an improvement over 'more'.
31 //config:config FEATURE_LESS_MAXLINES
32 //config: int "Max number of input lines less will try to eat"
33 //config: default 9999999
34 //config: depends on LESS
36 //config:config FEATURE_LESS_BRACKETS
37 //config: bool "Enable bracket searching"
39 //config: depends on LESS
41 //config: This option adds the capability to search for matching left and right
42 //config: brackets, facilitating programming.
44 //config:config FEATURE_LESS_FLAGS
45 //config: bool "Enable -m/-M"
47 //config: depends on LESS
49 //config: The -M/-m flag enables a more sophisticated status line.
51 //config:config FEATURE_LESS_TRUNCATE
52 //config: bool "Enable -S"
54 //config: depends on LESS
56 //config: The -S flag causes long lines to be truncated rather than
59 //config:config FEATURE_LESS_MARKS
60 //config: bool "Enable marks"
62 //config: depends on LESS
64 //config: Marks enable positions in a file to be stored for easy reference.
66 //config:config FEATURE_LESS_REGEXP
67 //config: bool "Enable regular expressions"
69 //config: depends on LESS
71 //config: Enable regular expressions, allowing complex file searches.
73 //config:config FEATURE_LESS_WINCH
74 //config: bool "Enable automatic resizing on window size changes"
76 //config: depends on LESS
78 //config: Makes less track window size changes.
80 //config:config FEATURE_LESS_ASK_TERMINAL
81 //config: bool "Use 'tell me cursor position' ESC sequence to measure window"
83 //config: depends on FEATURE_LESS_WINCH
85 //config: Makes less track window size changes.
86 //config: If terminal size can't be retrieved and $LINES/$COLUMNS are not set,
87 //config: this option makes less perform a last-ditch effort to find it:
88 //config: position cursor to 999,999 and ask terminal to report real
89 //config: cursor position using "ESC [ 6 n" escape sequence, then read stdin.
91 //config: This is not clean but helps a lot on serial lines and such.
93 //config:config FEATURE_LESS_DASHCMD
94 //config: bool "Enable flag changes ('-' command)"
96 //config: depends on LESS
98 //config: This enables the ability to change command-line flags within
99 //config: less itself ('-' keyboard command).
101 //config:config FEATURE_LESS_LINENUMS
102 //config: bool "Enable dynamic switching of line numbers"
104 //config: depends on FEATURE_LESS_DASHCMD
106 //config: Enables "-N" command.
108 //usage:#define less_trivial_usage
109 //usage: "[-E" IF_FEATURE_LESS_REGEXP("I")IF_FEATURE_LESS_FLAGS("Mm")
110 //usage: "N" IF_FEATURE_LESS_TRUNCATE("S") "h~] [FILE]..."
111 //usage:#define less_full_usage "\n\n"
112 //usage: "View FILE (or stdin) one screenful at a time\n"
113 //usage: "\n -E Quit once the end of a file is reached"
114 //usage: IF_FEATURE_LESS_REGEXP(
115 //usage: "\n -I Ignore case in all searches"
117 //usage: IF_FEATURE_LESS_FLAGS(
118 //usage: "\n -M,-m Display status line with line numbers"
119 //usage: "\n and percentage through the file"
121 //usage: "\n -N Prefix line number to each line"
122 //usage: IF_FEATURE_LESS_TRUNCATE(
123 //usage: "\n -S Truncate long lines"
125 //usage: "\n -~ Suppress ~s displayed past EOF"
127 #include <sched.h> /* sched_yield() */
130 #include "common_bufsiz.h"
131 #if ENABLE_FEATURE_LESS_REGEXP
137 /* The escape codes for highlighted and normal text */
138 #define HIGHLIGHT ESC"[7m"
139 #define NORMAL ESC"[0m"
140 /* The escape code to home and clear to the end of screen */
141 #define CLEAR ESC"[H\033[J"
142 /* The escape code to clear to the end of line */
143 #define CLEAR_2_EOL ESC"[K"
146 /* Absolute max of lines eaten */
147 MAXLINES = CONFIG_FEATURE_LESS_MAXLINES,
148 /* This many "after the end" lines we will show (at max) */
152 /* Command line options */
160 FLAG_S = (1 << 6) * ENABLE_FEATURE_LESS_TRUNCATE,
161 /* hijack command line options variable for internal state vars */
162 LESS_STATE_MATCH_BACKWARDS = 1 << 15,
165 #if !ENABLE_FEATURE_LESS_REGEXP
166 enum { pattern_valid = 0 };
170 int cur_fline; /* signed */
171 int kbd_fd; /* fd to get input from */
172 int kbd_fd_orig_flags;
174 /* last position in last line, taking into account tabs */
175 size_t last_line_pos;
177 unsigned max_lineno; /* this one tracks linewrap */
178 unsigned max_displayed_line;
180 #if ENABLE_FEATURE_LESS_WINCH
181 unsigned winch_counter;
183 ssize_t eof_error; /* eof if 0, error if < 0 */
185 ssize_t readeof; /* must be signed */
188 const char *empty_line_marker;
190 unsigned current_file;
193 #if ENABLE_FEATURE_LESS_FLAGS
194 int num_lines; /* a flag if < 0, line count if >= 0 */
195 # define REOPEN_AND_COUNT (-1)
196 # define REOPEN_STDIN (-2)
197 # define NOT_REGULAR_FILE (-3)
199 #if ENABLE_FEATURE_LESS_MARKS
201 unsigned mark_lines[15][2];
203 #if ENABLE_FEATURE_LESS_REGEXP
204 unsigned *match_lines;
205 int match_pos; /* signed! */
206 int wanted_match; /* signed! */
209 smallint pattern_valid;
211 #if ENABLE_FEATURE_LESS_ASK_TERMINAL
212 smallint winsize_err;
215 struct termios term_orig, term_less;
216 char kbd_input[KEYCODE_BUFFER_SIZE];
218 #define G (*ptr_to_globals)
219 #define cur_fline (G.cur_fline )
220 #define kbd_fd (G.kbd_fd )
221 #define less_gets_pos (G.less_gets_pos )
222 #define last_line_pos (G.last_line_pos )
223 #define max_fline (G.max_fline )
224 #define max_lineno (G.max_lineno )
225 #define max_displayed_line (G.max_displayed_line)
226 #define width (G.width )
227 #define winch_counter (G.winch_counter )
228 /* This one is 100% not cached by compiler on read access */
229 #define WINCH_COUNTER (*(volatile unsigned *)&winch_counter)
230 #define eof_error (G.eof_error )
231 #define readpos (G.readpos )
232 #define readeof (G.readeof )
233 #define buffer (G.buffer )
234 #define flines (G.flines )
235 #define empty_line_marker (G.empty_line_marker )
236 #define num_files (G.num_files )
237 #define current_file (G.current_file )
238 #define filename (G.filename )
239 #define files (G.files )
240 #define num_lines (G.num_lines )
241 #define num_marks (G.num_marks )
242 #define mark_lines (G.mark_lines )
243 #if ENABLE_FEATURE_LESS_REGEXP
244 #define match_lines (G.match_lines )
245 #define match_pos (G.match_pos )
246 #define num_matches (G.num_matches )
247 #define wanted_match (G.wanted_match )
248 #define pattern (G.pattern )
249 #define pattern_valid (G.pattern_valid )
251 #define terminated (G.terminated )
252 #define term_orig (G.term_orig )
253 #define term_less (G.term_less )
254 #define kbd_input (G.kbd_input )
255 #define INIT_G() do { \
256 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
257 less_gets_pos = -1; \
258 empty_line_marker = "~"; \
263 IF_FEATURE_LESS_REGEXP(wanted_match = -1;) \
266 /* flines[] are lines read from stdin, each in malloc'ed buffer.
267 * Line numbers are stored as uint32_t prepended to each line.
268 * Pointer is adjusted so that flines[i] points directly past
269 * line number. Accesor: */
270 #define MEMPTR(p) ((char*)(p) - 4)
271 #define LINENO(p) (*(uint32_t*)((p) - 4))
274 /* Reset terminal input to normal */
275 static void set_tty_cooked(void)
278 tcsetattr(kbd_fd, TCSANOW, &term_orig);
281 /* Move the cursor to a position (x,y), where (0,0) is the
282 top-left corner of the console */
283 static void move_cursor(int line, int row)
285 printf(ESC"[%u;%uH", line, row);
288 static void clear_line(void)
290 printf(ESC"[%u;0H" CLEAR_2_EOL, max_displayed_line + 2);
293 static void print_hilite(const char *str)
295 printf(HIGHLIGHT"%s"NORMAL, str);
298 static void print_statusline(const char *str)
301 printf(HIGHLIGHT"%.*s"NORMAL, width - 1, str);
304 /* Exit the program gracefully */
305 static void less_exit(int code)
308 if (!(G.kbd_fd_orig_flags & O_NONBLOCK))
312 kill_myself_with_sig(- code); /* does not return */
316 #if (ENABLE_FEATURE_LESS_DASHCMD && ENABLE_FEATURE_LESS_LINENUMS) \
317 || ENABLE_FEATURE_LESS_WINCH
318 static void re_wrap(void)
324 int new_cur_fline = 0;
327 const char **old_flines = flines;
329 char **new_flines = NULL;
332 if (option_mask32 & FLAG_N)
345 if (*d == '\t') { /* tab */
347 new_line_pos &= (~7);
351 if (new_line_pos >= w) {
353 /* new line is full, create next one */
356 sz = (d - linebuf) + 1; /* + 1: NUL */
357 d = ((char*)xmalloc(sz + 4)) + 4;
359 memcpy(d, linebuf, sz);
360 new_flines = xrealloc_vector(new_flines, 8, dst_idx);
361 new_flines[dst_idx] = d;
363 if (new_line_pos < w) {
364 /* if we came here thru "goto next_new" */
365 if (src_idx > max_fline)
374 /* *d == NUL: old line ended, go to next old one */
375 free(MEMPTR(old_flines[src_idx]));
376 /* btw, convert cur_fline... */
377 if (cur_fline == src_idx)
378 new_cur_fline = dst_idx;
380 /* no more lines? finish last new line (and exit the loop) */
381 if (src_idx > max_fline)
383 s = old_flines[src_idx];
384 if (lineno != LINENO(s)) {
385 /* this is not a continuation line!
386 * create next _new_ line too */
392 flines = (const char **)new_flines;
394 max_fline = dst_idx - 1;
395 last_line_pos = new_line_pos;
396 cur_fline = new_cur_fline;
397 /* max_lineno is screen-size independent */
398 #if ENABLE_FEATURE_LESS_REGEXP
404 #if ENABLE_FEATURE_LESS_REGEXP
405 static void fill_match_lines(unsigned pos);
407 #define fill_match_lines(pos) ((void)0)
410 static int at_end(void)
412 return (option_mask32 & FLAG_S)
413 ? !(cur_fline <= max_fline &&
414 max_lineno > LINENO(flines[cur_fline]) + max_displayed_line)
415 : !(max_fline > cur_fline + max_displayed_line);
418 /* Devilishly complex routine.
420 * Has to deal with EOF and EPIPE on input,
421 * with line wrapping, with last line not ending in '\n'
422 * (possibly not ending YET!), with backspace and tabs.
423 * It reads input again if last time we got an EOF (thus supporting
424 * growing files) or EPIPE (watching output of slow process like make).
427 * flines[] - array of lines already read. Linewrap may cause
428 * one source file line to occupy several flines[n].
429 * flines[max_fline] - last line, possibly incomplete.
430 * terminated - 1 if flines[max_fline] is 'terminated'
431 * (if there was '\n' [which isn't stored itself, we just remember
433 * max_lineno - last line's number, this one doesn't increment
434 * on line wrap, only on "real" new lines.
435 * readbuf[0..readeof-1] - small preliminary buffer.
436 * readbuf[readpos] - next character to add to current line.
437 * last_line_pos - screen line position of next char to be read
438 * (takes into account tabs and backspaces)
439 * eof_error - < 0 error, == 0 EOF, > 0 not EOF/error
441 * "git log -p | less -m" on the kernel git tree is a good test for EAGAINs,
442 * "/search on very long input" and "reaching max line count" corner cases.
444 static void read_lines(void)
446 char *current_line, *p;
448 char last_terminated = terminated;
449 time_t last_time = 0;
450 int retry_EAGAIN = 2;
451 #if ENABLE_FEATURE_LESS_REGEXP
452 unsigned old_max_fline = max_fline;
455 #define readbuf bb_common_bufsiz1
456 setup_common_bufsiz();
458 /* (careful: max_fline can be -1) */
459 if (max_fline + 1 > MAXLINES)
462 if (option_mask32 & FLAG_N)
465 p = current_line = ((char*)xmalloc(w + 5)) + 4;
466 if (!last_terminated) {
467 const char *cp = flines[max_fline];
470 /* last_line_pos is still valid from previous read_lines() */
476 while (1) { /* read lines until we reach cur_fline or wanted_match */
479 while (1) { /* read chars until we have a line */
481 /* if no unprocessed chars left, eat more */
482 if (readpos >= readeof) {
483 int flags = ndelay_on(0);
489 eof_error = safe_read(STDIN_FILENO, readbuf, COMMON_BUFSIZE);
493 if (t != last_time) {
495 if (--retry_EAGAIN < 0)
500 fcntl(0, F_SETFL, flags); /* ndelay_off(0) */
507 c = readbuf[readpos];
508 /* backspace? [needed for manpages] */
509 /* <tab><bs> is (a) insane and */
510 /* (b) harder to do correctly, so we refuse to do it */
511 if (c == '\x8' && last_line_pos && p[-1] != '\t') {
512 readpos++; /* eat it */
514 /* was buggy (p could end up <= current_line)... */
519 size_t new_last_line_pos = last_line_pos + 1;
521 new_last_line_pos += 7;
522 new_last_line_pos &= (~7);
524 if ((int)new_last_line_pos > w)
526 last_line_pos = new_last_line_pos;
528 /* ok, we will eat this char */
535 /* NUL is substituted by '\n'! */
536 if (c == '\0') c = '\n';
539 } /* end of "read chars until we have a line" loop */
541 //BUG: also triggers on this:
542 // { printf "\nfoo\n"; sleep 1; printf "\nbar\n"; } | less
543 // (resulting in lost empty line between "foo" and "bar" lines)
544 // the "terminated" logic needs fixing (or explaining)
545 /* Corner case: linewrap with only "" wrapping to next line */
546 /* Looks ugly on screen, so we do not store this empty line */
547 if (!last_terminated && !current_line[0]) {
554 last_terminated = terminated;
555 flines = xrealloc_vector(flines, 8, max_fline);
557 flines[max_fline] = (char*)xrealloc(MEMPTR(current_line), strlen(current_line) + 1 + 4) + 4;
558 LINENO(flines[max_fline]) = max_lineno;
562 if (max_fline >= MAXLINES) {
563 eof_error = 0; /* Pretend we saw EOF */
567 #if !ENABLE_FEATURE_LESS_REGEXP
570 if (wanted_match >= num_matches) { /* goto_match called us */
571 fill_match_lines(old_max_fline);
572 old_max_fline = max_fline;
574 if (wanted_match < num_matches)
578 if (eof_error <= 0) {
582 current_line = ((char*)xmalloc(w + 5)) + 4;
585 } /* end of "read lines until we reach cur_fline" loop */
588 if (errno == EAGAIN) {
591 print_statusline(bb_msg_read_error);
594 #if ENABLE_FEATURE_LESS_FLAGS
595 else if (eof_error == 0)
596 num_lines = max_lineno;
599 fill_match_lines(old_max_fline);
600 #if ENABLE_FEATURE_LESS_REGEXP
601 /* prevent us from being stuck in search for a match */
607 #if ENABLE_FEATURE_LESS_FLAGS
608 static int safe_lineno(int fline)
610 if (fline >= max_fline)
611 fline = max_fline - 1;
613 /* also catches empty file (max_fline == 0) */
617 return LINENO(flines[fline]) + 1;
620 /* count number of lines in file */
621 static void update_num_lines(void)
628 /* only do this for regular files */
629 if (num_lines == REOPEN_AND_COUNT || num_lines == REOPEN_STDIN) {
631 fd = open("/proc/self/fd/0", O_RDONLY);
632 if (fd < 0 && num_lines == REOPEN_AND_COUNT) {
633 /* "filename" is valid only if REOPEN_AND_COUNT */
634 fd = open(filename, O_RDONLY);
637 /* somebody stole my file! */
638 num_lines = NOT_REGULAR_FILE;
641 if (fstat(fd, &stbuf) != 0 || !S_ISREG(stbuf.st_mode)) {
642 num_lines = NOT_REGULAR_FILE;
645 while ((len = safe_read(fd, buf, sizeof(buf))) > 0) {
646 for (i = 0; i < len; ++i) {
647 if (buf[i] == '\n' && ++count == MAXLINES)
658 /* Print a status line if -M was specified */
659 static void m_status_print(void)
664 if (less_gets_pos >= 0) /* don't touch statusline while input is done! */
668 printf(HIGHLIGHT"%s", filename);
670 printf(" (file %i of %i)", current_file, num_files);
672 first = safe_lineno(cur_fline);
673 last = (option_mask32 & FLAG_S)
674 ? MIN(first + max_displayed_line, max_lineno)
675 : safe_lineno(cur_fline + max_displayed_line);
676 printf(" lines %i-%i", first, last);
680 printf("/%i", num_lines);
684 if (num_files > 1 && current_file != num_files)
685 printf(" - next: %s", files[current_file]);
686 } else if (num_lines > 0) {
687 percent = (100 * last + num_lines/2) / num_lines;
688 printf(" %i%%", percent <= 100 ? percent : 100);
694 /* Print the status line */
695 static void status_print(void)
699 if (less_gets_pos >= 0) /* don't touch statusline while input is done! */
702 /* Change the status if flags have been set */
703 #if ENABLE_FEATURE_LESS_FLAGS
704 if (option_mask32 & (FLAG_M|FLAG_m)) {
712 if (cur_fline && !at_end()) {
720 printf(HIGHLIGHT"%s (file %i of %i)"NORMAL,
721 p, current_file, num_files);
727 static const char controls[] ALIGN1 =
728 /* NUL: never encountered; TAB: not converted */
729 /**/"\x01\x02\x03\x04\x05\x06\x07\x08" "\x0a\x0b\x0c\x0d\x0e\x0f"
730 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
731 "\x7f\x9b"; /* DEL and infamous Meta-ESC :( */
732 static const char ctrlconv[] ALIGN1 =
733 /* why 40 instead of 4a below? - it is a replacement for '\n'.
734 * '\n' is a former NUL - we subst it with @, not J */
735 "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x40\x4b\x4c\x4d\x4e\x4f"
736 "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f";
738 static void print_lineno(const char *line)
740 const char *fmt = " ";
741 unsigned n = n; /* for compiler */
743 if (line != empty_line_marker) {
744 /* Width of 7 preserves tab spacing in the text */
746 n = LINENO(line) + 1;
747 if (n > 9999999 && MAXLINES > 9999999) {
756 #if ENABLE_FEATURE_LESS_REGEXP
757 static void print_found(const char *line)
762 regmatch_t match_structs;
765 const char *str = line;
770 n = strcspn(str, controls);
777 n = strspn(str, controls);
784 /* buf[] holds quarantined version of str */
786 /* Each part of the line that matches has the HIGHLIGHT
787 * and NORMAL escape sequences placed around it.
788 * NB: we regex against line, but insert text
789 * from quarantined copy (buf[]) */
795 while (match_status == 0) {
796 char *new = xasprintf("%s%.*s"HIGHLIGHT"%.*s"NORMAL,
797 growline ? growline : "",
798 (int)match_structs.rm_so, str,
799 (int)(match_structs.rm_eo - match_structs.rm_so),
800 str + match_structs.rm_so);
803 str += match_structs.rm_eo;
804 line += match_structs.rm_eo;
807 /* Most of the time doesn't find the regex, optimize for that */
808 match_status = regexec(&pattern, line, 1, &match_structs, eflags);
809 /* if even "" matches, treat it as "not a match" */
810 if (match_structs.rm_so >= match_structs.rm_eo)
814 printf("%s%s\n", growline ? growline : "", str);
818 void print_found(const char *line);
821 static void print_ascii(const char *str)
828 n = strcspn(str, controls);
831 printf("%.*s", (int) n, str);
834 n = strspn(str, controls);
839 else if (*str == (char)0x9b)
840 /* VT100's CSI, aka Meta-ESC. Who's inventor? */
841 /* I want to know who committed this sin */
844 *p++ = ctrlconv[(unsigned char)*str];
853 /* Print the buffer */
854 static void buffer_print(void)
859 for (i = 0; i <= max_displayed_line; i++) {
861 if (option_mask32 & FLAG_N)
862 print_lineno(buffer[i]);
864 print_found(buffer[i]);
866 print_ascii(buffer[i]);
868 if ((option_mask32 & FLAG_E)
870 && (max_fline - cur_fline) <= max_displayed_line
872 less_exit(EXIT_SUCCESS);
877 static void buffer_fill_and_print(void)
880 #if ENABLE_FEATURE_LESS_TRUNCATE
881 int fpos = cur_fline;
883 if (option_mask32 & FLAG_S) {
884 /* Go back to the beginning of this line */
885 while (fpos && LINENO(flines[fpos]) == LINENO(flines[fpos-1]))
890 while (i <= max_displayed_line && fpos <= max_fline) {
891 int lineno = LINENO(flines[fpos]);
892 buffer[i] = flines[fpos];
896 } while ((fpos <= max_fline)
897 && (option_mask32 & FLAG_S)
898 && lineno == LINENO(flines[fpos])
902 for (i = 0; i <= max_displayed_line && cur_fline + i <= max_fline; i++) {
903 buffer[i] = flines[cur_fline + i];
906 for (; i <= max_displayed_line; i++) {
907 buffer[i] = empty_line_marker;
912 /* move cur_fline to a given line number, reading lines if necessary */
913 static void goto_lineno(int target)
918 else if (target > LINENO(flines[cur_fline])) {
920 while (LINENO(flines[cur_fline]) != target && cur_fline < max_fline)
922 /* target not reached but more input is available */
923 if (LINENO(flines[cur_fline]) != target && eof_error > 0) {
929 /* search backwards through already-read lines */
930 while (LINENO(flines[cur_fline]) != target && cur_fline > 0)
935 static void cap_cur_fline(void)
937 if ((option_mask32 & FLAG_S)) {
938 if (cur_fline > max_fline)
939 cur_fline = max_fline;
940 if (LINENO(flines[cur_fline]) + max_displayed_line > max_lineno + TILDES) {
941 goto_lineno(max_lineno - max_displayed_line + TILDES);
946 if (cur_fline + max_displayed_line > max_fline + TILDES)
947 cur_fline = max_fline - max_displayed_line + TILDES;
953 /* Move the buffer up and down in the file in order to scroll */
954 static void buffer_down(int nlines)
956 if ((option_mask32 & FLAG_S))
957 goto_lineno(LINENO(flines[cur_fline]) + nlines);
962 buffer_fill_and_print();
965 static void buffer_up(int nlines)
967 if ((option_mask32 & FLAG_S)) {
968 goto_lineno(LINENO(flines[cur_fline]) - nlines);
976 buffer_fill_and_print();
979 /* display a given line where the argument can be either an index into
980 * the flines array or a line number */
981 static void buffer_to_line(int linenum, int is_lineno)
986 goto_lineno(linenum);
991 buffer_fill_and_print();
994 static void buffer_line(int linenum)
996 buffer_to_line(linenum, FALSE);
999 static void buffer_lineno(int lineno)
1001 buffer_to_line(lineno, TRUE);
1004 static void open_file_and_read_lines(void)
1007 xmove_fd(xopen(filename, O_RDONLY), STDIN_FILENO);
1008 #if ENABLE_FEATURE_LESS_FLAGS
1009 num_lines = REOPEN_AND_COUNT;
1012 /* "less" with no arguments in argv[] */
1013 /* For status line only */
1014 filename = xstrdup(bb_msg_standard_input);
1015 #if ENABLE_FEATURE_LESS_FLAGS
1016 num_lines = REOPEN_STDIN;
1026 /* Reinitialize everything for a new file - free the memory and start over */
1027 static void reinitialize(void)
1032 for (i = 0; i <= max_fline; i++)
1033 free(MEMPTR(flines[i]));
1041 open_file_and_read_lines();
1042 #if ENABLE_FEATURE_LESS_ASK_TERMINAL
1044 printf("\033[999;999H" "\033[6n");
1046 buffer_fill_and_print();
1049 static int64_t getch_nowait(void)
1053 struct pollfd pfd[2];
1055 pfd[0].fd = STDIN_FILENO;
1056 pfd[0].events = POLLIN;
1058 pfd[1].events = POLLIN;
1060 tcsetattr(kbd_fd, TCSANOW, &term_less);
1061 /* NB: select/poll returns whenever read will not block. Therefore:
1062 * if eof is reached, select/poll will return immediately
1063 * because read will immediately return 0 bytes.
1064 * Even if select/poll says that input is available, read CAN block
1065 * (switch fd into O_NONBLOCK'ed mode to avoid it)
1068 /* Are we interested in stdin? */
1070 if (eof_error > 0) /* did NOT reach eof yet */
1071 rd = 0; /* yes, we are interested in stdin */
1073 /* Position cursor if line input is done */
1074 if (less_gets_pos >= 0)
1075 move_cursor(max_displayed_line + 2, less_gets_pos + 1);
1078 if (kbd_input[0] == 0) { /* if nothing is buffered */
1079 #if ENABLE_FEATURE_LESS_WINCH
1082 /* NB: SIGWINCH interrupts poll() */
1083 r = poll(pfd + rd, 2 - rd, -1);
1084 if (/*r < 0 && errno == EINTR &&*/ winch_counter)
1085 return '\\'; /* anything which has no defined function */
1089 safe_poll(pfd + rd, 2 - rd, -1);
1093 /* We have kbd_fd in O_NONBLOCK mode, read inside read_key()
1094 * would not block even if there is no input available */
1095 key64 = read_key(kbd_fd, kbd_input, /*timeout off:*/ -2);
1096 if ((int)key64 == -1) {
1097 if (errno == EAGAIN) {
1098 /* No keyboard input available. Since poll() did return,
1099 * we should have input on stdin */
1101 buffer_fill_and_print();
1104 /* EOF/error (ssh session got killed etc) */
1111 /* Grab a character from input without requiring the return key.
1112 * May return KEYCODE_xxx values.
1113 * Note that this function works best with raw input. */
1114 static int64_t less_getch(int pos)
1120 less_gets_pos = pos;
1121 key = key64 = getch_nowait();
1124 /* Discard Ctrl-something chars.
1125 * (checking only lower 32 bits is a size optimization:
1126 * upper 32 bits are used only by KEYCODE_CURSOR_POS)
1128 if (key >= 0 && key < ' ' && key != 0x0d && key != 8)
1134 static char* less_gets(int sz)
1138 char *result = xzalloc(1);
1142 less_gets_pos = sz + i;
1155 if (c < ' ') /* filters out KEYCODE_xxx too (<0) */
1157 if (i >= width - sz - 1)
1158 continue; /* len limit */
1161 result = xrealloc(result, i+1);
1165 static void examine_file(void)
1169 print_statusline("Examine: ");
1170 new_fname = less_gets(sizeof("Examine: ") - 1);
1171 if (!new_fname[0]) {
1177 if (access(new_fname, R_OK) != 0) {
1178 print_statusline("Cannot read this file");
1182 filename = new_fname;
1183 /* files start by = argv. why we assume that argv is infinitely long??
1184 files[num_files] = filename;
1185 current_file = num_files + 1;
1187 files[0] = filename;
1188 num_files = current_file = 1;
1192 /* This function changes the file currently being paged. direction can be one of the following:
1193 * -1: go back one file
1194 * 0: go to the first file
1195 * 1: go forward one file */
1196 static void change_file(int direction)
1198 if (current_file != ((direction > 0) ? num_files : 1)) {
1199 current_file = direction ? current_file + direction : 1;
1201 filename = xstrdup(files[current_file - 1]);
1204 print_statusline(direction > 0 ? "No next file" : "No previous file");
1208 static void remove_current_file(void)
1215 if (current_file != 1) {
1217 for (i = 3; i <= num_files; i++)
1218 files[i - 2] = files[i - 1];
1222 for (i = 2; i <= num_files; i++)
1223 files[i - 2] = files[i - 1];
1229 static void colon_process(void)
1233 /* Clear the current line and print a prompt */
1234 print_statusline(" :");
1236 keypress = less_getch(2);
1239 remove_current_file();
1244 #if ENABLE_FEATURE_LESS_FLAGS
1256 less_exit(EXIT_SUCCESS);
1264 #if ENABLE_FEATURE_LESS_REGEXP
1265 static void normalize_match_pos(int match)
1267 if (match >= num_matches)
1268 match = num_matches - 1;
1274 static void goto_match(int match)
1280 /* Try to find next match if eof isn't reached yet */
1281 if (match >= num_matches && eof_error > 0) {
1282 wanted_match = match; /* "I want to read until I see N'th match" */
1286 normalize_match_pos(match);
1287 buffer_line(match_lines[match_pos]);
1289 print_statusline("No matches found");
1293 static void fill_match_lines(unsigned pos)
1297 /* Run the regex on each line of the current file */
1298 while (pos <= max_fline) {
1299 /* If this line matches */
1300 if (regexec(&pattern, flines[pos], 0, NULL, 0) == 0
1301 /* and we didn't match it last time */
1302 && !(num_matches && match_lines[num_matches-1] == pos)
1304 match_lines = xrealloc_vector(match_lines, 4, num_matches);
1305 match_lines[num_matches++] = pos;
1311 static void regex_process(void)
1313 char *uncomp_regex, *err;
1315 /* Reset variables */
1320 if (pattern_valid) {
1325 /* Get the uncompiled regular expression from the user */
1327 bb_putchar((option_mask32 & LESS_STATE_MATCH_BACKWARDS) ? '?' : '/');
1328 uncomp_regex = less_gets(1);
1329 if (!uncomp_regex[0]) {
1335 /* Compile the regex and check for errors */
1336 err = regcomp_or_errmsg(&pattern, uncomp_regex,
1337 (option_mask32 & FLAG_I) ? REG_ICASE : 0);
1340 print_statusline(err);
1347 fill_match_lines(0);
1348 while (match_pos < num_matches) {
1349 if ((int)match_lines[match_pos] > cur_fline)
1353 if (option_mask32 & LESS_STATE_MATCH_BACKWARDS)
1356 /* It's possible that no matches are found yet.
1357 * goto_match() will read input looking for match,
1359 goto_match(match_pos);
1363 static void number_process(int first_digit)
1368 char num_input[sizeof(int)*4]; /* more than enough */
1370 num_input[0] = first_digit;
1372 /* Clear the current line, print a prompt, and then print the digit */
1374 printf(":%c", first_digit);
1376 /* Receive input until a letter is given */
1378 while (i < sizeof(num_input)-1) {
1379 keypress = less_getch(i + 1);
1380 if ((unsigned)keypress > 255 || !isdigit(keypress))
1382 num_input[i] = keypress;
1383 bb_putchar(keypress);
1387 num_input[i] = '\0';
1388 num = bb_strtou(num_input, NULL, 10);
1389 /* on format error, num == -1 */
1390 if (num < 1 || num > MAXLINES) {
1395 /* We now know the number and the letter entered, so we process them */
1397 case KEYCODE_DOWN: case 'z': case 'd': case 'e': case ' ': case '\015':
1400 case KEYCODE_UP: case 'b': case 'w': case 'y': case 'u':
1403 case 'g': case '<': case 'G': case '>':
1404 buffer_lineno(num - 1);
1407 #if ENABLE_FEATURE_LESS_FLAGS
1409 num = num * (num_lines > 0 ? num_lines : max_lineno) / 100;
1411 num = num * max_lineno / 100;
1415 #if ENABLE_FEATURE_LESS_REGEXP
1417 goto_match(match_pos + num);
1420 option_mask32 &= ~LESS_STATE_MATCH_BACKWARDS;
1424 option_mask32 |= LESS_STATE_MATCH_BACKWARDS;
1431 #if ENABLE_FEATURE_LESS_DASHCMD
1432 static void flag_change(void)
1438 keypress = less_getch(1);
1442 option_mask32 ^= FLAG_M;
1445 option_mask32 ^= FLAG_m;
1448 option_mask32 ^= FLAG_E;
1451 option_mask32 ^= FLAG_TILDE;
1453 #if ENABLE_FEATURE_LESS_TRUNCATE
1455 option_mask32 ^= FLAG_S;
1456 buffer_fill_and_print();
1459 #if ENABLE_FEATURE_LESS_LINENUMS
1461 option_mask32 ^= FLAG_N;
1463 buffer_fill_and_print();
1470 static void show_flag_status(void)
1477 keypress = less_getch(1);
1481 flag_val = option_mask32 & FLAG_M;
1484 flag_val = option_mask32 & FLAG_m;
1487 flag_val = option_mask32 & FLAG_TILDE;
1490 flag_val = option_mask32 & FLAG_N;
1493 flag_val = option_mask32 & FLAG_E;
1501 printf(HIGHLIGHT"The status of the flag is: %u"NORMAL, flag_val != 0);
1505 #endif /* ENABLE_FEATURE_LESS_DASHCMD */
1507 static void save_input_to_file(void)
1509 const char *msg = "";
1514 print_statusline("Log file: ");
1515 current_line = less_gets(sizeof("Log file: ")-1);
1516 if (current_line[0]) {
1517 fp = fopen_for_write(current_line);
1519 msg = "Error opening log file";
1522 for (i = 0; i <= max_fline; i++)
1523 fprintf(fp, "%s\n", flines[i]);
1528 print_statusline(msg);
1532 #if ENABLE_FEATURE_LESS_MARKS
1533 static void add_mark(void)
1537 print_statusline("Mark: ");
1538 letter = less_getch(sizeof("Mark: ") - 1);
1540 if (isalpha(letter)) {
1541 /* If we exceed 15 marks, start overwriting previous ones */
1542 if (num_marks == 14)
1545 mark_lines[num_marks][0] = letter;
1546 mark_lines[num_marks][1] = cur_fline;
1549 print_statusline("Invalid mark letter");
1553 static void goto_mark(void)
1558 print_statusline("Go to mark: ");
1559 letter = less_getch(sizeof("Go to mark: ") - 1);
1562 if (isalpha(letter)) {
1563 for (i = 0; i <= num_marks; i++)
1564 if (letter == mark_lines[i][0]) {
1565 buffer_line(mark_lines[i][1]);
1568 if (num_marks == 14 && letter != mark_lines[14][0])
1569 print_statusline("Mark not set");
1571 print_statusline("Invalid mark letter");
1575 #if ENABLE_FEATURE_LESS_BRACKETS
1576 static char opp_bracket(char bracket)
1579 case '{': case '[': /* '}' == '{' + 2. Same for '[' */
1581 case '(': /* ')' == '(' + 1 */
1593 static void match_right_bracket(char bracket)
1595 unsigned i = cur_fline;
1598 || strchr(flines[i], bracket) == NULL
1600 print_statusline("No bracket in top line");
1604 bracket = opp_bracket(bracket);
1605 for (; i < max_fline; i++) {
1606 if (strchr(flines[i], bracket) != NULL) {
1608 * Line with matched right bracket becomes
1611 buffer_line(i - max_displayed_line);
1615 print_statusline("No matching bracket found");
1618 static void match_left_bracket(char bracket)
1620 int i = cur_fline + max_displayed_line;
1623 || strchr(flines[i], bracket) == NULL
1625 print_statusline("No bracket in bottom line");
1629 bracket = opp_bracket(bracket);
1630 for (; i >= 0; i--) {
1631 if (strchr(flines[i], bracket) != NULL) {
1633 * Line with matched left bracket becomes
1634 * first visible line
1640 print_statusline("No matching bracket found");
1642 #endif /* FEATURE_LESS_BRACKETS */
1644 static void keypress_process(int keypress)
1647 case KEYCODE_DOWN: case 'e': case 'j': case 0x0d:
1650 case KEYCODE_UP: case 'y': case 'k':
1653 case KEYCODE_PAGEDOWN: case ' ': case 'z': case 'f':
1654 buffer_down(max_displayed_line + 1);
1656 case KEYCODE_PAGEUP: case 'w': case 'b':
1657 buffer_up(max_displayed_line + 1);
1660 buffer_down((max_displayed_line + 1) / 2);
1663 buffer_up((max_displayed_line + 1) / 2);
1665 case KEYCODE_HOME: case 'g': case 'p': case '<': case '%':
1668 case KEYCODE_END: case 'G': case '>':
1669 cur_fline = MAXLINES;
1671 buffer_line(cur_fline);
1674 less_exit(EXIT_SUCCESS);
1676 #if ENABLE_FEATURE_LESS_MARKS
1687 /* TODO: (1) also bind ^R, ^L to this?
1688 * (2) re-measure window size?
1696 save_input_to_file();
1701 #if ENABLE_FEATURE_LESS_FLAGS
1706 #if ENABLE_FEATURE_LESS_REGEXP
1708 option_mask32 &= ~LESS_STATE_MATCH_BACKWARDS;
1712 goto_match(match_pos + 1);
1715 goto_match(match_pos - 1);
1718 option_mask32 |= LESS_STATE_MATCH_BACKWARDS;
1722 #if ENABLE_FEATURE_LESS_DASHCMD
1733 #if ENABLE_FEATURE_LESS_BRACKETS
1734 case '{': case '(': case '[':
1735 match_right_bracket(keypress);
1737 case '}': case ')': case ']':
1738 match_left_bracket(keypress);
1746 if (isdigit(keypress))
1747 number_process(keypress);
1750 static void sig_catcher(int sig)
1755 #if ENABLE_FEATURE_LESS_WINCH
1756 static void sigwinch_handler(int sig UNUSED_PARAM)
1762 int less_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1763 int less_main(int argc, char **argv)
1770 /* TODO: -x: do not interpret backspace, -xx: tab also
1771 * -xxx: newline also
1772 * -w N: assume width N (-xxx -w 32: hex viewer of sorts)
1773 * -s: condense many empty lines to one
1774 * (used by some setups for manpage display)
1776 getopt32(argv, "EMmN~I" IF_FEATURE_LESS_TRUNCATE("S") /*ignored:*/"s");
1782 /* Another popular pager, most, detects when stdout
1783 * is not a tty and turns into cat. This makes sense. */
1784 if (!isatty(STDOUT_FILENO))
1785 return bb_cat(argv);
1788 if (isatty(STDIN_FILENO)) {
1789 /* Just "less"? No args and no redirection? */
1790 bb_error_msg("missing filename");
1794 filename = xstrdup(files[0]);
1797 if (option_mask32 & FLAG_TILDE)
1798 empty_line_marker = "";
1800 /* Some versions of less can survive w/o controlling tty,
1801 * try to do the same. This also allows to specify an alternative
1802 * tty via "less 1<>TTY".
1804 * We prefer not to use STDOUT_FILENO directly,
1805 * since we want to set this fd to non-blocking mode,
1806 * and not interfere with other processes which share stdout with us.
1808 tty_name = xmalloc_ttyname(STDOUT_FILENO);
1810 tty_fd = open(tty_name, O_RDONLY);
1815 /* Try controlling tty */
1817 tty_fd = open(CURRENT_TTY, O_RDONLY);
1819 /* If all else fails, less 481 uses stdout. Mimic that */
1820 tty_fd = STDOUT_FILENO;
1823 G.kbd_fd_orig_flags = ndelay_on(tty_fd);
1824 kbd_fd = tty_fd; /* save in a global */
1826 tcgetattr(kbd_fd, &term_orig);
1827 term_less = term_orig;
1828 term_less.c_lflag &= ~(ICANON | ECHO);
1829 term_less.c_iflag &= ~(IXON | ICRNL);
1830 /*term_less.c_oflag &= ~ONLCR;*/
1831 term_less.c_cc[VMIN] = 1;
1832 term_less.c_cc[VTIME] = 0;
1834 IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(kbd_fd, &width, &max_displayed_line);
1835 /* 20: two tabstops + 4 */
1836 if (width < 20 || max_displayed_line < 3)
1837 return bb_cat(argv);
1838 max_displayed_line -= 2;
1840 /* We want to restore term_orig on exit */
1841 bb_signals(BB_FATAL_SIGS, sig_catcher);
1842 #if ENABLE_FEATURE_LESS_WINCH
1843 signal(SIGWINCH, sigwinch_handler);
1846 buffer = xmalloc((max_displayed_line+1) * sizeof(char *));
1851 #if ENABLE_FEATURE_LESS_WINCH
1852 while (WINCH_COUNTER) {
1855 IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(kbd_fd, &width, &max_displayed_line);
1856 IF_FEATURE_LESS_ASK_TERMINAL(got_size:)
1857 /* 20: two tabstops + 4 */
1860 if (max_displayed_line < 3)
1861 max_displayed_line = 3;
1862 max_displayed_line -= 2;
1864 buffer = xmalloc((max_displayed_line+1) * sizeof(char *));
1865 /* Avoid re-wrap and/or redraw if we already know
1866 * we need to do it again. These ops are expensive */
1872 buffer_fill_and_print();
1873 /* This took some time. Loop back and check,
1874 * were there another SIGWINCH? */
1876 keypress = less_getch(-1); /* -1: do not position cursor */
1877 # if ENABLE_FEATURE_LESS_ASK_TERMINAL
1878 if ((int32_t)keypress == KEYCODE_CURSOR_POS) {
1879 uint32_t rc = (keypress >> 32);
1880 width = (rc & 0x7fff);
1881 max_displayed_line = ((rc >> 16) & 0x7fff);
1886 keypress = less_getch(-1); /* -1: do not position cursor */
1888 keypress_process(keypress);
1893 Help text of less version 418 is below.
1894 If you are implementing something, keeping
1895 key and/or command line switch compatibility is a good idea:
1898 SUMMARY OF LESS COMMANDS
1900 Commands marked with * may be preceded by a number, N.
1901 Notes in parentheses indicate the behavior if N is given.
1902 h H Display this help.
1904 ---------------------------------------------------------------------------
1906 e ^E j ^N CR * Forward one line (or N lines).
1907 y ^Y k ^K ^P * Backward one line (or N lines).
1908 f ^F ^V SPACE * Forward one window (or N lines).
1909 b ^B ESC-v * Backward one window (or N lines).
1910 z * Forward one window (and set window to N).
1911 w * Backward one window (and set window to N).
1912 ESC-SPACE * Forward one window, but don't stop at end-of-file.
1913 d ^D * Forward one half-window (and set half-window to N).
1914 u ^U * Backward one half-window (and set half-window to N).
1915 ESC-) RightArrow * Left one half screen width (or N positions).
1916 ESC-( LeftArrow * Right one half screen width (or N positions).
1917 F Forward forever; like "tail -f".
1918 r ^R ^L Repaint screen.
1919 R Repaint screen, discarding buffered input.
1920 ---------------------------------------------------
1921 Default "window" is the screen height.
1922 Default "half-window" is half of the screen height.
1923 ---------------------------------------------------------------------------
1925 /pattern * Search forward for (N-th) matching line.
1926 ?pattern * Search backward for (N-th) matching line.
1927 n * Repeat previous search (for N-th occurrence).
1928 N * Repeat previous search in reverse direction.
1929 ESC-n * Repeat previous search, spanning files.
1930 ESC-N * Repeat previous search, reverse dir. & spanning files.
1931 ESC-u Undo (toggle) search highlighting.
1932 ---------------------------------------------------
1933 Search patterns may be modified by one or more of:
1934 ^N or ! Search for NON-matching lines.
1935 ^E or * Search multiple files (pass thru END OF FILE).
1936 ^F or @ Start search at FIRST file (for /) or last file (for ?).
1937 ^K Highlight matches, but don't move (KEEP position).
1938 ^R Don't use REGULAR EXPRESSIONS.
1939 ---------------------------------------------------------------------------
1941 g < ESC-< * Go to first line in file (or line N).
1942 G > ESC-> * Go to last line in file (or line N).
1943 p % * Go to beginning of file (or N percent into file).
1944 t * Go to the (N-th) next tag.
1945 T * Go to the (N-th) previous tag.
1946 { ( [ * Find close bracket } ) ].
1947 } ) ] * Find open bracket { ( [.
1948 ESC-^F <c1> <c2> * Find close bracket <c2>.
1949 ESC-^B <c1> <c2> * Find open bracket <c1>
1950 ---------------------------------------------------
1951 Each "find close bracket" command goes forward to the close bracket
1952 matching the (N-th) open bracket in the top line.
1953 Each "find open bracket" command goes backward to the open bracket
1954 matching the (N-th) close bracket in the bottom line.
1955 m<letter> Mark the current position with <letter>.
1956 '<letter> Go to a previously marked position.
1957 '' Go to the previous position.
1959 ---------------------------------------------------
1960 A mark is any upper-case or lower-case letter.
1961 Certain marks are predefined:
1962 ^ means beginning of the file
1963 $ means end of the file
1964 ---------------------------------------------------------------------------
1966 :e [file] Examine a new file.
1968 :n * Examine the (N-th) next file from the command line.
1969 :p * Examine the (N-th) previous file from the command line.
1970 :x * Examine the first (or N-th) file from the command line.
1971 :d Delete the current file from the command line list.
1972 = ^G :f Print current file name.
1973 ---------------------------------------------------------------------------
1974 MISCELLANEOUS COMMANDS
1975 -<flag> Toggle a command line option [see OPTIONS below].
1976 --<name> Toggle a command line option, by name.
1977 _<flag> Display the setting of a command line option.
1978 __<name> Display the setting of an option, by name.
1979 +cmd Execute the less cmd each time a new file is examined.
1980 !command Execute the shell command with $SHELL.
1981 |Xcommand Pipe file between current pos & mark X to shell command.
1982 v Edit the current file with $VISUAL or $EDITOR.
1983 V Print version number of "less".
1984 ---------------------------------------------------------------------------
1986 Most options may be changed either on the command line,
1987 or from within less by using the - or -- command.
1988 Options may be given in one of two forms: either a single
1989 character preceded by a -, or a name preceded by --.
1991 Display help (from command line).
1992 -a ........ --search-skip-screen
1993 Forward search skips current screen.
1994 -b [N] .... --buffers=[N]
1996 -B ........ --auto-buffers
1997 Don't automatically allocate buffers for pipes.
1998 -c ........ --clear-screen
1999 Repaint by clearing rather than scrolling.
2002 -D [xn.n] . --color=xn.n
2003 Set screen colors. (MS-DOS only)
2004 -e -E .... --quit-at-eof --QUIT-AT-EOF
2005 Quit at end of file.
2007 Force open non-regular files.
2008 -F ........ --quit-if-one-screen
2009 Quit if entire file fits on first screen.
2010 -g ........ --hilite-search
2011 Highlight only last match for searches.
2012 -G ........ --HILITE-SEARCH
2013 Don't highlight any matches for searches.
2014 -h [N] .... --max-back-scroll=[N]
2015 Backward scroll limit.
2016 -i ........ --ignore-case
2017 Ignore case in searches that do not contain uppercase.
2018 -I ........ --IGNORE-CASE
2019 Ignore case in all searches.
2020 -j [N] .... --jump-target=[N]
2021 Screen position of target lines.
2022 -J ........ --status-column
2023 Display a status column at left edge of screen.
2024 -k [file] . --lesskey-file=[file]
2026 -L ........ --no-lessopen
2027 Ignore the LESSOPEN environment variable.
2028 -m -M .... --long-prompt --LONG-PROMPT
2030 -n -N .... --line-numbers --LINE-NUMBERS
2031 Don't use line numbers.
2032 -o [file] . --log-file=[file]
2033 Copy to log file (standard input only).
2034 -O [file] . --LOG-FILE=[file]
2035 Copy to log file (unconditionally overwrite).
2036 -p [pattern] --pattern=[pattern]
2037 Start at pattern (from command line).
2038 -P [prompt] --prompt=[prompt]
2040 -q -Q .... --quiet --QUIET --silent --SILENT
2041 Quiet the terminal bell.
2042 -r -R .... --raw-control-chars --RAW-CONTROL-CHARS
2043 Output "raw" control characters.
2044 -s ........ --squeeze-blank-lines
2045 Squeeze multiple blank lines.
2046 -S ........ --chop-long-lines
2048 -t [tag] .. --tag=[tag]
2050 -T [tagsfile] --tag-file=[tagsfile]
2051 Use an alternate tags file.
2052 -u -U .... --underline-special --UNDERLINE-SPECIAL
2053 Change handling of backspaces.
2054 -V ........ --version
2055 Display the version number of "less".
2056 -w ........ --hilite-unread
2057 Highlight first new line after forward-screen.
2058 -W ........ --HILITE-UNREAD
2059 Highlight first new line after any forward movement.
2060 -x [N[,...]] --tabs=[N[,...]]
2062 -X ........ --no-init
2063 Don't use termcap init/deinit strings.
2065 Don't use termcap keypad init/deinit strings.
2066 -y [N] .... --max-forw-scroll=[N]
2067 Forward scroll limit.
2068 -z [N] .... --window=[N]
2070 -" [c[c]] . --quotes=[c[c]]
2071 Set shell quote characters.
2073 Don't display tildes after end of file.
2074 -# [N] .... --shift=[N]
2075 Horizontal scroll amount (0 = one half screen width)
2077 ---------------------------------------------------------------------------
2079 These keys can be used to edit text being entered
2080 on the "command line" at the bottom of the screen.
2081 RightArrow ESC-l Move cursor right one character.
2082 LeftArrow ESC-h Move cursor left one character.
2083 CNTL-RightArrow ESC-RightArrow ESC-w Move cursor right one word.
2084 CNTL-LeftArrow ESC-LeftArrow ESC-b Move cursor left one word.
2085 HOME ESC-0 Move cursor to start of line.
2086 END ESC-$ Move cursor to end of line.
2087 BACKSPACE Delete char to left of cursor.
2088 DELETE ESC-x Delete char under cursor.
2089 CNTL-BACKSPACE ESC-BACKSPACE Delete word to left of cursor.
2090 CNTL-DELETE ESC-DELETE ESC-X Delete word under cursor.
2091 CNTL-U ESC (MS-DOS only) Delete entire line.
2092 UpArrow ESC-k Retrieve previous command line.
2093 DownArrow ESC-j Retrieve next command line.
2094 TAB Complete filename & cycle.
2095 SHIFT-TAB ESC-TAB Complete filename & reverse cycle.
2096 CNTL-L Complete filename, list all.