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 "command-line.h"
28 #include "read-line.h"
30 #include <data/dictionary.h>
31 #include <data/file-handle-def.h>
32 #include <data/file-name.h>
33 #include <data/format.h>
34 #include <data/procedure.h>
35 #include <data/settings.h>
36 #include <data/variable.h>
37 #include <gsl/gsl_errno.h>
38 #include <language/command.h>
39 #include <language/lexer/lexer.h>
40 #include <language/line-buffer.h>
41 #include <libpspp/compiler.h>
42 #include <libpspp/message.h>
43 #include <libpspp/version.h>
44 #include <math/random.h>
45 #include <output/output.h>
47 #if HAVE_FPU_CONTROL_H
48 #include <fpu_control.h>
60 #define _(msgid) gettext (msgid)
64 static void i18n_init (void);
65 static void fpu_init (void);
66 static void terminate (bool success) NO_RETURN;
68 /* If a segfault happens, issue a message to that effect and halt */
69 void bug_handler(int sig);
71 /* Handle quit/term/int signals */
72 void interrupt_handler(int sig);
73 static struct dataset * the_dataset = NULL;
75 static struct lexer *the_lexer;
77 /* Program entry point. */
79 main (int argc, char **argv)
81 signal (SIGABRT, bug_handler);
82 signal (SIGSEGV, bug_handler);
83 signal (SIGFPE, bug_handler);
84 signal (SIGINT, interrupt_handler);
86 set_program_name ("pspp");
89 gsl_set_error_handler_off ();
99 the_dataset = create_dataset ();
101 if (parse_command_line (argc, argv))
104 outp_read_devices ();
105 the_lexer = lex_create (do_read_line);
109 int result = cmd_parse (the_lexer, the_dataset,
110 proc_has_source (the_dataset)
111 ? CMD_STATE_DATA : CMD_STATE_INITIAL);
112 if (result == CMD_EOF || result == CMD_FINISH)
114 if (result == CMD_CASCADING_FAILURE && !getl_is_interactive ())
116 msg (SE, _("Stopping syntax file processing here to avoid "
117 "a cascade of dependent command failures."));
118 getl_abort_noninteractive ();
125 terminate (!any_errors ());
133 setlocale (LC_MESSAGES, "");
135 setlocale (LC_MONETARY, "");
136 bindtextdomain (PACKAGE, locale_dir);
137 textdomain (PACKAGE);
138 #endif /* ENABLE_NLS */
144 #if HAVE_FEHOLDEXCEPT
147 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
148 __setfpucw (_FPU_IEEE);
152 /* If a segfault happens, issue a message to that effect and halt */
159 request_bug_report_and_abort("Assertion Failure/Abort");
161 request_bug_report_and_abort("Floating Point Exception");
163 request_bug_report_and_abort("Segmentation Violation");
165 request_bug_report_and_abort("Unknown");
170 interrupt_handler(int sig UNUSED)
176 /* Terminate PSPP. SUCCESS should be true to exit successfully,
177 false to exit as a failure. */
179 terminate (bool success)
181 static bool terminating = false;
186 destroy_dataset (the_dataset);
191 lex_destroy (the_lexer);
192 getl_uninitialize ();
193 readln_uninitialize ();
199 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);