aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2005-09-06 01:57:11 +0000
committerRob Landley <rob@landley.net>2005-09-06 01:57:11 +0000
commit1283a150aeaff9e563223981a54f7bdf1592743f (patch)
treec47f4639d081f5cc395fc4b6b9c6963e0dca5737
parent9955c45907cb0a90648b76d23d1a8914926dedb9 (diff)
downloadbusybox-w32-1283a150aeaff9e563223981a54f7bdf1592743f.tar.gz
busybox-w32-1283a150aeaff9e563223981a54f7bdf1592743f.tar.bz2
busybox-w32-1283a150aeaff9e563223981a54f7bdf1592743f.zip
Whitespace-level changes. Replace s0,s1,e0,e1 with real variable names and
clean up whitespace and curly brackets a bit. Resulting binary should be identical.
-rw-r--r--coreutils/uniq.c63
1 files changed, 24 insertions, 39 deletions
diff --git a/coreutils/uniq.c b/coreutils/uniq.c
index 415f5db3b..312653263 100644
--- a/coreutils/uniq.c
+++ b/coreutils/uniq.c
@@ -36,74 +36,59 @@ static const char uniq_opts[] = "f:s:cdu\0\7\3\5\1\2\4";
36int uniq_main(int argc, char **argv) 36int uniq_main(int argc, char **argv)
37{ 37{
38 FILE *in, *out; 38 FILE *in, *out;
39 /* Note: Ignore the warning about dups and e0 being used uninitialized.
40 * They will be initialized on the fist pass of the loop (since s0 is NULL). */
41#warning The dups and e0 warnings are OK, ignore them
42 unsigned long dups, skip_fields, skip_chars, i; 39 unsigned long dups, skip_fields, skip_chars, i;
43 const char *s0, *e0, *s1, *e1, *input_filename; 40 const char *oldline, *oldskipped, *line, *skipped, *input_filename;
44 int opt; 41 int opt;
45 int uniq_flags = 6; /* -u */ 42 int uniq_flags = 6; /* -u */
46 43
47 skip_fields = skip_chars = 0; 44 skip_fields = skip_chars = 0;
48 45
49 while ((opt = getopt(argc, argv, uniq_opts)) > 0) { 46 while ((opt = getopt(argc, argv, uniq_opts)) > 0) {
50 if (opt == 'f') { 47 if (opt == 'f') skip_fields = bb_xgetularg10(optarg);
51 skip_fields = bb_xgetularg10(optarg); 48 else if (opt == 's') skip_chars = bb_xgetularg10(optarg);
52 } else if (opt == 's') { 49 else if ((line = strchr(uniq_opts, opt)) != NULL) {
53 skip_chars = bb_xgetularg10(optarg); 50 uniq_flags &= line[4];
54 } else if ((s0 = strchr(uniq_opts, opt)) != NULL) { 51 uniq_flags |= line[7];
55 uniq_flags &= s0[4]; 52 } else bb_show_usage();
56 uniq_flags |= s0[7];
57 } else {
58 bb_show_usage();
59 }
60 } 53 }
61 54
62 input_filename = *(argv += optind); 55 input_filename = *(argv += optind);
63 56
64 in = xgetoptfile_sort_uniq(argv, "r"); 57 in = xgetoptfile_sort_uniq(argv, "r");
65 if (*argv) { 58 if (*argv) ++argv;
66 ++argv;
67 }
68 out = xgetoptfile_sort_uniq(argv, "w"); 59 out = xgetoptfile_sort_uniq(argv, "w");
69 if (*argv && argv[1]) { 60 if (*argv && argv[1]) bb_show_usage();
70 bb_show_usage();
71 }
72 61
73 s0 = NULL; 62 oldline = NULL;
74 63
75 /* gnu uniq ignores newlines */ 64 /* gnu uniq ignores newlines */
76 while ((s1 = bb_get_chomped_line_from_file(in)) != NULL) { 65 while ((line = bb_get_chomped_line_from_file(in)) != NULL) {
77 e1 = s1; 66 skipped = line;
78 for (i=skip_fields ; i ; i--) { 67 for (i=skip_fields ; i ; i--) {
79 e1 = bb_skip_whitespace(e1); 68 skipped = bb_skip_whitespace(skipped);
80 while (*e1 && !isspace(*e1)) { 69 while (*skipped && !isspace(*skipped)) ++skipped;
81 ++e1;
82 }
83 }
84 for (i = skip_chars ; *e1 && i ; i--) {
85 ++e1;
86 } 70 }
87 if (s0) { 71 for (i = skip_chars ; *skipped && i ; i--) ++skipped;
88 if (strcmp(e0, e1) == 0) { 72 if (oldline) {
73 if (strcmp(oldskipped, skipped) == 0) {
89 ++dups; /* Note: Testing for overflow seems excessive. */ 74 ++dups; /* Note: Testing for overflow seems excessive. */
90 continue; 75 continue;
91 } 76 }
92 DO_LAST: 77DO_LAST:
93 if ((dups && (uniq_flags & 2)) || (!dups && (uniq_flags & 4))) { 78 if ((dups && (uniq_flags & 2)) || (!dups && (uniq_flags & 4))) {
94 bb_fprintf(out, "\0%7d\t" + (uniq_flags & 1), dups + 1); 79 bb_fprintf(out, "\0%7d\t" + (uniq_flags & 1), dups + 1);
95 bb_fprintf(out, "%s\n", s0); 80 bb_fprintf(out, "%s\n", oldline);
96 } 81 }
97 free((void *)s0); 82 free((void *)oldline);
98 } 83 }
99 84
100 s0 = s1; 85 oldline = line;
101 e0 = e1; 86 oldskipped = skipped;
102 dups = 0; 87 dups = 0;
103 } 88 }
104 89
105 if (s0) { 90 if (oldline) {
106 e1 = NULL; 91 skipped = NULL;
107 goto DO_LAST; 92 goto DO_LAST;
108 } 93 }
109 94