|
|
| typedef struct -- | -- |
#include <uvgetprogargs.h>
This Class provides program argument utilities.
This class provides programs with a well organized data structure which contains the arguments given to the program in an array form.
The array size is 0x100, which means, that 256 argument pairs ars possible. Each entry constist of an option (string) and an argument string, which are both dynamically allocated ( size is strlen(argv[x]) + 1 ).
The variable argcnt contains the amount of argument pairs, which are stored in the array.
If either the option entry or the argument entry is empty, a 0 lenght string is used.
Entry beyond argcnt are Null-pointers.
The following paragraph shows the structure definitions and the variable definition
#define UVMAXOPT 0x100
typedef struct
{
char *option, *argument;
} opt;
int argcnt;
opt cont[UVMAXOPT];
int maxargs;
|
Here comes the example of the usage of uvProgArgs.
popts = new uvProgArgs( argc, argv );
if ( !popts )
{
qwdebug->doDebug( 0, "%s[%d]getArgums : could not allocate popts \n",
__FILE__, __LINE__ );
prArgums();
doQuit( 5 );
}
for ( i = 0; i < popts->argcnt; i++ )
{
// adjust timer
if ( strcmp( popts->cont[i].option, "-t") == 0 )
{
sleeptime = (unsigned long)atol( popts->cont[i].argument ) * 1000L;
if ( sleeptime < 10000 )
sleeptime = 10000;
}
// PID Mode ( check out running process )
else if ( strcmp( popts->cont[i].option, "-p") == 0 )
{
pidmode = 1;
progpid = atoi( popts->cont[i].argument );
}
// File Mode ( results into file instead of stdout )
else if ( strcmp( popts->cont[i].option, "-f") == 0 )
{
filemode = 1;
filename = (char *) malloc ( strlen( popts->cont[i].argument ) + 1);
memset(filename, 0, strlen( popts->cont[i].argument ) + 1);
sprintf( filename, "%s", popts->cont[i].argument );
}
// Output Mode ( OutputFormat )
else if ( strcmp( popts->cont[i].option, "-m") == 0 )
{
outform = (char *) malloc ( strlen( popts->cont[i].argument ) + 1);
memset( outform, 0, strlen( popts->cont[i].argument ) + 1);
sprintf( outform, "%s", popts->cont[i].argument );
}
// difference Mode
else if ( strcmp( popts->cont[i].option, "-d") == 0 )
{
diffmode = atoi( popts->cont[i].argument );
}
}
|
| Generated by: sc on schomep4 on Sun Nov 23 16:54:46 2003, using kdoc 2.0a54. |