diff options
Diffstat (limited to 'editors/sed.c')
-rw-r--r-- | editors/sed.c | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/editors/sed.c b/editors/sed.c index f8ca5d351..3a0d917aa 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -330,7 +330,7 @@ static int get_address(const char *my_str, int *linenum, regex_t ** regex) | |||
330 | next = index_of_next_unescaped_regexp_delim(delimiter, ++pos); | 330 | next = index_of_next_unescaped_regexp_delim(delimiter, ++pos); |
331 | temp = copy_parsing_escapes(pos, next); | 331 | temp = copy_parsing_escapes(pos, next); |
332 | *regex = xzalloc(sizeof(regex_t)); | 332 | *regex = xzalloc(sizeof(regex_t)); |
333 | xregcomp(*regex, temp, G.regex_type|REG_NEWLINE); | 333 | xregcomp(*regex, temp, G.regex_type); |
334 | free(temp); | 334 | free(temp); |
335 | /* Move position to next character after last delimiter */ | 335 | /* Move position to next character after last delimiter */ |
336 | pos += (next+1); | 336 | pos += (next+1); |
@@ -649,6 +649,12 @@ static void add_cmd(const char *cmdstr) | |||
649 | sed_cmd->cmd = *cmdstr++; | 649 | sed_cmd->cmd = *cmdstr++; |
650 | cmdstr = parse_cmd_args(sed_cmd, cmdstr); | 650 | cmdstr = parse_cmd_args(sed_cmd, cmdstr); |
651 | 651 | ||
652 | /* cmdstr now points past args. | ||
653 | * GNU sed requires a separator, if there are more commands, | ||
654 | * else it complains "char N: extra characters after command". | ||
655 | * Example: "sed 'p;d'". We also allow "sed 'pd'". | ||
656 | */ | ||
657 | |||
652 | /* Add the command to the command array */ | 658 | /* Add the command to the command array */ |
653 | *G.sed_cmd_tail = sed_cmd; | 659 | *G.sed_cmd_tail = sed_cmd; |
654 | G.sed_cmd_tail = &sed_cmd->next; | 660 | G.sed_cmd_tail = &sed_cmd->next; |
@@ -1371,7 +1377,7 @@ static void process_files(void) | |||
1371 | /* It is possible to have a command line argument with embedded | 1377 | /* It is possible to have a command line argument with embedded |
1372 | * newlines. This counts as multiple command lines. | 1378 | * newlines. This counts as multiple command lines. |
1373 | * However, newline can be escaped: 's/e/z\<newline>z/' | 1379 | * However, newline can be escaped: 's/e/z\<newline>z/' |
1374 | * We check for this. | 1380 | * add_cmd() handles this. |
1375 | */ | 1381 | */ |
1376 | 1382 | ||
1377 | static void add_cmd_block(char *cmdstr) | 1383 | static void add_cmd_block(char *cmdstr) |
@@ -1381,22 +1387,8 @@ static void add_cmd_block(char *cmdstr) | |||
1381 | cmdstr = sv = xstrdup(cmdstr); | 1387 | cmdstr = sv = xstrdup(cmdstr); |
1382 | do { | 1388 | do { |
1383 | eol = strchr(cmdstr, '\n'); | 1389 | eol = strchr(cmdstr, '\n'); |
1384 | next: | 1390 | if (eol) |
1385 | if (eol) { | ||
1386 | /* Count preceding slashes */ | ||
1387 | int slashes = 0; | ||
1388 | char *sl = eol; | ||
1389 | |||
1390 | while (sl != cmdstr && *--sl == '\\') | ||
1391 | slashes++; | ||
1392 | /* Odd number of preceding slashes - newline is escaped */ | ||
1393 | if (slashes & 1) { | ||
1394 | overlapping_strcpy(eol - 1, eol); | ||
1395 | eol = strchr(eol, '\n'); | ||
1396 | goto next; | ||
1397 | } | ||
1398 | *eol = '\0'; | 1391 | *eol = '\0'; |
1399 | } | ||
1400 | add_cmd(cmdstr); | 1392 | add_cmd(cmdstr); |
1401 | cmdstr = eol + 1; | 1393 | cmdstr = eol + 1; |
1402 | } while (eol); | 1394 | } while (eol); |