Commit Graph

330 Commits

Author SHA1 Message Date
Ron Yorston
776b56d774 vi: code shrink
I was puzzled by code in find_range() which handles forward word
movement.  It included a test to see if we're at the start of a
word.  Since these are forward word movements surely we'd expect to
be at the start of a word?  In fact, the test was intended to fix a
problem with changes to the last word in a file, as discussed in the
thread starting here:

   http://lists.busybox.net/pipermail/busybox/2004-January/044552.html

The code can be simplified by testing directly for end of file instead
of indirectly for not being at the start of a word.  Since trailing
whitespace is now handled in do_cmd() the code to back up off a newline
is no longer required.

function                                             old     new   delta
find_range                                           619     514    -105
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-105)           Total: -105 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-29 12:05:53 +02:00
Ron Yorston
7b4c2276a8 vi: fix word operations across line boundaries
Commit 4b49422a0 (vi: fix changes to word at end of line. Closes
11796) fixed a problem where an operation on a word at the end of
a line followed by a line starting with whitespace incorrectly
joined the lines.  However it also broke the case where operating
on multiple words across a line boundary *should* join the lines.

Fix this by detecting when trailing whitepace in a word operation
includes a newline.  Whitespace beyond the newline is excluded
from consideration.

function                                             old     new   delta
do_cmd                                              5083    5088      +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 5/0)                 Total: 5 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-29 12:05:53 +02:00
Denys Vlasenko
70ee23399c vi: code shrink
function                                             old     new   delta
setops                                                85      73     -12
colon                                               2965    2915     -50
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-62)             Total: -62 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-01 14:41:39 +01:00
Alison Winters
63d9da322f vi: restore 0 offset after :set noXXX command
Fixes bug where commands after the first noXXX command are ignored.
    e.g. :set noic tabstop=4

While at it, stop recognizing "notabstop=NNN".

function                                             old     new   delta
colon                                               2990    2965     -25

Signed-off-by: Alison Winters <alisonatwork@outlook.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-01 14:26:36 +01:00
Ron Yorston
cad3fc743a libbb: introduce and use fputs_stdout
function                                             old     new   delta
fputs_stdout                                           -      12     +12
zxc_vm_process                                      7237    7230      -7
yes_main                                              85      78      -7
write_block                                          380     373      -7
wrapf                                                305     298      -7
strings_main                                         437     430      -7
show_bridge                                          353     346      -7
rev_main                                             384     377      -7
put_prompt_custom                                     58      51      -7
put_cur_glyph_and_inc_cursor                         168     161      -7
print_numbered_lines                                 152     145      -7
print_named_ascii                                    130     123      -7
print_name                                           135     128      -7
print_login_issue                                    386     379      -7
print_ascii                                          208     201      -7
powertop_main                                       1249    1242      -7
od_main                                             1789    1782      -7
logread_main                                         518     511      -7
head_main                                            804     797      -7
display_process_list                                1319    1312      -7
cut_main                                            1002     995      -7
bb_dump_dump                                        1550    1543      -7
bb_ask_noecho                                        393     386      -7
baseNUM_main                                         702     695      -7
expand_main                                          755     745     -10
dumpleases_main                                      497     487     -10
write1                                                12       -     -12
putcsi                                                37      23     -14
print_login_prompt                                    55      41     -14
paste_main                                           525     511     -14
cat_main                                             440     426     -14
print_it                                             245     230     -15
print_addrinfo                                      1188    1171     -17
print_rule                                           770     750     -20
print_linkinfo                                       842     822     -20
httpd_main                                           791     771     -20
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/34 up/down: 12/-341)         Total: -329 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-03 20:52:40 +01:00
Ron Yorston
5bef6781fa vi: fix range selection by forward character motion
Selection of ranges for change/delete/yank by forward character
motion commands (SPACE or 'l') was incorrect.  The range was
always one character whereas vi allows the size of the range to
be specified.

Fix this by executing the motion command the required number of times.
There is a complication when the range is at the end of a line.  We need
to distinguish between a range which excludes the last character and
one which includes it.  This requires comparing the actual range with
that expected from the command count.  (With the additional quirk that
a command count of zero is equivalent to a command count of one.)

