sed: adjust line-terminator of F/l/= commands when -z is used

Change F/l/= commands to use NUL line terminator if '-z' option is used.
Previously F/l/= used '\n' regardless of -z option.
See: http://lists.gnu.org/archive/html/sed-devel/2016-08/msg00000.html
http://lists.gnu.org/archive/html/sed-devel/2016-08/msg00002.html .

* sed/execute.c: (do_list,execute_program): Use 'buffer_delimiter' as
line delimiter instead of hard-coded '\n'.
* testsuite/nulldata.sh: Adjust tests accordingly.
This commit is contained in:
Assaf Gordon committed 2016-08-08 20:59:10 -04:00
1 parent cbd13f729d
commit f62a2a9965
2 files changed
+25 -13

No files matched your search

+10 -6
View File
@@ -955,13 +955,15 @@ do_list(int line_len)
}
olen = o - obuf;
if (width+olen >= line_len && line_len > 0) {
ck_fwrite("\\\n", 1, 2, fp);
ck_fwrite("\\", 1, 1, fp);
ck_fwrite(&buffer_delimiter, 1, 1, fp);
width = 0;
}
ck_fwrite(obuf, 1, olen, fp);
width += olen;
}
ck_fwrite("$\n", 1, 2, fp);
ck_fwrite("$", 1, 1, fp);
ck_fwrite(&buffer_delimiter, 1, 1, fp);
flush_output (fp);
}
@@ -1567,15 +1569,17 @@ execute_program(struct vector *vec, struct input *input)
case '=':
output_missing_newline(&output_file);
fprintf(output_file.fp, "%lu\n",
(unsigned long)input->line_number);
fprintf(output_file.fp, "%lu%c",
(unsigned long)input->line_number,
buffer_delimiter);
flush_output(output_file.fp);
break;
case 'F':
output_missing_newline(&output_file);
fprintf(output_file.fp, "%s\n",
input->in_file_name);
fprintf(output_file.fp, "%s%c",
input->in_file_name,
buffer_delimiter);
flush_output(output_file.fp);
break;
+15 -7
View File
@@ -30,8 +30,7 @@ printf "xB\000xD\nEF\n\000" > exp-s-z || framework_failure_
printf "1\nAB\000CD\n2\nEF\n3\n\000" > exp-=-nl || framework_failure_
# '=' cmd processed with EOF=\0
# NOTE: currenly the line numbers are printed with \n, regardless of -z
printf "1\nAB\0002\nCD\nEF\n\000" > exp-=-z || framework_failure_
printf "1\000AB\0002\000CD\nEF\n\000" > exp-=-z || framework_failure_
# 'l' cmd processed with EOF=\n
@@ -42,11 +41,13 @@ EF$
EOF
# 'l' cmd processed with EOF=\0
# NOTE: currently the line-endings of 'l' are always \n, regardless of -z
cat <<\EOF >exp-l-z || framework_failure_
AB$
CD\nEF\n$
EOF
printf 'AB$\000CD\\nEF\\n$\000' >exp-l-z || framework_failure_
# 'F' cmd with EOL=\n
printf "in1\n" > exp-F-nl || framework_failure_
# 'F' cmd with EOL=\0
printf "in1\000" > exp-F-z || framework_failure_
# Test substitution
@@ -75,5 +76,12 @@ sed -zn l in1 > out-l-z || fail=1
compare_ exp-l-z out-l-z || fail=1
# Test 'F' command
sed -n 1F in1 > out-F-nl || fail=1
compare_ exp-F-nl out-F-nl || fail=1
sed -zn 1F in1 > out-F-z || fail=1
compare_ exp-F-z out-F-z || fail=1
Exit $fail