1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2004, 2005, 2006 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/>. */
22 #include <gsl/gsl_errno.h>
26 #include <ui/command-line.h>
27 #include "relocatable.h"
29 #include "data-editor.h"
32 #include <libpspp/getl.h>
34 #include <data/casereader.h>
35 #include <data/datasheet.h>
36 #include <data/file-handle-def.h>
37 #include <data/settings.h>
38 #include <data/file-name.h>
39 #include <data/procedure.h>
40 #include <libpspp/getl.h>
41 #include <language/lexer/lexer.h>
42 #include <libpspp/version.h>
43 #include <output/output.h>
44 #include <output/journal.h>
45 #include <language/syntax-string-source.h>
48 #include <glade/glade.h>
49 #include "psppire-dict.h"
50 #include "psppire-var-store.h"
51 #include "psppire-data-store.h"
53 #include "message-dialog.h"
54 #include <ui/syntax-gen.h>
56 #include "output-viewer.h"
58 #include <data/sys-file-reader.h>
59 #include <data/por-file-reader.h>
61 #include <ui/source-init-opts.h>
63 PsppireDataStore *the_data_store = 0;
64 PsppireVarStore *the_var_store = 0;
66 static void create_icon_factory (void);
68 struct source_stream *the_source_stream ;
69 struct dataset * the_dataset = NULL;
73 replace_casereader (struct casereader *s)
75 PsppireCaseFile *pcf = psppire_case_file_new (s);
77 psppire_data_store_set_case_file (the_data_store, pcf);
80 #define _(msgid) gettext (msgid)
81 #define N_(msgid) msgid
84 initialize (struct command_line_processor *clp, int argc, char **argv)
86 PsppireDict *dictionary = 0;
88 /* gtk_init messes with the locale.
89 So unset the bits we want to control ourselves */
90 setlocale (LC_NUMERIC, "C");
92 bindtextdomain (PACKAGE, locale_dir);
97 gsl_set_error_handler_off ();
100 settings_init (&viewer_width, &viewer_length);
103 create_source_stream (
104 fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
107 the_dataset = create_dataset ();
110 message_dialog_init (the_source_stream);
112 dictionary = psppire_dict_new_from_dict (dataset_dict (the_dataset));
114 bind_textdomain_codeset (PACKAGE, "UTF-8");
116 /* Create the model for the var_sheet */
117 the_var_store = psppire_var_store_new (dictionary);
119 the_data_store = psppire_data_store_new (dictionary);
120 replace_casereader (NULL);
124 create_icon_factory ();
126 outp_configure_driver_line (
127 ss_cstr ("gui:ascii:screen:squeeze=on headers=off top-margin=0 "
128 "bottom-margin=0 paginate=off length=auto width=auto "
130 "output-file=\"" OUTPUT_FILE_NAME "\" append=yes"));
132 unlink (OUTPUT_FILE_NAME);
135 textdomain (PACKAGE);
137 /* Ignore alarm clock signals */
138 signal (SIGALRM, SIG_IGN);
140 command_line_processor_replace_aux (clp, &post_init_argp, the_source_stream);
141 command_line_processor_replace_aux (clp, &non_option_argp, the_source_stream);
143 command_line_processor_parse (clp, argc, argv);
145 new_data_window (NULL, NULL);
147 execute_syntax (create_syntax_string_source (""));
154 destroy_source_stream (the_source_stream);
155 message_dialog_done ();
164 const char *file_name;
169 static const struct icon_info icons[] =
171 {PKGDATADIR "/value-labels.png", "pspp-value-labels"},
172 {PKGDATADIR "/weight-cases.png", "pspp-weight-cases"},
173 {PKGDATADIR "/goto-variable.png", "pspp-goto-variable"},
174 {PKGDATADIR "/insert-variable.png", "pspp-insert-variable"},
175 {PKGDATADIR "/insert-case.png", "pspp-insert-case"},
176 {PKGDATADIR "/split-file.png", "pspp-split-file"},
177 {PKGDATADIR "/select-cases.png", "pspp-select-cases"},
178 {PKGDATADIR "/recent-dialogs.png", "pspp-recent-dialogs"},
179 {PKGDATADIR "/nominal.png", "var-nominal"},
180 {PKGDATADIR "/ordinal.png", "var-ordinal"},
181 {PKGDATADIR "/scale.png", "var-scale"},
182 {PKGDATADIR "/string.png", "var-string"},
183 {PKGDATADIR "/date-scale.png", "var-date-scale"}
187 create_icon_factory (void)
190 GtkIconFactory *factory = gtk_icon_factory_new ();
192 for (i = 0 ; i < sizeof (icons) / sizeof(icons[0]); ++i)
196 gdk_pixbuf_new_from_file (relocate (icons[i].file_name), &err);
200 GtkIconSet *icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
201 g_object_unref (pixbuf);
202 gtk_icon_factory_add ( factory, icons[i].id, icon_set);
206 g_warning ("Cannot create icon: %s", err->message);
207 g_clear_error (&err);
212 /* Create our own "pspp-stock-reset" item, using the
213 GTK_STOCK_REFRESH icon set */
215 GtkStockItem items[] = {
216 {"pspp-stock-reset", N_("_Reset"), 0, 0, PACKAGE},
217 {"pspp-stock-select", N_("_Select"), 0, 0, PACKAGE}
221 gtk_stock_add (items, 2);
222 gtk_icon_factory_add (factory, "pspp-stock-reset",
223 gtk_icon_factory_lookup_default (GTK_STOCK_REFRESH)
226 gtk_icon_factory_add (factory, "pspp-stock-select",
227 gtk_icon_factory_lookup_default (GTK_STOCK_INDEX)
231 gtk_icon_factory_add_default (factory);
237 parse_non_options (int key, char *arg, struct argp_state *state)
239 struct source_stream *ss = state->input;
248 struct string syntax;
249 FILE *fp = fopen (arg, "r");
252 const int errnum = errno;
253 fprintf (state->err_stream, _("Cannot open %s: %s.\n"),
254 arg, strerror (errnum));
257 if ( sfm_detect (fp))
259 ds_init_cstr (&syntax, "GET FILE=");
265 ds_init_cstr (&syntax, "IMPORT FILE=");
270 msg (ME, _("%s is neither a system nor portable file"), arg);
276 syntax_gen_string (&syntax, ss_cstr (arg));
277 ds_put_cstr (&syntax, ".");
279 getl_append_source (ss,
280 create_syntax_string_source (ds_cstr (&syntax)),
284 ds_destroy (&syntax);
288 return ARGP_ERR_UNKNOWN;
294 const struct argp non_option_argp = {NULL, parse_non_options, 0, 0, 0, 0, 0};