1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007 Free Software Foundation
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.
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.
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/>. */
18 /* This file is a rubbish bin where stuff gets put when it doesn't seem to
23 #include <glib-object.h>
27 #include "message-dialog.h"
28 #include <data/data-in.h>
29 #include <data/data-out.h>
30 #include <data/dictionary.h>
31 #include <libpspp/message.h>
33 #include <libpspp/i18n.h>
37 #include <data/settings.h>
39 #include <language/command.h>
40 #include <data/procedure.h>
41 #include <language/lexer/lexer.h>
42 #include "psppire-data-store.h"
47 /* Formats a value according to FORMAT
48 The returned string must be freed when no longer required */
50 value_to_text (union value v, struct fmt_spec format)
54 s = g_new (gchar, format.w + 1);
55 data_out (&v, &format, s);
65 text_to_value (const gchar *text, union value *v,
66 struct fmt_spec format)
70 if ( format.type != FMT_A)
72 if ( ! text ) return FALSE;
75 const gchar *s = text;
83 if ( !*s) return FALSE;
88 ok = data_in (ss_cstr (text), format.type, 0, 0,
89 v, fmt_var_width (&format));
97 get_widget_assert (GladeXML *xml, const gchar *name)
103 w = glade_xml_get_widget (xml, name);
106 g_warning ("Widget \"%s\" could not be found\n", name);
111 /* Converts a string in the pspp locale to utf-8.
112 The return value must be freed when no longer required*/
114 pspp_locale_to_utf8 (const gchar *text, gssize len, GError **err)
116 return recode_string (CONV_PSPP_TO_UTF8, text, len);
119 #define _(msgid) gettext (msgid)
120 #define N_(msgid) msgid
126 static struct msg m = {
134 m.text=g_strdup (_("Sorry. The help system hasn't yet been implemented."));
140 connect_help (GladeXML *xml)
142 GList *helps = glade_xml_get_widget_prefix (xml, "help_button_");
145 for ( i = g_list_first (helps); i ; i = g_list_next (i))
146 g_signal_connect (GTK_WIDGET (i->data), "clicked", give_help, 0);
152 reference_manual (GtkMenuItem *menu, gpointer data)
155 if ( ! g_spawn_command_line_async ("yelp info:pspp", &err) )
157 msg (ME, _("Cannot open reference manual: %s"), err->message);
159 g_clear_error (&err);
163 extern struct dataset *the_dataset;
164 extern struct source_stream *the_source_stream;
165 extern PsppireDataStore *the_data_store;
168 execute_syntax (struct getl_interface *sss)
172 struct casereader *reader = psppire_data_store_get_reader (the_data_store);
174 proc_set_active_file_data (the_dataset, reader);
176 g_return_if_fail (proc_has_active_file (the_dataset));
178 lexer = lex_create (the_source_stream);
180 getl_append_source (the_source_stream, sss);
184 int result = cmd_parse (lexer, the_dataset);
186 if (result == CMD_EOF || result == CMD_FINISH)
190 getl_abort_noninteractive (the_source_stream);
194 psppire_dict_replace_dictionary (the_data_store->dict,
195 dataset_dict (the_dataset));
198 PsppireCaseFile *pcf = psppire_case_file_new (dataset_source (the_dataset));
200 psppire_data_store_set_case_file (the_data_store, pcf);
206 #ifdef G_ENABLE_DEBUG
207 # define g_marshal_value_peek_int(v) g_value_get_int (v)
209 # define g_marshal_value_peek_int(v) (v)->data[0].v_int
213 /* VOID:INT,INT,INT */
215 marshaller_VOID__INT_INT_INT (GClosure *closure,
216 GValue *return_value,
217 guint n_param_values,
218 const GValue *param_values,
219 gpointer invocation_hint,
220 gpointer marshal_data)
222 typedef void (*GMarshalFunc_VOID__INT_INT_INT) (gpointer data1,
227 register GMarshalFunc_VOID__INT_INT_INT callback;
228 register GCClosure *cc = (GCClosure*) closure;
229 register gpointer data1, data2;
231 g_return_if_fail (n_param_values == 4);
233 if (G_CCLOSURE_SWAP_DATA (closure))
235 data1 = closure->data;
236 data2 = g_value_peek_pointer (param_values + 0);
240 data1 = g_value_peek_pointer (param_values + 0);
241 data2 = closure->data;
243 callback = (GMarshalFunc_VOID__INT_INT_INT) (marshal_data ? marshal_data : cc->callback);
246 g_marshal_value_peek_int (param_values + 1),
247 g_marshal_value_peek_int (param_values + 2),
248 g_marshal_value_peek_int (param_values + 3),