aboutsummaryrefslogtreecommitdiff
path: root/libbb/lineedit.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* win32: case-sensitivity in tab completionRon Yorston2023-04-191-31/+62
| | | | | | | | | | | | | | | | | | The tab-completion code treated all matches as case-insensitive because that's how Microsoft Windows handles filenames. This is now inadequate, as shell builtins, functions and aliases are case sensitive. Modify the treatment of case-sensitivity in tab completion: - Track whether each potential match is case-insensitive (filename) or case-sensitive (shell builtin, function or alias). - When comparing matches use a case-insensitive comparison if either value is a filename. Otherwise use a case-sensitive comparison. Adds 64 bytes.
* Merge branch 'busybox' into mergeRon Yorston2023-04-171-2/+2
|\
| * lineedit: fix crash when icanon set with -echoAkos Somfai2023-04-121-2/+2
| | | | | | | | | | | | | | | | | | 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>
| * lineedit: fix matching of directories when searching PATHRon Yorston2023-03-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | ash: add support for INT trapRon Yorston2023-04-031-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The trap builtin now handles INT. As before, other signals (from a limited list) are accepted but their traps don't have any effect. There's some variability in how shells handle traps. This patch upholds that proud tradition. Various changes are needed to make this work: - Line editing has a new flag to ignore Ctrl-C. - If INT is being trapped or ignored don't call raise_interrupt(). - A minimal implementation of dotrap() is provided. - Call dotrap() when the read builtin or line input detect Ctrl-C. - Adjust Ctrl-C detection when the INT trap is changed. - Set may_have_traps when an INT trap is set. Costs 368-448 bytes. (GitHub issue #303)
* | lineedit: fix matching of directories when searching PATHRon Yorston2023-03-241-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | win32: add support for virtual terminal inputRon Yorston2023-03-051-12/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Alter certain applets to support virtual terminal input, if enabled. In many places this is achieved by building previously excluded upstream terminal-handling code. The busybox-w32 implementation of termios(3) functions does nothing if virtual terminal input is disabled, so it can be invoked regardless. Some applet-specific terminal-handling code is also required. This affects less, more, vi and command line editing in the shell. (The `more` applet isn't enabled in the default configuration.) This series of patches adds about 1.7KB to the binaries.
* | Merge branch 'busybox' into mergeRon Yorston2023-02-131-7/+10
|\|
| * shell: fix SIGWINCH and SIGCHLD (in hush) interrupting line input, closes 15256Denys Vlasenko2023-01-261-7/+10
| | | | | | | | | | | | | | | | | | | | 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>
* | Merge branch 'busybox' into mergeRon Yorston2023-01-051-11/+13
|\|
| * shell: fix compile failures in some configsDenys Vlasenko2023-01-031-11/+13
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | win32: revert special treatment of Unix-style absolute pathsRon Yorston2022-10-261-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 605972390 (win32: handle Unix-style absolute paths for executables) added special treatment of paths for executables starting with a slash. Such paths are absolute on Unix but are relative to the current drive on Windows. On reflection this commit did more than necessary. Later commits provided special treatment only for paths starting with locations traditionally used to contain binaries on Unix. This is probably sufficient. Problems introduced by commit 605972390 include: - If the current drive isn't the system drive tab completion of a command starting with a slash confusingly references the system drive. - Building busybox-w32 with w64devkit fails on drives other than the system drive. Revert the changes introduced by commit 605972390. This saves 192 bytes. (GitHub issue #239)
* | Merge branch 'busybox' into mergeRon Yorston2022-10-121-0/+6
|\|
| * lineedit: get PWD from ashRon Yorston2022-07-031-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Merge branch 'busybox' into mergeRon Yorston2022-06-271-1/+11
|\|
| * ash,hush: use HOME for tab completion and promptsRon Yorston2022-06-261-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | lineedit: case-insensitive matching for '~'Ron Yorston2022-05-111-0/+4
| | | | | | | | | | | | | | | | Use case-insensitive matching when determining if the directory name in the prompt can be shortened using '~'. This doesn't seem to have been a problem, as directories are often canonicalized, but it doesn't have any great cost.
* | win32: allow preference for applets to be disabled at runtimeRon Yorston2022-05-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The default busybox-w32 configuration enables the PREFER_APPLETS and SH_STANDALONE features. Sometimes it may be desirable to override the default preference for applets, for example, if an applet needs to be replaced by an external program with additional features. Add support for the environment variable BB_OVERRIDE_APPLETS. Its value may be: - a single dash ('-'): all applets are overridden; - a space-separated list of names: only the specified applets are overridden.
* | Merge busybox into mergeRon Yorston2022-02-091-5/+29
|\| | | | | | | | | | | | | | | Fix conflicts in reset and ash. Redefine the new safe_read_key() as a reference to read_key(). Disable SHA256_HWACCEL.
| * libbb: shrink lineedit_read_key()Denys Vlasenko2022-01-181-10/+16
| | | | | | | | | | | | | | function old new delta lineedit_read_key 237 231 -6 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash,hush: fix handling of SIGINT while waiting for interactive inputDenys Vlasenko2022-01-171-3/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Merge branch 'busybox' into mergeRon Yorston2021-10-131-38/+56
|\|
| * shell: do not read user database for every prompt - only for those which need itDenys Vlasenko2021-10-111-27/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * Make const ptr assign as function call in clangYU Jincheng2021-10-091-1/+1
| | | | | | | | | | | | | | | | - 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>
| * *: generalize "const trick"YU Jincheng2021-10-071-3/+2
| | | | | | | | | | | | | | | | 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>
| * libbb/lineedit: tweak #if indenting, no code changesDenys Vlasenko2021-09-251-8/+8
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2021-09-211-1/+10
|\|
| * libbb/lineedit: do not escape %^=+}]:, escape ~? in tab completionDenys Vlasenko2021-09-171-1/+10
| | | | | | | | | | | | | | function old new delta .rodata 104185 104180 -5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | win32: more efficient tests for executablesRon Yorston2021-07-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | file_is_executable() calls access(2) and stat(2); in this case our WIN32 implementation also calls stat(2). Avoid this unnecessary duplication by copying the required test from the WIN32 access(2). In find_executable() it's possible to avoid calling file_is_executable() if add_win32_extension() returns TRUE as the latter will already have verified that the file is executable. Replace a call to file_is_executable() in the tab completion code with the equivalent tests, avoiding (up to) two calls to stat(2). These changes don't affect the size of the binary and should be faster.
* | Merge branch 'busybox' into mergeRon Yorston2021-05-141-2/+2
|\|
| * fix gcc-11.0 warningsDenys Vlasenko2021-04-141-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * lineedit: fix tab completion with equal signNatanael Copa2021-04-111-1/+1
| | | | | | | | | | | | | | | | 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>
* | libbb: fix another tab-completion corner caseRon Yorston2021-03-171-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 90f35327c (libbb: avoid problems with quoted characters in tab completion) avoided a conflict between the code to quote special characters and that to display case-preserved filenames. Here's another one. I'd installed a third-party binary on Microsoft Windows and wanted to execute it from a busybox-w32 shell which didn't have it in its path. No problem: $ c:/prog<tab> $ c:/Program<tab> Program Files/ ProgramData $ c:/Program\<tab> $ c:/PProgram I was too quick to enter the final <tab>, I'd meant to add a space. A trailing backslash is effectively removed by the tab completion matching code but it remains on the display. This confuses the code to display case-preserved filenames. Upstream BusyBox just ends up with a spurious backslash in the name. Bash rewrites the command line to remove the surplus backslash. Fix the issue in busybox-w32 by leaving the backslash in the name, even for matching purposes. This will never result in a match, thus affording the user a change to correct their mistake.
* | Merge branch 'busybox' into mergeRon Yorston2021-03-011-15/+4
|\|
| * lineedit: support empty PATH entries in tab completionRon Yorston2021-02-231-6/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | win32: code shrinkRon Yorston2021-02-131-5/+15
| | | | | | | | | | | | | | | | Rewrite the recent change to tab completion so it only needs one call to sprintf. Then replace sprintf with strcpy/stpcpy, both there and in a couple of other places. Saves 40 bytes.
* | libbb: avoid problems with quoted characters in tab completionRon Yorston2021-02-121-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 9e341902d (libbb: copy entire match during tab-completion) adjusted the display of matches during tab completion to make any changes in case visible. Unfortunately the presence of quoted special characters upsets the display: $ touch t+1+2+3 t+1+4+5 $ ls t+1<TAB> changes the command to: $ lst\+1\+ In such cases just revert to the upstream code which only displays the tail of the match, giving: $ ls t+1\+
* | Merge branch 'busybox' into mergeRon Yorston2021-02-051-4/+4
|\|
| * libbb: introduce and use fputs_stdoutRon Yorston2021-02-031-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Merge branch 'busybox' into mergeRon Yorston2021-01-141-48/+81
|\|
| * lineedit: code shrinkDenys Vlasenko2020-12-211-5/+5
| | | | | | | | | | | | | | function old new delta read_line_input 3171 3157 -14 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * lineedit: add a comment about possible use of tcflush()Denys Vlasenko2020-12-211-0/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * bc: do not allocate line editing state until neededDenys Vlasenko2020-12-211-7/+11
| | | | | | | | | | | | | | | | | | | | | | 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>
| * lineedit: disable completion and fancy prompts if no shells are selectedDenys Vlasenko2020-12-161-13/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * lineedit: use strncmp instead of is_prefixed_with (we know the length)Denys Vlasenko2020-12-161-22/+25
| | | | | | | | | | | | Also: add comments, rename some variables Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * lineedit: remove ->path_lookup if ash is not configuredDenys Vlasenko2020-12-161-0/+2
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * lineedit: match local directories when searching PATHRon Yorston2020-12-161-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * lineedit: omit directories when tab-completing from PATHRon Yorston2020-12-161-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | 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>
| * lineedit: fix unicode characters in promptAudun-Marius Gangstø2020-11-211-4/+11
| | | | | | | | | | | | | | | | 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>
* | win32: code shrink Unix-style path handlingRon Yorston2020-08-231-1/+2
| | | | | | | | | | | | | | | | Replace auto_add_system_drive() with alloc_system_drive() which leaves space for a possible filename extension. This makes it possible to drop alloc_win32_extension() and auto_win32_extension(). Saves 144 bytes.