function                                             old     new   delta
find_range                                           587     619     +32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 32/0)               Total: 32 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-02 14:41:55 +01:00
Denys Vlasenko
84d5eddb25 help text: replace [OPTIONS] with actual options (if not too long)
function                                             old     new   delta
packed_usage                                       33620   33665     +45

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 22:34:05 +01:00
Ron Yorston
16bcd504a3 vi: fixes to string search in colon commands, closes 10321
Handling of string searches in colon commands (e.g ':/pat1/,/pat2/cmd')
differ from standard vi:

- As reported in bug 10321 such searches can't be repeated using the
  'n' command.  This is because the last search pattern isn't updated.

- The search also can't be repeated using the command '://' because
  an empty search pattern doesn't imply the use of the last search
  pattern.

- Such searches should start on the line after the current line,
  otherwise '://' never moves to the next occurrence of the pattern.
  This can also affect other cases where line ranges are specified
  using search patterns.

Fix these various issues.

function                                             old     new   delta
get_one_address                                      325     342     +17

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-01-29 14:01:50 +01:00
Denys Vlasenko
9a0c404d5f vi: placate "warning: shifting a negative signed value is undefined"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 17:42:23 +02:00
James Byrne
6937487be7 libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d437 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().

This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.

Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.

This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.

The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):

Arm:     -92 bytes
MIPS:    -52 bytes
PPC:   -1836 bytes
x86_64: -938 bytes

Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.

Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 11:35:03 +02:00
Denys Vlasenko
fa182a355a vi: code shrink
function                                             old     new   delta
colon                                               2852    2846      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-06-08 12:57:07 +02:00
Ron Yorston
7b93e317c1 vi: enable 'dG' command. Closes 11801
The 'G' command was omitted from the list of commands that change or
delete whole lines.  Add it in the appropriate places so the 'dG',
'cG' and 'yG' commands work, including in cases where an explicit
line number has been supplied.

function                                             old     new   delta
find_range                                           534     596     +62
.rodata                                           175166  175167      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 63/0)               Total: 63 bytes

Reported-by: David Kelly <david.kelly@liberica.ch>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-28 17:16:46 +02:00
Ron Yorston
4b49422a08 vi: fix changes to word at end of line. Closes 11796
As reported in bug 11796 BusyBox vi incorrectly handles changes
to a word at the end of a line.  If the following line starts
with whitespace changing or deleting the last word of a line
with the 'cw' or 'dw' commands causes the lines to be joined.

This happens because the range for the change returned by
find_range() covers all whitespace after the word, including
newlines.  The problem can be fixed by setting 'ml' to zero
to indicate to yank_delete() that processing should stop at
the end of the current line.

However, this results in a new problem.  'dw' correctly deletes
all whitespace following the word but so does 'cw', which should
preserve the trailing whitespace.  To fix this the code to omit
whitespace from the change is modified to include all whitespace
not just blanks.

function                                             old     new   delta
do_cmd                                              5034    5069     +35
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 35/0)               Total: 35 bytes

Reported-by: David Kelly <david.kelly@liberica.ch>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-28 17:16:46 +02:00
Denys Vlasenko
a3ce161363 vi: revert change in how "end of file list" is deteced - fixes 'q' in bare "vi"
function                                             old     new   delta
vi_main                                              273     272      -1
colon                                               2853    2852      -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-2)               Total: -2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-03 16:35:23 +02:00
Denys Vlasenko
e1a1b64f43 vi: code shrink
function                                             old     new   delta
new_screen                                            84      75      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-03 16:30:50 +02:00
Ron Yorston
3e61b59ef3 vi: avoid build failure in non-default case
If vi is built with FEATURE_VI_USE_SIGNALS disabled and
FEATURE_VI_WIN_RESIZE enabled new_screen() is used without a
declaration.  Move the function to avoid this.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-03 16:20:13 +02:00
Denys Vlasenko
8939359180 vi: rename save_argc -> cmdline_filecnt
function                                             old     new   delta
vi_main                                              272     273      +1
colon                                               2852    2853      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-02 12:45:30 +02:00
Denys Vlasenko
bbacd03ccc vi: restore capability to remember insertion cmds for "."
function                                             old     new   delta
modifying_cmds                                        17      22      +5
get_one_char                                         103      98      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 5/-5)                Total: 0 bytes
   text	   data	    bss	    dec	    hex	filename
 982121	    485	   7296	 989902	  f1ace	busybox_old
 982094	    485	   7296	 989875	  f1ab3	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-02 11:50:25 +02:00
