mirror of
https://github.com/sheumann/hush.git
synced 2024-12-23 05:29:58 +00:00
sed: make 's///w FILE' actually write to FILE. Closes 8251
function old new delta add_cmd 1167 1210 +43 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
eb5091070f
commit
2a4bba3ce2
@ -113,7 +113,7 @@ typedef struct sed_cmd_s {
|
|||||||
int end_line; /* 'sed 1,3p' 0 == one line only. -1 = last line ($). -2-N = +N */
|
int end_line; /* 'sed 1,3p' 0 == one line only. -1 = last line ($). -2-N = +N */
|
||||||
int end_line_orig;
|
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. */
|
char *string; /* Data string for (saicytb) commands. */
|
||||||
|
|
||||||
unsigned which_match; /* (s) Which match to replace (0 for all) */
|
unsigned which_match; /* (s) Which match to replace (0 for all) */
|
||||||
@ -179,7 +179,7 @@ static void sed_free_and_close_stuff(void)
|
|||||||
sed_cmd_t *sed_cmd_next = sed_cmd->next;
|
sed_cmd_t *sed_cmd_next = sed_cmd->next;
|
||||||
|
|
||||||
if (sed_cmd->sw_file)
|
if (sed_cmd->sw_file)
|
||||||
xprint_and_close_file(sed_cmd->sw_file);
|
fclose(sed_cmd->sw_file);
|
||||||
|
|
||||||
if (sed_cmd->beg_match) {
|
if (sed_cmd->beg_match) {
|
||||||
regfree(sed_cmd->beg_match);
|
regfree(sed_cmd->beg_match);
|
||||||
@ -426,8 +426,11 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
|
|||||||
/* Write to file */
|
/* Write to file */
|
||||||
case 'w':
|
case 'w':
|
||||||
{
|
{
|
||||||
char *temp;
|
char *fname;
|
||||||
idx += parse_file_cmd(/*sed_cmd,*/ substr+idx, &temp);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
/* Ignore case (gnu exension) */
|
/* Ignore case (gnu exension) */
|
||||||
|
@ -365,6 +365,12 @@ testing "sed /regex/,+0<cmd> -i works" \
|
|||||||
"1\n2\n3\n4\n5\n6\n7\n8\n" \
|
"1\n2\n3\n4\n5\n6\n7\n8\n" \
|
||||||
"1\n2\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"
|
# testing "description" "commands" "result" "infile" "stdin"
|
||||||
|
|
||||||
exit $FAILCOUNT
|
exit $FAILCOUNT
|
||||||
|
Loading…
Reference in New Issue
Block a user