Imported the initial C files that make up a decent sorting network toolkit already.
[sort-networks.git] / src / sn-cut.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <strings.h>
4
5 #include "sn_network.h"
6
7 void exit_usage (const char *name)
8 {
9   printf ("%s <position> <min|max>\n", name);
10   exit (1);
11 }
12
13 int main (int argc, char **argv)
14 {
15   sn_network_t *n;
16
17   int pos = 0;
18   enum sn_network_cut_dir_e dir = DIR_MIN;
19
20   if (argc != 3)
21     exit_usage (argv[0]);
22
23   pos = atoi (argv[1]);
24   if (strcasecmp ("max", argv[2]) == 0)
25     dir = DIR_MAX;
26
27   n = sn_network_read (stdin);
28   if (n == NULL)
29   {
30     printf ("n == NULL!\n");
31     return (1);
32   }
33
34   sn_network_cut_at (n, pos, dir);
35   sn_network_compress (n);
36
37   sn_network_write (n, stdout);
38
39   return (0);
40 } /* int main */
41
42 /* vim: set shiftwidth=2 softtabstop=2 : */