X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fterminal%2Fmsg-ui.c;h=b63ec25bef38fa6c15277c6748f9ffbecba972db;hb=48386ee68a5283653435d05a9ea4e449710fd370;hp=3e354a7b372d7b5c5cd2b882be5e85780b8fdd91;hpb=b74d09af5e07f954c18e7cdb8aca3af47fa10208;p=pspp-builds.git diff --git a/src/ui/terminal/msg-ui.c b/src/ui/terminal/msg-ui.c index 3e354a7b..b63ec25b 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 @@ -21,12 +20,16 @@ #include "msg-ui.h" -#include "exit.h" #include "linebreak.h" -#include +#include +#include #include #include +#include +#include +#include +#include #include "gettext.h" #define _(msgid) gettext (msgid) @@ -35,27 +38,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); + 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.")); @@ -68,7 +98,7 @@ check_msg_count (void) else return; - getl_abort_noninteractive (); + getl_abort_noninteractive (ss); } } @@ -140,9 +170,8 @@ handle_msg (const struct msg *m) ds_put_cstr (&string, m->text); - /* FIXME: Check set_messages and set_errors to determine where to - send errors and messages. */ - 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); }