diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-03 13:05:51 +0200 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-03 13:05:51 +0200 |
commit | a46e16ef52952b1ed82ab1dbc4b9da2aeb40107e (patch) | |
tree | 0047135d6c37913d033b569cf50d9c925c826777 /libbb | |
parent | 9b56bf541667ce1b4d408cd4e23bc51a44ae9267 (diff) | |
download | busybox-w32-a46e16ef52952b1ed82ab1dbc4b9da2aeb40107e.tar.gz busybox-w32-a46e16ef52952b1ed82ab1dbc4b9da2aeb40107e.tar.bz2 busybox-w32-a46e16ef52952b1ed82ab1dbc4b9da2aeb40107e.zip |
lineedit: rename tmp -> chosen_match; small code shrink
function old new delta
input_tab 1016 1012 -4
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/lineedit.c | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index e212a1aa8..dda702455 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -1040,7 +1040,7 @@ static NOINLINE void input_tab(smallint *lastWasTab) | |||
1040 | return; | 1040 | return; |
1041 | 1041 | ||
1042 | if (!*lastWasTab) { | 1042 | if (!*lastWasTab) { |
1043 | char *tmp; | 1043 | char *chosen_match; |
1044 | size_t len_found; | 1044 | size_t len_found; |
1045 | /* char matchBuf[MAX_LINELEN]; */ | 1045 | /* char matchBuf[MAX_LINELEN]; */ |
1046 | #define matchBuf (S.input_tab__matchBuf) | 1046 | #define matchBuf (S.input_tab__matchBuf) |
@@ -1067,8 +1067,6 @@ static NOINLINE void input_tab(smallint *lastWasTab) | |||
1067 | cursor_mb = strlen(matchBuf); | 1067 | cursor_mb = strlen(matchBuf); |
1068 | } | 1068 | } |
1069 | #endif | 1069 | #endif |
1070 | tmp = matchBuf; | ||
1071 | |||
1072 | find_type = build_match_prefix(matchBuf); | 1070 | find_type = build_match_prefix(matchBuf); |
1073 | 1071 | ||
1074 | /* Free up any memory already allocated */ | 1072 | /* Free up any memory already allocated */ |
@@ -1104,38 +1102,39 @@ static NOINLINE void input_tab(smallint *lastWasTab) | |||
1104 | } | 1102 | } |
1105 | /* Did we find exactly one match? */ | 1103 | /* Did we find exactly one match? */ |
1106 | if (num_matches != 1) { /* no */ | 1104 | if (num_matches != 1) { /* no */ |
1107 | char *tmp1; | 1105 | char *cp; |
1108 | beep(); | 1106 | beep(); |
1109 | if (!matches) | 1107 | if (!matches) |
1110 | return; /* no matches at all */ | 1108 | return; /* no matches at all */ |
1111 | /* Find common prefix */ | 1109 | /* Find common prefix */ |
1112 | tmp1 = xstrdup(matches[0]); | 1110 | chosen_match = xstrdup(matches[0]); |
1113 | for (tmp = tmp1; *tmp; tmp++) { | 1111 | for (cp = chosen_match; *cp; cp++) { |
1114 | unsigned n; | 1112 | unsigned n; |
1115 | for (n = 1; n < num_matches; n++) { | 1113 | for (n = 1; n < num_matches; n++) { |
1116 | if (matches[n][tmp - tmp1] != *tmp) { | 1114 | if (matches[n][cp - chosen_match] != *cp) { |
1117 | goto stop; | 1115 | goto stop; |
1118 | } | 1116 | } |
1119 | } | 1117 | } |
1120 | } | 1118 | } |
1121 | stop: | 1119 | stop: |
1122 | if (tmp1 == tmp) { /* have unique prefix? */ | 1120 | if (cp == chosen_match) { /* have unique prefix? */ |
1123 | free(tmp1); /* no */ | 1121 | free(chosen_match); /* no */ |
1124 | return; | 1122 | return; |
1125 | } | 1123 | } |
1126 | *tmp = '\0'; | 1124 | *cp = '\0'; |
1127 | tmp = add_quote_for_spec_chars(tmp1); | 1125 | cp = add_quote_for_spec_chars(chosen_match); |
1128 | free(tmp1); | 1126 | free(chosen_match); |
1129 | len_found = strlen(tmp); | 1127 | chosen_match = cp; |
1128 | len_found = strlen(chosen_match); | ||
1130 | } else { /* exactly one match */ | 1129 | } else { /* exactly one match */ |
1131 | /* Next <tab> is not a double-tab */ | 1130 | /* Next <tab> is not a double-tab */ |
1132 | *lastWasTab = 0; | 1131 | *lastWasTab = 0; |
1133 | 1132 | ||
1134 | tmp = add_quote_for_spec_chars(matches[0]); | 1133 | chosen_match = add_quote_for_spec_chars(matches[0]); |
1135 | len_found = strlen(tmp); | 1134 | len_found = strlen(chosen_match); |
1136 | if (tmp[len_found-1] != '/') { | 1135 | if (chosen_match[len_found-1] != '/') { |
1137 | tmp[len_found] = ' '; | 1136 | chosen_match[len_found] = ' '; |
1138 | tmp[++len_found] = '\0'; | 1137 | chosen_match[++len_found] = '\0'; |
1139 | } | 1138 | } |
1140 | } | 1139 | } |
1141 | 1140 | ||
@@ -1149,7 +1148,7 @@ static NOINLINE void input_tab(smallint *lastWasTab) | |||
1149 | /* save tail */ | 1148 | /* save tail */ |
1150 | strcpy(matchBuf, &command_ps[cursor]); | 1149 | strcpy(matchBuf, &command_ps[cursor]); |
1151 | /* add match and tail */ | 1150 | /* add match and tail */ |
1152 | sprintf(&command_ps[cursor], "%s%s", tmp + match_pfx_len, matchBuf); | 1151 | sprintf(&command_ps[cursor], "%s%s", chosen_match + match_pfx_len, matchBuf); |
1153 | command_len = strlen(command_ps); | 1152 | command_len = strlen(command_ps); |
1154 | /* new pos */ | 1153 | /* new pos */ |
1155 | pos = cursor + len_found - match_pfx_len; | 1154 | pos = cursor + len_found - match_pfx_len; |
@@ -1167,10 +1166,10 @@ static NOINLINE void input_tab(smallint *lastWasTab) | |||
1167 | /* save tail */ | 1166 | /* save tail */ |
1168 | strcpy(matchBuf, &command[cursor_mb]); | 1167 | strcpy(matchBuf, &command[cursor_mb]); |
1169 | /* where do we want to have cursor after all? */ | 1168 | /* where do we want to have cursor after all? */ |
1170 | strcpy(&command[cursor_mb], tmp + match_pfx_len); | 1169 | strcpy(&command[cursor_mb], chosen_match + match_pfx_len); |
1171 | len = load_string(command, S.maxsize); | 1170 | len = load_string(command, S.maxsize); |
1172 | /* add match and tail */ | 1171 | /* add match and tail */ |
1173 | sprintf(&command[cursor_mb], "%s%s", tmp + match_pfx_len, matchBuf); | 1172 | sprintf(&command[cursor_mb], "%s%s", chosen_match + match_pfx_len, matchBuf); |
1174 | command_len = load_string(command, S.maxsize); | 1173 | command_len = load_string(command, S.maxsize); |
1175 | /* write out the matched command */ | 1174 | /* write out the matched command */ |
1176 | /* paranoia: load_string can return 0 on conv error, | 1175 | /* paranoia: load_string can return 0 on conv error, |
@@ -1180,17 +1179,15 @@ static NOINLINE void input_tab(smallint *lastWasTab) | |||
1180 | } | 1179 | } |
1181 | } | 1180 | } |
1182 | #endif | 1181 | #endif |
1183 | free(tmp); | 1182 | free(chosen_match); |
1184 | #undef matchBuf | 1183 | #undef matchBuf |
1185 | } else { | 1184 | } else { |
1186 | /* Ok -- the last char was a TAB. Since they | 1185 | /* Ok -- the last char was a TAB. Since they |
1187 | * just hit TAB again, print a list of all the | 1186 | * just hit TAB again, print a list of all the |
1188 | * available choices... */ | 1187 | * available choices... */ |
1189 | if (matches && num_matches > 0) { | 1188 | if (num_matches > 0) { |
1190 | /* changed by goto_new_line() */ | 1189 | /* cursor will be changed by goto_new_line() */ |
1191 | int sav_cursor = cursor; | 1190 | int sav_cursor = cursor; |
1192 | |||
1193 | /* Go to the next line */ | ||
1194 | goto_new_line(); | 1191 | goto_new_line(); |
1195 | showfiles(); | 1192 | showfiles(); |
1196 | redraw(0, command_len - sav_cursor); | 1193 | redraw(0, command_len - sav_cursor); |