diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-21 22:24:46 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-21 22:24:46 +0000 |
commit | d56b47f9a6ec15bebb9291937b3555105c469c47 (patch) | |
tree | 39e5e61bbd7e76de37a0fbe7ee550f42acf6a568 | |
parent | f1282a8792ad531f26b478c6680bafd5416f6b8f (diff) | |
download | busybox-w32-d56b47f9a6ec15bebb9291937b3555105c469c47.tar.gz busybox-w32-d56b47f9a6ec15bebb9291937b3555105c469c47.tar.bz2 busybox-w32-d56b47f9a6ec15bebb9291937b3555105c469c47.zip |
fix type character mixup in command completion
-rw-r--r-- | shell/cmdedit.c | 61 |
1 files changed, 26 insertions, 35 deletions
diff --git a/shell/cmdedit.c b/shell/cmdedit.c index 944be00ab..8409bb267 100644 --- a/shell/cmdedit.c +++ b/shell/cmdedit.c | |||
@@ -539,20 +539,18 @@ static void cmdedit_init(void) | |||
539 | 539 | ||
540 | static char **matches; | 540 | static char **matches; |
541 | static int num_matches; | 541 | static int num_matches; |
542 | static char *add_char_to_match; | ||
543 | 542 | ||
544 | static void add_match(char *matched, int add_char) | 543 | static void add_match(char *matched) |
545 | { | 544 | { |
546 | int nm = num_matches; | 545 | int nm = num_matches; |
547 | int nm1 = nm + 1; | 546 | int nm1 = nm + 1; |
548 | 547 | ||
549 | matches = xrealloc(matches, nm1 * sizeof(char *)); | 548 | matches = xrealloc(matches, nm1 * sizeof(char *)); |
550 | add_char_to_match = xrealloc(add_char_to_match, nm1); | ||
551 | matches[nm] = matched; | 549 | matches[nm] = matched; |
552 | add_char_to_match[nm] = (char)add_char; | ||
553 | num_matches++; | 550 | num_matches++; |
554 | } | 551 | } |
555 | 552 | ||
553 | /* | ||
556 | static int is_execute(const struct stat *st) | 554 | static int is_execute(const struct stat *st) |
557 | { | 555 | { |
558 | if ((!my_euid && (st->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) || | 556 | if ((!my_euid && (st->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) || |
@@ -561,6 +559,7 @@ static int is_execute(const struct stat *st) | |||
561 | (st->st_mode & S_IXOTH)) return TRUE; | 559 | (st->st_mode & S_IXOTH)) return TRUE; |
562 | return FALSE; | 560 | return FALSE; |
563 | } | 561 | } |
562 | */ | ||
564 | 563 | ||
565 | #if ENABLE_FEATURE_COMMAND_USERNAME_COMPLETION | 564 | #if ENABLE_FEATURE_COMMAND_USERNAME_COMPLETION |
566 | 565 | ||
@@ -605,7 +604,7 @@ static void username_tab_completion(char *ud, char *with_shash_flg) | |||
605 | while ((entry = getpwent()) != NULL) { | 604 | while ((entry = getpwent()) != NULL) { |
606 | /* Null usernames should result in all users as possible completions. */ | 605 | /* Null usernames should result in all users as possible completions. */ |
607 | if ( /*!userlen || */ !strncmp(ud, entry->pw_name, userlen)) { | 606 | if ( /*!userlen || */ !strncmp(ud, entry->pw_name, userlen)) { |
608 | add_match(xasprintf("~%s", entry->pw_name), '/'); | 607 | add_match(xasprintf("~%s/", entry->pw_name)); |
609 | } | 608 | } |
610 | } | 609 | } |
611 | 610 | ||
@@ -672,7 +671,7 @@ static int path_parse(char ***p, int flags) | |||
672 | return npth; | 671 | return npth; |
673 | } | 672 | } |
674 | 673 | ||
675 | static char *add_quote_for_spec_chars(char *found, int add) | 674 | static char *add_quote_for_spec_chars(char *found) |
676 | { | 675 | { |
677 | int l = 0; | 676 | int l = 0; |
678 | char *s = xmalloc((strlen(found) + 1) * 2); | 677 | char *s = xmalloc((strlen(found) + 1) * 2); |
@@ -682,8 +681,6 @@ static char *add_quote_for_spec_chars(char *found, int add) | |||
682 | s[l++] = '\\'; | 681 | s[l++] = '\\'; |
683 | s[l++] = *found++; | 682 | s[l++] = *found++; |
684 | } | 683 | } |
685 | if (add) | ||
686 | s[l++] = (char)add; | ||
687 | s[l] = 0; | 684 | s[l] = 0; |
688 | return s; | 685 | return s; |
689 | } | 686 | } |
@@ -732,7 +729,6 @@ static void exe_n_cwd_tab_completion(char *command, int type) | |||
732 | 729 | ||
733 | while ((next = readdir(dir)) != NULL) { | 730 | while ((next = readdir(dir)) != NULL) { |
734 | char *str_found = next->d_name; | 731 | char *str_found = next->d_name; |
735 | int add_chr = 0; | ||
736 | 732 | ||
737 | /* matched ? */ | 733 | /* matched ? */ |
738 | if (strncmp(str_found, pfind, strlen(pfind))) | 734 | if (strncmp(str_found, pfind, strlen(pfind))) |
@@ -751,23 +747,24 @@ static void exe_n_cwd_tab_completion(char *command, int type) | |||
751 | /* find with dirs ? */ | 747 | /* find with dirs ? */ |
752 | if (paths[i] != dirbuf) | 748 | if (paths[i] != dirbuf) |
753 | strcpy(found, next->d_name); /* only name */ | 749 | strcpy(found, next->d_name); /* only name */ |
750 | |||
751 | int len1 = strlen(found); | ||
752 | found = xrealloc(found, len1+2); | ||
753 | found[len1] = '\0'; | ||
754 | found[len1+1] = '\0'; | ||
755 | |||
754 | if (S_ISDIR(st.st_mode)) { | 756 | if (S_ISDIR(st.st_mode)) { |
755 | /* name is directory */ | 757 | /* name is directory */ |
756 | char *e = found + strlen(found) - 1; | 758 | if (found[len1-1] != '/') { |
757 | 759 | found[len1] = '/'; | |
758 | add_chr = '/'; | 760 | } |
759 | if (*e == '/') | ||
760 | *e = '\0'; | ||
761 | } else { | 761 | } else { |
762 | /* not put found file if search only dirs for cd */ | 762 | /* not put found file if search only dirs for cd */ |
763 | if (type == FIND_DIR_ONLY) | 763 | if (type == FIND_DIR_ONLY) |
764 | goto cont; | 764 | goto cont; |
765 | if (type == FIND_FILE_ONLY || | ||
766 | (type == FIND_EXE_ONLY && is_execute(&st))) | ||
767 | add_chr = ' '; | ||
768 | } | 765 | } |
769 | /* Add it to the list */ | 766 | /* Add it to the list */ |
770 | add_match(found, add_chr); | 767 | add_match(found); |
771 | continue; | 768 | continue; |
772 | cont: | 769 | cont: |
773 | free(found); | 770 | free(found); |
@@ -959,14 +956,11 @@ static void showfiles(void) | |||
959 | int column_width = 0; | 956 | int column_width = 0; |
960 | int nfiles = num_matches; | 957 | int nfiles = num_matches; |
961 | int nrows = nfiles; | 958 | int nrows = nfiles; |
962 | char str_add_chr[2]; | ||
963 | int l; | 959 | int l; |
964 | 960 | ||
965 | /* find the longest file name- use that as the column width */ | 961 | /* find the longest file name- use that as the column width */ |
966 | for (row = 0; row < nrows; row++) { | 962 | for (row = 0; row < nrows; row++) { |
967 | l = strlen(matches[row]); | 963 | l = strlen(matches[row]); |
968 | if (add_char_to_match[row]) | ||
969 | l++; | ||
970 | if (column_width < l) | 964 | if (column_width < l) |
971 | column_width = l; | 965 | column_width = l; |
972 | } | 966 | } |
@@ -980,20 +974,15 @@ static void showfiles(void) | |||
980 | } else { | 974 | } else { |
981 | ncols = 1; | 975 | ncols = 1; |
982 | } | 976 | } |
983 | str_add_chr[1] = 0; | ||
984 | for (row = 0; row < nrows; row++) { | 977 | for (row = 0; row < nrows; row++) { |
985 | int n = row; | 978 | int n = row; |
986 | int nc; | 979 | int nc; |
987 | int acol; | ||
988 | 980 | ||
989 | for(nc = 1; nc < ncols && n+nrows < nfiles; n += nrows, nc++) { | 981 | for(nc = 1; nc < ncols && n+nrows < nfiles; n += nrows, nc++) { |
990 | str_add_chr[0] = add_char_to_match[n]; | 982 | printf("%s%-*s", matches[n], |
991 | acol = str_add_chr[0] ? column_width - 1 : column_width; | 983 | column_width - strlen(matches[n]), ""); |
992 | printf("%s%s%-*s", matches[n], str_add_chr, | ||
993 | acol - strlen(matches[n]), ""); | ||
994 | } | 984 | } |
995 | str_add_chr[0] = add_char_to_match[n]; | 985 | printf("%s\n", matches[n]); |
996 | printf("%s%s\n", matches[n], str_add_chr); | ||
997 | } | 986 | } |
998 | } | 987 | } |
999 | 988 | ||
@@ -1011,8 +1000,6 @@ static void input_tab(int *lastWasTab) | |||
1011 | free(matches[--num_matches]); | 1000 | free(matches[--num_matches]); |
1012 | free(matches); | 1001 | free(matches); |
1013 | matches = (char **) NULL; | 1002 | matches = (char **) NULL; |
1014 | free(add_char_to_match); | ||
1015 | add_char_to_match = NULL; | ||
1016 | } | 1003 | } |
1017 | return; | 1004 | return; |
1018 | } | 1005 | } |
@@ -1056,12 +1043,10 @@ static void input_tab(int *lastWasTab) | |||
1056 | free(matches[i]); | 1043 | free(matches[i]); |
1057 | matches[i] = 0; | 1044 | matches[i] = 0; |
1058 | } else { | 1045 | } else { |
1059 | add_char_to_match[n] = add_char_to_match[i]; | ||
1060 | matches[n++] = matches[i]; | 1046 | matches[n++] = matches[i]; |
1061 | } | 1047 | } |
1062 | } | 1048 | } |
1063 | } | 1049 | } |
1064 | add_char_to_match[n] = add_char_to_match[num_matches-1]; | ||
1065 | matches[n++] = matches[num_matches-1]; | 1050 | matches[n++] = matches[num_matches-1]; |
1066 | num_matches = n; | 1051 | num_matches = n; |
1067 | } | 1052 | } |
@@ -1082,12 +1067,18 @@ static void input_tab(int *lastWasTab) | |||
1082 | free(tmp1); | 1067 | free(tmp1); |
1083 | return; | 1068 | return; |
1084 | } | 1069 | } |
1085 | tmp = add_quote_for_spec_chars(tmp1, 0); | 1070 | tmp = add_quote_for_spec_chars(tmp1); |
1086 | free(tmp1); | 1071 | free(tmp1); |
1087 | } else { /* one match */ | 1072 | } else { /* one match */ |
1088 | tmp = add_quote_for_spec_chars(matches[0], add_char_to_match[0]); | 1073 | tmp = add_quote_for_spec_chars(matches[0]); |
1089 | /* for next completion current found */ | 1074 | /* for next completion current found */ |
1090 | *lastWasTab = FALSE; | 1075 | *lastWasTab = FALSE; |
1076 | |||
1077 | len_found = strlen(tmp); | ||
1078 | if (tmp[len_found-1] != '/') { | ||
1079 | tmp[len_found] = ' '; | ||
1080 | tmp[len_found+1] = '\0'; | ||
1081 | } | ||
1091 | } | 1082 | } |
1092 | len_found = strlen(tmp); | 1083 | len_found = strlen(tmp); |
1093 | /* have space to placed match? */ | 1084 | /* have space to placed match? */ |