3 /// \ingroup ConfigParsers MEntry
20 #include "parser-mecmd.h"
23 m_entry_list_free(m_entry_t
* lst
) {
26 for(i
= 0 ; lst
[i
].name
!= NULL
; i
++){
28 for(j
= 0 ; lst
[i
].opts
[2*j
] != NULL
; j
++) {
29 free(lst
[i
].opts
[2*j
]);
30 free(lst
[i
].opts
[2*j
+1]);
38 m_entry_set_options(m_config_t
*config
, m_entry_t
* entry
) {
41 for(i
= 0 ; entry
->opts
[2*i
] != NULL
; i
++){
42 r
= m_config_set_option(config
,entry
->opts
[2*i
],entry
->opts
[2*i
+1]);
53 m_config_parse_me_command_line(m_config_t
*config
, int argc
, char **argv
)
60 m_entry_t
*lst
= NULL
, *entry
= NULL
;
63 assert(config
!= NULL
);
68 config
->mode
= M_COMMAND_LINE
;
70 lst
= calloc(1,sizeof(m_entry_t
));
72 for (i
= 1; i
< argc
; i
++) {
75 /* check for -- (no more options id.) except --help! */
76 if ((*opt
== '-') && (*(opt
+1) == '-') && (*(opt
+2) == 0))
81 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, MSGTR_NoFileGivenOnCommandLine
);
87 if ((no_more_opts
== 0) && (*opt
== '-') && (*(opt
+1) != 0)) /* option */
89 m_option_t
* mp_opt
= NULL
;
90 /* remove trailing '-' */
92 mp_msg(MSGT_CFGPARSER
, MSGL_DBG3
, "this_opt = option: %s\n", opt
);
93 mp_opt
= m_config_get_option(config
,opt
);
96 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, MSGTR_NotAnMEncoderOption
, opt
);
99 if(!entry
|| (mp_opt
->flags
& M_OPT_GLOBAL
)){
100 tmp
= m_config_set_option(config
, opt
, argv
[i
+ 1]);
101 if (tmp
<= M_OPT_EXIT
) {
103 tmp
= M_OPT_EXIT
- tmp
;
107 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
108 mp_msg(MSGT_CFGPARSER
, MSGL_FATAL
, MSGTR_ErrorParsingOptionOnCommandLine
, opt
);
112 tmp
= m_config_check_option(config
, opt
, argv
[i
+ 1]);
113 if (tmp
<= M_OPT_EXIT
) {
115 tmp
= M_OPT_EXIT
- tmp
;
118 entry
->opts
= realloc(entry
->opts
,(no
+2)*2*sizeof(char*));
119 entry
->opts
[2*no
] = strdup(opt
);
120 entry
->opts
[2*no
+1] = argv
[i
+ 1] ? strdup(argv
[i
+ 1]) : NULL
;
121 entry
->opts
[2*no
+2] = entry
->opts
[2*no
+3] = NULL
;
124 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
129 } else {/* filename */
130 mp_msg(MSGT_CFGPARSER
, MSGL_DBG2
,"Adding file %s\n",argv
[i
]);
131 lst
= realloc(lst
,(nf
+2)*sizeof(m_entry_t
));
132 lst
[nf
].name
= strdup(argv
[i
]);
133 lst
[nf
].opts
= calloc(2,sizeof(char*));
136 memset(&lst
[nf
+1],0,sizeof(m_entry_t
));
144 m_entry_list_free(lst
);
145 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, MSGTR_NoFileGiven
);
151 m_entry_list_free(lst
);