git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@2108 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
54 lines
1.4 KiB
C++
54 lines
1.4 KiB
C++
#ifndef __OPTIONSPARSER_EXT_HPP__
|
|
#define __OPTIONSPARSER_EXT_HPP__
|
|
|
|
|
|
struct Arg: public option::Arg
|
|
{
|
|
static void printError(const char* msg1, const option::Option& opt, const char* msg2)
|
|
{
|
|
fprintf(stderr, "%s", msg1);
|
|
fwrite(opt.name, opt.namelen, 1, stderr);
|
|
fprintf(stderr, "%s", msg2);
|
|
}
|
|
|
|
static option::ArgStatus Unknown(const option::Option& option, bool msg)
|
|
{
|
|
if (msg) printError("Unknown option '", option, "'\n");
|
|
return option::ARG_ILLEGAL;
|
|
}
|
|
|
|
static option::ArgStatus Required(const option::Option& option, bool msg)
|
|
{
|
|
if (option.arg != 0)
|
|
return option::ARG_OK;
|
|
|
|
if (msg) printError("Option '", option, "' requires an argument\n");
|
|
return option::ARG_ILLEGAL;
|
|
}
|
|
|
|
static option::ArgStatus NonEmpty(const option::Option& option, bool msg)
|
|
{
|
|
if (option.arg != 0 && option.arg[0] != 0)
|
|
return option::ARG_OK;
|
|
|
|
if (msg) printError("Option '", option, "' requires a non-empty argument\n");
|
|
return option::ARG_ILLEGAL;
|
|
}
|
|
|
|
static option::ArgStatus Numeric(const option::Option& option, bool msg)
|
|
{
|
|
char* endptr = 0;
|
|
if (option.arg != 0 && strtol(option.arg, &endptr, 10)){};
|
|
if (endptr != option.arg && *endptr == 0)
|
|
return option::ARG_OK;
|
|
|
|
if (msg) printError("Option '", option, "' requires a numeric argument\n");
|
|
return option::ARG_ILLEGAL;
|
|
}
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // __OPTIONSPARSER_EXT_HPP__
|