summaryrefslogtreecommitdiff
path: root/src/optparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/optparser.cpp')
-rw-r--r--src/optparser.cpp105
1 files changed, 86 insertions, 19 deletions
diff --git a/src/optparser.cpp b/src/optparser.cpp
index f99dd85..2a8e64b 100644
--- a/src/optparser.cpp
+++ b/src/optparser.cpp
@@ -28,28 +28,48 @@ void Bu::OptParser::parse( int argc, char **argv )
28 28
29 Bu::FString sOpt; 29 Bu::FString sOpt;
30 int iCount = argc-j; 30 int iCount = argc-j;
31 Bu::FString sExtraParam;
31 if( argv[j][iEPos] == '=' ) 32 if( argv[j][iEPos] == '=' )
32 { 33 {
33 sOpt.set( argv[j]+2, iEPos-2 ); 34 sOpt.set( argv[j]+2, iEPos-2 );
34 iCount++; 35 iCount++;
36 sExtraParam.set( argv[j]+iEPos+1 );
35 } 37 }
36 else 38 else
37 { 39 {
38 sOpt.set( argv[j]+2 ); 40 sOpt.set( argv[j]+2 );
39 } 41 }
40 Option *pOpt = hlOption.get( sOpt ); 42 Option *pOpt = hlOption.get( sOpt );
41 Bu::StrArray aParams( iCount ); 43 if( pOpt->sUsed )
42 aParams.append( sOpt );
43 if( argv[j][iEPos] == '=' )
44 { 44 {
45 aParams.append( argv[j]+iEPos+1 ); 45 Bu::StrArray aParams( iCount );
46 aParams.append( sOpt );
47 if( sExtraParam )
48 {
49 aParams.append( argv[j]+iEPos+1 );
50 }
51 for( int k = j+1; k < argc; k++ )
52 {
53 aParams.append( argv[k] );
54 }
55 j += pOpt->sUsed( aParams );
46 } 56 }
47 for( int k = j+1; k < argc; k++ ) 57 else if( pOpt->pProxy )
48 { 58 {
49 aParams.append( argv[k] ); 59 if( pOpt->sOverride )
60 {
61 pOpt->pProxy->setValue( pOpt->sOverride );
62 }
63 else if( sExtraParam )
64 {
65 pOpt->pProxy->setValue( sExtraParam );
66 }
67 else if( argv[j+1] != '\0' )
68 {
69 pOpt->pProxy->setValue( argv[j+1] );
70 j++;
71 }
50 } 72 }
51 if( pOpt->sUsed )
52 j += pOpt->sUsed( aParams );
53 } 73 }
54 else 74 else
55 { 75 {
@@ -57,26 +77,45 @@ void Bu::OptParser::parse( int argc, char **argv )
57 for( iCPos = 1; argv[j][iCPos] != '\0'; iCPos++ ) 77 for( iCPos = 1; argv[j][iCPos] != '\0'; iCPos++ )
58 { 78 {
59 Option *pOpt = hsOption.get( argv[j][iCPos] ); 79 Option *pOpt = hsOption.get( argv[j][iCPos] );
60 Bu::StrArray aParams( argc-j+1 );
61 char buf[2] = {argv[j][iCPos], '\0'}; 80 char buf[2] = {argv[j][iCPos], '\0'};
62 aParams.append( buf );
63 if( pOpt->bShortHasParams ) 81 if( pOpt->bShortHasParams )
64 { 82 {
65 if( argv[j][iCPos+1] != '\0' )
66 aParams.append( argv[j]+iCPos+1 );
67 for( int k = j+1; k < argc; k++ )
68 {
69 aParams.append( argv[k] );
70 }
71 if( pOpt->sUsed ) 83 if( pOpt->sUsed )
72 { 84 {
85 Bu::StrArray aParams( argc-j+1 );
86 aParams.append( buf );
87 if( argv[j][iCPos+1] != '\0' )
88 aParams.append( argv[j]+iCPos+1 );
89 for( int k = j+1; k < argc; k++ )
90 {
91 aParams.append( argv[k] );
92 }
73 j += pOpt->sUsed( aParams ); 93 j += pOpt->sUsed( aParams );
94 break;
95 }
96 else if( pOpt->pProxy )
97 {
98 if( pOpt->sOverride )
99 {
100 pOpt->pProxy->setValue( pOpt->sOverride );
101 }
102 else if( argv[j][iCPos+1] != '\0' )
103 {
104 pOpt->pProxy->setValue(
105 argv[j]+iCPos+1
106 );
107 break;
108 }
74 } 109 }
75 break;
76 } 110 }
77 else 111 else
78 { 112 {
79 pOpt->sUsed( aParams ); 113 if( pOpt->sUsed )
114 {
115 Bu::StrArray aParam( 1 );
116 aParam.append( buf );
117 pOpt->sUsed( aParam );
118 }
80 } 119 }
81 } 120 }
82 } 121 }
@@ -247,16 +286,44 @@ Bu::FString Bu::OptParser::format( const Bu::FString &sIn, int iWidth,
247 286
248 287
249// 288//
289// Code for Bu::OptParser::_ValueProxy
290//
291
292Bu::OptParser::_ValueProxy::_ValueProxy()
293{
294}
295
296Bu::OptParser::_ValueProxy::~_ValueProxy()
297{
298}
299
300//
250// Code for Bu::OptParser::Option 301// Code for Bu::OptParser::Option
251// 302//
252 303
253Bu::OptParser::Option::Option() : 304Bu::OptParser::Option::Option() :
254 cOpt( '\0' ), 305 cOpt( '\0' ),
255 bShortHasParams( false ) 306 bShortHasParams( false ),
307 pProxy( NULL )
308{
309}
310
311Bu::OptParser::Option::Option( const Option &rSrc ) :
312 cOpt( rSrc.cOpt ),
313 sOpt( rSrc.sOpt ),
314 sHelp( rSrc.sHelp ),
315 sUsed( rSrc.sUsed ),
316 bShortHasParams( rSrc.bShortHasParams ),
317 pProxy( NULL ),
318 sOverride( rSrc.sOverride )
256{ 319{
320 if( rSrc.pProxy )
321 pProxy = rSrc.pProxy->clone();
257} 322}
258 323
259Bu::OptParser::Option::~Option() 324Bu::OptParser::Option::~Option()
260{ 325{
326 delete pProxy;
327 pProxy = NULL;
261} 328}
262 329