Debugging Tools for Windows |
The EngExtCpp extension framework provides methods to aid in parsing the command-line arguments passed to an extension. To take advantage of these methods, the extension must first declare the format of the command-line arguments in the EXT_COMMAND macro.
To bypass the command-line argument parsing done by the framework and let the extension itself parse the arguments, set the command-line description to "{{custom}}" and use the method GetRawArgStr to get the command-line arguments for parsing.
Command-line description strings will automatically be wrapped when printed, to fit the column width of the display. However, newline characters can be embedded in the description strings – using '\n' – to start new lines.
The command-line description can be NULL or the empty string. If either occurs, it indicates that the extension command does not take any arguments.
The description of the command-line arguments is a sequence that contains two types of components: directives and arguments. The description can optionally contain one of each directive and can contain up to 64 arguments.
Directives specify how the arguments are parsed. They are enclosed by double braces ('{{' and '}}'). Each directive can optionally appear zero or one times in the string that describes the arguments.
The following directives are available:
Here are some examples of directives. The following string is used by an extension command that parses its own arguments. It also provides short and long descriptions for use with the automatic !help extension command:
The following string changes the argument option prefix characters to '/' or '-'. With this directive, the arguments will be specified using '+arg' and ':arg' instead of '/arg' and '-arg':
Arguments can be of two types: named and unnamed. Unnamed arguments are read positionally. Both types of argument also have a display name, used by the help command.
Argument descriptions are enclosed by single braces ('{' and '}').
Each argument description has the following syntax:
where:
The expression is limited to the next space character in the argument string. If this is not present, the expression evaluator will consume characters from the command line until it determines that it reached the end of the expression.
sThe value of the expression is signed. Otherwise, the value of the expression is unsigned.
bitsThe number of bits in the value of the argument. The maximum value for bits is 64.
String type. The string is limited to the next space character. Named string arguments can be retrieved using GetArgStr and unnamed string arguments can be retrieved using GetUnnamedArgStr.
xString type. The argument is the rest of the command line. The argument is retrieved using GetArgStr or GetUnnamedArgStr, as with the s string type.
Here are some examples of argument descriptions. The following expression defines a command which takes a single optional expression argument. The argument must fit in 32bits. If the argument isn't present on the command line, the default value of 0x100 will be used.
The following expression defines a command with an optional Boolean "/v" argument and a required unnamed string argument.
The following expression defines a command that has an optional named expression argument /oname expr and an optional named string argument /eol str. If /eol is present, its value will be set to the remainder of the command line and no further arguments will be parsed.
The following is a list of some ways that arguments are parsed on the command line:
Several methods are used by the argument parser to set arguments.
The method SetUnnamedArg will change the value of an unnamed argument. And, for convenience, the methods SetUnnamedArgStr and SetUnnamedArgU64 will set unnamed string and expression arguments respectively.
Similar methods exist for named arguments. SetArg is used to change the value of any named argument and SetArgStr and SetArgU64 are used for named string and expression arguments respectively.