lexer: Reimplement for better testability and internationalization.
[pspp-builds.git] / src / language / tests / paper-size.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #include <config.h>
18
19 #include <stdio.h>
20
21 #include "language/command.h"
22 #include "language/lexer/lexer.h"
23 #include "libpspp/assertion.h"
24 #include "libpspp/string-map.h"
25 #include "output/measure.h"
26
27 /* Executes the DEBUG PAPER SIZE command. */
28 int
29 cmd_debug_paper_size (struct lexer *lexer, struct dataset *ds UNUSED)
30 {
31   const char *paper_size;
32   int h, v;
33
34   if (!lex_force_string (lexer))
35     return CMD_FAILURE;
36   paper_size = lex_tokcstr (lexer);
37
38   printf ("\"%s\" => ", paper_size);
39   if (measure_paper (paper_size, &h, &v))
40     printf ("%.1f x %.1f in, %.0f x %.0f mm\n",
41             h / 72000., v / 72000.,
42             h / (72000 / 25.4), v / (72000 / 25.4));
43   else
44     printf ("error\n");
45   lex_get (lexer);
46
47   return CMD_SUCCESS;
48 }