Denys Vlasenko
b29dce4bc2 vi: code shrink
function                                             old     new   delta
get_input_line                                       172     175      +3
char_insert                                          444     447      +3
rawmode                                               36      24     -12
edit_file                                            644     626     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 6/-30)             Total: -24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-01 17:17:02 +02:00
Denys Vlasenko
26f5e9d21c vi: convert more /**/ comments to //
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-01 16:42:30 +02:00
Denys Vlasenko
2a57608f67 vi: code shrink
function                                             old     new   delta
get_one_char                                         108     103      -5
edit_file                                            651     644      -7
do_cmd                                              4696    4688      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-20)             Total: -20 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-01 16:15:51 +02:00
Denys Vlasenko
6ce60b9cca vi: use vsnprintf to format status line
This is the last use of "vsprintf" in busybox:

function                                             old     new   delta
status_line_bold                                      72      77      +5
status_line                                           40      45      +5
vsprintf                                              23       -     -23
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 2/0 up/down: 10/-23)            Total: -13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-01 15:41:05 +02:00
Denys Vlasenko
d4f2e7ff71 vi: rearrange functions, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-01 14:18:02 +02:00
Denys Vlasenko
de69775838 vi: rearrange functions, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-01 14:16:53 +02:00
Denys Vlasenko
616e4699d2 vi: rearrange functions, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-01 14:02:37 +02:00
Denys Vlasenko
363a2bc9b1 vi: rearrange functions, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-01 13:59:38 +02:00
Denys Vlasenko
24bd350aaa vi: rearrange functions, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-01 13:55:27 +02:00
Denys Vlasenko
c319310404 vi: fix ^Z not always working as intended
function                                             old     new   delta
tstp_handler                                          64      71      +7
text_yank                                             54      56      +2
vi_main                                              280     272      -8
do_cmd                                              4705    4696      -9
colon                                               2861    2852      -9
cont_handler                                          66       -     -66
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/3 up/down: 9/-92)             Total: -83 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-01 12:29:27 +02:00
Denys Vlasenko
6ed94aa9b2 vi: install SIGINT handler _after_ restart setjmp is initialized
While at it, sanitized comment style, deleted wrong ones, renamed signal
handlers to <sig>_handler(), slightly optimized "cursor home+clear screen".

function                                             old     new   delta
cont_handler                                           -      66     +66
tstp_handler                                           -      64     +64
winch_handler                                          -      60     +60
int_handler                                            -      32     +32
edit_file                                            648     651      +3
redraw                                                52      43      -9
catch_sig                                             32       -     -32
winch_sig                                             60       -     -60
suspend_sig                                           64       -     -64
cont_sig                                              66       -     -66
------------------------------------------------------------------------------
(add/remove: 4/4 grow/shrink: 1/1 up/down: 225/-231)           Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-01 11:58:11 +02:00
Ron Yorston
a2fd1aaf86 vi: allow manual screen update if SIGWINCH isn't supported
On platforms that don't support SIGWINCH vi can be configured
with FEATURE_VI_USE_SIGNALS disabled and FEATURE_VI_WIN_RESIZE
enabled.  This allows the user to force an update with ^L when
the screen is resized.

