cb68fcd345f1fb956d043243cc70b3cad9ff1be6
[sort-networks.git] / src / sn-cut.c
1 /**
2  * collectd - src/sn-cut.c
3  * Copyright (C) 2008  Florian octo Forster
4  *
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.
8  *
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.
13  *
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
17  *
18  * Authors:
19  *   Florian octo Forster <octo at verplant.org>
20  **/
21
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <strings.h>
25
26 #include "sn_network.h"
27
28 void exit_usage (const char *name)
29 {
30   printf ("%s <position> <min|max>\n", name);
31   exit (1);
32 }
33
34 int main (int argc, char **argv)
35 {
36   sn_network_t *n;
37
38   int pos = 0;
39   enum sn_network_cut_dir_e dir = DIR_MIN;
40
41   if (argc != 3)
42     exit_usage (argv[0]);
43
44   pos = atoi (argv[1]);
45   if (strcasecmp ("max", argv[2]) == 0)
46     dir = DIR_MAX;
47
48   n = sn_network_read (stdin);
49   if (n == NULL)
50   {
51     printf ("n == NULL!\n");
52     return (1);
53   }
54
55   sn_network_cut_at (n, pos, dir);
56   sn_network_compress (n);
57
58   sn_network_write (n, stdout);
59
60   return (0);
61 } /* int main */
62
63 /* vim: set shiftwidth=2 softtabstop=2 : */