aboutsummaryrefslogtreecommitdiff
path: root/libbb/lineedit.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* | win32: handle Unix-style absolute paths for executablesRon Yorston2020-08-131-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As noted in commit 548ec7045 (win32: interpret absolute paths as relative to %SYSTEMDRIVE%) a path starting with a '/' in the Unix world is treated as relative to the current drive by Windows. To avoid ambiguity that commit considered certain such paths to be relative to %SYSTEMDRIVE%. Extend this to paths representing executables. Add the functions need_system_drive() and auto_add_system_drive() to detect the need for a system drive prefix and to add it if necessary. Use these functions in: - the 'which' applet - the find_executable() function - tab-completion code - PATH look-up, shellexec(), describe_command() and find_command() in ash - parse_interpreter() and mingw_spawn_1() With these changes executable paths starting with a slash are handled consistently, whatever the current drive.
* | Merge branch 'busybox' into mergeRon Yorston2020-07-091-1/+1
|\|
| * suppress a few compile warningsDenys Vlasenko2020-06-241-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | win32: more improvements to 'c:file' pathsRon Yorston2020-03-291-1/+1
| | | | | | | | | | | | | | | | Tab-completion of 'c:file' paths was leaking memory and incorrectly included BusyBox applets and shell built-ins. Fix handling of 'c:file' paths used as arguments to spawn functions. Otherwise things like 'timeout 5 c:busybox sleep 99' don't work.
* | Merge branch 'busybox' into mergeRon Yorston2020-02-151-3/+14
|\|
| * ash,hush: allow builtins to be tab-completed, closes 7532Ron Yorston2020-01-291-3/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Merge branch 'busybox' into mergeRon Yorston2020-01-081-1/+1
|\|
| * clang/llvm 9 fix - do not eliminate a store to a fake "const"Denys Vlasenko2019-10-251-1/+1
| | | | | | | | | | | | | | This is *much* better (9 kbytes better) than dropping "*const" optimization trick. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2019-05-271-3/+10
|\|
| * style fix, no code changesDenys Vlasenko2019-05-141-3/+10
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | lineedit: reinstate tab-completion of '~/'Ron Yorston2019-04-091-1/+7
| | | | | | | | | | | | Commit 195902a64 (lineedit: improvements to tab completion) disabled tab-completion of usernames. It was too heavy-handed, in that it also removed tab-completion of '~/'.
* | win32: improved support for c:path path namesRon Yorston2019-03-301-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Microsoft Windows permits path names of the form 'c:path', without a path separator after the colon. The system records a current directory for each drive and the path is interpreted relative to that. Since Windows API calls understand 'c:path' path names many commands in busybox-w32 already work with them. This commit adds the following: - The 'cd' shell built-in interprets 'c:path' path names correctly. Previously it treated them as relative to the shell's concept of the current working directory, not the current directory of the specified drive. - The 'pwd' shell built-in takes the '-a' option to list the current directory for all drives. - 'c:path' path names are subject to tab-completion. Paths of the form 'c:path' don't work for mapped network drives or paths that have been associated with a drive using SUBST. See GitHub issue #147.
* | win32: add function to convert slashes to backslashesRon Yorston2019-03-151-1/+1
| | | | | | | | | | | | | | | | | | There are now two places where slashes are converted to backslashes throughout a string so it makes sense to create a function to do this. To avoid confusion rename convert_slashes() to bs_to_slash() and call the new function slash_to_bs().
* | lineedit: add a command to change backslashes to slashesRon Yorston2019-03-151-0/+7
| | | | | | | | | | | | | | | | | | | | | | When a path name is copied to a console application using drag and drop the path separator is backslash. To handle this situation in the shell add an editing command (Ctrl-Z) to convert all backslashes on the current line to slashes. See GitHub issue #149. Also remove some unused code from read_key().
* | win32: changes to user idsRon Yorston2019-03-101-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Formalise the use of 0 as the uid of a process running with elevated privileges: - Rewrite getuid(2) to return DEFAULT_UID by default and 0 if the process has elevated privileges. - geteuid(2) and the corresponding functions for groups are aliases for getuid(2). - Change root's home directory to be whatever GetSystemDirectory() returns, probably C:/Windows/System32 in most cases. - Remove the special handling of geteuid(2) in the line editing code. With these changes the shell started by 'su' is a lot more like a *nix root shell.
* | win32: add a function to detect running with elevated privilegesRon Yorston2019-03-091-0/+3
| | | | | | | | | | Add is_admin() and use it to alter the command prompt in the line editor when running with admin privileges.
* | libbb: copy entire match during tab-completionRon Yorston2019-03-011-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | Because tab-completion is case-insensitive the matching text might differ from what the user typed. Insert the whole of the matching text, not just the tail. Thus: $ cd doc<TAB> now expands to: $ cd Documents/
* | Merge branch 'busybox' into mergeRon Yorston2019-02-121-4/+5
|\|
| * lineedit: fix SEGV in isk, hexedit, ed, closes 11661Denys Vlasenko2019-02-041-4/+5
| | | | | | | | | | | | | | | | | | | | | | 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>
* | Merge branch 'busybox' into mergeRon Yorston2019-01-101-9/+23
|\|
| * randomconfig fixesDenys Vlasenko2018-12-271-8/+10
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>