My Project
|
Command-line argument parsing module. More...
#include <stdbool.h>
Go to the source code of this file.
Functions | |
int | cmdlineInit (int argc, char *argv[]) |
Initializes the command-line parsing module. More... | |
const char * | cmdlineGetProgramName (void) |
Retrieves the program name. More... | |
const char * | cmdlineGetValueForKey (const char key[]) |
Gets the corresponding value for a given option key ("-key=value" or "--key=value"). More... | |
bool | cmdlineGetFlag (const char flag[]) |
Checks if a given flag ("-flag" or "--flag") was passed via the command line. More... | |
unsigned int | cmdlineGetExtraArgCount (void) |
const char * | cmdlineGetExtraArg (unsigned int index) |
Retrieves an extra argument. More... | |
Command-line argument parsing module.
This module is useful for parsing the argv
array passed to a program via the command line, which can consist of the following argument classes:
argv
[0]), which can be retrieved by calling cmdlineGetProgramName().Both keys and flags must begin with one or two dashes followed by one alpha-numeric character and an arbitrary number of additional characters (excluding '\0'
and '='
).
const char * cmdlineGetExtraArg | ( | unsigned int | index | ) |
Retrieves an extra argument.
index | Zero-based index of the extra argument. |
NULL
if index is greater than or equal to the number of extra arguments. unsigned int cmdlineGetExtraArgCount | ( | void | ) |
Retrieves the number of extra command-line arguments.
bool cmdlineGetFlag | ( | const char | flag[] | ) |
Checks if a given flag ("-flag" or "--flag") was passed via the command line.
flag | Name of the flag. Leading dashes may be omitted. |
true
if the flag is set, otherwise false
. const char * cmdlineGetProgramName | ( | void | ) |
Retrieves the program name.
argv
[0]. const char * cmdlineGetValueForKey | ( | const char | key[] | ) |
Gets the corresponding value for a given option key ("-key=value" or "--key=value").
If the same key appears several times in the command line, the value of its latest occurrence is returned.
key | The key. Leading dashes may be omitted. |
NULL
if no such pair exists. int cmdlineInit | ( | int | argc, |
char * | argv[] | ||
) |
Initializes the command-line parsing module.
This function must be invoked before any of the other functions.
argc | Number of command-line arguments. |
argv | Array of command-line arguments. The contents of this array are not modified in any manner. |
EINVAL
.