work
[pspp] / src / language / tests / format-guesser-test.c
index 6285fc042c04a07cac583e68a38c814921ab4022..5b37aa7e6a4390ad972f24984475701a59113392 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2008, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2010, 2011 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
 #include <stdio.h>
 
-#include <data/format.h>
-#include <data/format-guesser.h>
-#include <language/command.h>
-#include <language/lexer/lexer.h>
-#include <libpspp/message.h>
+#include "data/format.h"
+#include "data/format-guesser.h"
+#include "language/command.h"
+#include "language/lexer/lexer.h"
+#include "libpspp/message.h"
 
 /* Executes the DEBUG FORMAT GUESSER command. */
 int
 cmd_debug_format_guesser (struct lexer *lexer, struct dataset *ds UNUSED)
 {
-  struct fmt_guesser *g;
-  struct fmt_spec format;
-  char format_string[FMT_STRING_LEN_MAX + 1];
-
-  g = fmt_guesser_create ();
+  struct fmt_guesser *g = fmt_guesser_create ();
   while (lex_is_string (lexer))
     {
-      fprintf (stderr, "\"%s\" ", ds_cstr (lex_tokstr (lexer)));
-      fmt_guesser_add (g, ds_ss (lex_tokstr (lexer)));
+      fprintf (stderr, "\"%s\" ", lex_tokcstr (lexer));
+      fmt_guesser_add (g, lex_tokss (lexer));
       lex_get (lexer);
     }
 
-  fmt_guesser_guess (g, &format);
-  fmt_to_string (&format, format_string);
+  struct fmt_spec format = fmt_guesser_guess (g);
+  char format_string[FMT_STRING_LEN_MAX + 1];
+  fmt_to_string (format, format_string);
   fprintf (stderr, "=> %s", format_string);
-  msg_disable ();
-  if (!fmt_check_input (&format))
+  if (!fmt_check_input (format))
     {
       fmt_fix_input (&format);
-      fmt_to_string (&format, format_string);
+      fmt_to_string (format, format_string);
       fprintf (stderr, " (%s)", format_string);
     }
-  msg_enable ();
   putc ('\n', stderr);
+  fmt_guesser_destroy (g);
 
-  return lex_end_of_command (lexer);
+  return CMD_SUCCESS;
 }