Ecore_Getopt.h File Reference

Contains powerful getopt replacement. More...

Functions

EAPI void ecore_getopt_help (FILE *fp, const Ecore_Getopt *info)
 Show nicely formatted help message for the given parser.
EAPI Eina_Bool ecore_getopt_parser_has_duplicates (const Ecore_Getopt *parser)
 Check parser for duplicate entries, print them out.
EAPI int ecore_getopt_parse (const Ecore_Getopt *parser, Ecore_Getopt_Value *values, int argc, char **argv)
 Parse command line parameters.
EAPI Eina_List * ecore_getopt_list_free (Eina_List *list)
 Utility to free list and nodes allocated by ECORE_GETOPT_ACTION_APPEND.
EAPI Eina_Bool ecore_getopt_callback_geometry_parse (const Ecore_Getopt *parser, const Ecore_Getopt_Desc *desc, const char *str, void *data, Ecore_Getopt_Value *storage)
 Helper ecore_getopt callback to parse geometry (x:y:w:h).
EAPI Eina_Bool ecore_getopt_callback_size_parse (const Ecore_Getopt *parser, const Ecore_Getopt_Desc *desc, const char *str, void *data, Ecore_Getopt_Value *storage)
 Helper ecore_getopt callback to parse geometry size (WxH).

Detailed Description

Contains powerful getopt replacement.

This replacement handles both short (-X) or long options (–ABC) options, with various actions supported, like storing one value and already converting to required type, counting number of occurrences, setting true or false values, show help, license, copyright and even support user-defined callbacks.

It is provided a set of C Pre Processor macros so definition is straightforward.

Values will be stored elsewhere indicated by an array of pointers to values, it is given in separate to parser description so you can use multiple values with the same parser.

Function Documentation

EAPI Eina_Bool ecore_getopt_callback_geometry_parse ( const Ecore_Getopt *  parser,
const Ecore_Getopt_Desc *  desc,
const char *  str,
void *  data,
Ecore_Getopt_Value *  storage 
)

Helper ecore_getopt callback to parse geometry (x:y:w:h).

Parameters
parserThis parameter isn't in use.
descThis parameter isn't in use.
strGeometry value
dataThis parameter isn't in use.
storagemust be a pointer to Eina_Rectangle and will be used to store the four values passed in the given string.
Returns
EINA_TRUE on success, EINA_FALSE on incorrect geometry value.

callback_data value is ignored, you can safely use NULL.

EAPI Eina_Bool ecore_getopt_callback_size_parse ( const Ecore_Getopt *  parser,
const Ecore_Getopt_Desc *  desc,
const char *  str,
void *  data,
Ecore_Getopt_Value *  storage 
)

Helper ecore_getopt callback to parse geometry size (WxH).

Parameters
parserThis parameter isn't in use.
descThis parameter isn't in use.
strsize value
dataThis parameter isn't in use.
storagemust be a pointer to Eina_Rectangle and will be used to store the two values passed in the given string and 0 in the x and y fields.
Returns
EINA_TRUE on success, EINA_FALSE on incorrect size value.

callback_data value is ignored, you can safely use NULL.

EAPI void ecore_getopt_help ( FILE *  fp,
const Ecore_Getopt *  parser 
)

Show nicely formatted help message for the given parser.

Parameters
fpThe file the message will be printed on.
parserThe parser to be used.

References ecore_app_args_get().

EAPI Eina_List* ecore_getopt_list_free ( Eina_List *  list)

Utility to free list and nodes allocated by ECORE_GETOPT_ACTION_APPEND.

Parameters
listpointer to list to be freed.
Returns
always NULL, so you can easily make your list head NULL.
EAPI int ecore_getopt_parse ( const Ecore_Getopt *  parser,
Ecore_Getopt_Value *  values,
int  argc,
char **  argv 
)

Parse command line parameters.

Walks the command line parameters and parse them based on parser description, doing actions based on parser->descs->action, like showing help text, license, copyright, storing values in values and so on.

It is expected that values is of the same size than parser->descs, options that do not need a value it will be left untouched.

All values are expected to be initialized before use. Options with action ECORE_GETOPT_ACTION_STORE and non required arguments (others than ECORE_GETOPT_DESC_ARG_REQUIREMENT_YES), are expected to provide a value in def to be used.

The following actions will store 1 on value as a boolean (value->boolp) if it's not NULL to indicate these actions were executed:

  • ECORE_GETOPT_ACTION_HELP
  • ECORE_GETOPT_ACTION_VERSION
  • ECORE_GETOPT_ACTION_COPYRIGHT
  • ECORE_GETOPT_ACTION_LICENSE

Just ECORE_GETOPT_ACTION_APPEND will allocate memory and thus need to be freed. For consistency between all of appended subtypes, eina_list->data will contain an allocated memory with the value, that is, for ECORE_GETOPT_TYPE_STR it will contain a copy of the argument, ECORE_GETOPT_TYPE_INT a pointer to an allocated integer and so on.

If parser is in strict mode (see Ecore_Getopt->strict), then any error will abort parsing and -1 is returned. Otherwise it will try to continue as far as possible.

This function may reorder argv elements.

Translation of help strings (description), metavar, usage, license and copyright may be translated, standard/global gettext() call will be applied on them if ecore was compiled with such support.

Parameters
parserdescription of how to work.
valueswhere to store values, it is assumed that this is a vector of the same size as parser->descs. Values should be previously initialized.
argchow many elements in argv. If not provided it will be retrieved with ecore_app_args_get().
argvcommand line parameters.
Returns
index of first non-option parameter or -1 on error.
Examples:
ecore_thread_example.c.

References ecore_app_args_get().

EAPI Eina_Bool ecore_getopt_parser_has_duplicates ( const Ecore_Getopt *  parser)

Check parser for duplicate entries, print them out.

Returns
EINA_TRUE if there are duplicates, EINA_FALSE otherwise.
Parameters
parserThe parser to be checked.