treewide: Replace <name>_cnt by n_<name>s and <name>_cap by allocated_<name>.
[pspp] / src / ui / gui / executor.c
index 8fb4c2603e37662c0753041b1221a131a0ee52cf..6d5af138e8dad4b16e57b858475e9844cd0b273c 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2007, 2009, 2010, 2011  Free Software Foundation
+   Copyright (C) 2007, 2009, 2010, 2011, 2012  Free Software Foundation
 
    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
@@ -26,7 +26,7 @@
 #include "libpspp/cast.h"
 #include "output/driver.h"
 #include "ui/gui/psppire-data-store.h"
-#include "ui/gui/psppire-output-window.h"
+#include "ui/gui/psppire.h"
 
 /* Lazy casereader callback function used by execute_syntax. */
 static struct casereader *
@@ -36,6 +36,20 @@ create_casereader_from_data_store (void *data_store_)
   return psppire_data_store_get_reader (data_store);
 }
 
+/* Ensures that dataset DS has a name, because some parts of the GUI insist
+   upon this. */
+static void
+name_dataset_cb (struct dataset *ds, void *aux UNUSED)
+{
+  if (dataset_name (ds)[0] == '\0')
+    {
+      struct session *session = dataset_session (ds);
+      char *dataset_name = session_generate_dataset_name (session);
+      dataset_set_name (ds, dataset_name);
+      free (dataset_name);
+    }
+}
+
 static void
 new_pdw_cb (struct dataset *ds, void *aux UNUSED)
 {
@@ -81,7 +95,7 @@ execute_syntax (PsppireDataWindow *window, struct lex_reader *lex_reader)
     {
       const struct caseproto *proto;
       struct casereader *reader;
-      casenumber case_cnt;
+      casenumber n_cases;
 
       /* When the user executes a number of snippets of syntax in a
          row, none of which read from the active dataset, the GUI becomes
@@ -97,8 +111,8 @@ execute_syntax (PsppireDataWindow *window, struct lex_reader *lex_reader)
          it is reused the next time syntax is run, without wrapping
          it in another layer. */
       proto = psppire_data_store_get_proto (pdw->data_store);
-      case_cnt = psppire_data_store_get_case_count (pdw->data_store);
-      reader = lazy_casereader_create (proto, case_cnt,
+      n_cases = psppire_data_store_get_case_count (pdw->data_store);
+      reader = lazy_casereader_create (proto, n_cases,
                                        create_casereader_from_data_store,
                                        pdw->data_store, &pdw->lazy_serial);
       dataset_set_source (pdw->dataset, reader);
@@ -120,17 +134,19 @@ execute_syntax (PsppireDataWindow *window, struct lex_reader *lex_reader)
       struct dataset *ds = session_active_dataset (the_session);
       enum cmd_result result = cmd_parse (lexer, ds);
 
-      if ( cmd_result_is_failure (result))
+      if (cmd_result_is_failure (result))
        {
          retval = FALSE;
-         if ( lex_get_error_mode (lexer) == LEX_ERROR_STOP )
+         if (lex_get_error_mode (lexer) == LEX_ERROR_STOP)
            break;
        }
 
-      if ( result == CMD_EOF || result == CMD_FINISH)
+      if (result == CMD_EOF || result == CMD_FINISH)
        break;
     }
 
+  session_for_each_dataset (the_session, name_dataset_cb, NULL);
+
   ll_for_each_safe (pdw, next_pdw, PsppireDataWindow, ll, &all_data_windows)
     {
       struct dataset *ds;
@@ -184,5 +200,5 @@ execute_syntax_string (PsppireDataWindow *window, gchar *syntax)
 void
 execute_const_syntax_string (PsppireDataWindow *window, const gchar *syntax)
 {
-  execute_syntax (window, lex_reader_for_string (syntax));
+  execute_syntax (window, lex_reader_for_string (syntax, "UTF-8"));
 }