2 * libsortnetwork - src/sn-svg.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>
28 #include "sn_network.h"
30 #define INNER_SPACING 15.0
31 #define OUTER_SPACING 40.0
37 static double x_offset = OUTER_SPACING;
38 static int next_vertex_number = 0;
40 static _Bool embedded = 0;
42 static void exit_usage (void) /* {{{ */
44 printf ("Usage: sn-svg [options] [file]\n"
46 "Valid options are:\n"
47 " -e Create output suitable for embedding into other XML files.\n"
50 } /* }}} void exit_usage */
52 static int read_options (int argc, char **argv) /* {{{ */
56 while ((option = getopt (argc, argv, "eh?")) != -1)
72 } /* }}} int read_options */
74 static int tex_show_stage (sn_stage_t *s) /* {{{ */
76 int lines[s->comparators_num];
77 int right[s->comparators_num];
81 printf (" <!-- stage %i -->\n", SN_STAGE_DEPTH (s));
83 for (i = 0; i < SN_STAGE_COMP_NUM (s); i++)
89 for (i = 0; i < SN_STAGE_COMP_NUM (s); i++)
92 sn_comparator_t *c = SN_STAGE_COMP_GET (s, i);
97 min_num = next_vertex_number;
100 max_num = next_vertex_number;
101 next_vertex_number++;
103 for (j = 0; j < lines_used; j++)
104 if (SN_COMP_LEFT (c) > right[j])
108 right[j] = SN_COMP_RIGHT (c);
114 double x1 = x_offset + (j * INNER_SPACING);
116 int y1 = Y_OFFSET + (SN_COMP_MIN (c) * Y_SPACING);
117 int y2 = Y_OFFSET + (SN_COMP_MAX (c) * Y_SPACING);
119 printf (" <svg:line x1=\"%g\" y1=\"%i\" x2=\"%g\" y2=\"%i\" "
120 "stroke=\"black\" stroke-width=\"1\" />\n"
121 " <svg:circle cx=\"%g\" cy=\"%i\" r=\"%g\" fill=\"black\" />\n"
122 " <svg:circle cx=\"%g\" cy=\"%i\" r=\"%g\" fill=\"black\" />\n",
129 x_offset = x_offset + ((lines_used - 1) * INNER_SPACING) + OUTER_SPACING;
134 } /* }}} int tex_show_stage */
136 int main (int argc, char **argv) /* {{{ */
142 read_options (argc, argv);
144 if ((argc - optind) == 0)
146 else if ((argc - optind) == 1)
147 fh = fopen (argv[optind], "r");
152 n = sn_network_read (fh);
156 printf ("n == NULL!\n");
161 printf ("<svg:svg version=\"1.1\">\n");
163 printf ("<?xml version=\"1.0\" standalone=\"no\"?>\n"
164 "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" "
165 "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
166 "<svg:svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n");
168 printf ("<!-- Output generated with sn-svg from %s -->\n", PACKAGE_STRING);
170 for (i = 0; i < SN_NETWORK_STAGE_NUM (n); i++)
171 tex_show_stage (SN_NETWORK_STAGE_GET (n, i));
173 printf (" <!-- horizontal lines -->\n");
174 for (i = 0; i < SN_NETWORK_INPUT_NUM (n); i++)
175 printf (" <svg:line x1=\"%g\" y1=\"%i\" x2=\"%g\" y2=\"%i\" "
176 "stroke=\"black\" stroke-width=\"1\" />\n",
177 0.0, Y_OFFSET + (i * Y_SPACING),
178 x_offset, Y_OFFSET + (i * Y_SPACING));
180 printf ("</svg:svg>\n");
185 /* vim: set shiftwidth=2 softtabstop=2 fdm=marker : */