Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image

MiraParser

Simple CMD arg parser (powered by pure C)

Pros/Minuses:
+ simplicity
+ written in pure C

- human comments in code (or this a pros?)

@@ +- @@
! There is no direct support for short arguments (Implementation is possible via two parsers (which would require more careful handling))

Functions

Init. functions

MiraParser * _MiraParser_open(char * argv[], int argc, char * prefix);

or

MiraParser_Open(prefix)
Define: #define MiraParser_Open(prefix) _MiraParser_open((argv), (argc), (prefix))

Used to initialize the parser; the function with the _ prefix is needed in case your operating system provides a different input data format for programs

--

MiraParser_Return * MiraParser_Value_Arg_Open();

Used to initialize variables for returning values (for arguments with values).

--

void MiraParser_Free(MiraParser * parser);

Used to close the parser

--

void MiraParser_Value_Arg_Free(MiraParser_Return * var);

Used to close the variable for returning values

--

int MiraParser_Free_String_Return(MiraParser_Return * var);

Used to clean the string stored in the variable for returning values

Warning

if you only needed the variable for a short time, use only MiraParser_Value_Arg_Free.

Argument checking functions

int MiraParser_Arg(const char * arg, MiraParser * parser);

Returns 0 if such argument is present, 1 if absent. Use for validating the presence of an argument (In the expected argument, you must write the argument WITHOUT the prefix declared in MiraParser_open)

Value retrieval functions

int MiraParser_Value_Arg(const char* arg, MiraParser_Return * var, MiraParser_argument_type type, MiraParser * parser);

Parses an argument that implies a value. Value is written to var (In the expected argument, you must write the argument WITHOUT the prefix declared in MiraParser_open). To get the value, BEFORE closing MiraParser_Return use the following approach:

MIRAPARSER_RETURN_INSTANCE->string/character/floating/integer

Argument types

Type (For MiraParser) Type (For Humans)
MIRAPARSER_INT_TYPE Integer
MIRAPARSER_FLOAT_TYPE Float
MIRAPARSER_STRING_TYPE String
MIRAPARSER_CHAR_TYPE Character
MIRAPARSER_NO_ACCEPT_VALUE No value (better use MiraParser_Arg)

Examples

See there

About

Simple CMD arg parser (powered by pure C)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages