
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))MiraParser*_MiraParser_open(char*argv[], intargc, char*prefix);or
MiraParser_Open(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).
--
voidMiraParser_Free(MiraParser*parser);Used to close the parser
--
voidMiraParser_Value_Arg_Free(MiraParser_Return*var);Used to close the variable for returning values
--
intMiraParser_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.
intMiraParser_Arg(constchar*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)
intMiraParser_Value_Arg(constchar*arg, MiraParser_Return*var, MiraParser_argument_typetype, 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| 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) |