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>
27 #include "sn_network.h"
29 #define INNER_SPACING 15.0
30 #define OUTER_SPACING 40.0
36 static double x_offset = OUTER_SPACING;
37 static int next_vertex_number = 0;
39 static int tex_show_stage (sn_stage_t *s)
41 int lines[s->comparators_num];
42 int right[s->comparators_num];
46 printf (" <!-- stage %i -->\n", SN_STAGE_DEPTH (s));
48 for (i = 0; i < SN_STAGE_COMP_NUM (s); i++)
54 for (i = 0; i < SN_STAGE_COMP_NUM (s); i++)
57 sn_comparator_t *c = SN_STAGE_COMP_GET (s, i);
62 min_num = next_vertex_number;
65 max_num = next_vertex_number;
68 for (j = 0; j < lines_used; j++)
69 if (SN_COMP_LEFT (c) > right[j])
73 right[j] = SN_COMP_RIGHT (c);
79 double x1 = x_offset + (j * INNER_SPACING);
81 int y1 = Y_OFFSET + (SN_COMP_MIN (c) * Y_SPACING);
82 int y2 = Y_OFFSET + (SN_COMP_MAX (c) * Y_SPACING);
84 printf (" <line x1=\"%g\" y1=\"%i\" x2=\"%g\" y2=\"%i\" "
85 "stroke=\"black\" stroke-width=\"1\" />\n"
86 " <circle cx=\"%g\" cy=\"%i\" r=\"%g\" fill=\"black\" />\n"
87 " <circle cx=\"%g\" cy=\"%i\" r=\"%g\" fill=\"black\" />\n",
94 x_offset = x_offset + ((lines_used - 1) * INNER_SPACING) + OUTER_SPACING;
99 } /* int tex_show_stage */
101 int main (int argc, char **argv)
110 fh = fopen (argv[1], "r");
114 printf ("fh == NULL!\n");
118 n = sn_network_read (fh);
122 printf ("n == NULL!\n");
126 printf ("<?xml version=\"1.0\" standalone=\"no\"?>\n"
127 "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" "
128 "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
129 "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n");
131 printf ("<!-- Output generated with sn-svg from %s -->\n", PACKAGE_STRING);
133 for (i = 0; i < SN_NETWORK_STAGE_NUM (n); i++)
134 tex_show_stage (SN_NETWORK_STAGE_GET (n, i));
136 printf (" <!-- horizontal lines -->\n");
137 for (i = 0; i < SN_NETWORK_INPUT_NUM (n); i++)
138 printf (" <line x1=\"%g\" y1=\"%i\" x2=\"%g\" y2=\"%i\" "
139 "stroke=\"black\" stroke-width=\"1\" />\n",
140 0.0, Y_OFFSET + (i * Y_SPACING),
141 x_offset, Y_OFFSET + (i * Y_SPACING));
148 /* vim: set shiftwidth=2 softtabstop=2 : */