add -z/--null-data

2012-02-05  Paolo Bonzini  <bonzini@gnu.org>
            Jim Hill  <gjthill@gmail.com>

	* autoboot.conf: Change getline to getdelim.
	* doc/sed-in.texi: Document -z/--null-data.
	* doc/sed.texi: Regenerate.
	* sed/execute.c: Change '\n' to buffer_delimiter.
	* sed/sed.c: Add support for -z/--null-data.
	* sed/sed.h: Add buffer_delimiter.
	* sed/utils.c: Change ck_getline to ck_getdelim.
	* sed/utils.h: Change ck_getline to ck_getdelim.
	* NEWS: Document new option.
This commit is contained in:
Paolo Bonzini committed 2012-02-05 12:08:57 +01:00
1 parent 727d6fa860
commit a085906489
11 files changed
+77 -21

No files matched your search

+14
View File
@@ -1,3 +1,17 @@
2012-02-05 Paolo Bonzini <bonzini@gnu.org>
Jim Hill <gjthill@gmail.com>
* autoboot.conf: Change getline to getdelim.
* doc/sed-in.texi: Document -z/--null-data.
* doc/sed.texi: Regenerate.
* doc/sed.1: Regenerate.
* sed/execute.c: Change '\n' to buffer_delimiter.
* sed/sed.c: Add support for -z/--null-data.
* sed/sed.h: Add buffer_delimiter.
* sed/utils.c: Change ck_getline to ck_getdelim.
* sed/utils.h: Change ck_getline to ck_getdelim.
* NEWS: Document new option.
2011-11-23 Paolo Bonzini <bonzini@gnu.org>
* doc/sed-in.texi: Document how multiline mode affects matching
+2
View File
@@ -14,6 +14,8 @@ Sed 4.2.2
* --posix fails for scripts (or fragments as passed to the -e option) that
end in a backslash, as they are not portable.
* New option -z (--null-data) to separate lines by ASCII NUL characters.
----------------------------------------------------------------------------
Sed 4.2.1
+1 -1
View File
@@ -18,7 +18,7 @@
# gnulib modules used by this package.
gnulib_modules="
acl alloca btowc c-ctype extensions fwriting getline getopt gettext-h
acl alloca btowc c-ctype extensions fwriting getdelim getopt gettext-h
localcharset mbrlen mbrtowc mbsinit memchr mkostemp obstack pathmax regex
rename selinux-h stdbool stat-macros ssize_t strerror strverscmp
unlocked-io verify version-etc-fsf wcrtomb wctob"
+10
View File
@@ -369,6 +369,16 @@ Buffer both input and output as minimally as practical.
the likes of @samp{tail -f}, and you wish to see the transformed
output as soon as possible.)
@item -z
@itemx --null-data
@itemx --zero-terminated
@opindex -z
@opindex --null-data
@opindex --zero-terminated
Treat the input as a set of lines, each terminated by a zero byte
(the ASCII @samp{NUL} character) instead of a newline. This option can
be used with commands like @samp{sort -z} and @samp{find -print0}
to process arbitrary file names.
@end table
If no @option{-e}, @option{-f}, @option{--expression}, or @option{--file}
+7 -3
View File
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.28.
.TH SED "1" "December 2010" "sed 4.2.1" "User Commands"
.TH SED "1" "February 2012" "sed 4.2.1" "User Commands"
.SH NAME
sed \- stream editor for filtering and transforming text
.SH SYNOPSIS
@@ -38,7 +38,7 @@ follow symlinks when processing in place
.HP
\fB\-i[SUFFIX]\fR, \fB\-\-in\-place\fR[=\fISUFFIX\fR]
.IP
edit files in place (makes backup if extension supplied)
edit files in place (makes backup if SUFFIX supplied)
.HP
\fB\-l\fR N, \fB\-\-line\-length\fR=\fIN\fR
.IP
@@ -61,6 +61,10 @@ long stream.
.IP
load minimal amounts of data from the input files and flush
the output buffers more often
.HP
\fB\-z\fR, \fB\-\-null\-data\fR
.IP
separate lines by NUL characters
.TP
\fB\-\-help\fR
display this help and exit
@@ -374,7 +378,7 @@ General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-sed@gnu.org>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
.SH COPYRIGHT
Copyright \(co 2010 Free Software Foundation, Inc.
Copyright \(co 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
.br
This is free software: you are free to change and redistribute it.
+10
View File
@@ -370,6 +370,16 @@ Buffer both input and output as minimally as practical.
the likes of @samp{tail -f}, and you wish to see the transformed
output as soon as possible.)
@item -z
@itemx --null-data
@itemx --zero-terminated
@opindex -z
@opindex --null-data
@opindex --zero-terminated
Treat the input as a set of lines, each terminated by a zero byte
(the ASCII @samp{NUL} character) instead of a newline. This option can
be used with commands like @samp{sort -z} and @samp{find -print0}
to process arbitrary file names.
@end table
If no @option{-e}, @option{-f}, @option{--expression}, or @option{--file}
+13 -12
View File
@@ -472,7 +472,7 @@ line_append(from, to, state)
struct line *to;
int state;
{
str_append(to, "\n", 1);
str_append(to, &buffer_delimiter, 1);
str_append(to, from->active, from->length);
to->chomped = from->chomped;
@@ -525,12 +525,12 @@ read_file_line(input)
static char *b;
static size_t blen;
long result = ck_getline (&b, &blen, input->fp);
long result = ck_getdelim (&b, &blen, buffer_delimiter, input->fp);
if (result <= 0)
return false;
/* Remove the trailing new-line that is left by getline. */
if (b[result - 1] == '\n')
if (b[result - 1] == buffer_delimiter)
--result;
else
line.chomped = false;
@@ -547,7 +547,7 @@ output_missing_newline(outf)
{
if (outf->missing_newline)
{
ck_fwrite("\n", 1, 1, outf->fp);
ck_fwrite(&buffer_delimiter, 1, 1, outf->fp);
outf->missing_newline = false;
}
}
@@ -576,7 +576,7 @@ output_line(text, length, nl, outf)
if (length)
ck_fwrite(text, 1, length, outf->fp);
if (nl)
ck_fwrite("\n", 1, 1, outf->fp);
ck_fwrite(&buffer_delimiter, 1, 1, outf->fp);
else
outf->missing_newline = true;
@@ -1315,7 +1315,7 @@ do_subst(sub)
for 'g' as to while the third argument is incorrect anyway. */
line_exchange(&line, &s_accum, true);
if (line.length &&
line.active[line.length - 1] == '\n')
line.active[line.length - 1] == buffer_delimiter)
line.length--;
}
else
@@ -1435,7 +1435,7 @@ execute_program(vec, input)
case 'D':
{
char *p = memchr(line.active, '\n', line.length);
char *p = memchr(line.active, buffer_delimiter, line.length);
if (!p)
return -1;
@@ -1485,7 +1485,7 @@ execute_program(vec, input)
{
/* Store into pattern space for plain `e' commands */
if (s_accum.length &&
s_accum.active[s_accum.length - 1] == '\n')
s_accum.active[s_accum.length - 1] == buffer_delimiter)
s_accum.length--;
/* Exchange line and s_accum. This can be much
@@ -1566,7 +1566,7 @@ execute_program(vec, input)
break;
case 'N':
str_append(&line, "\n", 1);
str_append(&line, &buffer_delimiter, 1);
if (test_eof(input) || !read_pattern_space(input, vec, true))
{
@@ -1584,7 +1584,7 @@ execute_program(vec, input)
case 'P':
{
char *p = memchr(line.active, '\n', line.length);
char *p = memchr(line.active, buffer_delimiter, line.length);
output_line(line.active, p ? p - line.active : line.length,
p ? true : line.chomped, &output_file);
}
@@ -1614,7 +1614,8 @@ execute_program(vec, input)
char *text = NULL;
int result;
result = ck_getline (&text, &buflen, cur_cmd->x.fp);
result = ck_getdelim (&text, &buflen, buffer_delimiter,
cur_cmd->x.fp);
if (result != EOF)
{
aq = next_append_slot();
@@ -1657,7 +1658,7 @@ execute_program(vec, input)
case 'W':
if (cur_cmd->x.fp)
{
char *p = memchr(line.active, '\n', line.length);
char *p = memchr(line.active, buffer_delimiter, line.length);
output_line(line.active, p ? p - line.active : line.length,
p ? true : line.chomped, cur_cmd->x.outf);
}
+13 -2
View File
@@ -68,6 +68,9 @@ char *program_name;
int extended_regexp_flags = 0;
/* one-byte buffer delimiter */
char buffer_delimiter = '\n';
/* If set, fflush(stdout) on every line output. */
bool unbuffered = false;
@@ -163,6 +166,8 @@ Usage: %s [OPTION]... {script-only-if-no-other-script} [input-file]...\n\
fprintf(out, _(" -u, --unbuffered\n\
load minimal amounts of data from the input files and flush\n\
the output buffers more often\n"));
fprintf(out, _(" -z, --null-data\n\
separate lines by NUL characters\n"));
fprintf(out, _(" --help display this help and exit\n"));
fprintf(out, _(" --version output version information and exit\n"));
fprintf(out, _("\n\
@@ -183,9 +188,9 @@ main(argc, argv)
char **argv;
{
#ifdef REG_PERL
#define SHORTOPTS "bsnrRuEe:f:l:i::V:"
#define SHORTOPTS "bsnrzRuEe:f:l:i::V:"
#else
#define SHORTOPTS "bsnruEe:f:l:i::V:"
#define SHORTOPTS "bsnrzuEe:f:l:i::V:"
#endif
static struct option longopts[] = {
@@ -198,6 +203,8 @@ main(argc, argv)
{"file", 1, NULL, 'f'},
{"in-place", 2, NULL, 'i'},
{"line-length", 1, NULL, 'l'},
{"null-data", 0, NULL, 'z'},
{"zero-terminated", 0, NULL, 'z'},
{"quiet", 0, NULL, 'n'},
{"posix", 0, NULL, 'p'},
{"silent", 0, NULL, 'n'},
@@ -261,6 +268,10 @@ main(argc, argv)
the_program = compile_file(the_program, optarg);
break;
case 'z':
buffer_delimiter = 0;
break;
case 'F':
follow_symlinks = true;
break;
+3
View File
@@ -211,6 +211,9 @@ extern void fmt P_ ((const char *line, const char *line_end, int max_length, FIL
extern int extended_regexp_flags;
/* one-byte buffer delimiter */
extern char buffer_delimiter;
/* If set, fflush(stdout) on every line output,
and turn off stream buffering on inputs. */
extern bool unbuffered;
+3 -2
View File
@@ -259,9 +259,10 @@ ck_fread(ptr, size, nmemb, stream)
}
size_t
ck_getline(text, buflen, stream)
ck_getdelim(text, buflen, buffer_delimiter, stream)
char **text;
size_t *buflen;
char buffer_delimiter;
FILE *stream;
{
ssize_t result;
@@ -270,7 +271,7 @@ ck_getline(text, buflen, stream)
error = ferror (stream);
if (!error)
{
result = getline (text, buflen, stream);
result = getdelim (text, buflen, buffer_delimiter, stream);
error = ferror (stream);
}
+1 -1
View File
@@ -29,7 +29,7 @@ size_t ck_fread P_((VOID *ptr, size_t size, size_t nmemb, FILE *stream));
void ck_fflush P_((FILE *stream));
void ck_fclose P_((FILE *stream));
const char *follow_symlink P_((const char *path));
size_t ck_getline P_((char **text, size_t *buflen, FILE *stream));
size_t ck_getdelim P_((char **text, size_t *buflen, char buffer_delimiter, FILE *stream));
FILE * ck_mkstemp P_((char **p_filename, const char *tmpdir, const char *base,
const char *mode));
void ck_rename P_((const char *from, const char *to, const char *unlink_if_fail));