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"
26 #include "dictionary.h"
28 #include "file-handle-def.h"
30 #include "line-buffer.h"
35 #include "read-line.h"
40 #if HAVE_FPU_CONTROL_H
41 #include <fpu_control.h>
53 #define _(msgid) gettext (msgid)
57 #include "debug-print.h"
59 static void i18n_init (void);
60 static void fpu_init (void);
61 static void handle_error (int code);
62 static int execute_command (void);
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);
70 void terminate (bool success);
72 /* Program entry point. */
74 main (int argc, char **argv)
76 signal (SIGSEGV, bug_handler);
77 signal (SIGFPE, bug_handler);
78 signal (SIGINT, interrupt_handler);
80 set_program_name ("pspp");
83 gsl_set_error_handler_off ();
93 default_dict = dict_create ();
95 if (parse_command_line (argc, argv))
106 retval = execute_command ();
107 if (retval == CMD_EOF)
109 if (retval != CMD_SUCCESS)
110 handle_error (retval);
114 terminate (err_error_count == 0);
118 /* Parse and execute a command, returning its return code. */
120 execute_command (void)
124 /* Read the command's first token.
125 The first token is part of the first line of the command. */
126 getl_set_prompt_style (GETL_PROMPT_FIRST);
131 /* Parse the command.
132 Any lines read after the first token must be continuation
134 getl_set_prompt_style (GETL_PROMPT_LATER);
135 result = cmd_parse ();
137 /* Unset the /ALGORITHM subcommand if it was used */
138 unset_cmd_algorithm ();
140 /* Clear any auxiliary data from the dictionary. */
141 dict_clear_aux (default_dict);
146 /* Print an error message corresponding to the command return code
149 handle_error (int code)
151 if (code == CMD_CASCADING_FAILURE && !getl_is_interactive ())
153 msg (SW, _("This command not executed. Stopping here "
154 "to avoid cascading failures."));
155 getl_abort_noninteractive ();
162 case CMD_CASCADING_FAILURE:
163 msg (SW, _("This command not executed."));
166 case CMD_PART_SUCCESS_MAYBE:
167 msg (SW, _("Skipping the rest of this command. Part of "
168 "this command may have been executed."));
171 case CMD_PART_SUCCESS:
172 msg (SW, _("Skipping the rest of this command. This "
173 "command was fully executed up to this point."));
176 case CMD_TRAILING_GARBAGE:
177 msg (SW, _("Trailing garbage was encountered following "
178 "this command. The command was fully executed "
186 if (!getl_is_interactive ())
188 while (token != T_STOP && token != '.')
193 msg (SW, _("The rest of this command has been discarded."));
203 setlocale (LC_MESSAGES, "");
205 setlocale (LC_MONETARY, "");
206 bindtextdomain (PACKAGE, locale_dir);
207 textdomain (PACKAGE);
208 #endif /* ENABLE_NLS */
214 #if HAVE_FEHOLDEXCEPT
217 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
218 __setfpucw (_FPU_IEEE);
222 /* If a segfault happens, issue a message to that effect and halt */
229 request_bug_report_and_abort("Floating Point Exception");
232 request_bug_report_and_abort("Segmentation Violation");
235 request_bug_report_and_abort("");
241 interrupt_handler(int sig UNUSED)
247 /* Terminate PSPP. SUCCESS should be true to exit successfully,
248 false to exit as a failure. */
250 terminate (bool success)
252 static bool terminating = false;
260 cancel_transformations ();
261 dict_destroy (default_dict);
267 getl_uninitialize ();
269 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);