diff options
Diffstat (limited to 'coreutils/uniq.c')
-rw-r--r-- | coreutils/uniq.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/coreutils/uniq.c b/coreutils/uniq.c index e1594286f..a3058ac07 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,23 +46,25 @@ 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; |
62 | max_chars = INT_MAX; | 65 | max_chars = INT_MAX; |
63 | 66 | ||
64 | opt = getopt32(argv, "cduf:+s:+w:+i", &skip_fields, &skip_chars, &max_chars); | 67 | opt = getopt32(argv, "cduf:+s:+w:+iz", &skip_fields, &skip_chars, &max_chars); |
65 | argv += optind; | 68 | argv += optind; |
66 | 69 | ||
67 | input_filename = argv[0]; | 70 | input_filename = argv[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 | } |