1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 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, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include <ui/debugger.h>
25 #include "command-line.h"
28 #include "read-line.h"
30 #include <data/fastfile-factory.h>
31 #include <data/dictionary.h>
32 #include <data/file-handle-def.h>
33 #include <libpspp/getl.h>
34 #include <data/file-name.h>
35 #include <data/format.h>
36 #include <data/procedure.h>
37 #include <data/settings.h>
38 #include <data/variable.h>
39 #include <gsl/gsl_errno.h>
40 #include <language/command.h>
41 #include <language/lexer/lexer.h>
42 #include <language/prompt.h>
43 #include <libpspp/compiler.h>
44 #include <libpspp/message.h>
45 #include <libpspp/version.h>
46 #include <math/random.h>
47 #include <output/output.h>
49 #if HAVE_FPU_CONTROL_H
50 #include <fpu_control.h>
66 #define _(msgid) gettext (msgid)
70 static void i18n_init (void);
71 static void fpu_init (void);
72 static void terminate (bool success) NO_RETURN;
74 /* If a segfault happens, issue a message to that effect and halt */
75 void bug_handler(int sig);
77 /* Handle quit/term/int signals */
78 void interrupt_handler(int sig);
79 static struct dataset * the_dataset = NULL;
81 static struct lexer *the_lexer;
82 static struct source_stream *the_source_stream ;
85 /* Program entry point. */
87 main (int argc, char **argv)
89 struct casefile_factory *factory;
90 signal (SIGABRT, bug_handler);
91 signal (SIGSEGV, bug_handler);
92 signal (SIGFPE, bug_handler);
93 signal (SIGINT, interrupt_handler);
95 set_program_name ("pspp");
98 gsl_set_error_handler_off ();
105 create_source_stream (
106 fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
109 readln_initialize ();
113 factory = fastfile_factory_create ();
115 the_dataset = create_dataset (factory, NULL, NULL);
117 if (parse_command_line (argc, argv, the_source_stream))
119 msg_ui_init (the_source_stream);
120 outp_read_devices ();
121 the_lexer = lex_create (the_source_stream);
125 int result = cmd_parse (the_lexer, the_dataset);
127 if (result == CMD_EOF || result == CMD_FINISH)
129 if (result == CMD_CASCADING_FAILURE &&
130 !getl_is_interactive (the_source_stream))
132 msg (SE, _("Stopping syntax file processing here to avoid "
133 "a cascade of dependent command failures."));
134 getl_abort_noninteractive (the_source_stream);
137 check_msg_count (the_source_stream);
141 terminate (!any_errors ());
149 setlocale (LC_MESSAGES, "");
151 setlocale (LC_MONETARY, "");
152 bindtextdomain (PACKAGE, locale_dir);
153 textdomain (PACKAGE);
154 #endif /* ENABLE_NLS */
160 #if HAVE_FEHOLDEXCEPT
163 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
164 __setfpucw (_FPU_IEEE);
170 /* If a segfault happens, issue a message to that effect and halt */
180 request_bug_report_and_abort("Assertion Failure/Abort");
182 request_bug_report_and_abort("Floating Point Exception");
184 request_bug_report_and_abort("Segmentation Violation");
186 request_bug_report_and_abort("Unknown");
191 interrupt_handler(int sig UNUSED)
197 /* Terminate PSPP. SUCCESS should be true to exit successfully,
198 false to exit as a failure. */
200 terminate (bool success)
202 static bool terminating = false;
207 destroy_dataset (the_dataset);
212 lex_destroy (the_lexer);
213 destroy_source_stream (the_source_stream);
215 readln_uninitialize ();
221 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);