diff options
author | Ron Yorston <rmy@pobox.com> | 2021-02-13 10:17:16 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-02-13 10:17:16 +0000 |
commit | 8489ebce32f4b6cf5c1c1120fd474e26f7659db7 (patch) | |
tree | eaa5471ae7c13aaf335358fdf1079547fea0226a /libbb | |
parent | 7587b56c10a4d11fe434e3eaa51212113f09ec10 (diff) | |
download | busybox-w32-8489ebce32f4b6cf5c1c1120fd474e26f7659db7.tar.gz busybox-w32-8489ebce32f4b6cf5c1c1120fd474e26f7659db7.tar.bz2 busybox-w32-8489ebce32f4b6cf5c1c1120fd474e26f7659db7.zip |
win32: code shrink
Rewrite the recent change to tab completion so it only needs
one call to sprintf. Then replace sprintf with strcpy/stpcpy,
both there and in a couple of other places.
Saves 40 bytes.
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/lineedit.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 4802b46b4..55141e141 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -1251,6 +1251,8 @@ static NOINLINE void input_tab(smallint *lastWasTab) | |||
1251 | unsigned match_pfx_len = match_pfx_len; | 1251 | unsigned match_pfx_len = match_pfx_len; |
1252 | #if ENABLE_PLATFORM_MINGW32 | 1252 | #if ENABLE_PLATFORM_MINGW32 |
1253 | unsigned orig_pfx_len; | 1253 | unsigned orig_pfx_len; |
1254 | char *target; | ||
1255 | const char *source; | ||
1254 | #endif | 1256 | #endif |
1255 | int find_type; | 1257 | int find_type; |
1256 | # if ENABLE_UNICODE_SUPPORT | 1258 | # if ENABLE_UNICODE_SUPPORT |
@@ -1393,13 +1395,21 @@ static NOINLINE void input_tab(smallint *lastWasTab) | |||
1393 | /* save tail */ | 1395 | /* save tail */ |
1394 | strcpy(match_buf, &command_ps[cursor]); | 1396 | strcpy(match_buf, &command_ps[cursor]); |
1395 | /* add match and tail */ | 1397 | /* add match and tail */ |
1396 | #if ENABLE_PLATFORM_MINGW32 | 1398 | # if ENABLE_PLATFORM_MINGW32 |
1397 | if (match_pfx_len == orig_pfx_len) { | 1399 | if (match_pfx_len == orig_pfx_len) { |
1398 | sprintf(&command_ps[cursor-match_pfx_len], "%s%s", | 1400 | /* replace match prefix to allow for altered case */ |
1399 | chosen_match, match_buf); | 1401 | target = &command_ps[cursor-match_pfx_len]; |
1400 | } else | 1402 | source = chosen_match; |
1401 | #endif | 1403 | } |
1404 | else { | ||
1405 | /* only replace tail of match if special characters are quoted */ | ||
1406 | target = &command_ps[cursor]; | ||
1407 | source = chosen_match + match_pfx_len; | ||
1408 | } | ||
1409 | strcpy(stpcpy(target, source), match_buf); | ||
1410 | # else | ||
1402 | sprintf(&command_ps[cursor], "%s%s", chosen_match + match_pfx_len, match_buf); | 1411 | sprintf(&command_ps[cursor], "%s%s", chosen_match + match_pfx_len, match_buf); |
1412 | # endif | ||
1403 | command_len = strlen(command_ps); | 1413 | command_len = strlen(command_ps); |
1404 | /* new pos */ | 1414 | /* new pos */ |
1405 | pos = cursor + len_found - match_pfx_len; | 1415 | pos = cursor + len_found - match_pfx_len; |