summaryrefslogtreecommitdiff
path: root/libbb/lineedit.c
AgeCommit message (Collapse)Author
2023-04-12lineedit: fix crash when icanon set with -echoAkos Somfai
When icanon is set with -echo (e.g. ssh from an emacs shell) then S.state will remain null but later it will be deferenced causing ash to crash. Fix: additional check on state. Signed-off-by: Akos Somfai <akos.somfai@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-29lineedit: fix matching of directories when searching PATHRon Yorston
Commit 8baa643a3 (lineedit: match local directories when searching PATH) included subdirectories of the current directory in the search when tab-completing commands. Unfortunately a short time later commit 1d180cd74 (lineedit: use strncmp instead of is_prefixed_with (we know the length)) broke this feature by returning an incorrect length for the array of paths. Fix the length and reinstate matching of subdirectories. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-26shell: fix SIGWINCH and SIGCHLD (in hush) interrupting line input, closes 15256Denys Vlasenko
function old new delta record_pending_signo 32 63 +31 lineedit_read_key 231 224 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 31/-7) Total: 24 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-03shell: fix compile failures in some configsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-03lineedit: get PWD from ashRon Yorston
The line editing code and ash disagree when the current directory is changed to a symbolic link: ~ $ mkdir real ~ $ ln -s real link ~ $ cd link ~/real $ pwd /home/rmyf36/link Note the prompt says we're in ~/real. Bash does: [rmy@random ~]$ cd link [rmy@random link]$ pwd /home/rmyf36/link Ash uses the name supplied by the user while the line editing code calls getcwd(3). The discrepancy can be avoided by fetching the value of PWD from ash. Hush calls getcwd(3) when the directory is changed so there's no disagreement with the line editing code. There is no standard how shells should handle cd'ing into symlinks. function old new delta parse_and_put_prompt 838 869 +31 Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-06-26ash,hush: use HOME for tab completion and promptsRon Yorston
ash and hush correctly use the value of HOME for tilde expansion. However the line editing code in libbb obtains the user's home directory by calling getpwuid(). Thus tildes in tab completion and prompts may be interpreted differently than in tilde expansion. When the line editing code is invoked from a shell make it use the shell's interpretation of tilde. This is similar to how GNU readline and bash collaborate. function old new delta get_homedir_or_NULL 29 72 +43 optschanged 119 126 +7 hush_main 1204 1211 +7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 57/0) Total: 57 bytes v2: Always check for HOME before trying the password database: this is what GNU readline does. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-18libbb: shrink lineedit_read_key()Denys Vlasenko
function old new delta lineedit_read_key 237 231 -6 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-17ash,hush: fix handling of SIGINT while waiting for interactive inputDenys Vlasenko
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>
2021-10-11shell: do not read user database for every prompt - only for those which need itDenys Vlasenko
function old new delta get_user_strings - 52 +52 get_homedir_or_NULL - 23 +23 parse_and_put_prompt 823 838 +15 null_str 1 - -1 complete_cmd_dir_file 814 812 -2 deinit_S 51 42 -9 read_line_input 3059 3015 -44 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 1/3 up/down: 90/-56) Total: 34 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-09Make const ptr assign as function call in clangYU Jincheng
- This can act as memory barrier in clang to avoid read before assign of a const ptr Signed-off-by: LoveSy <shana@zju.edu.cn> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-07*: generalize "const trick"YU Jincheng
While at it, change all "__asm__" to "asm" Co-authored-by: canyie <31466456+canyie@users.noreply.github.com> Signed-off-by: YU Jincheng <shana@zju.edu.cn> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-25libbb/lineedit: tweak #if indenting, no code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-17libbb/lineedit: do not escape %^=+}]:, escape ~? in tab completionDenys Vlasenko
function old new delta .rodata 104185 104180 -5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-14fix gcc-11.0 warningsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-11lineedit: fix tab completion with equal signNatanael Copa
Fix tab completion for the path when equal sign (=) is used. For example: dd if=/dev/ze<tab> Signed-off-by: Natanael Copa <ncopa@alpinelinux.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-23lineedit: support empty PATH entries in tab completionRon Yorston
Zero-length path prefixes can be specified in PATH as a leading or trailing colon or two adjacent colons. POSIX says that the use of zero-length prefixes to refer to the current directory is a legacy feature. Nonetheless the shells in BusyBox respect this feature, as does 'which'. Tab-completion of executables using PATH should support this too. function old new delta complete_cmd_dir_file 934 931 -3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-3) Total: -3 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-03libbb: introduce and use fputs_stdoutRon Yorston
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>
2020-12-21lineedit: code shrinkDenys Vlasenko
function old new delta read_line_input 3171 3157 -14 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-21lineedit: add a comment about possible use of tcflush()Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-21bc: do not allocate line editing state until neededDenys Vlasenko
function old new delta xc_read_line 324 353 +29 free_line_input_t 34 39 +5 xc_vm_init 656 640 -16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 34/-16) Total: 18 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16lineedit: disable completion and fancy prompts if no shells are selectedDenys Vlasenko
function old new delta get_previous_history 51 56 +5 get_next_history 47 52 +5 null_str 1 - -1 beep 10 - -10 bb_msg_unknown 10 - -10 bb_internal_setpwent 24 - -24 remove_chunk 30 - -30 goto_new_line 33 - -33 bb_internal_endpwent 36 - -36 deinit_S 51 - -51 free_tab_completion_data 54 - -54 read_line_input 3171 3114 -57 rewind 68 - -68 add_match 70 - -70 complete_username 77 - -77 quote_special_chars 78 - -78 build_match_prefix 557 - -557 complete_cmd_dir_file 697 - -697 parse_and_put_prompt 823 53 -770 input_tab 926 - -926 ------------------------------------------------------------------------------ (add/remove: 0/17 grow/shrink: 2/2 up/down: 10/-3549) Total: -3539 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16lineedit: use strncmp instead of is_prefixed_with (we know the length)Denys Vlasenko
Also: add comments, rename some variables Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16lineedit: remove ->path_lookup if ash is not configuredDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16lineedit: match local directories when searching PATHRon Yorston
When tab-completing a command we search PATH if the partial text doesn't include a slash. Also match subdirectories of the current directory, in case the user intends to run a binary from one of them. function old new delta complete_cmd_dir_file 894 917 +23 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 23/0) Total: 23 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16lineedit: omit directories when tab-completing from PATHRon Yorston
Only files should be matched when using PATH for tab-completion. function old new delta complete_cmd_dir_file 883 894 +11 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 11/0) Total: 11 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-21lineedit: fix unicode characters in promptAudun-Marius Gangstø
function old new delta parse_and_put_prompt 779 823 +44 Signed-off-by: Audun-Marius Gangstø <audun@gangsto.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-24suppress a few compile warningsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-01-29ash,hush: allow builtins to be tab-completed, closes 7532Ron Yorston
function old new delta complete_cmd_dir_file 678 830 +152 get_builtin_name - 35 +35 optschanged 125 132 +7 hush_main 1069 1076 +7 save_command_ps_at_cur_history 76 78 +2 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 4/0 up/down: 203/0) Total: 203 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25clang/llvm 9 fix - do not eliminate a store to a fake "const"Denys Vlasenko
This is *much* better (9 kbytes better) than dropping "*const" optimization trick. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-14style fix, no code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-04lineedit: fix SEGV in isk, hexedit, ed, closes 11661Denys Vlasenko
fdisk, hexedit and ed calls read_line_edit in libbb/lineedit.c with NULL as first argument. On line 2373 of lineedit.c of busybox version 1.29.3, state->hist_file is referenced without checking the state->flag. This causes segmentation fault on fdisk, hexedit and ed on ARM Cortex-A9. It somehow works on x86_64. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-27randomconfig fixesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-08lineedit: fix "defined but not used" sigaction2 warningDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-08suppress gcc 8 aliasing warningsDenys Vlasenko
function old new delta sigprocmask_SIG_SETMASK - 16 +16 wait_for_child_or_signal 221 213 -8 dowait 432 424 -8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-06bc: unbreak FEATURE_CLEAN_UP buildDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-17Treat custom and applet scripts as appletsRon Yorston
BusyBox has support for embedded shell scripts. Two types can be distinguished: custom scripts and scripts implementing applets. Custom scripts should be placed in the 'embed' directory at build time. They are given a default applet configuration and appear as applets to the user but no further configuration is possible. Applet scripts are integrated with the BusyBox build system and are intended to be used to ship standard applets that just happen to be implemented as scripts. They can be configured at build time and appear just like native applets. Such scripts should be placed in the 'applets_sh' directory. A stub C program should be written to provide the usual applet configuration details and placed in a suitable subsystem directory. It may be helpful to have a configuration option to enable any dependencies the script requires: see the 'nologin' applet for an example. function old new delta scripted_main - 41 +41 applet_names 2773 2781 +8 applet_main 1600 1604 +4 i2cdetect_main 672 674 +2 applet_suid 100 101 +1 applet_install_loc 200 201 +1 applet_flags 100 101 +1 packed_usage 33180 33179 -1 tryexec 159 152 -7 evalcommand 1661 1653 -8 script_names 9 - -9 packed_scripts 123 114 -9 complete_cmd_dir_file 826 811 -15 shellexec 271 254 -17 find_command 1007 990 -17 busybox_main 642 624 -18 run_applet_and_exit 100 78 -22 find_script_by_name 51 - -51 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 6/9 up/down: 58/-174) Total: -116 bytes text data bss dec hex filename 950034 477 7296 957807 e9d6f busybox_old 949918 477 7296 957691 e9cfb busybox_unstripped Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-01lineedit: autocompletion for embedded scriptsRon Yorston
function old new delta complete_cmd_dir_file 811 826 +15 Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-01ash: allow shell scripts to be embedded in the binaryDenys Vlasenko
To assist in the deployment of shell scripts it may be convenient to embed them in the BusyBox binary. 'Embed scripts in the binary' takes any files in the directory 'embed', concatenates them with null separators, compresses them and embeds them in the binary. When scripts are embedded in the binary, scripts can be run as 'busybox SCRIPT [ARGS]' or by usual (sym)link mechanism. embed/nologin is provided as an example. function old new delta packed_scripts - 123 +123 unpack_scripts - 87 +87 ash_main 1103 1171 +68 run_applet_and_exit 78 128 +50 get_script_content - 32 +32 script_names - 10 +10 expmeta 663 659 -4 ------------------------------------------------------------------------------ (add/remove: 4/0 grow/shrink: 2/1 up/down: 370/-4) Total: 366 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-09-30unzip: use printable_string() for printing filenamesDenys Vlasenko
function old new delta unzip_main 2726 2792 +66 printable_string2 - 57 +57 identify 4329 4336 +7 expmeta 659 663 +4 add_interface 99 103 +4 beep_main 286 289 +3 changepath 192 194 +2 builtin_type 115 117 +2 devmem_main 469 470 +1 input_tab 1076 1074 -2 create_J 1821 1819 -2 poplocalvars 314 311 -3 doCommands 2222 2214 -8 do_load 918 902 -16 printable_string 57 9 -48 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 8/6 up/down: 146/-79) Total: 67 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-06hush: fix "unset PS1/PS2", and put them into initial variable setDenys Vlasenko
"unset PS1/PS2" causes prompts to be empty strings function old new delta hush_main 1031 1089 +58 goto_new_line 27 33 +6 fgetc_interactive 244 245 +1 unset_local_var 155 149 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 65/-6) Total: 59 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-25lineedit: allow window size tracking to be disabledRon Yorston
function old new delta lineedit_read_key 269 261 -8 win_changed 47 - -47 read_line_input 3884 3821 -63 cmdedit_setwidth 63 - -63 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 0/2 up/down: 0/-181) Total: -181 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-12-31randomconfig fixesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-11-08lineedit: get terminal width before printing promptDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-11-08lineedit: do not tab-complete any strings which have control charactersDenys Vlasenko
function old new delta add_match 41 68 +27 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-10-12lineedit: improve multiline PS1 - redraw using last PS1 line. Closes 10381Avi Halachmi
This patch only affects prompts with newlines. We redraw the prompt [+ input] occasionally, e.g. during tab completion, history browsing or search, etc, and we expect it to align with prior redraws, such that the visible effect is that only the input changes. With multi-line PS1, redraw always printed the prompt some lines below the old one, which resulted in terminal scroll during every redraw. Now we only redraw the last PS1 line, so vertical alignment is easier to manage (we already calculated it using only the last line, but re-drew all lines - that was the culprit), which fixes those extra scrolls. Notes: - We now use the full prompt for the initial draw, after clear-screen (^L), and after tab-completion choices are displayed. Everything else now redraws using the last/sole prompt line. - During terminal resize we now only redraw the last[/sole] prompt line, which is arguably better because it's hard to do right (and we never did). - Good side effect for reverse-i-search: its prompt now replaces only the last line of the original prompt - like other shells do. function old new delta put_prompt_custom - 66 +66 draw_custom - 66 +66 parse_and_put_prompt 766 806 +40 read_line_input 3867 3884 +17 input_tab 1069 1076 +7 cmdedit_setwidth 61 63 +2 redraw 59 47 -12 put_prompt 46 - -46 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 4/1 up/down: 198/-58) Total: 140 bytes Signed-off-by: Avi Halachmi <avihpit@yahoo.com> 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-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-08-02line editing: make read_line_input() not take timeout paramDenys Vlasenko
It's almost always -1. function old new delta read_line_input 3902 3912 +10 new_line_input_t 24 31 +7 pgetc 583 585 +2 save_command_ps_at_cur_history 80 78 -2 read_line 76 74 -2 fgetc_interactive 246 244 -2 addLines 84 82 -2 doCommands 2226 2222 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/5 up/down: 19/-12) Total: 7 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-29shell: make standalone shell tab-complete "busybox"Denys Vlasenko
function old new delta busybox_main - 624 +624 packed_usage 31758 31777 +19 applet_names 2638 2646 +8 applet_main 1528 1532 +4 applet_install_loc 191 192 +1 run_applet_and_exit 681 78 -603 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 4/1 up/down: 656/-603) Total: 53 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11libbb: consolidate the code to set termios unbuffered modeDenys Vlasenko
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>