YAAP - Yet Another Argument Parser
A simple commandline argument parser for C
Data Structures | Macros | Enumerations | Functions
argparse.h File Reference

header file for all argparse functions More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  arg_base
 base structure for a command line argument More...
 
struct  arg_parse_cmd
 structure representing a command More...
 
struct  arg_str
 structure representing a string command line argument More...
 
struct  arg_flag
 structure representing a simple flag command line argument More...
 
struct  arg_int
 structure representing a simple int command line argument More...
 
struct  arg_parse_ctx
 structure for the argparse context, holding argparse specific data structures More...
 

Macros

#define ARGPARSE_INITIAL_COMMAND_NR   5
 initial size for the command array
 
#define to_argbase(ptr)   ((struct arg_base *) ptr)
 convert a pointer to an arg_base structure pointer
 
#define to_cmd(ptr)   ((struct arg_parse_cmd *)ptr)
 convert a pointer to an arg_parse_cmd structure pointer
 
#define to_str(ptr)   ((struct arg_str *)ptr)
 convert a pointer to an arg_str structure pointer
 
#define to_flag(ptr)   ((struct arg_flag *) ptr)
 convert a pointer to an arg_flag structure pointer
 
#define to_int(ptr)   ((struct arg_int *) ptr)
 convert a pointer to an arg_int structure pointer
 

Enumerations

enum  argtypes { ARG_CMD, ARG_FLAG, ARG_STR, ARG_INT }
 supported argument types More...
 

Functions

struct arg_parse_ctxargparse_init ()
 initialize parsing context More...
 
void argparse_free (struct arg_parse_ctx *ctx)
 free the parsing context at program end More...
 
int argparse_add_command (struct arg_parse_ctx *ctx, struct arg_parse_cmd *cmd)
 add a commandline command to the context More...
 
int argparse_add_string (struct arg_parse_ctx *ctx, struct arg_str *str)
 add a string argument to the context More...
 
int argparse_add_flag (struct arg_parse_ctx *ctx, struct arg_flag *flag)
 add a flag argument to the context More...
 
int argparse_add_int (struct arg_parse_ctx *ctx, struct arg_int *integer)
 add a integer argument to the context More...
 
int argparse_parse (struct arg_parse_ctx *ctx, int argc, char **argv)
 parse the given commandline in the context More...
 

Detailed Description

header file for all argparse functions

Author
Dominik Meyer dmeye.nosp@m.r@fe.nosp@m.derat.nosp@m.ionh.nosp@m.q.de

Enumeration Type Documentation

◆ argtypes

enum argtypes

supported argument types

Enumerator
ARG_CMD 

a command argument like git uses it (git commit)

ARG_FLAG 

a simple flag like -v without additional parameter

ARG_STR 

an argument with a string parameter (-t hallo, –title=hallo)

ARG_INT 

an argument with a integer parameter (-s 10, –size=10)

Function Documentation

◆ argparse_add_command()

int argparse_add_command ( struct arg_parse_ctx ctx,
struct arg_parse_cmd cmd 
)

add a commandline command to the context

add a commandline command to the context

Parameters
ctx- the context the command should be added to
cmd- the command to add to the context
Returns
0 = everything is fine, -1 error occured

◆ argparse_add_flag()

int argparse_add_flag ( struct arg_parse_ctx ctx,
struct arg_flag flag 
)

add a flag argument to the context

add a flag argument to the context

add an arg_flag to the context for later parsing

Parameters
ctx- the context the command should be added to
flag- the arg_flag to add
Returns
0 = everything is fine, -1 error occured

◆ argparse_add_int()

int argparse_add_int ( struct arg_parse_ctx ctx,
struct arg_int integer 
)

add a integer argument to the context

add a integer argument to the context

Parameters
ctx- the context the command should be added to
integer- the arg_int to add
Returns
0 = everything is fine, -1 error occured

◆ argparse_add_string()

int argparse_add_string ( struct arg_parse_ctx ctx,
struct arg_str str 
)

add a string argument to the context

add a string argument to the context

Parameters
ctx- the context the command should be added to
str- the arg_str to add
Returns
0 = everything is fine, -1 error occured

◆ argparse_free()

void argparse_free ( struct arg_parse_ctx ctx)

free the parsing context at program end

free the parsing context at program end

this function should be called at the end of the programm

Parameters
ctx- the arg_parse_ctx structure to free

◆ argparse_init()

struct arg_parse_ctx* argparse_init ( )

initialize parsing context

initialize parsing context

This function has to be called at every start of the programm and before any other argparse functions are called!!!

Returns
returns an initialized arg parse structure

◆ argparse_parse()

int argparse_parse ( struct arg_parse_ctx ctx,
int  argc,
char **  argv 
)

parse the given commandline in the context

parse the given commandline in the context

Parameters
ctx- the arg parse context to use
argc- the argument count of the commandline
argv- the argument list of the commandline
Returns
0 - everything is fine
<0 - parsing failed