However, because the SIGWINCH handler hasn't run the virtual
screen buffer won't have been updated and the display becomes
corrupted.  Fix this by calling new_screen() if necessary.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-03-30 18:03:37 +01:00
Denys Vlasenko
eabf4b2b57 vi: code shrink, proper printf formatting for strlen()
function                                             old     new   delta
yank_delete                                           98      99      +1
what_reg                                              34      33      -1
text_yank                                             56      54      -2
end_cmd_q                                             17      14      -3
do_cmd                                              4718    4705     -13
colon                                               2875    2861     -14
edit_file                                            668     648     -20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/6 up/down: 1/-53)             Total: -52 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-03-29 14:40:01 +01:00
Ron Yorston
61052d1bb8 vi: further fixes to undo after autoindent
Commit bb983f30e (vi: fix faulty undo after autoinsert) has a
number of problems:

- The commit message refers to 'autoinsert' when it really means
  'autoindent'.

- The indentation of undo_push_insert() was incorrect.

- Most seriously the commit only fixed the problem for cases where
  the indentation was exactly one character.  This is because undo_push()
  only allows single characters to be queued for UNDO_INS_QUEUED.

  Lifting this restriction allows the example given in the previous
  commit message (with a three character indent) to work.

function                                             old     new   delta
undo_push                                            406     435     +29
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 29/0)               Total: 29 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-11 11:47:20 +01:00
Ron Yorston
df4e3af9f7 vi: fix replacement of single character with CR
Currently if the 'r' command is followed by a carriage return a
literal CR replaces the current character.

Fix this so that:

- a new line is inserted
- the autoindent setting is respected
- the cursor is placed at the start of the new line

function                                             old     new   delta
do_cmd                                              5052    5060      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 8/0)                 Total: 8 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-08 13:03:06 +01:00
Ron Yorston
bb983f30e7 vi: fix faulty undo after autoinsert
Enable autoinsert and enter the following with an indent of three
spaces:

   line 1
   line 2

Using 'u' to undo the last insert results in:

   line1e 2

The insertion of the indent hasn't been properly recorded.

Since recording insertions is a common operation add a convenience
function, undo_push_insert(), to handle this and use it to record
the autoindent correctly.

function                                             old     new   delta
undo_push_insert                                       -      36     +36
string_insert                                        133     129      -4
char_insert                                          518     473     -45
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 36/-49)            Total: -13 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-08 12:57:58 +01: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
Ron Yorston
d08206dce1 vi: correctly detect when a deletion empties the buffer
Michał Berger has reported two issues:

- Repeatedly deleting and undoing the deletion of the last line
  results in characters being lost from the end of the line.

- Deleting the bottom line twice then attempting to undo each of
  these deletions results in a segfault.

The problem seems to be an incorrect test for whether the text buffer
is empty.

Reported-by: Michał Berger <michallinuxstuff@gmail.com>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-03 10:07:58 +01:00
Denys Vlasenko
b733046069 vi: code shrink
function                                             old     new   delta
char_search                                          241     247      +6
get_one_address                                      275     272      -3
colon                                               2878    2875      -3
do_cmd                                              4726    4720      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 6/-12)              Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-29 14:39:52 +01:00
Denys Vlasenko
836d0a7ee4 vi: fix FEATURE_VI_REGEX_SEARCH to respect LIMITED (one-line) search
If busybox is compiled with FEATURE_VI_REGEX_SEARCH enabled, command
":s/x/y/" searches not only in the current line, but continues search
after it. This makes range searches (":1,3s/x/y/") work incorrect. For
example file "./test":
1
2
3

$ vi ./test
:1,2s/3/e/
gives us:
1
2
e

function                                             old     new   delta
char_search                                          213     241     +28

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-29 14:19:57 +01:00
Ron Yorston
552796791f vi: remove duplicated code
At worst show_status_line() might be called needlessly when the
user presses ^L/^R, but I don't think we'll get many complaints
about that.

