2 * libsortnetwork - src/sn-tex.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>
22 #ifndef _ISOC99_SOURCE
23 # define _ISOC99_SOURCE
25 #ifndef _POSIX_C_SOURCE
26 # define _POSIX_C_SOURCE 200112L
33 #define INNER_SPACING 0.35
34 #define OUTER_SPACING 1.5
36 #include "sn_network.h"
38 static double x_offset = OUTER_SPACING;
39 static int next_vertex_number = 0;
41 static int tex_show_stage (sn_stage_t *s)
43 int lines[s->comparators_num];
44 int right[s->comparators_num];
48 for (i = 0; i < s->comparators_num; i++)
54 for (i = 0; i < s->comparators_num; i++)
57 sn_comparator_t *c = s->comparators + 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);
77 printf ("\\node[vertex] (v%i) at (%.2f,%i) {};\n"
78 "\\node[vertex] (v%i) at (%.2f,%i) {};\n"
79 "\\path[comp] (v%i) -- (v%i);\n"
81 min_num, x_offset + (j * INNER_SPACING), c->min,
82 max_num, x_offset + (j * INNER_SPACING), c->max,
86 x_offset = x_offset + ((lines_used - 1) * INNER_SPACING) + OUTER_SPACING;
89 } /* int tex_show_stage */
91 int main (int argc, char **argv)
100 fh = fopen (argv[1], "r");
104 printf ("fh == NULL!\n");
108 n = sn_network_read (fh);
112 printf ("n == NULL!\n");
116 printf ("\\begin{tikzpicture}[scale=%.2f,auto]\n", SCALE);
118 for (i = 0; i < SN_NETWORK_STAGE_NUM (n); i++)
119 tex_show_stage (SN_NETWORK_STAGE_GET (n, i));
121 for (i = 0; i < SN_NETWORK_INPUT_NUM (n); i++)
122 printf ("\\path[edge] (0,%i) -- (%.2f,%i);\n",
125 printf ("\\end{tikzpicture}\n");
130 /* vim: set shiftwidth=2 softtabstop=2 : */