aboutsummaryrefslogtreecommitdiff
path: root/src/old
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/old/paramproc.h153
-rw-r--r--src/paramproc.cpp (renamed from src/old/paramproc.cpp)98
2 files changed, 49 insertions, 202 deletions
diff --git a/src/old/paramproc.h b/src/old/paramproc.h
deleted file mode 100644
index d857193..0000000
--- a/src/old/paramproc.h
+++ /dev/null
@@ -1,153 +0,0 @@
1#ifndef PARAM_PROC_H
2#define PARAM_PROC_H
3
4#include <stdint.h>
5#include <string>
6#include <list>
7#include "staticstring.h"
8
9class ParamProc
10{
11public:
12 class ParamPtr
13 {
14 public:
15 ParamPtr();
16 ParamPtr( std::string *str );
17 ParamPtr( uint64_t *uint64 );
18 ParamPtr( uint32_t *uint32 );
19 ParamPtr( uint16_t *uint16 );
20 ParamPtr( uint8_t *uint8 );
21 ParamPtr( int64_t *int64 );
22 ParamPtr( int32_t *int32 );
23 ParamPtr( int16_t *int16 );
24 ParamPtr( int8_t *int8 );
25 ParamPtr( float *float32 );
26 ParamPtr( double *float64 );
27 ParamPtr( long double *float96 );
28 ParamPtr( bool *bln );
29
30 enum
31 {
32 vtunset,
33 vtstr,
34 vtuint64,
35 vtuint32,
36 vtuint16,
37 vtuint8,
38 vtint64,
39 vtint32,
40 vtint16,
41 vtint8,
42 vtfloat32,
43 vtfloat64,
44 vtfloat96,
45 vtbln,
46 };
47 ParamPtr &operator=( ParamPtr &ptr );
48 ParamPtr &operator=( const char *str );
49
50 bool isSet();
51
52 private:
53 int type;
54 union
55 {
56 std::string *str;
57 uint64_t *uint64;
58 uint32_t *uint32;
59 uint16_t *uint16;
60 uint8_t *uint8;
61 int64_t *int64;
62 int32_t *int32;
63 int16_t *int16;
64 int8_t *int8;
65 float *float32;
66 double *float64;
67 long double *float96;
68 bool *bln;
69 } val;
70 };
71
72 typedef int (ParamProc::*Proc)( int, char *[] );
73
74 typedef struct ArgSpec
75 {
76 uint8_t nFlags;
77 StaticString sWord;
78 char cChar;
79 Proc proc;
80 ParamProc::ParamPtr val;
81 StaticString sExtra;
82 StaticString sDesc;
83 StaticString sValue;
84 } ArgSpec;
85
86public:
87 ParamProc();
88 virtual ~ParamProc();
89
90 void addParam( const char *lpWord, char cChar, Proc proc, ParamPtr val,
91 const char *lpDesc=NULL, const char *lpExtra=NULL,
92 const char *lpValue=NULL
93 );
94 void addParam( const char *lpWord, char cChar, Proc proc,
95 const char *lpDesc=NULL, const char *lpExtra=NULL,
96 const char *lpValue=NULL
97 );
98 void addParam( const char *lpWord, char cChar, ParamPtr val,
99 const char *lpDesc=NULL, const char *lpExtra=NULL,
100 const char *lpValue=NULL
101 );
102
103 void addParam( const char *lpWord, Proc proc, ParamPtr val,
104 const char *lpDesc=NULL, const char *lpExtra=NULL,
105 const char *lpValue=NULL
106 );
107 void addParam( const char *lpWord, Proc proc,
108 const char *lpDesc=NULL, const char *lpExtra=NULL,
109 const char *lpValue=NULL
110 );
111 void addParam( const char *lpWord, ParamPtr val,
112 const char *lpDesc=NULL, const char *lpExtra=NULL,
113 const char *lpValue=NULL
114 );
115
116 void addParam( char cChar, Proc proc, ParamPtr val,
117 const char *lpDesc=NULL, const char *lpExtra=NULL,
118 const char *lpValue=NULL
119 );
120 void addParam( char cChar, Proc proc,
121 const char *lpDesc=NULL, const char *lpExtra=NULL,
122 const char *lpValue=NULL
123 );
124 void addParam( char cChar, ParamPtr val,
125 const char *lpDesc=NULL, const char *lpExtra=NULL,
126 const char *lpValue=NULL
127 );
128
129 void process( int argc, char *argv[] );
130 void addHelpBanner( const char *sHelpBanner );
131
132private:
133 ArgSpec *checkWord( const char *arg );
134 ArgSpec *checkLetr( const char arg );
135
136public:
137 virtual int cmdParam( int argc, char *argv[] );
138 virtual int unknownParam( int argc, char *argv[] );
139 virtual int help( int argc, char *argv[] );
140
141private:
142 typedef struct Banner
143 {
144 StaticString sBanner;
145 ArgSpec *pBefore;
146 } Banner;
147 std::list<Banner *> lBan;
148 std::list<ArgSpec *> lArg;
149};
150
151#define mkproc( cls ) static_cast<int (ParamProc::*)( int, char *[])>(&cls)
152
153#endif
diff --git a/src/old/paramproc.cpp b/src/paramproc.cpp
index a352e66..34e973e 100644
--- a/src/old/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
8ParamProc::ParamPtr::ParamPtr() 8Bu::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 );
25ptrtype( long double, float96 ); 25ptrtype( long double, float96 );
26ptrtype( bool, bln ); 26ptrtype( bool, bln );
27 27
28ParamProc::ParamPtr &ParamProc::ParamPtr::operator=( ParamProc::ParamPtr &ptr ) 28Bu::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
36bool ParamProc::ParamPtr::isSet() 36bool Bu::ParamProc::ParamPtr::isSet()
37{ 37{
38 return type != vtunset; 38 return type != vtunset;
39} 39}
40 40
41ParamProc::ParamPtr &ParamProc::ParamPtr::operator=( const char *str ) 41Bu::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
110ParamProc::ParamProc() 110Bu::ParamProc::ParamProc()
111{ 111{
112} 112}
113 113
114ParamProc::~ParamProc() 114Bu::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/*
130void ParamProc::addParam( const char *lpWord, char cChar, Proc proc, ParamPtr val ) 130void 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
137void ParamProc::addParam( const char *lpWord, char cChar, Proc proc, 137void 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
164void ParamProc::addParam( const char *lpWord, char cChar, Proc proc, 164void 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
171void ParamProc::addParam( const char *lpWord, char cChar, ParamPtr val, 171void 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
178void ParamProc::addParam( const char *lpWord, Proc proc, ParamPtr val, 178void 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
185void ParamProc::addParam( const char *lpWord, Proc proc, 185void 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
192void ParamProc::addParam( const char *lpWord, ParamPtr val, 192void 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
199void ParamProc::addParam( char cChar, Proc proc, ParamPtr val, 199void 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
206void ParamProc::addParam( char cChar, Proc proc, 206void 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
213void ParamProc::addParam( char cChar, ParamPtr val, 213void 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
220void ParamProc::process( int argc, char *argv[] ) 220void 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
387ParamProc::ArgSpec *ParamProc::checkWord( const char *arg ) 387Bu::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
412ParamProc::ArgSpec *ParamProc::checkLetr( const char arg ) 412Bu::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
430int ParamProc::cmdParam( int argc, char *argv[] ) 430int 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
436int ParamProc::unknownParam( int argc, char *argv[] ) 436int 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
442int ParamProc::help( int argc, char *argv[] ) 442int 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
507void ParamProc::addHelpBanner( const char *sHelpBanner ) 507void 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;