Mercurial > mplayer.hg
comparison parser-cfg.c @ 26408:7a36d5941fd8
Replace the trivial command line preparser with a more robust version
allowing all kind of options to be used.
author | albeu |
---|---|
date | Sun, 13 Apr 2008 19:18:51 +0000 |
parents | 65d1238b3631 |
children | 0f1b5b68af32 |
comparison
equal
deleted
inserted
replaced
26407:7451ffea2efb | 26408:7a36d5941fd8 |
---|---|
243 config->mode = prev_mode; | 243 config->mode = prev_mode; |
244 --recursion_depth; | 244 --recursion_depth; |
245 return ret; | 245 return ret; |
246 } | 246 } |
247 | 247 |
248 extern int mp_msg_levels[]; | |
249 | |
250 /// Parse the command line option that must be handled at startup. | |
251 int m_config_preparse_command_line(m_config_t *config, int argc, char **argv) | |
252 { | |
253 int msg_lvl, i, r, ret = 0; | |
254 char* arg; | |
255 m_option_t* opt; | |
256 | |
257 // Hack to shutup the parser error messages. | |
258 msg_lvl = mp_msg_levels[MSGT_CFGPARSER]; | |
259 mp_msg_levels[MSGT_CFGPARSER] = -11; | |
260 | |
261 config->mode = M_COMMAND_LINE_PRE_PARSE; | |
262 | |
263 for(i = 1 ; i < argc ; i++) { | |
264 arg = argv[i]; | |
265 // Ignore non option | |
266 if(arg[0] != '-' || arg[1] == 0) continue; | |
267 arg++; | |
268 // No more options after -- | |
269 if(arg[0] == '-' && arg[1] == 0) break; | |
270 | |
271 opt = m_config_get_option(config,arg); | |
272 // Ignore invalid option | |
273 if(!opt) continue; | |
274 // Set, non-pre-parse options will be ignored | |
275 r = m_config_set_option(config,arg, | |
276 i+1 < argc ? argv[i+1] : NULL); | |
277 if(r < 0) ret = r; | |
278 else i += r; | |
279 } | |
280 | |
281 mp_msg_levels[MSGT_CFGPARSER] = msg_lvl; | |
282 | |
283 return ret; | |
284 } | |
285 | |
248 ///@} | 286 ///@} |