X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsn-svg.c;h=47d7f9377d12894ff845f88e43db831169771a90;hb=81effefb7705a491ca062e54f31aa03093c28dbc;hp=850c422c297092916c45d83ddbbf817f472f3956;hpb=6416d2f513c62a1618dbca58165e85542a0785a2;p=sort-networks.git diff --git a/src/sn-svg.c b/src/sn-svg.c index 850c422..47d7f93 100644 --- a/src/sn-svg.c +++ b/src/sn-svg.c @@ -21,8 +21,16 @@ #include "config.h" +#ifndef _ISOC99_SOURCE +# define _ISOC99_SOURCE +#endif +#ifndef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L +#endif + #include #include +#include #include #include "sn_network.h" @@ -35,8 +43,41 @@ #define Y_SPACING 40 static double x_offset = OUTER_SPACING; +static _Bool embedded = 0; -static double determine_stage_width (sn_stage_t *s) +static void exit_usage (void) /* {{{ */ +{ + printf ("Usage: sn-svg [options] [file]\n" + "\n" + "Valid options are:\n" + " -e Create output suitable for embedding into other XML files.\n" + "\n"); + exit (EXIT_FAILURE); +} /* }}} void exit_usage */ + +static int read_options (int argc, char **argv) /* {{{ */ +{ + int option; + + while ((option = getopt (argc, argv, "eh?")) != -1) + { + switch (option) + { + case 'e': + embedded = 1; + break; + + case 'h': + case '?': + default: + exit_usage (); + } + } + + return (0); +} /* }}} int read_options */ + +static double determine_stage_width (sn_stage_t *s) /* {{{ */ { int lines[s->comparators_num]; int right[s->comparators_num]; @@ -69,7 +110,7 @@ static double determine_stage_width (sn_stage_t *s) assert (lines_used >= 1); return (((double) (lines_used - 1)) * INNER_SPACING); -} +} /* }}} double determine_stage_width */ static double determine_network_width (sn_network_t *n) /* {{{ */ { @@ -86,7 +127,7 @@ static double determine_network_width (sn_network_t *n) /* {{{ */ return (width); } /* }}} double determine_network_width */ -static int sn_svg_show_stage (sn_stage_t *s) +static int sn_svg_show_stage (sn_stage_t *s) /* {{{ */ { int lines[s->comparators_num]; int right[s->comparators_num]; @@ -122,10 +163,10 @@ static int sn_svg_show_stage (sn_stage_t *s) int y1 = Y_OFFSET + (SN_COMP_MIN (c) * Y_SPACING); int y2 = Y_OFFSET + (SN_COMP_MAX (c) * Y_SPACING); - printf (" \n" - " \n" - " \n", + " \n" + " \n", x1, y1, x2, y2, x1, y1, RADIUS, x2, y2, RADIUS); @@ -137,9 +178,9 @@ static int sn_svg_show_stage (sn_stage_t *s) printf ("\n"); return (0); -} /* int sn_svg_show_stage */ +} /* }}} int sn_svg_show_stage */ -int main (int argc, char **argv) +int main (int argc, char **argv) /* {{{ */ { sn_network_t *n; FILE *fh = NULL; @@ -149,16 +190,15 @@ int main (int argc, char **argv) int i; - if (argc == 1) + read_options (argc, argv); + + if ((argc - optind) == 0) fh = stdin; - else if (argc == 2) - fh = fopen (argv[1], "r"); + else if ((argc - optind) == 1) + fh = fopen (argv[optind], "r"); if (fh == NULL) - { - printf ("fh == NULL!\n"); - return (1); - } + exit_usage (); n = sn_network_read (fh); @@ -171,12 +211,16 @@ int main (int argc, char **argv) svg_height = (2 * Y_OFFSET) + ((SN_NETWORK_INPUT_NUM (n) - 1) * Y_SPACING); svg_width = determine_network_width (n); - printf ("\n" - "\n" - "\n", - svg_width, svg_height, svg_width, svg_height); + if (embedded) + printf ("\n", + svg_width, svg_height); + else + printf ("\n" + "\n" + "\n", + svg_width, svg_height, svg_width, svg_height); printf ("\n", PACKAGE_STRING); @@ -185,14 +229,14 @@ int main (int argc, char **argv) printf (" \n"); for (i = 0; i < SN_NETWORK_INPUT_NUM (n); i++) - printf (" \n", 0.0, Y_OFFSET + (i * Y_SPACING), x_offset, Y_OFFSET + (i * Y_SPACING)); - printf ("\n"); + printf ("\n"); return (0); -} /* int main */ +} /* }}} int main */ -/* vim: set shiftwidth=2 softtabstop=2 : */ +/* vim: set shiftwidth=2 softtabstop=2 fdm=marker : */