creeper
Functions
argumentParser.h File Reference

Simple command-line argument parsing module. More...

Go to the source code of this file.

Functions

int initArgumentParser (int argc, char *argv[])
 Initializes the simple command-line parsing module. More...
 
char * getCommand (void)
 Retrieves the program name. More...
 
char * getValueForOption (char *keyName)
 Gets the corresponding value for a given option key ("-key=value") More...
 
int getNumberOfArguments (void)
 
char * getArgument (int index)
 Retrieves an argument. More...
 

Detailed Description

Simple 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:

Command-line argument format supported by this modul: <command> [arguments..] [options..] After the command an arbitray number of arguments followed by an arbitrary number of options can be specified. Both, arguments and options, are optional.

Function Documentation

◆ getArgument()

char* getArgument ( int  index)

Retrieves an argument.

Parameters
indexZero-based index of the argument.
Returns
The argument with the given index, or NULL if index is greater than or equal to the number of arguments.

◆ getCommand()

char* getCommand ( void  )

Retrieves the program name.

Returns
The value of argv[0].

◆ getNumberOfArguments()

int getNumberOfArguments ( void  )

Retrieves the number of arguments.

◆ getValueForOption()

char* getValueForOption ( char *  keyName)

Gets the corresponding value for a given option key ("-key=value")

If the same key appears several times in the command line, the value of its first occurrence is returned.

Parameters
keyThe key without leading dash.
Returns
The value associated with the given key, or NULL if no such pair exists.

◆ initArgumentParser()

int initArgumentParser ( int  argc,
char *  argv[] 
)

Initializes the simple command-line parsing module.

This function must be invoked before any of the other functions.

Parameters
argcNumber of command-line arguments.
argvArray of command-line arguments. The contents of this array are not modified in any manner.
Returns
0 on success. If argc or argv is invalid, -1 is returned and errno is set to EINVAL.