1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
CMDOptions::CMDOptions(int argc, char **argv)
: isForeground(false)
{
this->parseCommandLineArguments(argc, argv);
};
void CMDOptions::parseCommandLineArguments(int argc, char **argv)
{
int character = 0;
int option_index = 0;
int verbose_flag = 0;
struct option longopt[] = {
/* These options set a flag. */
{"verbose", no_argument, &verbose_flag, 1},
/**
** These options don't set a flag.
** We distinguish them by their indices.
**/
{"add", no_argument, 0, 'a'},
{"append", no_argument, 0, 'b'},
{"delete", required_argument, 0, 'd'},
{"create", required_argument, 0, 'c'},
{"foreground", no_argument, 0, 'f'},
{0, 0, 0, 0}
};
while((character = getopt_long(argc, argv, "abcfd", longopt, &option_index)) != -1){
switch(character){
case 'f':
this->setForeground();
break;
}
}
};
void CMDOptions::setForeground()
{
this->isForeground = true;
}
bool CMDOptions::isForegroundSet()
{
return this->isForeground;
};
|