1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
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 <ui/debugger.h>
23 #include "command-line.h"
26 #include "read-line.h"
28 #include <data/dictionary.h>
29 #include <data/file-handle-def.h>
30 #include <libpspp/getl.h>
31 #include <data/file-name.h>
32 #include <data/format.h>
33 #include <data/procedure.h>
34 #include <data/settings.h>
35 #include <data/variable.h>
36 #include <gsl/gsl_errno.h>
37 #include <language/command.h>
38 #include <language/lexer/lexer.h>
39 #include <language/prompt.h>
40 #include <libpspp/compiler.h>
41 #include <libpspp/message.h>
42 #include <libpspp/version.h>
43 #include <math/random.h>
44 #include <output/output.h>
46 #if HAVE_FPU_CONTROL_H
47 #include <fpu_control.h>
63 #define _(msgid) gettext (msgid)
67 static void i18n_init (void);
68 static void fpu_init (void);
69 static void terminate (bool success) NO_RETURN;
71 /* If a segfault happens, issue a message to that effect and halt */
72 void bug_handler(int sig);
74 /* Handle quit/term/int signals */
75 void interrupt_handler(int sig);
76 static struct dataset * the_dataset = NULL;
78 static struct lexer *the_lexer;
79 static struct source_stream *the_source_stream ;
82 /* Program entry point. */
84 main (int argc, char **argv)
86 signal (SIGABRT, bug_handler);
87 signal (SIGSEGV, bug_handler);
88 signal (SIGFPE, bug_handler);
89 signal (SIGINT, interrupt_handler);
91 set_program_name (argv[0]);
95 gsl_set_error_handler_off ();
102 create_source_stream (
103 fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
106 readln_initialize ();
110 the_dataset = create_dataset (NULL, NULL);
112 if (parse_command_line (argc, argv, the_source_stream))
114 msg_ui_init (the_source_stream);
115 outp_read_devices ();
116 the_lexer = lex_create (the_source_stream);
120 int result = cmd_parse (the_lexer, the_dataset);
122 if (result == CMD_EOF || result == CMD_FINISH)
124 if (result == CMD_CASCADING_FAILURE &&
125 !getl_is_interactive (the_source_stream))
127 msg (SE, _("Stopping syntax file processing here to avoid "
128 "a cascade of dependent command failures."));
129 getl_abort_noninteractive (the_source_stream);
132 check_msg_count (the_source_stream);
136 terminate (!any_errors ());
144 setlocale (LC_MESSAGES, "");
146 setlocale (LC_MONETARY, "");
147 bindtextdomain (PACKAGE, locale_dir);
148 textdomain (PACKAGE);
149 #endif /* ENABLE_NLS */
155 #if HAVE_FEHOLDEXCEPT
158 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
159 __setfpucw (_FPU_IEEE);
165 /* If a segfault happens, issue a message to that effect and halt */
175 request_bug_report_and_abort("Assertion Failure/Abort");
177 request_bug_report_and_abort("Floating Point Exception");
179 request_bug_report_and_abort("Segmentation Violation");
181 request_bug_report_and_abort("Unknown");
186 interrupt_handler(int sig UNUSED)
192 /* Terminate PSPP. SUCCESS should be true to exit successfully,
193 false to exit as a failure. */
195 terminate (bool success)
197 static bool terminating = false;
202 destroy_dataset (the_dataset);
207 lex_destroy (the_lexer);
208 destroy_source_stream (the_source_stream);
210 readln_uninitialize ();
216 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);