function                                             old     new   delta
do_cmd                                              4592    4558     -34
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-34)             Total: -34 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-10-31 12:51:51 +01:00
Denys Vlasenko
8825cb6660 vi: placate "warning: variable orig_buf set but not used"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 15:11:36 +02:00
Denys Vlasenko
39043ad25e vi: placate "warning: statement with no effect"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 14:46:08 +02:00
Denys Vlasenko
6f97b30a90 use %m printf specifier where appropriate
function                                             old     new   delta
out                                                   85      75     -10
udhcpd_main                                         1472    1461     -11
open_stdio_to_tty                                     98      85     -13
init_exec                                            245     232     -13
udhcpc_main                                         2763    2749     -14
do_cmd                                              4771    4755     -16
status_line_bold_errno                                32      14     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/7 up/down: 0/-95)             Total: -95 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-29 18:17:25 +02: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
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
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
75d151e31d libarchive: FEATURE_LZMA_FAST should be visible if FEATURE_SEAMLESS_LZMA
While at it, tweak some config help texts.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-20 23:28:00 +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
0cc9b1843d vi: survive if stdin is nonblocking. closes 9851
function                                             old     new   delta
readit                                                55      69     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-05-02 20:39:02 +02:00
Yousong Zhou
8f3bf4f0d3 vi: avoid touching a new file with ZZ when no editing has been done
This is the behaviour observed with standard vim and busybox vi of at
least 1.22.1.  It was changed with commit "32afd3a vi: some
simplifications" which happened before 1.23.0.

Mistyping filename on command line happens fairly often and it's better
we restore the old behaviour to avoid a few unnecessary flash writes and
sometimes efforts of debugging bugs caused by those unneeded stray
files.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-24 21:13:10 +01:00
Denys Vlasenko
e88608eae2 vi: don't touch file with :x when modified_count == 0
Along with it, there are other changes

 - Check for uppercase X is removed as the expression will be always false and
   :X itself is another totally different command in standard vim
 - The status line will show number of written lines instead of lines requested
   by the colon command.  This is also how the standard vim is doing, though
   the difference is that '!' has to be explicitly specified in vim to allow
   partial writes

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-13 20:50:42 +01:00
Denys Vlasenko
eba7fe6bb9 vi,fsck: do not use build timestamp unconditionally. Closes 9626
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-29 19:14:26 +01:00
Denys Vlasenko
01ccdd1d3c libbb: consolidate the code to set termios unbuffered mode
function                                             old     new   delta
set_termios_to_raw                                     -     116    +116
count_lines                                           72      74      +2
powertop_main                                       1458    1430     -28
top_main                                             943     914     -29
more_main                                            759     714     -45
fsck_minix_main                                     2969    2921     -48
conspy_main                                         1197    1135     -62
rawmode                                               99      36     -63
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/6 up/down: 118/-275)         Total: -157 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 16:17:59 +01: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
61fcc8c781 vi: fix '' command (goto to prev context)
The '' command in vi doesn't currently work because after the first
apostrophe is read, the next character is converted to an integer
between 0 and 25 inclusive (for indexing the array of marks). The
comparison of the converted character with an apostrophe therefore never
succeeds, meaning that '' doesn't do anything.

Based on the patch by Francis Rounds <francis.rounds@4bridgeworks.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-28 16:23:05 +02:00
Denys Vlasenko
de1996dac5 vi: make "g<key>" error message less likely to show garbage
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-15 13:53:42 +02:00
Denys Vlasenko
3e134ebf6a *: slap on a few ALIGN1/2s where appropriate
The result of looking at "grep -F -B2 '*fill*' busybox_unstripped.map"

   text	   data	    bss	    dec	    hex	filename
 829901	   4086	   1904	 835891	  cc133	busybox_before
 829665	   4086	   1904	 835655	  cc047	busybox

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-22 18:09:21 +02:00
Denys Vlasenko
7f3a2a2256 join some common strings, -400 bytes
function                                             old     new   delta
print_intel_cstates                                  499     511     +12
file_insert                                          355     364      +9
dpkg_main                                           2944    2940      -4
ifenslave_main                                       645     640      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 21/-9)              Total: 12 bytes
   text	   data	    bss	    dec	    hex	filename
 937564	    932	  17676	 956172	  e970c	busybox_old
 937164	    932	  17676	 955772	  e957c	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-08 11:24:44 +02:00
