Skip to content
modkitv0.2

args.h

#include <modkit/args.h>11 functions · 5 structs · 6 typedefs

Command-line argument parsing for modkit applications.

Simple wrapper around argtable3 providing a cleaner API for parsing command-line arguments in modkit applications. Example usage:

Functions

mk_args_createfunction

mk_args_t * mk_args_create(const char *name, const char *description)

Create a new argument parser.

ParameterTypeDescription
nameconst char *Application name (shown in help)
descriptionconst char *Brief description of the application

Returns New parser instance, or NULL on failure

mk_args_dblfunction

void mk_args_dbl(mk_args_t *args, mk_arg_dbl_t *out, const char *short_opt, const char *long_opt, const char *metavar, const char *help, double default_val)

Add a double argument.

Example: -s 1.5, scale=2.0

ParameterTypeDescription
argsmk_args_t *Parser instance
outmk_arg_dbl_t *Output structure (filled after parsing)
short_optconst char *Short option (e.g., "s"), or NULL
long_optconst char *Long option (e.g., "scale"), or NULL
metavarconst char *Value placeholder in help (e.g., "FACTOR")
helpconst char *Help text for this option
default_valdoubleDefault value if not provided

mk_args_destroyfunction

void mk_args_destroy(mk_args_t *args)

Destroy argument parser and free resources.

ParameterTypeDescription
argsmk_args_t *Parser instance

mk_args_flagfunction

void mk_args_flag(mk_args_t *args, mk_arg_flag_t *out, const char *short_opt, const char *long_opt, const char *help)

Add a flag (boolean) argument.

Flags don't take values; they're either present or not. Example: -v, verbose

ParameterTypeDescription
argsmk_args_t *Parser instance
outmk_arg_flag_t *Output structure (filled after parsing)
short_optconst char *Short option (e.g., "v"), or NULL
long_optconst char *Long option (e.g., "verbose"), or NULL
helpconst char *Help text for this option

mk_args_intfunction

void mk_args_int(mk_args_t *args, mk_arg_int_t *out, const char *short_opt, const char *long_opt, const char *metavar, const char *help, int default_val)

Add an integer argument.

Example: -p 8080, port=8080

ParameterTypeDescription
argsmk_args_t *Parser instance
outmk_arg_int_t *Output structure (filled after parsing)
short_optconst char *Short option (e.g., "p"), or NULL
long_optconst char *Long option (e.g., "port"), or NULL
metavarconst char *Value placeholder in help (e.g., "PORT")
helpconst char *Help text for this option
default_valintDefault value if not provided

mk_args_parsefunction

bool mk_args_parse(mk_args_t *args, int argc, char **argv)

Parse command-line arguments.

ParameterTypeDescription
argsmk_args_t *Parser instance
argcintArgument count from main()
argvchar **Argument values from main()

Returns true on success, false on error

mk_args_positionalfunction

void mk_args_positional(mk_args_t *args, mk_arg_pos_t *out, const char *metavar, const char *help)

Add a required positional argument.

Positional arguments don't have -/ prefix. Example: program INPUT

ParameterTypeDescription
argsmk_args_t *Parser instance
outmk_arg_pos_t *Output structure (filled after parsing)
metavarconst char *Name shown in help (e.g., "INPUT")
helpconst char *Help text for this argument

mk_args_positional_optfunction

void mk_args_positional_opt(mk_args_t *args, mk_arg_pos_t *out, const char *metavar, const char *help, const char *default_val)

Add an optional positional argument.

ParameterTypeDescription
argsmk_args_t *Parser instance
outmk_arg_pos_t *Output structure (filled after parsing)
metavarconst char *Name shown in help (e.g., "OUTPUT")
helpconst char *Help text for this argument
default_valconst char *Default value if not provided (can be NULL)

mk_args_print_errorsfunction

void mk_args_print_errors(mk_args_t *args, const char *program)

Print error messages from parsing.

ParameterTypeDescription
argsmk_args_t *Parser instance
programconst char *Program name (usually argv[0])

mk_args_strfunction

void mk_args_str(mk_args_t *args, mk_arg_str_t *out, const char *short_opt, const char *long_opt, const char *metavar, const char *help, const char *default_val)

Add a string argument.

Example: -o output.txt, output=file.txt

ParameterTypeDescription
argsmk_args_t *Parser instance
outmk_arg_str_t *Output structure (filled after parsing)
short_optconst char *Short option (e.g., "o"), or NULL
long_optconst char *Long option (e.g., "output"), or NULL
metavarconst char *Value placeholder in help (e.g., "FILE")
helpconst char *Help text for this option
default_valconst char *Default value if not provided (can be NULL)

mk_args_usagefunction

void mk_args_usage(mk_args_t *args, const char *program)

Print usage/help message.

ParameterTypeDescription
argsmk_args_t *Parser instance
programconst char *Program name (usually argv[0])

Structs

mk_arg_dblstruct

Double argument.

After parsing, set is true if the argument was provided. value contains either the parsed value or the default.

FieldTypeDescription
setboolTrue if argument was provided.
valuedoubleParsed or default value.
_internalvoid *Internal argtable pointer.

mk_arg_flagstruct

Flag argument (boolean switch).

After parsing, set is true if the flag was provided on command line.

FieldTypeDescription
setboolTrue if flag was provided.
_internalvoid *Internal argtable pointer.

mk_arg_intstruct

Integer argument.

After parsing, set is true if the argument was provided. value contains either the parsed value or the default.

FieldTypeDescription
setboolTrue if argument was provided.
valueintParsed or default value.
_internalvoid *Internal argtable pointer.

mk_arg_posstruct

Positional argument (unnamed).

For arguments without -/ prefix, like: program INPUT OUTPUT

FieldTypeDescription
setboolTrue if argument was provided.
valueconst char *Parsed value (or NULL if not set).
_internalvoid *Internal argtable pointer.

mk_arg_strstruct

String argument.

After parsing, set is true if the argument was provided. value contains either the parsed value or the default.

FieldTypeDescription
setboolTrue if argument was provided.
valueconst char *Parsed or default value.
_internalvoid *Internal argtable pointer.

Typedefs

mk_arg_dbl_ttypedef

typedef struct mk_arg_dbl mk_arg_dbl_t

Double argument.

After parsing, set is true if the argument was provided. value contains either the parsed value or the default.

mk_arg_flag_ttypedef

typedef struct mk_arg_flag mk_arg_flag_t

Flag argument (boolean switch).

After parsing, set is true if the flag was provided on command line.

mk_arg_int_ttypedef

typedef struct mk_arg_int mk_arg_int_t

Integer argument.

After parsing, set is true if the argument was provided. value contains either the parsed value or the default.

mk_arg_pos_ttypedef

typedef struct mk_arg_pos mk_arg_pos_t

Positional argument (unnamed).

For arguments without -/ prefix, like: program INPUT OUTPUT

mk_arg_str_ttypedef

typedef struct mk_arg_str mk_arg_str_t

String argument.

After parsing, set is true if the argument was provided. value contains either the parsed value or the default.

mk_args_ttypedef

typedef struct mk_args mk_args_t

Opaque argument parser state.