diff options
Diffstat (limited to 'src/paramproc.cpp')
-rw-r--r-- | src/paramproc.cpp | 82 |
1 files changed, 78 insertions, 4 deletions
diff --git a/src/paramproc.cpp b/src/paramproc.cpp index eaaf466..85274e2 100644 --- a/src/paramproc.cpp +++ b/src/paramproc.cpp | |||
@@ -141,6 +141,12 @@ void ParamProc::addParam( const char *lpWord, char cChar, Proc proc, | |||
141 | as->sValue = lpValue; | 141 | as->sValue = lpValue; |
142 | 142 | ||
143 | lArg.push_back( as ); | 143 | lArg.push_back( as ); |
144 | |||
145 | if( !lBan.empty() ) | ||
146 | { | ||
147 | if( lBan.back()->pBefore == NULL ) | ||
148 | lBan.back()->pBefore = as; | ||
149 | } | ||
144 | } | 150 | } |
145 | 151 | ||
146 | void ParamProc::addParam( const char *lpWord, char cChar, Proc proc, | 152 | void ParamProc::addParam( const char *lpWord, char cChar, Proc proc, |
@@ -203,7 +209,7 @@ void ParamProc::process( int argc, char *argv[] ) | |||
203 | { | 209 | { |
204 | for( int arg = 1; arg < argc; arg++ ) | 210 | for( int arg = 1; arg < argc; arg++ ) |
205 | { | 211 | { |
206 | printf(":::%d:::%s\n", arg, argv[arg] ); | 212 | //printf(":::%d:::%s\n", arg, argv[arg] ); |
207 | if( argv[arg][0] == '-' ) | 213 | if( argv[arg][0] == '-' ) |
208 | { | 214 | { |
209 | if( argv[arg][1] == '-' ) | 215 | if( argv[arg][1] == '-' ) |
@@ -270,6 +276,10 @@ void ParamProc::process( int argc, char *argv[] ) | |||
270 | } | 276 | } |
271 | continue; | 277 | continue; |
272 | } | 278 | } |
279 | else | ||
280 | { | ||
281 | unknownParam( argc-arg, argv+arg ); | ||
282 | } | ||
273 | } | 283 | } |
274 | else | 284 | else |
275 | { | 285 | { |
@@ -347,15 +357,23 @@ void ParamProc::process( int argc, char *argv[] ) | |||
347 | } | 357 | } |
348 | } | 358 | } |
349 | } | 359 | } |
360 | else | ||
361 | { | ||
362 | unknownParam( argc-arg, argv+arg ); | ||
363 | } | ||
350 | } | 364 | } |
351 | } | 365 | } |
352 | } | 366 | } |
367 | else | ||
368 | { | ||
369 | cmdParam( argc-arg, argv+arg ); | ||
370 | } | ||
353 | } | 371 | } |
354 | } | 372 | } |
355 | 373 | ||
356 | ParamProc::ArgSpec *ParamProc::checkWord( const char *arg ) | 374 | ParamProc::ArgSpec *ParamProc::checkWord( const char *arg ) |
357 | { | 375 | { |
358 | printf("Checking \"%s\"...\n", arg ); | 376 | //printf("Checking \"%s\"...\n", arg ); |
359 | std::list<ArgSpec *>::const_iterator i; | 377 | std::list<ArgSpec *>::const_iterator i; |
360 | for( i = lArg.begin(); i != lArg.end(); i++ ) | 378 | for( i = lArg.begin(); i != lArg.end(); i++ ) |
361 | { | 379 | { |
@@ -380,7 +398,7 @@ ParamProc::ArgSpec *ParamProc::checkWord( const char *arg ) | |||
380 | 398 | ||
381 | ParamProc::ArgSpec *ParamProc::checkLetr( const char arg ) | 399 | ParamProc::ArgSpec *ParamProc::checkLetr( const char arg ) |
382 | { | 400 | { |
383 | printf("Checking \'%c\'...\n", arg ); | 401 | //printf("Checking \'%c\'...\n", arg ); |
384 | std::list<ArgSpec *>::const_iterator i; | 402 | std::list<ArgSpec *>::const_iterator i; |
385 | for( i = lArg.begin(); i != lArg.end(); i++ ) | 403 | for( i = lArg.begin(); i != lArg.end(); i++ ) |
386 | { | 404 | { |
@@ -408,6 +426,62 @@ int ParamProc::unknownParam( int argc, char *argv[] ) | |||
408 | 426 | ||
409 | int ParamProc::help( int argc, char *argv[] ) | 427 | int ParamProc::help( int argc, char *argv[] ) |
410 | { | 428 | { |
411 | // Insert help here later on | 429 | std::list<Banner *>::const_iterator b = lBan.begin(); |
430 | std::list<ArgSpec *>::const_iterator i; | ||
431 | int len=0; | ||
432 | for( i = lArg.begin(); i != lArg.end(); i++ ) | ||
433 | { | ||
434 | if( len < (*i)->sWord.getLength() ) | ||
435 | len = (*i)->sWord.getLength(); | ||
436 | } | ||
437 | char fmt[10]; | ||
438 | sprintf( fmt, "%%-%ds ", len ); | ||
439 | |||
440 | for( i = lArg.begin(); i != lArg.end(); i++ ) | ||
441 | { | ||
442 | if( b != lBan.end() ) | ||
443 | { | ||
444 | if( (*b)->pBefore == (*i) ) | ||
445 | { | ||
446 | printf( (*b)->sBanner.getString() ); | ||
447 | b++; | ||
448 | } | ||
449 | } | ||
450 | printf(" "); | ||
451 | if( (*i)->cChar ) | ||
452 | { | ||
453 | printf("-%c, ", (*i)->cChar ); | ||
454 | } | ||
455 | else | ||
456 | { | ||
457 | printf(" "); | ||
458 | } | ||
459 | if( (*i)->sWord.getString() ) | ||
460 | { | ||
461 | printf("--"); | ||
462 | printf( fmt, (*i)->sWord.getString() ); | ||
463 | } | ||
464 | else | ||
465 | { | ||
466 | printf(" "); | ||
467 | printf(fmt, "" ); | ||
468 | } | ||
469 | printf("%s\n", (*i)->sDesc.getString() ); | ||
470 | } | ||
471 | if( b != lBan.end() ) | ||
472 | { | ||
473 | if( (*b)->pBefore == NULL ) | ||
474 | { | ||
475 | printf( (*b)->sBanner.getString() ); | ||
476 | } | ||
477 | } | ||
478 | } | ||
479 | |||
480 | void ParamProc::addHelpBanner( const char *sHelpBanner ) | ||
481 | { | ||
482 | Banner *pBan = new Banner; | ||
483 | pBan->sBanner = sHelpBanner; | ||
484 | pBan->pBefore = NULL; | ||
485 | lBan.push_back( pBan ); | ||
412 | } | 486 | } |
413 | 487 | ||