diff options
author | Denys Vlasenko | 2021-06-17 00:36:13 +0200 |
---|---|---|
committer | Denys Vlasenko | 2021-06-17 00:36:13 +0200 |
commit | 894466cc5182a022051868ede316f378071020cd (patch) | |
tree | 980a7d015b79cb19312e5aadfbef3a31be5f103f | |
parent | 038d4007092f6d0d2dc107f31397c57e62751717 (diff) | |
download | busybox-894466cc5182a022051868ede316f378071020cd.zip busybox-894466cc5182a022051868ede316f378071020cd.tar.gz |
uniq: support -z
function old new delta
uniq_main 391 427 +36
packed_usage 33570 33549 -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 36/-21) Total: 15 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/sort.c | 2 | ||||
-rw-r--r-- | coreutils/uniq.c | 22 | ||||
-rw-r--r-- | modutils/modinfo.c | 2 |
3 files changed, 15 insertions, 11 deletions
diff --git a/coreutils/sort.c b/coreutils/sort.c index 6c4e303..32a06e4 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -67,7 +67,7 @@ //usage: "\n -r Reverse sort order" //usage: "\n -s Stable (don't sort ties alphabetically)" //usage: "\n -u Suppress duplicate lines" -//usage: "\n -z Lines are terminated by NUL, not newline" +//usage: "\n -z NUL terminated input and output" ///////: "\n -m Ignored for GNU compatibility" ///////: "\n -S BUFSZ Ignored for GNU compatibility" ///////: "\n -T TMPDIR Ignored for GNU compatibility" diff --git a/coreutils/uniq.c b/coreutils/uniq.c index e159428..ef50981 100644 --- a/coreutils/uniq.c +++ b/coreutils/uniq.c @@ -20,13 +20,14 @@ /* http://www.opengroup.org/onlinepubs/007904975/utilities/uniq.html */ //usage:#define uniq_trivial_usage -//usage: "[-cdui] [-f,s,w N] [INPUT [OUTPUT]]" +//usage: "[-cduiz] [-f,s,w N] [FILE [OUTFILE]]" //usage:#define uniq_full_usage "\n\n" //usage: "Discard duplicate lines\n" //usage: "\n -c Prefix lines by the number of occurrences" //usage: "\n -d Only print duplicate lines" //usage: "\n -u Only print unique lines" //usage: "\n -i Ignore case" +//usage: "\n -z NUL terminated output" //usage: "\n -f N Skip first N fields" //usage: "\n -s N Skip first N chars (after any skipped fields)" //usage: "\n -w N Compare N characters in line" @@ -45,17 +46,19 @@ int uniq_main(int argc UNUSED_PARAM, char **argv) const char *input_filename; unsigned skip_fields, skip_chars, max_chars; unsigned opt; + char eol; char *cur_line; const char *cur_compare; enum { - OPT_c = 0x1, - OPT_d = 0x2, /* print only dups */ - OPT_u = 0x4, /* print only uniq */ - OPT_f = 0x8, - OPT_s = 0x10, - OPT_w = 0x20, - OPT_i = 0x40, + OPT_c = 1 << 0, + OPT_d = 1 << 1, /* print only dups */ + OPT_u = 1 << 2, /* print only uniq */ + OPT_f = 1 << 3, + OPT_s = 1 << 4, + OPT_w = 1 << 5, + OPT_i = 1 << 6, + OPT_z = 1 << 7, }; skip_fields = skip_chars = 0; @@ -86,6 +89,7 @@ int uniq_main(int argc UNUSED_PARAM, char **argv) } cur_compare = cur_line = NULL; /* prime the pump */ + eol = (opt & OPT_z) ? 0 : '\n'; do { unsigned i; @@ -127,7 +131,7 @@ int uniq_main(int argc UNUSED_PARAM, char **argv) /* %7lu matches GNU coreutils 6.9 */ printf("%7lu ", dups + 1); } - puts(old_line); + printf("%s%c", old_line, eol); } free(old_line); } diff --git a/modutils/modinfo.c b/modutils/modinfo.c index d15772f..0a86c32 100644 --- a/modutils/modinfo.c +++ b/modutils/modinfo.c @@ -131,7 +131,7 @@ static void modinfo(const char *path, const char *version, //usage: "\n -p Shortcut for '-F parm'" ////usage: "\n -n Shortcut for '-F filename'" //usage: "\n -F keyword Keyword to look for" -//usage: "\n -0 Separate output with NULs" +//usage: "\n -0 NUL terminated output" //usage:#define modinfo_example_usage //usage: "$ modinfo -F vermagic loop\n" |