diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-17 00:36:13 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-17 00:36:13 +0200 |
commit | 894466cc5182a022051868ede316f378071020cd (patch) | |
tree | 980a7d015b79cb19312e5aadfbef3a31be5f103f | |
parent | 038d4007092f6d0d2dc107f31397c57e62751717 (diff) | |
download | busybox-w32-894466cc5182a022051868ede316f378071020cd.tar.gz busybox-w32-894466cc5182a022051868ede316f378071020cd.tar.bz2 busybox-w32-894466cc5182a022051868ede316f378071020cd.zip |
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 6c4e3038c..32a06e40a 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
@@ -67,7 +67,7 @@ | |||
67 | //usage: "\n -r Reverse sort order" | 67 | //usage: "\n -r Reverse sort order" |
68 | //usage: "\n -s Stable (don't sort ties alphabetically)" | 68 | //usage: "\n -s Stable (don't sort ties alphabetically)" |
69 | //usage: "\n -u Suppress duplicate lines" | 69 | //usage: "\n -u Suppress duplicate lines" |
70 | //usage: "\n -z Lines are terminated by NUL, not newline" | 70 | //usage: "\n -z NUL terminated input and output" |
71 | ///////: "\n -m Ignored for GNU compatibility" | 71 | ///////: "\n -m Ignored for GNU compatibility" |
72 | ///////: "\n -S BUFSZ Ignored for GNU compatibility" | 72 | ///////: "\n -S BUFSZ Ignored for GNU compatibility" |
73 | ///////: "\n -T TMPDIR Ignored for GNU compatibility" | 73 | ///////: "\n -T TMPDIR Ignored for GNU compatibility" |
diff --git a/coreutils/uniq.c b/coreutils/uniq.c index e1594286f..ef50981ed 100644 --- a/coreutils/uniq.c +++ b/coreutils/uniq.c | |||
@@ -20,13 +20,14 @@ | |||
20 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/uniq.html */ | 20 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/uniq.html */ |
21 | 21 | ||
22 | //usage:#define uniq_trivial_usage | 22 | //usage:#define uniq_trivial_usage |
23 | //usage: "[-cdui] [-f,s,w N] [INPUT [OUTPUT]]" | 23 | //usage: "[-cduiz] [-f,s,w N] [FILE [OUTFILE]]" |
24 | //usage:#define uniq_full_usage "\n\n" | 24 | //usage:#define uniq_full_usage "\n\n" |
25 | //usage: "Discard duplicate lines\n" | 25 | //usage: "Discard duplicate lines\n" |
26 | //usage: "\n -c Prefix lines by the number of occurrences" | 26 | //usage: "\n -c Prefix lines by the number of occurrences" |
27 | //usage: "\n -d Only print duplicate lines" | 27 | //usage: "\n -d Only print duplicate lines" |
28 | //usage: "\n -u Only print unique lines" | 28 | //usage: "\n -u Only print unique lines" |
29 | //usage: "\n -i Ignore case" | 29 | //usage: "\n -i Ignore case" |
30 | //usage: "\n -z NUL terminated output" | ||
30 | //usage: "\n -f N Skip first N fields" | 31 | //usage: "\n -f N Skip first N fields" |
31 | //usage: "\n -s N Skip first N chars (after any skipped fields)" | 32 | //usage: "\n -s N Skip first N chars (after any skipped fields)" |
32 | //usage: "\n -w N Compare N characters in line" | 33 | //usage: "\n -w N Compare N characters in line" |
@@ -45,17 +46,19 @@ int uniq_main(int argc UNUSED_PARAM, char **argv) | |||
45 | const char *input_filename; | 46 | const char *input_filename; |
46 | unsigned skip_fields, skip_chars, max_chars; | 47 | unsigned skip_fields, skip_chars, max_chars; |
47 | unsigned opt; | 48 | unsigned opt; |
49 | char eol; | ||
48 | char *cur_line; | 50 | char *cur_line; |
49 | const char *cur_compare; | 51 | const char *cur_compare; |
50 | 52 | ||
51 | enum { | 53 | enum { |
52 | OPT_c = 0x1, | 54 | OPT_c = 1 << 0, |
53 | OPT_d = 0x2, /* print only dups */ | 55 | OPT_d = 1 << 1, /* print only dups */ |
54 | OPT_u = 0x4, /* print only uniq */ | 56 | OPT_u = 1 << 2, /* print only uniq */ |
55 | OPT_f = 0x8, | 57 | OPT_f = 1 << 3, |
56 | OPT_s = 0x10, | 58 | OPT_s = 1 << 4, |
57 | OPT_w = 0x20, | 59 | OPT_w = 1 << 5, |
58 | OPT_i = 0x40, | 60 | OPT_i = 1 << 6, |
61 | OPT_z = 1 << 7, | ||
59 | }; | 62 | }; |
60 | 63 | ||
61 | skip_fields = skip_chars = 0; | 64 | skip_fields = skip_chars = 0; |
@@ -86,6 +89,7 @@ int uniq_main(int argc UNUSED_PARAM, char **argv) | |||
86 | } | 89 | } |
87 | 90 | ||
88 | cur_compare = cur_line = NULL; /* prime the pump */ | 91 | cur_compare = cur_line = NULL; /* prime the pump */ |
92 | eol = (opt & OPT_z) ? 0 : '\n'; | ||
89 | 93 | ||
90 | do { | 94 | do { |
91 | unsigned i; | 95 | unsigned i; |
@@ -127,7 +131,7 @@ int uniq_main(int argc UNUSED_PARAM, char **argv) | |||
127 | /* %7lu matches GNU coreutils 6.9 */ | 131 | /* %7lu matches GNU coreutils 6.9 */ |
128 | printf("%7lu ", dups + 1); | 132 | printf("%7lu ", dups + 1); |
129 | } | 133 | } |
130 | puts(old_line); | 134 | printf("%s%c", old_line, eol); |
131 | } | 135 | } |
132 | free(old_line); | 136 | free(old_line); |
133 | } | 137 | } |
diff --git a/modutils/modinfo.c b/modutils/modinfo.c index d15772f0d..0a86c3296 100644 --- a/modutils/modinfo.c +++ b/modutils/modinfo.c | |||
@@ -131,7 +131,7 @@ static void modinfo(const char *path, const char *version, | |||
131 | //usage: "\n -p Shortcut for '-F parm'" | 131 | //usage: "\n -p Shortcut for '-F parm'" |
132 | ////usage: "\n -n Shortcut for '-F filename'" | 132 | ////usage: "\n -n Shortcut for '-F filename'" |
133 | //usage: "\n -F keyword Keyword to look for" | 133 | //usage: "\n -F keyword Keyword to look for" |
134 | //usage: "\n -0 Separate output with NULs" | 134 | //usage: "\n -0 NUL terminated output" |
135 | //usage:#define modinfo_example_usage | 135 | //usage:#define modinfo_example_usage |
136 | //usage: "$ modinfo -F vermagic loop\n" | 136 | //usage: "$ modinfo -F vermagic loop\n" |
137 | 137 | ||