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

Function getoptions

v2/engine/option.c:20–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18 */
19
20int getoptions( int argc, char * * argv, char * opts, bjam_option * optv )
21{
22 int i;
23 int optc = N_OPTS;
24
25 memset( (char *)optv, '\0', sizeof( *optv ) * N_OPTS );
26
27 for ( i = 0; i < argc; ++i )
28 {
29 char *arg;
30
31 if ( ( argv[ i ][ 0 ] != '-' ) ||
32 ( ( argv[ i ][ 1 ] != '-' ) && !isalpha( argv[ i ][ 1 ] ) ) )
33 continue;
34
35 if ( !optc-- )
36 {
37 printf( "too many options (%d max)\n", N_OPTS );
38 return -1;
39 }
40
41 for ( arg = &argv[ i ][ 1 ]; *arg; ++arg )
42 {
43 char * f;
44
45 for ( f = opts; *f; ++f )
46 if ( *f == *arg )
47 break;
48
49 if ( !*f )
50 {
51 printf( "Invalid option: -%c\n", *arg );
52 return -1;
53 }
54
55 optv->flag = *f;
56
57 if ( f[ 1 ] != ':' )
58 {
59 optv++->val = "true";
60 }
61 else if ( arg[ 1 ] )
62 {
63 optv++->val = &arg[1];
64 break;
65 }
66 else if ( ++i < argc )
67 {
68 optv++->val = argv[ i ];
69 break;
70 }
71 else
72 {
73 printf( "option: -%c needs argument\n", *f );
74 return -1;
75 }
76 }
77 }

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected