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);
62 static void terminate (bool success) NO_RETURN;
64 /* If a segfault happens, issue a message to that effect and halt */
65 void bug_handler(int sig);
67 /* Handle quit/term/int signals */
68 void interrupt_handler(int sig);
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);
116 /* Parse and execute a command, returning its return code. */
118 execute_command (void)
122 /* Read the command's first token.
123 The first token is part of the first line of the command. */
124 getl_set_prompt_style (GETL_PROMPT_FIRST);
129 /* Parse the command.
130 Any lines read after the first token must be continuation
132 getl_set_prompt_style (GETL_PROMPT_LATER);
133 result = cmd_parse ();
135 /* Unset the /ALGORITHM subcommand if it was used */
136 unset_cmd_algorithm ();
138 /* Clear any auxiliary data from the dictionary. */
139 dict_clear_aux (default_dict);
144 /* Print an error message corresponding to the command return code
147 handle_error (int code)
149 if (code == CMD_CASCADING_FAILURE && !getl_is_interactive ())
151 msg (SW, _("This command not executed. Stopping here "
152 "to avoid cascading failures."));
153 getl_abort_noninteractive ();
160 case CMD_CASCADING_FAILURE:
161 msg (SW, _("This command not executed."));
164 case CMD_PART_SUCCESS_MAYBE:
165 msg (SW, _("Skipping the rest of this command. Part of "
166 "this command may have been executed."));
169 case CMD_PART_SUCCESS:
170 msg (SW, _("Skipping the rest of this command. This "
171 "command was fully executed up to this point."));
174 case CMD_TRAILING_GARBAGE:
175 msg (SW, _("Trailing garbage was encountered following "
176 "this command. The command was fully executed "
184 if (!getl_is_interactive ())
186 while (token != T_STOP && token != '.')
191 msg (SW, _("The rest of this command has been discarded."));
201 setlocale (LC_MESSAGES, "");
203 setlocale (LC_MONETARY, "");
204 bindtextdomain (PACKAGE, locale_dir);
205 textdomain (PACKAGE);
206 #endif /* ENABLE_NLS */
212 #if HAVE_FEHOLDEXCEPT
215 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
216 __setfpucw (_FPU_IEEE);
220 /* If a segfault happens, issue a message to that effect and halt */
227 request_bug_report_and_abort("Floating Point Exception");
230 request_bug_report_and_abort("Segmentation Violation");
233 request_bug_report_and_abort("");
239 interrupt_handler(int sig UNUSED)
245 /* Terminate PSPP. SUCCESS should be true to exit successfully,
246 false to exit as a failure. */
248 terminate (bool success)
250 static bool terminating = false;
258 cancel_transformations ();
259 dict_destroy (default_dict);
265 getl_uninitialize ();
266 readln_uninitialize ();
268 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);