15 #include "parser-mecmd.h"
18 m_entry_list_free(m_entry_t
* lst
) {
21 for(i
= 0 ; lst
[i
].name
!= NULL
; i
++){
23 for(j
= 0 ; lst
[i
].opts
[2*j
] != NULL
; j
++) {
24 free(lst
[i
].opts
[2*j
]);
25 free(lst
[i
].opts
[2*j
+1]);
33 m_entry_set_options(m_config_t
*config
, m_entry_t
* entry
) {
36 for(i
= 0 ; entry
->opts
[2*i
] != NULL
; i
++){
37 r
= m_config_set_option(config
,entry
->opts
[2*i
],entry
->opts
[2*i
+1]);
48 m_config_parse_me_command_line(m_config_t
*config
, int argc
, char **argv
)
54 m_entry_t
*lst
= NULL
, *entry
= NULL
;
57 assert(config
!= NULL
);
62 config
->mode
= M_COMMAND_LINE
;
64 lst
= calloc(1,sizeof(m_entry_t
));
66 for (i
= 1; i
< argc
; i
++) {
69 /* check for -- (no more options id.) except --help! */
70 if ((*opt
== '-') && (*(opt
+1) == '-') && (*(opt
+2) != 'h'))
75 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "You added '--' but no filenames presented!\n");
81 if ((no_more_opts
== 0) && (*opt
== '-') && (*(opt
+1) != 0)) /* option */
83 m_option_t
* mp_opt
= NULL
;
84 /* remove trailing '-' */
86 mp_msg(MSGT_CFGPARSER
, MSGL_DBG3
, "this_opt = option: %s\n", opt
);
87 mp_opt
= m_config_get_option(config
,opt
);
90 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "%s is not an MEncoder option\n",opt
);
93 if(!entry
|| (mp_opt
->flags
& M_OPT_GLOBAL
)){
94 tmp
= m_config_set_option(config
, opt
, argv
[i
+ 1]);
96 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
100 tmp
= m_config_check_option(config
, opt
, argv
[i
+ 1]);
102 entry
->opts
= realloc(entry
->opts
,(no
+2)*2*sizeof(char*));
103 entry
->opts
[2*no
] = strdup(opt
);
104 entry
->opts
[2*no
+1] = argv
[i
+ 1] ? strdup(argv
[i
+ 1]) : NULL
;
105 entry
->opts
[2*no
+2] = entry
->opts
[2*no
+3] = NULL
;
108 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
109 if(tmp
== M_OPT_EXIT
)
115 } else {/* filename */
116 mp_msg(MSGT_CFGPARSER
, MSGL_DBG2
,"Adding file %s\n",argv
[i
]);
117 lst
= realloc(lst
,(nf
+2)*sizeof(m_entry_t
));
118 lst
[nf
].name
= strdup(argv
[i
]);
119 lst
[nf
].opts
= calloc(2,sizeof(char*));
122 memset(&lst
[nf
+1],0,sizeof(m_entry_t
));
128 m_entry_list_free(lst
);
129 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
, "No file given\n");
135 m_entry_list_free(lst
);