YAAP - Yet Another Argument Parser
A simple commandline argument parser for C
Functions
argparse.c File Reference

file for all argparse functions More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "argparse.h"
Include dependency graph for argparse.c:

Functions

void argparse_usage (struct arg_parse_ctx *ctx, char *program)
 forward declaration of function More...
 
int argparse_add_flag (struct arg_parse_ctx *ctx, struct arg_flag *flag)
 forward declaration of function More...
 
int argparse_help (void *ctx, void *user)
 wrapper function for calling argparse_usage from the -h arg_flag command line argument More...
 
struct arg_parse_ctxargparse_init ()
 initialize the argparse context More...
 
void argparse_free (struct arg_parse_ctx *ctx)
 free an arg_parse context (all memory will be freed) More...
 
int argparse_add_command (struct arg_parse_ctx *ctx, struct arg_parse_cmd *cmd)
 add an arg_parse_cmd to the context for later parsing More...
 
int argparse_add_string (struct arg_parse_ctx *ctx, struct arg_str *str)
 add an arg_str to the context for later parsing More...
 
int argparse_add_int (struct arg_parse_ctx *ctx, struct arg_int *integer)
 add an arg_int to the context for later parsing More...
 
void argparse_unknown_command (struct arg_parse_ctx *ctx, char *program, char *command)
 internal function to print usage information, if an unknown command has been found More...
 
int argparse_parse (struct arg_parse_ctx *ctx, int argc, char **argv)
 parse the given commandline More...
 

Detailed Description

file for all argparse functions

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

Function Documentation

◆ argparse_add_command()

int argparse_add_command ( struct arg_parse_ctx ctx,
struct arg_parse_cmd cmd 
)

add an arg_parse_cmd to the context for later parsing

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
Examples:
example1.c.

◆ argparse_add_flag()

int argparse_add_flag ( struct arg_parse_ctx ctx,
struct arg_flag flag 
)

forward declaration of function

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 an arg_int to the context for later parsing

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
Examples:
example1.c.

◆ argparse_add_string()

int argparse_add_string ( struct arg_parse_ctx ctx,
struct arg_str str 
)

add an arg_str to the context for later parsing

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 an arg_parse context (all memory will be freed)

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
Examples:
example1.c.

◆ argparse_help()

int argparse_help ( void *  ctx,
void *  user 
)

wrapper function for calling argparse_usage from the -h arg_flag command line argument

Parameters
ctx- the current yaap context
user- some user specific data in this case the command line arguments
Returns
0 - everything is fine

◆ argparse_init()

struct arg_parse_ctx* argparse_init ( )

initialize the argparse 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
Examples:
example1.c.

◆ argparse_parse()

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

parse the given commandline

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
Examples:
example1.c.

◆ argparse_unknown_command()

void argparse_unknown_command ( struct arg_parse_ctx ctx,
char *  program,
char *  command 
)

internal function to print usage information, if an unknown command has been found

Parameters
ctx- the context for which to print the usage information
program- the program name the application was called with
command- the command found

◆ argparse_usage()

void argparse_usage ( struct arg_parse_ctx ctx,
char *  program 
)

forward declaration of function

internal function to print usage information, not exported to user

Parameters
ctx- the context for which to print the usage information
program- the program name the application was called with