diff options
author | Mike Frysinger <vapier@gentoo.org> | 2005-05-12 22:25:41 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2005-05-12 22:25:41 +0000 |
commit | 0d605e98b2ad4940dcd9dceaba21286718af9cbe (patch) | |
tree | 239671caeffaef7449ed35025ae3d7ccefc12868 /coreutils/comm.c | |
parent | a84a512700eae9606d3c1f657381ce9b6446677a (diff) | |
download | busybox-w32-0d605e98b2ad4940dcd9dceaba21286718af9cbe.tar.gz busybox-w32-0d605e98b2ad4940dcd9dceaba21286718af9cbe.tar.bz2 busybox-w32-0d605e98b2ad4940dcd9dceaba21286718af9cbe.zip |
fix whitespace/coding style
Diffstat (limited to 'coreutils/comm.c')
-rw-r--r-- | coreutils/comm.c | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/coreutils/comm.c b/coreutils/comm.c index 3e81a5aa3..6b7b9554c 100644 --- a/coreutils/comm.c +++ b/coreutils/comm.c | |||
@@ -38,17 +38,21 @@ static int only_file_2; | |||
38 | static int both; | 38 | static int both; |
39 | 39 | ||
40 | /* writeline outputs the input given, appropriately aligned according to class */ | 40 | /* writeline outputs the input given, appropriately aligned according to class */ |
41 | static void writeline (char *line, int class) { | 41 | static void writeline (char *line, int class) |
42 | { | ||
42 | switch (class) { | 43 | switch (class) { |
43 | case 1: if (!only_file_1) | 44 | case 1: |
45 | if (!only_file_1) | ||
44 | return; | 46 | return; |
45 | break; | 47 | break; |
46 | case 2: if (!only_file_2) | 48 | case 2: |
49 | if (!only_file_2) | ||
47 | return; | 50 | return; |
48 | if (only_file_1) | 51 | if (only_file_1) |
49 | putchar('\t'); | 52 | putchar('\t'); |
50 | break; | 53 | break; |
51 | case 3: if (!both) | 54 | case 3: |
55 | if (!both) | ||
52 | return; | 56 | return; |
53 | if (only_file_1) | 57 | if (only_file_1) |
54 | putchar('\t'); | 58 | putchar('\t'); |
@@ -56,50 +60,49 @@ static void writeline (char *line, int class) { | |||
56 | putchar('\t'); | 60 | putchar('\t'); |
57 | break; | 61 | break; |
58 | } | 62 | } |
59 | fputs(line, stdout); | 63 | fputs(line, stdout); |
60 | } | 64 | } |
61 | 65 | ||
62 | /* This is the real core of the program - lines are compared here */ | 66 | /* This is the real core of the program - lines are compared here */ |
63 | static int cmp_files(char **infiles) { | 67 | static int cmp_files(char **infiles) |
64 | 68 | { | |
65 | char thisline[2][100]; | 69 | char thisline[2][100]; |
66 | FILE *streams[2]; | 70 | FILE *streams[2]; |
67 | int i = 0; | 71 | int i = 0; |
68 | 72 | ||
69 | for (i = 0; i < 2; i++) { | 73 | for (i = 0; i < 2; i++) { |
70 | streams[i] = (strcmp(infiles[i], "=") == 0 ? stdin : fopen(infiles[i], "r")); | 74 | streams[i] = (strcmp(infiles[i], "=") == 0 ? stdin : fopen(infiles[i], "r")); |
71 | fgets(thisline[i], 100, streams[i]); | 75 | fgets(thisline[i], 100, streams[i]); |
72 | } | 76 | } |
73 | 77 | ||
74 | while (thisline[0] || thisline[1]) { | 78 | while (thisline[0] || thisline[1]) { |
75 | |||
76 | int order = 0; | 79 | int order = 0; |
77 | int tl0_len = strlen(thisline[0]); | 80 | int tl0_len = strlen(thisline[0]); |
78 | int tl1_len = strlen(thisline[1]); | 81 | int tl1_len = strlen(thisline[1]); |
82 | |||
79 | if (!thisline[0]) | 83 | if (!thisline[0]) |
80 | order = 1; | 84 | order = 1; |
81 | else if (!thisline[1]) | 85 | else if (!thisline[1]) |
82 | order = -1; | 86 | order = -1; |
83 | else { | 87 | else { |
84 | order = memcmp(thisline[0], thisline[1], tl0_len < tl1_len ? tl0_len : tl1_len); | 88 | order = memcmp(thisline[0], thisline[1], tl0_len < tl1_len ? tl0_len : tl1_len); |
85 | if (!order) | 89 | if (!order) |
86 | order = tl0_len < tl1_len ? -1 : tl0_len != tl1_len; | 90 | order = tl0_len < tl1_len ? -1 : tl0_len != tl1_len; |
87 | } | 91 | } |
88 | 92 | ||
89 | if ((order == 0) && (!feof(streams[0])) && (!feof(streams[1]))) | 93 | if ((order == 0) && (!feof(streams[0])) && (!feof(streams[1]))) |
90 | writeline(thisline[1], 3); | 94 | writeline(thisline[1], 3); |
91 | else if ((order > 0) && (!feof(streams[1]))) | 95 | else if ((order > 0) && (!feof(streams[1]))) |
92 | writeline(thisline[1], 2); | 96 | writeline(thisline[1], 2); |
93 | else if ((order < 0) && (!feof(streams[0]))) | 97 | else if ((order < 0) && (!feof(streams[0]))) |
94 | writeline(thisline[0], 1); | 98 | writeline(thisline[0], 1); |
95 | 99 | ||
96 | if (feof(streams[0]) && feof(streams[1])) { | 100 | if (feof(streams[0]) && feof(streams[1])) { |
97 | fclose(streams[0]); | 101 | fclose(streams[0]); |
98 | fclose(streams[1]); | 102 | fclose(streams[1]); |
99 | break; | 103 | break; |
100 | } | 104 | |
101 | else if (feof(streams[0])) { | 105 | } else if (feof(streams[0])) { |
102 | |||
103 | while (!feof(streams[1])) { | 106 | while (!feof(streams[1])) { |
104 | if (order < 0) | 107 | if (order < 0) |
105 | writeline(thisline[1], 2); | 108 | writeline(thisline[1], 2); |
@@ -108,9 +111,8 @@ static int cmp_files(char **infiles) { | |||
108 | fclose(streams[0]); | 111 | fclose(streams[0]); |
109 | fclose(streams[1]); | 112 | fclose(streams[1]); |
110 | break; | 113 | break; |
111 | } | ||
112 | else if (feof(streams[1])) { | ||
113 | 114 | ||
115 | } else if (feof(streams[1])) { | ||
114 | while (!feof(streams[0])) { | 116 | while (!feof(streams[0])) { |
115 | if (order > 0) | 117 | if (order > 0) |
116 | writeline(thisline[0], 1); | 118 | writeline(thisline[0], 1); |
@@ -119,8 +121,8 @@ static int cmp_files(char **infiles) { | |||
119 | fclose(streams[0]); | 121 | fclose(streams[0]); |
120 | fclose(streams[1]); | 122 | fclose(streams[1]); |
121 | break; | 123 | break; |
122 | } | 124 | |
123 | else { | 125 | } else { |
124 | if (order >= 0) | 126 | if (order >= 0) |
125 | fgets(thisline[1], 100, streams[1]); | 127 | fgets(thisline[1], 100, streams[1]); |
126 | if (order <= 0) | 128 | if (order <= 0) |
@@ -131,19 +133,18 @@ static int cmp_files(char **infiles) { | |||
131 | return 0; | 133 | return 0; |
132 | } | 134 | } |
133 | 135 | ||
134 | int comm_main (int argc, char **argv) { | 136 | int comm_main (int argc, char **argv) |
135 | 137 | { | |
136 | unsigned long opt; | 138 | unsigned long opt; |
137 | only_file_1 = 1; | 139 | only_file_1 = 1; |
138 | only_file_2 = 1; | 140 | only_file_2 = 1; |
139 | both = 1; | 141 | both = 1; |
140 | 142 | ||
141 | opt = bb_getopt_ulflags(argc, argv, "123"); | 143 | opt = bb_getopt_ulflags(argc, argv, "123"); |
142 | 144 | ||
143 | if ((opt & 0x80000000UL) || (optind == argc)) { | 145 | if ((opt & 0x80000000UL) || (optind == argc)) |
144 | bb_show_usage(); | 146 | bb_show_usage(); |
145 | } | 147 | |
146 | |||
147 | if (opt & COMM_OPT_1) | 148 | if (opt & COMM_OPT_1) |
148 | only_file_1 = 0; | 149 | only_file_1 = 0; |
149 | if (opt & COMM_OPT_2) | 150 | if (opt & COMM_OPT_2) |