diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-07 00:45:27 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-07 00:45:27 +0000 |
commit | bb5b01c7c711dd9ffc2abf23a05ccdfbf7fc0325 (patch) | |
tree | bc45e2297786ead1aec3836fad2ade137c01bf96 | |
parent | 04c99ebb4f59d784d8bceaad86cb6227c1babd17 (diff) | |
download | busybox-w32-bb5b01c7c711dd9ffc2abf23a05ccdfbf7fc0325.tar.gz busybox-w32-bb5b01c7c711dd9ffc2abf23a05ccdfbf7fc0325.tar.bz2 busybox-w32-bb5b01c7c711dd9ffc2abf23a05ccdfbf7fc0325.zip |
comm: eliminate statics
-rw-r--r-- | coreutils/comm.c | 74 |
1 files changed, 30 insertions, 44 deletions
diff --git a/coreutils/comm.c b/coreutils/comm.c index b6412968d..28e3982f2 100644 --- a/coreutils/comm.c +++ b/coreutils/comm.c | |||
@@ -9,41 +9,34 @@ | |||
9 | 9 | ||
10 | #include "busybox.h" | 10 | #include "busybox.h" |
11 | 11 | ||
12 | #define COMM_OPT_1 0x01 | 12 | #define COMM_OPT_1 (1 << 0) |
13 | #define COMM_OPT_2 0x02 | 13 | #define COMM_OPT_2 (1 << 1) |
14 | #define COMM_OPT_3 0x04 | 14 | #define COMM_OPT_3 (1 << 2) |
15 | |||
16 | /* These three variables control behaviour if non-zero */ | ||
17 | |||
18 | static int only_file_1; | ||
19 | static int only_file_2; | ||
20 | static int both; | ||
21 | 15 | ||
22 | /* writeline outputs the input given, appropriately aligned according to class */ | 16 | /* writeline outputs the input given, appropriately aligned according to class */ |
23 | static void writeline(char *line, int class) | 17 | static void writeline(char *line, int class, int flags) |
24 | { | 18 | { |
25 | if (class == 0) { | 19 | if (class == 0) { |
26 | if (!only_file_1) | 20 | if (flags & COMM_OPT_1) |
27 | return; | 21 | return; |
28 | } else if (class == 1) { | 22 | } else if (class == 1) { |
29 | if (!only_file_2) | 23 | if (flags & COMM_OPT_2) |
30 | return; | 24 | return; |
31 | if (only_file_1) | 25 | if (!(flags & COMM_OPT_1)) |
32 | putchar('\t'); | 26 | putchar('\t'); |
33 | } | 27 | } else /*if (class == 2)*/ { |
34 | else /*if (class == 2)*/ { | 28 | if (flags & COMM_OPT_3) |
35 | if (!both) | ||
36 | return; | 29 | return; |
37 | if (only_file_1) | 30 | if (!(flags & COMM_OPT_1)) |
38 | putchar('\t'); | 31 | putchar('\t'); |
39 | if (only_file_2) | 32 | if (!(flags & COMM_OPT_2)) |
40 | putchar('\t'); | 33 | putchar('\t'); |
41 | } | 34 | } |
42 | fputs(line, stdout); | 35 | fputs(line, stdout); |
43 | } | 36 | } |
44 | 37 | ||
45 | /* This is the real core of the program - lines are compared here */ | 38 | int comm_main(int argc, char **argv); |
46 | static void cmp_files(char **infiles) | 39 | int comm_main(int argc, char **argv) |
47 | { | 40 | { |
48 | #define LINE_LEN 100 | 41 | #define LINE_LEN 100 |
49 | #define BB_EOF_0 0x1 | 42 | #define BB_EOF_0 0x1 |
@@ -51,12 +44,19 @@ static void cmp_files(char **infiles) | |||
51 | char thisline[2][LINE_LEN]; | 44 | char thisline[2][LINE_LEN]; |
52 | FILE *streams[2]; | 45 | FILE *streams[2]; |
53 | int i; | 46 | int i; |
47 | unsigned flags; | ||
48 | |||
49 | opt_complementary = "=2"; | ||
50 | flags = getopt32(argc, argv, "123"); | ||
51 | argv += optind; | ||
54 | 52 | ||
55 | for (i = 0; i < 2; ++i) { | 53 | for (i = 0; i < 2; ++i) { |
56 | streams[i] = ((infiles[i][0] == '=' && infiles[i][1]) ? stdin : xfopen(infiles[i], "r")); | 54 | streams[i] = (argv[i][0] == '-' && !argv[i][1]) ? stdin : xfopen(argv[i], "r"); |
57 | fgets(thisline[i], LINE_LEN, streams[i]); | 55 | fgets(thisline[i], LINE_LEN, streams[i]); |
58 | } | 56 | } |
59 | 57 | ||
58 | /* This is the real core of the program - lines are compared here */ | ||
59 | |||
60 | while (*thisline[0] || *thisline[1]) { | 60 | while (*thisline[0] || *thisline[1]) { |
61 | int order = 0; | 61 | int order = 0; |
62 | 62 | ||
@@ -78,11 +78,11 @@ static void cmp_files(char **infiles) | |||
78 | } | 78 | } |
79 | 79 | ||
80 | if (order == 0 && !i) | 80 | if (order == 0 && !i) |
81 | writeline(thisline[1], 2); | 81 | writeline(thisline[1], 2, flags); |
82 | else if (order > 0 && !(i & BB_EOF_1)) | 82 | else if (order > 0 && !(i & BB_EOF_1)) |
83 | writeline(thisline[1], 1); | 83 | writeline(thisline[1], 1, flags); |
84 | else if (order < 0 && !(i & BB_EOF_0)) | 84 | else if (order < 0 && !(i & BB_EOF_0)) |
85 | writeline(thisline[0], 0); | 85 | writeline(thisline[0], 0, flags); |
86 | 86 | ||
87 | if (i & BB_EOF_0 & BB_EOF_1) { | 87 | if (i & BB_EOF_0 & BB_EOF_1) { |
88 | break; | 88 | break; |
@@ -91,7 +91,7 @@ static void cmp_files(char **infiles) | |||
91 | i = (i & BB_EOF_0 ? 1 : 0); | 91 | i = (i & BB_EOF_0 ? 1 : 0); |
92 | while (!feof(streams[i])) { | 92 | while (!feof(streams[i])) { |
93 | if ((order < 0 && i) || (order > 0 && !i)) | 93 | if ((order < 0 && i) || (order > 0 && !i)) |
94 | writeline(thisline[i], i); | 94 | writeline(thisline[i], i, flags); |
95 | fgets(thisline[i], LINE_LEN, streams[i]); | 95 | fgets(thisline[i], LINE_LEN, streams[i]); |
96 | } | 96 | } |
97 | break; | 97 | break; |
@@ -104,24 +104,10 @@ static void cmp_files(char **infiles) | |||
104 | } | 104 | } |
105 | } | 105 | } |
106 | 106 | ||
107 | fclose(streams[0]); | 107 | if (ENABLE_FEATURE_CLEAN_UP) { |
108 | fclose(streams[1]); | 108 | fclose(streams[0]); |
109 | } | 109 | fclose(streams[1]); |
110 | 110 | } | |
111 | int comm_main(int argc, char **argv); | ||
112 | int comm_main(int argc, char **argv) | ||
113 | { | ||
114 | unsigned long flags; | ||
115 | |||
116 | flags = getopt32(argc, argv, "123"); | ||
117 | |||
118 | if (optind + 2 != argc) | ||
119 | bb_show_usage(); | ||
120 | |||
121 | only_file_1 = !(flags & COMM_OPT_1); | ||
122 | only_file_2 = !(flags & COMM_OPT_2); | ||
123 | both = !(flags & COMM_OPT_3); | ||
124 | 111 | ||
125 | cmp_files(argv + optind); | 112 | return EXIT_SUCCESS; |
126 | exit(EXIT_SUCCESS); | ||
127 | } | 113 | } |