diff options
Diffstat (limited to '')
-rw-r--r-- | src/paramproc.cpp | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/src/paramproc.cpp b/src/paramproc.cpp index a352e66..34e973e 100644 --- a/src/paramproc.cpp +++ b/src/paramproc.cpp | |||
@@ -2,10 +2,10 @@ | |||
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | 3 | ||
4 | #define ptrtype( iitype, iiname ) \ | 4 | #define ptrtype( iitype, iiname ) \ |
5 | ParamProc::ParamPtr::ParamPtr( iitype *iiname ) : \ | 5 | Bu::ParamProc::ParamPtr::ParamPtr( iitype *iiname ) : \ |
6 | type( vt ##iiname ) { val.iiname = iiname; } | 6 | type( vt ##iiname ) { val.iiname = iiname; } |
7 | 7 | ||
8 | ParamProc::ParamPtr::ParamPtr() | 8 | Bu::ParamProc::ParamPtr::ParamPtr() |
9 | { | 9 | { |
10 | val.str = NULL; | 10 | val.str = NULL; |
11 | type = vtunset; | 11 | type = vtunset; |
@@ -25,7 +25,7 @@ ptrtype( double, float64 ); | |||
25 | ptrtype( long double, float96 ); | 25 | ptrtype( long double, float96 ); |
26 | ptrtype( bool, bln ); | 26 | ptrtype( bool, bln ); |
27 | 27 | ||
28 | ParamProc::ParamPtr &ParamProc::ParamPtr::operator=( ParamProc::ParamPtr &ptr ) | 28 | Bu::ParamProc::ParamPtr &Bu::ParamProc::ParamPtr::operator=( ParamProc::ParamPtr &ptr ) |
29 | { | 29 | { |
30 | val = ptr.val; | 30 | val = ptr.val; |
31 | type = ptr.type; | 31 | type = ptr.type; |
@@ -33,12 +33,12 @@ ParamProc::ParamPtr &ParamProc::ParamPtr::operator=( ParamProc::ParamPtr &ptr ) | |||
33 | return *this; | 33 | return *this; |
34 | } | 34 | } |
35 | 35 | ||
36 | bool ParamProc::ParamPtr::isSet() | 36 | bool Bu::ParamProc::ParamPtr::isSet() |
37 | { | 37 | { |
38 | return type != vtunset; | 38 | return type != vtunset; |
39 | } | 39 | } |
40 | 40 | ||
41 | ParamProc::ParamPtr &ParamProc::ParamPtr::operator=( const char *str ) | 41 | Bu::ParamProc::ParamPtr &Bu::ParamProc::ParamPtr::operator=( const char *str ) |
42 | { | 42 | { |
43 | if( !isSet() ) return *this; | 43 | if( !isSet() ) return *this; |
44 | switch( type ) | 44 | switch( type ) |
@@ -107,11 +107,11 @@ ParamProc::ParamPtr &ParamProc::ParamPtr::operator=( const char *str ) | |||
107 | return *this; | 107 | return *this; |
108 | } | 108 | } |
109 | 109 | ||
110 | ParamProc::ParamProc() | 110 | Bu::ParamProc::ParamProc() |
111 | { | 111 | { |
112 | } | 112 | } |
113 | 113 | ||
114 | ParamProc::~ParamProc() | 114 | Bu::ParamProc::~ParamProc() |
115 | { | 115 | { |
116 | for( std::list<ArgSpec *>::iterator i = lArg.begin(); | 116 | for( std::list<ArgSpec *>::iterator i = lArg.begin(); |
117 | i != lArg.end(); i++ ) | 117 | i != lArg.end(); i++ ) |
@@ -127,14 +127,14 @@ ParamProc::~ParamProc() | |||
127 | 127 | ||
128 | } | 128 | } |
129 | /* | 129 | /* |
130 | void ParamProc::addParam( const char *lpWord, char cChar, Proc proc, ParamPtr val ) | 130 | void Bu::ParamProc::addParam( const char *lpWord, char cChar, Proc proc, ParamPtr val ) |
131 | { | 131 | { |
132 | printf("Calling callback...\n"); | 132 | printf("Calling callback...\n"); |
133 | val = "Hello there, this is set in the ParamProc"; | 133 | val = "Hello there, this is set in the ParamProc"; |
134 | (this->*proc)(); | 134 | (this->*proc)(); |
135 | }*/ | 135 | }*/ |
136 | 136 | ||
137 | void ParamProc::addParam( const char *lpWord, char cChar, Proc proc, | 137 | void Bu::ParamProc::addParam( const char *lpWord, char cChar, Proc proc, |
138 | ParamPtr val, const char *lpDesc, const char *lpExtra, | 138 | ParamPtr val, const char *lpDesc, const char *lpExtra, |
139 | const char *lpValue ) | 139 | const char *lpValue ) |
140 | { | 140 | { |
@@ -161,63 +161,63 @@ void ParamProc::addParam( const char *lpWord, char cChar, Proc proc, | |||
161 | } | 161 | } |
162 | } | 162 | } |
163 | 163 | ||
164 | void ParamProc::addParam( const char *lpWord, char cChar, Proc proc, | 164 | void Bu::ParamProc::addParam( const char *lpWord, char cChar, Proc proc, |
165 | const char *lpDesc, const char *lpExtra, | 165 | const char *lpDesc, const char *lpExtra, |
166 | const char *lpValue ) | 166 | const char *lpValue ) |
167 | { | 167 | { |
168 | addParam( lpWord, cChar, proc, ParamPtr(), lpDesc, lpExtra, lpValue ); | 168 | addParam( lpWord, cChar, proc, ParamPtr(), lpDesc, lpExtra, lpValue ); |
169 | } | 169 | } |
170 | 170 | ||
171 | void ParamProc::addParam( const char *lpWord, char cChar, ParamPtr val, | 171 | void Bu::ParamProc::addParam( const char *lpWord, char cChar, ParamPtr val, |
172 | const char *lpDesc, const char *lpExtra, | 172 | const char *lpDesc, const char *lpExtra, |
173 | const char *lpValue ) | 173 | const char *lpValue ) |
174 | { | 174 | { |
175 | addParam( lpWord, cChar, NULL, val, lpDesc, lpExtra, lpValue ); | 175 | addParam( lpWord, cChar, NULL, val, lpDesc, lpExtra, lpValue ); |
176 | } | 176 | } |
177 | 177 | ||
178 | void ParamProc::addParam( const char *lpWord, Proc proc, ParamPtr val, | 178 | void Bu::ParamProc::addParam( const char *lpWord, Proc proc, ParamPtr val, |
179 | const char *lpDesc, const char *lpExtra, | 179 | const char *lpDesc, const char *lpExtra, |
180 | const char *lpValue ) | 180 | const char *lpValue ) |
181 | { | 181 | { |
182 | addParam( lpWord, '\0', proc, val, lpDesc, lpExtra, lpValue ); | 182 | addParam( lpWord, '\0', proc, val, lpDesc, lpExtra, lpValue ); |
183 | } | 183 | } |
184 | 184 | ||
185 | void ParamProc::addParam( const char *lpWord, Proc proc, | 185 | void Bu::ParamProc::addParam( const char *lpWord, Proc proc, |
186 | const char *lpDesc, const char *lpExtra, | 186 | const char *lpDesc, const char *lpExtra, |
187 | const char *lpValue ) | 187 | const char *lpValue ) |
188 | { | 188 | { |
189 | addParam( lpWord, '\0', proc, ParamPtr(), lpDesc, lpExtra, lpValue ); | 189 | addParam( lpWord, '\0', proc, ParamPtr(), lpDesc, lpExtra, lpValue ); |
190 | } | 190 | } |
191 | 191 | ||
192 | void ParamProc::addParam( const char *lpWord, ParamPtr val, | 192 | void Bu::ParamProc::addParam( const char *lpWord, ParamPtr val, |
193 | const char *lpDesc, const char *lpExtra, | 193 | const char *lpDesc, const char *lpExtra, |
194 | const char *lpValue ) | 194 | const char *lpValue ) |
195 | { | 195 | { |
196 | addParam( lpWord, '\0', NULL, val, lpDesc, lpExtra, lpValue ); | 196 | addParam( lpWord, '\0', NULL, val, lpDesc, lpExtra, lpValue ); |
197 | } | 197 | } |
198 | 198 | ||
199 | void ParamProc::addParam( char cChar, Proc proc, ParamPtr val, | 199 | void Bu::ParamProc::addParam( char cChar, Proc proc, ParamPtr val, |
200 | const char *lpDesc, const char *lpExtra, | 200 | const char *lpDesc, const char *lpExtra, |
201 | const char *lpValue ) | 201 | const char *lpValue ) |
202 | { | 202 | { |
203 | addParam( NULL, cChar, proc, val, lpDesc, lpExtra, lpValue ); | 203 | addParam( NULL, cChar, proc, val, lpDesc, lpExtra, lpValue ); |
204 | } | 204 | } |
205 | 205 | ||
206 | void ParamProc::addParam( char cChar, Proc proc, | 206 | void Bu::ParamProc::addParam( char cChar, Proc proc, |
207 | const char *lpDesc, const char *lpExtra, | 207 | const char *lpDesc, const char *lpExtra, |
208 | const char *lpValue ) | 208 | const char *lpValue ) |
209 | { | 209 | { |
210 | addParam( NULL, cChar, proc, ParamPtr(), lpDesc, lpExtra, lpValue ); | 210 | addParam( NULL, cChar, proc, ParamPtr(), lpDesc, lpExtra, lpValue ); |
211 | } | 211 | } |
212 | 212 | ||
213 | void ParamProc::addParam( char cChar, ParamPtr val, | 213 | void Bu::ParamProc::addParam( char cChar, ParamPtr val, |
214 | const char *lpDesc, const char *lpExtra, | 214 | const char *lpDesc, const char *lpExtra, |
215 | const char *lpValue ) | 215 | const char *lpValue ) |
216 | { | 216 | { |
217 | addParam( NULL, cChar, NULL, val, lpDesc, lpExtra, lpValue ); | 217 | addParam( NULL, cChar, NULL, val, lpDesc, lpExtra, lpValue ); |
218 | } | 218 | } |
219 | 219 | ||
220 | void ParamProc::process( int argc, char *argv[] ) | 220 | void Bu::ParamProc::process( int argc, char *argv[] ) |
221 | { | 221 | { |
222 | for( int arg = 1; arg < argc; arg++ ) | 222 | for( int arg = 1; arg < argc; arg++ ) |
223 | { | 223 | { |
@@ -229,23 +229,23 @@ void ParamProc::process( int argc, char *argv[] ) | |||
229 | ArgSpec *s = checkWord( argv[arg]+2 ); | 229 | ArgSpec *s = checkWord( argv[arg]+2 ); |
230 | if( s ) | 230 | if( s ) |
231 | { | 231 | { |
232 | if( argv[arg][s->sWord.getLength()+2] == '=' ) | 232 | if( argv[arg][s->sWord.getSize()+2] == '=' ) |
233 | { | 233 | { |
234 | if( s->val.isSet() ) | 234 | if( s->val.isSet() ) |
235 | { | 235 | { |
236 | if( s->sValue.getString() == NULL ) | 236 | if( s->sValue.getStr() == NULL ) |
237 | { | 237 | { |
238 | s->val = argv[arg]+s->sWord.getLength()+3; | 238 | s->val = argv[arg]+s->sWord.getSize()+3; |
239 | } | 239 | } |
240 | else | 240 | else |
241 | { | 241 | { |
242 | s->val = s->sValue.getString(); | 242 | s->val = s->sValue.getStr(); |
243 | } | 243 | } |
244 | } | 244 | } |
245 | if( s->proc ) | 245 | if( s->proc ) |
246 | { | 246 | { |
247 | char **tmp = new char*[argc-arg]; | 247 | char **tmp = new char*[argc-arg]; |
248 | tmp[0] = argv[arg]+s->sWord.getLength()+3; | 248 | tmp[0] = argv[arg]+s->sWord.getSize()+3; |
249 | for( int k = 1; k < argc-arg; k++ ) | 249 | for( int k = 1; k < argc-arg; k++ ) |
250 | tmp[k] = argv[arg+k]; | 250 | tmp[k] = argv[arg+k]; |
251 | int ret = (this->*s->proc)( argc-arg, tmp ); | 251 | int ret = (this->*s->proc)( argc-arg, tmp ); |
@@ -261,7 +261,7 @@ void ParamProc::process( int argc, char *argv[] ) | |||
261 | int add = 0; | 261 | int add = 0; |
262 | if( s->val.isSet() ) | 262 | if( s->val.isSet() ) |
263 | { | 263 | { |
264 | if( s->sValue.getString() == NULL ) | 264 | if( s->sValue.getStr() == NULL ) |
265 | { | 265 | { |
266 | if( arg+1 >= argc ) | 266 | if( arg+1 >= argc ) |
267 | { | 267 | { |
@@ -272,7 +272,7 @@ void ParamProc::process( int argc, char *argv[] ) | |||
272 | } | 272 | } |
273 | else | 273 | else |
274 | { | 274 | { |
275 | s->val = s->sValue.getString(); | 275 | s->val = s->sValue.getStr(); |
276 | } | 276 | } |
277 | } | 277 | } |
278 | if( s->proc ) | 278 | if( s->proc ) |
@@ -307,14 +307,14 @@ void ParamProc::process( int argc, char *argv[] ) | |||
307 | bool bUsed = false; | 307 | bool bUsed = false; |
308 | if( s->val.isSet() ) | 308 | if( s->val.isSet() ) |
309 | { | 309 | { |
310 | if( s->sValue.getString() == NULL ) | 310 | if( s->sValue.getStr() == NULL ) |
311 | { | 311 | { |
312 | s->val = argv[arg]+chr+1; | 312 | s->val = argv[arg]+chr+1; |
313 | bUsed = true; | 313 | bUsed = true; |
314 | } | 314 | } |
315 | else | 315 | else |
316 | { | 316 | { |
317 | s->val = s->sValue.getString(); | 317 | s->val = s->sValue.getStr(); |
318 | } | 318 | } |
319 | } | 319 | } |
320 | if( s->proc ) | 320 | if( s->proc ) |
@@ -342,14 +342,14 @@ void ParamProc::process( int argc, char *argv[] ) | |||
342 | bool bUsed = false; | 342 | bool bUsed = false; |
343 | if( s->val.isSet() ) | 343 | if( s->val.isSet() ) |
344 | { | 344 | { |
345 | if( s->sValue.getString() == NULL ) | 345 | if( s->sValue.getStr() == NULL ) |
346 | { | 346 | { |
347 | s->val = argv[arg+1]; | 347 | s->val = argv[arg+1]; |
348 | bUsed = true; | 348 | bUsed = true; |
349 | } | 349 | } |
350 | else | 350 | else |
351 | { | 351 | { |
352 | s->val = s->sValue.getString(); | 352 | s->val = s->sValue.getStr(); |
353 | } | 353 | } |
354 | } | 354 | } |
355 | if( s->proc ) | 355 | if( s->proc ) |
@@ -384,22 +384,22 @@ void ParamProc::process( int argc, char *argv[] ) | |||
384 | } | 384 | } |
385 | } | 385 | } |
386 | 386 | ||
387 | ParamProc::ArgSpec *ParamProc::checkWord( const char *arg ) | 387 | Bu::ParamProc::ArgSpec *Bu::ParamProc::checkWord( const char *arg ) |
388 | { | 388 | { |
389 | //printf("Checking \"%s\"...\n", arg ); | 389 | //printf("Checking \"%s\"...\n", arg ); |
390 | std::list<ArgSpec *>::const_iterator i; | 390 | std::list<ArgSpec *>::const_iterator i; |
391 | for( i = lArg.begin(); i != lArg.end(); i++ ) | 391 | for( i = lArg.begin(); i != lArg.end(); i++ ) |
392 | { | 392 | { |
393 | if( (*i)->sWord.getString() == NULL ) | 393 | if( (*i)->sWord.getStr() == NULL ) |
394 | continue; | 394 | continue; |
395 | 395 | ||
396 | if( !strcmp( (*i)->sWord, arg ) ) | 396 | if( !strcmp( (*i)->sWord.getStr(), arg ) ) |
397 | return *i; | 397 | return *i; |
398 | 398 | ||
399 | if( (*i)->val.isSet() ) | 399 | if( (*i)->val.isSet() ) |
400 | { | 400 | { |
401 | if( !strncmp( (*i)->sWord, arg, (*i)->sWord.getLength() ) && | 401 | if( !strncmp( (*i)->sWord.getStr(), arg, (*i)->sWord.getSize() ) && |
402 | arg[(*i)->sWord.getLength()] == '=' ) | 402 | arg[(*i)->sWord.getSize()] == '=' ) |
403 | { | 403 | { |
404 | return *i; | 404 | return *i; |
405 | } | 405 | } |
@@ -409,7 +409,7 @@ ParamProc::ArgSpec *ParamProc::checkWord( const char *arg ) | |||
409 | return NULL; | 409 | return NULL; |
410 | } | 410 | } |
411 | 411 | ||
412 | ParamProc::ArgSpec *ParamProc::checkLetr( const char arg ) | 412 | Bu::ParamProc::ArgSpec *Bu::ParamProc::checkLetr( const char arg ) |
413 | { | 413 | { |
414 | //printf("Checking \'%c\'...\n", arg ); | 414 | //printf("Checking \'%c\'...\n", arg ); |
415 | std::list<ArgSpec *>::const_iterator i; | 415 | std::list<ArgSpec *>::const_iterator i; |
@@ -427,27 +427,27 @@ ParamProc::ArgSpec *ParamProc::checkLetr( const char arg ) | |||
427 | return NULL; | 427 | return NULL; |
428 | } | 428 | } |
429 | 429 | ||
430 | int ParamProc::cmdParam( int argc, char *argv[] ) | 430 | int Bu::ParamProc::cmdParam( int argc, char *argv[] ) |
431 | { | 431 | { |
432 | printf("Unhandled command parameter \"%s\" found!\n", argv[0] ); | 432 | printf("Unhandled command parameter \"%s\" found!\n", argv[0] ); |
433 | return 0; | 433 | return 0; |
434 | } | 434 | } |
435 | 435 | ||
436 | int ParamProc::unknownParam( int argc, char *argv[] ) | 436 | int Bu::ParamProc::unknownParam( int argc, char *argv[] ) |
437 | { | 437 | { |
438 | printf("Unknown parameter \"%s\" found!\n", argv[0] ); | 438 | printf("Unknown parameter \"%s\" found!\n", argv[0] ); |
439 | return 0; | 439 | return 0; |
440 | } | 440 | } |
441 | 441 | ||
442 | int ParamProc::help( int argc, char *argv[] ) | 442 | int Bu::ParamProc::help( int argc, char *argv[] ) |
443 | { | 443 | { |
444 | std::list<Banner *>::const_iterator b = lBan.begin(); | 444 | std::list<Banner *>::const_iterator b = lBan.begin(); |
445 | std::list<ArgSpec *>::const_iterator i; | 445 | std::list<ArgSpec *>::const_iterator i; |
446 | int len=0; | 446 | int len=0; |
447 | for( i = lArg.begin(); i != lArg.end(); i++ ) | 447 | for( i = lArg.begin(); i != lArg.end(); i++ ) |
448 | { | 448 | { |
449 | if( len < (*i)->sWord.getLength() + (*i)->sExtra.getLength() ) | 449 | if( len < (*i)->sWord.getSize() + (*i)->sExtra.getSize() ) |
450 | len = (*i)->sWord.getLength() + (*i)->sExtra.getLength(); | 450 | len = (*i)->sWord.getSize() + (*i)->sExtra.getSize(); |
451 | } | 451 | } |
452 | char fmt[10]; | 452 | char fmt[10]; |
453 | sprintf( fmt, "%%-%ds ", len ); | 453 | sprintf( fmt, "%%-%ds ", len ); |
@@ -458,14 +458,14 @@ int ParamProc::help( int argc, char *argv[] ) | |||
458 | { | 458 | { |
459 | if( (*b)->pBefore == (*i) ) | 459 | if( (*b)->pBefore == (*i) ) |
460 | { | 460 | { |
461 | printf( (*b)->sBanner.getString() ); | 461 | printf( (*b)->sBanner.getStr() ); |
462 | b++; | 462 | b++; |
463 | } | 463 | } |
464 | } | 464 | } |
465 | printf(" "); | 465 | printf(" "); |
466 | if( (*i)->cChar ) | 466 | if( (*i)->cChar ) |
467 | { | 467 | { |
468 | if( (*i)->sWord.getString() ) | 468 | if( (*i)->sWord.getStr() ) |
469 | { | 469 | { |
470 | printf("-%c, ", (*i)->cChar ); | 470 | printf("-%c, ", (*i)->cChar ); |
471 | } | 471 | } |
@@ -478,12 +478,12 @@ int ParamProc::help( int argc, char *argv[] ) | |||
478 | { | 478 | { |
479 | printf(" "); | 479 | printf(" "); |
480 | } | 480 | } |
481 | if( (*i)->sWord.getString() ) | 481 | if( (*i)->sWord.getStr() ) |
482 | { | 482 | { |
483 | printf("--"); | 483 | printf("--"); |
484 | std::string sTmp = (*i)->sWord.getString(); | 484 | std::string sTmp = (*i)->sWord.getStr(); |
485 | if( (*i)->sExtra.getString() ) | 485 | if( (*i)->sExtra.getStr() ) |
486 | sTmp += (*i)->sExtra.getString(); | 486 | sTmp += (*i)->sExtra.getStr(); |
487 | printf( fmt, sTmp.c_str() ); | 487 | printf( fmt, sTmp.c_str() ); |
488 | } | 488 | } |
489 | else | 489 | else |
@@ -491,20 +491,20 @@ int ParamProc::help( int argc, char *argv[] ) | |||
491 | printf(" "); | 491 | printf(" "); |
492 | printf(fmt, "" ); | 492 | printf(fmt, "" ); |
493 | } | 493 | } |
494 | printf("%s\n", (*i)->sDesc.getString() ); | 494 | printf("%s\n", (*i)->sDesc.getStr() ); |
495 | } | 495 | } |
496 | if( b != lBan.end() ) | 496 | if( b != lBan.end() ) |
497 | { | 497 | { |
498 | if( (*b)->pBefore == NULL ) | 498 | if( (*b)->pBefore == NULL ) |
499 | { | 499 | { |
500 | printf( (*b)->sBanner.getString() ); | 500 | printf( (*b)->sBanner.getStr() ); |
501 | } | 501 | } |
502 | } | 502 | } |
503 | 503 | ||
504 | exit( 0 ); | 504 | exit( 0 ); |
505 | } | 505 | } |
506 | 506 | ||
507 | void ParamProc::addHelpBanner( const char *sHelpBanner ) | 507 | void Bu::ParamProc::addHelpBanner( const char *sHelpBanner ) |
508 | { | 508 | { |
509 | Banner *pBan = new Banner; | 509 | Banner *pBan = new Banner; |
510 | pBan->sBanner = sHelpBanner; | 510 | pBan->sBanner = sHelpBanner; |