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