2 * command line and config file parser
7 #warning "NEW_CONFIG defined but still using the old cfgparser.h"
16 #define CONF_TYPE_FLAG 0
17 #define CONF_TYPE_INT 1
18 #define CONF_TYPE_FLOAT 2
19 #define CONF_TYPE_STRING 3
20 #define CONF_TYPE_FUNC 4
21 #define CONF_TYPE_FUNC_PARAM 5
22 #define CONF_TYPE_PRINT 6
23 #define CONF_TYPE_FUNC_FULL 7
24 #define CONF_TYPE_SUBCONFIG 8
25 #define CONF_TYPE_STRING_LIST 9
26 #define CONF_TYPE_POSITION 10
29 #define ERR_NOT_AN_OPTION -1
30 #define ERR_MISSING_PARAM -2
31 #define ERR_OUT_OF_RANGE -3
32 #define ERR_FUNC_ERR -4
36 #define CONF_MIN (1<<0)
37 #define CONF_MAX (1<<1)
38 #define CONF_RANGE (CONF_MIN|CONF_MAX)
39 #define CONF_NOCFG (1<<2)
40 #define CONF_NOCMD (1<<3)
41 #define CONF_GLOBAL (1<<4)
42 #define CONF_NOSAVE (1<<5)
43 #define CONF_OLD (1<<6)
46 typedef struct config config_t
;
47 typedef struct m_config m_config_t
;
48 typedef struct config_save config_save_t
;
52 typedef void (*cfg_default_func_t
)(config_t
*, char*);
60 /* Use this field when your need to do something before a new value is
61 assigned to your option */
62 cfg_default_func_t default_func
;
69 config_save_t
** config_stack
;
71 int parser_mode
; /* COMMAND_LINE or CONFIG_FILE */
73 char* sub_conf
; // When we save a subconfig
74 struct play_tree
* pt
; // play tree we use for playlist option, etc
75 struct play_tree
* last_entry
; // last added entry
76 struct play_tree
* last_parent
; // if last_entry is NULL we must create child of this
92 typedef int (*cfg_func_arg_param_t
)(config_t
*, char *, char *);
93 typedef int (*cfg_func_param_t
)(config_t
*, char *);
94 typedef int (*cfg_func_t
)(config_t
*);
96 /* parse_config_file returns:
97 * -1 on error (can't malloc, invalid option...)
98 * 0 if can't open configfile
101 int m_config_parse_config_file(m_config_t
*config
, char *conffile
);
103 /* parse_command_line returns:
104 * -1 on error (invalid option...)
107 int m_config_parse_command_line(m_config_t
* config
, int argc
, char **argv
);
109 m_config_t
* m_config_new(struct play_tree
* pt
);
111 void m_config_free(m_config_t
* config
);
113 void m_config_push(m_config_t
* config
);
116 * Return 0 on error 1 on success
118 int m_config_pop(m_config_t
* config
);
121 * Return 0 on error 1 on success
123 int m_config_register_options(m_config_t
*config
,config_t
*args
);
126 * For all the following function when it's a subconfig option
127 * you must give an option name like 'tv:channel' and not just
132 * Return 1 on sucess 0 on failure
134 int m_config_set_option(m_config_t
*config
,char *opt
, char *param
);
137 * Get the config struct defining an option
138 * Return NULL on error
140 config_t
* m_config_get_option(m_config_t
*config
, char* arg
);
143 * Get the p field of the struct defining an option
144 * Return NULL on error
146 void* m_config_get_option_ptr(m_config_t
*config
, char* arg
);
149 * Tell is an option is alredy set or not
150 * Return -1 one error (requested option arg exist)
153 int m_config_is_option_set(m_config_t
*config
, char* arg
);
156 * Return 0 on error 1 on success
158 int m_config_switch_flag(m_config_t
*config
, char* opt
);
161 * Return 0 on error 1 on success
163 int m_config_set_flag(m_config_t
*config
, char* opt
, int max
);
166 * Return the value of a flag (O or 1) and -1 on error
168 int m_config_get_flag(m_config_t
*config
, char* opt
);
171 * Set the value of an int option
172 * Return 0 on error 1 on success
175 m_config_set_int(m_config_t
*config
, char* arg
,int val
);
178 * Get the value of an int option
179 * Return the option value or -1 on error
180 * If err_ret is not NULL it's set to 1 on error
183 m_config_get_int (m_config_t
*config
, char* arg
,int* err_ret
);
186 * Set the value of a float option
187 * Return 0 on error 1 on success
190 m_config_set_float(m_config_t
*config
, char* arg
,float val
);
194 * Get the value of a float option
195 * Return the option value or -1 on error
196 * If err_ret is not NULL it's set to 1 on error
199 m_config_get_float (m_config_t
*config
, char* arg
,int* err_ret
);
201 #endif /* __CONFIG_H */
203 #endif /* NEW_CONFIG */