+ /* Only triggers on last line of a matching range. */
+ if (!sed_cmd->in_match) sed_puts(sed_cmd->string,1);
+ goto discard_line;
+
+ /* Read file, append contents to output */
+ case 'r':
+ {
+ FILE *outfile;
+
+ outfile = fopen(sed_cmd->string, "r");
+ if (outfile) {
+ char *line;
+
+ while ((line = bb_get_chomped_line_from_file(outfile))
+ != NULL)
+ append(line);
+ bb_xprint_and_close_file(outfile);
+ }
+
+ break;
+ }
+
+ /* Write pattern space to file. */
+ case 'w':
+ sed_cmd->no_newline=puts_maybe_newline(pattern_space,sed_cmd->file, sed_cmd->no_newline,no_newline);
+ break;
+
+ /* Read next line from input */
+ case 'n':
+ if (!be_quiet)
+ sed_puts(pattern_space,no_newline);
+ if (next_line) {
+ free(pattern_space);
+ pattern_space = next_line;
+ no_newline=next_no_newline;
+ next_line = get_next_line(file,&next_no_newline);
+ linenum++;
+ break;
+ }
+ /* fall through */
+
+ /* Quit. End of script, end of input. */
+ case 'q':
+ /* Exit the outer while loop */
+ free(next_line);
+ next_line = NULL;
+ goto discard_commands;
+
+ /* Append the next line to the current line */
+ case 'N':
+ {
+ /* If no next line, jump to end of script and exit. */
+ if (next_line == NULL) {
+ /* Jump to end of script and exit */
+ free(next_line);
+ next_line = NULL;
+ goto discard_line;
+ /* append next_line, read new next_line. */
+ } else {
+ int len=strlen(pattern_space);
+
+ pattern_space = realloc(pattern_space, len + strlen(next_line) + 2);
+ pattern_space[len]='\n';
+ strcpy(pattern_space+len+1, next_line);
+ no_newline=next_no_newline;
+ next_line = get_next_line(file,&next_no_newline);
+ linenum++;
+ }
+ break;
+ }
+
+ /* Test if substition worked, branch if so. */
+ case 't':
+ if (!substituted) break;
+ substituted=0;
+ /* Fall through */
+ /* Branch to label */
+ case 'b':
+ if (!sed_cmd->string) goto discard_commands;
+ else sed_cmd = branch_to(sed_cmd->string);
+ break;
+ /* Transliterate characters */
+ case 'y':
+ {
+ int i;
+
+ for (i = 0; pattern_space[i]; i++) {
+ int j;
+
+ for (j = 0; sed_cmd->string[j]; j += 2) {
+ if (pattern_space[i] == sed_cmd->string[j]) {
+ pattern_space[i] = sed_cmd->string[j + 1];
+ }
+ }