1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "data/file-handle-def.h"
26 #include "libpspp/assertion.h"
27 #include "libpspp/compiler.h"
28 #include "libpspp/i18n.h"
29 #include "libpspp/string-map.h"
30 #include "output/ascii.h"
31 #include "output/driver.h"
32 #include "output/table.h"
33 #include "output/table-item.h"
36 #include "gl/progname.h"
37 #include "gl/xalloc.h"
38 #include "gl/xvasprintf.h"
40 /* --emphasis: ASCII driver emphasis option. */
42 static bool underline;
44 /* --box: ASCII driver box option. */
47 /* ASCII driver, for ASCII driver test mode. */
48 static struct output_driver *ascii_driver;
50 static const char *parse_options (int argc, char **argv);
51 static void usage (void) NO_RETURN;
52 static void draw (FILE *);
55 main (int argc, char **argv)
57 set_program_name (argv[0]);
59 output_engine_push ();
60 const char *input_file_name = parse_options (argc, argv);
62 FILE *input = (!strcmp (input_file_name, "-")
64 : fopen (input_file_name, "r"));
66 error (1, errno, "%s: open failed", input_file_name);
79 static struct output_driver *
80 configure_driver (int width, int min_break)
82 struct string_map options = STRING_MAP_INITIALIZER (options);
83 string_map_insert (&options, "format", "txt");
84 string_map_insert (&options, "output-file", "-");
85 string_map_insert_nocopy (&options, xstrdup ("width"),
86 xasprintf ("%d", width));
88 string_map_insert_nocopy (&options, xstrdup ("min-hbreak"),
89 xasprintf ("%d", min_break));
90 if (bold || underline)
91 string_map_insert (&options, "emphasis", "true");
93 string_map_insert (&options, "box", box);
95 struct output_driver *driver = output_driver_create (&options);
96 string_map_destroy (&options);
99 output_driver_register (driver);
104 parse_options (int argc, char **argv)
112 OPT_WIDTH = UCHAR_MAX + 1,
119 static const struct option options[] =
121 {"width", required_argument, NULL, OPT_WIDTH},
122 {"length", required_argument, NULL, OPT_LENGTH},
123 {"emphasis", required_argument, NULL, OPT_EMPHASIS},
124 {"box", required_argument, NULL, OPT_BOX},
125 {"help", no_argument, NULL, OPT_HELP},
129 int c = getopt_long (argc, argv, "o:", options, NULL);
136 width = atoi (optarg);
140 if (!strcmp (optarg, "bold"))
145 else if (!strcmp (optarg, "underline"))
150 else if (!strcmp (optarg, "none"))
152 bold = underline = false;
155 error (1, 0, "argument to --emphasis must be \"bold\" or "
156 "\"underline\" or \"none\"");
179 ascii_driver = configure_driver (width, min_break);
181 if (optind + 1 != argc)
182 error (1, 0, "exactly one non-option argument required; "
183 "use --help for help");
190 printf ("%s, to test PSPP ASCII driver drawing\n"
191 "usage: %s [OPTIONS] INPUT\n"
193 " --width=WIDTH set page width in characters\n"
194 " --length=LINE set page length in lines\n",
195 program_name, program_name);
205 while (fgets (buffer, sizeof buffer, stream))
207 char text[sizeof buffer];
213 if (strchr ("#\r\n", buffer[0]))
216 if (sscanf (buffer, "%d %d %d %[^\n]", &x, &y, &emph, text) == 4)
217 ascii_test_write (ascii_driver, text, x, y, emph ? bold : false,
218 emph ? underline : false);
219 else if (sscanf (buffer, "set-length %d %d", &y, &length) == 2)
220 ascii_test_set_length (ascii_driver, y, length);
222 error (1, 0, "line %d has invalid format", line);
224 ascii_test_flush (ascii_driver);