ROSE  0.9.9.139
Classes | Functions | Variables
CommandlineProcessing Namespace Reference

Description

Command line processing utility functions.

Classes

struct  GenericSwitchArgs
 Type for storing generic switch arguments. More...
 

Functions

ROSE_UTIL_API Sawyer::CommandLine::Parser createEmptyParser (const std::string &purpose, const std::string &description)
 Empty command-line parser. More...
 
ROSE_UTIL_API Sawyer::CommandLine::Parser createEmptyParserStage (const std::string &purpose, const std::string &description)
 Empty command-line parser suitable for use with other parsers. More...
 
ROSE_UTIL_API Sawyer::CommandLine::SwitchGroup genericSwitches ()
 Generic command-line components. More...
 
ROSE_UTIL_API void insertBooleanSwitch (Sawyer::CommandLine::SwitchGroup &, const std::string &switchName, bool &storageLocation, const std::string &documentation)
 Convenience for for adding Boolean switches. More...
 
ROSE_UTIL_API std::vector< std::string > generateArgListFromString (std::string commandline)
 Separate a string into individual parameters and store them into a string vector.
 
ROSE_UTIL_API std::string generateStringFromArgList (const std::vector< std::string > &argList)
 Convert a vector of string to a single string.
 
ROSE_UTIL_API std::vector< std::string > generateArgListFromArgcArgv (int argc, const char *argv[])
 Convert an argc-argv pair into a string vector.
 
std::vector< std::string > generateArgListFromArgcArgv (int argc, char *argv[])
 
ROSE_UTIL_API void generateArgcArgvFromList (std::vector< std::string > argList, int &argc, char **&argv)
 Convert a string vector back to an argc-argv pair.
 
ROSE_UTIL_API std::vector< std::string > generateOptionList (const std::vector< std::string > &argList, std::string inputPrefix)
 Looks for inputPrefix prefixed options. More...
 
ROSE_UTIL_API std::vector< std::string > generateOptionListWithDeclaredParameters (const std::vector< std::string > &argList, std::string inputPrefix)
 Looks for inputPrefix-prefixed options. More...
 
ROSE_UTIL_API std::vector< std::string > generateOptionWithNameParameterList (std::vector< std::string > &argList, std::string inputPrefix, std::string newPrefix="")
 Find all options matching 'inputPrefix:optionName' || 'inputPrefix:optionName optionValue' from argList, strip off 'inputPrefix:' or replace it by 'newPrefix' if provided. More...
 
ROSE_UTIL_API bool isOption (std::vector< std::string > &argv, std::string optionPrefix, std::string Option, bool removeOption)
 Search 'argv' for an option like optionPrefixOption, remove the option if 'removeOption' is true. e.g. isOption(argv,"-rose:","(C99|C99_only)",false) More...
 
ROSE_UTIL_API bool isOptionWithParameter (std::vector< std::string > &argv, std::string optionPrefix, std::string Option, int &optionParameter, bool removeOption)
 Search 'argv' for 'optionPrefixOption value', store the integer value into 'optionParameter'. More...
 
ROSE_UTIL_API bool isOptionWithParameter (std::vector< std::string > &argv, std::string optionPrefix, std::string Option, float &optionParameter, bool removeOption)
 Search 'argv' for 'optionPrefixOption value', store the float value into 'optionParameter'. Remove the original option if 'removeOption' is true.
 
ROSE_DLL_API bool isOptionWithParameter (std::vector< std::string > &argv, std::string optionPrefix, std::string Option, std::string &optionParameter, bool removeOption)
 Search 'argv' for 'optionPrefixOption value', store the string type value into 'optionParameter'. Remove the original option if 'removeOption' is true.
 
ROSE_UTIL_API void addListToCommandLine (std::vector< std::string > &argv, std::string prefix, std::vector< std::string > argList)
 Add the strings in argList to the command line represented by argc and argv, prepend 'prefix' to each of the arguments.
 
ROSE_UTIL_API void removeArgs (std::vector< std::string > &argv, std::string prefix)
 Remove all options matching a specified prefix 'prefix' from the argument list 'argv'.
 
