3 /// \ingroup ConfigParsers MEntry
19 #include "parser-mecmd.h"
22 m_entry_list_free(m_entry_t
* lst
) {
25 for(i
= 0 ; lst
[i
].name
!= NULL
; i
++){
27 for(j
= 0 ; lst
[i
].opts
[2*j
] != NULL
; j
++) {
28 free(lst
[i
].opts
[2*j
]);
29 free(lst
[i
].opts
[2*j
+1]);
37 m_entry_set_options(m_config_t
*config
, m_entry_t
* entry
) {
40 for(i
= 0 ; entry
->opts
[2*i
] != NULL
; i
++){
41 r
= m_config_set_option(config
,entry
->opts
[2*i
],entry
->opts
[2*i
+1]);
52 m_config_parse_me_command_line(m_config_t
*config
, int argc
, char **argv
)
59 m_entry_t
*lst
= NULL
, *entry
= NULL
;
62 assert(config
!= NULL
);
67 config
->mode
= M_COMMAND_LINE
;
69 lst
= calloc(1,sizeof(m_entry_t
));
71 for (i
= 1; i
< argc
; i
++) {
74 /* check for -- (no more options id.) except --help! */
75 if ((*opt
== '-') && (*(opt
+1) == '-') && (*(opt
+2) == 0))
80 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "'--' indicates no more options, but no filename was given on the command line.\n");
86 if ((no_more_opts
== 0) && (*opt
== '-') && (*(opt
+1) != 0)) /* option */
88 m_option_t
* mp_opt
= NULL
;
89 /* remove trailing '-' */
91 mp_msg(MSGT_CFGPARSER
, MSGL_DBG3
, "this_opt = option: %s\n", opt
);
92 mp_opt
= m_config_get_option(config
,opt
);
95 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "-%s is not an MEncoder option\n",opt
);
98 if(!entry
|| (mp_opt
->flags
& M_OPT_GLOBAL
)){
99 tmp
= m_config_set_option(config
, opt
, argv
[i
+ 1]);
100 if (tmp
<= M_OPT_EXIT
) {
102 tmp
= M_OPT_EXIT
- tmp
;
106 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
107 mp_msg(MSGT_CFGPARSER
, MSGL_FATAL
, "Error parsing option on the command line: -%s\n",opt
);
111 tmp
= m_config_check_option(config
, opt
, argv
[i
+ 1]);
112 if (tmp
<= M_OPT_EXIT
) {
114 tmp
= M_OPT_EXIT
- tmp
;
117 entry
->opts
= realloc(entry
->opts
,(no
+2)*2*sizeof(char*));
118 entry
->opts
[2*no
] = strdup(opt
);
119 entry
->opts
[2*no
+1] = argv
[i
+ 1] ? strdup(argv
[i
+ 1]) : NULL
;
120 entry
->opts
[2*no
+2] = entry
->opts
[2*no
+3] = NULL
;
123 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
128 } else {/* filename */
129 mp_msg(MSGT_CFGPARSER
, MSGL_DBG2
,"Adding file %s\n",argv
[i
]);
130 lst
= realloc(lst
,(nf
+2)*sizeof(m_entry_t
));
131 lst
[nf
].name
= strdup(argv
[i
]);
132 lst
[nf
].opts
= calloc(2,sizeof(char*));
135 memset(&lst
[nf
+1],0,sizeof(m_entry_t
));
143 m_entry_list_free(lst
);
144 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "No file given\n");
150 m_entry_list_free(lst
);