Maninder Singh
97f2f7ca7f Removes stray empty line from code
This patch removes stray empty line from busybox code
reported by script find_stray_empty_lines

Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
Signed-off-by: Akhilesh Kumar <akhilesh.k@samsung.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-13 03:25:46 +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
Andrew Fuller
4d8ddb810d vi: basic undo feature shouldn't depend on yankmark
Currently basic undo functionality with the 'u' key depends on
FEATURE_VI_YANKMARK. These two features are separate, so we can remove this
dependency.

Signed-off-by: Andrew Fuller <abf@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-03 18:18:25 +02:00
Denys Vlasenko
49acc1a761 vi: make BACKSPACE and DELETE join lines at start/end of line
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12 21:15:34 +01:00
Ron Yorston
70f4320b40 vi: fix reading of file after last line
If the :r command is used to read a file after the last line of the
buffer the last line of the buffer and the first line of the file
are joined.  An extra blank line appears at the end of the buffer.

   file 1
   file 1
   file 1file 2
   file 2
   file 2

	~
	~

The insertion point is normally at the start of the line following the
specified line.  When the specified line is the last one the next_line
function baulks at moving to the non-existent following line.

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-07 18:23:29 +01:00
Ron Yorston
e5213cee38 vi: failure to open file is not an error when initialising buffer
Commit 32afd3a introduced these regressions on the master branch:

Starting vi with no filename on the command line gives the status message
"'(null)' Bad address" instead of "- No file 1/1 100%".

Starting vi with a non-existent file on the command line gives the status
message "'new.txt' No such file or directory" instead of "- new.txt 1/1 100%"

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-07 17:00:48 +01:00
Denys Vlasenko
05399fc53d vi: fix incorrect memory access on brace matching. Closes 7256
While at it, fix brace matching to actually show the match
(missed fflush was causing cursor positioning to be buffered);
shorten brace matching code; remove unused macro indirection
in indicate_error().

Custom linker script 'busybox_ldscript' found, using it
function                                             old     new   delta
indicate_error                                         -      61     +61
mysleep                                               43      56     +13
char_insert                                          483     486      +3
find_pair                                            167     124     -43
Indicate_Error                                        61       -     -61
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 2/1 up/down: 77/-104)           Total: -27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-15 17:06:10 +02:00
Denys Vlasenko
32afd3aa60 vi: some simplifications
function                                             old     new   delta
file_insert                                          301     315     +14
init_text_buffer                                     179     171      -8
colon                                               2889    2878     -11
file_size                                             37       -     -37
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/2 up/down: 14/-56)            Total: -42 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-05 22:57:46 +02:00
Denys Vlasenko
e7430867a8 vi: clear undo buffer when we change to another file
function                                             old     new   delta
init_text_buffer                                     156     190     +34
undo_push                                            360     382     +22
count_lines                                           74      72      -2
undo_pop                                             246     222     -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 56/-26)             Total: 30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-03 12:47:48 +02:00
Denys Vlasenko
2c51202aec vi: undo code shrink
function                                             old     new   delta
undo_push                                            414     395     -19
do_cmd                                              4803    4761     -42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-03 01:45:05 +02:00
Jody Bruchon
a8d6f9bee4 vi: undo support for vi with intermediate queuing
function                                             old     new   delta
undo_push                                              -     411    +411
undo_pop                                               -     288    +288
do_cmd                                              4160    4426    +266
char_insert                                          363     483    +120
undo_queue_commit                                      -      61     +61
text_hole_delete                                     108     163     +55
string_insert                                         94     127     +33
colon                                               2864    2882     +18
yank_delete                                           92     101      +9
vi_main                                              273     280      +7
dot_scroll                                            88      93      +5
dot_right                                             29      34      +5
dot_prev                                              20      25      +5
dot_next                                              20      25      +5
dot_left                                              24      29      +5
dot_end                                               20      25      +5
dot_begin                                             20      25      +5
init_text_buffer                                     154     156      +2
text_hole_make                                       145     142      -3
file_insert                                          333     318     -15
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 15/2 up/down: 1305/-18)        Total: 1287 bytes

