summaryrefslogtreecommitdiff
path: root/jam-files/engine/output.c
diff options
context:
space:
mode:
authorPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-05-13 03:35:30 +0200
committerPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-05-13 03:35:30 +0200
commit670a8f984fc6d8342180c59ae9e96b0b76f34d3d (patch)
tree9f2ce7eec1a77e56b3bb1ad0ad40f212d7a996b0 /jam-files/engine/output.c
parenteb3ee28dc0eb1d3e5ed01ba0df843be329ae450d (diff)
parent2f64af3e06a518b93f7ca2c30a9d0aeb2c947031 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'jam-files/engine/output.c')
-rw-r--r--jam-files/engine/output.c125
1 files changed, 125 insertions, 0 deletions
diff --git a/jam-files/engine/output.c b/jam-files/engine/output.c
new file mode 100644
index 00000000..483c6ca9
--- /dev/null
+++ b/jam-files/engine/output.c
@@ -0,0 +1,125 @@
+/*
+ Copyright 2007 Rene Rivera
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+*/
+
+#include "jam.h"
+#include "output.h"
+#include "newstr.h"
+#include <stdio.h>
+
+#define bjam_out (stdout)
+#define bjam_err (stderr)
+
+static void out_
+(
+ char const * data,
+ FILE * io
+)
+{
+ while ( *data )
+ {
+ size_t len = strcspn(data,"\r");
+ data += fwrite(data,1,len,io);
+ if ( *data == '\r' ) ++data;
+ }
+}
+
+
+void out_action
+(
+ char const * action,
+ char const * target,
+ char const * command,
+ char const * out_data,
+ char const * err_data,
+ int exit_reason
+)
+{
+ /* Print out the action+target line, if the action is quite the action
+ * should be null.
+ */
+ if ( action )
+ {
+ fprintf( bjam_out, "%s %s\n", action, target );
+ }
+
+ /* Print out the command executed if given -d+2. */
+ if ( DEBUG_EXEC )
+ {
+ fputs( command, bjam_out );
+ fputc( '\n', bjam_out );
+ }
+
+ /* Print out the command executed to the command stream. */
+ if ( globs.cmdout )
+ {
+ fputs( command, globs.cmdout );
+ }
+
+ switch ( exit_reason )
+ {
+ case EXIT_OK:
+ break;
+ case EXIT_FAIL:
+ break;
+ case EXIT_TIMEOUT:
+ {
+ /* Process expired, make user aware with explicit message. */
+ if ( action )
+ {
+ /* But only output for non-quietly actions. */
+ fprintf( bjam_out, "%ld second time limit exceeded\n", globs.timeout );
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
+ /* Print out the command output, if requested, or if the program failed. */
+ if ( action || exit_reason != EXIT_OK)
+ {
+ /* But only output for non-quietly actions. */
+ if ( ( 0 != out_data ) &&
+ ( ( globs.pipe_action & 1 /* STDOUT_FILENO */ ) ||
+ ( globs.pipe_action == 0 ) ) )
+ {
+ out_( out_data, bjam_out );
+ }
+ if ( ( 0 != err_data ) &&
+ ( globs.pipe_action & 2 /* STDERR_FILENO */ ) )
+ {
+ out_( err_data, bjam_err );
+ }
+ }
+
+ fflush( bjam_out );
+ fflush( bjam_err );
+ fflush( globs.cmdout );
+}
+
+
+char * outf_int( int value )
+{
+ char buffer[50];
+ sprintf( buffer, "%i", value );
+ return newstr( buffer );
+}
+
+
+char * outf_double( double value )
+{
+ char buffer[50];
+ sprintf( buffer, "%f", value );
+ return newstr( buffer );
+}
+
+
+char * outf_time( time_t value )
+{
+ char buffer[50];
+ strftime( buffer, 49, "%Y-%m-%d %H:%M:%SZ", gmtime( &value ) );
+ return newstr( buffer );
+}