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-def.h"
42 #if HAVE_FPU_CONTROL_H
43 #include <fpu_control.h>
55 #define _(msgid) gettext (msgid)
59 #include "debug-print.h"
61 static void i18n_init (void);
62 static void fpu_init (void);
63 static void handle_error (int code);
64 static int execute_command (void);
66 /* Whether FINISH. has been executed. */
69 /* If a segfault happens, issue a message to that effect and halt */
70 void bug_handler(int sig);
72 /* Handle quit/term/int signals */
73 void interrupt_handler(int sig);
75 /* Whether we're dropping down to interactive mode immediately because
76 we hit end-of-file unexpectedly (or whatever). */
77 int start_interactive;
79 /* Program entry point. */
81 main (int argc, char **argv)
83 signal (SIGSEGV, bug_handler);
84 signal (SIGFPE, bug_handler);
85 signal (SIGINT, interrupt_handler);
87 set_program_name ("pspp");
90 gsl_set_error_handler_off ();
100 default_dict = dict_create ();
102 parse_command_line (argc, argv);
103 outp_read_devices ();
110 handle_error (execute_command ());
113 terminate (err_error_count == 0);
117 /* Terminate PSPP. SUCCESS should be true to exit successfully,
118 false to exit as a failure. */
120 terminate (bool success)
122 static bool terminating = false;
130 cancel_transformations ();
131 dict_destroy (default_dict);
137 getl_uninitialize ();
139 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);
142 /* Parse and execute a command, returning its return code. */
144 execute_command (void)
148 /* Read the command's first token.
149 We may hit end of file.
150 If so, give the line reader a chance to proceed to the next file.
151 End of file is not handled transparently since the user may want
152 the dictionary cleared between files. */
153 getl_prompt = GETL_PRPT_STANDARD;
160 /* Sets the options flag of the current script to 0, thus allowing it
161 to be read in. Returns nonzero if this action was taken, zero
163 if (getl_head && getl_head->separate)
165 getl_head->separate = 0;
166 discard_variables ();
170 terminate (err_error_count == 0);
173 /* Parse the command. */
174 getl_prompt = GETL_PRPT_CONTINUATION;
175 result = cmd_parse ();
177 /* Unset the /ALGORITHM subcommand if it was used */
178 unset_cmd_algorithm ();
180 /* Clear any auxiliary data from the dictionary. */
181 dict_clear_aux (default_dict);
186 /* Print an error message corresponding to the command return code
189 handle_error (int code)
197 msg (SW, _("This command not executed."));
200 case CMD_PART_SUCCESS_MAYBE:
201 msg (SW, _("Skipping the rest of this command. Part of "
202 "this command may have been executed."));
205 case CMD_PART_SUCCESS:
206 msg (SW, _("Skipping the rest of this command. This "
207 "command was fully executed up to this point."));
210 case CMD_TRAILING_GARBAGE:
211 msg (SW, _("Trailing garbage was encountered following "
212 "this command. The command was fully executed "
220 if (getl_reading_script())
223 while (token != T_STOP && token != '.')
228 msg (SW, _("The rest of this command has been discarded."));
238 setlocale (LC_MESSAGES, "");
240 setlocale (LC_MONETARY, "");
241 bindtextdomain (PACKAGE, locale_dir);
242 textdomain (PACKAGE);
243 #endif /* ENABLE_NLS */
249 #if HAVE_FEHOLDEXCEPT
252 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
253 __setfpucw (_FPU_IEEE);
257 /* If a segfault happens, issue a message to that effect and halt */
264 request_bug_report_and_abort("Floating Point Exception");
267 request_bug_report_and_abort("Segmentation Violation");
270 request_bug_report_and_abort("");
277 interrupt_handler(int sig UNUSED)