aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-09-03 14:08:24 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-09-03 14:08:24 +0200
commitba0e103a662f640060041c5b56c2afdce09408b3 (patch)
tree513ca8b725d9f69c5d7cbd2c451e11983fa3e4bb
parenta46e16ef52952b1ed82ab1dbc4b9da2aeb40107e (diff)
downloadbusybox-w32-ba0e103a662f640060041c5b56c2afdce09408b3.tar.gz
busybox-w32-ba0e103a662f640060041c5b56c2afdce09408b3.tar.bz2
busybox-w32-ba0e103a662f640060041c5b56c2afdce09408b3.zip
lineedit: de-indent large block in input_tab. No logic changes.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--libbb/lineedit.c262
1 files changed, 131 insertions, 131 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index dda702455..ff5d28408 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -924,7 +924,7 @@ static NOINLINE int build_match_prefix(char *matchBuf)
924 for (i = 0; int_buf[i]; i++) { 924 for (i = 0; int_buf[i]; i++) {
925 if (int_buf[i] == '(' || int_buf[i] == '{') { 925 if (int_buf[i] == '(' || int_buf[i] == '{') {
926 remove_chunk(int_buf, 0, i + 1); 926 remove_chunk(int_buf, 0, i + 1);
927 i = -1; /* hack increment */ 927 i = -1; /* back to square 1 */
928 } 928 }
929 } 929 }
930 930
@@ -1036,163 +1036,163 @@ static char *add_quote_for_spec_chars(char *found)
1036/* Do TAB completion */ 1036/* Do TAB completion */
1037static NOINLINE void input_tab(smallint *lastWasTab) 1037static NOINLINE void input_tab(smallint *lastWasTab)
1038{ 1038{
1039 if (!(state->flags & TAB_COMPLETION)) 1039 char *chosen_match;
1040 return; 1040 size_t len_found;
1041 1041/* char matchBuf[MAX_LINELEN]; */
1042 if (!*lastWasTab) {
1043 char *chosen_match;
1044 size_t len_found;
1045/* char matchBuf[MAX_LINELEN]; */
1046#define matchBuf (S.input_tab__matchBuf) 1042#define matchBuf (S.input_tab__matchBuf)
1047 /* Length of string used for matching */ 1043 /* Length of string used for matching */
1048 unsigned match_pfx_len = match_pfx_len; 1044 unsigned match_pfx_len = match_pfx_len;
1049 int find_type; 1045 int find_type;
1050#if ENABLE_UNICODE_SUPPORT 1046#if ENABLE_UNICODE_SUPPORT
1051 /* cursor pos in command converted to multibyte form */ 1047 /* cursor pos in command converted to multibyte form */
1052 int cursor_mb; 1048 int cursor_mb;
1053#endif 1049#endif
1050 if (!(state->flags & TAB_COMPLETION))
1051 return;
1054 1052
1055 *lastWasTab = 1; 1053 if (*lastWasTab) {
1054 /* The last char was a TAB too.
1055 * Print a list of all the available choices.
1056 */
1057 if (num_matches > 0) {
1058 /* cursor will be changed by goto_new_line() */
1059 int sav_cursor = cursor;
1060 goto_new_line();
1061 showfiles();
1062 redraw(0, command_len - sav_cursor);
1063 }
1064 return;
1065 }
1066
1067 *lastWasTab = 1;
1056 1068
1057 /* Make a local copy of the string -- 1069 /* Make a local copy of the string --
1058 * up to the position of the cursor */ 1070 * up to the position of the cursor */
1059#if !ENABLE_UNICODE_SUPPORT 1071#if !ENABLE_UNICODE_SUPPORT
1060 save_string(matchBuf, cursor + 1); 1072 save_string(matchBuf, cursor + 1);
1061#else 1073#else
1062 { 1074 {
1063 CHAR_T wc = command_ps[cursor]; 1075 CHAR_T wc = command_ps[cursor];
1064 command_ps[cursor] = BB_NUL; 1076 command_ps[cursor] = BB_NUL;
1065 save_string(matchBuf, MAX_LINELEN); 1077 save_string(matchBuf, MAX_LINELEN);
1066 command_ps[cursor] = wc; 1078 command_ps[cursor] = wc;
1067 cursor_mb = strlen(matchBuf); 1079 cursor_mb = strlen(matchBuf);
1068 } 1080 }
1069#endif 1081#endif
1070 find_type = build_match_prefix(matchBuf); 1082 find_type = build_match_prefix(matchBuf);
1071 1083
1072 /* Free up any memory already allocated */ 1084 /* Free up any memory already allocated */
1073 free_tab_completion_data(); 1085 free_tab_completion_data();
1074 1086
1075#if ENABLE_FEATURE_USERNAME_COMPLETION 1087#if ENABLE_FEATURE_USERNAME_COMPLETION
1076 /* If the word starts with `~' and there is no slash in the word, 1088 /* If the word starts with `~' and there is no slash in the word,
1077 * then try completing this word as a username. */ 1089 * then try completing this word as a username. */
1078 if (state->flags & USERNAME_COMPLETION) 1090 if (state->flags & USERNAME_COMPLETION)
1079 if (matchBuf[0] == '~' && strchr(matchBuf, '/') == NULL) 1091 if (matchBuf[0] == '~' && strchr(matchBuf, '/') == NULL)
1080 match_pfx_len = complete_username(matchBuf); 1092 match_pfx_len = complete_username(matchBuf);
1081#endif 1093#endif
1082 /* Try to match a command in $PATH, or a directory, or a file */ 1094 /* Try to match a command in $PATH, or a directory, or a file */
1083 if (!matches) 1095 if (!matches)
1084 match_pfx_len = complete_cmd_dir_file(matchBuf, find_type); 1096 match_pfx_len = complete_cmd_dir_file(matchBuf, find_type);
1085 /* Remove duplicates */ 1097 /* Remove duplicates */
1086 if (matches) { 1098 if (matches) {
1087 unsigned i; 1099 unsigned i;
1088 unsigned n = 0; 1100 unsigned n = 0;
1089 qsort_string_vector(matches, num_matches); 1101 qsort_string_vector(matches, num_matches);
1090 for (i = 0; i < num_matches - 1; ++i) { 1102 for (i = 0; i < num_matches - 1; ++i) {
1091 //if (matches[i] && matches[i+1]) { /* paranoia */ 1103 //if (matches[i] && matches[i+1]) { /* paranoia */
1092 if (strcmp(matches[i], matches[i+1]) == 0) { 1104 if (strcmp(matches[i], matches[i+1]) == 0) {
1093 free(matches[i]); 1105 free(matches[i]);
1094 //matches[i] = NULL; /* paranoia */ 1106 //matches[i] = NULL; /* paranoia */
1095 } else { 1107 } else {
1096 matches[n++] = matches[i]; 1108 matches[n++] = matches[i];
1097 } 1109 }
1098 //} 1110 //}
1099 }
1100 matches[n++] = matches[i];
1101 num_matches = n;
1102 } 1111 }
1103 /* Did we find exactly one match? */ 1112 matches[n++] = matches[i];
1104 if (num_matches != 1) { /* no */ 1113 num_matches = n;
1105 char *cp; 1114 }
1106 beep(); 1115 /* Did we find exactly one match? */
1107 if (!matches) 1116 if (num_matches != 1) { /* no */
1108 return; /* no matches at all */ 1117 char *cp;
1109 /* Find common prefix */ 1118 beep();
1110 chosen_match = xstrdup(matches[0]); 1119 if (!matches)
1111 for (cp = chosen_match; *cp; cp++) { 1120 return; /* no matches at all */
1112 unsigned n; 1121 /* Find common prefix */
1113 for (n = 1; n < num_matches; n++) { 1122 chosen_match = xstrdup(matches[0]);
1114 if (matches[n][cp - chosen_match] != *cp) { 1123 for (cp = chosen_match; *cp; cp++) {
1115 goto stop; 1124 unsigned n;
1116 } 1125 for (n = 1; n < num_matches; n++) {
1126 if (matches[n][cp - chosen_match] != *cp) {
1127 goto stop;
1117 } 1128 }
1118 } 1129 }
1130 }
1119 stop: 1131 stop:
1120 if (cp == chosen_match) { /* have unique prefix? */ 1132 if (cp == chosen_match) { /* have unique prefix? */
1121 free(chosen_match); /* no */ 1133 free(chosen_match); /* no */
1122 return; 1134 return;
1123 }
1124 *cp = '\0';
1125 cp = add_quote_for_spec_chars(chosen_match);
1126 free(chosen_match);
1127 chosen_match = cp;
1128 len_found = strlen(chosen_match);
1129 } else { /* exactly one match */
1130 /* Next <tab> is not a double-tab */
1131 *lastWasTab = 0;
1132
1133 chosen_match = add_quote_for_spec_chars(matches[0]);
1134 len_found = strlen(chosen_match);
1135 if (chosen_match[len_found-1] != '/') {
1136 chosen_match[len_found] = ' ';
1137 chosen_match[++len_found] = '\0';
1138 }
1139 } 1135 }
1136 *cp = '\0';
1137 cp = add_quote_for_spec_chars(chosen_match);
1138 free(chosen_match);
1139 chosen_match = cp;
1140 len_found = strlen(chosen_match);
1141 } else { /* exactly one match */
1142 /* Next <tab> is not a double-tab */
1143 *lastWasTab = 0;
1144
1145 chosen_match = add_quote_for_spec_chars(matches[0]);
1146 len_found = strlen(chosen_match);
1147 if (chosen_match[len_found-1] != '/') {
1148 chosen_match[len_found] = ' ';
1149 chosen_match[++len_found] = '\0';
1150 }
1151 }
1140 1152
1141#if !ENABLE_UNICODE_SUPPORT 1153#if !ENABLE_UNICODE_SUPPORT
1154 /* Have space to place the match? */
1155 /* The result consists of three parts with these lengths: */
1156 /* cursor + (len_found - match_pfx_len) + (command_len - cursor) */
1157 /* it simplifies into: */
1158 if ((int)(len_found - match_pfx_len + command_len) < S.maxsize) {
1159 int pos;
1160 /* save tail */
1161 strcpy(matchBuf, &command_ps[cursor]);
1162 /* add match and tail */
1163 sprintf(&command_ps[cursor], "%s%s", chosen_match + match_pfx_len, matchBuf);
1164 command_len = strlen(command_ps);
1165 /* new pos */
1166 pos = cursor + len_found - match_pfx_len;
1167 /* write out the matched command */
1168 redraw(cmdedit_y, command_len - pos);
1169 }
1170#else
1171 {
1172 char command[MAX_LINELEN];
1173 int len = save_string(command, sizeof(command));
1142 /* Have space to place the match? */ 1174 /* Have space to place the match? */
1143 /* The result consists of three parts with these lengths: */ 1175 /* cursor_mb + (len_found - match_pfx_len) + (len - cursor_mb) */
1144 /* cursor + (len_found - match_pfx_len) + (command_len - cursor) */ 1176 if ((int)(len_found - match_pfx_len + len) < MAX_LINELEN) {
1145 /* it simplifies into: */
1146 if ((int)(len_found - match_pfx_len + command_len) < S.maxsize) {
1147 int pos; 1177 int pos;
1148 /* save tail */ 1178 /* save tail */
1149 strcpy(matchBuf, &command_ps[cursor]); 1179 strcpy(matchBuf, &command[cursor_mb]);
1180 /* where do we want to have cursor after all? */
1181 strcpy(&command[cursor_mb], chosen_match + match_pfx_len);
1182 len = load_string(command, S.maxsize);
1150 /* add match and tail */ 1183 /* add match and tail */
1151 sprintf(&command_ps[cursor], "%s%s", chosen_match + match_pfx_len, matchBuf); 1184 sprintf(&command[cursor_mb], "%s%s", chosen_match + match_pfx_len, matchBuf);
1152 command_len = strlen(command_ps); 1185 command_len = load_string(command, S.maxsize);
1153 /* new pos */
1154 pos = cursor + len_found - match_pfx_len;
1155 /* write out the matched command */ 1186 /* write out the matched command */
1156 redraw(cmdedit_y, command_len - pos); 1187 /* paranoia: load_string can return 0 on conv error,
1157 } 1188 * prevent passing pos = (0 - 12) to redraw */
1158#else 1189 pos = command_len - len;
1159 { 1190 redraw(cmdedit_y, pos >= 0 ? pos : 0);
1160 char command[MAX_LINELEN];
1161 int len = save_string(command, sizeof(command));
1162 /* Have space to place the match? */
1163 /* cursor_mb + (len_found - match_pfx_len) + (len - cursor_mb) */
1164 if ((int)(len_found - match_pfx_len + len) < MAX_LINELEN) {
1165 int pos;
1166 /* save tail */
1167 strcpy(matchBuf, &command[cursor_mb]);
1168 /* where do we want to have cursor after all? */
1169 strcpy(&command[cursor_mb], chosen_match + match_pfx_len);
1170 len = load_string(command, S.maxsize);
1171 /* add match and tail */
1172 sprintf(&command[cursor_mb], "%s%s", chosen_match + match_pfx_len, matchBuf);
1173 command_len = load_string(command, S.maxsize);
1174 /* write out the matched command */
1175 /* paranoia: load_string can return 0 on conv error,
1176 * prevent passing pos = (0 - 12) to redraw */
1177 pos = command_len - len;
1178 redraw(cmdedit_y, pos >= 0 ? pos : 0);
1179 }
1180 } 1191 }
1192 }
1181#endif 1193#endif
1182 free(chosen_match); 1194 free(chosen_match);
1183#undef matchBuf 1195#undef matchBuf
1184 } else {
1185 /* Ok -- the last char was a TAB. Since they
1186 * just hit TAB again, print a list of all the
1187 * available choices... */
1188 if (num_matches > 0) {
1189 /* cursor will be changed by goto_new_line() */
1190 int sav_cursor = cursor;
1191 goto_new_line();
1192 showfiles();
1193 redraw(0, command_len - sav_cursor);
1194 }
1195 }
1196} 1196}
1197 1197
1198#endif /* FEATURE_TAB_COMPLETION */ 1198#endif /* FEATURE_TAB_COMPLETION */