8164
|
1
|
|
2 #ifndef NEW_CONFIG
|
|
3 #warning "Including m_option.h but NEW_CONFIG is disabled"
|
|
4 #else
|
|
5
|
|
6 typedef struct m_option_type m_option_type_t;
|
|
7 typedef struct m_option m_option_t;
|
|
8
|
|
9 ///////////////////////////// Options types declarations ////////////////////////////
|
|
10
|
|
11 // Simple types
|
|
12 extern m_option_type_t m_option_type_flag;
|
|
13 extern m_option_type_t m_option_type_int;
|
|
14 extern m_option_type_t m_option_type_float;
|
|
15 extern m_option_type_t m_option_type_string;
|
|
16 extern m_option_type_t m_option_type_string_list;
|
|
17 extern m_option_type_t m_option_type_position;
|
|
18
|
|
19 extern m_option_type_t m_option_type_print;
|
8736
|
20 extern m_option_type_t m_option_type_print_indirect;
|
8164
|
21 extern m_option_type_t m_option_type_subconfig;
|
|
22 extern m_option_type_t m_option_type_imgfmt;
|
|
23
|
|
24 // Func based types
|
|
25 extern m_option_type_t m_option_type_func_full;
|
|
26 extern m_option_type_t m_option_type_func_param;
|
|
27 extern m_option_type_t m_option_type_func;
|
|
28
|
|
29 typedef void (*m_opt_default_func_t)(m_option_t *, char*);
|
|
30 typedef int (*m_opt_func_full_t)(m_option_t *, char *, char *);
|
|
31 typedef int (*m_opt_func_param_t)(m_option_t *, char *);
|
|
32 typedef int (*m_opt_func_t)(m_option_t *);
|
|
33 ///////////// Backward compat
|
|
34 typedef m_opt_default_func_t cfg_default_func_t;
|
|
35 typedef m_opt_func_full_t cfg_func_arg_param_t;
|
|
36 typedef m_opt_func_param_t cfg_func_param_t;
|
|
37 typedef m_opt_func_t cfg_func_t;
|
|
38
|
|
39 // Track/Chapter range
|
|
40 // accept range in the form 1[hh:mm:ss.zz]-5[hh:mm:ss.zz]
|
|
41 // ommited fields are assumed to be 0
|
|
42 // Not finished !!!!
|
|
43 typedef struct {
|
|
44 int idx; // in the e.g 1 or 5
|
|
45 unsigned int seconds; // hh:mm:ss converted in seconds
|
|
46 unsigned int sectors; // zz
|
|
47 } m_play_pos_t;
|
|
48
|
|
49 typedef struct {
|
|
50 m_play_pos_t start;
|
|
51 m_play_pos_t end;
|
|
52 } m_span_t;
|
|
53 extern m_option_type_t m_option_type_span;
|
|
54
|
|
55 // Don't be stupid keep tho old names ;-)
|
|
56 #define CONF_TYPE_FLAG (&m_option_type_flag)
|
|
57 #define CONF_TYPE_INT (&m_option_type_int)
|
|
58 #define CONF_TYPE_FLOAT (&m_option_type_float)
|
|
59 #define CONF_TYPE_STRING (&m_option_type_string)
|
|
60 #define CONF_TYPE_FUNC (&m_option_type_func)
|
|
61 #define CONF_TYPE_FUNC_PARAM (&m_option_type_func_param)
|
|
62 #define CONF_TYPE_PRINT (&m_option_type_print)
|
8736
|
63 #define CONF_TYPE_PRINT_INDIRECT (&m_option_type_print_indirect)
|
8164
|
64 #define CONF_TYPE_FUNC_FULL (&m_option_type_func_full)
|
|
65 #define CONF_TYPE_SUBCONFIG (&m_option_type_subconfig)
|
|
66 #define CONF_TYPE_STRING_LIST (&m_option_type_string_list)
|
|
67 #define CONF_TYPE_POSITION (&m_option_type_position)
|
|
68 #define CONF_TYPE_IMGFMT (&m_option_type_imgfmt)
|
|
69 #define CONF_TYPE_SPAN (&m_option_type_span)
|
|
70
|
|
71
|
|
72 /////////////////////////////////////////////////////////////////////////////////////////////
|
|
73
|
|
74 struct m_option_type {
|
|
75 char* name;
|
|
76 char* comments; // syntax desc, etc
|
|
77 unsigned int size; // size needed for a save slot
|
|
78 unsigned int flags;
|
|
79
|
|
80 // parse is the only requiered function all others can be NULL
|
|
81 // If dst if non-NULL it should create/update the save slot
|
|
82 // If dst is NULL it should just test the validity of the arg if possible
|
|
83 // Src tell from where come this setting (ie cfg file, command line, playlist, ....
|
|
84 // It should return 1 if param was used, 0 if not.
|
|
85 // On error it must return 1 of the error code below
|
|
86 int (*parse)(m_option_t* opt,char *name, char *param, void* dst, int src);
|
|
87 // Print back a value in human form
|
|
88 char* (*print)(m_option_t* opt, void* val);
|
|
89
|
|
90 // These 3 will be a memcpy in 50% of the case, it's called to save/restore the status of
|
|
91 // the var it's there for complex type like CONF_TYPE_FUNC*
|
|
92 // update a save slot (dst) from the current value in the prog (src)
|
|
93 void (*save)(m_option_t* opt,void* dst, void* src);
|
|
94 // set the current value (dst) from a save slot
|
|
95 void (*set)(m_option_t* opt,void* dst, void* src);
|
|
96 // Copy betewen 2 slot (if NULL and size > 0 a memcpy will be used
|
|
97 void (*copy)(m_option_t* opt,void* dst, void* src);
|
|
98 // Free the data allocated for a save slot if needed
|
|
99 void (*free)(void* dst);
|
|
100 };
|
|
101
|
|
102 /// This is the same thing as a struct config it have been renamed
|
|
103 /// to remove this config_t, m_config_t mess. Sorry about that,
|
|
104 /// config_t is still provided for backward compat.
|
|
105 struct m_option {
|
|
106 char *name;
|
|
107 void *p;
|
|
108 m_option_type_t* type;
|
|
109 unsigned int flags;
|
|
110 float min,max;
|
|
111 // This used to be function pointer to hold a 'reverse to defaults' func.
|
|
112 // Nom it can be used to pass any type of extra args.
|
|
113 // Passing a 'default func' is still valid for all func based option types
|
|
114 void* priv; // Type dependent data (for all kind of extended setting)
|
|
115 };
|
|
116
|
|
117
|
|
118 //////////////////////////////// Option flags /////////////////////////////////
|
|
119
|
|
120 // Option flags
|
|
121 #define M_OPT_MIN (1<<0)
|
|
122 #define M_OPT_MAX (1<<1)
|
|
123 #define M_OPT_RANGE (M_OPT_MIN|M_OPT_MAX)
|
|
124 #define M_OPT_NOCFG (1<<2)
|
|
125 #define M_OPT_NOCMD (1<<3)
|
|
126 // This option is global : it won't be saved on push and the command
|
|
127 // line parser will set it when it's parsed (ie. it won't be set later)
|
|
128 // e.g options : -v, -quiet
|
|
129 #define M_OPT_GLOBAL (1<<4)
|
|
130 // Do not save this option : it won't be saved on push but the command
|
|
131 // line parser will put it with it's entry (ie : it may be set later)
|
|
132 // e.g options : -include
|
|
133 #define M_OPT_NOSAVE (1<<5)
|
|
134 // Emulate old behaviour by pushing the option only if it was set by the user
|
|
135 #define M_OPT_OLD (1<<6)
|
|
136
|
|
137
|
|
138 ///////////////////////////// Option type flags ///////////////////////////////////
|
|
139
|
|
140 // These flags are for the parsers. The description here apply to the m_config_t
|
|
141 // based parsers (ie. cmd line and config file parsers)
|
|
142 // Some parser will refuse option types that have some of these flags
|
|
143
|
|
144 // This flag is used for the subconfig
|
|
145 // When this flag is set, opt->p should point to another m_option_t array
|
|
146 // Only the parse function will be called. If dst is set, it should create/update
|
|
147 // an array of char* containg opt/val pairs.
|
|
148 // Then the options in the child array will then be set automaticly.
|
|
149 // You can only affect the way suboption are parsed.
|
|
150 // Also note that suboptions may be directly accessed by using -option:subopt blah :-)
|
|
151 #define M_OPT_TYPE_HAS_CHILD (1<<0)
|
|
152 // If this flag is set the option type support option name with * at the end (used for -aa*)
|
|
153 // This only affect the option name matching, the option type have to implement
|
|
154 // the needed stuff.
|
|
155 #define M_OPT_TYPE_ALLOW_WILDCARD (1<<1)
|
|
156 // This flag indicate that the data is dynamicly allocated (opt->p point to a pointer)
|
|
157 // It enable a little hack wich replace the initial value by a dynamic copy
|
|
158 // in case the initial value is staticly allocated (pretty common with strings)
|
|
159 #define M_OPT_TYPE_DYNAMIC (1<<2)
|
|
160 /// If this is set the parse function doesn't directly return
|
|
161 // the wanted thing. Options use this if for some reasons they have to wait
|
|
162 // until the set call to be able to correctly set the target var.
|
|
163 // So for those types you have to first parse and then set the target var
|
|
164 // If this flag isn't set you can parse directly to the target var
|
|
165 // It's used for the callback based option as the callback call may append
|
|
166 // later on.
|
|
167 #define M_OPT_TYPE_INDIRECT (1<<3)
|
|
168
|
|
169
|
|
170 ///////////////////////////// Parser flags ////////////////////////////////////////
|
|
171
|
|
172 // Config mode : some parser type behave differently depending
|
|
173 // on config->mode value wich is passed in the src param of parse()
|
|
174 #define M_CONFIG_FILE 0
|
|
175 #define M_COMMAND_LINE 1
|
|
176
|
|
177 // Option parser error code
|
|
178 #define M_OPT_UNKNOW -1
|
|
179 #define M_OPT_MISSING_PARAM -2
|
|
180 #define M_OPT_INVALID -3
|
|
181 #define M_OPT_OUT_OF_RANGE -4
|
|
182 #define M_OPT_PARSER_ERR -5
|
|
183
|
|
184
|
|
185 inline static int
|
|
186 m_option_parse(m_option_t* opt,char *name, char *param, void* dst, int src) {
|
|
187 return opt->type->parse(opt,name,param,dst,src);
|
|
188 }
|
|
189
|
|
190 inline static char*
|
|
191 m_option_print(m_option_t* opt, void* val_ptr) {
|
|
192 if(opt->type->print)
|
|
193 return opt->type->print(opt,val_ptr);
|
|
194 else
|
8168
|
195 return (char*)-1;
|
8164
|
196 }
|
|
197
|
|
198 inline static void
|
|
199 m_option_save(m_option_t* opt,void* dst, void* src) {
|
|
200 if(opt->type->save)
|
|
201 opt->type->save(opt,dst,src);
|
|
202 }
|
|
203
|
|
204 inline static void
|
|
205 m_option_set(m_option_t* opt,void* dst, void* src) {
|
|
206 if(opt->type->set)
|
|
207 opt->type->set(opt,dst,src);
|
|
208 }
|
|
209
|
|
210 inline static void
|
|
211 m_option_copy(m_option_t* opt,void* dst, void* src) {
|
|
212 if(opt->type->copy)
|
|
213 opt->type->set(opt,dst,src);
|
|
214 else if(opt->type->size > 0)
|
|
215 memcpy(dst,src,opt->type->size);
|
|
216 }
|
|
217
|
|
218 inline static void
|
|
219 m_option_free(m_option_t* opt,void* dst) {
|
|
220 if(opt->type->free)
|
|
221 opt->type->free(dst);
|
|
222 }
|
|
223
|
|
224 #endif
|