Command-line argument parsing module. More...
Go to the source code of this file.
Functions | |
| int | parseArgs (int argc, char *argv[]) |
| Parses a command-line argument array. | |
| const char * | getOptionVal (const char option[]) |
| Retrieves the corresponding value for a given option key. | |
| const char * | getLeadingArg (unsigned int i) |
| Retrieves a leading argument. | |
| const char * | getTrailingArg (unsigned int i) |
| Retrieves a trailing argument. | |
Command-line argument parsing module.
| const char* getLeadingArg | ( | unsigned int | i | ) |
Retrieves a leading argument.
| i | Argument index. |
argv[0]) itself is omitted, so i = 0 will yield argv[1]. It can be retrieved by calling getProgramName(). | const char* getOptionVal | ( | const char | option[] | ) |
Retrieves the corresponding value for a given option key.
If the command line contains more than one pair with the same key, the value of the last pair is returned.
| option | Option key. Must begin with a dash ('-'). |
NULL if no mapping with this key was found. | const char* getTrailingArg | ( | unsigned int | i | ) |
Retrieves a trailing argument.
| i | Argument index. |
NULL if i is out of range. | int parseArgs | ( | int | argc, | |
| char * | argv[] | |||
| ) |
Parses a command-line argument array.
This function must be invoked before any of the other functions. It parses the given argument array containing key-to-value mappings. The array has to come in a form like this:
program -key0 value0 -key1 value1 ...
Keys have to begin with a dash ('-') whereas values must not. The value associated with a given key can be retrieved using getOptionVal(). The array may contain additional arguments that are not part of the mapping before or after the key-value pairs, but not in between. They can be retrieved using getLeadingArg() or getTrailingArg(), respectively. If there are no key-value pairs, all arguments are considered to be both, leading and trailing.
| argc | Number of command-line arguments. | |
| argv | Array of command-line arguments. |
1.7.1