X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fterminal%2Fmsg-ui.c;h=1a2cd27f0d8cb12b41999342dc4cf8347d678057;hb=7579fa32442ac9b623043f8cd995d9b6aa550e51;hp=bcfe1ea6dcda81b54f9b49b9bc37162ded66a36e;hpb=1959a8562768999654fb385a5f8892a0c3a69f93;p=pspp diff --git a/src/ui/terminal/msg-ui.c b/src/ui/terminal/msg-ui.c index bcfe1ea6dc..1a2cd27f0d 100644 --- a/src/ui/terminal/msg-ui.c +++ b/src/ui/terminal/msg-ui.c @@ -1,6 +1,5 @@ /* PSPP - computes sample statistics. Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc. - Written by Ben Pfaff . This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -24,9 +23,14 @@ #include "exit.h" #include "linebreak.h" -#include +#include +#include #include #include +#include +#include +#include + #include "gettext.h" #define _(msgid) gettext (msgid) @@ -35,28 +39,54 @@ /* Number of errors, warnings reported. */ static int error_count; static int warning_count; +static const char *error_file; static void handle_msg (const struct msg *); +static FILE *msg_file ; + +void +msg_ui_set_error_file (const char *filename) +{ + error_file = filename; +} + void -msg_ui_init (void) +msg_ui_init (struct source_stream *ss) { - msg_init (handle_msg, get_msg_location); + msg_file = stdout; + + if ( error_file ) + { + msg_file = fopen (error_file, "a"); + if ( NULL == msg_file ) + { + int err = errno; + printf ( _("Cannot open %s (%s). " + "Writing errors to stdout instead.\n"), + error_file, strerror(err) ); + msg_file = stdout; + } + } + msg_init (ss, handle_msg); } void msg_ui_done (void) { msg_done (); + msg_locator_done (); + + if ( msg_file ) /* FIXME: do we really want to close stdout ?? */ + fclose (msg_file); } - /* Checks whether we've had so many errors that it's time to quit processing this syntax file. */ void -check_msg_count (void) +check_msg_count (struct source_stream *ss) { - if (!getl_is_interactive ()) + if (!getl_is_interactive (ss)) { if (get_errorbreak () && error_count) msg (MN, _("Terminating execution of syntax file due to error.")); @@ -69,7 +99,7 @@ check_msg_count (void) else return; - getl_abort_noninteractive (); + getl_abort_noninteractive (ss); } } @@ -141,8 +171,8 @@ handle_msg (const struct msg *m) ds_put_cstr (&string, m->text); - if (get_error_routing_to_terminal ()) - dump_message (ds_cstr (&string), get_viewwidth (), 8, stdout); + if (msg_file != stdout || get_error_routing_to_terminal ()) + dump_message (ds_cstr (&string), get_viewwidth (), 8, msg_file); ds_destroy (&string); }