ROSE_UTIL_API void removeArgsWithParameters (std::vector< std::string > &argv, std::string prefix)
 Remove all options matching a specified prefix 'prefix' from the argument list 'argv', as well as the option values following them.
 
ROSE_UTIL_API void removeAllFileNamesExcept (std::vector< std::string > &argv, std::vector< std::string > filenameList, std::string exceptFilename)
 Remove file names specified in filenameList from argv, except for 'exceptFilename'.
 
ROSE_UTIL_API std::string generateStringFromArgList (std::vector< std::string > argList, bool skipInitialEntry, bool skipSourceFiles)
 Build a string from the argList.
 
ROSE_DLL_API std::vector< std::string > generateSourceFilenames (std::vector< std::string > argList, bool binaryMode)
 Build the list of isolated file names from the command line.
 
ROSE_UTIL_API void addSourceFileSuffix (const std::string &suffix)
 Add another valid source file suffix.
 
ROSE_UTIL_API void addCppSourceFileSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isSourceFilename (std::string name)
 
ROSE_UTIL_API bool isObjectFilename (std::string name)
 
ROSE_DLL_API bool isExecutableFilename (std::string name)
 
ROSE_DLL_API bool isValidFileWithExecutableFileSuffixes (std::string name)
 
ROSE_UTIL_API bool isCFileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isUPCFileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isCppFileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isFortranFileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isFortranFileNameSuffixRequiringCPP (const std::string &suffix)
 
ROSE_UTIL_API bool isFortran77FileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isFortran90FileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isFortran95FileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isFortran2003FileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isFortran2008FileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isCoArrayFortranFileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isPHPFileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isPythonFileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isCudaFileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isOpenCLFileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isJavaFileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API bool isX10FileNameSuffix (const std::string &suffix)
 
ROSE_UTIL_API void initSourceFileSuffixList ()
 
ROSE_UTIL_API void initObjectFileSuffixList ()
 
ROSE_DLL_API void initExecutableFileSuffixList ()
 
ROSE_DLL_API bool isOptionTakingSecondParameter (std::string argument)
 
ROSE_DLL_API bool isOptionTakingThirdParameter (std::string argument)
 

Variables

ROSE_UTIL_API GenericSwitchArgs genericSwitchArgs
 Global location for parsed generic command-line switches. More...
 
std::vector< std::string > extraCppSourceFileSuffixes
 

Function Documentation

ROSE_UTIL_API Sawyer::CommandLine::Parser CommandlineProcessing::createEmptyParser ( const std::string &  purpose,
const std::string &  description 
)

Empty command-line parser.

Returns a command-line parser that has no switch declarations, but is set up consistently for ROSE tools. The purpose should be an uncapitalized, short, single-line string that appears near the top of the man page. The description can be much longer, multiple paragraphs, free-format, with Sawyer markup. It will appear under the heading "Description" in the man page.

See also, createEmptyParserStage.

ROSE_UTIL_API Sawyer::CommandLine::Parser CommandlineProcessing::createEmptyParserStage ( const std::string &  purpose,
const std::string &  description 
)

Empty command-line parser suitable for use with other parsers.

Returns a command-line parser that has no switch declarations, but is set up consistently for ROSE tools. The parser is configured to skip over any program arguments it doesn't recognize, with the assumption that those arguments will be passed to another parser. This also means that this parser cannot report errors for misspelled or misused switches because it cannot tell whether the switch is misspelled or simply intended for the next parser.

The purpose should be an uncapitalized, short, single-line string that appears near the top of the man page. The description can be much longer, multiple paragraphs, free-format, with Sawyer markup. It will appear under the heading "Description" in the man page.

See also, createEmptyParser.

ROSE_UTIL_API Sawyer::CommandLine::SwitchGroup CommandlineProcessing::genericSwitches ( )

Generic command-line components.

Returns a description of the switches that should be available for all ROSE tools. To make a command-line parser that recognizes these switches, add the switches to the parser using its with method. For example, here's how to construct a parser that recognizes only these switches:

