487 |
static void add_cmd(const char *cmdstr) |
static void add_cmd(const char *cmdstr) |
488 |
{ |
{ |
489 |
sed_cmd_t *sed_cmd; |
sed_cmd_t *sed_cmd; |
490 |
int temp; |
unsigned len, n; |
491 |
|
|
492 |
/* Append this line to any unfinished line from last time. */ |
/* Append this line to any unfinished line from last time. */ |
493 |
if (G.add_cmd_line) { |
if (G.add_cmd_line) { |
496 |
cmdstr = G.add_cmd_line = tp; |
cmdstr = G.add_cmd_line = tp; |
497 |
} |
} |
498 |
|
|
499 |
/* If this line ends with backslash, request next line. */ |
/* If this line ends with unescaped backslash, request next line. */ |
500 |
temp = strlen(cmdstr); |
n = len = strlen(cmdstr); |
501 |
if (temp && cmdstr[--temp] == '\\') { |
while (n && cmdstr[n-1] == '\\') |
502 |
|
n--; |
503 |
|
if ((len - n) & 1) { /* if odd number of trailing backslashes */ |
504 |
if (!G.add_cmd_line) |
if (!G.add_cmd_line) |
505 |
G.add_cmd_line = xstrdup(cmdstr); |
G.add_cmd_line = xstrdup(cmdstr); |
506 |
G.add_cmd_line[temp] = '\0'; |
G.add_cmd_line[len-1] = '\0'; |
507 |
return; |
return; |
508 |
} |
} |
509 |
|
|
938 |
/* Skip blocks of commands we didn't match */ |
/* Skip blocks of commands we didn't match */ |
939 |
if (sed_cmd->cmd == '{') { |
if (sed_cmd->cmd == '{') { |
940 |
if (sed_cmd->invert ? matched : !matched) { |
if (sed_cmd->invert ? matched : !matched) { |
941 |
while (sed_cmd->cmd != '}') { |
unsigned nest_cnt = 0; |
942 |
|
while (1) { |
943 |
|
if (sed_cmd->cmd == '{') |
944 |
|
nest_cnt++; |
945 |
|
if (sed_cmd->cmd == '}') { |
946 |
|
nest_cnt--; |
947 |
|
if (nest_cnt == 0) |
948 |
|
break; |
949 |
|
} |
950 |
sed_cmd = sed_cmd->next; |
sed_cmd = sed_cmd->next; |
951 |
if (!sed_cmd) |
if (!sed_cmd) |
952 |
bb_error_msg_and_die("unterminated {"); |
bb_error_msg_and_die("unterminated {"); |
1041 |
case 'c': |
case 'c': |
1042 |
/* Only triggers on last line of a matching range. */ |
/* Only triggers on last line of a matching range. */ |
1043 |
if (!sed_cmd->in_match) |
if (!sed_cmd->in_match) |
1044 |
sed_puts(sed_cmd->string, NO_EOL_CHAR); |
sed_puts(sed_cmd->string, '\n'); |
1045 |
goto discard_line; |
goto discard_line; |
1046 |
|
|
1047 |
/* Read file, append contents to output */ |
/* Read file, append contents to output */ |