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

Function exec_cmd

v2/engine/execnt.c:270–347  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268 */
269
270void exec_cmd
271(
272 string const * cmd_orig,
273 ExecCmdCallback func,
274 void * closure,
275 LIST * shell
276)
277{
278 int const slot = get_free_cmdtab_slot();
279 int const is_raw_cmd = is_raw_command_request( shell );
280 string cmd_local[ 1 ];
281
282 /* Initialize default shell - anything more than /Q/C is non-portable. */
283 static LIST * default_shell;
284 if ( !default_shell )
285 default_shell = list_new( object_new( "cmd.exe /Q/C" ) );
286
287 /* Specifying no shell means requesting the default shell. */
288 if ( list_empty( shell ) )
289 shell = default_shell;
290
291 if ( DEBUG_EXECCMD )
292 if ( is_raw_cmd )
293 printf( "Executing raw command directly\n" );
294 else
295 {
296 printf( "Executing using a command file and the shell: " );
297 list_print( shell );
298 printf( "\n" );
299 }
300
301 /* If we are running a raw command directly - trim its leading whitespaces
302 * as well as any trailing all-whitespace lines but keep any trailing
303 * whitespace in the final/only line containing something other than
304 * whitespace).
305 */
306 if ( is_raw_cmd )
307 {
308 char const * start = cmd_orig->value;
309 char const * p = cmd_orig->value + cmd_orig->size;
310 char const * end = p;
311 while ( isspace( *start ) ) ++start;
312 while ( p > start && isspace( p[ -1 ] ) )
313 if ( *--p == '\n' )
314 end = p;
315 string_new( cmd_local );
316 string_append_range( cmd_local, start, end );
317 assert( cmd_local->size == raw_command_length( cmd_orig->value ) );
318 }
319 /* If we are not running a raw command directly, prepare a command file to
320 * be executed using an external shell and the actual command string using
321 * that command file.
322 */
323 else
324 {
325 char const * const cmd_file = prepare_command_file( cmd_orig, slot );
326 char const * argv[ MAXARGC + 1 ]; /* +1 for NULL */
327 argv_from_shell( argv, shell, cmd_file, slot );

Callers 1

make1cFunction · 0.70

Calls 13

is_raw_command_requestFunction · 0.85
list_newFunction · 0.85
object_newFunction · 0.85
list_printFunction · 0.85
string_newFunction · 0.85
string_append_rangeFunction · 0.85
raw_command_lengthFunction · 0.85
prepare_command_fileFunction · 0.85
argv_from_shellFunction · 0.85
string_new_from_argvFunction · 0.85
invoke_cmdFunction · 0.85
string_freeFunction · 0.85

Tested by

no test coverage detected