lexer: Use lex_is_string() more consistently.
[pspp] / src / language / tests / format-guesser-test.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2008, 2010 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;
32   struct fmt_spec format;
33   char format_string[FMT_STRING_LEN_MAX + 1];
34
35   g = fmt_guesser_create ();
36   while (lex_is_string (lexer))
37     {
38       fprintf (stderr, "\"%s\" ", ds_cstr (lex_tokstr (lexer)));
39       fmt_guesser_add (g, ds_ss (lex_tokstr (lexer)));
40       lex_get (lexer);
41     }
42
43   fmt_guesser_guess (g, &format);
44   fmt_to_string (&format, format_string);
45   fprintf (stderr, "=> %s", format_string);
46   msg_disable ();
47   if (!fmt_check_input (&format))
48     {
49       fmt_fix_input (&format);
50       fmt_to_string (&format, format_string);
51       fprintf (stderr, " (%s)", format_string);
52     }
53   msg_enable ();
54   putc ('\n', stderr);
55
56   return lex_end_of_command (lexer);
57 }