X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmain.c;h=be22605b822dec1d0b9d17ccc3a25b584614d039;hb=d5fd364b203a2a84e5034b6ff5ac5d6c4412edb7;hp=ab3a0b6d0ec30cf1eb710a1cc2e23b9d6aaea7c0;hpb=4fdeb2145d081ff1b84e3f6c99f9d1c048c0d64a;p=pspp-builds.git diff --git a/src/main.c b/src/main.c index ab3a0b6d..be22605b 100644 --- a/src/main.c +++ b/src/main.c @@ -18,39 +18,54 @@ 02110-1301, USA. */ #include -#include -#include #include "main.h" +#include +#include +#include #include "cmdline.h" #include "command.h" #include "dictionary.h" #include "error.h" -#include "getline.h" +#include "file-handle.h" +#include "filename.h" +#include "getl.h" #include "glob.h" #include "lexer.h" #include "output.h" +#include "progname.h" +#include "random.h" +#include "readln.h" #include "settings.h" #include "var.h" -#include +#include "version.h" + +#if HAVE_FPU_CONTROL_H +#include +#endif + +#if HAVE_LOCALE_H +#include +#endif + +#if HAVE_FENV_H +#include +#endif + +#include "gettext.h" +#define _(msgid) gettext (msgid) #include #include "debug-print.h" -static void parse_script (void) NO_RETURN; +static void i18n_init (void); +static void fpu_init (void); static void handle_error (int code); static int execute_command (void); -/* argv[0] with stripped leading directories. */ -char *pgmname; - /* Whether FINISH. has been executed. */ int finished; -/* The current date in the form DD MMM YYYY. */ -char curdate[12]; - - /* If a segfault happens, issue a message to that effect and halt */ void bug_handler(int sig); @@ -61,50 +76,67 @@ void interrupt_handler(int sig); we hit end-of-file unexpectedly (or whatever). */ int start_interactive; - - - - - /* Program entry point. */ int main (int argc, char **argv) { - signal (SIGSEGV, bug_handler); - signal (SIGFPE, bug_handler); - signal (SIGINT, interrupt_handler); + signal (SIGFPE, bug_handler); + signal (SIGINT, interrupt_handler); - gsl_set_error_handler_off(); + set_program_name ("pspp"); + i18n_init (); + fpu_init (); + gsl_set_error_handler_off (); - /* Initialization. */ - if (!outp_init ()) - err_hcf (0); - init_glob (argc, argv); - parse_command_line (argc, argv); - if (!outp_read_devices ()) - msg (FE, _("Error initializing output drivers.")); + outp_init (); + fn_init (); + fh_init (); + getl_initialize (); + readln_initialize (); + settings_init (); + random_init (); - lex_init (); + default_dict = dict_create (); - /* Execution. */ - parse_script (); + parse_command_line (argc, argv); + outp_read_devices (); - /* Should never be reached */ - return (-1); -} + lex_init (); -/* Parses the entire script. */ -static void -parse_script (void) -{ while (!finished) { err_check_count (); handle_error (execute_command ()); } - err_hcf (err_error_count==0); + terminate (err_error_count == 0); + abort (); +} + +/* Terminate PSPP. SUCCESS should be true to exit successfully, + false to exit as a failure. */ +void +terminate (bool success) +{ + static bool terminating = false; + if (terminating) + return; + terminating = true; + + err_done (); + outp_done (); + + cancel_transformations (); + dict_destroy (default_dict); + + random_done (); + settings_done (); + fh_done (); + lex_done (); + getl_uninitialize (); + + exit (success ? EXIT_SUCCESS : EXIT_FAILURE); } /* Parse and execute a command, returning its return code. */ @@ -125,8 +157,17 @@ execute_command (void) if (token != T_STOP) break; - if (!getl_perform_delayed_reset ()) - err_hcf (err_error_count==0); + /* Sets the options flag of the current script to 0, thus allowing it + to be read in. Returns nonzero if this action was taken, zero + otherwise. */ + if (getl_head && getl_head->separate) + { + getl_head->separate = 0; + discard_variables (); + lex_reset_eof (); + } + else + terminate (err_error_count == 0); } /* Parse the command. */ @@ -176,7 +217,7 @@ handle_error (int code) assert (0); } - if (getl_reading_script) + if (getl_reading_script()) { err_break (); while (token != T_STOP && token != '.') @@ -188,12 +229,34 @@ handle_error (int code) lex_discard_line (); } } + +static void +i18n_init (void) +{ +#if ENABLE_NLS +#if HAVE_LC_MESSAGES + setlocale (LC_MESSAGES, ""); +#endif + setlocale (LC_MONETARY, ""); + bindtextdomain (PACKAGE, locale_dir); + textdomain (PACKAGE); +#endif /* ENABLE_NLS */ +} - +static void +fpu_init (void) +{ +#if HAVE_FEHOLDEXCEPT + fenv_t foo; + feholdexcept (&foo); +#elif HAVE___SETFPUCW && defined(_FPU_IEEE) + __setfpucw (_FPU_IEEE); +#endif +} /* If a segfault happens, issue a message to that effect and halt */ void -bug_handler(int sig UNUSED) +bug_handler(int sig) { switch (sig) { @@ -213,5 +276,5 @@ bug_handler(int sig UNUSED) void interrupt_handler(int sig UNUSED) { - err_hcf(0); + terminate (false); }