2 * libsortnetwork - src/sn-merge.c
3 * Copyright (C) 2008-2010 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <ff at octo.it>
29 #include "sn_network.h"
31 static _Bool use_bitonic = 0;
32 static const char *file0 = NULL;
33 static const char *file1 = NULL;
35 static void exit_usage (void) /* {{{ */
37 printf ("sn-merge [options] <file0> <file1>\n"
40 " -b Use the bitonic merger.\n"
41 " -o Use the odd-even merger. (default)\n"
42 " -h Display this help and exit.\n"
45 } /* }}} void exit_usage */
47 static int read_options (int argc, char **argv) /* {{{ */
51 while ((option = getopt (argc, argv, "boh")) != -1)
69 if ((argc - optind) != 2)
73 file1 = argv[optind + 1];
75 if ((file0 == NULL) || (file1 == NULL))
79 } /* }}} int read_options */
81 int main (int argc, char **argv)
87 read_options (argc, argv);
89 if (strcmp ("-", file0) == 0)
90 n0 = sn_network_read (stdin);
92 n0 = sn_network_read_file (file0);
95 fprintf (stderr, "Unable to read first network.\n");
99 if (strcmp ("-", file1) == 0)
101 if (strcmp ("-", file0) == 0)
102 n1 = sn_network_clone (n0);
104 n1 = sn_network_read (stdin);
107 n1 = sn_network_read_file (file1);
110 fprintf (stderr, "Unable to read second network.\n");
115 n = sn_network_combine_bitonic_merge (n0, n1);
117 n = sn_network_combine_odd_even_merge (n0, n1);
121 fprintf (stderr, "Combining the networks faild.\n");
125 sn_network_destroy (n0);
126 sn_network_destroy (n1);
128 sn_network_write (n, stdout);
133 /* vim: set shiftwidth=2 softtabstop=2 : */