From: Florian Forster Date: Mon, 20 Dec 2010 08:41:04 +0000 (+0100) Subject: Merge remote branch 'origin/master' X-Git-Tag: v1.0.0~13 X-Git-Url: https://git.octo.it/?p=sort-networks.git;a=commitdiff_plain;h=9f77fbe43254d5920b3b1fac1ab0c01cc3a3adcc Merge remote branch 'origin/master' Conflicts: src/sn-svg.c --- 9f77fbe43254d5920b3b1fac1ab0c01cc3a3adcc diff --cc src/sn-svg.c index c69c59d,850c422..d3da59c --- a/src/sn-svg.c +++ b/src/sn-svg.c @@@ -23,7 -23,7 +23,8 @@@ #include #include +#include + #include #include "sn_network.h" @@@ -35,43 -35,8 +36,41 @@@ #define Y_SPACING 40 static double x_offset = OUTER_SPACING; - static int next_vertex_number = 0; - +static _Bool embedded = 0; + +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 int tex_show_stage (sn_stage_t *s) /* {{{ */ + static double determine_stage_width (sn_stage_t *s) { int lines[s->comparators_num]; int right[s->comparators_num]; @@@ -91,14 -57,54 +91,54 @@@ int j; sn_comparator_t *c = SN_STAGE_COMP_GET (s, i); - int min_num; - int max_num; + for (j = 0; j < lines_used; j++) + if (SN_COMP_LEFT (c) > right[j]) + break; + + lines[i] = j; + right[j] = SN_COMP_RIGHT (c); + if (j >= lines_used) + lines_used = j + 1; + } + assert (lines_used >= 1); + + return (((double) (lines_used - 1)) * INNER_SPACING); + } + + static double determine_network_width (sn_network_t *n) /* {{{ */ + { + double width; + int i; + + /* Spacing between stages and at the beginning and end of the network */ + width = (SN_NETWORK_STAGE_NUM (n) + 1) * OUTER_SPACING; - min_num = next_vertex_number; - next_vertex_number++; + /* Spacing required within a stage */ + for (i = 0; i < SN_NETWORK_STAGE_NUM (n); i++) + width += determine_stage_width (SN_NETWORK_STAGE_GET (n, i)); - max_num = next_vertex_number; - next_vertex_number++; + 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]; + int lines_used = 0; + int i; + + printf (" \n", SN_STAGE_DEPTH (s)); + + for (i = 0; i < SN_STAGE_COMP_NUM (s); i++) + { + lines[i] = -1; + right[i] = -1; + } + + for (i = 0; i < SN_STAGE_COMP_NUM (s); i++) + { + int j; + sn_comparator_t *c = SN_STAGE_COMP_GET (s, i); for (j = 0; j < lines_used; j++) if (SN_COMP_LEFT (c) > right[j]) @@@ -131,23 -137,28 +171,27 @@@ printf ("\n"); return (0); - } /* }}} int tex_show_stage */ -} /* 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; + + double svg_height; + double svg_width; + 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); @@@ -157,13 -168,15 +201,19 @@@ return (1); } + 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"); ++ printf ("\n", ++ svg_width, svg_height); + else + printf ("\n" + "\n" - "\n"); ++ "\n", ++ svg_width, svg_height, svg_width, svg_height); printf ("\n", PACKAGE_STRING);