Simple CMD arg parser (powered by pure C)
Pros/Minuses:
+ simplicity
+ written in pure C
- human comments in code (or this a pros?)MiraParser * _MiraParser_open(char * argv[], int argc, 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).
--
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.
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)
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| 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) |