lexer: Reimplement for better testability and internationalization.
[pspp-builds.git] / src / ui / gui / psppire.c
index 089208148defdebb240659e85a85dfa12605ed9e..0d41932adc0e6cd51036420908ba439418e33250 100644 (file)
@@ -16,8 +16,6 @@
 
 #include <config.h>
 
-#include "ui/gui/psppire.h"
-
 #include <assert.h>
 #include <gsl/gsl_errno.h>
 #include <gtk/gtk.h>
 #include "data/procedure.h"
 #include "data/settings.h"
 #include "data/sys-file-reader.h"
+
 #include "language/lexer/lexer.h"
-#include "language/syntax-string-source.h"
-#include "libpspp/getl.h"
 #include "libpspp/i18n.h"
 #include "libpspp/message.h"
 #include "libpspp/version.h"
+
 #include "output/driver.h"
 #include "output/journal.h"
 #include "output/message-item.h"
+
 #include "ui/gui/dict-display.h"
 #include "ui/gui/executor.h"
 #include "ui/gui/psppire-data-store.h"
@@ -66,12 +65,10 @@ PsppireVarStore *the_var_store = 0;
 
 static void create_icon_factory (void);
 
-struct source_stream *the_source_stream ;
 struct dataset * the_dataset = NULL;
 
 static GtkWidget *the_data_window;
 
-static void handle_msg (const struct msg *);
 static void load_data_file (const char *);
 
 static void
@@ -87,7 +84,7 @@ replace_casereader (struct casereader *s)
 
 
 void
-initialize (struct source_stream *ss, const char *data_file)
+initialize (const char *data_file)
 {
   PsppireDict *dictionary = 0;
 
@@ -100,9 +97,7 @@ initialize (struct source_stream *ss, const char *data_file)
   fh_init ();
 
   the_dataset = create_dataset ();
-
-  the_source_stream = ss;
-  msg_init (ss, handle_msg);
+  psppire_set_lexer (NULL);
 
   dictionary = psppire_dict_new_from_dict (dataset_dict (the_dataset));
 
@@ -132,7 +127,7 @@ initialize (struct source_stream *ss, const char *data_file)
   if (data_file != NULL)
     load_data_file (data_file);
 
-  execute_syntax (create_syntax_string_source (""));
+  execute_const_syntax_string ("");
 
   gtk_widget_show (the_data_window);
 }
@@ -141,7 +136,6 @@ initialize (struct source_stream *ss, const char *data_file)
 void
 de_initialize (void)
 {
-  destroy_source_stream (the_source_stream);
   settings_done ();
   output_close ();
   i18n_done ();
@@ -268,7 +262,7 @@ load_data_file (const char *arg)
       utf8 = g_locale_to_utf8 (arg, -1, NULL, &written, &err);
       if ( NULL == utf8)
         {
-          g_warning ("Cannot convert filename from local encoding \"%s\" to UTF-8: %s",
+          g_warning ("Cannot convert filename from local encoding `%s' to UTF-8: %s",
                      local_encoding,
                      err->message);
           g_clear_error (&err);
@@ -298,7 +292,25 @@ load_data_file (const char *arg)
 }
 
 static void
-handle_msg (const struct msg *m)
+handle_msg (const struct msg *m_, void *lexer_)
+{
+  struct lexer *lexer = lexer_;
+  struct msg m = *m_;
+
+  if (lexer != NULL && m.file_name == NULL)
+    {
+      m.file_name = CONST_CAST (char *, lex_get_file_name (lexer));
+      m.first_line = lex_get_first_line_number (lexer, 0);
+      m.last_line = lex_get_last_line_number (lexer, 0);
+      m.first_column = lex_get_first_column (lexer, 0);
+      m.last_column = lex_get_last_column (lexer, 0);
+    }
+
+  message_item_submit (message_item_create (&m));
+}
+
+void
+psppire_set_lexer (struct lexer *lexer)
 {
-  message_item_submit (message_item_create (m));
+  msg_set_handler (handle_msg, lexer);
 }