1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include <ui/debugger.h>
26 #include "command-line.h"
29 #include "read-line.h"
31 #include <data/dictionary.h>
32 #include <data/file-handle-def.h>
33 #include <data/file-name.h>
34 #include <data/format.h>
35 #include <data/procedure.h>
36 #include <data/settings.h>
37 #include <data/variable.h>
38 #include <gsl/gsl_errno.h>
39 #include <language/command.h>
40 #include <language/lexer/lexer.h>
41 #include <language/line-buffer.h>
42 #include <libpspp/compiler.h>
43 #include <libpspp/message.h>
44 #include <libpspp/version.h>
45 #include <math/random.h>
46 #include <output/output.h>
48 #if HAVE_FPU_CONTROL_H
49 #include <fpu_control.h>
61 #define _(msgid) gettext (msgid)
65 static void i18n_init (void);
66 static void fpu_init (void);
67 static void terminate (bool success) NO_RETURN;
69 /* If a segfault happens, issue a message to that effect and halt */
70 void bug_handler(int sig);
72 /* Handle quit/term/int signals */
73 void interrupt_handler(int sig);
74 static struct dataset * the_dataset = NULL;
76 static struct lexer *the_lexer;
78 /* Program entry point. */
80 main (int argc, char **argv)
82 signal (SIGABRT, bug_handler);
83 signal (SIGSEGV, bug_handler);
84 signal (SIGFPE, bug_handler);
85 signal (SIGINT, interrupt_handler);
87 set_program_name ("pspp");
90 gsl_set_error_handler_off ();
100 the_dataset = create_dataset ();
102 if (parse_command_line (argc, argv))
105 outp_read_devices ();
106 the_lexer = lex_create (do_read_line);
110 int result = cmd_parse (the_lexer, the_dataset,
111 proc_has_source (the_dataset)
112 ? CMD_STATE_DATA : CMD_STATE_INITIAL);
113 if (result == CMD_EOF || result == CMD_FINISH)
115 if (result == CMD_CASCADING_FAILURE && !getl_is_interactive ())
117 msg (SE, _("Stopping syntax file processing here to avoid "
118 "a cascade of dependent command failures."));
119 getl_abort_noninteractive ();
126 terminate (!any_errors ());
134 setlocale (LC_MESSAGES, "");
136 setlocale (LC_MONETARY, "");
137 bindtextdomain (PACKAGE, locale_dir);
138 textdomain (PACKAGE);
139 #endif /* ENABLE_NLS */
145 #if HAVE_FEHOLDEXCEPT
148 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
149 __setfpucw (_FPU_IEEE);
153 /* If a segfault happens, issue a message to that effect and halt */
163 request_bug_report_and_abort("Assertion Failure/Abort");
165 request_bug_report_and_abort("Floating Point Exception");
167 request_bug_report_and_abort("Segmentation Violation");
169 request_bug_report_and_abort("Unknown");
174 interrupt_handler(int sig UNUSED)
180 /* Terminate PSPP. SUCCESS should be true to exit successfully,
181 false to exit as a failure. */
183 terminate (bool success)
185 static bool terminating = false;
190 destroy_dataset (the_dataset);
195 lex_destroy (the_lexer);
196 getl_uninitialize ();
197 readln_uninitialize ();
203 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);