Real rstp:// streaming support, ported from xine
[mplayer/greg.git] / cfgparser.h
blob2e627246d3161d3094a5a4b711d27bf4964eeba5
1 /*
2 * command line and config file parser
3 */
5 #ifdef NEW_CONFIG
6 #ifdef MP_DEBUG
7 #warning "NEW_CONFIG defined but still using the old cfgparser.h"
8 #endif
9 #include "m_config.h"
10 #include "m_option.h"
11 #else
13 #ifndef __CONFIG_H
14 #define __CONFIG_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;
50 struct play_tree;
52 typedef void (*cfg_default_func_t)(config_t *, char*);
54 struct config {
55 char *name;
56 void *p;
57 unsigned int type;
58 unsigned int flags;
59 float min,max;
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;
67 struct m_config {
68 config_t** opt_list;
69 config_save_t** config_stack;
70 int cs_level;
71 int parser_mode; /* COMMAND_LINE or CONFIG_FILE */
72 int flags;
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
77 int recursion_depth;
80 struct config_save {
81 config_t* opt;
82 union {
83 int as_int;
84 float as_float;
85 void* as_pointer;
86 off_t as_off_t;
87 } param;
88 char* opt_name;
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
99 * 1 on success
101 int m_config_parse_config_file(m_config_t *config, char *conffile);
103 /* parse_command_line returns:
104 * -1 on error (invalid option...)
105 * 1 otherwise
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
128 * 'channel'
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)
151 * Otherwise 0 or 1
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
198 float
199 m_config_get_float (m_config_t *config, char* arg,int* err_ret);
201 #endif /* __CONFIG_H */
203 #endif /* NEW_CONFIG */