2 * libsortnetwork - src/sn-cut.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>
24 #ifndef _ISOC99_SOURCE
25 # define _ISOC99_SOURCE
27 #ifndef _POSIX_C_SOURCE
28 # define _POSIX_C_SOURCE 200809L
31 # define _XOPEN_SOURCE 700
39 #include "sn_network.h"
41 static void exit_usage (const char *name)
43 printf ("Usage: %s <num>[:min|max] [<num>[:min|max] ...]\n", name);
47 static int do_cut (sn_network_t *n, int defs_num, char **defs)
49 int mask[SN_NETWORK_INPUT_NUM (n)];
53 memset (mask, 0, sizeof (mask));
54 for (i = 0; i < defs_num; i++)
60 pos = (int) strtol (defs[i], &endptr, /* base = */ 0);
61 if (strcasecmp (":min", endptr) == 0)
64 if ((pos < 0) || (pos >= SN_NETWORK_INPUT_NUM (n)))
66 fprintf (stderr, "Invalid line number: %i\n", pos);
73 status = sn_network_cut (n, mask);
76 fprintf (stderr, "sn_network_cut failed with status %i.\n", status);
81 } /* }}} int do_cut */
83 int main (int argc, char **argv)
90 n = sn_network_read (stdin);
93 fprintf (stderr, "Unable to read network from STDIN.\n");
97 do_cut (n, argc - 1, argv + 1);
98 sn_network_compress (n);
100 sn_network_write (n, stdout);
105 /* vim: set shiftwidth=2 softtabstop=2 : */