aboutsummaryrefslogtreecommitdiff
path: root/editors/sed.c
diff options
context:
space:
mode:
Diffstat (limited to 'editors/sed.c')
-rw-r--r--editors/sed.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/editors/sed.c b/editors/sed.c
index fd56e0e7f..a5cedbd8d 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -377,25 +377,25 @@ static int get_address(const char *my_str, int *linenum, regex_t ** regex)
377/* Grab a filename. Whitespace at start is skipped, then goes to EOL. */ 377/* Grab a filename. Whitespace at start is skipped, then goes to EOL. */
378static int parse_file_cmd(/*sed_cmd_t *sed_cmd,*/ const char *filecmdstr, char **retval) 378static int parse_file_cmd(/*sed_cmd_t *sed_cmd,*/ const char *filecmdstr, char **retval)
379{ 379{
380 int start = 0, idx, hack = 0; 380 const char *start;
381 const char *eol;
381 382
382 /* Skip whitespace, then grab filename to end of line */ 383 /* Skip whitespace, then grab filename to end of line */
383 while (isspace(filecmdstr[start])) 384 start = skip_whitespace(filecmdstr);
384 start++; 385 eol = strchrnul(start, '\n');
385 idx = start; 386 if (eol == start)
386 while (filecmdstr[idx] && filecmdstr[idx] != '\n')
387 idx++;
388
389 /* If lines glued together, put backslash back. */
390 if (filecmdstr[idx] == '\n')
391 hack = 1;
392 if (idx == start)
393 bb_error_msg_and_die("empty filename"); 387 bb_error_msg_and_die("empty filename");
394 *retval = xstrndup(filecmdstr+start, idx-start+hack+1);
395 if (hack)
396 (*retval)[idx] = '\\';
397 388
398 return idx; 389 if (*eol) {
390 /* If lines glued together, put backslash back. */
391 *retval = xstrndup(start, eol-start + 1);
392 (*retval)[eol-start] = '\\';
393 } else {
394 /* eol is NUL */
395 *retval = xstrdup(start);
396 }
397
398 return eol - filecmdstr;
399} 399}
400 400
401static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr) 401static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)