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"
32 #include <data/dictionary.h>
33 #include <data/file-handle-def.h>
34 #include <libpspp/getl.h>
35 #include <data/file-name.h>
36 #include <data/format.h>
37 #include <data/procedure.h>
38 #include <data/settings.h>
39 #include <data/variable.h>
40 #include <gsl/gsl_errno.h>
41 #include <language/command.h>
42 #include <language/lexer/lexer.h>
43 #include <language/prompt.h>
44 #include <libpspp/compiler.h>
45 #include <libpspp/message.h>
46 #include <libpspp/version.h>
47 #include <math/random.h>
48 #include <output/output.h>
50 #if HAVE_FPU_CONTROL_H
51 #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 ("pspp");
94 gsl_set_error_handler_off ();
101 create_source_stream (
102 fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
105 readln_initialize ();
108 the_dataset = create_dataset ();
110 if (parse_command_line (argc, argv, the_source_stream))
112 msg_ui_init (the_source_stream);
113 outp_read_devices ();
114 the_lexer = lex_create (the_source_stream);
118 int result = cmd_parse (the_lexer, the_dataset,
119 proc_has_source (the_dataset)
120 ? CMD_STATE_DATA : CMD_STATE_INITIAL);
121 if (result == CMD_EOF || result == CMD_FINISH)
123 if (result == CMD_CASCADING_FAILURE &&
124 !getl_is_interactive (the_source_stream))
126 msg (SE, _("Stopping syntax file processing here to avoid "
127 "a cascade of dependent command failures."));
128 getl_abort_noninteractive (the_source_stream);
131 check_msg_count (the_source_stream);
135 terminate (!any_errors ());
143 setlocale (LC_MESSAGES, "");
145 setlocale (LC_MONETARY, "");
146 bindtextdomain (PACKAGE, locale_dir);
147 textdomain (PACKAGE);
148 #endif /* ENABLE_NLS */
154 #if HAVE_FEHOLDEXCEPT
157 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
158 __setfpucw (_FPU_IEEE);
162 /* If a segfault happens, issue a message to that effect and halt */
172 request_bug_report_and_abort("Assertion Failure/Abort");
174 request_bug_report_and_abort("Floating Point Exception");
176 request_bug_report_and_abort("Segmentation Violation");
178 request_bug_report_and_abort("Unknown");
183 interrupt_handler(int sig UNUSED)
189 /* Terminate PSPP. SUCCESS should be true to exit successfully,
190 false to exit as a failure. */
192 terminate (bool success)
194 static bool terminating = false;
199 destroy_dataset (the_dataset);
204 lex_destroy (the_lexer);
205 destroy_source_stream (the_source_stream);
207 readln_uninitialize ();
213 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);