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"
27 #include "dictionary.h"
29 #include "file-handle-def.h"
31 #include "line-buffer.h"
36 #include "read-line.h"
41 #if HAVE_FPU_CONTROL_H
42 #include <fpu_control.h>
54 #define _(msgid) gettext (msgid)
58 #include "debug-print.h"
60 static void i18n_init (void);
61 static void fpu_init (void);
62 static void handle_error (int code);
63 static int execute_command (void);
65 /* If a segfault happens, issue a message to that effect and halt */
66 void bug_handler(int sig);
68 /* Handle quit/term/int signals */
69 void interrupt_handler(int sig);
71 void terminate (bool success);
73 /* Program entry point. */
75 main (int argc, char **argv)
77 signal (SIGSEGV, bug_handler);
78 signal (SIGFPE, bug_handler);
79 signal (SIGINT, interrupt_handler);
81 set_program_name ("pspp");
84 gsl_set_error_handler_off ();
94 default_dict = dict_create ();
96 if (parse_command_line (argc, argv))
107 retval = execute_command ();
108 if (retval == CMD_EOF)
110 if (retval != CMD_SUCCESS)
111 handle_error (retval);
115 terminate (err_error_count == 0);
119 /* Parse and execute a command, returning its return code. */
121 execute_command (void)
125 /* Read the command's first token.
126 The first token is part of the first line of the command. */
127 getl_set_prompt_style (GETL_PROMPT_FIRST);
132 /* Parse the command.
133 Any lines read after the first token must be continuation
135 getl_set_prompt_style (GETL_PROMPT_LATER);
136 result = cmd_parse ();
138 /* Unset the /ALGORITHM subcommand if it was used */
139 unset_cmd_algorithm ();
141 /* Clear any auxiliary data from the dictionary. */
142 dict_clear_aux (default_dict);
147 /* Print an error message corresponding to the command return code
150 handle_error (int code)
152 if (code == CMD_CASCADING_FAILURE && !getl_is_interactive ())
154 msg (SW, _("This command not executed. Stopping here "
155 "to avoid cascading failures."));
156 getl_abort_noninteractive ();
163 case CMD_CASCADING_FAILURE:
164 msg (SW, _("This command not executed."));
167 case CMD_PART_SUCCESS_MAYBE:
168 msg (SW, _("Skipping the rest of this command. Part of "
169 "this command may have been executed."));
172 case CMD_PART_SUCCESS:
173 msg (SW, _("Skipping the rest of this command. This "
174 "command was fully executed up to this point."));
177 case CMD_TRAILING_GARBAGE:
178 msg (SW, _("Trailing garbage was encountered following "
179 "this command. The command was fully executed "
187 if (!getl_is_interactive ())
189 while (token != T_STOP && token != '.')
194 msg (SW, _("The rest of this command has been discarded."));
204 setlocale (LC_MESSAGES, "");
206 setlocale (LC_MONETARY, "");
207 bindtextdomain (PACKAGE, locale_dir);
208 textdomain (PACKAGE);
209 #endif /* ENABLE_NLS */
215 #if HAVE_FEHOLDEXCEPT
218 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
219 __setfpucw (_FPU_IEEE);
223 /* If a segfault happens, issue a message to that effect and halt */
230 request_bug_report_and_abort("Floating Point Exception");
233 request_bug_report_and_abort("Segmentation Violation");
236 request_bug_report_and_abort("");
242 interrupt_handler(int sig UNUSED)
248 /* Terminate PSPP. SUCCESS should be true to exit successfully,
249 false to exit as a failure. */
251 terminate (bool success)
253 static bool terminating = false;
261 cancel_transformations ();
262 dict_destroy (default_dict);
268 getl_uninitialize ();
270 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);