prelude-getopt

Name

prelude-getopt -- 

Synopsis



#define     CLI_HOOK
#define     CFG_HOOK
#define     WIDE_HOOK
#define     prelude_option_success
#define     prelude_option_end
#define     prelude_option_error
enum        prelude_option_argument_t;
#define     option_run_last
#define     option_run_first
#define     option_run_no_order
void        prelude_option_set_priority     (prelude_option_t *option,
                                             int priority);
void        prelude_option_print            (int flags,
                                             int descoff);
prelude_msg_t* prelude_option_wide_get_msg  (void);
void        prelude_option_destroy          (prelude_option_t *option);
int         prelude_option_parse_arguments  (prelude_option_t *option,
                                             const char *filename,
                                             int argc,
                                             char **argv);
prelude_option_t* prelude_option_add        (prelude_option_t *parent,
                                             int flags,
                                             char shortopt,
                                             const char *longopt,
                                             const char *desc,
                                             prelude_option_argument_t has_arg,
                                             int (*set) (prelude_option_t *opt, const char *optarg),
                                             int (*get) (char *buf, size_t size));
#define     OPT_INVAL
#define     OPT_INVAL_ARG
void        prelude_option_set_warnings     (int flags,
                                             int *old_flags);
char        prelude_option_get_shortname    (prelude_option_t *opt);
const char* prelude_option_get_longname     (prelude_option_t *opt);
void        prelude_option_set_private_data (prelude_option_t *opt,
                                             void *data);
void*       prelude_option_get_private_data (prelude_option_t *opt);

Description

Details

CLI_HOOK

#define CLI_HOOK 0x1 /* Option to be hooked to command line */


CFG_HOOK

#define CFG_HOOK 0x2 /* Option to be hooked to config file  */


WIDE_HOOK

#define WIDE_HOOK 0x4


prelude_option_success

#define prelude_option_success 0


prelude_option_end

#define prelude_option_end 1


prelude_option_error

#define prelude_option_error -1


enum prelude_option_argument_t

typedef enum {
        required_argument,
        optionnal_argument,
        no_argument
} prelude_option_argument_t;


option_run_last

#define option_run_last      -1


option_run_first

#define option_run_first     -2


option_run_no_order

#define option_run_no_order   0


prelude_option_set_priority ()

void        prelude_option_set_priority     (prelude_option_t *option,
                                             int priority);

option :

priority :


prelude_option_print ()

void        prelude_option_print            (int flags,
                                             int descoff);

Dump option available in opt and hooked to the given flags. If opt is NULL, then the root of the option list is used.

flags :

Only option with specified flags will be printed.

descoff :

offset from the begining of the line where the description should start.


prelude_option_wide_get_msg ()

prelude_msg_t* prelude_option_wide_get_msg  (void);

Returns :


prelude_option_destroy ()

void        prelude_option_destroy          (prelude_option_t *option);

Destroy a prelude_option_t object and all data associated with it (including all suboption).

option :

Pointer on an option object.


prelude_option_parse_arguments ()

int         prelude_option_parse_arguments  (prelude_option_t *option,
                                             const char *filename,
                                             int argc,
                                             char **argv);

prelude_option_parse_arguments(), parse the given argument and try to match them against option in option. If an option match, it's associated callback function is called with the eventual option argument if any.

Option not matched on the command line are searched in the configuration file specified by filename.

if option is NULL, all system option will be matched against argc, and argv.

option :

A pointer on an option (list).

filename :

Pointer to the config filename.

argc :

Number of argument.

argv :

Argument list.

Returns :

0 if parsing the option succeed (including the case where one of the callback returned -1 to request interruption of parsing), -1 if an error occured.


prelude_option_add ()

prelude_option_t* prelude_option_add        (prelude_option_t *parent,
                                             int flags,
                                             char shortopt,
                                             const char *longopt,
                                             const char *desc,
                                             prelude_option_argument_t has_arg,
                                             int (*set) (prelude_option_t *opt, const char *optarg),
                                             int (*get) (char *buf, size_t size));

prelude_option_add() create a new option. The option is set to be the child of parent, unless it is NULL. In this case the option is a root option.

The flags parameters can be set to CLI_HOOK (telling the option may be searched on the command line only) or CFG_HOOk (telling the option may be searched in the configuration file only) or both.

parent :

Pointer on a parent option.

flags :

bitfields.

shortopt :

Short option name.

longopt :

Long option name.

desc :

Description of the option.

has_arg :

Define if the option has argument.

set :

Callback to be called when the value for this option change.

get :

Callback to be called to get the value for this option.

Returns :

Pointer on the option object, or NULL if an error occured.


OPT_INVAL

#define OPT_INVAL     0x1


OPT_INVAL_ARG

#define OPT_INVAL_ARG 0x2


prelude_option_set_warnings ()

void        prelude_option_set_warnings     (int flags,
                                             int *old_flags);

Set current warnings flags to flags (unless flags is 0).

Uppon return, the variable pointed to by old_flags is updated to contain the old flags unless it point to NULL.

flags :

bitwise OR of flags.

old_flags :

Pointer to an integer where to store old flags to.


prelude_option_get_shortname ()

char        prelude_option_get_shortname    (prelude_option_t *opt);

opt :

Returns :


prelude_option_get_longname ()

const char* prelude_option_get_longname     (prelude_option_t *opt);

opt :

Returns :


prelude_option_set_private_data ()

void        prelude_option_set_private_data (prelude_option_t *opt,
                                             void *data);

opt :

data :


prelude_option_get_private_data ()

void*       prelude_option_get_private_data (prelude_option_t *opt);

opt :