set on the command line.
+Tue Nov 7 20:54:32 WST 2006 John Darrington <john@darrington.wattle.id.au>
+
+ * command-line.c msg-ui.c msg-ui.h main.c: Added an -e
+ option to set the file for error messages.
+
Sat Nov 4 15:48:04 2006 Ben Pfaff <blp@gnu.org>
* msg-ui.c (handle_msg): Only write message to terminal if
#include <config.h>
#include "command-line.h"
+#include "msg-ui.h"
#include <libpspp/message.h>
#include <ctype.h>
#include <stdio.h>
{"device", required_argument, NULL, 'o'},
{"dry-run", no_argument, NULL, 'n'},
{"edit", no_argument, NULL, 'n'},
+ {"error-file", required_argument, NULL, 'e'},
{"help", no_argument, NULL, 'h'},
{"include-directory", required_argument, NULL, 'I'},
{"interactive", no_argument, NULL, 'i'},
for (;;)
{
- c = getopt_long (argc, argv, "a:x:B:c:f:hiI:lno:prsvV", long_options, NULL);
+ c = getopt_long (argc, argv, "a:x:B:c:e:f:hiI:lno:prsvV", long_options, NULL);
if (c == -1)
break;
return false;
}
break;
-
+ case 'e':
+ msg_ui_set_error_file (optarg);
+ break;
case 'B':
config_path = optarg;
break;
" -B, --config-dir=DIR set configuration directory to DIR\n"
" -o, --device=DEVICE select output driver DEVICE and disable defaults\n"
"\nInput and output:\n"
+" -e, --error-file=FILE send error messages to FILE (appended)\n"
" -f, --out-file=FILE send output to FILE (overwritten)\n"
" -p, --pipe read script from stdin, send output to stdout\n"
" -I-, --no-include clear include path\n"
fmt_init ();
outp_init ();
- msg_ui_init ();
fn_init ();
fh_init ();
getl_initialize ();
if (parse_command_line (argc, argv))
{
+ msg_ui_init ();
outp_read_devices ();
lex_init (do_read_line);
#include <language/line-buffer.h>
#include <data/settings.h>
#include <libpspp/message.h>
+#include <errno.h>
#include "gettext.h"
#define _(msgid) gettext (msgid)
/* 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_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 (handle_msg, get_msg_location);
}
msg_ui_done (void)
{
msg_done ();
+ fclose (msg_file);
}
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);
}
#include <stdbool.h>
+void msg_ui_set_error_file (const char *filename);
void msg_ui_init (void);
void msg_ui_done (void);
void check_msg_count (void);
# So this will have a non zero error status.
# But it shouldn't crash!
activity="run_program"
-$SUPERVISOR $PSPP $TESTFILE > /dev/null
+$SUPERVISOR $PSPP -e /dev/null $TESTFILE
if [ $? -ne 1 ] ; then fail ; fi
if [ $? -ne 0 ] ; then no_result ; fi
activity="run program"
-$SUPERVISOR $PSPP -o raw-ascii $TESTFILE > /dev/null
+$SUPERVISOR $PSPP -o raw-ascii -e /dev/null $TESTFILE
if [ $? -ne 0 ] ; then fail ; fi
activity="appending to data"
if [ $? -ne 0 ] ; then no_result ; fi
activity="run program"
-$SUPERVISOR $PSPP -o raw-ascii $TESTFILE > /dev/null
+$SUPERVISOR $PSPP -o raw-ascii -e /dev/null $TESTFILE
if [ $? -ne 0 ] ; then fail ; fi
pass;
if [ $? -ne 0 ] ; then no_result ; fi
activity="run program"
-$SUPERVISOR $PSPP -o raw-ascii $TEMPDIR/foo.sps > /dev/null
+$SUPERVISOR $PSPP -o raw-ascii -e /dev/null $TEMPDIR/foo.sps
if [ $? -ne 0 ] ; then fail ; fi
pass;
#This must fail
activity="run program"
-$SUPERVISOR $PSPP $TESTFILE > /dev/null
+$SUPERVISOR $PSPP -e /dev/null $TESTFILE
if [ $? -ne 1 ] ; then fail ; fi
#This must fail
activity="run program"
-$SUPERVISOR $PSPP $TEMPDIR/ct.stat > /dev/null
+$SUPERVISOR $PSPP -e /dev/null $TEMPDIR/ct.stat
if [ $? -ne 1 ] ; then fail ; fi
-
pass;
if [ $? -ne 0 ] ; then no_result ; fi
activity="run program"
-$SUPERVISOR $PSPP -o raw-ascii $TESTFILE > /dev/null 2>&1
+$SUPERVISOR $PSPP -o raw-ascii -e /dev/null $TESTFILE 2> /dev/null
if [ $? -ne 0 ] ; then fail ; fi
pass;
# So this will have a non zero error status.
# But it shouldn't crash!
activity="run_program"
-$SUPERVISOR $PSPP $TESTFILE > /dev/null
+$SUPERVISOR $PSPP -e /dev/null $TESTFILE
if [ $? -ne 1 ] ; then fail ; fi
# The above syntax is invalid, so this program should fail to parse
activity="run program"
-$SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > /dev/null
+$SUPERVISOR $PSPP --testing-mode -o raw-ascii -e /dev/null $TESTFILE
if [ $? -ne 1 ] ; then fail ; fi
activity="run program"
-$SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > /dev/null
+$SUPERVISOR $PSPP --testing-mode -o raw-ascii -e /dev/null $TESTFILE
if [ $? -ne 1 ] ; then fail ; fi
#The syntax was invalid. Therefore pspp must return non zero.
activity="run program"
-$SUPERVISOR $PSPP -o raw-ascii $TESTFILE > /dev/null
+$SUPERVISOR $PSPP -o raw-ascii -e /dev/null $TESTFILE
if [ $? -ne 1 ] ; then fail ; fi
pass;
activity="run program"
# This must exit with non zero status
-$SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/foo.sps > /dev/null 2> $TEMPDIR/stderr
+$SUPERVISOR $here/../src/pspp -o raw-ascii -e /dev/null $TEMPDIR/foo.sps 2> $TEMPDIR/stderr
if [ $? -eq 0 ] ; then fail ; fi
activity="compare stderr"
#Invalid syntax --- return value is non zero.
activity="run program"
-$SUPERVISOR $PSPP -o raw-ascii $TESTFILE > /dev/null
+$SUPERVISOR $PSPP -o raw-ascii -e /dev/null $TESTFILE
if [ $? -ne 1 ] ; then fail ; fi
pass;
if [ $? -ne 0 ] ; then no_result ; fi
activity="run $name.pspp"
- $SUPERVISOR $PSPP --testing-mode -o raw-ascii $name.pspp >/dev/null 2>&1
+ $SUPERVISOR $PSPP --testing-mode -o raw-ascii -e /dev/null $name.pspp
if [ $? -ne 0 ] ; then no_result ; fi
activity="check $name output"
# This command must fail
activity="run prog 1"
-$SUPERVISOR $PSPP $TESTFILE > /dev/null
+$SUPERVISOR $PSPP -e /dev/null $TESTFILE
if [ $? -eq 0 ] ; then fail ; fi
if [ $? -ne 0 ] ; then no_result ; fi
activity="run program"
-$SUPERVISOR $PSPP --testing-mode -o raw-ascii $TEMPDIR/loop.stat > $TEMPDIR/stdout
+$SUPERVISOR $PSPP --testing-mode -o raw-ascii -e $TEMPDIR/stdout $TEMPDIR/loop.stat
if [ $? -ne 0 ] ; then no_result ; fi
activity="compare stdout"
if [ $? -ne 0 ] ; then no_result ; fi
activity="run $name.pspp"
- $SUPERVISOR $PSPP -o raw-ascii $name.pspp >/dev/null 2>&1
+ $SUPERVISOR $PSPP -o raw-ascii -e /dev/null $name.pspp
if [ $? -ne 0 ] ; then no_result ; fi
activity="check $name output"
if [ $? -ne 0 ] ; then no_result ; fi
activity="run $name.pspp"
-$SUPERVISOR $PSPP -o raw-ascii $name.pspp >/dev/null 2>&1
+$SUPERVISOR $PSPP -o raw-ascii -e /dev/null $name.pspp
if [ $? -ne 0 ] ; then no_result ; fi
activity="check $name output"
if [ $? -ne 0 ] ; then no_result ; fi
activity="run $name.pspp"
-$SUPERVISOR $PSPP -o raw-ascii $name.pspp >/dev/null 2>&1
+$SUPERVISOR $PSPP -o raw-ascii -e /dev/null $name.pspp
if [ $? -ne 0 ] ; then no_result ; fi
activity="check $name output"
activity="run program"
-$SUPERVISOR $PSPP --testing-mode -o raw-ascii --testing-mode $TEMPDIR/missing-values.stat > $TEMPDIR/errs
+$SUPERVISOR $PSPP --testing-mode -o raw-ascii --testing-mode --error-file=$TEMPDIR/errs $TEMPDIR/missing-values.stat
# Note vv --- there are errors in input. Therefore, the command must FAIL
if [ $? -eq 0 ] ; then fail ; fi
activity="run program"
-$SUPERVISOR $PSPP --testing-mode -o raw-ascii --testing-mode $TEMPDIR/print.stat > $TEMPDIR/errs
+$SUPERVISOR $PSPP --testing-mode -o raw-ascii --testing-mode --error-file=$TEMPDIR/errs $TEMPDIR/print.stat
if [ $? -ne 0 ] ; then fail ; fi
activity="compare print.out"
# Check that it properly handles failed transformations.
activity="run program 1"
-$SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > $TEMPDIR/err
+$SUPERVISOR $PSPP --testing-mode -o raw-ascii -e $TEMPDIR/err $TESTFILE
if [ $? -ne 1 ] ; then fail ; fi
activity="diff 1"
activity="run program (syntax errors)"
-$SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > $TEMPDIR/errs
+$SUPERVISOR $PSPP --testing-mode -o raw-ascii -e $TEMPDIR/errs $TESTFILE
if [ $? -ne 1 ] ; then fail ; fi
activity="compare errors"
if [ $? -ne 0 ] ; then no_result ; fi
activity="run program 4"
-$SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > /dev/null
+$SUPERVISOR $PSPP --testing-mode -o raw-ascii -e /dev/null $TESTFILE
if [ $? -ne 0 ] ; then fail ; fi
if [ $? -ne 0 ] ; then no_result ; fi
activity="run program 0"
-$SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > /dev/null
+$SUPERVISOR $PSPP --testing-mode -o raw-ascii -e /dev/null $TESTFILE
if [ $? -ne 0 ] ; then fail ; fi
activity="compare variable display 0"