+static int flip = 0;
+
+#define INPUT_TO_Y(i) (((double) (i)) * vertical_spacing)
+
+static void exit_usage (void) /* {{{ */
+{
+ printf ("Usage: sn-tex [options] [file]\n"
+ "\n"
+ "Valid options are:\n"
+ " -w <width> Specify the width of the graph (in TikZ default units).\n"
+ " -f Flip the sorting network (min wire at the top, max wire at the bottom).\n"
+ "\n");
+ exit (EXIT_FAILURE);
+} /* }}} void exit_usage */
+
+static int read_options (int argc, char **argv) /* {{{ */
+{
+ int option;
+
+ while ((option = getopt (argc, argv, "w:fh?")) != -1)
+ {
+ switch (option)
+ {
+ case 'w':
+ {
+ double width = atof (optarg);
+ if (width <= 0.0)
+ {
+ fprintf (stderr, "Invalid width argument: %s\n", optarg);
+ exit (EXIT_FAILURE);
+ }
+ output_width = width;
+ break;
+ }
+
+ case 'f':
+ flip = 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];
+ int lines_used = 0;
+ int i;
+
+ if (SN_STAGE_COMP_NUM (s) == 0)
+ return (0.0);
+
+ 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);