* the puzzling message on error is replaced with strerror(errno)
so it should be even more detailed and smaller at the same time.
* merged code in edit_file() and code for ':edit <file>' in colon() into
new func init_text_buffer(). Was horribly duplicate. Moved most of
error/sanity checking to file_insert(). Result is that you get a proper
validation (prevent reading /dev/*) and error messages for ':r <file>'
* renamed 'cfn' to 'current_filename' for improved readability
* merged smallint vi_readonly and readonly into bitfields into
readonly_mode to save space.
* added text_size variable to keep track how big the text buffer is.
This is used to fix a buffer overflow. To reproduce bug:
./busybox vi TODO
:r Makefile
vi segfaults due to no buffer checking is done at all. som redesign is
needed here but i added a check in text_hole_make() to aviod the
segfault at least.
* removed isblnk() and use isblank(3) instead.
* fixed compiler warning by displaying the return code for :!<command>
This makes things bigger than needed but since the patch reduces the
overall size... (see below)
* new func next_tabstop(int) merges some duplicate code. There are more
cuplicode here but i couldnt find a good way to merge them.
* Fix *ANNOYING* placement of cursor on '\t' characters. To reproduce:
echo -e "\thello" > file1
./busybox vi file1
Try to insert some text at the beginning of line. Text will be inserted
but cursor is blinking somewhere else. The patch should make busybox vi
behave more like original vi(m). Costs a few bytes but its worth it
imho.
* new_text() is moved into init_text_buffer()
* the previously added update_ro_status() was moved info file_insert due
to duplication removal mentioned above.
function old new delta
init_text_buffer - 245 +245
file_insert 312 420 +108
next_tabstop - 82 +82
text_hole_make 154 171 +17
do_cmd 5093 5100 +7
static.cmd_mode_indicator - 5 +5
refresh 1248 1253 +5
current_filename - 4 +4
yank_delete 161 164 +3
what_reg 96 99 +3
end_cmd_q 78 81 +3
char_insert 440 442 +2
readonly_mode - 1 +1
vi_readonly 1 - -1
setops 154 153 -1
readonly 1 - -1
vi_setops 4 1 -3
string_insert 161 158 -3
cfn 4 - -4
show_status_line 532 514 -18
readit 519 500 -19
move_to_col 161 138 -23
vi_main 495 433 -62
isblnk 75 - -75
.rodata 4751 4655 -96
edit_file 892 787 -105
new_text 125 - -125
update_ro_status 131 - -131
colon 3848 3667 -181
------------------------------------------------------------------------------
(add/remove: 5/6 grow/shrink: 8/10 up/down: 485/-848) Total: -363
bytes
text data bss dec hex filename
34751 873 4260 39884 9bcc busybox_old
34439 877 4260 39576 9a98 busybox_unstripped
awk: some 'lineno' vars were shorts, made them ints (code got smaller)
awk: rename global t to global ttt. still an awful name, but at least
you can grep for it now.
function old new delta
ttt - 28 +28
mysleep 104 120 +16
readit 408 418 +10
lineno 2 4 +2
parse_program 338 339 +1
evaluate 6446 6445 -1
syntax_error 25 23 -2
next_token 917 915 -2
new_node 26 24 -2
tv 16 8 -8
skip_spaces 68 53 -15
t 28 - -28
rfds 128 - -128
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 4/6 up/down: 57/-186) Total: -129 bytes
('size' happily displays 0 bytes in data and bss,
but in reality sed.o used 180 bytes of it). Oh well.
function old new delta
pipe_putc 67 76 +9
sed_main 627 633 +6
get_next_line 161 166 +5
bbg 180 - -180
(add/remove: 0/1 grow/shrink: 3/0 up/down: 20/-180) Total: -160 bytes
sed: also make sed -i failure message less cryptic