int end_line; /* 'sed 1,3p' 0 == one line only. -1 = last line ($). -2-N = +N */
int end_line_orig;
- FILE *sw_file; /* File (sw) command writes to, -1 for none. */
+ FILE *sw_file; /* File (sw) command writes to, NULL for none. */
char *string; /* Data string for (saicytb) commands. */
unsigned which_match; /* (s) Which match to replace (0 for all) */
sed_cmd_t *sed_cmd_next = sed_cmd->next;
if (sed_cmd->sw_file)
- xprint_and_close_file(sed_cmd->sw_file);
+ fclose(sed_cmd->sw_file);
if (sed_cmd->beg_match) {
regfree(sed_cmd->beg_match);
/* Write to file */
case 'w':
{
- char *temp;
- idx += parse_file_cmd(/*sed_cmd,*/ substr+idx, &temp);
+ char *fname;
+ idx += parse_file_cmd(/*sed_cmd,*/ substr+idx+1, &fname);
+ sed_cmd->sw_file = xfopen_for_write(fname);
+ sed_cmd->sw_last_char = '\n';
+ free(fname);
break;
}
/* Ignore case (gnu exension) */
"1\n2\n3\n4\n5\n6\n7\n8\n" \
"1\n2\n4\n5\n6\n7\n8\n" \
+testing "sed 's///w FILE'" \
+ "sed 's/qwe/ZZZ/wz'; cat z; rm z" \
+ "123\nZZZ\nasd\n""ZZZ\n" \
+ "" \
+ "123\nqwe\nasd\n"
+
# testing "description" "commands" "result" "infile" "stdin"
exit $FAILCOUNT