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
21 #include <gsl/gsl_errno.h>
24 #include "command-line.h"
25 #include <language/command.h>
26 #include <libpspp/compiler.h>
27 #include <data/dictionary.h>
28 #include <libpspp/message.h>
29 #include <data/file-handle-def.h>
30 #include <data/file-name.h>
31 #include <language/line-buffer.h>
32 #include <language/lexer/lexer.h>
33 #include <output/output.h>
35 #include <math/random.h>
36 #include "read-line.h"
37 #include <data/settings.h>
38 #include <data/variable.h>
39 #include <libpspp/version.h>
41 #if HAVE_FPU_CONTROL_H
42 #include <fpu_control.h>
54 #define _(msgid) gettext (msgid)
58 static void i18n_init (void);
59 static void fpu_init (void);
60 static void handle_error (int code);
61 static int execute_command (void);
63 /* If a segfault happens, issue a message to that effect and halt */
64 void bug_handler(int sig);
66 /* Handle quit/term/int signals */
67 void interrupt_handler(int sig);
69 void terminate (bool success);
71 /* Program entry point. */
73 main (int argc, char **argv)
75 signal (SIGSEGV, bug_handler);
76 signal (SIGFPE, bug_handler);
77 signal (SIGINT, interrupt_handler);
79 set_program_name ("pspp");
82 gsl_set_error_handler_off ();
92 default_dict = dict_create ();
94 if (parse_command_line (argc, argv))
105 retval = execute_command ();
106 if (retval == CMD_EOF)
108 if (retval != CMD_SUCCESS)
109 handle_error (retval);
113 terminate (err_error_count == 0);
117 /* Parse and execute a command, returning its return code. */
119 execute_command (void)
123 /* Read the command's first token.
124 The first token is part of the first line of the command. */
125 getl_set_prompt_style (GETL_PROMPT_FIRST);
130 /* Parse the command.
131 Any lines read after the first token must be continuation
133 getl_set_prompt_style (GETL_PROMPT_LATER);
134 result = cmd_parse ();
136 /* Unset the /ALGORITHM subcommand if it was used */
137 unset_cmd_algorithm ();
139 /* Clear any auxiliary data from the dictionary. */
140 dict_clear_aux (default_dict);
145 /* Print an error message corresponding to the command return code
148 handle_error (int code)
150 if (code == CMD_CASCADING_FAILURE && !getl_is_interactive ())
152 msg (SW, _("This command not executed. Stopping here "
153 "to avoid cascading failures."));
154 getl_abort_noninteractive ();
161 case CMD_CASCADING_FAILURE:
162 msg (SW, _("This command not executed."));
165 case CMD_PART_SUCCESS_MAYBE:
166 msg (SW, _("Skipping the rest of this command. Part of "
167 "this command may have been executed."));
170 case CMD_PART_SUCCESS:
171 msg (SW, _("Skipping the rest of this command. This "
172 "command was fully executed up to this point."));
175 case CMD_TRAILING_GARBAGE:
176 msg (SW, _("Trailing garbage was encountered following "
177 "this command. The command was fully executed "
185 if (!getl_is_interactive ())
187 while (token != T_STOP && token != '.')
192 msg (SW, _("The rest of this command has been discarded."));
202 setlocale (LC_MESSAGES, "");
204 setlocale (LC_MONETARY, "");
205 bindtextdomain (PACKAGE, locale_dir);
206 textdomain (PACKAGE);
207 #endif /* ENABLE_NLS */
213 #if HAVE_FEHOLDEXCEPT
216 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
217 __setfpucw (_FPU_IEEE);
221 /* If a segfault happens, issue a message to that effect and halt */
228 request_bug_report_and_abort("Floating Point Exception");
231 request_bug_report_and_abort("Segmentation Violation");
234 request_bug_report_and_abort("");
240 interrupt_handler(int sig UNUSED)
246 /* Terminate PSPP. SUCCESS should be true to exit successfully,
247 false to exit as a failure. */
249 terminate (bool success)
251 static bool terminating = false;
259 cancel_transformations ();
260 dict_destroy (default_dict);
266 getl_uninitialize ();
268 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);