diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-01-21 13:49:28 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-01-21 13:49:28 +0100 |
commit | 4906faafab9760bd2d3ed1c6eb11def9efdc438c (patch) | |
tree | 373e80f9008ec9228963706fc6c21bf434714415 | |
parent | b7928e18b14a2bc2aa27f82b80803fdff68c328a (diff) | |
download | busybox-w32-4906faafab9760bd2d3ed1c6eb11def9efdc438c.tar.gz busybox-w32-4906faafab9760bd2d3ed1c6eb11def9efdc438c.tar.bz2 busybox-w32-4906faafab9760bd2d3ed1c6eb11def9efdc438c.zip |
sed: code shrink
function old new delta
parse_file_cmd 115 94 -21
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/sed.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/editors/sed.c b/editors/sed.c index cddb0c732..bb39de149 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -371,25 +371,25 @@ static int get_address(const char *my_str, int *linenum, regex_t ** regex) | |||
371 | /* Grab a filename. Whitespace at start is skipped, then goes to EOL. */ | 371 | /* Grab a filename. Whitespace at start is skipped, then goes to EOL. */ |
372 | static int parse_file_cmd(/*sed_cmd_t *sed_cmd,*/ const char *filecmdstr, char **retval) | 372 | static int parse_file_cmd(/*sed_cmd_t *sed_cmd,*/ const char *filecmdstr, char **retval) |
373 | { | 373 | { |
374 | int start = 0, idx, hack = 0; | 374 | const char *start; |
375 | const char *eol; | ||
375 | 376 | ||
376 | /* Skip whitespace, then grab filename to end of line */ | 377 | /* Skip whitespace, then grab filename to end of line */ |
377 | while (isspace(filecmdstr[start])) | 378 | start = skip_whitespace(filecmdstr); |
378 | start++; | 379 | eol = strchrnul(start, '\n'); |
379 | idx = start; | 380 | if (eol == start) |
380 | while (filecmdstr[idx] && filecmdstr[idx] != '\n') | ||
381 | idx++; | ||
382 | |||
383 | /* If lines glued together, put backslash back. */ | ||
384 | if (filecmdstr[idx] == '\n') | ||
385 | hack = 1; | ||
386 | if (idx == start) | ||
387 | bb_error_msg_and_die("empty filename"); | 381 | bb_error_msg_and_die("empty filename"); |
388 | *retval = xstrndup(filecmdstr+start, idx-start+hack+1); | ||
389 | if (hack) | ||
390 | (*retval)[idx-start] = '\\'; | ||
391 | 382 | ||
392 | return idx; | 383 | if (*eol) { |
384 | /* If lines glued together, put backslash back. */ | ||
385 | *retval = xstrndup(start, eol-start + 1); | ||
386 | (*retval)[eol-start] = '\\'; | ||
387 | } else { | ||
388 | /* eol is NUL */ | ||
389 | *retval = xstrdup(start); | ||
390 | } | ||
391 | |||
392 | return eol - filecmdstr; | ||
393 | } | 393 | } |
394 | 394 | ||
395 | static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr) | 395 | static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr) |