summaryrefslogtreecommitdiff
path: root/miscutils/less.c
AgeCommit message (Collapse)Author
2022-01-05libbb: code shrink: introduce and use [_]exit_SUCCESS()Denys Vlasenko
function old new delta exit_SUCCESS - 7 +7 _exit_SUCCESS - 7 +7 run_pipe 1562 1567 +5 pseudo_exec_argv 399 400 +1 finish 86 87 +1 start_stop_daemon_main 1109 1107 -2 shutdown_on_signal 38 36 -2 runsv_main 1662 1660 -2 redirect 1070 1068 -2 read_line 79 77 -2 pause_and_low_level_reboot 54 52 -2 list_i2c_busses_and_exit 483 481 -2 less_exit 12 10 -2 identify 4123 4121 -2 grep_file 1161 1159 -2 getty_main 1519 1517 -2 fsck_minix_main 2681 2679 -2 free_session 132 130 -2 fdisk_main 4739 4737 -2 clean_up_and_exit 53 51 -2 bsd_select 1566 1564 -2 bb_daemonize_or_rexec 198 196 -2 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 3/17 up/down: 21/-34) Total: -13 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-05less: code shrinkDenys Vlasenko
function old new delta restore_tty - 29 +29 less_main 2107 2105 -2 getch_nowait 253 251 -2 buffer_print 614 612 -2 less_exit 51 12 -39 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/4 up/down: 29/-45) Total: -16 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-28less: Ignore -XIsmael Luceno
The flag disables termcap init/deinit of the terminal, which the applet doesn't do anyway. Signed-off-by: Ismael Luceno <ismael@iodev.co.uk> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-28config: update size informationDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-16less: fix fallout from "use common routine to set raw termios"Denys Vlasenko
Testcase: (sleep 10; ls) | busybox less [...] ~ LICENSE ~ Makefile ~ Makefile.custom ~ Makefile.flags [...] less did not want this part: + /* dont convert NL to CR+NL on output */ + newterm->c_oflag &= ~(ONLCR); function old new delta get_termios_and_make_raw 108 115 +7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15less: remove unnecessary messageDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15less: implement -FAaro Koskinen
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>
2018-02-27less: accept -R option. Closes 10816Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-24less: fix help text conditional for -RDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-22less: optional support of -RDenys Vlasenko
Based on patches by Lubomir Rintel <lkundrak@v3.sk> function old new delta read_lines 653 722 +69 less_main 2464 2531 +67 packed_usage 32202 32239 +37 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 173/0) Total: 173 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-08less: code shrinkDenys Vlasenko
function old new delta less_main 2471 2464 -7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-18regularize format of source file headers, no code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-15less,microcom,lineedit: use common routine to set raw termiosDenys Vlasenko
function old new delta get_termios_and_make_raw - 139 +139 xget1 39 8 -31 read_line_input 3912 3867 -45 less_main 2525 2471 -54 set_termios_to_raw 116 36 -80 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/4 up/down: 139/-210) Total: -71 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-14hexedit: implement "[enter] goto offset" keyDenys Vlasenko
This is a must if you need to edit sector 123456789999 on your /dev/disk. text data bss dec hex filename 922745 481 6832 930058 e310a busybox_old 923023 481 6832 930336 e3220 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-14hexedit: restore screen on exitDenys Vlasenko
function old new delta hexedit_main 998 1082 +84 restore_term - 29 +29 remap 168 173 +5 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/0 up/down: 118/0) Total: 118 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-13*: use ESC define instead of "\033"; use ESC[m instead of ESC[0mDenys Vlasenko
text data bss dec hex filename 922535 481 6832 929848 e3038 busybox_old 922534 481 6832 929847 e3037 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-13hexedit: new appletDenys Vlasenko
function old new delta hexedit_main - 930 +930 format_line - 197 +197 remap - 168 +168 move_mapping_further - 141 +141 move_mapping_lower - 107 +107 redraw_cur_line - 104 +104 packed_usage 31802 31812 +10 applet_names 2688 2696 +8 applet_main 1552 1556 +4 applet_suid 97 98 +1 applet_install_loc 194 195 +1 ------------------------------------------------------------------------------ (add/remove: 7/0 grow/shrink: 5/0 up/down: 1671/0) Total: 1671 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-21config: deindent all help textsDenys Vlasenko
Those two spaces after tab have no effect, and always a nuisance when editing. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18Update menuconfig items with approximate applet sizesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-17Spelling fixes in comments, documentation, tests and examplesDenys Vlasenko
By klemens <ka7@github.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10Big cleanup in config help and descriptionDenys Vlasenko
Redundant help texts (one which only repeats the description) are deleted. Descriptions and help texts are trimmed. Some config options are moved, even across menus. No config option _names_ are changed. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-22Convert all miscutils/* applets to "new style" applet definitionsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-13less: switch off nonblock on kbd_fd before exitDenys Vlasenko
This is only necessary if we use stdout fd. function old new delta less_exit 32 51 +19 less_main 2540 2543 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 22/0) Total: 22 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-13less: fall back to using fd #1 for keyboard reading. Closes 9231Denys Vlasenko
function old new delta less_main 2535 2540 +5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-16less: fix bracket search to match behavior of less 481Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-16less: fix SEGVDenys Vlasenko
testcase: echo "" | less, then press ')' key Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21*: hopefully all setup_common_bufsiz() are in placeDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21libbb: make bb_common_bufsiz1 1 kbyte, add capability to use bss tail for itDenys Vlasenko
The config item is FEATURE_USE_BSS_TAIL. When it is off (default): function old new delta read_config 210 228 +18 doCommands 2279 2294 +15 ipneigh_list_or_flush 763 772 +9 ipaddr_list_or_flush 1256 1261 +5 display_process_list 1301 1306 +5 conspy_main 1378 1383 +5 do_lzo_compress 352 355 +3 do_lzo_decompress 565 567 +2 push 46 44 -2 inetd_main 2136 2134 -2 uevent_main 421 418 -3 addLines 97 92 -5 bb_common_bufsiz1 8193 1024 -7169 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 8/5 up/down: 62/-7181) Total: -7119 bytes text data bss dec hex filename 829850 4086 9080 843016 cdd08 busybox_old 829901 4086 1904 835891 cc133 busybox_unstripped FEATURE_USE_BSS_TAIL=y: read_config 210 228 +18 doCommands 2279 2294 +15 ipneigh_list_or_flush 763 772 +9 ipaddr_list_or_flush 1256 1261 +5 display_process_list 1301 1306 +5 conspy_main 1378 1383 +5 do_lzo_compress 352 355 +3 do_lzo_decompress 565 567 +2 inetd_main 2136 2134 -2 bb_common_bufsiz1 8193 - -8193 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 8/1 up/down: 62/-8195) Total: -8133 bytes text data bss dec hex filename 829850 4086 9080 843016 cdd08 busybox_old 829911 4086 880 834877 cbd3d busybox_unstripped FIXME: setup_common_bufsiz() calls are missing. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-16less: fix botched attempt to use last columnRon Yorston
Commit 1ecb996 attempted to make read_lines() use the last column of the terminal (as re_wrap() did). There were two problems with this: - The size of the buffer allocated for lines wasn't increased to allow for the extra character. - The test for width overflow was moved after the point where the next character was added to the buffer. This caused a buffer overflow in certain circumstances. For example, if the line beyond the end of the display was wider than the display read_lines() would initially read the partial line into a buffer. When the user moved down read_lines() would be called again to ensure the rest of the line was read. This would place the next character in the partial line before checking for overflow. This can be fixed by moving the test for overflow back to where it was before commit 1ecb996 and changing the comparison to `>` rather than `>=`. There are two other places where buffers are created without allowing for width+1 characters. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-03less: further tweaks to regular file detectionRon Yorston
Test explicitly for REOPEN flags: update_num_lines is called unconditionally so (num_lines != NOT_REGULAR_FILE) is also true when num_lines contains a valid number of lines. The call to fstat doesn't need to be in #if ENABLE_FEATURE_LESS_FLAGS: the whole function is already in such a test. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31less: improve regular file detection in line counting codeDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31less: allow use of last column of terminalRon Yorston
When read_lines tests whether a character will fit on the current line it checks the *next* character but in case of overflow doesn't display the *current* one. This results in the last column of the terminal never being used. The test in re_wrap (used when the terminal width changes or line numbers are enabled/disabled) is different: it does allow the use of the final column. function old new delta read_lines 764 770 +6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 6/0) Total: 6 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31less: fix line number confusionRon Yorston
Much of the code refers to lines using indices into the flines array (which splits lines into portions that fit on the terminal). In some cases this is wrong and actual line numbers should be used: - when lines are being truncated rather than wrapped (-S flag) - when line numbers have been entered by the user Also fix a bug in numeric input and improve the display at EOF. function old new delta goto_lineno - 111 +111 cap_cur_fline - 101 +101 buffer_to_line - 56 +56 buffer_up 35 66 +31 less_main 2606 2615 +9 goto_match 125 127 +2 buffer_down 81 56 -25 buffer_line 64 - -64 ------------------------------------------------------------------------------ (add/remove: 3/1 grow/shrink: 3/1 up/down: 310/-89) Total: 221 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31less: add a function to detect when display is at end of fileRon Yorston
Add a function to package the test that detects whether enough has been read from the file to allow a screenful to be displayed. Also use this to determine when to display '(END)' in the status line. The previous code was incomplete and didn't handle truncated lines (-S flag) properly. function old new delta at_end - 63 +63 status_print 111 109 -2 read_lines 819 764 -55 getch_nowait 319 264 -55 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/3 up/down: 63/-112) Total: -49 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31less: rearrange detection of non-regular filesRon Yorston
Move the code to detect non-regular files to the point where the file is being opened. If num_lines == READING_FILE guarantees that the file is regular. Detect when a file becomes unreadable between it first being opened and the call to update_num_lines. Mark the file as being non-regular so we don't try that again. function old new delta reinitialize 197 245 +48 update_num_lines 159 127 -32 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 48/-32) Total: 16 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31less: move code to count lines into a separate functionRon Yorston
function old new delta update_num_lines - 159 +159 m_status_print 409 266 -143 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 159/-143) Total: 16 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31less: fix numeric inputRon Yorston
Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-21less: improvements to verbose status messagesRon Yorston
Make verbose status messages (-m/-M flags) behave more like the real `less` command: - fix display of line numbers so they're correct whether lines are being truncated (-S flag) or wrapped. - don't display total lines or percentage when lines are read from stdin: we don't have that information until we reach EOF. When we do reach EOF the additional information is displayed. - when lines are read from a file count the total number of lines so that we can display percentages. Counting lines is avoided until the information is actually needed. If the user pages to EOF the separate read pass can be avoided entirely. Fixes Bug 7586 function old new delta m_status_print 195 382 +187 safe_lineno - 35 +35 reinitialize 172 182 +10 read_lines 675 685 +10 buffer_fill_and_print 178 169 -9 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 3/1 up/down: 242/-9) Total: 233 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-19less: correctly account for tabs when rewrapping linesRon Yorston
Lines are rewrapped when the terminal width changes or line numbers are enabled/disabled. The current calculation always adds eight to the line length for a tab whereas it should only add enough to move to the next tab stop. This doesn't affect the display of lines, which is handled elsewhere and gets tab stops right, but it does cause lines to be wrapped at the wrong position. Signed-off-by: Ron Yorston <rmy@frippery.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-19less: fix display of line numbersRon Yorston
Line numbers are displayed incorrectly on lines that have a search pattern highlighted. The problem can be fixed by moving the call to lineno_str in print_found above the while loop that alters the value of the line pointer. However, a more substantial rewrite results in savings. function old new delta buffer_print 688 697 +9 .rodata 156077 156045 -32 lineno_str 85 - -85 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/1 up/down: 9/-117) Total: -108 bytes Signed-off-by: Ron Yorston <rmy@frippery.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-19less: document -S flag and make it independently configurableRon Yorston
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>
2015-05-25typo fixesManinder Singh
Signed-off-by: Maninder Singh <maninder1.s@samsung.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-23less: make -E workAaro Koskinen
function old new delta buffer_print 71 104 +33 Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-22less: trivial code shrinkDenys Vlasenko
function old new delta read_lines 715 695 -20 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-22less: move "retry-on-EAGAIN" logic closer to read opsDenys Vlasenko
This makes "G" (goto end of input) command work as well as /search_for_nonexistent_string: both will read to EOF now even from somewhat slow input (such as kernel's "git log"). function old new delta ndelay_on 35 43 +8 ndelay_off 35 43 +8 read_lines 695 691 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 16/-4) Total: 12 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-21less: disable "suppress empty wraparound" optimizationDenys Vlasenko
It is buggy wrt another use case... Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-05-02Fix compile failuresDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-13less: fix bugs discovered with "git log -p | less -m" on kernel treeDenys Vlasenko
function old new delta read_lines 685 733 +48 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-22less: accept and ignore -sDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-08-04less: support "less 1<>TTY"Denys Vlasenko
function old new delta less_main 2466 2507 +41 xmalloc_ttyname 46 42 -4 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>