1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 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
22 #include "command-line.h"
25 #include "read-line.h"
27 #include <data/dictionary.h>
28 #include <data/file-handle-def.h>
29 #include <data/file-name.h>
30 #include <data/settings.h>
31 #include <data/variable.h>
32 #include <gsl/gsl_errno.h>
33 #include <language/command.h>
34 #include <language/lexer/lexer.h>
35 #include <language/line-buffer.h>
36 #include <libpspp/compiler.h>
37 #include <libpspp/message.h>
38 #include <libpspp/version.h>
39 #include <math/random.h>
40 #include <output/output.h>
45 #if HAVE_FPU_CONTROL_H
46 #include <fpu_control.h>
58 #define _(msgid) gettext (msgid)
62 static void i18n_init (void);
63 static void fpu_init (void);
64 static void handle_error (int code);
65 static int execute_command (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);
75 /* Program entry point. */
77 main (int argc, char **argv)
79 signal (SIGSEGV, bug_handler);
80 signal (SIGFPE, bug_handler);
81 signal (SIGINT, interrupt_handler);
83 set_program_name ("pspp");
86 gsl_set_error_handler_off ();
97 default_dict = dict_create ();
99 if (parse_command_line (argc, argv))
101 outp_read_devices ();
110 retval = execute_command ();
111 if (retval == CMD_EOF)
113 if (retval != CMD_SUCCESS)
114 handle_error (retval);
118 terminate (!any_errors ());
121 /* Parse and execute a command, returning its return code. */
123 execute_command (void)
127 /* Read the command's first token.
128 The first token is part of the first line of the command. */
129 getl_set_prompt_style (GETL_PROMPT_FIRST);
134 /* Parse the command.
135 Any lines read after the first token must be continuation
137 getl_set_prompt_style (GETL_PROMPT_LATER);
138 result = cmd_parse ();
140 /* Unset the /ALGORITHM subcommand if it was used */
141 unset_cmd_algorithm ();
143 /* Clear any auxiliary data from the dictionary. */
144 dict_clear_aux (default_dict);
149 /* Print an error message corresponding to the command return code
152 handle_error (int code)
154 if (code == CMD_CASCADING_FAILURE && !getl_is_interactive ())
156 msg (SW, _("This command not executed. Stopping here "
157 "to avoid cascading failures."));
158 getl_abort_noninteractive ();
165 case CMD_CASCADING_FAILURE:
166 msg (SW, _("This command not executed."));
169 case CMD_PART_SUCCESS_MAYBE:
170 msg (SW, _("Skipping the rest of this command. Part of "
171 "this command may have been executed."));
174 case CMD_PART_SUCCESS:
175 msg (SW, _("Skipping the rest of this command. This "
176 "command was fully executed up to this point."));
179 case CMD_TRAILING_GARBAGE:
180 msg (SW, _("Trailing garbage was encountered following "
181 "this command. The command was fully executed "
189 if (!getl_is_interactive ())
191 while (token != T_STOP && token != '.')
196 msg (SW, _("The rest of this command has been discarded."));
206 setlocale (LC_MESSAGES, "");
208 setlocale (LC_MONETARY, "");
209 bindtextdomain (PACKAGE, locale_dir);
210 textdomain (PACKAGE);
211 #endif /* ENABLE_NLS */
217 #if HAVE_FEHOLDEXCEPT
220 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
221 __setfpucw (_FPU_IEEE);
225 /* If a segfault happens, issue a message to that effect and halt */
232 request_bug_report_and_abort("Floating Point Exception");
235 request_bug_report_and_abort("Segmentation Violation");
238 request_bug_report_and_abort("");
244 interrupt_handler(int sig UNUSED)
250 /* Terminate PSPP. SUCCESS should be true to exit successfully,
251 false to exit as a failure. */
253 terminate (bool success)
255 static bool terminating = false;
260 cancel_transformations ();
261 dict_destroy (default_dict);
267 getl_uninitialize ();
268 readln_uninitialize ();
273 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);