diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-01 15:41:05 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-01 15:41:05 +0200 |
commit | 6ce60b9cca55c908de3747f1224b2e8aabb557bf (patch) | |
tree | 85fa5d63b43920bf7d046b2074a366ea7653eb7e | |
parent | d4f2e7ff71f253ee993e11cf7ce6a1244dec52e0 (diff) | |
download | busybox-w32-6ce60b9cca55c908de3747f1224b2e8aabb557bf.tar.gz busybox-w32-6ce60b9cca55c908de3747f1224b2e8aabb557bf.tar.bz2 busybox-w32-6ce60b9cca55c908de3747f1224b2e8aabb557bf.zip |
vi: use vsnprintf to format status line
This is the last use of "vsprintf" in busybox:
function old new delta
status_line_bold 72 77 +5
status_line 40 45 +5
vsprintf 23 - -23
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 2/0 up/down: 10/-23) Total: -13 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/vi.c | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/editors/vi.c b/editors/vi.c index a0a2b7a82..5c585a390 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -482,16 +482,13 @@ struct globals { | |||
482 | IF_FEATURE_VI_SEARCH(last_search_pattern = xzalloc(2);) \ | 482 | IF_FEATURE_VI_SEARCH(last_search_pattern = xzalloc(2);) \ |
483 | } while (0) | 483 | } while (0) |
484 | 484 | ||
485 | |||
486 | static void show_status_line(void); // put a message on the bottom line | ||
487 | static void status_line_bold(const char *, ...); | ||
488 | |||
489 | #if ENABLE_FEATURE_VI_CRASHME | 485 | #if ENABLE_FEATURE_VI_CRASHME |
490 | static void crash_dummy(); | ||
491 | static void crash_test(); | ||
492 | static int crashme = 0; | 486 | static int crashme = 0; |
493 | #endif | 487 | #endif |
494 | 488 | ||
489 | static void show_status_line(void); // put a message on the bottom line | ||
490 | static void status_line_bold(const char *, ...); | ||
491 | |||
495 | static void show_help(void) | 492 | static void show_help(void) |
496 | { | 493 | { |
497 | puts("These features are available:" | 494 | puts("These features are available:" |
@@ -1218,35 +1215,34 @@ static void show_status_line(void) | |||
1218 | } | 1215 | } |
1219 | 1216 | ||
1220 | //----- format the status buffer, the bottom line of screen ------ | 1217 | //----- format the status buffer, the bottom line of screen ------ |
1221 | // format status buffer, with STANDOUT mode | 1218 | static void status_line(const char *format, ...) |
1222 | static void status_line_bold(const char *format, ...) | ||
1223 | { | 1219 | { |
1224 | va_list args; | 1220 | va_list args; |
1225 | 1221 | ||
1226 | va_start(args, format); | 1222 | va_start(args, format); |
1227 | strcpy(status_buffer, ESC_BOLD_TEXT); | 1223 | vsnprintf(status_buffer, STATUS_BUFFER_LEN, format, args); |
1228 | vsprintf(status_buffer + sizeof(ESC_BOLD_TEXT)-1, format, args); | ||
1229 | strcat(status_buffer, ESC_NORM_TEXT); | ||
1230 | va_end(args); | 1224 | va_end(args); |
1231 | 1225 | ||
1232 | have_status_msg = 1 + sizeof(ESC_BOLD_TEXT) + sizeof(ESC_NORM_TEXT) - 2; | 1226 | have_status_msg = 1; |
1233 | } | ||
1234 | |||
1235 | static void status_line_bold_errno(const char *fn) | ||
1236 | { | ||
1237 | status_line_bold("'%s' "STRERROR_FMT, fn STRERROR_ERRNO); | ||
1238 | } | 1227 | } |
1239 | 1228 | static void status_line_bold(const char *format, ...) | |
1240 | // format status buffer | ||
1241 | static void status_line(const char *format, ...) | ||
1242 | { | 1229 | { |
1243 | va_list args; | 1230 | va_list args; |
1244 | 1231 | ||
1245 | va_start(args, format); | 1232 | va_start(args, format); |
1246 | vsprintf(status_buffer, format, args); | 1233 | strcpy(status_buffer, ESC_BOLD_TEXT); |
1234 | vsnprintf(status_buffer + (sizeof(ESC_BOLD_TEXT)-1), | ||
1235 | STATUS_BUFFER_LEN - sizeof(ESC_BOLD_TEXT) - sizeof(ESC_NORM_TEXT), | ||
1236 | format, args | ||
1237 | ); | ||
1238 | strcat(status_buffer, ESC_NORM_TEXT); | ||
1247 | va_end(args); | 1239 | va_end(args); |
1248 | 1240 | ||
1249 | have_status_msg = 1; | 1241 | have_status_msg = 1 + (sizeof(ESC_BOLD_TEXT)-1) + (sizeof(ESC_NORM_TEXT)-1); |
1242 | } | ||
1243 | static void status_line_bold_errno(const char *fn) | ||
1244 | { | ||
1245 | status_line_bold("'%s' "STRERROR_FMT, fn STRERROR_ERRNO); | ||
1250 | } | 1246 | } |
1251 | 1247 | ||
1252 | // copy s to buf, convert unprintable | 1248 | // copy s to buf, convert unprintable |
@@ -1290,15 +1286,14 @@ static void print_literal(char *buf, const char *s) | |||
1290 | break; | 1286 | break; |
1291 | } | 1287 | } |
1292 | } | 1288 | } |
1293 | |||
1294 | static void not_implemented(const char *s) | 1289 | static void not_implemented(const char *s) |
1295 | { | 1290 | { |
1296 | char buf[MAX_INPUT_LEN]; | 1291 | char buf[MAX_INPUT_LEN]; |
1297 | |||
1298 | print_literal(buf, s); | 1292 | print_literal(buf, s); |
1299 | status_line_bold("\'%s\' is not implemented", buf); | 1293 | status_line_bold("'%s' is not implemented", buf); |
1300 | } | 1294 | } |
1301 | 1295 | ||
1296 | //----- Block insert/delete, undo ops -------------------------- | ||
1302 | #if ENABLE_FEATURE_VI_YANKMARK | 1297 | #if ENABLE_FEATURE_VI_YANKMARK |
1303 | static char *text_yank(char *p, char *q, int dest) // copy text into a register | 1298 | static char *text_yank(char *p, char *q, int dest) // copy text into a register |
1304 | { | 1299 | { |
@@ -4318,10 +4313,10 @@ int vi_main(int argc, char **argv) | |||
4318 | 4313 | ||
4319 | #if ENABLE_FEATURE_VI_UNDO | 4314 | #if ENABLE_FEATURE_VI_UNDO |
4320 | /* undo_stack_tail = NULL; - already is */ | 4315 | /* undo_stack_tail = NULL; - already is */ |
4321 | #if ENABLE_FEATURE_VI_UNDO_QUEUE | 4316 | # if ENABLE_FEATURE_VI_UNDO_QUEUE |
4322 | undo_queue_state = UNDO_EMPTY; | 4317 | undo_queue_state = UNDO_EMPTY; |
4323 | /* undo_q = 0; - already is */ | 4318 | /* undo_q = 0; - already is */ |
4324 | #endif | 4319 | # endif |
4325 | #endif | 4320 | #endif |
4326 | 4321 | ||
4327 | #if ENABLE_FEATURE_VI_CRASHME | 4322 | #if ENABLE_FEATURE_VI_CRASHME |