本文整理汇总了C++中COptions::parseArguments方法的典型用法代码示例。如果您正苦于以下问题:C++ COptions::parseArguments方法的具体用法?C++ COptions::parseArguments怎么用?C++ COptions::parseArguments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类COptions
的用法示例。
在下文中一共展示了COptions::parseArguments方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//--------------------------------------------------------------------------------
int main(int argc, const char * argv[])
{
// We handle options early because the later code may
// depend on them (-verbose, -testing, -help, --file)
SFString cmdFile=EMPTY;
for (int i=0;i<argc;i++)
{
SFString arg = argv[i];
if (arg.startsWith("--file:"))
{
cmdFile = arg.Substitute("--file:",EMPTY);
cmdFile.Replace("~/",getHomeFolder());
if (!SFos::fileExists(cmdFile))
return usage("--file: '" + cmdFile + "' not found. Quitting.");
} else if (arg == "-h" || arg == "-help" || arg == "--help")
{
return usage();
} else if (arg.startsWith("-v") || arg.startsWith("-verbose"))
{
verbose = TRUE;
arg.Replace("-verbose",EMPTY);
arg.Replace("-v", EMPTY);
arg.Replace(":", EMPTY);
if (!arg.IsEmpty())
verbose = toLong(arg);
} else if (arg=="-t" || arg=="-test" || arg=="-titles")
{
// During testing, we send all output (including error messages)
// to the screen so it can be re-directed to a file
outErr = outScreen;
isTesting = TRUE;
}
}
// If we have a command file, we will use it, if not we will create
// one and pretend we had one. This makes the processing code easier.
SFString commandList;
if (cmdFile.IsEmpty())
{
for (int i=1;i<argc;i++) // we know the program's name
commandList += (SFString(argv[i]) + " ");
commandList += '\n';
} else
{
commandList = asciiFileToString(cmdFile).Substitute("\t", " ").Substitute(" ", " ");
}
// We keep only a single slurper. If the user is using the --file option and they
// are reading the same account repeatedly, we only need to read the cache once.
CSlurperApp slurper;
// For each command we first parse the options (expanding them if neceassary), then setup
// the sluper, then read from either cache or the blockchain, then display the results.
while (!commandList.IsEmpty())
{
SFString command = StripAny(nextTokenClear(commandList, '\n'),"\t\r\n ");
if (!command.IsEmpty() && !command.startsWith(";")) // ignore comments
{
outErr << "Processing: " << command << "\n";
SFInt32 nArgs=0;
SFString args[40]; // safe enough
while (!command.IsEmpty())
{
SFString arg = nextTokenClear(command, ' ');
while (!arg.IsEmpty())
args[nArgs++] = expandOption(arg); // handles case of -rf for example
}
SFString message;
// Parse the command line
COptions options; options.cmdFile=!cmdFile.IsEmpty();
if (!options.parseArguments(nArgs, args))
return FALSE;
// Setup the slurper
if (!slurper.Initialize(options, message))
return usage(message);
// Slurp the address...
if (!slurper.Slurp(options, message))
return usage(message);
// Apply the filters if any...
if (!slurper.Filter(options, message))
return usage(message);
// Report on the address...
if (!slurper.Display(options, message))
return usage(message);
}
}
return FALSE;
}