aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shell/cmdedit.c51
1 files changed, 20 insertions, 31 deletions
diff --git a/shell/cmdedit.c b/shell/cmdedit.c
index 187aa545b..944be00ab 100644
--- a/shell/cmdedit.c
+++ b/shell/cmdedit.c
@@ -989,18 +989,19 @@ static void showfiles(void)
989 for(nc = 1; nc < ncols && n+nrows < nfiles; n += nrows, nc++) { 989 for(nc = 1; nc < ncols && n+nrows < nfiles; n += nrows, nc++) {
990 str_add_chr[0] = add_char_to_match[n]; 990 str_add_chr[0] = add_char_to_match[n];
991 acol = str_add_chr[0] ? column_width - 1 : column_width; 991 acol = str_add_chr[0] ? column_width - 1 : column_width;
992 printf("%s%s", matches[n], str_add_chr); 992 printf("%s%s%-*s", matches[n], str_add_chr,
993 l = strlen(matches[n]); 993 acol - strlen(matches[n]), "");
994 while (l < acol) {
995 putchar(' ');
996 l++;
997 }
998 } 994 }
999 str_add_chr[0] = add_char_to_match[n]; 995 str_add_chr[0] = add_char_to_match[n];
1000 printf("%s%s\n", matches[n], str_add_chr); 996 printf("%s%s\n", matches[n], str_add_chr);
1001 } 997 }
1002} 998}
1003 999
1000static int match_compare(const void *a, const void *b)
1001{
1002 return strcmp(*(char**)a, *(char**)b);
1003}
1004
1004static void input_tab(int *lastWasTab) 1005static void input_tab(int *lastWasTab)
1005{ 1006{
1006 /* Do TAB completion */ 1007 /* Do TAB completion */
@@ -1016,7 +1017,6 @@ static void input_tab(int *lastWasTab)
1016 return; 1017 return;
1017 } 1018 }
1018 if (! *lastWasTab) { 1019 if (! *lastWasTab) {
1019
1020 char *tmp, *tmp1; 1020 char *tmp, *tmp1;
1021 int len_found; 1021 int len_found;
1022 char matchBuf[BUFSIZ]; 1022 char matchBuf[BUFSIZ];
@@ -1046,38 +1046,27 @@ static void input_tab(int *lastWasTab)
1046 /* Try to match any executable in our path and everything 1046 /* Try to match any executable in our path and everything
1047 * in the current working directory that matches. */ 1047 * in the current working directory that matches. */
1048 exe_n_cwd_tab_completion(matchBuf, find_type); 1048 exe_n_cwd_tab_completion(matchBuf, find_type);
1049 /* Remove duplicate found and sort */ 1049 /* Sort, then remove any duplicates found */
1050 if (matches) { 1050 if (matches) {
1051 int i, n; 1051 int i, n = 0;
1052 /* strcmp is int(*f)(const char*, const char*) */ 1052 qsort(matches, num_matches, sizeof(char*), match_compare);
1053 /* qsort wants int(*f)(const void*, const void*) */ 1053 for (i = 0; i < num_matches - 1; ++i) {
1054 /* We cheat here :) */ 1054 if (matches[i] && matches[i+1]) {
1055 qsort(matches, num_matches, sizeof(char*), (void*)strcmp); 1055 if (strcmp(matches[i], matches[i+1]) == 0) {
1056 i = 0; 1056 free(matches[i]);
1057 while (i < num_matches - 1) { 1057 matches[i] = 0;
1058 n = i + 1; 1058 } else {
1059 if (matches[i] && matches[n]) { 1059 add_char_to_match[n] = add_char_to_match[i];
1060 while (n < num_matches 1060 matches[n++] = matches[i];
1061 && !strcmp(matches[i], matches[n])) {
1062 free(matches[n]);
1063 matches[n] = 0;
1064 n++;
1065 } 1061 }
1066 } 1062 }
1067 i = n;
1068 } 1063 }
1069 n = 0; 1064 add_char_to_match[n] = add_char_to_match[num_matches-1];
1070 for(i = 0; i < num_matches; i++) 1065 matches[n++] = matches[num_matches-1];
1071 if (matches[i]) {
1072 matches[n] = matches[i];
1073 add_char_to_match[n] = add_char_to_match[i];
1074 n++;
1075 }
1076 num_matches = n; 1066 num_matches = n;
1077 } 1067 }
1078 /* Did we find exactly one match? */ 1068 /* Did we find exactly one match? */
1079 if (!matches || num_matches > 1) { 1069 if (!matches || num_matches > 1) {
1080
1081 beep(); 1070 beep();
1082 if (!matches) 1071 if (!matches)
1083 return; /* not found */ 1072 return; /* not found */