MCPcopy Create free account
hub / github.com/boostorg/build / function_execute_write_file

Function function_execute_write_file

src/engine/function.cpp:4004–4143  ·  view source on GitHub ↗

Result is either the filename or contents depending on: 1. If the RESPONSE_FILE_SUB == f or not set (it's filename) 2. If the RESPONSE_FILE_SUB == c (it's contents) 3. If the RESPONSE_FILE_SUB == a (depends on the length of contents) Note, returns a *copy* of the filename or contents.

Source from the content-addressed store, hash-verified

4002// 3. If the RESPONSE_FILE_SUB == a (depends on the length of contents)
4003// Note, returns a *copy* of the filename or contents.
4004LIST * function_execute_write_file(
4005 JAM_FUNCTION * function, FRAME * frame, STACK * s,
4006 VAR_EXPANDED filename, LIST * contents )
4007{
4008 LIST * filename_or_contents_result = nullptr;
4009
4010 char response_file_sub_c = 'f';
4011 if ( filename.opt_file && filename.opt_content )
4012 {
4013 LIST * response_file_sub = function_get_named_variable(
4014 function, frame, constant_RESPONSE_FILE_SUB );
4015 if ( response_file_sub && list_front( response_file_sub ) )
4016 response_file_sub_c = object_str( list_front( response_file_sub ) )[0];
4017 list_free( response_file_sub );
4018 const char * contents_str = object_str( list_front( contents ) );
4019 if ( response_file_sub_c == 'a' )
4020 {
4021 if ( int32_t( strlen( contents_str ) + 256 ) > shell_maxline() )
4022 response_file_sub_c = 'f';
4023 else
4024 response_file_sub_c = 'c';
4025 }
4026 }
4027 else if ( filename.opt_file )
4028 response_file_sub_c = 'f';
4029 else if ( filename.opt_content )
4030 response_file_sub_c = 'c';
4031 if ( response_file_sub_c == 'c' )
4032 {
4033 filename_or_contents_result = list_copy( contents );
4034 }
4035 else
4036 {
4037 char const * out = object_str( list_front( filename.inner ) );
4038 OBJECT * tmp_filename = nullptr;
4039 FILE * out_file = nullptr;
4040 bool out_debug = DEBUG_EXEC != 0;
4041
4042 /* For stdout/stderr we will create a temp file and generate a
4043 * command that outputs the content as needed.
4044 */
4045 if ( ( strcmp( "STDOUT", out ) == 0 ) ||
4046 ( strcmp( "STDERR", out ) == 0 ) )
4047 {
4048 int32_t err_redir = strcmp( "STDERR", out ) == 0;
4049 string result[ 1 ];
4050
4051 tmp_filename = path_tmpfile();
4052
4053 /* Construct os-specific cat command. */
4054 {
4055 const char * command = "cat";
4056 const char * quote = "\"";
4057 const char * redirect = "1>&2";
4058
4059 #ifdef OS_NT
4060 command = "type";
4061 quote = "\"";

Callers 1

function_runFunction · 0.85

Calls 15

object_strFunction · 0.85
list_freeFunction · 0.85
list_copyFunction · 0.85
path_tmpfileFunction · 0.85
string_newFunction · 0.85
path_translate_to_osFunction · 0.85
object_freeFunction · 0.85
object_newFunction · 0.85
string_freeFunction · 0.85
string_appendFunction · 0.85
list_newFunction · 0.85

Tested by

no test coverage detected