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 <gsl/gsl_errno.h>
27 #include "dictionary.h"
29 #include "file-handle.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 /* Whether FINISH. has been executed. */
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);
74 /* Whether we're dropping down to interactive mode immediately because
75 we hit end-of-file unexpectedly (or whatever). */
76 int start_interactive;
78 /* Program entry point. */
80 main (int argc, char **argv)
82 signal (SIGSEGV, bug_handler);
83 signal (SIGFPE, bug_handler);
84 signal (SIGINT, interrupt_handler);
86 set_program_name ("pspp");
89 gsl_set_error_handler_off ();
98 default_dict = dict_create ();
100 parse_command_line (argc, argv);
101 outp_read_devices ();
108 handle_error (execute_command ());
111 terminate (err_error_count == 0);
115 /* Terminate PSPP. SUCCESS should be true to exit successfully,
116 false to exit as a failure. */
118 terminate (bool success)
120 static bool terminating = false;
128 cancel_transformations ();
129 dict_destroy (default_dict);
135 getl_uninitialize ();
137 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);
140 /* Parse and execute a command, returning its return code. */
142 execute_command (void)
146 /* Read the command's first token.
147 We may hit end of file.
148 If so, give the line reader a chance to proceed to the next file.
149 End of file is not handled transparently since the user may want
150 the dictionary cleared between files. */
151 getl_prompt = GETL_PRPT_STANDARD;
158 if (!getl_perform_delayed_reset ())
159 terminate (err_error_count == 0);
162 /* Parse the command. */
163 getl_prompt = GETL_PRPT_CONTINUATION;
164 result = cmd_parse ();
166 /* Unset the /ALGORITHM subcommand if it was used */
167 unset_cmd_algorithm ();
169 /* Clear any auxiliary data from the dictionary. */
170 dict_clear_aux (default_dict);
175 /* Print an error message corresponding to the command return code
178 handle_error (int code)
186 msg (SW, _("This command not executed."));
189 case CMD_PART_SUCCESS_MAYBE:
190 msg (SW, _("Skipping the rest of this command. Part of "
191 "this command may have been executed."));
194 case CMD_PART_SUCCESS:
195 msg (SW, _("Skipping the rest of this command. This "
196 "command was fully executed up to this point."));
199 case CMD_TRAILING_GARBAGE:
200 msg (SW, _("Trailing garbage was encountered following "
201 "this command. The command was fully executed "
209 if (getl_reading_script)
212 while (token != T_STOP && token != '.')
217 msg (SW, _("The rest of this command has been discarded."));
227 setlocale (LC_MESSAGES, "");
229 setlocale (LC_MONETARY, "");
230 bindtextdomain (PACKAGE, locale_dir);
231 textdomain (PACKAGE);
232 #endif /* ENABLE_NLS */
238 #if HAVE_FEHOLDEXCEPT
241 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
242 __setfpucw (_FPU_IEEE);
246 /* If a segfault happens, issue a message to that effect and halt */
253 request_bug_report_and_abort("Floating Point Exception");
256 request_bug_report_and_abort("Segmentation Violation");
259 request_bug_report_and_abort("");
266 interrupt_handler(int sig UNUSED)