Commit Graph

166 Commits

Author SHA1 Message Date
Denys Vlasenko
12566e7f9b ash,hush: fix handling of SIGINT while waiting for interactive input
function                                             old     new   delta
lineedit_read_key                                    160     237     +77
__pgetc                                              522     589     +67
fgetc_interactive                                    244     309     +65
safe_read_key                                          -      39     +39
read_key                                             588     607     +19
record_pending_signo                                  23      32      +9
signal_handler                                        75      81      +6
.rodata                                           104312  104309      -3
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 6/1 up/down: 282/-3)            Total: 279 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-17 11:46:23 +01:00
Denys Vlasenko
db5546ca10 libbb: code shrink: introduce and use [_]exit_SUCCESS()
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-05 22:16:06 +01:00
Denys Vlasenko
076f5e064f less: code shrink
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>
2022-01-05 22:04:21 +01:00
Ismael Luceno
35727f5741 less: Ignore -X
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>
2021-09-28 23:22:47 +02:00
Denys Vlasenko
b097a84d62 config: update size information
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-28 03:20:17 +01:00
Denys Vlasenko
058a153b69 less: fix fallout from "use common routine to set raw termios"
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-16 10:24:48 +02:00
Denys Vlasenko
50aea2786b less: remove unnecessary message
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15 13:14:51 +02:00
Aaro Koskinen
36941503bd 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>
2018-04-15 13:13:34 +02:00
Denys Vlasenko
0e0209ac53 less: accept -R option. Closes 10816
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-27 11:47:51 +01:00
Denys Vlasenko
14bc965ea9 less: fix help text conditional for -R
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-24 16:47:08 +01:00
Denys Vlasenko
8528d3d4f8 less: optional support of -R
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-22 14:38:51 +01:00
Denys Vlasenko
83c99ab446 less: code shrink
function                                             old     new   delta
less_main                                           2471    2464      -7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-08 10:27:23 +01:00
Denys Vlasenko
0c4dbd481a regularize format of source file headers, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-18 16:28:43 +02:00
Denys Vlasenko
aaaaaa5ad6 less,microcom,lineedit: use common routine to set raw termios
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-15 17:14:01 +02:00
Denys Vlasenko
d54f58d487 hexedit: implement "[enter] goto offset" key
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-14 10:51:12 +02:00
Denys Vlasenko
363fb5ec40 hexedit: restore screen on exit
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-14 09:42:40 +02:00
Denys Vlasenko
8187e01438 *: use ESC define instead of "\033"; use ESC[m instead of ESC[0m
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-13 22:48:30 +02:00
Denys Vlasenko
73af705628 hexedit: new applet
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-09-13 19:20:27 +02:00
Denys Vlasenko
72089cf6b4 config: deindent all help texts
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-21 09:50:55 +02:00
Denys Vlasenko
4eed2c6c50 Update menuconfig items with approximate applet sizes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 22:01:24 +02:00
Denys Vlasenko
10ad622dc2 Spelling fixes in comments, documentation, tests and examples
By klemens <ka7@github.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-17 16:13:32 +02:00
Denys Vlasenko
f560422fa0 Big cleanup in config help and description
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>
2017-01-10 14:58:54 +01:00
Denys Vlasenko
f88e3bfa8d Convert all miscutils/* applets to "new style" applet definitions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-22 23:54:17 +01:00
Denys Vlasenko
7fa799a97d less: switch off nonblock on kbd_fd before exit
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-13 21:05:48 +02:00
Denys Vlasenko
3c0e579a06 less: fall back to using fd #1 for keyboard reading. Closes 9231
function                                             old     new   delta
less_main                                           2535    2540      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-13 20:53:38 +02:00
Denys Vlasenko
110c6bb413 less: fix bracket search to match behavior of less 481
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-16 15:27:30 +02:00
Denys Vlasenko
252559601f less: fix SEGV
testcase: echo "" | less, then press ')' key

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-16 15:09:40 +02:00
Denys Vlasenko
9de2e5a222 *: hopefully all setup_common_bufsiz() are in place
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21 18:38:51 +02:00
Denys Vlasenko
e6a2f4cc5a libbb: make bb_common_bufsiz1 1 kbyte, add capability to use bss tail for it
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>
2016-04-21 17:39:11 +02:00
Ron Yorston
26ccd3d062 less: fix botched attempt to use last column
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-16 18:54:49 +02:00
Ron Yorston
b27cf31003 less: further tweaks to regular file detection
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-08-03 16:41:19 +02:00
Denys Vlasenko
9dc526d0f9 less: improve regular file detection in line counting code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:42:20 +02:00
Ron Yorston
1ecb996fd2 less: allow use of last column of terminal
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-31 16:22:09 +02:00
Ron Yorston
d542d183e1 less: fix line number confusion
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-31 16:22:08 +02:00
Ron Yorston
ad1b4d5882 less: add a function to detect when display is at end of file
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-31 16:22:08 +02:00
Ron Yorston
70b84be9e8 less: rearrange detection of non-regular files
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-31 16:22:07 +02:00
Ron Yorston
159e032bf4 less: move code to count lines into a separate function
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-31 16:22:07 +02:00
Ron Yorston
ae1a9e899e less: fix numeric input
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 15:33:53 +02:00
Ron Yorston
193ba408a4 less: improvements to verbose status messages
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-21 22:28:09 +02:00
Ron Yorston
78cfa00154 less: correctly account for tabs when rewrapping lines
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-19 22:50:25 +02:00
Ron Yorston
f06386ad4f less: fix display of line numbers
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-19 22:48:05 +02:00
Ron Yorston
51aa861843 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>
2015-07-19 22:34:13 +02:00
Maninder Singh
97c6491b4e typo fixes
Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-25 13:46:36 +02:00
Aaro Koskinen
307d26c0eb less: make -E work
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-23 22:58:18 +02:00
Denys Vlasenko
865814a617 less: trivial code shrink
function                                             old     new   delta
read_lines                                           715     695     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-22 21:17:24 +02:00
Denys Vlasenko
d6e7672545 less: move "retry-on-EAGAIN" logic closer to read ops
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-22 21:14:02 +02:00
Denys Vlasenko
15943c886d less: disable "suppress empty wraparound" optimization
It is buggy wrt another use case...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-21 22:10:55 +02:00
Denys Vlasenko
fe33683c8b Fix compile failures
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-05-02 07:18:55 +02:00
Denys Vlasenko
69b114fb8a less: fix bugs discovered with "git log -p | less -m" on kernel tree
function                                             old     new   delta
read_lines                                           685     733     +48

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-13 16:02:59 +02:00
Denys Vlasenko
821e64316a less: accept and ignore -s
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-22 16:36:22 +01:00