1 /* vi: set sw=4 ts=4: */
3 * Mini comm implementation for busybox
5 * Copyright (C) 2005 by Robert Sullivan <cogito.ergo.cogito@gmail.com>
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
12 #define COMM_OPT_1 (1 << 0)
13 #define COMM_OPT_2 (1 << 1)
14 #define COMM_OPT_3 (1 << 2)
16 /* writeline outputs the input given, appropriately aligned according to class */
17 static void writeline(char *line, int class)
19 int flags = option_mask32;
21 if (flags & COMM_OPT_1)
23 } else if (class == 1) {
24 if (flags & COMM_OPT_2)
26 if (!(flags & COMM_OPT_1))
28 } else /*if (class == 2)*/ {
29 if (flags & COMM_OPT_3)
31 if (!(flags & COMM_OPT_1))
33 if (!(flags & COMM_OPT_2))
39 int comm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
40 int comm_main(int argc UNUSED_PARAM, char **argv)
47 opt_complementary = "=2";
48 getopt32(argv, "123");
51 for (i = 0; i < 2; ++i) {
52 stream[i] = xfopen_stdin(argv[i]);
56 thisline[1] = thisline[0] = NULL;
60 thisline[0] = xmalloc_fgetline(stream[0]);
64 thisline[1] = xmalloc_fgetline(stream[1]);
67 i = !thisline[0] + (!thisline[1] << 1);
70 order = strcmp(thisline[0], thisline[1]);
73 writeline(thisline[1], order ? 1 : 2);
75 writeline(thisline[0], 0);
78 /* EOF at least on one of the streams */
81 /* stream[i] is not at EOF yet */
82 /* we did not print thisline[i] yet */
83 char *p = thisline[i];
87 p = xmalloc_fgetline(stream[i]);
94 if (ENABLE_FEATURE_CLEAN_UP) {