treewide: Use struct fmt_spec by value instead of pointer in most cases.
[pspp] / src / language / tests / format-guesser-test.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2008, 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 "data/format.h"
22 #include "data/format-guesser.h"
23 #include "language/command.h"
24 #include "language/lexer/lexer.h"
25 #include "libpspp/message.h"
26
27 /* Executes the DEBUG FORMAT GUESSER command. */
28 int
29 cmd_debug_format_guesser (struct lexer *lexer, struct dataset *ds UNUSED)
30 {
31   struct fmt_guesser *g = fmt_guesser_create ();
32   while (lex_is_string (lexer))
33     {
34       fprintf (stderr, "\"%s\" ", lex_tokcstr (lexer));
35       fmt_guesser_add (g, lex_tokss (lexer));
36       lex_get (lexer);
37     }
38
39   struct fmt_spec format = fmt_guesser_guess (g);
40   char format_string[FMT_STRING_LEN_MAX + 1];
41   fmt_to_string (format, format_string);
42   fprintf (stderr, "=> %s", format_string);
43   if (!fmt_check_input (format))
44     {
45       fmt_fix_input (&format);
46       fmt_to_string (format, format_string);
47       fprintf (stderr, " (%s)", format_string);
48     }
49   putc ('\n', stderr);
50   fmt_guesser_destroy (g);
51
52   return CMD_SUCCESS;
53 }