(without queuing it's ~870 bytes)

Signed-off-by: Jody Bruchon <jody@jodybruchon.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-02 13:49:26 +02:00
Denys Vlasenko
264f37363d vi: make regexp search case-insensitive if ":set ignorecase" is active
Reported by Dan Moinescu <dan@moinescu.net>.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-04-21 15:51:41 +02:00
Denys Vlasenko
9e7c002182 vi: code shrink
function                                             old     new   delta
status_line_bold_errno                                 -      32     +32
colon                                               2891    2873     -18
file_insert                                          354     313     -41
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 32/-59)            Total: -27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-15 02:17:29 +01:00
Ron Yorston
cb5aa725df vi: fix adjustment of buffer on partial file read
The second argument to text_hole_delete was incorrect: it should
be a pointer to the end of the hole.

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-15 02:10:07 +01:00
Denys Vlasenko
778794d1dd *: reuse more strings
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-01-22 10:13:52 +01:00
Denys Vlasenko
6830ade6aa whitespace fixes. no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-01-15 13:58:01 +01:00
Denys Vlasenko
60cb48ca50 whitespace cleanup. no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-01-14 15:57:44 +01:00
Denys Vlasenko
d3dff879f0 vi: save/restore screen upon invocation
function                                             old     new   delta
vi_main                                              253     273     +20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-06-11 13:53:26 +02:00
Denys Vlasenko
04b52892ed vi: nuke FEATURE_VI_OPTIMIZE_CURSOR
It is not Unicode safe, it is not saving much of I/O, and it's large:

function                                             old     new   delta
vi_main                                              255     253      -2
go_bottom_and_clear_to_eol                            28      26      -2
do_cmd                                              4194    4182     -12
show_status_line                                     388     374     -14
strncat                                               39       -     -39
__GI_strncat                                          39       -     -39
refresh                                              774     724     -50
place_cursor                                         276      83    -193
------------------------------------------------------------------------------
(add/remove: 0/3 grow/shrink: 0/6 up/down: 0/-351)           Total: -351 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-06-11 13:51:38 +02:00
Denys Vlasenko
605f2641d8 vi: do not set autoindent by default
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-06-11 01:53:33 +02:00
Dennis Groenen
c0657e0d0a vi: add ":prev" command support
function                                             old     new   delta
colon                                               2844    2891     +47
vi_main                                              243     255     +12
text_yank                                             54      56      +2
refresh                                              780     774      -6

Signed-off-by: Dennis Groenen <tj.groenen@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-01-31 14:12:38 +01:00
Denys Vlasenko
800a9a056a vi: move mark[i] pointers if text[] moves after realloc
While at it, optimized :s/find/repl/ a bit

function                                             old     new   delta
text_hole_make                                       120     150     +30
colon                                               2848    2844      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-01-31 14:10:26 +01:00
Denys Vlasenko
6e8861b5f1 *: better comments on termios manipulations. No code changes.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-01-15 23:00:13 +01:00
Denys Vlasenko
1fd7129bc6 vi: fix [end] key handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-11-28 04:55:48 +01:00
Denys Vlasenko
12e154f0cf vi: prevent unlimited recursion in do_cmd(). Closes 4153
function                                             old     new   delta
do_cmd                                              4284    4194     -90

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-09-09 12:35:49 +02:00
Denys Vlasenko
4e552a70ec less: optionally query terminal size via "ESC [ 6 n". Closes bug 2659.
+7 bytes is not selected, +100 if selected.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-07-25 15:18:20 +02:00
Denys Vlasenko
066f399566 vi: tweak regex.h include
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-07-03 03:19:43 +02:00
Walter Harms
b9ba580917 vi: fix regex search, make it selectable in config
function                                             old     new   delta
char_search                                          134     214     +80
find_pair                                            187     169     -18
mycmp                                                 37       -     -37