parseCommandLine(int argc, char *argv[]) {
return parser
.with(CommandlineProcessing::genericSwitches()) // these generic switches
.with(mySwitches) // my own switches, etc.
.parse(argc, argv) // parse without side effects
.apply(); // apply parser results
}

If you encounter strange errors near this call, make sure you're using -pthread consistently in your compile and link commands. Its presence or absence should be the same as however the ROSE library itself was compiled and linked. Mixing up the -pthread switch creates ABI incompatibilities that manifest themselves in various ways that usually look like a problem with a function that's called from a program that uses librose: often a segmentation fault, but can also be hangs, incorrect results, etc. Note that -pthread is both a compile and a link switch.

See any recent tool for more examples.

ROSE_UTIL_API void CommandlineProcessing::insertBooleanSwitch ( Sawyer::CommandLine::SwitchGroup ,
const std::string &  switchName,
bool &  storageLocation,
const std::string &  documentation 
)

Convenience for for adding Boolean switches.

Adds "--foo" (if switchName is "foo") and "--no-foo" to the specified switch group. The storage location's lifetime must extend to the point where the command-line is parsed. This function adds additional documentation describing how to disable the switch using "--no-foo" and what the default is (current value of storage location).

An alternative is to use a switch that takes a Boolean argument (e.g., "--foo=yes" or "--foo=no"), but this is more difficult for users to remember and type than just "--foo" and "--no-foo".

ROSE_UTIL_API std::vector<std::string> CommandlineProcessing::generateOptionList ( const std::vector< std::string > &  argList,
std::string  inputPrefix 
)

Looks for inputPrefix prefixed options.

Push the stripped-off option in the result list. Warning: As opposed to what the former documentation was saying this function doesn't modify argList.

ROSE_UTIL_API std::vector<std::string> CommandlineProcessing::generateOptionListWithDeclaredParameters ( const std::vector< std::string > &  argList,
std::string  inputPrefix 
)

Looks for inputPrefix-prefixed options.

Push the stripped-off option in the result list. If isOptionTakingSecondParameter of the inputPrefix-prefixed returns true, add the parameter(s) to the result list.

ROSE_UTIL_API std::vector<std::string> CommandlineProcessing::generateOptionWithNameParameterList ( std::vector< std::string > &  argList,
std::string  inputPrefix,
std::string  newPrefix = "" 
)

Find all options matching 'inputPrefix:optionName' || 'inputPrefix:optionName optionValue' from argList, strip off 'inputPrefix:' or replace it by 'newPrefix' if provided.

Returns a string list of matched options. All matching options and values are removed from argList.

ROSE_UTIL_API bool CommandlineProcessing::isOption ( std::vector< std::string > &  argv,
std::string  optionPrefix,
std::string  Option,
bool  removeOption 
)

Search 'argv' for an option like optionPrefixOption, remove the option if 'removeOption' is true. e.g. isOption(argv,"-rose:","(C99|C99_only)",false)

The argument 'option' adds () to the actual option, and allows the |(OR) operations.For example: CommandlineProcessing::isOption(argv,"-rose:","(skip_syntax_check)",true) CommandlineProcessing::isOption(argv,"-rose:","(C99|C99_only)",false)

ROSE_UTIL_API bool CommandlineProcessing::isOptionWithParameter ( std::vector< std::string > &  argv,
std::string  optionPrefix,
std::string  Option,
int &  optionParameter,
bool  removeOption 
)

Search 'argv' for 'optionPrefixOption value', store the integer value into 'optionParameter'.

Remove the original option if 'removeOption' is true. Available value types are: str, float, double, int, short, long, unsigned int, unsigned short, unsigned long, char, etc.

Variable Documentation

ROSE_UTIL_API GenericSwitchArgs CommandlineProcessing::genericSwitchArgs

Global location for parsed generic command-line switches.

This global variable holds the results of command-line parsing using genericSwitches. Normally these settings are passed per command-line parsing request, but the interface in ROSE doesn't have that ability yet, so we use a global variable.