diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-08-30 19:32:45 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-08-30 19:32:45 +0200 |
commit | 0aec9ff6b822116f453effb1867f9811c40ad59b (patch) | |
tree | d71a14231b73a071e048af02423c403349e7d292 /coreutils | |
parent | 7218af9f83c28bc40892c6e71a3774822b7df230 (diff) | |
download | busybox-w32-0aec9ff6b822116f453effb1867f9811c40ad59b.tar.gz busybox-w32-0aec9ff6b822116f453effb1867f9811c40ad59b.tar.bz2 busybox-w32-0aec9ff6b822116f453effb1867f9811c40ad59b.zip |
uniq: rename some variables. no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/uniq.c | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/coreutils/uniq.c b/coreutils/uniq.c index 126eaeef9..eceff6d4b 100644 --- a/coreutils/uniq.c +++ b/coreutils/uniq.c | |||
@@ -18,7 +18,7 @@ static FILE *xgetoptfile_uniq_s(char **argv, int read0write2) | |||
18 | 18 | ||
19 | n = *argv; | 19 | n = *argv; |
20 | if (n != NULL) { | 20 | if (n != NULL) { |
21 | if ((*n != '-') || n[1]) { | 21 | if ((n[0] != '-') || n[1]) { |
22 | return xfopen(n, "r\0w" + read0write2); | 22 | return xfopen(n, "r\0w" + read0write2); |
23 | } | 23 | } |
24 | } | 24 | } |
@@ -29,16 +29,16 @@ int uniq_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
29 | int uniq_main(int argc UNUSED_PARAM, char **argv) | 29 | int uniq_main(int argc UNUSED_PARAM, char **argv) |
30 | { | 30 | { |
31 | FILE *in, *out; | 31 | FILE *in, *out; |
32 | const char *s0, *e0, *s1, *e1, *input_filename; | 32 | const char *input_filename; |
33 | unsigned long dups; | ||
34 | unsigned skip_fields, skip_chars, max_chars; | 33 | unsigned skip_fields, skip_chars, max_chars; |
35 | unsigned opt; | 34 | unsigned opt; |
36 | unsigned i; | 35 | char *cur_line; |
36 | const char *cur_compare; | ||
37 | 37 | ||
38 | enum { | 38 | enum { |
39 | OPT_c = 0x1, | 39 | OPT_c = 0x1, |
40 | OPT_d = 0x2, | 40 | OPT_d = 0x2, /* print only dups */ |
41 | OPT_u = 0x4, | 41 | OPT_u = 0x4, /* print only uniq */ |
42 | OPT_f = 0x8, | 42 | OPT_f = 0x8, |
43 | OPT_s = 0x10, | 43 | OPT_s = 0x10, |
44 | OPT_w = 0x20, | 44 | OPT_w = 0x20, |
@@ -62,39 +62,44 @@ int uniq_main(int argc UNUSED_PARAM, char **argv) | |||
62 | bb_show_usage(); | 62 | bb_show_usage(); |
63 | } | 63 | } |
64 | 64 | ||
65 | s1 = e1 = NULL; /* prime the pump */ | 65 | cur_compare = cur_line = NULL; /* prime the pump */ |
66 | 66 | ||
67 | do { | 67 | do { |
68 | s0 = s1; | 68 | unsigned i; |
69 | e0 = e1; | 69 | unsigned long dups; |
70 | char *old_line; | ||
71 | const char *old_compare; | ||
72 | |||
73 | old_line = cur_line; | ||
74 | old_compare = cur_compare; | ||
70 | dups = 0; | 75 | dups = 0; |
71 | 76 | ||
72 | /* gnu uniq ignores newlines */ | 77 | /* gnu uniq ignores newlines */ |
73 | while ((s1 = xmalloc_fgetline(in)) != NULL) { | 78 | while ((cur_line = xmalloc_fgetline(in)) != NULL) { |
74 | e1 = s1; | 79 | cur_compare = cur_line; |
75 | for (i = skip_fields; i; i--) { | 80 | for (i = skip_fields; i; i--) { |
76 | e1 = skip_whitespace(e1); | 81 | cur_compare = skip_whitespace(cur_compare); |
77 | e1 = skip_non_whitespace(e1); | 82 | cur_compare = skip_non_whitespace(cur_compare); |
78 | } | 83 | } |
79 | for (i = skip_chars; *e1 && i; i--) { | 84 | for (i = skip_chars; *cur_compare && i; i--) { |
80 | ++e1; | 85 | ++cur_compare; |
81 | } | 86 | } |
82 | 87 | ||
83 | if (!s0 || strncmp(e0, e1, max_chars)) { | 88 | if (!old_line || strncmp(old_compare, cur_compare, max_chars)) { |
84 | break; | 89 | break; |
85 | } | 90 | } |
86 | 91 | ||
87 | ++dups; /* note: testing for overflow seems excessive. */ | 92 | ++dups; /* testing for overflow seems excessive */ |
88 | } | 93 | } |
89 | 94 | ||
90 | if (s0) { | 95 | if (old_line) { |
91 | if (!(opt & (OPT_d << !!dups))) { /* (if dups, opt & OPT_e) */ | 96 | if (!(opt & (OPT_d << !!dups))) { /* (if dups, opt & OPT_u) */ |
92 | fprintf(out, "\0%ld " + (opt & 1), dups + 1); /* 1 == OPT_c */ | 97 | fprintf(out, "\0%lu " + (opt & 1), dups + 1); /* 1 == OPT_c */ |
93 | fprintf(out, "%s\n", s0); | 98 | fprintf(out, "%s\n", old_line); |
94 | } | 99 | } |
95 | free((void *)s0); | 100 | free(old_line); |
96 | } | 101 | } |
97 | } while (s1); | 102 | } while (cur_line); |
98 | 103 | ||
99 | die_if_ferror(in, input_filename); | 104 | die_if_ferror(in, input_filename); |
100 | 105 | ||