Signed-off-by: Walter Harms <wharms@bfs.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-06-27 02:59:37 +02:00
Denys Vlasenko
66426760be *: remove "Options:" string from help texts
function                                             old     new   delta
packed_usage                                       28706   28623     -83

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-06-05 03:58:28 +02:00
Cristian Ionescu-Idbohrn
9a296fbeab vi.c: remove warning: variable 'sp' set but not used
Signed-off-by: Cristian Ionescu-Idbohrn <cii@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-05-16 03:53:43 +02:00
Denys Vlasenko
60a9414cad fix "variable 'foo' set but not used" warnings
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-05-13 20:57:01 +02:00
Pere Orga
6a3e01d5a9 move help text from include/usage.src.h to debianutils/*.c e2fsprogs/*.c editors/*.c loginutils/*.c mailutils/*.c
Signed-off-by: Pere Orga <gotrunks@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-04-03 01:33:55 +02:00
Denys Vlasenko
0ef64bdb40 *: make GNU licensing statement forms more regular
This change retains "or later" state! No licensing _changes_ here,
only form is adjusted (article, space between "GPL" and "v2" and so on).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-08-16 20:14:46 +02:00
Denys Vlasenko
c5fb0ada9b vi: fix "ask terminal" code
function                                             old     new   delta
edit_file                                            761     793     +32
refresh                                              773     780      +7
query_screen_dimensions                               63      54      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-07-21 12:39:42 +02:00
Denys Vlasenko
243d1757d7 remove some dead assignments, add a TODO comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-07-04 04:26:55 +02:00
Denys Vlasenko
9f82d0be61 vi: fix "set ic" command; code shrink while at it. closes bug 1765
function                                             old     new   delta
colon                                               2970    2848    -122

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-05-19 01:54:37 +02:00
Denys Vlasenko
d9a3e89f50 consolidate ESC sequences
function                                             old     new   delta
bell                                                   2       -      -2
CMdown                                                 2       -      -2
Ceos                                                   4       -      -4
Ceol                                                   4       -      -4
CMup                                                   4       -      -4
SOs                                                    5       -      -5
SOn                                                    5       -      -5
CMrc                                                   9       -      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-05-16 23:42:13 +02:00
Denys Vlasenko
94043e8ad2 lineedit: change how cmdedit_set_out_char works
Rename two badly names functions, use "clear to end of screen"
to eliminate annoying problems with clearing wide/combining chars,
and such. Run tested.

function                                             old     new   delta
put_cur_glyph_and_inc_cursor                           -     124    +124
put_till_end_and_adv_cursor                            -      24     +24
input_delete                                         125     130      +5
Ceos                                                   5       4      -1
Ceol                                                   5       4      -1
input_end                                             24       -     -24
cmdedit_set_out_char                                 122       -    -122
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 1/2 up/down: 153/-148)            Total: 5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-05-11 14:49:13 +02:00
Denys Vlasenko
c175c46647 vi: discover window size even on serial consoles. optional
function                                             old     new   delta
edit_file                                            671     761     +90
wh_helper                                              -      57     +57
query_screen_dimensions                               54      63      +9
ar_main                                              533     542      +9
refresh                                              767     773      +6
vi_main                                              242     243      +1
text_yank                                             56      54      -2
get_terminal_width_height                            180     135     -45
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 5/2 up/down: 172/-47)           Total: 125 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-04-18 22:09:30 -07:00
Denys Vlasenko
def4783a8a vi: remove superfluous check on filename == ""
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-04-18 20:39:41 -07:00
Denys Vlasenko
04cecd5e61 vi: code shrink
function                                             old     new   delta
vi_main                                              250     242      -8
colon                                               2980    2970     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-18)             Total: -18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-04-16 22:13:55 -07:00
Denys Vlasenko
2bb651ae10 vi: code shrink; save/restore errno in signal handlers
function                                             old     new   delta
query_screen_dimensions                                -      54     +54
suspend_sig                                           50      64     +14
cont_sig                                              65      66      +1
catch_sig                                             42      32     -10
winch_sig                                             88      60     -28
edit_file                                            719     671     -48
refresh                                              848     767     -81
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/4 up/down: 69/-167)           Total: -98 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-04-16 20:55:52 -07:00
Denys Vlasenko
35fdb1bc9c vi: fix NUM + "$" handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-03-26 16:10:14 +01:00