]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/engine/execcmd.c
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / tools / build / src / engine / execcmd.c
1 /*
2 * Copyright 1993, 1995 Christopher Seiwald.
3 * Copyright 2007 Noel Belcourt.
4 *
5 * Utility functions shared between different exec*.c platform specific
6 * implementation modules.
7 *
8 * This file is part of Jam - see jam.c for Copyright information.
9 */
10
11 #include "jam.h"
12 #include "execcmd.h"
13
14 #include <assert.h>
15 #include <stdio.h>
16 #include <string.h>
17
18
19 /* Internal interrupt counter. */
20 static int intr;
21
22
23 /* Constructs a list of command-line elements using the format specified by the
24 * given shell list.
25 *
26 * Given argv array should have at least MAXARGC + 1 elements.
27 * Slot numbers may be between 0 and 998 (inclusive).
28 *
29 * Constructed argv list will be zero terminated. Character arrays referenced by
30 * the argv structure elements will be either elements from the give shell list,
31 * internal static buffers or the given command string and should thus not
32 * considered owned by or released via the argv structure and should be
33 * considered invalidated by the next argv_from_shell() call.
34 *
35 * Shell list elements:
36 * - Starting with '%' - represent the command string.
37 * - Starting with '!' - represent the slot number (increased by one).
38 * - Anything else - used as a literal.
39 * - If no '%' element is found, the command string is appended as an extra.
40 */
41
42 void argv_from_shell( char const * * argv, LIST * shell, char const * command,
43 int const slot )
44 {
45 static char jobno[ 4 ];
46
47 int i;
48 int gotpercent = 0;
49 LISTITER iter = list_begin( shell );
50 LISTITER end = list_end( shell );
51
52 assert( 0 <= slot );
53 assert( slot < 999 );
54 sprintf( jobno, "%d", slot + 1 );
55
56 for ( i = 0; iter != end && i < MAXARGC; ++i, iter = list_next( iter ) )
57 {
58 switch ( object_str( list_item( iter ) )[ 0 ] )
59 {
60 case '%': argv[ i ] = command; ++gotpercent; break;
61 case '!': argv[ i ] = jobno; break;
62 default : argv[ i ] = object_str( list_item( iter ) );
63 }
64 }
65
66 if ( !gotpercent )
67 argv[ i++ ] = command;
68
69 argv[ i ] = NULL;
70 }
71
72
73 /* Returns whether the given command string contains lines longer than the given
74 * maximum.
75 */
76 int check_cmd_for_too_long_lines( char const * command, int const max,
77 int * const error_length, int * const error_max_length )
78 {
79 while ( *command )
80 {
81 size_t const l = strcspn( command, "\n" );
82 if ( l > max )
83 {
84 *error_length = l;
85 *error_max_length = max;
86 return EXEC_CHECK_LINE_TOO_LONG;
87 }
88 command += l;
89 if ( *command )
90 ++command;
91 }
92 return EXEC_CHECK_OK;
93 }
94
95
96 /* Checks whether the given shell list is actually a request to execute raw
97 * commands without an external shell.
98 */
99 int is_raw_command_request( LIST * shell )
100 {
101 return !list_empty( shell ) &&
102 !strcmp( object_str( list_front( shell ) ), "%" ) &&
103 list_next( list_begin( shell ) ) == list_end( shell );
104 }
105
106
107 /* Returns whether an interrupt has been detected so far. */
108
109 int interrupted( void )
110 {
111 return intr != 0;
112 }
113
114
115 /* Internal interrupt handler. */
116
117 void onintr( int disp )
118 {
119 ++intr;
120 out_printf( "...interrupted\n" );
121 }