summaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorDenys Vlasenko2019-01-21 13:49:28 +0100
committerDenys Vlasenko2019-01-21 13:49:28 +0100
commit4906faafab9760bd2d3ed1c6eb11def9efdc438c (patch)
tree373e80f9008ec9228963706fc6c21bf434714415 /editors
parentb7928e18b14a2bc2aa27f82b80803fdff68c328a (diff)
downloadbusybox-4906faafab9760bd2d3ed1c6eb11def9efdc438c.zip
busybox-4906faafab9760bd2d3ed1c6eb11def9efdc438c.tar.gz
sed: code shrink
function old new delta parse_file_cmd 115 94 -21 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r--editors/sed.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/editors/sed.c b/editors/sed.c
index cddb0c7..bb39de1 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)
/* Grab a filename. Whitespace at start is skipped, then goes to EOL. */
static int parse_file_cmd(/*sed_cmd_t *sed_cmd,*/ const char *filecmdstr, char **retval)
{
- int start = 0, idx, hack = 0;
+ const char *start;
+ const char *eol;
/* Skip whitespace, then grab filename to end of line */
- while (isspace(filecmdstr[start]))
- start++;
- idx = start;
- while (filecmdstr[idx] && filecmdstr[idx] != '\n')
- idx++;
-
- /* If lines glued together, put backslash back. */
- if (filecmdstr[idx] == '\n')
- hack = 1;
- if (idx == start)
+ start = skip_whitespace(filecmdstr);
+ eol = strchrnul(start, '\n');
+ if (eol == start)
bb_error_msg_and_die("empty filename");
- *retval = xstrndup(filecmdstr+start, idx-start+hack+1);
- if (hack)
- (*retval)[idx-start] = '\\';
- return idx;
+ if (*eol) {
+ /* If lines glued together, put backslash back. */
+ *retval = xstrndup(start, eol-start + 1);
+ (*retval)[eol-start] = '\\';
+ } else {
+ /* eol is NUL */
+ *retval = xstrdup(start);
+ }
+
+ return eol - filecmdstr;
}
static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)