diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-03 14:11:08 +0200 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-03 14:11:08 +0200 |
commit | 3926363214bfa783db08c931d867dbf4855d31ef (patch) | |
tree | 963ffa915ac6cc74df491234c191e41b15f98613 /libbb | |
parent | 76939e7b72937a5a2d00be3f62a6d2fa2757bdc9 (diff) | |
download | busybox-w32-3926363214bfa783db08c931d867dbf4855d31ef.tar.gz busybox-w32-3926363214bfa783db08c931d867dbf4855d31ef.tar.bz2 busybox-w32-3926363214bfa783db08c931d867dbf4855d31ef.zip |
lineedit: on tab completion, show filenames obly in all cases (bash compat)
function old new delta
complete_cmd_dir_file 731 730 -1
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/lineedit.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index a917c5f92..d2b808adf 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -751,6 +751,7 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) | |||
751 | continue; /* don't print an error */ | 751 | continue; /* don't print an error */ |
752 | 752 | ||
753 | while ((next = readdir(dir)) != NULL) { | 753 | while ((next = readdir(dir)) != NULL) { |
754 | unsigned len; | ||
754 | const char *name_found = next->d_name; | 755 | const char *name_found = next->d_name; |
755 | 756 | ||
756 | /* .../<tab>: bash 3.2.0 shows dotfiles, but not . and .. */ | 757 | /* .../<tab>: bash 3.2.0 shows dotfiles, but not . and .. */ |
@@ -767,18 +768,15 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) | |||
767 | if (stat(found, &st) && lstat(found, &st)) | 768 | if (stat(found, &st) && lstat(found, &st)) |
768 | goto cont; /* hmm, remove in progress? */ | 769 | goto cont; /* hmm, remove in progress? */ |
769 | 770 | ||
770 | /* save only name if we scan PATH */ | 771 | /* Save only name */ |
771 | if (paths[i] != dirbuf) | 772 | len = strlen(name_found); |
772 | strcpy(found, name_found); | 773 | found = xrealloc(found, len + 2); /* +2: for slash and NUL */ |
774 | strcpy(found, name_found); | ||
773 | 775 | ||
774 | if (S_ISDIR(st.st_mode)) { | 776 | if (S_ISDIR(st.st_mode)) { |
775 | unsigned len1 = strlen(found); | 777 | /* name is a directory, add slash */ |
776 | /* name is a directory */ | 778 | found[len] = '/'; |
777 | if (found[len1-1] != '/') { | 779 | found[len + 1] = '\0'; |
778 | found = xrealloc(found, len1 + 2); | ||
779 | found[len1] = '/'; | ||
780 | found[len1 + 1] = '\0'; | ||
781 | } | ||
782 | } else { | 780 | } else { |
783 | /* skip files if looking for dirs only (example: cd) */ | 781 | /* skip files if looking for dirs only (example: cd) */ |
784 | if (type == FIND_DIR_ONLY) | 782 | if (type == FIND_DIR_ONLY) |
@@ -796,10 +794,8 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) | |||
796 | if (paths != path1) { | 794 | if (paths != path1) { |
797 | free(paths[0]); /* allocated memory is only in first member */ | 795 | free(paths[0]); /* allocated memory is only in first member */ |
798 | free(paths); | 796 | free(paths); |
799 | } else if (dirbuf) { | ||
800 | pf_len += strlen(dirbuf); | ||
801 | free(dirbuf); | ||
802 | } | 797 | } |
798 | free(dirbuf); | ||
803 | 799 | ||
804 | return pf_len; | 800 | return pf_len; |
805 | } | 801 | } |