Remove #include <assert.h> from files which don't need it
[pspp] / src / ui / gui / psppire.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2004, 2005, 2006, 2009, 2010, 2011, 2012, 2013, 2014, 2016  Free Software Foundation
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
20 #include <gsl/gsl_errno.h>
21 #include <gtk/gtk.h>
22 #include <libintl.h>
23 #include <unistd.h>
24
25 #include "data/any-reader.h"
26 #include "data/casereader.h"
27 #include "data/dataset.h"
28 #include "data/datasheet.h"
29 #include "data/file-handle-def.h"
30 #include "data/session.h"
31 #include "data/settings.h"
32
33 #include "language/lexer/lexer.h"
34 #include "libpspp/i18n.h"
35 #include "libpspp/message.h"
36 #include "libpspp/version.h"
37
38 #include "output/driver.h"
39 #include "output/journal.h"
40 #include "output/message-item.h"
41
42 #include "ui/gui/dict-display.h"
43 #include "ui/gui/executor.h"
44 #include "ui/gui/psppire-data-store.h"
45 #include "ui/gui/psppire-data-window.h"
46 #include "ui/gui/psppire-dict.h"
47 #include "ui/gui/psppire.h"
48 #include "ui/gui/psppire-output-window.h"
49 #include "ui/gui/psppire-syntax-window.h"
50 #include "ui/gui/psppire-selector.h"
51 #include "ui/gui/psppire-var-view.h"
52 #include "ui/gui/psppire-means-layer.h"
53 #include "ui/gui/psppire-window-register.h"
54 #include "ui/gui/widgets.h"
55 #include "ui/source-init-opts.h"
56 #include "ui/syntax-gen.h"
57
58
59 #include "gl/configmake.h"
60 #include "gl/xalloc.h"
61 #include "gl/relocatable.h"
62
63 void create_icon_factory (void);
64
65 #define _(msgid) gettext (msgid)
66 #define N_(msgid) msgid
67
68 void
69 register_selection_functions (void)
70 {
71   psppire_selector_set_default_selection_func (GTK_TYPE_ENTRY, insert_source_row_into_entry);
72   psppire_selector_set_default_selection_func (PSPPIRE_VAR_VIEW_TYPE, insert_source_row_into_tree_view);
73   psppire_selector_set_default_selection_func (GTK_TYPE_TREE_VIEW, insert_source_row_into_tree_view);
74   psppire_selector_set_default_selection_func (PSPPIRE_TYPE_MEANS_LAYER, insert_source_row_into_layers);
75 }
76
77 bool
78 initialize (const struct init_source *is)
79 {
80   switch (is->state)
81     {
82     case 0:
83       i18n_init ();
84       break;
85     case 1:
86       preregister_widgets ();
87       break;
88     case 2:
89       gsl_set_error_handler_off ();
90       break;
91     case 3:
92       output_engine_push ();
93       break;
94     case 4:
95       settings_init ();
96       break;
97     case 5:
98       fh_init ();
99       break;
100     case 6:
101       psppire_set_lexer (NULL);
102       break;
103     case 7:
104       bind_textdomain_codeset (PACKAGE, "UTF-8");
105       break;
106     case 8:
107       if ( ! gtk_parse_args (is->argc, is->argv) )
108         {
109           perror ("Error parsing arguments");
110           exit (1);
111         }
112       break;
113     case 9:
114       journal_init ();
115       break;
116     case 10:
117       textdomain (PACKAGE);
118       break;
119     default:
120       return TRUE;
121       break;
122     }
123   return FALSE;
124 }
125
126
127 void
128 de_initialize (void)
129 {
130   settings_done ();
131   output_engine_pop ();
132   i18n_done ();
133 }
134
135 void
136 psppire_quit (GApplication *app)
137 {
138   g_application_quit (app);
139 }
140
141 struct icon_size
142 {
143   int resolution;  /* The dimension of the images which will be used */
144   size_t n_sizes;  /* The number of items in the array below. */
145   const GtkIconSize *usage; /* An array determining for what the icon set is used */
146 };
147 \f
148 static void
149 handle_msg (const struct msg *m_, void *lexer_)
150 {
151   struct lexer *lexer = lexer_;
152   struct msg m = *m_;
153
154   if (lexer != NULL && m.file_name == NULL)
155     {
156       m.file_name = CONST_CAST (char *, lex_get_file_name (lexer));
157       m.first_line = lex_get_first_line_number (lexer, 0);
158       m.last_line = lex_get_last_line_number (lexer, 0);
159       m.first_column = lex_get_first_column (lexer, 0);
160       m.last_column = lex_get_last_column (lexer, 0);
161     }
162   m.command_name = CONST_CAST (char *, output_get_command_name ());
163
164   message_item_submit (message_item_create (&m));
165 }
166
167 void
168 psppire_set_lexer (struct lexer *lexer)
169 {
170   msg_set_handler (handle_msg, lexer);
171 }
172
173
174 GtkWindow *
175 psppire_preload_file (const gchar *file)
176 {
177   const gchar *local_encoding = "UTF-8";
178
179   struct file_handle *fh = fh_create_file (NULL,
180                                            file,
181                                            local_encoding,
182                                            fh_default_properties ());
183   const char *filename = fh_get_file_name (fh);
184
185   int retval = any_reader_detect (fh, NULL);
186
187   GtkWindow *w = NULL;
188   /* Check to see if the file is a .sav or a .por file.  If not
189      assume that it is a syntax file */
190   if (retval == 1)
191     w = open_data_window (NULL, filename, NULL, NULL);
192   else if (retval == 0)
193     {
194       create_data_window ();
195       w = open_syntax_window (filename, NULL);
196     }
197
198   fh_unref (fh);
199   return w;
200 }