diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-05-03 07:21:27 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-05-03 07:21:27 +0000 |
commit | 96b99b860cc15f13b85b1b2d5b5b20ab7183a652 (patch) | |
tree | f7f5236085dcc40f02bd29078900d971a787344e /coreutils/uniq.c | |
parent | 687a26fe0dcf10f227cb0541882d1daa8a21991d (diff) | |
download | busybox-w32-96b99b860cc15f13b85b1b2d5b5b20ab7183a652.tar.gz busybox-w32-96b99b860cc15f13b85b1b2d5b5b20ab7183a652.tar.bz2 busybox-w32-96b99b860cc15f13b85b1b2d5b5b20ab7183a652.zip |
uniq: support -w. closes bug 3094.
function old new delta
packed_usage 24136 24132 -4
uniq_main 399 384 -15
Diffstat (limited to 'coreutils/uniq.c')
-rw-r--r-- | coreutils/uniq.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/coreutils/uniq.c b/coreutils/uniq.c index 32327c6ce..41f1fed7b 100644 --- a/coreutils/uniq.c +++ b/coreutils/uniq.c | |||
@@ -12,8 +12,6 @@ | |||
12 | 12 | ||
13 | #include "libbb.h" | 13 | #include "libbb.h" |
14 | 14 | ||
15 | static const char uniq_opts[] ALIGN1 = "cdu" "f:s:" "cdu\0\1\2\4"; | ||
16 | |||
17 | static FILE *xgetoptfile_uniq_s(char **argv, int read0write2) | 15 | static FILE *xgetoptfile_uniq_s(char **argv, int read0write2) |
18 | { | 16 | { |
19 | const char *n; | 17 | const char *n; |
@@ -31,9 +29,11 @@ int uniq_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
31 | int uniq_main(int argc ATTRIBUTE_UNUSED, char **argv) | 29 | int uniq_main(int argc ATTRIBUTE_UNUSED, char **argv) |
32 | { | 30 | { |
33 | FILE *in, *out; | 31 | FILE *in, *out; |
34 | unsigned long dups, skip_fields, skip_chars, i; | ||
35 | const char *s0, *e0, *s1, *e1, *input_filename; | 32 | const char *s0, *e0, *s1, *e1, *input_filename; |
33 | unsigned long dups; | ||
34 | unsigned skip_fields, skip_chars, max_chars; | ||
36 | unsigned opt; | 35 | unsigned opt; |
36 | unsigned i; | ||
37 | 37 | ||
38 | enum { | 38 | enum { |
39 | OPT_c = 0x1, | 39 | OPT_c = 0x1, |
@@ -41,15 +41,14 @@ int uniq_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
41 | OPT_u = 0x4, | 41 | OPT_u = 0x4, |
42 | OPT_f = 0x8, | 42 | OPT_f = 0x8, |
43 | OPT_s = 0x10, | 43 | OPT_s = 0x10, |
44 | OPT_w = 0x20, | ||
44 | }; | 45 | }; |
45 | 46 | ||
46 | skip_fields = skip_chars = 0; | 47 | skip_fields = skip_chars = 0; |
48 | max_chars = -1; | ||
47 | 49 | ||
48 | opt = getopt32(argv, "cduf:s:", &s0, &s1); | 50 | opt_complementary = "f+:s+:w+"; |
49 | if (opt & OPT_f) | 51 | opt = getopt32(argv, "cduf:s:w:", &skip_fields, &skip_chars, &max_chars); |
50 | skip_fields = xatoul(s0); | ||
51 | if (opt & OPT_s) | ||
52 | skip_chars = xatoul(s1); | ||
53 | argv += optind; | 52 | argv += optind; |
54 | 53 | ||
55 | input_filename = *argv; | 54 | input_filename = *argv; |
@@ -63,7 +62,7 @@ int uniq_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
63 | bb_show_usage(); | 62 | bb_show_usage(); |
64 | } | 63 | } |
65 | 64 | ||
66 | s1 = e1 = NULL; /* prime the pump */ | 65 | s1 = e1 = NULL; /* prime the pump */ |
67 | 66 | ||
68 | do { | 67 | do { |
69 | s0 = s1; | 68 | s0 = s1; |
@@ -81,16 +80,16 @@ int uniq_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
81 | ++e1; | 80 | ++e1; |
82 | } | 81 | } |
83 | 82 | ||
84 | if (!s0 || strcmp(e0, e1)) { | 83 | if (!s0 || strncmp(e0, e1, max_chars)) { |
85 | break; | 84 | break; |
86 | } | 85 | } |
87 | 86 | ||
88 | ++dups; /* Note: Testing for overflow seems excessive. */ | 87 | ++dups; /* note: testing for overflow seems excessive. */ |
89 | } | 88 | } |
90 | 89 | ||
91 | if (s0) { | 90 | if (s0) { |
92 | if (!(opt & (OPT_d << !!dups))) { /* (if dups, opt & OPT_e) */ | 91 | if (!(opt & (OPT_d << !!dups))) { /* (if dups, opt & OPT_e) */ |
93 | fprintf(out, "\0%d " + (opt & 1), dups + 1); | 92 | fprintf(out, "\0%ld " + (opt & 1), dups + 1); /* 1 == OPT_c */ |
94 | fprintf(out, "%s\n", s0); | 93 | fprintf(out, "%s\n", s0); |
95 | } | 94 | } |
96 | free((void *)s0); | 95 | free((void *)s0); |